explode-compress.red 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. %
  2. % EXPLODE-COMPRESS.RED - Write to/read from a list; includes FlatSize
  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>EXPLODE-COMPRESS.RED.3, 12-Oct-82 16:49:54, Edit by BENSON
  12. % Changed CompressReadChar to use Lisp2Char, so ASCII characters are OK,
  13. % but digits 0..9 as !0..!9 are not.
  14. fluid '(ExplodeEndPointer!* % pointer used to RplacD new chars onto
  15. CompressList!* % list being compressed
  16. !*Compressing); % if T, don't intern IDs when read
  17. external WArray LinePosition,UnReadBuffer;
  18. on SysLisp;
  19. syslsp procedure ExplodeWriteChar(Channel, Ch);
  20. << RplacD(LispVar ExplodeEndPointer!*, list MkID Ch);
  21. LispVar ExplodeEndPointer!* := cdr LispVar ExplodeEndPointer!* >>;
  22. syslsp procedure Explode U; %. S-expr --> char-list
  23. begin scalar Result;
  24. Result := LispVar ExplodeEndPointer!* := NIL . NIL;
  25. LinePosition[3] := 0;
  26. ChannelPrin1('3, U);
  27. return cdr Result;
  28. end;
  29. syslsp procedure Explode2 U; %. Prin2 version of Explode
  30. begin scalar Result;
  31. Result := LispVar ExplodeEndPointer!* := NIL . NIL;
  32. LinePosition[3] := 0;
  33. ChannelPrin2('3, U);
  34. return cdr Result;
  35. end;
  36. internal WVar FlatSizeAccumulator;
  37. syslsp procedure FlatSizeWriteChar(Channel, Ch);
  38. FlatSizeAccumulator := FlatSizeAccumulator + 1;
  39. syslsp procedure FlatSize U; %. character length of S-expression
  40. << FlatSizeAccumulator := 0;
  41. LinePosition[4] := 0;
  42. ChannelPrin1('4, U);
  43. MkINT FlatSizeAccumulator >>;
  44. lisp procedure FlatSize2 U; %. Prin2 version of FlatSize
  45. << FlatSizeAccumulator := 0;
  46. LinePosition[4] := 0;
  47. ChannelPrin2('4, U);
  48. MkINT FlatSizeAccumulator >>;
  49. internal WVar AtEndOfList;
  50. syslsp procedure CompressReadChar Channel;
  51. begin scalar NextEntry;
  52. if AtEndOfList then return CompressError();
  53. if not PairP LispVar CompressList!* then
  54. << AtEndOfList := 'T;
  55. return char BLANK >>;
  56. NextEntry := car LispVar CompressList!*;
  57. LispVar CompressList!* := cdr LispVar CompressList!*;
  58. return Lisp2Char NextEntry;
  59. end;
  60. syslsp procedure ClearCompressChannel();
  61. << UnReadBuffer[3] := char NULL;
  62. AtEndOfList := 'NIL >>;
  63. off SysLisp;
  64. lisp procedure CompressError();
  65. StdError "Poorly formed S-expression in COMPRESS";
  66. lisp procedure Compress CompressList!*; %. Char-list --> S-expr
  67. begin scalar !*Compressing;
  68. !*Compressing := T;
  69. ClearCompressChannel();
  70. return ChannelRead 3;
  71. end;
  72. lisp procedure Implode CompressList!*; %. Compress with IDs interned
  73. << ClearCompressChannel();
  74. ChannelRead 3 >>;
  75. END;