STRCNV1.LST 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. Listing:
  2. 1 IMPLEMENTATION MODULE StrCnv1;
  3. 2 (*
  4. 3 * REPERTOIRE
  5. 4 * Release 1.6
  6. 5 * By Charles Bradford and Cole Brecheen
  7. 6 * (c) Copyright 1985-1992 PMI
  8. 7 * Green Bay, Wisconsin
  9. 8 * All rights reserved
  10. 9 * (414) 468-6040
  11. 10 *
  12. 11 * $Header: D:/logfiles/mods/strcnv1.mov 1.5 10 Mar 1991 15:33:02 coleb $
  13. 12 *
  14. 13 *)
  15. 14
  16. 15
  17. 16 IMPORT M2Strings;
  18. 17 IMPORT Numbers;
  19. 18 IMPORT NumTypes;
  20. 19
  21. 20 VAR
  22. 21 Initialized : BOOLEAN;
  23. 22
  24. 23 PROCEDURE Init();
  25. 24 BEGIN
  26. 25 IF Initialized THEN
  27. 26 RETURN;
  28. 27 ELSE
  29. 28 Initialized := TRUE;
  30. 29 END;
  31. 30 M2Strings.Init();
  32. ***** ^ not supported yet
  33. ***** ^ not supported yet
  34. ***** ^ not supported yet
  35. 31 Numbers.Init();
  36. ***** ^ not supported yet
  37. ***** ^ not supported yet
  38. ***** ^ not supported yet
  39. 32 NumTypes.Init();
  40. ***** ^ not supported yet
  41. ***** ^ not supported yet
  42. ***** ^ not supported yet
  43. 33 END Init;
  44. ***** ^ not supported yet
  45. 34
  46. 35 CONST
  47. 36 blank = ' ';
  48. 37
  49. 38
  50. 39 PROCEDURE GetEmbeddedCard(TheStr : ARRAY OF CHAR; VAR Spot :
  51. ***** ^ not supported yet
  52. 40 CARDINAL; VAR TheCard : CARDINAL) : BOOLEAN;
  53. 41 VAR
  54. 42 StrLen : CARDINAL;
  55. 43 BEGIN
  56. 44 TheCard := 0;
  57. 45 StrLen := M2Strings.Length(TheStr);
  58. ***** ^ not supported yet
  59. ***** ^ not supported yet
  60. ***** ^ not supported yet
  61. 46 WHILE ((Spot<StrLen) AND ((TheStr[Spot]<'0'
  62. ***** ^ not supported yet
  63. ***** ^ not supported yet
  64. 47 ) OR (TheStr[Spot]>'9'))) DO
  65. ***** ^ not supported yet
  66. ***** ^ not supported yet
  67. 48 INC(Spot);
  68. ***** ^ undeclared identifier
  69. ***** ^ not supported yet
  70. 49 (*Skips all leading non-numeric stuff.*)
  71. 50 END;
  72. 51 IF Spot>=StrLen THEN
  73. 52 RETURN FALSE;
  74. 53 END;
  75. 54 WHILE (Spot<StrLen) AND (TheStr[Spot]>='0'
  76. ***** ^ not supported yet
  77. ***** ^ not supported yet
  78. 55 ) AND (TheStr[Spot]<='9') DO
  79. ***** ^ not supported yet
  80. ***** ^ not supported yet
  81. 56 TheCard := TheCard*10;
  82. 57 INC(TheCard, ORD(TheStr[Spot])-48);
  83. ***** ^ undeclared identifier
  84. ***** ^ undeclared identifier
  85. ***** ^ not supported yet
  86. ***** ^ not supported yet
  87. ***** ^ not supported yet
  88. 58 INC(Spot);
  89. ***** ^ undeclared identifier
  90. ***** ^ not supported yet
  91. 59 END;
  92. 60 RETURN TRUE;
  93. 61 END GetEmbeddedCard;
  94. ***** ^ not supported yet
  95. 62
  96. 63
  97. 64 PROCEDURE GetEmbeddedInt(TheStr : ARRAY OF CHAR; VAR Spot :
  98. ***** ^ not supported yet
  99. 65 CARDINAL; VAR TheInt : INTEGER) : BOOLEAN;
  100. 66 VAR
  101. 67 StrLen : CARDINAL;
  102. 68 negative : BOOLEAN;
  103. 69 BEGIN
  104. 70 TheInt := 0;
  105. 71 StrLen := M2Strings.Length(TheStr);
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. ***** ^ not supported yet
  109. 72 negative := FALSE;
  110. 73 WHILE ((Spot<StrLen) AND ((TheStr[Spot]<'0'
  111. ***** ^ not supported yet
  112. ***** ^ not supported yet
  113. 74 ) OR (TheStr[Spot]>'9'))) DO
  114. ***** ^ not supported yet
  115. ***** ^ not supported yet
  116. 75 IF TheStr[Spot]='-' THEN
  117. ***** ^ not supported yet
  118. ***** ^ not supported yet
  119. 76 negative := NOT negative;
  120. 77 (* Means negative will go back to FALSE if
  121. 78 there are two leading minus signs; may
  122. 79 not be good for much, but why not? *)
  123. 80 END;
  124. 81 INC(Spot);
  125. ***** ^ undeclared identifier
  126. ***** ^ not supported yet
  127. 82 (*Skips all leading non-numeric stuff.*)
  128. 83 END;
  129. 84 IF Spot>=StrLen THEN
  130. 85 RETURN FALSE;
  131. 86 END;
  132. 87 WHILE (Spot<StrLen) AND (TheStr[Spot]>='0'
  133. ***** ^ not supported yet
  134. ***** ^ not supported yet
  135. 88 ) AND (TheStr[Spot]<='9') DO
  136. ***** ^ not supported yet
  137. ***** ^ not supported yet
  138. 89 TheInt := TheInt*10;
  139. 90 INC(TheInt, ORD(TheStr[Spot])-48);
  140. ***** ^ undeclared identifier
  141. ***** ^ undeclared identifier
  142. ***** ^ not supported yet
  143. ***** ^ not supported yet
  144. ***** ^ not supported yet
  145. 91 INC(Spot);
  146. ***** ^ undeclared identifier
  147. ***** ^ not supported yet
  148. 92 END;
  149. 93 IF negative THEN
  150. 94 TheInt := -TheInt;
  151. 95 END;
  152. 96 RETURN TRUE;
  153. 97 END GetEmbeddedInt;
  154. ***** ^ not supported yet
  155. 98
  156. 99
  157. 100 (*$O-*)
  158. 101 (*We turn off optimization for this procedure because of a bug in
  159. 102 the beta copy of Logitech's v3.0.*)
  160. 103 PROCEDURE GetEmbeddedLongInt(TheStr : ARRAY OF CHAR; VAR Spot :
  161. ***** ^ not supported yet
  162. 104 CARDINAL; VAR TheLong : LONGINT) : BOOLEAN;
  163. 105 TYPE
  164. 106 LongAndShort =
  165. 107 RECORD
  166. 108 CASE : CHAR OF
  167. ***** ^ not supported yet
  168. ***** ^ 'POINTER' expected
  169. 109 'A' :
  170. 110 longi : LONGINT;
  171. 111 | 'B' :
  172. 112 locard, hicard : CARDINAL;
  173. 113 | 'C' :
  174. 114 loint, hiint : INTEGER;
  175. 115 END;
  176. 116 END;
  177. 117 VAR
  178. 118 positive : BOOLEAN;
  179. 119 ten : LONGINT;
  180. 120 dumlong : LongAndShort;
  181. 121 charstr : ARRAY [0..10] OF CHAR;
  182. 122 leng : CARDINAL;
  183. 123 BEGIN
  184. 124 leng := M2Strings.Length(TheStr);
  185. 125 TheLong := NumTypes.L0;
  186. 126 ten := Numbers.Lc(10);
  187. 127 positive := TRUE;
  188. 128 WHILE (Spot<leng) AND ((TheStr[Spot]<'0')
  189. 129 OR (TheStr[Spot]>'9')) DO
  190. 130 IF TheStr[Spot]='-' THEN
  191. 131 positive := FALSE;
  192. 132 END;
  193. 133 INC(Spot);
  194. 134 END;
  195. 135 IF (Spot>=leng) THEN
  196. 136 RETURN FALSE;
  197. 137 END;
  198. 138 WHILE (Spot<leng) AND ((TheStr[Spot]>='0'
  199. 139 ) AND (TheStr[Spot]<='9')) DO
  200. 140 TheLong := TheLong * ten;
  201. 141 dumlong.hicard := 0;
  202. 142 dumlong.locard := ORD(TheStr[Spot])-48;
  203. 143 TheLong := TheLong + dumlong.longi;
  204. 144 INC(Spot);
  205. 145 END;
  206. 146 IF NOT positive THEN
  207. 147 TheLong := -TheLong;
  208. 148 END;
  209. 149 RETURN TRUE;
  210. 150 END GetEmbeddedLongInt;
  211. 151 (*$O=*)
  212. 152
  213. 153
  214. 154 PROCEDURE GetEmbeddedReal(TheStr : ARRAY OF CHAR; VAR Spot :
  215. 155 CARDINAL; VAR TheReal : NumTypes.Real8): BOOLEAN;
  216. 156 CONST
  217. 157 ten = 10.0;
  218. 158 one = 1.0;
  219. 159 zero = 0.0;
  220. 160 digitsize = 16;
  221. 161 OrdZero = 48;
  222. 162 VAR
  223. 163 digit : ARRAY [1..digitsize] OF INTEGER;
  224. 164 expstr : ARRAY [0..24] OF CHAR;
  225. 165 temp, WholeNum, r, fac : NumTypes.Real8;
  226. 166 scalesign, negative : BOOLEAN;
  227. 167 scale, DigitsRightOfDec, exp : INTEGER;
  228. 168 NumOfBlanks, Zeroes, DecPt, EPos : INTEGER;
  229. 169 limit, DigitArrayIndex, j : INTEGER;
  230. 170 lngth, tmpspot : CARDINAL;
  231. 171 BEGIN
  232. 172 TheReal := 0.0;
  233. 173 exp := 0;
  234. 174 DigitsRightOfDec := 0;
  235. 175 lngth := M2Strings.Length(TheStr);
  236. 176 negative := FALSE;
  237. 177 (* First we skip to the start of something that looks
  238. 178 like a number. *)
  239. 179 WHILE (Spot<lngth) AND (TheStr[Spot]#'.') AND
  240. 180 ((TheStr[Spot]<'0') OR (TheStr[Spot]>'9')) DO
  241. 181 IF TheStr[Spot]='-' THEN
  242. 182 negative := NOT negative;
  243. 183 ELSIF TheStr[Spot]='+' THEN
  244. 184 negative := FALSE;
  245. 185 END;
  246. 186 INC(Spot);
  247. 187 END;
  248. 188 IF (Spot>=lngth) THEN
  249. 189 RETURN FALSE;
  250. 190 END;
  251. 191 DigitArrayIndex := 1;
  252. 192 WHILE (Spot<lngth) AND (DigitArrayIndex<=digitsize) AND
  253. 193 (('0'<=TheStr[Spot]) AND (TheStr[Spot]<='9')) DO
  254. 194 digit[DigitArrayIndex] := INTEGER(ORD(TheStr[Spot])-OrdZero);
  255. 195 INC(DigitArrayIndex);
  256. 196 INC(Spot);
  257. 197 END;
  258. 198
  259. 199 WholeNum := zero;
  260. 200 FOR j := 1 TO DigitArrayIndex-1 DO
  261. 201 WholeNum := WholeNum*ten + Numbers.IntToR8(digit[j]);
  262. 202 END;
  263. 203 IF negative THEN
  264. 204 TheReal := -WholeNum;
  265. 205 ELSE
  266. 206 TheReal := WholeNum;
  267. 207 END;
  268. 208
  269. 209 IF (Spot=lngth) OR ((TheStr[Spot]#'.') AND (TheStr[Spot]#'E')) THEN
  270. 210 (*We're either at the end of the string or at the end of
  271. 211 the part of it that contains a valid real number, and
  272. 212 we've found at least one numeric character, so we
  273. 213 return true. *)
  274. 214 RETURN TRUE;
  275. 215 END;
  276. 216
  277. 217 IF (TheStr[Spot]='.') THEN
  278. 218 scale := 0;
  279. 219 WholeNum := zero;
  280. 220 INC(Spot);
  281. 221 WHILE (Spot<lngth) AND (DigitArrayIndex<=digitsize) AND
  282. 222 (('0'<=TheStr[Spot]) AND (TheStr[Spot]<='9')) DO
  283. 223 temp := Numbers.IntToR8(ORD(TheStr[Spot])-OrdZero);
  284. 224 IF negative THEN
  285. 225 WholeNum := WholeNum*ten-temp;
  286. 226 ELSE
  287. 227 WholeNum := WholeNum*ten+temp;
  288. 228 END;
  289. 229 INC(scale);
  290. 230 INC(DigitArrayIndex);
  291. 231 INC(DigitsRightOfDec);
  292. 232 INC(Spot);
  293. 233 END;
  294. 234 IF WholeNum#zero THEN
  295. 235 r := WholeNum;
  296. 236 REPEAT
  297. 237 r := r/ten;
  298. 238 DEC(scale);
  299. 239 UNTIL scale=0;
  300. 240 TheReal := TheReal + r;
  301. 241 ELSE
  302. 242 scale := 0;
  303. 243 END;
  304. 244 END;
  305. 245 IF (Spot=lngth) OR (TheStr[Spot] # 'E') THEN
  306. 246 RETURN TRUE;
  307. 247 END;
  308. 248
  309. 249 IF TheStr[Spot]='E' THEN
  310. 250 INC(Spot);
  311. 251 M2Strings.Copy( TheStr, Spot, lngth - Spot, expstr );
  312. 252 IF NOT GetEmbeddedInt(expstr, Spot, exp) THEN
  313. 253 RETURN FALSE;
  314. 254 END;
  315. 255 END;
  316. 256
  317. 257 scale := DigitsRightOfDec + exp;
  318. 258 IF scale#0 THEN
  319. 259 scalesign := scale<0;
  320. 260 scale := ABS(scale);
  321. 261 IF scale>307 THEN
  322. 262 RETURN FALSE;
  323. 263 END;
  324. 264 IF TheReal # zero THEN
  325. 265 FOR tmpspot := 0 TO 8 DO
  326. 266 IF tmpspot IN BITSET(scale) THEN
  327. 267 IF scalesign THEN
  328. 268 TheReal := TheReal / NumTypes.R8TenPowers[tmpspot];
  329. 269 ELSE
  330. 270 TheReal := TheReal * NumTypes.R8TenPowers[tmpspot];
  331. 271 END;
  332. 272 END;
  333. 273 END;
  334. 274 END;
  335. 275 END;
  336. 276 RETURN TRUE;
  337. 277 END GetEmbeddedReal;
  338. 278
  339. 279
  340. 280 BEGIN
  341. 281 Initialized := FALSE;
  342. 282 Init();
  343. 283 END StrCnv1.
  344. 59 errors