rprint.red 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. COMMENT MODULE RPRINT;
  2. COMMENT THE STANDARD LISP TO REDUCE PRETTY PRINTER;
  3. FLUID '(PRETOP PRETOPRINF);
  4. PRETOP := 'OP; PRETOPRINF := 'OPRINF;
  5. FLUID '(COMBUFF);
  6. FLUID '(CURMARK BUFFP RMAR !*N);
  7. SYMBOLIC PROCEDURE RPRINT U;
  8. BEGIN INTEGER !*N; SCALAR BUFF,BUFFP,CURMARK,RMAR,X;
  9. CURMARK := 0;
  10. BUFF := BUFFP := LIST LIST(0,0);
  11. RMAR := LINELENGTH NIL;
  12. X := GET('!*SEMICOL!*,PRETOP);
  13. !*N := 0;
  14. MPRINO1(U,LIST(CAAR X,CADAR X));
  15. PRIN2OX ";";
  16. OMARKO CURMARK;
  17. PRINOS BUFF
  18. END;
  19. SYMBOLIC PROCEDURE RPRIN1 U;
  20. BEGIN SCALAR BUFF,BUFFP,CURMARK,X;
  21. CURMARK := 0;
  22. BUFF := BUFFP := LIST LIST(0,0);
  23. X := GET('!*SEMICOL!*,PRETOP);
  24. MPRINO1(U,LIST(CAAR X,CADAR X));
  25. OMARKO CURMARK;
  26. PRINOS BUFF
  27. END;
  28. SYMBOLIC PROCEDURE MPRINO U; MPRINO1(U,LIST(0,0));
  29. SYMBOLIC PROCEDURE MPRINO1(U,V);
  30. BEGIN SCALAR X;
  31. IF X := ATSOC(U,COMBUFF)
  32. THEN <<FOR EACH Y IN CDR X DO COMPROX Y;
  33. COMBUFF := DELETE(X,COMBUFF)>>;
  34. IF NUMBERP U AND U<0 AND (X := GET('DIFFERENCE,PRETOP))
  35. THEN RETURN BEGIN SCALAR P;
  36. X := CAR X;
  37. P := (NOT CAR X>CADR V) OR (NOT CADR X>CAR V);
  38. IF P THEN PRIN2OX "(";
  39. PRINOX U;
  40. IF P THEN PRINOX ")"
  41. END
  42. ELSE IF ATOM U THEN RETURN PRINOX U
  43. ELSE IF NOT ATOM CAR U
  44. THEN <<CURMARK := CURMARK+1;
  45. PRIN2OX "("; MPRINO CAR U; PRIN2OX ")";
  46. OMARK LIST(CURMARK,3); CURMARK := CURMARK-1>>
  47. ELSE IF X := GET(CAR U,PRETOPRINF)
  48. THEN RETURN BEGIN SCALAR P;
  49. P := CAR V>0 AND NOT CAR U MEMQ '(BLOCK PROG QUOTE STRING);
  50. IF P THEN PRIN2OX "(";
  51. APPLY(X,LIST CDR U);
  52. IF P THEN PRIN2OX ")"
  53. END
  54. ELSE IF X := GET(CAR U,PRETOP)
  55. THEN RETURN IF CAR X THEN INPRINOX(U,CAR X,V)
  56. ELSE IF CDDR U THEN REDERR "Syntax error"
  57. ELSE IF NULL CADR X THEN INPRINOX(U,LIST(100,1),V)
  58. ELSE INPRINOX(U,LIST(100,CADR X),V)
  59. ELSE PRINOX CAR U;
  60. IF RLISTATP CAR U THEN RETURN RLPRI(CDR U,V);
  61. U := CDR U;
  62. IF NULL U THEN PRIN2OX "()"
  63. ELSE MPRARGS(U,V)
  64. END;
  65. SYMBOLIC PROCEDURE MPRARGS(U,V);
  66. IF NULL CDR U THEN <<PRIN2OX " "; MPRINO1(CAR U,LIST(100,100))>>
  67. ELSE INPRINOX('!*COMMA!* . U,LIST(0,0),V);
  68. SYMBOLIC PROCEDURE INPRINOX(U,X,V);
  69. BEGIN SCALAR P;
  70. P := (NOT CAR X>CADR V) OR (NOT CADR X>CAR V);
  71. IF P THEN PRIN2OX "("; OMARK '(M U);
  72. INPRINO(CAR U,X,CDR U);
  73. IF P THEN PRIN2OX ")"; OMARK '(M D)
  74. END;
  75. SYMBOLIC PROCEDURE INPRINO(OPR,V,L);
  76. BEGIN SCALAR FLG,X;
  77. CURMARK := CURMARK+2;
  78. X := GET(OPR,PRETOP);
  79. IF X AND CAR X
  80. THEN <<MPRINO1(CAR L,LIST(CAR V,0)); L := CDR L; FLG := T>>;
  81. WHILE L DO
  82. <<IF OPR EQ '!*COMMA!* THEN <<PRIN2OX ","; OMARKO CURMARK>>
  83. ELSE IF OPR EQ 'SETQ
  84. THEN <<PRIN2OX " := "; OMARK LIST(CURMARK,1)>>
  85. ELSE IF ATOM CAR L OR NOT OPR EQ GET!*(CAAR L,'ALT)
  86. THEN <<OMARK LIST(CURMARK,1); OPRINO(OPR,FLG); FLG := T>>;
  87. MPRINO1(CAR L,LIST(IF NULL CDR L THEN 0 ELSE CAR V,
  88. IF NULL FLG THEN 0 ELSE CADR V));
  89. L := CDR L>>;
  90. CURMARK := CURMARK-2
  91. END;
  92. SYMBOLIC PROCEDURE OPRINO(OPR,B);
  93. (LAMBDA X; IF NULL X
  94. THEN <<IF B THEN PRIN2OX " "; PRINOX OPR; PRIN2OX " ">>
  95. ELSE PRIN2OX CAR X)
  96. GET(OPR,'PRTCH);
  97. SYMBOLIC PROCEDURE PRIN2OX U;
  98. <<RPLACD(BUFFP,EXPLODE2 U);
  99. WHILE CDR BUFFP DO BUFFP := CDR BUFFP>>;
  100. SYMBOLIC PROCEDURE PRINOX U;
  101. <<RPLACD(BUFFP,EXPLODE U);
  102. WHILE CDR BUFFP DO BUFFP := CDR BUFFP>>;
  103. SYMBOLIC PROCEDURE GET!*(U,V);
  104. IF NUMBERP U THEN NIL ELSE GET(U,V);
  105. SYMBOLIC PROCEDURE OMARK U;
  106. <<RPLACD(BUFFP,LIST U); BUFFP := CDR BUFFP>>;
  107. SYMBOLIC PROCEDURE OMARKO U; OMARK LIST(U,0);
  108. SYMBOLIC PROCEDURE COMPROX U;
  109. BEGIN SCALAR X;
  110. IF CAR BUFFP = '(0 0)
  111. THEN RETURN <<FOR EACH J IN U DO PRIN2OX J;
  112. OMARK '(0 0)>>;
  113. X := CAR BUFFP;
  114. RPLACA(BUFFP,LIST(CURMARK+1,3));
  115. FOR EACH J IN U DO PRIN2OX J;
  116. OMARK X
  117. END;
  118. SYMBOLIC PROCEDURE RLISTATP U;
  119. GET(U,'STAT) MEMBER '(ENDSTAT RLIS);
  120. SYMBOLIC PROCEDURE RLPRI(U,V);
  121. IF NULL U THEN NIL
  122. ELSE BEGIN
  123. PRIN2OX " ";
  124. OMARK '(M U);
  125. INPRINO('!*COMMA!*,LIST(0,0),U);
  126. OMARK '(M D)
  127. END;
  128. SYMBOLIC PROCEDURE CONDOX U;
  129. BEGIN SCALAR X;
  130. OMARK '(M U);
  131. CURMARK := CURMARK+2;
  132. WHILE U DO
  133. <<PRIN2OX "IF "; MPRINO CAAR U; OMARK LIST(CURMARK,1);
  134. PRIN2OX " THEN ";
  135. IF CDR U AND EQCAR(CADAR U,'COND)
  136. AND NOT EQCAR(CAR REVERSE CADAR U,'T)
  137. THEN <<X := T; PRIN2OX "(">>;
  138. MPRINO CADAR U;
  139. IF X THEN PRIN2OX ")";
  140. U := CDR U;
  141. IF U THEN <<OMARKO(CURMARK-1); PRIN2OX " ELSE ">>;
  142. IF U AND NULL CDR U AND CAAR U EQ 'T
  143. THEN <<MPRINO CADAR U; U := NIL>>>>;
  144. CURMARK := CURMARK-2;
  145. OMARK '(M D)
  146. END;
  147. PUT('COND,PRETOPRINF,'CONDOX);
  148. SYMBOLIC PROCEDURE BLOCKOX U;
  149. BEGIN
  150. OMARK '(M U);
  151. CURMARK := CURMARK+2;
  152. PRIN2OX "BEGIN ";
  153. IF CAR U THEN VARPRX CAR U;
  154. U := LABCHK CDR U;
  155. OMARK LIST(CURMARK,IF EQCAR(CAR U,'!*LABEL) THEN 1 ELSE 3);
  156. WHILE U DO
  157. <<MPRINO CAR U;
  158. IF NOT EQCAR(CAR U,'!*LABEL) AND CDR U THEN PRIN2OX "; ";
  159. U := CDR U;
  160. IF U
  161. THEN OMARK LIST(CURMARK,
  162. IF EQCAR(CAR U,'!*LABEL) THEN 1 ELSE 3)>>;
  163. OMARK LIST(CURMARK-1,-1);
  164. PRIN2OX " END";
  165. CURMARK := CURMARK-2;
  166. OMARK '(M D)
  167. END;
  168. SYMBOLIC PROCEDURE RETOX U;
  169. BEGIN
  170. OMARK '(M U);
  171. CURMARK := CURMARK+2;
  172. PRIN2OX "RETURN ";
  173. OMARK '(M U);
  174. MPRINO CAR U;
  175. CURMARK := CURMARK-2;
  176. OMARK '(M D);
  177. OMARK '(M D)
  178. END;
  179. PUT('RETURN,PRETOPRINF,'RETOX);
  180. SYMBOLIC PROCEDURE VARPRX U;
  181. MAPC(CDR U,FUNCTION (LAMBDA J;
  182. <<PRIN2OX CAR J;
  183. PRIN2OX " ";
  184. INPRINO('!*COMMA!*,LIST(0,0),CDR J);
  185. PRIN2OX "; ";
  186. OMARK LIST(CURMARK,6)>>));
  187. COMMENT a version for the old parser;
  188. SYMBOLIC PROCEDURE VARPRX U;
  189. BEGIN SCALAR TYP;
  190. U := REVERSE U;
  191. WHILE U DO
  192. <<IF CDAR U EQ TYP
  193. THEN <<PRIN2OX ","; OMARKO(CURMARK+1); PRINOX CAAR U>>
  194. ELSE <<IF TYP THEN <<PRIN2OX "; "; OMARK '(M D)>>;
  195. PRINOX (TYP := CDAR U);
  196. PRIN2OX " "; OMARK '(M U); PRINOX CAAR U>>;
  197. U := CDR U>>;
  198. PRIN2OX "; ";
  199. OMARK '(M D)
  200. END;
  201. PUT('BLOCK,PRETOPRINF,'BLOCKOX);
  202. SYMBOLIC PROCEDURE PROGOX U;
  203. BLOCKOX(MAPCAR(REVERSE CAR U,FUNCTION (LAMBDA J; J . 'SCALAR))
  204. . CDR U);
  205. SYMBOLIC PROCEDURE LABCHK U;
  206. BEGIN SCALAR X;
  207. FOR EACH Z IN U DO IF ATOM Z
  208. THEN X := LIST('!*LABEL,Z) . X ELSE X := Z . X;
  209. RETURN REVERSIP X
  210. END;
  211. PUT('PROG,PRETOPRINF,'PROGOX);
  212. SYMBOLIC PROCEDURE GOX U;
  213. <<PRIN2OX "GO TO "; PRINOX CAR U>>;
  214. PUT('GO,PRETOPRINF,'GOX);
  215. SYMBOLIC PROCEDURE LABOX U;
  216. <<PRINOX CAR U; PRIN2OX ": ">>;
  217. PUT('!*LABEL,PRETOPRINF,'LABOX);
  218. SYMBOLIC PROCEDURE QUOTOX U;
  219. IF STRINGP U THEN PRINOX U ELSE <<PRIN2OX "'"; PRINSOX CAR U>>;
  220. SYMBOLIC PROCEDURE PRINSOX U;
  221. IF ATOM U THEN PRINOX U
  222. ELSE <<PRIN2OX "(";
  223. OMARK '(M U);
  224. CURMARK := CURMARK+1;
  225. WHILE U DO <<PRINSOX CAR U;
  226. U := CDR U;
  227. IF U THEN <<OMARK LIST(CURMARK,-1);
  228. IF ATOM U
  229. THEN <<PRIN2OX " . "; PRINSOX U; U := NIL>>
  230. ELSE PRIN2OX " ">>>>;
  231. CURMARK := CURMARK-1;
  232. OMARK '(M D);
  233. PRIN2OX ")">>;
  234. PUT('QUOTE,PRETOPRINF,'QUOTOX);
  235. SYMBOLIC PROCEDURE PROGNOX U;
  236. BEGIN
  237. CURMARK := CURMARK+1;
  238. PRIN2OX "<<";
  239. OMARK '(M U);
  240. WHILE U DO <<MPRINO CAR U; U := CDR U;
  241. IF U THEN <<PRIN2OX "; "; OMARKO CURMARK>>>>;
  242. OMARK '(M D);
  243. PRIN2OX ">>";
  244. CURMARK := CURMARK-1
  245. END;
  246. PUT('PROG2,PRETOPRINF,'PROGNOX);
  247. PUT('PROGN,PRETOPRINF,'PROGNOX);
  248. SYMBOLIC PROCEDURE REPEATOX U;
  249. BEGIN
  250. CURMARK := CURMARK+1;
  251. OMARK '(M U);
  252. PRIN2OX "REPEAT ";
  253. MPRINO CAR U;
  254. PRIN2OX " UNTIL ";
  255. OMARK LIST(CURMARK,3);
  256. MPRINO CADR U;
  257. OMARK '(M D);
  258. CURMARK := CURMARK-1
  259. END;
  260. PUT('REPEAT,PRETOPRINF,'REPEATOX);
  261. SYMBOLIC PROCEDURE WHILEOX U;
  262. BEGIN
  263. CURMARK := CURMARK+1;
  264. OMARK '(M U);
  265. PRIN2OX "WHILE ";
  266. MPRINO CAR U;
  267. PRIN2OX " DO ";
  268. OMARK LIST(CURMARK,3);
  269. MPRINO CADR U;
  270. OMARK '(M D);
  271. CURMARK := CURMARK-1
  272. END;
  273. PUT('WHILE,PRETOPRINF,'WHILEOX);
  274. SYMBOLIC PROCEDURE PROCOX U;
  275. BEGIN
  276. OMARK '(M U);
  277. CURMARK := CURMARK+1;
  278. IF CADDDR CDR U THEN <<MPRINO CADDDR CDR U; PRIN2OX " ">>;
  279. PRIN2OX "PROCEDURE ";
  280. PROCOX1(CAR U,CADR U,CADDR U)
  281. END;
  282. SYMBOLIC PROCEDURE PROCOX1(U,V,W);
  283. BEGIN
  284. PRINOX U;
  285. IF V THEN MPRARGS(V,LIST(0,0));
  286. PRIN2OX "; ";
  287. OMARK LIST(CURMARK,3);
  288. MPRINO W;
  289. CURMARK := CURMARK-1;
  290. OMARK '(M D)
  291. END;
  292. PUT('PROC,PRETOPRINF,'PROCOX);
  293. SYMBOLIC PROCEDURE PROCEOX U;
  294. BEGIN
  295. OMARK '(M U);
  296. CURMARK := CURMARK+1;
  297. MPRINO CADR U; PRIN2OX " ";
  298. IF NOT CADDR U EQ 'EXPR THEN <<MPRINO CADDR U; PRIN2OX " ">>;
  299. PRIN2OX "PROCEDURE ";
  300. PROCEOX1(CAR U,CADDDR U,CAR CDDDDR U)
  301. END;
  302. SYMBOLIC PROCEDURE PROCEOX1(U,V,W);
  303. BEGIN
  304. PRINOX U;
  305. IF V
  306. THEN <<IF NOT ATOM CAR V THEN V:= FOR EACH J IN V COLLECT CAR J;
  307. %allows for typing to be included with proc arguments;
  308. MPRARGS(V,LIST(0,0))>>;
  309. PRIN2OX "; ";
  310. OMARK LIST(CURMARK,3);
  311. MPRINO W;
  312. CURMARK := CURMARK -1;
  313. OMARK '(M D)
  314. END;
  315. PUT('PROCEDURE,PRETOPRINF,'PROCEOX);
  316. SYMBOLIC PROCEDURE PROCEOX0(U,V,W,X);
  317. PROCEOX LIST(U,'SYMBOLIC,V,
  318. MAPCAR(W,FUNCTION (LAMBDA J; J . 'SYMBOLIC)),X);
  319. SYMBOLIC PROCEDURE DEOX U;
  320. PROCEOX0(CAR U,'EXPR,CADR U,CADDR U);
  321. PUT('DE,PRETOPRINF,'DEOX);
  322. SYMBOLIC PROCEDURE DFOX U;
  323. PROCEOX0(CAR U,'FEXPR,CADR U,CADDR U);
  324. %PUT('DF,PRETOPRINF,'DFOX); %commented out because of confusion with
  325. %differentiation;
  326. SYMBOLIC PROCEDURE STRINGOX U;
  327. <<PRIN2OX '!"; PRIN2OX CAR U; PRIN2OX '!">>;
  328. PUT('STRING,PRETOPRINF,'STRINGOX);
  329. SYMBOLIC PROCEDURE LAMBDOX U;
  330. BEGIN
  331. OMARK '(M U);
  332. CURMARK := CURMARK+1;
  333. PROCOX1('LAMBDA,CAR U,CADR U)
  334. END;
  335. PUT('LAMBDA,PRETOPRINF,'LAMBDOX);
  336. SYMBOLIC PROCEDURE EACHOX U;
  337. <<PRIN2OX "FOR EACH ";
  338. WHILE CDR U DO <<MPRINO CAR U; PRIN2OX " "; U := CDR U>>;
  339. MPRINO CAR U>>;
  340. PUT('FOREACH,PRETOPRINF,'EACHOX);
  341. SYMBOLIC PROCEDURE FOROX U;
  342. BEGIN
  343. CURMARK := CURMARK+1;
  344. OMARK '(M U);
  345. PRIN2OX "FOR ";
  346. MPRINO CAR U;
  347. PRIN2OX " := ";
  348. MPRINO CAADR U;
  349. IF CADR CADR U NEQ 1
  350. THEN <<PRIN2OX " STEP "; MPRINO CADR CADR U; PRIN2OX " UNTIL ">>
  351. ELSE PRIN2OX ":";
  352. MPRINO CADDR CADR U;
  353. PRIN2OX " ";
  354. MPRINO CADDR U;
  355. PRIN2OX " ";
  356. OMARK LIST(CURMARK,3);
  357. MPRINO CADDDR U;
  358. OMARK '(M D);
  359. CURMARK := CURMARK-1
  360. END;
  361. PUT('FOR,PRETOPRINF,'FOROX);
  362. SYMBOLIC PROCEDURE FORALLOX U;
  363. BEGIN
  364. CURMARK := CURMARK+1;
  365. OMARK '(M U);
  366. PRIN2OX "FOR ALL ";
  367. INPRINO('!*COMMA!*,LIST(0,0),CAR U);
  368. IF CADR U
  369. THEN <<OMARK LIST(CURMARK,3);
  370. PRIN2OX " SUCH THAT ";
  371. MPRINO CADR U>>;
  372. PRIN2OX " ";
  373. OMARK LIST(CURMARK,3);
  374. MPRINO CADDR U;
  375. OMARK '(M D);
  376. CURMARK := CURMARK-1
  377. END;
  378. PUT('FORALL,PRETOPRINF,'FORALLOX);
  379. COMMENT Declarations needed by old parser;
  380. IF NULL GET('!*SEMICOL!*,'OP)
  381. THEN <<PUT('!*SEMICOL!*,'OP,'((-1 0)));
  382. PUT('!*COMMA!*,'OP,'((5 6)))>>;
  383. COMMENT RPRINT MODULE, Part 2;
  384. FLUID '(ORIG CURPOS);
  385. SYMBOLIC PROCEDURE PRINOS U;
  386. BEGIN INTEGER CURPOS;
  387. SCALAR ORIG;
  388. ORIG := LIST POSN();
  389. CURPOS := CAR ORIG;
  390. PRINOY(U,0);
  391. TERPRI0X()
  392. END;
  393. SYMBOLIC PROCEDURE PRINOY(U,N);
  394. BEGIN SCALAR X;
  395. IF CAR(X := SPACELEFT(U,N)) THEN RETURN PRINOM(U,N)
  396. ELSE IF NULL CDR X THEN RETURN IF CAR ORIG<10 THEN PRINOM(U,N)
  397. ELSE <<ORIG := 9 . CDR ORIG;
  398. TERPRI0X();
  399. SPACES2(CURPOS := 9+CADAR U);
  400. PRINOY(U,N)>>
  401. ELSE BEGIN
  402. A: U := PRINOY(U,N+1);
  403. IF NULL CDR U OR CAAR U<=N THEN RETURN;
  404. TERPRI0X();
  405. SPACES2(CURPOS := CAR ORIG+CADAR U);
  406. GO TO A END;
  407. RETURN U
  408. END;
  409. SYMBOLIC PROCEDURE SPACELEFT(U,MARK);
  410. %U is an expanded buffer of characters delimited by non-atom marks
  411. %of the form: '(M ...) or '(INT INT))
  412. %MARK is an integer;
  413. BEGIN INTEGER N; SCALAR FLG,MFLG;
  414. N := RMAR - CURPOS;
  415. U := CDR U; %move over the first mark;
  416. WHILE U AND NOT FLG AND N>=0 DO
  417. <<IF ATOM CAR U THEN N := N-1
  418. ELSE IF CAAR U EQ 'M THEN NIL
  419. ELSE IF MARK>=CAAR U THEN <<FLG := T; U := NIL . U>>
  420. ELSE MFLG := T;
  421. U := CDR U>>;
  422. RETURN ((N>=0) . MFLG)
  423. END;
  424. SYMBOLIC PROCEDURE PRINOM(U,MARK);
  425. BEGIN INTEGER N; SCALAR FLG,X;
  426. N := CURPOS;
  427. U := CDR U;
  428. WHILE U AND NOT FLG DO
  429. <<IF ATOM CAR U THEN <<X := PRIN20X CAR U; N := N+1>>
  430. ELSE IF CAAR U EQ 'M
  431. THEN IF CADAR U EQ 'U THEN ORIG := N . ORIG
  432. ELSE ORIG := CDR ORIG
  433. ELSE IF MARK>=CAAR U
  434. AND NOT(X='!, AND RMAR-N-6>CHARSPACE(U,X,MARK))
  435. THEN <<FLG := T; U := NIL . U>>;
  436. U := CDR U>>;
  437. CURPOS := N;
  438. IF MARK=0 AND CDR U
  439. THEN <<TERPRI0X();
  440. TERPRI0X();
  441. ORIG := LIST 0; CURPOS := 0; PRINOY(U,MARK)>>;
  442. %must be a top level constant;
  443. RETURN U
  444. END;
  445. SYMBOLIC PROCEDURE CHARSPACE(U,CHAR,MARK);
  446. %determines if there is space until the next character CHAR;
  447. BEGIN INTEGER N;
  448. N := 0;
  449. WHILE U DO
  450. <<IF CAR U = CHAR THEN U := LIST NIL
  451. ELSE IF ATOM CAR U THEN N := N+1
  452. ELSE IF CAR U='(M U) THEN <<N := 1000; U := LIST NIL>>
  453. ELSE IF NUMBERP CAAR U AND CAAR U<MARK THEN U := LIST NIL;
  454. U := CDR U>>;
  455. RETURN N
  456. END;
  457. SYMBOLIC PROCEDURE SPACES2 N;
  458. %FOR I := 1:N DO PRIN20X '! ;
  459. WHILE N>0 DO <<PRIN20X '! ; N := N-1>>;
  460. SYMBOLIC PROCEDURE PRIN2ROX U;
  461. BEGIN INTEGER M,N; SCALAR X,Y;
  462. M := RMAR-12;
  463. N := RMAR-1;
  464. WHILE U DO
  465. IF CAR U EQ '!"
  466. THEN <<IF NOT STRINGSPACE(CDR U,N-!*N)
  467. THEN <<TERPRI0X(); !*N := 0>>
  468. ELSE NIL;
  469. PRIN20X '!";
  470. U := CDR U;
  471. WHILE NOT CAR U EQ '!" DO
  472. <<PRIN20X CAR U; U := CDR U; !*N := !*N+1>>;
  473. PRIN20X '!";
  474. U := CDR U;
  475. !*N := !*N+2;
  476. X := Y := NIL>>
  477. ELSE IF ATOM CAR U AND NOT(CAR U EQ '! AND (!*N=0 OR NULL X
  478. OR CDR U AND BREAKP CADR U OR BREAKP X AND NOT Y EQ '!!))
  479. THEN <<Y := X; PRIN20X(X := CAR U); !*N := !*N+1;
  480. U := CDR U;
  481. IF !*N=N OR !*N>M AND NOT BREAKP CAR U AND NOSPACE(U,N-!*N)
  482. THEN <<TERPRI0X(); X := Y := NIL>> ELSE NIL>>
  483. ELSE U := CDR U
  484. END;
  485. SYMBOLIC PROCEDURE NOSPACE(U,N);
  486. IF N<1 THEN T
  487. ELSE IF NULL U THEN NIL
  488. ELSE IF NOT ATOM CAR U THEN NOSPACE(CDR U,N)
  489. ELSE IF NOT CAR U EQ '!! AND (CADR U EQ '! OR BREAKP CADR U)
  490. THEN NIL
  491. ELSE NOSPACE(CDR U,N-1);
  492. SYMBOLIC PROCEDURE BREAKP U;
  493. U MEMBER '(!< !> !; !: != !) !+ !- !, !' !");
  494. SYMBOLIC PROCEDURE STRINGSPACE(U,N);
  495. IF N<1 THEN NIL ELSE IF CAR U EQ '!" THEN T
  496. ELSE STRINGSPACE(CDR U,N-1);
  497. COMMENT Some interfaces needed;
  498. PUT('CONS,'PRTCH,'(! !.! !.));
  499. GLOBAL '(RPRIFN!* RTERFN!*);
  500. COMMENT RPRIFN!* allows output from RPRINT to be handled differently,
  501. RTERFN!* allows end of lines to be handled differently;
  502. SYMBOLIC PROCEDURE PRIN20X U;
  503. IF RPRIFN!* THEN APPLY(RPRIFN!*,LIST U) ELSE PRIN2 U;
  504. SYMBOLIC PROCEDURE TERPRI0X;
  505. IF RTERFN!* THEN APPLY(RTERFN!*,NIL) ELSE TERPRI();
  506. END;