open-close.red 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. %
  2. % OPEN-CLOSE.RED - File primitives
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 27 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % Edit by Cris Perdue, 27 Jan 1983 1700-PST
  12. % Close now checks for a legitimate FileDes argument
  13. fluid '(SpecialReadFunction!* % These must be set up for special
  14. SpecialWriteFunction!* % Open call
  15. SpecialCloseFunction!*);
  16. on SysLisp;
  17. external WArray ReadFunction, % indexed by channel to read a char
  18. WriteFunction, % indexed by channel to write a char
  19. CloseFunction, % indexed by channel to close channel
  20. UnReadBuffer, % indexed by channel for input backup
  21. LinePosition, % indexed by channel for Posn()
  22. MaxLine; % when to force an end-of-line
  23. syslsp procedure Open(FileName, AccessType); %. Get access to file
  24. begin scalar FileDes;
  25. if AccessType eq 'INPUT then
  26. << FileDes := SystemOpenFileForInput FileName;
  27. UnReadBuffer[FileDes] := char NULL;
  28. WriteFunction[FileDes] := 'ReadOnlyChannel >>
  29. else if AccessType eq 'OUTPUT then
  30. << FileDes := SystemOpenFileForOutput FileName;
  31. LinePosition[FileDes] := 0;
  32. MaxLine[FileDes] := 80;
  33. ReadFunction[FileDes] := 'WriteOnlyChannel >>
  34. else if AccessType eq 'SPECIAL then
  35. if IDP LispVar SpecialReadFunction!*
  36. and IDP LispVar SpecialWriteFunction!*
  37. and IDP LispVar SpecialCloseFunction!* then
  38. << FileDes := SystemOpenFileSpecial FileName;
  39. LinePosition[FileDes] := 0;
  40. MaxLine[FileDes] := 80;
  41. UnReadBuffer[FileDes] := char NULL;
  42. ReadFunction[FileDes] := IdInf LispVar SpecialReadFunction!*;
  43. WriteFunction[FileDes] := IdInf LispVar SpecialWriteFunction!*;
  44. CloseFunction[FileDes] := IdInf LispVar SpecialCloseFunction!* >>
  45. else IOError "Improperly set-up special IO open call"
  46. else IOError "Unknown access type";
  47. return MkINT FileDes;
  48. end;
  49. syslsp procedure Close FileDes; %. End access to file
  50. begin scalar BareFileDes;
  51. BareFileDes := IntInf FileDes;
  52. if not (0 <= BareFileDes and BareFileDes <= MaxChannels) then
  53. NonIOChannelError(FileDes, "Close");
  54. IDApply1(BareFileDes, CloseFunction[BareFileDes]);
  55. SystemMarkAsClosedChannel FileDes;
  56. ReadFunction[BareFileDes] := 'ChannelNotOpen;
  57. WriteFunction[BareFileDes] := 'ChannelNotOpen;
  58. CloseFunction[BareFileDes] := 'ChannelNotOpen;
  59. return FileDes;
  60. end;
  61. off SysLisp;
  62. END;