GraphTool.Mod.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. MODULE GraphTool; (*NW 8.8.2013*)
  2. IMPORT Files, Texts, Oberon;
  3. CONST Context = 0; Line = 1; Caption = 2; Macro = 3; Rectangles = 4;
  4. VAR W: Texts.Writer;
  5. PROCEDURE DecGraph*;
  6. VAR ch: CHAR;
  7. class, col, fno, cat, inx, libno: BYTE;
  8. xy, wh: INTEGER;
  9. name: ARRAY 32 OF CHAR;
  10. F: Files.File; R: Files.Rider;
  11. S: Texts.Scanner;
  12. BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
  13. IF S.class = Texts.Name THEN
  14. Texts.WriteString(W, "decode "); Texts.WriteString(W, S.s);
  15. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
  16. F := Files.Old(S.s);
  17. IF F # NIL THEN
  18. Files.Set(R, F, 0); Files.Read(R, ch);
  19. IF ch = 0F8X THEN
  20. Files.ReadByte(R, class);
  21. WHILE ~R.eof & (class < 255) DO
  22. Texts.WriteInt(W, class, 4);
  23. IF class = Context THEN
  24. Files.ReadByte(R, cat); Files.ReadByte(R, inx); Texts.WriteInt(W, cat, 4); Texts.WriteInt(W, inx, 4);
  25. Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name);
  26. IF cat = 2 THEN Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name) END
  27. ELSE Files.ReadInt(R, xy);
  28. Texts.WriteInt(W, xy * 10000H DIV 10000H, 5); Texts.WriteInt(W, xy DIV 10000H, 5);
  29. Files.ReadInt(R, wh);
  30. Texts.WriteInt(W, wh * 10000H DIV 10000H, 5); Texts.WriteInt(W, wh DIV 10000H, 5);
  31. Files.ReadByte(R, col); Files.Read(R, ch); Texts.WriteInt(W, col, 5); Texts.Write(W, "|");
  32. IF class = Line THEN
  33. ELSIF class = Caption THEN
  34. Files.ReadByte(R, fno); Texts.WriteInt(W, fno, 5); Texts.Write(W, " ");
  35. Files.ReadString(R, name); Texts.WriteString(W, name)
  36. ELSIF class = Macro THEN
  37. Files.ReadByte(R, libno); Files.ReadString(R, name);
  38. Texts.WriteInt(W, libno, 4); Texts.Write(W, " "); Texts.WriteString(W, name)
  39. ELSIF class = Rectangles THEN
  40. Files.ReadByte(R, fno); Texts.WriteInt(W, fno, 4); Files.ReadByte(R, fno); Texts.WriteInt(W, fno, 4);
  41. Files.ReadByte(R, fno); Texts.WriteInt(W, fno, 4)
  42. ELSE Texts.WriteString(W, "other class ="); Texts.WriteInt(W, class, 4)
  43. END
  44. END ;
  45. Texts.WriteLn(W); Files.ReadByte(R, class)
  46. END
  47. ELSE Texts.WriteString(W, " not a graphics file")
  48. END
  49. ELSE Texts.WriteString(W, " not found")
  50. END ;
  51. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  52. END
  53. END DecGraph;
  54. PROCEDURE DecGraph1*;
  55. VAR ch: CHAR;
  56. class, col, fno, len, lw, vers, cat, inx, libno: BYTE;
  57. xy, wh: INTEGER;
  58. name: ARRAY 32 OF CHAR;
  59. F: Files.File; R: Files.Rider;
  60. S: Texts.Scanner;
  61. BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
  62. IF S.class = Texts.Name THEN
  63. Texts.WriteString(W, "decode "); Texts.WriteString(W, S.s);
  64. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
  65. F := Files.Old(S.s);
  66. IF F # NIL THEN
  67. Files.Set(R, F, 0); Files.Read(R, ch);
  68. IF ch = 0FAX THEN
  69. Files.ReadByte(R, class);
  70. WHILE ~R.eof & (class < 255) DO
  71. Texts.WriteInt(W, class, 4);
  72. IF class = Context THEN
  73. Files.ReadByte(R, cat); Files.ReadByte(R, inx); Texts.WriteInt(W, cat, 4); Texts.WriteInt(W, inx, 4);
  74. Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name);
  75. IF cat = 2 THEN Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name) END
  76. ELSE Files.ReadInt(R, xy);
  77. Texts.WriteInt(W, xy * 10000H DIV 10000H, 5); Texts.WriteInt(W, xy DIV 10000H, 5);
  78. Files.ReadInt(R, wh);
  79. Texts.WriteInt(W, wh * 10000H DIV 10000H, 5); Texts.WriteInt(W, wh DIV 10000H, 5);
  80. Files.ReadByte(R, col); Texts.WriteInt(W, col, 5); Texts.Write(W, "|");
  81. IF class = Line THEN
  82. ELSIF class = Caption THEN
  83. Files.ReadByte(R, fno); Texts.WriteInt(W, fno, 5); Texts.Write(W, " ");
  84. Files.ReadString(R, name); Texts.WriteString(W, name)
  85. ELSIF class = Macro THEN
  86. Files.ReadByte(R, libno); Files.ReadString(R, name);
  87. Texts.WriteInt(W, libno, 4); Texts.Write(W, " "); Texts.WriteString(W, name)
  88. ELSIF class = Rectangles THEN
  89. Files.ReadByte(R, len); Texts.WriteInt(W, len, 4);
  90. Files.ReadByte(R, lw); Texts.WriteInt(W, lw, 4);
  91. Files.ReadByte(R, vers); Texts.WriteInt(W, vers, 4)
  92. ELSE Texts.WriteString(W, "other class ="); Texts.WriteInt(W, class, 4)
  93. END
  94. END ;
  95. Texts.WriteLn(W); Files.ReadByte(R, class)
  96. END
  97. ELSE Texts.WriteString(W, " not a graphics file")
  98. END
  99. ELSE Texts.WriteString(W, " not found")
  100. END ;
  101. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  102. END
  103. END DecGraph1;
  104. PROCEDURE DecLibrary1*;
  105. VAR ch: CHAR;
  106. class, col, fno, cat, inx, libno, len, lnw, vers: BYTE;
  107. xy, wh: INTEGER;
  108. name: ARRAY 32 OF CHAR;
  109. F: Files.File; R: Files.Rider;
  110. S: Texts.Scanner;
  111. BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
  112. IF S.class = Texts.Name THEN
  113. Texts.WriteString(W, "decode library1 "); Texts.WriteString(W, S.s);
  114. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
  115. F := Files.Old(S.s);
  116. IF F # NIL THEN
  117. Files.Set(R, F, 0); Files.Read(R, ch);
  118. IF ch = 0FBX THEN
  119. Files.ReadByte(R, class);
  120. WHILE (class < 255) & ~R.eof DO
  121. WHILE class < 255 DO
  122. Texts.WriteInt(W, class, 4);
  123. IF class = Context THEN
  124. Files.ReadByte(R, cat); Files.ReadByte(R, inx); Texts.WriteInt(W, cat, 4); Texts.WriteInt(W, inx, 4);
  125. Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name);
  126. IF cat = 2 THEN Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name) END
  127. ELSE Files.ReadInt(R, xy);
  128. Texts.WriteInt(W, xy * 10000H DIV 10000H, 5); Texts.WriteInt(W, xy DIV 10000H, 5);
  129. Files.ReadInt(R, wh);
  130. Texts.WriteInt(W, wh * 10000H DIV 10000H, 5); Texts.WriteInt(W, wh DIV 10000H, 5);
  131. Files.ReadByte(R, col); Texts.WriteInt(W, col, 5);
  132. IF class = Line THEN
  133. ELSIF class = Caption THEN
  134. Texts.Write(W, "|"); Files.ReadByte(R, fno); Texts.WriteInt(W, fno, 5); Texts.Write(W, " ");
  135. Files.ReadString(R, name); Texts.WriteString(W, name)
  136. ELSIF class = Rectangles THEN
  137. Texts.Write(W, "|"); Files.ReadByte(R, len); Texts.WriteInt(W, len, 4);
  138. Files.ReadByte(R, lnw); Texts.WriteInt(W, lnw, 4);
  139. Files.ReadByte(R, vers); Texts.WriteInt(W, vers, 4)
  140. ELSE Texts.WriteString(W, "other class ="); Texts.WriteInt(W, class, 4)
  141. END
  142. END ;
  143. Texts.WriteLn(W); Files.ReadByte(R, class)
  144. END ;
  145. (*end macro*) Texts.WriteString(W, "---");
  146. Files.ReadInt(R, wh); Texts.WriteInt(W, wh MOD 10000H, 5); Texts.WriteInt(W, wh DIV 10000H, 5);
  147. Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name);
  148. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf); Files.ReadByte(R, class)
  149. END
  150. ELSE Texts.WriteString(W, " not a graphics library")
  151. END
  152. ELSE Texts.WriteString(W, " not found")
  153. END ;
  154. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  155. END
  156. END DecLibrary1;
  157. PROCEDURE ConvertFontname(VAR x: ARRAY OF CHAR);
  158. BEGIN (* Syntax --> Oberon *)
  159. IF (x[0] = "S") & (x[1] = "y") & (x[2] = "n") & (x[3] = "t") & (x[4] = "a") & (x[5] = "x") THEN
  160. x[0] := "O"; x[1] := "b"; x[2] := "e"; x[3] := "r"; x[4] := "o"; x[5] := "n"
  161. END
  162. END ConvertFontname;
  163. PROCEDURE ConvertLibrary*;
  164. VAR ch: CHAR;
  165. class, col, fno, cat, inx, libno, len, lnw, vers: BYTE;
  166. xy, wh: INTEGER;
  167. name: ARRAY 32 OF CHAR;
  168. F, G: Files.File; R, Q: Files.Rider;
  169. S: Texts.Scanner;
  170. BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
  171. IF S.class = Texts.Name THEN
  172. Texts.WriteString(W, "convert library "); Texts.WriteString(W, S.s);
  173. F := Files.Old(S.s);
  174. IF F # NIL THEN
  175. Texts.Scan(S); G := Files.New(S.s);
  176. Texts.WriteString(W, " => "); Texts.WriteString(W, S.s);
  177. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
  178. Files.Set(R, F, 0); Files.Set(Q, G, 0); Files.Read(R, ch);
  179. IF ch = 0FDX THEN
  180. Files.Write(Q, 0FBX); Files.ReadByte(R, class);
  181. WHILE (class < 255) & ~R.eof DO
  182. WHILE class < 255 DO
  183. Files.WriteByte(Q, class);
  184. IF class = Context THEN
  185. Files.ReadByte(R, cat); Files.ReadByte(R, inx); Texts.WriteInt(W, cat, 4); Texts.WriteInt(W, inx, 4);
  186. Files.WriteByte(Q, cat); Files.WriteByte(Q, inx);
  187. Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name);
  188. IF cat = 0 THEN (*font*) ConvertFontname(name) END ;
  189. Files.WriteString(Q, name);
  190. IF cat = 2 THEN (*class*) Files.ReadString(R, name); Texts.Write(W, " "); Texts.WriteString(W, name); Files.WriteString(Q, name) END ;
  191. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  192. ELSE Files.ReadInt(R, xy); Files.WriteInt(Q, xy); Files.ReadInt(R, wh); Files.WriteInt(Q, wh);
  193. Files.ReadByte(R, col); Files.Read(R, ch); Files.WriteByte(Q, 1);
  194. IF class = Line THEN
  195. ELSIF class = Caption THEN
  196. Files.ReadByte(R, fno); Files.WriteByte(Q, fno); Files.ReadString(R, name); Files.WriteString(Q, name)
  197. ELSIF class = Rectangles THEN
  198. Files.ReadByte(R, len); Files.WriteByte(Q, len); Files.ReadByte(R, len);
  199. Files.ReadByte(R, lnw); Files.WriteByte(Q, lnw);
  200. Files.ReadByte(R, vers); Files.WriteByte(Q, vers)
  201. ELSE Texts.WriteString(W, "alien class "); Texts.WriteInt(W, class, 4)
  202. END
  203. END ;
  204. Files.ReadByte(R, class)
  205. END ;
  206. Files.WriteByte(Q, 255); (*end macro*) Files.ReadInt(R, wh); Files.WriteInt(Q, wh);
  207. Files.ReadString(R, name); Files.WriteString(Q, name);
  208. Texts.WriteString(W, name); Texts.WriteInt(W, wh MOD 10000H, 4); Texts.WriteInt(W, wh DIV 10000H, 4);
  209. Texts.WriteLn(W); Files.ReadByte(R, class)
  210. END
  211. ELSE Texts.WriteString(W, " not a graphics library")
  212. END ;
  213. Files.Register(G); Texts.WriteString(W, " done")
  214. ELSE Texts.WriteString(W, " not found")
  215. END ;
  216. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  217. END
  218. END ConvertLibrary;
  219. BEGIN Texts.OpenWriter(W); Texts.WriteString(W, "GraphTool 8.8.2013");
  220. Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf);
  221. END GraphTool.