| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071 |
- Listing:
- 1 IMPLEMENTATION MODULE StrConv;
- 2 (*
- 3 * REPERTOIRE
- 4 * Release 1.6
- 5 * By Charles Bradford and Cole Brecheen
- 6 * (c) Copyright 1985-1992 PMI
- 7 * Green Bay, Wisconsin
- 8 * All rights reserved
- 9 * (414) 468-6040
- 10 *
- 11 * $Header: D:/logfiles/mods/strconv.mov 1.7 10 Mar 1991 15:33:12 coleb $
- 12 *
- 13 *)
- 14
- 15
- 16 IMPORT ErrorManager;
- 17 IMPORT Key;
- 18 IMPORT LowLevel;
- 19 IMPORT M2Strings;
- 20 IMPORT Numbers;
- 21 IMPORT NumTypes;
- 22 IMPORT PosUtils;
- 23 IMPORT StrEdit;
- 24 IMPORT StringIO;
- 25 IMPORT SYSTEM;
- 26
- 27 VAR
- 28 Initialized : BOOLEAN;
- 29
- 30 CONST
- 31 blank = ' ';
- 32
- 33 VAR
- 34 ten, zero, one : NumTypes.Real8;
- ***** ^ not supported yet
- 35
- 36
- 37 PROCEDURE StrToReal(TheStr : ARRAY OF CHAR; StartingSpot :
- ***** ^ not supported yet
- 38 CARDINAL; VAR TheReal : NumTypes.Real8): BOOLEAN;
- ***** ^ not supported yet
- 39 CONST
- 40 ten = 10.0;
- 41 one = 1.0;
- 42 zero = 0.0;
- 43 digitsize = 16;
- 44 OrdZero = 48;
- 45 VAR
- 46 digit : ARRAY [1..digitsize] OF INTEGER;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 47 expstr : ARRAY [0..24] OF CHAR;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 48 temp, WholeNum, r, fac : NumTypes.Real8;
- ***** ^ not supported yet
- 49 scalesign, negative : BOOLEAN;
- 50 scale, DigitsRightOfDec, exp : INTEGER;
- 51 NumOfBlanks, Zeroes, DecPt, EPos : INTEGER;
- 52 lngth, limit, spot, DigitArrayIndex, j : INTEGER;
- 53 BEGIN
- 54 TheReal := 0.0;
- ***** ^ not supported yet
- 55 exp := 0;
- 56 DigitsRightOfDec := 0;
- 57 lngth := M2Strings.Length(TheStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 58 spot := StartingSpot;
- 59 negative := FALSE;
- 60 WHILE (spot<lngth) AND (TheStr[spot]#'.') AND
- ***** ^ not supported yet
- ***** ^ not supported yet
- 61 ((TheStr[spot]<'0') OR (TheStr[spot]>'9')) DO
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 62 IF TheStr[spot]='-' THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- 63 negative := NOT negative;
- 64 ELSIF TheStr[spot]='+' THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- 65 negative := FALSE;
- 66 END;
- 67 INC(spot);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 68 END;
- 69 IF (spot>=lngth) THEN
- 70 RETURN FALSE;
- 71 END;
- 72 DigitArrayIndex := 1;
- 73 WHILE (spot<lngth) AND (DigitArrayIndex<=digitsize) AND
- 74 (('0'<=TheStr[spot]) AND (TheStr[spot]<='9')) DO
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 75 digit[DigitArrayIndex] := INTEGER(ORD(TheStr[spot])-OrdZero);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 76 INC(DigitArrayIndex);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 77 INC(spot);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 78 END;
- 79
- 80 WholeNum := zero;
- ***** ^ not supported yet
- 81 FOR j := 1 TO DigitArrayIndex-1 DO
- 82 WholeNum := WholeNum*ten + Numbers.IntToR8(digit[j]);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 83 END;
- 84 IF negative THEN
- 85 TheReal := -WholeNum;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 86 ELSE
- 87 TheReal := WholeNum;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 88 END;
- 89
- 90 IF (spot=lngth) OR ((TheStr[spot]#'.') AND (TheStr[spot]#'E')) THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 91 (*We're either at the end of the string or at the end of
- 92 the part of it that contains a valid real number, and
- 93 we've found at least one numeric character, so we
- 94 return true. *)
- 95 RETURN TRUE;
- 96 END;
- 97
- 98 IF (TheStr[spot]='.') THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- 99 scale := 0;
- 100 WholeNum := zero;
- ***** ^ not supported yet
- 101 INC(spot);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 102 WHILE (spot<lngth)
- 103 AND (DigitArrayIndex<=digitsize)
- 104 AND PosUtils.IsNumericChar(TheStr[spot]) DO
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 105 temp := Numbers.IntToR8(ORD(TheStr[spot])-OrdZero);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 106 (* Every time we find a new digit right of the
- 107 decimal point, we essentially slide the number
- 108 thus far to the left one digit by multiplying
- 109 it by ten, and then we add this new digit as if
- 110 it were going to be the least significant digit
- 111 in the final number. WholeNum is the temporary
- 112 representation of the fractional part of the
- 113 real number. *)
- 114 IF negative THEN
- 115 WholeNum := (WholeNum * ten) - temp;
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 116 ELSE
- 117 WholeNum := (WholeNum * ten) + temp;
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 118 END;
- 119 INC(scale);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 120 INC(DigitArrayIndex);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 121 INC(DigitsRightOfDec);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 122 INC(spot);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 123 END;
- 124 IF WholeNum # zero THEN
- ***** ^ not supported yet
- 125 r := WholeNum;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 126 (* We kept track in the variable scale of how many times
- 127 we multiplied the fractional part by ten to make it
- 128 a whole number. Now we divide by ten that number of
- 129 times to get it back down to what it really is. *)
- 130 REPEAT
- 131 r := r/ten;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 132 DEC(scale);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 133 UNTIL scale=0;
- 134 (* Now add the fractional part to the whole number part. *)
- 135 TheReal := TheReal + r;
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 136 ELSE
- 137 scale := 0;
- 138 END;
- 139 (* Now we have to worry about the possibility that the number
- 140 is in scientific notation. Note that spot starts out
- 141 sitting on the first non-numeric character after the
- 142 fractional part of the number. *)
- 143 WHILE (spot<lngth)
- 144 AND PosUtils.IsWhiteSpace(TheStr[spot]) DO
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 145 INC(spot);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 146 END;
- 147 END;
- 148 IF (spot = lngth) THEN
- 149 RETURN TRUE;
- 150 END;
- 151 IF (TheStr[spot] # 'E') THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- 152 RETURN TRUE;
- 153 END;
- 154
- 155 INC(spot);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 156 M2Strings.Copy( TheStr, spot, lngth - spot, expstr );
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 157 IF NOT StrToInteger(expstr, 0, exp) THEN
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- 158 RETURN FALSE;
- 159 END;
- 160
- 161 scale := DigitsRightOfDec + exp;
- 162 IF scale#0 THEN
- 163 scalesign := scale<0;
- 164 scale := ABS(scale);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 165 IF scale>307 THEN
- 166 RETURN FALSE;
- 167 END;
- 168 IF TheReal # zero THEN
- ***** ^ not supported yet
- 169 FOR spot := 0 TO 8 DO
- 170 IF CARDINAL(spot) IN BITSET(scale) THEN
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 171 IF scalesign THEN
- 172 TheReal := TheReal / NumTypes.R8TenPowers[spot];
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 173 ELSE
- 174 TheReal := TheReal * NumTypes.R8TenPowers[spot];
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 175 END;
- 176 END;
- 177 END;
- 178 END;
- 179 END;
- 180 RETURN TRUE;
- 181 END StrToReal;
- ***** ^ not supported yet
- 182
- 183
- 184 PROCEDURE AppendDecoded(VAR TheStr : ARRAY OF CHAR; TheCodeChar : CHAR;
- ***** ^ not supported yet
- 185 StrConst : ARRAY OF CHAR);
- ***** ^ not supported yet
- 186 VAR
- 187 CharNum, spot1, spot2 : CARDINAL;
- 188 TmpStr : ARRAY [0..255] OF CHAR;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 189 tmpchar : CHAR;
- 190 BEGIN
- 191 spot2 := M2Strings.Pos(TheCodeChar,StrConst);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 192 spot1 := 0;
- 193 WHILE spot2<=HIGH(StrConst) DO
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 194 IF spot2>spot1 THEN
- 195 M2Strings.Copy(StrConst, spot1, spot2-spot1, TmpStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 196 StrEdit.Append(TheStr, TmpStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 197 (* Copies everything from the start of StrConst, or from
- 198 the end of the last CharCode, into TheStr. *)
- 199 END;
- 200 IF NOT StrToCardinal(StrConst,spot2+1,CharNum) THEN
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- 201 ErrorManager.WARN('Invalid string in AppendDecoded');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 202 END;
- 203 tmpchar := CHR(CharNum);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 204 StrEdit.Append(TheStr, tmpchar);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 205 spot1 := spot2+4;
- 206 spot2 := PosUtils.Positn(TheCodeChar,StrConst,spot2+1);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 207 END;
- 208 IF spot1< M2Strings.Length(StrConst) THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 209 M2Strings.Copy(StrConst, spot1, M2Strings.Length(StrConst)-spot1, TmpStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 210 StrEdit.Append(TheStr, TmpStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 211 END;
- 212 END AppendDecoded;
- ***** ^ not supported yet
- 213
- 214 PROCEDURE CardinalToStr(TheNum : CARDINAL; width : CARDINAL; VAR
- 215 TheStr : ARRAY OF CHAR);
- ***** ^ not supported yet
- 216 VAR
- 217 spot : INTEGER;
- 218 tmp : ARRAY [0..80] OF CHAR;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 219 BEGIN
- 220 LowLevel.Fill(SYSTEM.ADR(TheStr), 1+HIGH(TheStr), blank);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- 221 (*Fill TheStr with spaces.*)
- 222 spot := HIGH(TheStr);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 223 REPEAT
- 224 TheStr[spot] := CHR((TheNum MOD 10)+48);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 225 TheNum := TheNum DIV 10;
- 226 DEC(spot);
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 227 UNTIL (TheNum<10) OR (spot<=0);
- 228 IF TheNum#0 THEN
- 229 TheStr[spot] := CHR(TheNum+48);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- 230 END;
- 231 IF M2Strings.Length(TheStr)>width THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 232 StrEdit.CutLeadingChars(' ', TheStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 233 END;
- 234 IF M2Strings.Length(TheStr)<width THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 235 LowLevel.Fill(SYSTEM.ADR(tmp), 1+HIGH(tmp), blank);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- 236 StrEdit.SetLength(tmp, width-M2Strings.Length(TheStr));
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 237 StrEdit.Append(tmp, TheStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 238 M2Strings.Assign(tmp, TheStr);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 239 END;
- 240 END CardinalToStr;
- ***** ^ not supported yet
- 241
- 242 PROCEDURE IntegerToStr(TheNum : INTEGER; width : CARDINAL; VAR
- 243 TheStr : ARRAY OF CHAR);
- ***** ^ not supported yet
- 244 VAR
- 245 spot : CARDINAL;
- 246 BEGIN
- 247 CardinalToStr(ABS(TheNum), width, TheStr);
- ***** ^ not supported yet
- ***** ^ undeclared identifier
- ***** ^ not supported yet
- ***** ^ not supported yet
- 248 IF TheNum<0 THEN
- 249 spot := LowLevel.ScanNE( M2Strings.Length(TheStr), blank,
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 250 SYSTEM.ADR(TheStr) );
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 251 (* find the first nonblank *)
- 252 IF spot>0 THEN
- 253 (* We do this to preserve the correct width,
- 254 if possible. *)
- 255 TheStr[spot-1] := '-';
- ***** ^ not supported yet
- ***** ^ not supported yet
- 256 ELSE
- 257 M2Strings.Insert('-', TheStr, spot);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 258 END;
- 259 END;
- 260 END IntegerToStr;
- ***** ^ not supported yet
- 261
- 262
- 263 TYPE
- 264 LongAndShort =
- 265 RECORD
- 266 CASE : CHAR OF
- ***** ^ not supported yet
- ***** ^ 'POINTER' expected
- 267 'A' :
- 268 longi : LONGINT;
- 269 | 'B' :
- 270 locard, hicard : CARDINAL;
- 271 | 'C' :
- 272 loint, hiint : INTEGER;
- 273 END;
- 274 END;
- 275 VAR
- 276 TenPowers : ARRAY [0..9] OF LongAndShort;
- 277
- 278 PROCEDURE LongIntegerToStr(TheNum : LONGINT; width : CARDINAL;
- 279 VAR TheStr : ARRAY OF CHAR);
- 280 VAR
- 281 LongConv : LongAndShort;
- 282 positive : BOOLEAN;
- 283 charstr : ARRAY [0..80] OF CHAR;
- 284 i : CARDINAL;
- 285 tmpchar: CHAR;
- 286 BEGIN
- 287 LongConv.longi := TheNum;
- 288 IF LongConv.hiint < 0 THEN
- 289 TheNum := -TheNum;
- 290 positive := FALSE;
- 291 ELSE
- 292 positive := TRUE;
- 293 END;
- 294 (* Fill(ADR(charstr), 10, '0'); replaced below *)
- 295 charstr[10] := 0C;
- 296 FOR i := 0 TO 9 DO
- 297 tmpchar := '0';
- 298 WHILE NOT (TheNum < TenPowers[i].longi) DO
- 299 INC( tmpchar);
- 300 TheNum := TheNum - TenPowers[i].longi;
- 301 END;
- 302 charstr[i] := tmpchar;
- 303 END;
- 304 StrEdit.CutLeadingChars('0', charstr);
- 305 IF NOT positive THEN
- 306 M2Strings.Insert('-', charstr, 0);
- 307 END;
- 308 IF charstr[0]=0C THEN
- 309 charstr[0] := '0';
- 310 charstr[1] := 0C;
- 311 END;
- 312 M2Strings.Assign(charstr, TheStr);
- 313 IF M2Strings.Length(TheStr)<width THEN
- 314 LowLevel.Fill(SYSTEM.ADR(charstr), 1+HIGH(charstr), blank);
- 315 StrEdit.SetLength(charstr, width-M2Strings.Length(TheStr));
- 316 StrEdit.Append(charstr, TheStr);
- 317 M2Strings.Assign(charstr, TheStr);
- 318 END;
- 319 END LongIntegerToStr;
- 320
- 321
- 322 (*$O-*)
- 323 (*We turn off optimization for this procedure because of a bug in
- 324 the beta copy of Logitech's v3.0.*)
- 325 PROCEDURE StrToLongInteger(TheStr : ARRAY OF CHAR; StartingSpot :
- 326 CARDINAL; VAR TheLong : LONGINT) : BOOLEAN;
- 327 VAR
- 328 positive : BOOLEAN;
- 329 ten : LONGINT;
- 330 dumlong : LongAndShort;
- 331 charstr : ARRAY [0..10] OF CHAR;
- 332 leng : CARDINAL;
- 333 BEGIN
- 334 leng := M2Strings.Length(TheStr);
- 335 TheLong := NumTypes.L0;
- 336 ten := Numbers.Lc(10);
- 337 positive := TRUE;
- 338 WHILE (StartingSpot<leng) AND ((TheStr[StartingSpot]<'0')
- 339 OR (TheStr[StartingSpot]>'9')) DO
- 340 IF TheStr[StartingSpot]='-' THEN
- 341 positive := FALSE;
- 342 END;
- 343 INC(StartingSpot);
- 344 END;
- 345 IF (StartingSpot>=leng) THEN
- 346 RETURN FALSE;
- 347 END;
- 348 WHILE (StartingSpot<leng) AND ((TheStr[StartingSpot]>='0'
- 349 ) AND (TheStr[StartingSpot]<='9')) DO
- 350 TheLong := TheLong * ten;
- 351 dumlong.hicard := 0;
- 352 dumlong.locard := ORD(TheStr[StartingSpot])-48;
- 353 TheLong := TheLong + dumlong.longi;
- 354 INC(StartingSpot);
- 355 END;
- 356 IF NOT positive THEN
- 357 TheLong := -TheLong;
- 358 END;
- 359 RETURN TRUE;
- 360 END StrToLongInteger;
- 361 (*$O=*)
- 362
- 363
- 364 PROCEDURE StrToCardinal(TheStr : ARRAY OF CHAR; StartingSpot :
- 365 CARDINAL; VAR TheCard : CARDINAL) : BOOLEAN;
- 366 VAR
- 367 spot, StrLen : CARDINAL;
- 368 BEGIN
- 369 spot := StartingSpot;
- 370 TheCard := 0;
- 371 StrLen := M2Strings.Length(TheStr);
- 372 WHILE ((spot<StrLen) AND ((TheStr[spot]<'0'
- 373 ) OR (TheStr[spot]>'9'))) DO
- 374 INC(spot);
- 375 (*Skips all leading non-numeric stuff.*)
- 376 END;
- 377 IF spot>=StrLen THEN
- 378 RETURN FALSE;
- 379 END;
- 380 WHILE (spot<StrLen) AND (TheStr[spot]>='0'
- 381 ) AND (TheStr[spot]<='9') DO
- 382 TheCard := TheCard*10;
- 383 INC(TheCard, ORD(TheStr[spot])-48);
- 384 INC(spot);
- 385 END;
- 386 RETURN TRUE;
- 387 END StrToCardinal;
- 388
- 389
- 390 PROCEDURE StrToInteger(TheStr : ARRAY OF CHAR; StartingSpot :
- 391 CARDINAL; VAR TheInt : INTEGER) : BOOLEAN;
- 392 VAR
- 393 spot, StrLen : CARDINAL;
- 394 negative : BOOLEAN;
- 395 BEGIN
- 396 spot := StartingSpot;
- 397 TheInt := 0;
- 398 StrLen := M2Strings.Length(TheStr);
- 399 negative := FALSE;
- 400 WHILE ((spot<StrLen) AND ((TheStr[spot]<'0'
- 401 ) OR (TheStr[spot]>'9'))) DO
- 402 IF TheStr[spot]='-' THEN
- 403 negative := NOT negative;
- 404 (* Means negative will go back to FALSE if
- 405 there are two leading minus signs; may
- 406 not be good for much, but why not? *)
- 407 END;
- 408 INC(spot);
- 409 (*Skips all leading non-numeric stuff.*)
- 410 END;
- 411 IF spot>=StrLen THEN
- 412 RETURN FALSE;
- 413 END;
- 414 WHILE (spot<StrLen) AND (TheStr[spot]>='0'
- 415 ) AND (TheStr[spot]<='9') DO
- 416 TheInt := TheInt*10;
- 417 INC(TheInt, ORD(TheStr[spot])-48);
- 418 INC(spot);
- 419 END;
- 420 IF negative THEN
- 421 TheInt := -TheInt;
- 422 END;
- 423 RETURN TRUE;
- 424 END StrToInteger;
- 425
- 426
- 427 PROCEDURE DateToStr(month, day, year : CARDINAL; VAR TheStr :
- 428 ARRAY OF CHAR);
- 429 VAR
- 430 DayStr, MnthStr, YrStr : ARRAY [0..15] OF CHAR;
- 431 BEGIN
- 432 CardinalToStr(day, 2, DayStr);
- 433 IF DayStr[0]=' ' THEN
- 434 DayStr[0] := '0';
- 435 END;
- 436 CardinalToStr(month, 2, MnthStr);
- 437 CardinalToStr(year, 2, YrStr);
- 438 IF M2Strings.Length(YrStr)=4 THEN
- 439 (*Delete the '19' if it is present.*)
- 440 M2Strings.Delete(YrStr, 0, 2);
- 441 END;
- 442 M2Strings.Assign(MnthStr, TheStr);
- 443 StrEdit.Append(TheStr, '-');
- 444 StrEdit.Append(TheStr, DayStr);
- 445 StrEdit.Append(TheStr, '-');
- 446 StrEdit.Append(TheStr, YrStr);
- 447 END DateToStr;
- 448
- 449
- 450 PROCEDURE TimeToStr(hours, minutes, seconds, hundredths : CARDINAL;
- 451 VAR TheStr : ARRAY OF CHAR);
- 452 VAR
- 453 HundrStr, SecStr, MinStr, HourStr : ARRAY [0..20] OF CHAR;
- 454 pm : BOOLEAN;
- 455 BEGIN
- 456 CardinalToStr(hundredths, 2, HundrStr);
- 457 IF HundrStr[0]=' ' THEN
- 458 HundrStr[0] := '0';
- 459 END;
- 460 CardinalToStr(seconds, 2, SecStr);
- 461 IF SecStr[0]=' ' THEN
- 462 SecStr[0] := '0';
- 463 END;
- 464 CardinalToStr(minutes, 2, MinStr);
- 465 IF MinStr[0]=' ' THEN
- 466 MinStr[0] := '0';
- 467 END;
- 468 pm := hours>=12;
- 469 (* 10 July 87: changed from hours > 12 at suggestion of
- 470 H. A. Hofmans to correct problem with the first noon
- 471 hour being called am. *)
- 472 IF hours>12 THEN
- 473 DEC(hours, 12);
- 474 END;
- 475 CardinalToStr(hours, 2, HourStr);
- 476 M2Strings.Assign(HourStr, TheStr);
- 477 StrEdit.Append(TheStr, ':');
- 478 StrEdit.Append(TheStr, MinStr);
- 479 StrEdit.Append(TheStr, ':');
- 480 StrEdit.Append(TheStr, SecStr);
- 481 StrEdit.Append(TheStr, ':');
- 482 StrEdit.Append(TheStr, HundrStr);
- 483 IF pm THEN
- 484 StrEdit.Append(TheStr, 'p');
- 485 ELSE
- 486 StrEdit.Append(TheStr, 'a');
- 487 END;
- 488 END TimeToStr;
- 489
- 490
- 491 PROCEDURE RealToStr( TheNum: NumTypes.Real8; DigitsRightOfDec,
- 492 width: INTEGER; VAR TheStr: ARRAY OF CHAR);
- 493
- 494 CONST
- 495 ten = 10.0;
- 496 one = 1.0;
- 497 zero = 0.0;
- 498 VAR
- 499 spot : CARDINAL;
- 500 i, exp : INTEGER;
- 501 expstr : ARRAY [0..6] OF CHAR;
- 502 tmpstr : ARRAY [0..31] OF CHAR;
- 503
- 504 PROCEDURE PutDigit(VAR r : NumTypes.Real8);
- 505 VAR
- 506 dig : LONGINT;
- 507 d : CARDINAL;
- 508 WholePart : NumTypes.Real8;
- 509 BEGIN
- 510 dig := Numbers.R8ToL(r);
- 511 d := Numbers.C(dig);
- 512 tmpstr[spot] := CHR(d+ORD('0'));
- 513 INC(spot);
- 514 WholePart := Numbers.LToR8(dig);
- 515 r := r - WholePart;
- 516 END PutDigit;
- 517
- 518 BEGIN
- 519 LowLevel.Fill(SYSTEM.ADR(tmpstr), 1+HIGH(tmpstr), 0C);
- 520 (*Fill tmpstr with nulls.*)
- 521 spot := 0;
- 522 IF TheNum<zero THEN
- 523 tmpstr[spot] := '-';
- 524 INC(spot);
- 525 TheNum := -TheNum;
- 526 END;
- 527 exp := 0;
- 528 IF TheNum#zero THEN
- 529 LOOP
- 530 IF TheNum<one THEN
- 531 TheNum := TheNum*ten;
- 532 DEC(exp);
- 533 ELSIF TheNum>=ten THEN
- 534 TheNum := TheNum/ten;
- 535 INC(exp);
- 536 ELSE
- 537 EXIT;
- 538 END;
- 539 END;
- 540 END;
- 541 PutDigit(TheNum);
- 542 tmpstr[spot] := '.';
- 543 INC(spot);
- 544 FOR i := 1 TO 15 DO
- 545 TheNum := TheNum*ten;
- 546 PutDigit(TheNum);
- 547 END;
- 548 tmpstr[spot] := 'E';
- 549 IntegerToStr(exp, 0, expstr);
- 550 StrEdit.Append(tmpstr, expstr);
- 551 IF DigitsRightOfDec < 0 THEN
- 552 RETURN;
- 553 END;
- 554 IF NOT ScientificToPlain( tmpstr, DigitsRightOfDec,
- 555 width, TheStr ) THEN
- 556 ErrorManager.WARN('Invalid real');
- 557 END;
- 558 END RealToStr;
- 559
- 560
- 561 PROCEDURE ReturnedCard( TheStr: ARRAY OF CHAR ):
- 562 CARDINAL;
- 563 VAR
- 564 tmpc: CARDINAL;
- 565 BEGIN
- 566 IF NOT StrToCardinal( TheStr, 0, tmpc ) THEN
- 567 StrEdit.Append( TheStr, ' # number' );
- 568 ErrorManager.WARN( TheStr );
- 569 END;
- 570 RETURN tmpc;
- 571 END ReturnedCard;
- 572
- 573 PROCEDURE ReturnedInt( TheStr: ARRAY OF CHAR ):
- 574 INTEGER;
- 575 VAR
- 576 tmpi: INTEGER;
- 577 BEGIN
- 578 IF NOT StrToInteger( TheStr, 0, tmpi ) THEN
- 579 StrEdit.Append( TheStr, ' # number' );
- 580 ErrorManager.WARN( TheStr );
- 581 END;
- 582 RETURN tmpi;
- 583 END ReturnedInt;
- 584
- 585
- 586 PROCEDURE ScientificToPlain(scientific : ARRAY OF CHAR;
- 587 DigitsToRight, width : CARDINAL; VAR plain : ARRAY OF CHAR) :
- 588 BOOLEAN;
- 589 VAR
- 590 RoundSpot, lngth, FirstSpot, eSpot, DotSpot,
- 591 ProperNumOfDigits : CARDINAL;
- 592 cnt, DecimalShift : INTEGER;
- 593 tmpstr : ARRAY [0..79] OF CHAR;
- 594 carrying : BOOLEAN;
- 595 e, dot, space, zero : ARRAY [0..0] OF CHAR;
- 596 (* We use these instead of CHAR constants because this
- 597 procedure was actually written for the ITC version.
- 598 See CharStuf module chapter for explanation. *)
- 599 BEGIN
- 600 e[0] := 'E';
- 601 dot[0] := '.';
- 602 space[0] := ' ';
- 603 zero[0] := '0';
- 604 eSpot := M2Strings.Pos(e,scientific);
- 605 IF NOT StrToInteger(scientific, eSpot, DecimalShift) THEN
- 606 RETURN FALSE;
- 607 END;
- 608 M2Strings.Assign(scientific, tmpstr);
- 609 M2Strings.Delete(tmpstr, eSpot,
- 610 (M2Strings.Length(tmpstr) - eSpot) + 1);
- 611 DotSpot := M2Strings.Pos(dot,tmpstr);
- 612 IF DotSpot>HIGH(tmpstr) THEN
- 613 RETURN FALSE;
- 614 ELSE
- 615 M2Strings.Delete(tmpstr, DotSpot, 1);
- 616 END;
- 617 IF tmpstr[0]='-' THEN
- 618 FirstSpot := 1;
- 619 ELSE
- 620 FirstSpot := 0;
- 621 END;
- 622 IF DecimalShift>=0 THEN
- 623 DotSpot := DotSpot + CARDINAL(DecimalShift);
- 624 ELSE
- 625 DecimalShift := -DecimalShift;
- 626 FOR cnt := 1 TO DecimalShift DO
- 627 M2Strings.Insert(zero, tmpstr, FirstSpot);
- 628 END;
- 629 DotSpot := FirstSpot + 1;
- 630 END;
- 631 ProperNumOfDigits := (DotSpot + DigitsToRight);
- 632 lngth := M2Strings.Length(tmpstr) + 1;
- 633 IF lngth > ProperNumOfDigits THEN
- 634 IF LowLevel.ScanNE( ProperNumOfDigits, '9', SYSTEM.ADR(tmpstr)
- 635 ) < INTEGER(ProperNumOfDigits) THEN
- 636 (*We can round up without extending length of string.*)
- 637 RoundSpot := ProperNumOfDigits;
- 638 carrying := FALSE;
- 639 WHILE RoundSpot > 0 DO
- 640 IF (tmpstr[RoundSpot] >= '5') OR carrying THEN
- 641 INC( tmpstr[RoundSpot - 1] );
- 642 carrying := FALSE;
- 643 END;
- 644 DEC(RoundSpot);
- 645 IF tmpstr[RoundSpot] = ':' THEN
- 646 (*We tried to round up a 9.*)
- 647 carrying := TRUE;
- 648 tmpstr[RoundSpot] := '0';
- 649 ELSIF tmpstr[RoundSpot] = '/' THEN
- 650 carrying := TRUE;
- 651 (*We meant to round up the first digit to the
- 652 left of the decimal point, but actually rounded up
- 653 the decimal point itself. The carrying flag
- 654 will correct it next time through.*)
- 655 tmpstr[RoundSpot] := '.';
- 656 ELSE
- 657 RoundSpot := 0;
- 658 (*Forces us out of the loop.*)
- 659 END;
- 660 END;
- 661 END;
- 662 M2Strings.Delete(tmpstr, ProperNumOfDigits, lngth-ProperNumOfDigits);
- 663 lngth := ProperNumOfDigits + 1;
- 664 ELSE
- 665 WHILE (ProperNumOfDigits + 1) > lngth DO
- 666 StrEdit.Append(tmpstr, zero);
- 667 INC(lngth);
- 668 END;
- 669 END;
- 670 M2Strings.Insert(dot, tmpstr, DotSpot);
- 671 (*We postpone insertion of the dot so that we can scan
- 672 for non-9's above.*)
- 673 WHILE (lngth<width) AND (lngth < (HIGH(tmpstr)+1)) DO
- 674 M2Strings.Insert(space, tmpstr, 0);
- 675 INC(lngth);
- 676 END;
- 677 M2Strings.Assign(tmpstr, plain);
- 678 RETURN TRUE;
- 679 END ScientificToPlain;
- 680
- 681
- 682 PROCEDURE OldSetFormToNew( OldFormStr: ARRAY OF CHAR; VAR
- 683 NewFormStr: ARRAY OF CHAR );
- 684 (* This procedure will be deleted in the next release. *)
- 685 VAR
- 686 tmpcard, last, cnt: CARDINAL;
- 687 tmpstr, tmpstr2: ARRAY [0..79] OF CHAR;
- 688
- 689 PROCEDURE GetSymbol( VAR TheSymbol: ARRAY OF CHAR );
- 690 VAR
- 691 s: ARRAY [0..0] OF CHAR;
- 692 InQuote : BOOLEAN;
- 693 WhichQuote : CHAR;
- 694 BEGIN
- 695 TheSymbol[0] := 0C;
- 696 IF OldFormStr[cnt] = '.' THEN
- 697 StrEdit.Append( TheSymbol, '..' );
- 698 INC( cnt );
- 699 RETURN;
- 700 END;
- 701 s[0] := OldFormStr[cnt];
- 702 InQuote := FALSE;
- 703 WhichQuote := 0C;
- 704 REPEAT
- 705 IF InQuote OR (NOT PosUtils.Present(s, ';.')) THEN
- 706 StrEdit.Append( TheSymbol, s );
- 707 END;
- 708 IF (s[0] = '"') OR (s[0] = "'") THEN
- 709 IF InQuote THEN
- 710 IF (WhichQuote = s[0]) THEN
- 711 InQuote := FALSE;
- 712 END;
- 713 ELSE
- 714 InQuote := TRUE;
- 715 WhichQuote := s[0];
- 716 END
- 717 END;
- 718 INC( cnt );
- 719 IF cnt <= last THEN
- 720 s[0] := OldFormStr[cnt];
- 721 END;
- 722 UNTIL (cnt > last) OR ( (NOT InQuote) AND PosUtils.Present(s,
- 723 ';.') );
- 724 INC( cnt );
- 725 StrEdit.CrunchBlanks( TheSymbol );
- 726 END GetSymbol;
- 727
- 728 BEGIN
- 729 last := M2Strings.Length( OldFormStr );
- 730 IF last > 0 THEN
- 731 DEC( last );
- 732 ELSE
- 733 StrEdit.AssignStr( "{0..400}", NewFormStr );
- 734 RETURN;
- 735 END;
- 736 StrEdit.AssignStr( "{", NewFormStr );
- 737 cnt := 0;
- 738 REPEAT
- 739 GetSymbol( tmpstr );
- 740 IF CAP(tmpstr[0]) = 'E' THEN
- 741 IF NOT StrToCardinal( tmpstr, 1, tmpcard ) THEN
- 742 ErrorManager.WARN('Bad set string.');
- 743 END;
- 744 INC( tmpcard, Key.Extended );
- 745 CardinalToStr( tmpcard, 0, tmpstr2 );
- 746 StrEdit.Append( NewFormStr, tmpstr2 );
- 747 ELSE
- 748 (*These should always be numbers or ellipses.*)
- 749 IF (tmpstr[0] = '.') THEN
- 750 M2Strings.Delete( NewFormStr,
- 751 M2Strings.Length(NewFormStr) - 1, 1 );
- 752 (*delete the comma appended in the last loop*)
- 753 END;
- 754 StrEdit.Append( NewFormStr, tmpstr );
- 755 END;
- 756 IF (cnt <= last) AND (tmpstr[0] # '.') THEN
- 757 StrEdit.Append( NewFormStr, ',' );
- 758 END;
- 759 UNTIL cnt > last;
- 760 StrEdit.Append( NewFormStr, "}" );
- 761 END OldSetFormToNew;
- 762
- 763
- 764 PROCEDURE Init();
- 765 VAR
- 766 i : CARDINAL;
- 767 BEGIN
- 768 IF Initialized THEN
- 769 RETURN;
- 770 ELSE
- 771 Initialized := TRUE;
- 772 END;
- 773 ErrorManager.Init();
- 774 Key.Init();
- 775 LowLevel.Init();
- 776 M2Strings.Init();
- 777 Numbers.Init();
- 778 NumTypes.Init();
- 779 PosUtils.Init();
- 780 StrEdit.Init();
- 781
- 782 (*EntryDiag:
- 783 StringIO.WriteEol( 1, 'Entering StrConv' );
- 784 :EntryDiag*)
- 785
- 786 FOR i := 5 TO 9 DO
- 787 TenPowers[i].hicard := 0;
- 788 END;
- 789 TenPowers[9].locard := 1;
- 790 TenPowers[8].locard := 10;
- 791 TenPowers[7].locard := 100;
- 792 TenPowers[6].locard := 1000;
- 793 TenPowers[5].locard := 10000;
- 794 TenPowers[4].locard := 34464; (* 100,000 *)
- 795 TenPowers[3].locard := 16960; (* 1,000,000 *)
- 796 TenPowers[2].locard := 38528; (* 10,000,000 *)
- 797 TenPowers[1].locard := 57600; (* 100,000,000 *)
- 798 TenPowers[0].locard := 51712; (* 1,000,000,000 *)
- 799 TenPowers[4].hicard := 1; (* 100,000 *)
- 800 TenPowers[3].hicard := 15; (* 1,000,000 *)
- 801 TenPowers[2].hicard := 152; (* 10,000,000 *)
- 802 TenPowers[1].hicard := 1525; (* 100,000,000 *)
- 803 TenPowers[0].hicard := 15258; (* 1,000,000,000 *)
- 804
- 805 (*EntryDiag:
- 806 StringIO.WriteEol( 1, 'Exiting StrConv' );
- 807 :EntryDiag*)
- 808 END Init;
- 809
- 810 BEGIN
- 811 Initialized := FALSE;
- 812 Init();
- 813 END StrConv.
- 252 errors
|