inter.red 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. module inter; % Functions for interactive support.
  2. % Author: Anthony C. Hearn.
  3. % Copyright (c) 1993 RAND. All rights reserved.
  4. fluid '(!*echo !*int);
  5. global '(!$eof!$
  6. !$eol!$
  7. !*lessspace
  8. cloc!*
  9. contl!*
  10. curline!*
  11. edit!*
  12. eof!*
  13. erfg!*
  14. flg!*
  15. ifl!*
  16. ipl!*
  17. key!*
  18. ofl!*
  19. opl!*
  20. techo!*);
  21. symbolic procedure pause;
  22. %Must appear at the top-most level;
  23. if null !*int then nil
  24. else if key!* eq 'pause then pause1 nil
  25. else %typerr('pause,"lower level command");
  26. pause1 nil; % Allow at lower level for now.
  27. symbolic procedure pause1 bool;
  28. begin scalar x;
  29. if bool then
  30. if getd 'edit1 and erfg!* and cloc!* and yesp "Edit?"
  31. then return <<contl!* := nil;
  32. if ofl!* then <<lprim list(car ofl!*,'shut);
  33. close cdr ofl!*;
  34. opl!* := delete(ofl!*,opl!*);
  35. ofl!* := nil>>;
  36. edit1(cloc!*,nil)>>
  37. else if flg!* then return (edit!* := nil);
  38. if null ifl!* or yesp "Cont?" then return nil;
  39. ifl!* := list(car ifl!*,cadr ifl!*,curline!*);
  40. if x := assoccar(car ifl!*,contl!*)
  41. then <<contl!* := delete(x,contl!*); close cadar x>>;
  42. contl!* := (ifl!* . cdr ipl!* . !*echo) . contl!*;
  43. ifl!* := ipl!* := nil;
  44. rds nil;
  45. !*echo := techo!*
  46. end;
  47. symbolic procedure assoccar(u,v);
  48. % Returns element of v in which caar of that element = u.
  49. if null v then nil
  50. else if u=caaar v then car v
  51. else assoccar(u,cdr v);
  52. symbolic procedure yesp u;
  53. begin scalar ifl,ofl,x,y;
  54. if ifl!*
  55. then <<ifl := ifl!* := list(car ifl!*,cadr ifl!*,curline!*);
  56. rds nil>>;
  57. if ofl!* then <<ofl:= ofl!*; wrs nil>>;
  58. if null !*lessspace then terpri();
  59. if atom u then prin2 u else lpri u;
  60. prin2t " (Y or N)";
  61. if null !*lessspace then terpri();
  62. y := setpchar '!?;
  63. x := yesp1();
  64. setpchar y;
  65. if ofl then wrs cdr ofl;
  66. if ifl then rds cadr ifl;
  67. cursym!* := '!*semicol!*;
  68. return x
  69. end;
  70. symbolic procedure yesp1;
  71. % Basic loop for reading response.
  72. begin scalar bool,x,y;
  73. a: x := readch();
  74. if x eq !$eol!$ then go to a
  75. % Assume an end-of-file means lost control and exit.
  76. else if x eq !$eof!$ then eval '(bye)
  77. %% else if (y := x eq 'y) or x eq 'n then return y
  78. else if (y := x memq '(!y !Y)) or x memq '(!n !N)
  79. then return y % F.J. Wright.
  80. else if null bool then <<prin2t "Type Y or N"; bool := t>>;
  81. go to a
  82. end;
  83. symbolic procedure cont;
  84. begin scalar fl,techo;
  85. if ifl!* then return nil % CONT only active from terminal.
  86. else if null contl!* then rerror(rlisp,28,"No file open");
  87. fl := caar contl!*;
  88. ipl!* := fl . cadar contl!*;
  89. techo := cddar contl!*;
  90. contl!* := cdr contl!*;
  91. if car fl=caar ipl!* and cadr fl=cadar ipl!*
  92. then <<ifl!* := fl;
  93. if fl then <<rds cadr fl; curline!* := caddr fl>>
  94. else rds nil;
  95. !*echo := techo>>
  96. else <<eof!* := 1; lprim list(fl,"not open"); error1()>>
  97. end;
  98. deflist ('((cont endstat) (pause endstat) (retry endstat)),'stat);
  99. flag ('(cont),'ignore);
  100. endmodule;
  101. end;