dskin.red 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. %
  2. % DSKIN.RED - Read/Eval/Print from files
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 24 September 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % <PSL.KERNEL>DSKIN.RED.2, 5-Oct-82 11:32:28, Edit by BENSON
  12. % Changed DSKIN from FEXPR to 1 argument EXPR
  13. % <PSL.INTERP>DSKIN.RED.11, 7-May-82 06:14:27, Edit by GRISS
  14. % Added XPRINT in loop to handle levels of output
  15. % <PSL.INTERP>DSKIN.RED.6, 30-Apr-82 12:49:59, Edit by BENSON
  16. % Made !*DEFN call DfPrint instead of own processing
  17. % <PSL.INTERP>DSKIN.RED.3, 29-Apr-82 04:23:49, Edit by GRISS
  18. % Added !*DEFN flag, cf TOPLOOP
  19. CompileTime <<
  20. flag('(DskInDefnPrint), 'InternalFunction);
  21. >>;
  22. expr procedure DskIN F; %. Read a file (dskin "file")
  23. %
  24. % This is reasonably standard Standard Lisp, except for file name format
  25. % knowledge.
  26. %
  27. begin scalar OldIN, NewIN, TestOpen, Exp;
  28. TestOpen := ErrorSet(list('OPEN, F, '(QUOTE INPUT)), NIL, NIL);
  29. if not PairP TestOpen then return
  30. ContError(99, "Couldn't open file `%w'", F, DskIN F);
  31. NewIN := car TestOpen;
  32. OldIN := RDS NewIN;
  33. while PairP(Exp := ErrorSet(quote Read(), T, !*Backtrace))
  34. and not (car Exp eq !$EOF!$)
  35. and PairP(Exp := ErrorSet(list('DskInEval, MkQuote car Exp),
  36. T,
  37. !*Backtrace)) do
  38. if not !*Defn then PrintF("%f%p%n", car Exp);
  39. %/ no error protection for printing, maybe should be
  40. RDS OldIN;
  41. Close NewIN;
  42. end;
  43. lisp procedure DskInEval U;
  44. if not !*DEFN then Eval U else DskInDefnPrint U;
  45. lisp procedure DskInDefnPrint U; % handle case of !*Defn:=T
  46. %
  47. % Looks for special action on a form, otherwise prettyprints it;
  48. % Adapted from DFPRINT
  49. %
  50. if PairP U and FlagP(car U,'Ignore) then Eval U
  51. else % So 'IGNORE is EVALED, not output
  52. << if DfPrint!* then Apply(DfPrint!*, list U)
  53. else PrettyPrint U; % So 'EVAL gets EVALED and Output
  54. if PairP U and FlagP(Car U,'EVAL) then Eval U >>;
  55. flag('(DskIn), 'IGNORE);
  56. fluid '(!*RedefMSG !*Echo);
  57. SYMBOLIC PROCEDURE LAPIN FIL;
  58. BEGIN SCALAR OLDIN, EXP, !*REDEFMSG, !*ECHO;
  59. OLDIN := RDS OPEN(FIL,'INPUT);
  60. WHILE (EXP := READ()) NEQ !$EOF!$
  61. DO EVAL EXP;
  62. CLOSE RDS OLDIN;
  63. END;
  64. END;