IMPLEMENTATION MODULE StrCnv1; (* * REPERTOIRE * Release 1.6 * By Charles Bradford and Cole Brecheen * (c) Copyright 1985-1992 PMI * Green Bay, Wisconsin * All rights reserved * (414) 468-6040 * * $Header: D:/logfiles/mods/strcnv1.mov 1.5 10 Mar 1991 15:33:02 coleb $ * *) IMPORT M2Strings; IMPORT Numbers; IMPORT NumTypes; VAR Initialized : BOOLEAN; PROCEDURE Init(); BEGIN IF Initialized THEN RETURN; ELSE Initialized := TRUE; END; M2Strings.Init(); Numbers.Init(); NumTypes.Init(); END Init; CONST blank = ' '; PROCEDURE GetEmbeddedCard(TheStr : ARRAY OF CHAR; VAR Spot : CARDINAL; VAR TheCard : CARDINAL) : BOOLEAN; VAR StrLen : CARDINAL; BEGIN TheCard := 0; StrLen := M2Strings.Length(TheStr); WHILE ((Spot'9'))) DO INC(Spot); (*Skips all leading non-numeric stuff.*) END; IF Spot>=StrLen THEN RETURN FALSE; END; WHILE (Spot='0' ) AND (TheStr[Spot]<='9') DO TheCard := TheCard*10; INC(TheCard, ORD(TheStr[Spot])-48); INC(Spot); END; RETURN TRUE; END GetEmbeddedCard; PROCEDURE GetEmbeddedInt(TheStr : ARRAY OF CHAR; VAR Spot : CARDINAL; VAR TheInt : INTEGER) : BOOLEAN; VAR StrLen : CARDINAL; negative : BOOLEAN; BEGIN TheInt := 0; StrLen := M2Strings.Length(TheStr); negative := FALSE; WHILE ((Spot'9'))) DO IF TheStr[Spot]='-' THEN negative := NOT negative; (* Means negative will go back to FALSE if there are two leading minus signs; may not be good for much, but why not? *) END; INC(Spot); (*Skips all leading non-numeric stuff.*) END; IF Spot>=StrLen THEN RETURN FALSE; END; WHILE (Spot='0' ) AND (TheStr[Spot]<='9') DO TheInt := TheInt*10; INC(TheInt, ORD(TheStr[Spot])-48); INC(Spot); END; IF negative THEN TheInt := -TheInt; END; RETURN TRUE; END GetEmbeddedInt; (*$O-*) (*We turn off optimization for this procedure because of a bug in the beta copy of Logitech's v3.0.*) PROCEDURE GetEmbeddedLongInt(TheStr : ARRAY OF CHAR; VAR Spot : CARDINAL; VAR TheLong : LONGINT) : BOOLEAN; TYPE LongAndShort = RECORD CASE : CHAR OF 'A' : longi : LONGINT; | 'B' : locard, hicard : CARDINAL; | 'C' : loint, hiint : INTEGER; END; END; VAR positive : BOOLEAN; ten : LONGINT; dumlong : LongAndShort; charstr : ARRAY [0..10] OF CHAR; leng : CARDINAL; BEGIN leng := M2Strings.Length(TheStr); TheLong := NumTypes.L0; ten := Numbers.Lc(10); positive := TRUE; WHILE (Spot'9')) DO IF TheStr[Spot]='-' THEN positive := FALSE; END; INC(Spot); END; IF (Spot>=leng) THEN RETURN FALSE; END; WHILE (Spot='0' ) AND (TheStr[Spot]<='9')) DO TheLong := TheLong * ten; dumlong.hicard := 0; dumlong.locard := ORD(TheStr[Spot])-48; TheLong := TheLong + dumlong.longi; INC(Spot); END; IF NOT positive THEN TheLong := -TheLong; END; RETURN TRUE; END GetEmbeddedLongInt; (*$O=*) PROCEDURE GetEmbeddedReal(TheStr : ARRAY OF CHAR; VAR Spot : CARDINAL; VAR TheReal : NumTypes.Real8): BOOLEAN; CONST ten = 10.0; one = 1.0; zero = 0.0; digitsize = 16; OrdZero = 48; VAR digit : ARRAY [1..digitsize] OF INTEGER; expstr : ARRAY [0..24] OF CHAR; temp, WholeNum, r, fac : NumTypes.Real8; scalesign, negative : BOOLEAN; scale, DigitsRightOfDec, exp : INTEGER; NumOfBlanks, Zeroes, DecPt, EPos : INTEGER; limit, DigitArrayIndex, j : INTEGER; lngth, tmpspot : CARDINAL; BEGIN TheReal := 0.0; exp := 0; DigitsRightOfDec := 0; lngth := M2Strings.Length(TheStr); negative := FALSE; (* First we skip to the start of something that looks like a number. *) WHILE (Spot'9')) DO IF TheStr[Spot]='-' THEN negative := NOT negative; ELSIF TheStr[Spot]='+' THEN negative := FALSE; END; INC(Spot); END; IF (Spot>=lngth) THEN RETURN FALSE; END; DigitArrayIndex := 1; WHILE (Spot307 THEN RETURN FALSE; END; IF TheReal # zero THEN FOR tmpspot := 0 TO 8 DO IF tmpspot IN BITSET(scale) THEN IF scalesign THEN TheReal := TheReal / NumTypes.R8TenPowers[tmpspot]; ELSE TheReal := TheReal * NumTypes.R8TenPowers[tmpspot]; END; END; END; END; END; RETURN TRUE; END GetEmbeddedReal; BEGIN Initialized := FALSE; Init(); END StrCnv1.