c2.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. #include "globrig.h"
  2. #include "define.h"
  3. #include "defpage.h"
  4. #include "nef2.h"
  5. #include "c1.h"
  6. Void addnum(a1, a2)
  7. long *a1, a2;
  8. {
  9. /*===========*/
  10. /* a1 +:= a2 */
  11. /*===========*/
  12. mpd x;
  13. numberdescriptor *WITH;
  14. if (*a1 == null_) {
  15. mknumb(a2, a1);
  16. return;
  17. }
  18. points(*a1, &x.sa);
  19. /* changed from pointr 25-jul-1989
  20. due to change in vax 10-feb-1989 */
  21. if (x.snd->dtype != number) {
  22. er(9L);
  23. *a1 = null_;
  24. } else {
  25. WITH = x.snd;
  26. WITH->val += a2; /* deleted sign */
  27. }
  28. } /* addnum*/
  29. Void setsel(xn, not_atomic, xa, tr_, rez)
  30. long xn;
  31. boolean not_atomic;
  32. long xa, tr_, rez;
  33. {
  34. /*==============================================*/
  35. /* whod: tr x */
  36. /* wyhod: t.x <- rez */
  37. /*==============================================*/
  38. /* wyhod */
  39. mpd x;
  40. a n; /* imq selektora */
  41. a t;
  42. long i, j;
  43. maintreedescriptor *WITH;
  44. long FORLIM, FORLIM1;
  45. fragmtreedescriptor *WITH1;
  46. if (not_atomic) {
  47. if (xa == null_) {
  48. er(21L);
  49. goto _L1;
  50. }
  51. pointr(xa, &x.sa);
  52. if (x.sad->dtype != idatom) {
  53. er(22L);
  54. goto _L1;
  55. }
  56. n = x.sad->name;
  57. } else
  58. n = xn;
  59. if (tr_ == null_)
  60. goto _L1;
  61. /* rezulxtat =null */
  62. /* opredelitx tip tr */
  63. pointr(tr_, &x.sa);
  64. if (x.smtd->dtype != treemain) { /* sna~ala w glawnom derewe */
  65. /* oibka */
  66. er(23L);
  67. goto _L1;
  68. }
  69. /*=====================================*/
  70. /* x ukazywaet na glawn.deskr. derewa */
  71. /* tr na deskr.glawn. derewa */
  72. /*=====================================*/
  73. /* poisk selektora n w derewe x */
  74. WITH = x.smtd; /* with */
  75. FORLIM = WITH->arcnum;
  76. for (i = 1; i <= FORLIM; i++) {
  77. if (WITH->arc[i - 1].arcname == n) { /* na{li */
  78. points(tr_, &x.sa);
  79. WITH->arc[i - 1].elt = rez;
  80. if (rez == null_) {
  81. FORLIM1 = WITH->arcnum;
  82. for (j = i; j < FORLIM1; j++)
  83. WITH->arc[j - 1] = WITH->arc[j];
  84. WITH->arcnum--;
  85. WITH->totalarcnum--;
  86. }
  87. goto _L1;
  88. }
  89. }
  90. t = WITH->next;
  91. /* prodolvaem poisk w fragmentah */
  92. while (t != null_) {
  93. pointr(t, &x.sa);
  94. WITH1 = x.sftd;
  95. FORLIM = WITH1->arcnum;
  96. for (i = 1; i <= FORLIM; i++) {
  97. if (WITH1->arc[i - 1].arcname == n) { /* na{li */
  98. points(t, &x.sa);
  99. WITH1->arc[i - 1].elt = rez;
  100. if (rez == null_) {
  101. FORLIM1 = WITH1->arcnum;
  102. for (j = i; j < FORLIM1; j++)
  103. WITH1->arc[j - 1] = WITH1->arc[j];
  104. WITH1->arcnum--;
  105. points(tr_, &x.sa);
  106. WITH = x.smtd;
  107. WITH->totalarcnum--;
  108. }
  109. goto _L1;
  110. }
  111. }
  112. t = WITH1->next; /* with */
  113. } /* while */
  114. /* ne nali ! */
  115. er(8L);
  116. _L1: ;
  117. } /* setsel */
  118. Void setind(xx, isobject, xa, l, rez)
  119. long xx;
  120. boolean isobject;
  121. long xa, l, rez;
  122. {
  123. /*==============================================*/
  124. /* whod: l xx */
  125. /* wyhod: l[ xx ] := rez */
  126. /* */
  127. /* l[ -1 ] - poslednij |l-t spiska */
  128. /* l[ -2 ] - predposlednij |l-t spiska ... */
  129. /*==============================================*/
  130. /* wyhod */
  131. mpd y;
  132. long k, n;
  133. a t;
  134. if (isobject) {
  135. n = numval(xa);
  136. if (n == 0) {
  137. er(3L);
  138. goto _L1;
  139. }
  140. } else
  141. n = xx;
  142. /* w n -zna~enie indeksa */
  143. if (l == null_) /* rezulxtat= null */
  144. goto _L1;
  145. /* opredelitx tip l */
  146. pointr(l, &y.sa);
  147. if (y.smld->dtype != listmain) {
  148. er(4L);
  149. goto _L1;
  150. }
  151. /*============================================*/
  152. /* y ukazywaet na deskriptor glawnogo spiska */
  153. /*============================================*/
  154. /* wy~islenie l[x] */
  155. k = y.smld->totalelnum;
  156. if (n < 0)
  157. n += k + 1;
  158. if (n < 1 || n > k) {
  159. er(5L);
  160. /* indeks wne spiska */
  161. goto _L1;
  162. }
  163. /*================================*/
  164. /* poisk |l-ta spiska */
  165. /*================================*/
  166. if (n <= y.smld->elnum) {
  167. points(l, &y.sa);
  168. y.smld->elt[n - 1] = rez;
  169. } else {
  170. n -= y.smld->elnum;
  171. t = y.smld->next;
  172. pointr(t, &y.sa);
  173. while (n > y.sfld->elnum) {
  174. n -= y.sfld->elnum;
  175. t = y.sfld->next;
  176. pointr(t, &y.sa);
  177. }
  178. points(t, &y.sa);
  179. y.sfld->elt[n - 1] = rez;
  180. }
  181. _L1: ;
  182. } /* setind */
  183. Void selop(xn, not_atomic, xa, tr_, rez)
  184. long xn;
  185. boolean not_atomic;
  186. long xa, tr_, *rez;
  187. {
  188. /*==============================================*/
  189. /* whod: tr x */
  190. /* wyhod: t.x -> rez */
  191. /*==============================================*/
  192. /* wyhod */
  193. mpd x;
  194. a n; /* imq selektora */
  195. a t;
  196. long i;
  197. maintreedescriptor *WITH;
  198. long FORLIM;
  199. fragmtreedescriptor *WITH1;
  200. *rez = null_;
  201. if (not_atomic) {
  202. if (xa == null_) {
  203. er(21L);
  204. goto _L1;
  205. }
  206. pointr(xa, &x.sa);
  207. if (x.sad->dtype != idatom) {
  208. er(22L);
  209. goto _L1;
  210. }
  211. n = x.sad->name;
  212. } else
  213. n = xn;
  214. if (tr_ == null_)
  215. goto _L1;
  216. /* rezulxtat =null */
  217. /* opredelitx tip tr */
  218. pointr(tr_, &x.sa);
  219. if (x.smtd->dtype != treemain) { /* sna~ala w glawnom derewe */
  220. /* o{ibka */
  221. er(23L);
  222. goto _L1;
  223. }
  224. /*=====================================*/
  225. /* x ukazywaet na glawn.deskr. derewa */
  226. /* tr na deskr.glawn. derewa */
  227. /*=====================================*/
  228. /* poisk selektora n w derewe x */
  229. WITH = x.smtd; /* with */
  230. FORLIM = WITH->arcnum;
  231. for (i = 0; i < FORLIM; i++) {
  232. if (WITH->arc[i].arcname == n) { /* na{li */
  233. *rez = WITH->arc[i].elt;
  234. goto _L1;
  235. }
  236. }
  237. t = WITH->next;
  238. /* prodolvaem poisk w fragmentah */
  239. while (t != null_) {
  240. pointr(t, &x.sa);
  241. WITH1 = x.sftd;
  242. FORLIM = WITH1->arcnum;
  243. for (i = 0; i < FORLIM; i++) {
  244. if (WITH1->arc[i].arcname == n) { /* na{li */
  245. *rez = WITH1->arc[i].elt;
  246. goto _L1;
  247. }
  248. }
  249. t = WITH1->next; /* with */
  250. } /* while */
  251. /* ne na{li ! */
  252. _L1: ;
  253. } /* selop */
  254. Void indxop(xx, isobject, xa, l, rez)
  255. long xx;
  256. boolean isobject;
  257. long xa, l, *rez;
  258. {
  259. /*==============================================*/
  260. /* whod: l xx */
  261. /* wyhod: l[ xx ] */
  262. /* */
  263. /* l[ -1 ] - poslednij |l-t spiska */
  264. /* l[ -2 ] - predposlednij |l-t spiska ... */
  265. /*==============================================*/
  266. /* wyhod */
  267. mpd y;
  268. long k, n;
  269. a t;
  270. *rez = null_;
  271. if (isobject) {
  272. n = numval(xa);
  273. if (n == 0) {
  274. er(3L);
  275. goto _L1;
  276. }
  277. } else
  278. n = xx;
  279. /* w n -zna~enie indeksa */
  280. if (l == null_) /* rezulxtat= null */
  281. goto _L1;
  282. /* opredelitx tip l */
  283. pointr(l, &y.sa);
  284. if (y.smld->dtype != listmain) {
  285. er(4L);
  286. goto _L1;
  287. }
  288. /*============================================*/
  289. /* y ukazywaet na deskriptor glawnogo spiska */
  290. /*============================================*/
  291. /* wy~islenie l[x] */
  292. k = y.smld->totalelnum;
  293. if (n < 0)
  294. n += k + 1;
  295. if (n < 1 || n > k) {
  296. er(5L);
  297. /* indeks wne spiska */
  298. goto _L1;
  299. }
  300. /*================================*/
  301. /* poisk |l-ta spiska */
  302. /*================================*/
  303. if (n <= y.smld->elnum)
  304. *rez = y.smld->elt[n - 1];
  305. else {
  306. n -= y.smld->elnum;
  307. t = y.smld->next;
  308. pointr(t, &y.sa);
  309. while (n > y.sfld->elnum) {
  310. n -= y.sfld->elnum;
  311. t = y.sfld->next;
  312. pointr(t, &y.sa);
  313. }
  314. *rez = y.sfld->elt[n - 1];
  315. }
  316. /* w rez rezulxtat = l [ x ] */
  317. _L1: ;
  318. } /* indxop */
  319. Void concop(a1, a2)
  320. long *a1, a2;
  321. {
  322. /*======================================*/
  323. /* operaciq a1 !! a2 */
  324. /* ( a1 !! a2 ) -> a1 */
  325. /*======================================*/
  326. /* wyhod */
  327. mpd x;
  328. ptr_ p1;
  329. a l;
  330. l = *a1;
  331. if (a2 == null_) {
  332. if (l == null_)
  333. goto _L99;
  334. else {
  335. pointr(l, &x.sa);
  336. if (x.smld->dtype == listmain)
  337. goto _L99;
  338. else {
  339. l = null_;
  340. goto _L99;
  341. }
  342. }
  343. }
  344. pointr(a2, &x.sa);
  345. if (x.smld->dtype != listmain) {
  346. l = null_;
  347. goto _L99;
  348. }
  349. if (l != null_) {
  350. pointr(l, &x.sa);
  351. if (x.smld->dtype != listmain) {
  352. l = null_;
  353. goto _L99;
  354. }
  355. }
  356. first(a2, &p1);
  357. while (p1.nel != 0) {
  358. lconc(&l, p1.cel);
  359. next(&p1);
  360. }
  361. _L99:
  362. *a1 = l;
  363. } /* concop */
  364. Void copyop(ob, rez)
  365. long ob, *rez;
  366. {
  367. /*==========================*/
  368. /*whod: ob */
  369. /*wyhod: copy( a )-> rez */
  370. /*==========================*/
  371. /* wyhod */
  372. long k;
  373. mpd x, y, z;
  374. a r1, r2, r3;
  375. if (ob == null_) {
  376. *rez = null_;
  377. goto _L99;
  378. }
  379. pointr(ob, &x.sa);
  380. switch (x.sad->dtype) {
  381. case atom:
  382. case idatom:
  383. case keyword:
  384. case number:
  385. case tatom:
  386. case fatom:
  387. case variable:
  388. case idvariable:
  389. case nvariable:
  390. case fvariable:
  391. case spec: /* coord removed */
  392. gets1(&r1, &y.sa);
  393. *y.sad = *x.sad;
  394. *rez = r1;
  395. break;
  396. case rulename:
  397. case object_d:
  398. gets2(&r1, &y.sa);
  399. *y.srd = *x.srd;
  400. *rez = r1;
  401. break;
  402. case listmain:
  403. case treemain:
  404. gets5(&r1, &y.sa);
  405. /* skopirowatx glawnyj deskriptor */
  406. *y.smld = *x.smld;
  407. *rez = r1;
  408. r2 = x.smld->next;
  409. while (r2 != null_) {
  410. pointr(r2, &x.sa);
  411. gets5(&r3, &z.sa);
  412. *z.smld = *x.smld;
  413. points(r1, &y.sa);
  414. y.smld->next = r3;
  415. r1 = r3;
  416. r2 = z.smld->next;
  417. } /* while */
  418. break;
  419. }/* case */
  420. _L99: ; /* wyhod */
  421. } /* copyop */
  422. /* End. */