rds-wrs.red 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. %
  2. % RDS-WRS.RED - Switch the current input or output channel
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 28 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. global '(SpecialRDSAction!* % possibly apply to old and new channel
  12. SpecialWRSAction!* % ditto
  13. IN!* % Current input channel
  14. OUT!*); % Current output channel
  15. fluid '(StdIN!* % Standard input - may be rebound
  16. StdOUT!*); % Standard output - may be rebound
  17. on SysLisp;
  18. syslsp procedure RDS Channel; %. Switch input channels, return old
  19. begin scalar OldIN, ReadFn;
  20. if LispVar SpecialRDSAction!* then
  21. Apply(LispVar SpecialRDSAction!*, list(LispVar IN!*, Channel));
  22. OldIN := LispVar IN!*;
  23. if null Channel then Channel := LispVar StdIN!*;
  24. ReadFn := ReadFunction[IntInf Channel];
  25. if ReadFn eq 'ChannelNotOpen or ReadFn eq 'WriteOnlyChannel then return
  26. ChannelError(Channel, "Channel not open for input in RDS");
  27. LispVar IN!* := Channel;
  28. return OldIN;
  29. end;
  30. syslsp procedure WRS Channel; %. Switch output channels, return old
  31. begin scalar OldOUT, WriteFn;
  32. if LispVar SpecialWRSAction!* then
  33. Apply(LispVar SpecialWRSAction!*, list(LispVar OUT!*, Channel));
  34. OldOUT := LispVar OUT!*;
  35. if null Channel then Channel := LispVar StdOUT!*;
  36. WriteFn := WriteFunction[IntInf Channel];
  37. if WriteFn eq 'ChannelNotOpen or WriteFn eq 'ReadOnlyChannel then return
  38. ChannelError(Channel, "Channel not open for output in WRS");
  39. LispVar OUT!* := Channel;
  40. return OldOUT;
  41. end;
  42. off SysLisp;
  43. END;