PROG7.LST 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Listing:
  2. 1
  3. 2 MODULE prog7;
  4. 3 (* Sorts lines of a file into order, deleting duplicates *)
  5. 4 IMPORT IO, FIO, Lib, Storage, Str;
  6. 5
  7. 6 TYPE
  8. 7 StringType = ARRAY [0..255] OF CHAR;
  9. ***** ^ not supported yet
  10. ***** ^ not supported yet
  11. 8 StringPointerType = POINTER TO StringType;
  12. ***** ^ not supported yet
  13. 9 VAR
  14. 10 p : ARRAY [1..10000] OF StringPointerType;
  15. ***** ^ not supported yet
  16. ***** ^ not supported yet
  17. 11
  18. 12 PROCEDURE Less(i,j:CARDINAL):BOOLEAN;
  19. 13 BEGIN
  20. 14 RETURN Str.Compare(p[i]^, p[j]^) < 0 ;
  21. ***** ^ not supported yet
  22. ***** ^ not supported yet
  23. ***** ^ not supported yet
  24. ***** ^ not supported yet
  25. ***** ^ not supported yet
  26. ***** ^ not supported yet
  27. 15 END Less;
  28. ***** ^ not supported yet
  29. 16
  30. 17 PROCEDURE Swap(i,j:CARDINAL);
  31. 18 VAR tmp:StringPointerType;
  32. ***** ^ not supported yet
  33. 19 BEGIN
  34. 20 tmp := p[i]; p[i] := p[j]; p[j] := tmp;
  35. ***** ^ not supported yet
  36. ***** ^ not supported yet
  37. ***** ^ not supported yet
  38. ***** ^ not supported yet
  39. ***** ^ not supported yet
  40. ***** ^ not supported yet
  41. ***** ^ not supported yet
  42. ***** ^ not supported yet
  43. ***** ^ not supported yet
  44. ***** ^ not supported yet
  45. 21 END Swap;
  46. ***** ^ not supported yet
  47. 22
  48. 23 VAR s: StringType;
  49. ***** ^ not supported yet
  50. 24 len:CARDINAL;
  51. 25 i,n:CARDINAL;
  52. 26 InFile,OutFile:FIO.File;
  53. ***** ^ not supported yet
  54. 27 buffer:ARRAY [1..512+FIO.BufferOverhead] OF BYTE;
  55. ***** ^ not supported yet
  56. ***** ^ not supported yet
  57. ***** ^ undeclared identifier
  58. 28 BEGIN
  59. 29 (* check parameters *)
  60. 30 IF Lib.ParamCount() <> 2 THEN
  61. ***** ^ not supported yet
  62. ***** ^ not supported yet
  63. ***** ^ not supported yet
  64. 31 IO.WrStr('Try again : prog7 input-file output-file');
  65. ***** ^ not supported yet
  66. ***** ^ not supported yet
  67. ***** ^ not supported yet
  68. 32 IO.WrLn;
  69. ***** ^ not supported yet
  70. ***** ^ not supported yet
  71. 33 HALT;
  72. ***** ^ undeclared identifier
  73. 34 END;
  74. 35
  75. 36 (* read file in *)
  76. 37 Lib.ParamStr(s, 1); InFile := FIO.Open(s);
  77. ***** ^ not supported yet
  78. ***** ^ not supported yet
  79. ***** ^ not supported yet
  80. ***** ^ not supported yet
  81. ***** ^ not supported yet
  82. ***** ^ not supported yet
  83. ***** ^ not supported yet
  84. ***** ^ not supported yet
  85. 38 FIO.AssignBuffer(InFile, buffer);
  86. ***** ^ not supported yet
  87. ***** ^ not supported yet
  88. ***** ^ not supported yet
  89. ***** ^ not supported yet
  90. 39 n := 0;
  91. 40 LOOP
  92. 41 FIO.RdStr(InFile, s);
  93. ***** ^ not supported yet
  94. ***** ^ not supported yet
  95. ***** ^ not supported yet
  96. ***** ^ not supported yet
  97. 42 IF FIO.EOF THEN
  98. ***** ^ not supported yet
  99. ***** ^ not supported yet
  100. 43 EXIT;
  101. 44 END;
  102. 45 IF n = HIGH(p) THEN
  103. ***** ^ undeclared identifier
  104. ***** ^ not supported yet
  105. 46 IO.WrStr('Too many lines!');
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. ***** ^ not supported yet
  109. 47 IO.WrLn;
  110. ***** ^ not supported yet
  111. ***** ^ not supported yet
  112. 48 EXIT;
  113. 49 END;
  114. 50 INC(n);
  115. ***** ^ undeclared identifier
  116. ***** ^ not supported yet
  117. 51 len := Str.Length(s);
  118. ***** ^ not supported yet
  119. ***** ^ not supported yet
  120. ***** ^ not supported yet
  121. 52 Storage.ALLOCATE(p[n], len + 1);
  122. ***** ^ not supported yet
  123. ***** ^ not supported yet
  124. ***** ^ not supported yet
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. 53 Lib.Move(ADR(s), ADR(p[n]^), len + 1);
  128. ***** ^ not supported yet
  129. ***** ^ not supported yet
  130. ***** ^ undeclared identifier
  131. ***** ^ not supported yet
  132. ***** ^ undeclared identifier
  133. ***** ^ not supported yet
  134. ***** ^ not supported yet
  135. ***** ^ not supported yet
  136. 54 END;
  137. 55
  138. 56 FIO.Close(InFile);
  139. ***** ^ not supported yet
  140. ***** ^ not supported yet
  141. ***** ^ not supported yet
  142. 57
  143. 58 (* sort file in memory *)
  144. 59 Lib.HSort(n, Less, Swap);
  145. ***** ^ not supported yet
  146. ***** ^ not supported yet
  147. ***** ^ not supported yet
  148. ***** ^ not supported yet
  149. 60
  150. 61 (* write file out *)
  151. 62 Lib.ParamStr(s, 2); OutFile := FIO.Create(s);
  152. ***** ^ not supported yet
  153. ***** ^ not supported yet
  154. ***** ^ not supported yet
  155. ***** ^ not supported yet
  156. ***** ^ not supported yet
  157. ***** ^ not supported yet
  158. ***** ^ not supported yet
  159. ***** ^ not supported yet
  160. 63 FIO.AssignBuffer(OutFile, buffer);
  161. ***** ^ not supported yet
  162. ***** ^ not supported yet
  163. ***** ^ not supported yet
  164. ***** ^ not supported yet
  165. 64 FOR i := 1 TO n DO
  166. 65 IF (i = 1) OR (Str.Compare(p[i]^, p[i-1]^) <> 0) THEN
  167. ***** ^ not supported yet
  168. ***** ^ not supported yet
  169. ***** ^ not supported yet
  170. ***** ^ not supported yet
  171. ***** ^ not supported yet
  172. ***** ^ not supported yet
  173. 66 FIO.WrStr(OutFile, p[i]^);
  174. ***** ^ not supported yet
  175. ***** ^ not supported yet
  176. ***** ^ not supported yet
  177. ***** ^ not supported yet
  178. ***** ^ not supported yet
  179. 67 FIO.WrLn(OutFile);
  180. ***** ^ not supported yet
  181. ***** ^ not supported yet
  182. ***** ^ not supported yet
  183. 68 END;
  184. 69 END;
  185. 70 FIO.Close(OutFile);
  186. ***** ^ not supported yet
  187. ***** ^ not supported yet
  188. ***** ^ not supported yet
  189. 71
  190. 72 END prog7.
  191. 73
  192. 74
  193. 117 errors