usemod.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. #include "globrig.h"
  2. #include "define.h"
  3. #include "defpage.h"
  4. #include "ley.h"
  5. #include "scan.h"
  6. #include "nef2.h"
  7. #include "usemod.h"
  8. #include <math.h>
  9. #include <string.h>
  10. /* us1 bodies of use-procedures for sun */
  11. mpd xx;
  12. Static boolean plstr(p0, strval, lenval, stringflag, stringval)
  13. long p0;
  14. Char *strval;
  15. long *lenval;
  16. boolean stringflag;
  17. Char *stringval;
  18. {
  19. /* input - s-address*/
  20. /* output: array */
  21. /* length of atom */
  22. /* need stringval ? */
  23. /* string */
  24. /* returns array of letters of atom if it is list parameter; */
  25. /* stringval with the same contest returned only
  26. if required by stringflag */
  27. aa atm;
  28. long i, FORLIM;
  29. *stringval = '\0';
  30. if (p0 == null_)
  31. return false;
  32. else {
  33. pointr(p0, &xx.sa); /* access to atom in memory */
  34. if (((1L << ((long)xx.sad->dtype)) & ((1L << ((long)fatom + 1)) -
  35. (1L << ((long)atom))) & (~(1L << ((long)number)))) == 0)
  36. return false;
  37. else {
  38. atm = xx.sad->name; /* access to a-address */
  39. pointa(atm, strval, lenval); /* reads value to str variable */
  40. if (stringflag) {
  41. FORLIM = *lenval;
  42. for (i = 0; i < FORLIM; i++)
  43. sprintf(stringval + strlen(stringval), "%c", strval[i]);
  44. /* and to stringval variable */
  45. }
  46. return true;
  47. }
  48. }
  49. } /* plstr */
  50. Static Char bc(a_)
  51. long a_;
  52. {
  53. if (a_ >= 10)
  54. return ((Char)(a_ + 55));
  55. else
  56. return ((Char)(a_ + 48));
  57. }
  58. Static Void dump(adr, sad)
  59. long adr, sad;
  60. {
  61. /* physical address */
  62. }
  63. a a2, atm;
  64. long j, l, i1;
  65. error_rec_type error_rec_use;
  66. Char dty;
  67. FILE *workfile;
  68. Char c;
  69. boolean id;
  70. string80 sv1, sv2, svar;
  71. bl80 str_; /*for pointa & putatm*/
  72. bl80 str1_; /*for pointa & putatm*/
  73. longint im[5];
  74. typedef union sa_pointer {
  75. a pointa;
  76. Char immed[4];
  77. struct {
  78. word offset;
  79. Char page, pazime;
  80. } struct_;
  81. } sa_pointer;
  82. Void use_42(p1, p2, p3, rez)
  83. long p1, p2, p3, *rez;
  84. {
  85. /* returns current page (very useful for big algorythms) */
  86. sa_pointer xxx;
  87. long i;
  88. numberdescriptor *WITH;
  89. gets1(rez, &xx.sa);
  90. WITH = xx.snd;
  91. WITH->dtype = number;
  92. WITH->cord = 0;
  93. xxx.pointa = *rez;
  94. putchar('\n');
  95. for (i = 0; i <= 3; i++)
  96. printf("%d-", xxx.immed[i]);
  97. putchar('\n');
  98. WITH->val = xxx.immed[1];
  99. }
  100. Void use_43(p1, p2, p3, rez)
  101. long p1, p2, p3, *rez;
  102. {
  103. /* returns #call_pas(42) if current disk in use,
  104. 0 otherwise. */
  105. numberdescriptor *WITH;
  106. gets1(rez, &xx.sa);
  107. WITH = xx.snd;
  108. WITH->dtype = number;
  109. WITH->cord = 0;
  110. vols(im, &im[1], &WITH->val);
  111. }
  112. Void use_30(p1, p2, p3, rez)
  113. long p1, p2, p3, *rez;
  114. {
  115. *rez = null_;
  116. /*write atom or number*/
  117. if (plstr(p1, str_, &l, true, sv1))
  118. fputs(sv1, stdout);
  119. else {
  120. if (plnum(p1, im))
  121. printf("%12ld", im[0]);
  122. }
  123. }
  124. Void use_31(p1, p2, p3, rez)
  125. long p1, p2, p3, *rez;
  126. {
  127. long i, FORLIM;
  128. /*write atom or number with adding spaces after it or rupping the end*/
  129. *rez = 0;
  130. if (!plstr(p1, str_, &l, true, sv1)) {
  131. if (!plnum(p1, &im[1]))
  132. goto _L1;
  133. long_to_str(sv1, im[1]);
  134. }
  135. if (plnum(p2, im)) {
  136. if (im[0] > strlen(sv1)) {
  137. FORLIM = im[0];
  138. for (i = strlen(sv1); i < FORLIM; i++)
  139. sv1[i] = ' ';
  140. }
  141. printf("%*s", (int)im[0], sv1);
  142. } else
  143. fputs(sv1, stdout);
  144. _L1: ;
  145. }
  146. Void use_1(p1, p2, p3, rez)
  147. long p1, p2, p3, *rez;
  148. {
  149. char *TEMP; /* Char ->char */
  150. *rez = 0;
  151. /* puts an atom (or null) to screen.
  152. user's answer (atom, identifier or number ) is returned */
  153. if (plstr(p1, str_, &l, true, sv1))
  154. fputs(sv1, stdout);
  155. fgets(svar, 81, stdin);
  156. TEMP = strchr(svar, '\n');
  157. if (TEMP != NULL) /* enters from screen */
  158. *TEMP = 0;
  159. *rez = str_to_atom(svar);
  160. }
  161. /*rigal lexical analyser */
  162. Void use_14(p1, p2, p3, rez)
  163. long p1, p2, p3, *rez;
  164. {
  165. *rez = 0;
  166. *error_rec_use.message = '\0';
  167. if (plstr(p1, str_, &l, true, sv1))
  168. ley(sv1, rez, false, &error_rec_use);
  169. }
  170. Void use_15(p1, p2, p3, rez)
  171. long p1, p2, p3, *rez;
  172. {
  173. *rez = 0;
  174. *error_rec_use.message = '\0';
  175. if (plstr(p1, str_, &l, true, sv1))
  176. ley(sv1, rez, true, &error_rec_use);
  177. }
  178. Void use_16(p1, p2, p3, rez)
  179. long p1, p2, p3, *rez;
  180. {
  181. FILE *inpfile;
  182. string80 s;
  183. Char c;
  184. long rline;
  185. int fff;
  186. inpfile = NULL;
  187. *rez = 0;
  188. if (plstr(p1, str_, &l, true, sv1)) {
  189. if (existfile(sv1)) {
  190. inpfile = fopen(sv1, "r");
  191. if (inpfile == NULL) _EscIO(FileNotFound);
  192. *rez = null_;
  193. while (!feof(inpfile)) {
  194. fgets(s,145,inpfile);
  195. if (s[strlen(s)-1]=='\n')
  196. { s[strlen(s)-1]=0;
  197. fff=fgetc(inpfile);
  198. if (fff!=10)
  199. { ungetc(fff,inpfile);}
  200. }
  201. a2 = str_to_textatom(s);
  202. lconc(rez, a2);
  203. } /*while eof*/
  204. /* readln(inftext,svar); */
  205. if (inpfile != NULL)
  206. fclose(inpfile);
  207. inpfile = NULL;
  208. }
  209. }
  210. if (inpfile != NULL)
  211. fclose(inpfile);
  212. }
  213. Void use_4(p1, p2, p3, rez)
  214. long p1, p2, p3, *rez;
  215. {
  216. numberdescriptor *WITH;
  217. *rez = 0;
  218. /* finds coordinate of atom */
  219. if (p1 == 0)
  220. return;
  221. pointr(p1, &xx.sa);
  222. if (((1L << ((long)xx.sad->dtype)) & ((1L << ((long)fatom + 1)) -
  223. (1L << ((long)atom))) & (~(1L << ((long)number)))) != 0)
  224. a2 = xx.sad->cord;
  225. else if (xx.snd->dtype == number)
  226. a2 = xx.snd->cord;
  227. else
  228. a2 = 0;
  229. /* make numerical atom */
  230. gets1(rez, &xx.sa); /* fill descriptor */
  231. WITH = xx.snd;
  232. WITH->dtype = number;
  233. WITH->cord = 0;
  234. WITH->val = a2;
  235. }
  236. Void use_10(p1, p2, p3, rez)
  237. long p1, p2, p3, *rez;
  238. {
  239. /* dump */
  240. *rez = 0;
  241. if (p1 == 0)
  242. return;
  243. a2 = p1;
  244. do {
  245. pointr(a2, &xx.sa);
  246. dump(xx.sa, a2);
  247. printf(" Another address=");
  248. scanf("%ld%*[^\n]", &a2);
  249. getchar();
  250. } while (a2 != 0);
  251. }
  252. Void use_13(p1, p2, p3, rez)
  253. long p1, p2, p3, *rez;
  254. {
  255. /* nice print */
  256. *rez = 0;
  257. if (p1 != 0)
  258. putchar('\n'); /* dout(p1);*/
  259. }
  260. Void use_12(p1, p2, p3, rez)
  261. long p1, p2, p3, *rez;
  262. {
  263. *rez = 0;
  264. /* nice print */
  265. if (p1 != 0)
  266. fprintf(out, "\n\n"); /*dout2(p1);*/
  267. }
  268. Void use_19(p1, p2, p3, rez)
  269. long p1, p2, p3, *rez;
  270. {
  271. *rez = 0;
  272. }
  273. Void use_20(p1, p2, p3, rez)
  274. long p1, p2, p3, *rez;
  275. {
  276. /*random*/
  277. *rez = 0;
  278. }
  279. Void use_21(p1, p2, p3, rez)
  280. long p1, p2, p3, *rez;
  281. {
  282. /* atom->number, others->null */
  283. *rez = 0;
  284. if (!plstr(p1, str_, &l, true, sv1))
  285. return;
  286. /* if (sv1[l]='l') or (sv1[l]='L')
  287. then sv1:=substr(sv1,1,l-1);*/
  288. /*substr*/
  289. val(sv1, im, &l);
  290. if (l == 0)
  291. *rez = long_to_atom(im[0]);
  292. }
  293. a erlist;
  294. /* used to leave error message list in usepas after scaner
  295. return it to another usepas call later - when it will
  296. be retrieved */
  297. Void use_35(p1, p2, p3, rez)
  298. long p1, p2, p3, *rez;
  299. {
  300. /* scaner receives data from file */
  301. /* format #call_pas(35 $dos_filename [ $options ]) */
  302. /* returns null if file does not exist */
  303. erlist = 0;
  304. *rez = 0;
  305. if (!plstr(p1, str_, &l, true, sv1)) /* file name */
  306. return;
  307. if (!plstr(p2, str_, &l, true, sv2)) /* options */
  308. *sv2 = '\0';
  309. initialize_scan_variables();
  310. scaner(1L, sv1, sv2, rez, &erlist, (long)null_, 0L, 0L);
  311. }
  312. Void use_121(p1, p2, p3, rez)
  313. long p1, p2, p3, *rez;
  314. {
  315. /* scaner receives data from file */
  316. /* format #call_pas(121 $mif_filename [ $options ]) */
  317. /* returns null if file does not exist */
  318. erlist = 0;
  319. *rez = 0;
  320. if (!plstr(p1, str_, &l, true, sv1)) /* file name */
  321. return;
  322. if (!plstr(p2, str_, &l, true, sv2)) /* options */
  323. *sv2 = '\0';
  324. initialize_scan_variables_mif();
  325. scaner_mif(1L, sv1, sv2, rez, &erlist, (long)null_, 0L, 0L);
  326. }
  327. Void use_36(p1, p2, p3, rez)
  328. long p1, p2, p3, *rez;
  329. {
  330. /* scaner receives data from list of strings,
  331. numbers and complex structures in the input list are ignored */
  332. /* format #call_pas(36 $list [$options] ) */
  333. *rez = 0;
  334. erlist = 0;
  335. if (!plstr(p2, str_, &l, true, sv2)) /* options */
  336. *sv2 = '\0';
  337. initialize_scan_variables();
  338. scaner(2L, "", sv2, rez, &erlist, p1, 0L, 0L);
  339. }
  340. Void use_38(p1, p2, p3, rez)
  341. long p1, p2, p3, *rez;
  342. {
  343. /* returns error message list,
  344. produced after last call of "scaner" */
  345. *rez = erlist;
  346. }
  347. Void use_40(p1, p2, p3, rez)
  348. long p1, p2, p3, *rez;
  349. {
  350. /* any -> s-address */
  351. numberdescriptor *WITH;
  352. gets1(rez, &xx.sa);
  353. WITH = xx.snd;
  354. WITH->dtype = number;
  355. WITH->cord = 0;
  356. WITH->val = p1;
  357. }
  358. Void use_41(p1, p2, p3, rez)
  359. long p1, p2, p3, *rez;
  360. {
  361. /* returns current s-address */
  362. numberdescriptor *WITH;
  363. gets1(rez, &xx.sa);
  364. WITH = xx.snd;
  365. WITH->dtype = number;
  366. WITH->cord = 0;
  367. WITH->val = *rez;
  368. }
  369. Void use_44(p1, p2, p3, rez)
  370. long p1, p2, p3, *rez;
  371. {
  372. /* sets coordinate to atom */
  373. *rez = 0;
  374. if (!plnum(p2, im))
  375. goto _L1;
  376. if (p1 != 0) {
  377. *rez = p1;
  378. a2 = p1;
  379. points(a2, &xx.sa);
  380. if (((1L << ((long)xx.sad->dtype)) & ((1L << ((long)fatom + 1)) -
  381. (1L << ((long)atom))) & (~(1L << ((long)number)))) != 0)
  382. xx.sad->cord = im[0];
  383. else if (xx.snd->dtype == number)
  384. xx.snd->cord = im[0];
  385. }
  386. _L1: ;
  387. }
  388. Void use_45(p1, p2, p3, rez)
  389. long p1, p2, p3, *rez;
  390. {
  391. reopen(rez, &p1);
  392. /* removes all s-space saving only this p1 value in result;
  393. all variables after that moment will have wrong values */
  394. /* this not allowed in interpreter ! */
  395. }
  396. Void use_46(p1, p2, p3, rez)
  397. long p1, p2, p3, *rez;
  398. {
  399. *rez = null_;
  400. } /* returns null if we are in compiler */
  401. Void use_9(p1, p2, p3, rez)
  402. long p1, p2, p3, *rez;
  403. {
  404. *rez = 0;
  405. }
  406. Void use_85(p1, p2, p3, rez)
  407. long p1, p2, p3, *rez;
  408. {
  409. /* upcase */
  410. long FORLIM;
  411. *rez = 0;
  412. if (!plstr(p1, str_, &l, true, sv1))
  413. return;
  414. FORLIM = strlen(sv1);
  415. for (j = 1; j <= FORLIM; j++) {
  416. if (islower(sv1[j - 1]))
  417. sv1[j - 1] -= 32;
  418. }
  419. *rez = str_to_textatom(sv1);
  420. }
  421. Void use_86(p1, p2, p3, rez)
  422. long p1, p2, p3, *rez;
  423. {
  424. /* locase */
  425. long FORLIM;
  426. *rez = 0;
  427. if (!plstr(p1, str_, &l, true, sv1))
  428. return;
  429. FORLIM = strlen(sv1);
  430. for (j = 1; j <= FORLIM; j++) {
  431. if (isupper(sv1[j - 1]))
  432. sv1[j - 1] += 32;
  433. }
  434. *rez = str_to_textatom(sv1);
  435. }
  436. Void use_87(p1, p2, p3, rez)
  437. long p1, p2, p3, *rez;
  438. {
  439. /* substr */
  440. Char STR1[256];
  441. *rez = 0;
  442. if (!plstr(p1, str_, &l, true, sv1))
  443. return;
  444. if (plnum(p2, im)) {
  445. if (!plnum(p3, &im[1]))
  446. im[1] = l;
  447. }
  448. sprintf(STR1, "%.*s", (int)im[1], sv1 + im[0] - 1);
  449. *rez = str_to_textatom(STR1);
  450. }
  451. Void use_88(p1, p2, p3, rez)
  452. long p1, p2, p3, *rez;
  453. { char * tmp;
  454. /* position */
  455. *rez = 0;
  456. if (plstr(p1, str_, &l, true, sv1)) {
  457. if (plstr(p2, str_, &l, true, sv2))
  458. { tmp=strstr(sv2,sv1);
  459. *rez = long_to_atom((long) (tmp?((long)tmp-(long)sv1):0) );}
  460. }
  461. }
  462. Void use_90(p1, p2, p3, rez)
  463. long p1, p2, p3, *rez;
  464. {
  465. long iii;
  466. /* if plnum(p2,im[1]) then hlt:=im[1] else hlt:=0; */
  467. for (iii = 0; iii < filenum; iii++) {
  468. if (filetab[iii].isopen) {
  469. if (filetab[iii].screen)
  470. putchar('\n'); /* Corrected 29/5/95 */
  471. else
  472. {putc('\n', files[iii]);
  473. if (files[iii] != NULL)
  474. fclose(files[iii]);}
  475. files[iii] = NULL;
  476. }
  477. }
  478. if (out_open) {
  479. if (out != NULL)
  480. fclose(out);
  481. out = NULL;
  482. }
  483. closea();
  484. closes();
  485. exit(0);
  486. }
  487. Void use_78(p1, p2, p3, rez)
  488. long p1, p2, p3, *rez;
  489. {
  490. if (plnum(p1, im))
  491. max_printlevel = im[0];
  492. }
  493. Void use_79(p1, p2, p3, rez)
  494. long p1, p2, p3, *rez;
  495. {
  496. boolean is_tree;
  497. ptr_ ap;
  498. longint elnum;
  499. atomdescriptor *WITH;
  500. *rez = null_;
  501. first(p1, &ap);
  502. is_tree = (ap.ptrtype == ptrtree);
  503. elnum = 0;
  504. while (ap.nel != 0) {
  505. elnum++;
  506. if (eqatoms(ap.cel, p2))
  507. goto _L22;
  508. next(&ap);
  509. }
  510. return;
  511. _L22:
  512. if (!is_tree) {
  513. *rez = long_to_atom(elnum);
  514. return;
  515. }
  516. gets1(rez, &xx.sa); /* makes s-address */
  517. /* fills descriptor */
  518. WITH = xx.sad; /* with */
  519. WITH->dtype = idatom;
  520. WITH->name = ap.UU.U1.arc;
  521. }
  522. Void use_91(p1, p2, p3, rez)
  523. long p1, p2, p3, *rez;
  524. {
  525. /* for lists - modifies list descriptor and
  526. makes it 1 element shorter by deleting ladst element ;
  527. returns the argument.
  528. if length of list is 1 or 0 then this function returns null,
  529. but list descriptor is not modified (!!!)
  530. if argument is not list then returns null.
  531. e.g.
  532. $a:=(.a.)
  533. #call_pas(91 $a) returns null , but $a retain (.a.)
  534. $a:=(.a b.)
  535. #call_pas(91 $a) returns (.a.), and $a is (.a.)
  536. */
  537. ptr_ ap;
  538. longint len, i;
  539. *rez = null_;
  540. points(p1, &xx.sa);
  541. if (xx.smld->dtype != listmain)
  542. return;
  543. len = xx.smld->totalelnum;
  544. if (len == 1 || len == 0)
  545. return;
  546. first(p1, &ap);
  547. for (i = 1; i <= len - 2; i++)
  548. next(&ap);
  549. /* we are standing on the last element of future list */
  550. /* the next elements (or descriptor) are to cut off,
  551. we split to 4 cases main/fragm element/descriptor */
  552. *rez = p1;
  553. points(ap.UU.U1.curfragment, &xx.sa);
  554. if (xx.smld->dtype == listmain) {
  555. if (ap.nel == mainlistelnum) {
  556. xx.smld->next = null_;
  557. xx.smld->lastfragm = ap.UU.U1.curfragment;
  558. /* correction 8-apr-1993 */
  559. } else
  560. xx.smld->elnum--;
  561. xx.smld->totalelnum--;
  562. return;
  563. }
  564. if (ap.nel == fragmlistelnum) {
  565. xx.sfld->next = null_;
  566. points(p1, &xx.sa);
  567. xx.smld->lastfragm = ap.UU.U1.curfragment;
  568. /* correction 8-apr-1993 */
  569. } else
  570. xx.sfld->elnum--;
  571. points(p1, &xx.sa);
  572. xx.smld->totalelnum--;
  573. }
  574. Static long selection(tree, arc)
  575. long tree, arc;
  576. {
  577. long Result;
  578. ptr_ ap;
  579. Result = null_;
  580. first(tree, &ap);
  581. if (ap.ptrtype != ptrtree)
  582. return Result;
  583. while (ap.nel != null_ && ap.UU.U1.arc != arc)
  584. next(&ap);
  585. if (ap.UU.U1.arc == arc)
  586. return (ap.cel);
  587. return Result;
  588. }
  589. Static long indexing(list, index)
  590. long list, index;
  591. {
  592. long Result;
  593. ptr_ ap;
  594. longint maxind, i;
  595. Result = null_;
  596. first(list, &ap);
  597. if (ap.ptrtype != ptrlist)
  598. return Result;
  599. pointr(list, &xx.sa);
  600. maxind = xx.smld->totalelnum;
  601. if (index < -maxind || index == 0 || index > maxind)
  602. return Result;
  603. if (index < 0)
  604. index += maxind + 1;
  605. for (i = 1; i < index; i++)
  606. next(&ap);
  607. return (ap.cel);
  608. }
  609. Void use_92(p1, p2, p3, rez)
  610. long p1, p2, p3, *rez;
  611. {
  612. /* traverses list "p1".
  613. if element is a number then index is applied to "p2"
  614. if element is an atom the selection ia applied to "p2" */
  615. ptr_ ap;
  616. *rez = p2;
  617. first(p1, &ap);
  618. if (ap.ptrtype != ptrlist) {
  619. *rez = null_;
  620. return;
  621. }
  622. while (ap.nel != null_) {
  623. pointr(ap.cel, &xx.sa);
  624. if (xx.snd->dtype == number)
  625. *rez = indexing(*rez, xx.snd->val);
  626. else if (xx.sad->dtype == idatom)
  627. *rez = selection(*rez, xx.sad->name);
  628. else
  629. *rez = null_;
  630. if (*rez == null_)
  631. return;
  632. next(&ap);
  633. }
  634. }
  635. Void use_93(p1, p2, p3, rez)
  636. long p1, p2, p3, *rez;
  637. {
  638. /* returns stack size*/
  639. *rez = 0;
  640. }
  641. Void use_108(p1, p2, p3, rez)
  642. long p1, p2, p3, *rez;
  643. {
  644. /* get environment variable ;
  645. requires variable name(string)
  646. returns null if absent
  647. or value (converted to number if possible) */
  648. string80 pc;
  649. *rez = 0;
  650. if (plstr(p1, str_, &l, true, sv1)) {
  651. *rez = str_to_atom(getenv(sv1));
  652. }
  653. }
  654. Void use_110(p1, p2, p3, rez)
  655. long p1, p2, p3, *rez;
  656. {
  657. *rez = 0;
  658. }
  659. Void use_111(p1, p2, p3, rez)
  660. long p1, p2, p3, *rez;
  661. {
  662. *rez = 0;
  663. }
  664. Void use_116(p1, p2, p3, rez)
  665. long p1, p2, p3, *rez;
  666. {
  667. /* returns c-string value 'a"bc\n' -> '"abc\\m\"' */
  668. long i, FORLIM;
  669. *rez = 0;
  670. if (!plstr(p1, str_, &l, true, sv1))
  671. return;
  672. strcpy(sv2, "\"");
  673. FORLIM = l;
  674. for (i = 0; i < FORLIM; i++) {
  675. if (sv1[i] == '\\' || sv1[i] == '"')
  676. strcat(sv2, "\\");
  677. sprintf(sv2 + strlen(sv2), "%c", sv1[i]);
  678. }
  679. strcat(sv2, "\"");
  680. *rez = str_to_atom(sv2);
  681. }
  682. /* floating point processor */
  683. Void use_80(p1, p2, p3, rez)
  684. long p1, p2, p3, *rez;
  685. {
  686. long real_size;
  687. long i;
  688. double re1, re2, re3;
  689. Char c1, c2_;
  690. mpd x;
  691. double *refr2, *refr3;
  692. numberdescriptor *WITH;
  693. atomdescriptor *WITH1;
  694. real_size = sizeof(double);
  695. *rez = 0; /* in case of unsuccessful data returns null */
  696. if (!plstr(p1, str1_, &l, false, sv1))
  697. goto _L1;
  698. c1 = str1_[0];
  699. if (l > 1 )
  700. c2_ = str1_[1];
  701. else
  702. c2_ = ' ';
  703. switch (c1) { /*1*/
  704. case 'S': /* string -> real */
  705. if (!plstr(p2, str_, &l, true, sv1))
  706. goto _L1;
  707. val2(sv1, &re1, &i);
  708. if (i != 0)
  709. goto _L1;
  710. break;
  711. case 'I': /*2*/
  712. /* integer -> real */
  713. if (!plnum(p2, &im[1]))
  714. goto _L1;
  715. re1 = im[1]; /* *1.0 */
  716. break;
  717. /* real -> ... */
  718. default:
  719. if (!plstr(p2, str_, &l, false, sv1))
  720. goto _L1;
  721. if (l != real_size)
  722. goto _L1;
  723. refr2 = (double *)str_;
  724. /* re2 = *refr2; */
  725. memcpy(&re2,refr2,sizeof(double));
  726. switch (c1) { /*3*/
  727. case 'T':
  728. im[2] = (long)re2;
  729. gets1(rez, &x.sa);
  730. WITH = x.snd;
  731. WITH->dtype = number;
  732. WITH->val = im[2];
  733. goto _L1;
  734. break;
  735. case 'Z': /*4*/
  736. if (!plnum(p3, &im[1]))
  737. goto _L1;
  738. real_to_string_f(svar, re2, im[1] / 100, im[1] % 100);
  739. /* p2c: ./use80.pas, line 48:
  740. * Note: Using % for possibly-negative arguments [317] */
  741. i = strlen(svar);
  742. putatm(svar, i, &atm);
  743. gets1(rez, &x.sa);
  744. WITH1 = x.sad;
  745. WITH1->dtype = atom;
  746. WITH1->name = atm;
  747. goto _L1;
  748. break;
  749. case 'V': /*4*/
  750. sprintf(svar,"%E",re2);
  751. i = strlen(svar);
  752. putatm(svar, i, &atm);
  753. gets1(rez, &x.sa);
  754. WITH1 = x.sad;
  755. WITH1->dtype = atom;
  756. WITH1->name = atm;
  757. goto _L1;
  758. break;
  759. case 'F':
  760. if (!plstr(p3, str_, &l, true, sv1))
  761. goto _L1;
  762. sprintf(svar,sv1,re2);
  763. i = strlen(svar);
  764. putatm(svar, i, &atm);
  765. gets1(rez, &x.sa);
  766. WITH1 = x.sad;
  767. WITH1->dtype = atom;
  768. WITH1->name = atm;
  769. goto _L1;
  770. break;
  771. case 'Q': if (re2>0) re1=sqrt(re2); else goto _L1; break;
  772. case 'X': re1=exp(re2); break;
  773. case 'L': if (re2>0) re1=log(re2); else goto _L1; break;
  774. case 't':
  775. if (!strncmp("tSIN",str1_,4)) re1=sin(re2);
  776. else if (!strncmp("tCOS",str1_,4)) re1=cos(re2);
  777. else if (!strncmp("tTAN",str1_,4)) re1=tan(re2);
  778. else if (!strncmp("tASIN",str1_,5)) re1=asin(re2);
  779. else if (!strncmp("tACOS",str1_,5)) re1=acos(re2);
  780. else if (!strncmp("tATAN",str1_,5)) re1=atan(re2);
  781. break;
  782. default:
  783. if (!plstr(p3, str_, &l, false, sv1))
  784. goto _L1;
  785. if (l != real_size)
  786. goto _L1;
  787. refr3 = (double *)str_;
  788. /* re3 = *refr3; */
  789. memcpy(&re3,refr3,sizeof(double));
  790. switch (c1) { /*5*/
  791. case '+':
  792. re1 = re2 + re3;
  793. break;
  794. case '-':
  795. re1 = re2 - re3;
  796. break;
  797. case '*':
  798. re1 = re2 * re3;
  799. break;
  800. case '/':
  801. if (re3 == 0)
  802. goto _L1;
  803. re1 = re2 / re3;
  804. break;
  805. case '=':
  806. if (re2 == re3)
  807. *rez = p2;
  808. goto _L1;
  809. break;
  810. case '>':
  811. if (c2_ == '=') {
  812. if (re2 >= re3)
  813. *rez = p2;
  814. } else {
  815. if (re2 > re3)
  816. *rez = p2;
  817. }
  818. goto _L1;
  819. break;
  820. case '<':
  821. if (c2_ == '=') {
  822. if (re2 <= re3)
  823. *rez = p2;
  824. } else if (c2_ == '>') {
  825. if (re2 != re3)
  826. *rez = p2;
  827. } else if (re2 < re3)
  828. *rez = p2;
  829. goto _L1;
  830. break;
  831. case 'P':
  832. re1=pow(re2,re3); break;
  833. default: /* wrong real operation */
  834. goto _L1;
  835. break;
  836. }/*5*/
  837. /*4*/
  838. break;
  839. }/*3*/
  840. /*2*/
  841. break;
  842. }/*1*/
  843. /* this part processes only + - * / s(str->real) i(int->real) */
  844. refr2 = (double *)svar;
  845. /* *refr2 = re1; */
  846. memcpy(refr2,&re1,sizeof(double));
  847. putatm(svar, real_size, &atm);
  848. gets1(rez, &x.sa);
  849. WITH1 = x.sad;
  850. WITH1->dtype = fatom;
  851. WITH1->name = atm;
  852. _L1: ;
  853. }
  854. /* these procedures currently are used in ibm/pc version
  855. of rigal. don't use them for future compatibility */
  856. Void use_2(p1, p2, p3, rez)
  857. long p1, p2, p3, *rez;
  858. {
  859. }
  860. Void use_3(p1, p2, p3, rez)
  861. long p1, p2, p3, *rez;
  862. {
  863. }
  864. Void use_5(p1, p2, p3, rez)
  865. long p1, p2, p3, *rez;
  866. {
  867. }
  868. Void use_6(p1, p2, p3, rez)
  869. long p1, p2, p3, *rez;
  870. {
  871. }
  872. Void use_7(p1, p2, p3, rez)
  873. long p1, p2, p3, *rez;
  874. {
  875. }
  876. Void use_8(p1, p2, p3, rez)
  877. long p1, p2, p3, *rez;
  878. {
  879. }
  880. Void use_11(p1, p2, p3, rez)
  881. long p1, p2, p3, *rez;
  882. {
  883. }
  884. Void use_17(p1, p2, p3, rez)
  885. long p1, p2, p3, *rez;
  886. {
  887. }
  888. Void use_18(p1, p2, p3, rez)
  889. long p1, p2, p3, *rez;
  890. {
  891. }
  892. Void use_22(p1, p2, p3, rez)
  893. long p1, p2, p3, *rez;
  894. {
  895. }
  896. Void use_23(p1, p2, p3, rez)
  897. long p1, p2, p3, *rez;
  898. {
  899. }
  900. Void use_24(p1, p2, p3, rez)
  901. long p1, p2, p3, *rez;
  902. {
  903. }
  904. Void use_25(p1, p2, p3, rez)
  905. long p1, p2, p3, *rez;
  906. {
  907. }
  908. Void use_26(p1, p2, p3, rez)
  909. long p1, p2, p3, *rez;
  910. {
  911. }
  912. Void use_27(p1, p2, p3, rez)
  913. long p1, p2, p3, *rez;
  914. {
  915. }
  916. Void use_28(p1, p2, p3, rez)
  917. long p1, p2, p3, *rez;
  918. {
  919. }
  920. Void use_29(p1, p2, p3, rez)
  921. long p1, p2, p3, *rez;
  922. {
  923. }
  924. Void use_32(p1, p2, p3, rez)
  925. long p1, p2, p3, *rez;
  926. {
  927. }
  928. Void use_33(p1, p2, p3, rez)
  929. long p1, p2, p3, *rez;
  930. {
  931. }
  932. Void use_34(p1, p2, p3, rez)
  933. long p1, p2, p3, *rez;
  934. {
  935. }
  936. Void use_37(p1, p2, p3, rez)
  937. long p1, p2, p3, *rez;
  938. {
  939. }
  940. Void use_39(p1, p2, p3, rez)
  941. long p1, p2, p3, *rez;
  942. {
  943. }
  944. Void use_47(p1, p2, p3, rez)
  945. long p1, p2, p3, *rez;
  946. {
  947. }
  948. Void use_48(p1, p2, p3, rez)
  949. long p1, p2, p3, *rez;
  950. {
  951. }
  952. Void use_49(p1, p2, p3, rez)
  953. long p1, p2, p3, *rez;
  954. {
  955. }
  956. Void use_50(p1, p2, p3, rez)
  957. long p1, p2, p3, *rez;
  958. {
  959. }
  960. Void use_51(p1, p2, p3, rez)
  961. long p1, p2, p3, *rez;
  962. {
  963. }
  964. Void use_52(p1, p2, p3, rez)
  965. long p1, p2, p3, *rez;
  966. {
  967. }
  968. Void use_53(p1, p2, p3, rez)
  969. long p1, p2, p3, *rez;
  970. {
  971. }
  972. Void use_54(p1, p2, p3, rez)
  973. long p1, p2, p3, *rez;
  974. {
  975. }
  976. Void use_55(p1, p2, p3, rez)
  977. long p1, p2, p3, *rez;
  978. {
  979. }
  980. Void use_56(p1, p2, p3, rez)
  981. long p1, p2, p3, *rez;
  982. {
  983. }
  984. Void use_57(p1, p2, p3, rez)
  985. long p1, p2, p3, *rez;
  986. {
  987. }
  988. Void use_58(p1, p2, p3, rez)
  989. long p1, p2, p3, *rez;
  990. {
  991. }
  992. Void use_59(p1, p2, p3, rez)
  993. long p1, p2, p3, *rez;
  994. {
  995. }
  996. Void use_60(p1, p2, p3, rez)
  997. long p1, p2, p3, *rez;
  998. {
  999. }
  1000. Void use_61(p1, p2, p3, rez)
  1001. long p1, p2, p3, *rez;
  1002. {
  1003. }
  1004. Void use_62(p1, p2, p3, rez)
  1005. long p1, p2, p3, *rez;
  1006. {
  1007. }
  1008. Void use_63(p1, p2, p3, rez)
  1009. long p1, p2, p3, *rez;
  1010. {
  1011. }
  1012. Void use_64(p1, p2, p3, rez)
  1013. long p1, p2, p3, *rez;
  1014. {
  1015. }
  1016. Void use_65(p1, p2, p3, rez)
  1017. long p1, p2, p3, *rez;
  1018. {
  1019. }
  1020. Void use_66(p1, p2, p3, rez)
  1021. long p1, p2, p3, *rez;
  1022. {
  1023. }
  1024. Void use_67(p1, p2, p3, rez)
  1025. long p1, p2, p3, *rez;
  1026. {
  1027. }
  1028. Void use_68(p1, p2, p3, rez)
  1029. long p1, p2, p3, *rez;
  1030. {
  1031. }
  1032. Void use_69(p1, p2, p3, rez)
  1033. long p1, p2, p3, *rez;
  1034. {
  1035. }
  1036. Void use_70(p1, p2, p3, rez)
  1037. long p1, p2, p3, *rez;
  1038. {
  1039. }
  1040. Void use_71(p1, p2, p3, rez)
  1041. long p1, p2, p3, *rez;
  1042. {
  1043. }
  1044. Void use_72(p1, p2, p3, rez)
  1045. long p1, p2, p3, *rez;
  1046. {
  1047. }
  1048. Void use_73(p1, p2, p3, rez)
  1049. long p1, p2, p3, *rez;
  1050. {
  1051. }
  1052. Void use_74(p1, p2, p3, rez)
  1053. long p1, p2, p3, *rez;
  1054. {
  1055. }
  1056. Void use_75(p1, p2, p3, rez)
  1057. long p1, p2, p3, *rez;
  1058. {
  1059. }
  1060. Void use_76(p1, p2, p3, rez)
  1061. long p1, p2, p3, *rez;
  1062. {
  1063. }
  1064. Void use_77(p1, p2, p3, rez)
  1065. long p1, p2, p3, *rez;
  1066. {
  1067. }
  1068. Void use_81(p1, p2, p3, rez)
  1069. long p1, p2, p3, *rez;
  1070. {
  1071. }
  1072. Void use_82(p1, p2, p3, rez)
  1073. long p1, p2, p3, *rez;
  1074. {
  1075. }
  1076. Void use_83(p1, p2, p3, rez)
  1077. long p1, p2, p3, *rez;
  1078. {
  1079. }
  1080. Void use_84(p1, p2, p3, rez)
  1081. long p1, p2, p3, *rez;
  1082. {
  1083. }
  1084. Void use_89(p1, p2, p3, rez)
  1085. long p1, p2, p3, *rez;
  1086. {
  1087. }
  1088. Void use_94(p1, p2, p3, rez)
  1089. long p1, p2, p3, *rez;
  1090. {
  1091. }
  1092. Void use_95(p1, p2, p3, rez)
  1093. long p1, p2, p3, *rez;
  1094. {
  1095. }
  1096. Void use_96(p1, p2, p3, rez)
  1097. long p1, p2, p3, *rez;
  1098. {
  1099. }
  1100. Void use_97(p1, p2, p3, rez)
  1101. long p1, p2, p3, *rez;
  1102. {
  1103. }
  1104. Void use_98(p1, p2, p3, rez)
  1105. long p1, p2, p3, *rez;
  1106. {
  1107. }
  1108. Void use_99(p1, p2, p3, rez)
  1109. long p1, p2, p3, *rez;
  1110. {
  1111. }
  1112. Void use_100(p1, p2, p3, rez)
  1113. long p1, p2, p3, *rez;
  1114. {
  1115. }
  1116. Void use_101(p1, p2, p3, rez)
  1117. long p1, p2, p3, *rez;
  1118. {
  1119. }
  1120. Void use_102(p1, p2, p3, rez)
  1121. long p1, p2, p3, *rez;
  1122. {
  1123. }
  1124. Void use_103(p1, p2, p3, rez)
  1125. long p1, p2, p3, *rez;
  1126. {
  1127. }
  1128. Void use_104(p1, p2, p3, rez)
  1129. long p1, p2, p3, *rez;
  1130. {
  1131. }
  1132. Void use_105(p1, p2, p3, rez)
  1133. long p1, p2, p3, *rez;
  1134. {
  1135. }
  1136. Void use_106(p1, p2, p3, rez)
  1137. long p1, p2, p3, *rez;
  1138. {
  1139. }
  1140. Void use_107(p1, p2, p3, rez)
  1141. long p1, p2, p3, *rez;
  1142. {
  1143. }
  1144. Void use_109(p1, p2, p3, rez)
  1145. long p1, p2, p3, *rez;
  1146. {
  1147. }
  1148. Void use_112(p1, p2, p3, rez)
  1149. long p1, p2, p3, *rez;
  1150. {
  1151. }
  1152. Void use_113(p1, p2, p3, rez)
  1153. long p1, p2, p3, *rez;
  1154. {
  1155. }
  1156. Void use_114(p1, p2, p3, rez)
  1157. long p1, p2, p3, *rez;
  1158. {
  1159. }
  1160. Void use_115(p1, p2, p3, rez)
  1161. long p1, p2, p3, *rez;
  1162. {
  1163. }
  1164. Void use_117(p1, p2, p3, rez)
  1165. long p1, p2, p3, *rez;
  1166. {
  1167. }
  1168. Void use_118(p1, p2, p3, rez)
  1169. long p1, p2, p3, *rez;
  1170. {
  1171. }
  1172. Void use_119(p1, p2, p3, rez)
  1173. long p1, p2, p3, *rez;
  1174. {
  1175. }
  1176. /* these procedures are not used , you can use them ! */
  1177. Void use_120(p1, p2, p3, rez)
  1178. long p1, p2, p3, *rez;
  1179. {
  1180. }
  1181. Void use_122(p1, p2, p3, rez)
  1182. long p1, p2, p3, *rez;
  1183. {
  1184. }
  1185. Void use_123(p1, p2, p3, rez)
  1186. long p1, p2, p3, *rez;
  1187. {
  1188. }
  1189. Void use_124(p1, p2, p3, rez)
  1190. long p1, p2, p3, *rez;
  1191. {
  1192. }
  1193. Void use_125(p1, p2, p3, rez)
  1194. long p1, p2, p3, *rez;
  1195. {
  1196. }
  1197. Void use_126(p1, p2, p3, rez)
  1198. long p1, p2, p3, *rez;
  1199. {
  1200. }
  1201. Void use_127(p1, p2, p3, rez)
  1202. long p1, p2, p3, *rez;
  1203. {
  1204. }
  1205. Void use_128(p1, p2, p3, rez)
  1206. long p1, p2, p3, *rez;
  1207. {
  1208. }
  1209. Void use_129(p1, p2, p3, rez)
  1210. long p1, p2, p3, *rez;
  1211. {
  1212. }
  1213. Void use_130(p1, p2, p3, rez)
  1214. long p1, p2, p3, *rez;
  1215. {
  1216. }
  1217. Void use_131(p1, p2, p3, rez)
  1218. long p1, p2, p3, *rez;
  1219. {
  1220. }
  1221. Void use_132(p1, p2, p3, rez)
  1222. long p1, p2, p3, *rez;
  1223. {
  1224. }
  1225. Void use_133(p1, p2, p3, rez)
  1226. long p1, p2, p3, *rez;
  1227. {
  1228. }
  1229. Void use_134(p1, p2, p3, rez)
  1230. long p1, p2, p3, *rez;
  1231. {
  1232. }
  1233. Void use_135(p1, p2, p3, rez)
  1234. long p1, p2, p3, *rez;
  1235. {
  1236. }
  1237. Void use_136(p1, p2, p3, rez)
  1238. long p1, p2, p3, *rez;
  1239. {
  1240. }
  1241. Void use_137(p1, p2, p3, rez)
  1242. long p1, p2, p3, *rez;
  1243. {
  1244. }
  1245. Void use_138(p1, p2, p3, rez)
  1246. long p1, p2, p3, *rez;
  1247. {
  1248. }
  1249. Void use_139(p1, p2, p3, rez)
  1250. long p1, p2, p3, *rez;
  1251. {
  1252. }
  1253. Void use_140(p1, p2, p3, rez)
  1254. long p1, p2, p3, *rez;
  1255. {
  1256. }
  1257. Void use_141(p1, p2, p3, rez)
  1258. long p1, p2, p3, *rez;
  1259. {
  1260. }
  1261. Void use_142(p1, p2, p3, rez)
  1262. long p1, p2, p3, *rez;
  1263. {
  1264. }
  1265. Void use_143(p1, p2, p3, rez)
  1266. long p1, p2, p3, *rez;
  1267. {
  1268. }
  1269. Void use_144(p1, p2, p3, rez)
  1270. long p1, p2, p3, *rez;
  1271. {
  1272. }
  1273. Void use_145(p1, p2, p3, rez)
  1274. long p1, p2, p3, *rez;
  1275. {
  1276. }
  1277. Void use_146(p1, p2, p3, rez)
  1278. long p1, p2, p3, *rez;
  1279. {
  1280. }
  1281. Void use_147(p1, p2, p3, rez)
  1282. long p1, p2, p3, *rez;
  1283. {
  1284. }
  1285. Void use_148(p1, p2, p3, rez)
  1286. long p1, p2, p3, *rez;
  1287. {
  1288. }
  1289. Void use_149(p1, p2, p3, rez)
  1290. long p1, p2, p3, *rez;
  1291. {
  1292. }
  1293. Void use_150(p1, p2, p3, rez)
  1294. long p1, p2, p3, *rez;
  1295. {
  1296. }
  1297. /* End. */