libsimediting

NAME
libsimediting - editing/de-editing of numbers
DESCRIPTION
The following operations are offering facilities for safe
reading of input numbers. There are also some operations
that duplicate functionality of standard routines, but uses
the current value of Pos of a text where the standard
routines uses 1.
EXAMPLEexternaltextprocedureCheckReal;textT;longrealr;inimage;T:-intext(20);ifCheckReal(T)thenr:=T.GetRealelseError(Badnumber");"AUTHOR
Various people at QZ and FOA, Stockholm.
DETAILEDINTERFACECheckRealintegerprocedureCheckReal(T);nameT;textT;!Posusedandupdated.;
Considering the text from T.pos and on, if a GetReal
operation is legal the returned value is +1.
If it would give an error - then if the remaining text
string is blank, the result is 0, otherwise -1.
Pos is placed after a legal item (+1), after the first non-
blank illegal character (-1) or after the text if the rest
is empty (0).
CheckIntintegerprocedureCheckInt(T);nameT;textT;!Posusedandupdated.;
Considering the text from T.pos and on, if a GetInt
operation is legal the returned value is +1.
If it would give an error - then if the remaining text
string is blank, the result is 0, otherwise -1.
Pos is placed after a legal item (+1), after the first non-
blank illegal character (-1) or after the text if the rest
is empty (0).
ScanReallongrealprocedureScanReal(T);nameT;textT;!Posisusedandupdated.;
Scanreal is similar to GetReal, but the handling of error
conditions due to bad data is different. ScanReal returns
the value of the next real item in the text T. T.Pos will
only be moved if de-editing was successful. On Failure it
returns minlongreal (= 'minus infinity').
ScanIntintegerprocedureScanInt(T);nameT;textT;!Posisusedandupdated.;
Scanreal is similar to GetInt, but the handling of error
conditions due to bad data is different. ScanInt returns the
value of the next integer item in the text T. T.Pos will
only be moved if de-editing was successful. On Failure it
returns minint (= 'minus infinity').
GetRadixintegerprocedureGetRadix(Base,T);integerBase;!Baseusedforrepresentationof..;textT;!...thetextualrepresentationofaninteger.Posnotused.;
As GetInt, converts a text T containing digits (i.e. an
integer item) to an integer, but uses a selectable radix
Base. If Base = 16 then the characters 0123456789ABCDEF may
be used, otherwise, part of the sequence
0123456789(10)(11)(12)... may be used. Note that texts
containing illegal characters will always be (somehow)
interpreted.
RadixtextprocedureRadix(Base,I);integerBase;!radixbasetouse,8,10,16arepopular;integerI;!integertorepresentin'Base'.;
Returns a text containing the representation of I in radix
Base. Base may be negative but not -1 or zero. The
resulting text will never contain blanks. If Base = 16 then
the sequence 0123456789ABCDEF will be used, otherwise, part
of the sequence 0123456789(10)(11)(12)... will be used.
PutIntAtPosbooleanprocedurePutIntAtPos(T,I);nameT;textT;!Posusedandupdated,textchanged.;integerI;!Integertoconverttotext.;
Formats the integer I and deposits the result in the text T,
left adjusted, starting at Pos. T.pos is increased past the
stored digits. If T is not long enough, False is returned
and pos unchaged.
PutRealAtPosbooleanprocedurePutRealAtPos(T,L,N);nameT;textT;!Posusedandupdated,textchanged.;longrealL;!Realtoconverttotext.;integerN;!Numberofdigitsinresult.;
Formats the real/long real L and deposits the result in the
text T, left adjusted, starting at Pos. T.pos is increased
past the stored digits. N is the digits used (see PutReal).
If T is not long enough, False is returned and T.Pos is
unchaged.
PutTextbooleanprocedurePutText(T,String);nameT;textT;!Posusedandupdated,textchanged.;textString;!characterstoinsert.;
Puts the short word String into the long text T, starting at
Pos. T.Pos is increased to after the stored characters.
Returns False if there was not enough room in T.
GetItemtextprocedureGetItem(T);nameT;textT;!Posisusedandupdated.Resultissub-textofT;
First any blanks or tabs after T.Pos in the text are
skipped. Then the procedure reads an item. By an item is
meant either an identifier (a letter followed by letters,
digits) or a number (a series of digits which may contain
one dot) or any other character except blank. The result is
a reference to a subtext (not a copy) of T, or Notext if
there are only blanks left or pos=length+1.
Example: T="IF CAR.WHEEL_SIZE > 13.5", GetItem will return:
IF/CAR/./WHEEL/_/SIZE/>/13.5 and then Notext. Notes:
1.Thepositionoftheparameterstartsfromcurrentpos.2.Precedingblanksortabs(ifany)areskipped.3.Theresultingpositionindicatorsettingisthatfollowingthelastcharacterofthematchedword;GetSimItemtextprocedureGetSimItem(T);nameT;textT;!Posisusedandupdated.Resultissub-textofT;
Simliar to getItem but accepts also underline in
Identifiers.
First any blanks or tabs after T.Pos in the text are
skipped. Then the procedure reads an item. By an item is
meant either an identifier (a letter followed by letters,
digits, '_') or a number (a series of digits which may
contain one dot) or any other character except blank. The
result is a reference to a subtext (not a copy) of T, or
Notext if there are only blanks left or pos=length+1.
Example: T="IF CAR.WHEEL_SIZE > 13.5", GetSimItem will
return: IF/CAR/./WHEEL_SIZE/>/13.5 and then Notext. Notes:
1.Thepositionoftheparameterstartsfromcurrentpos.2.Precedingblanksortabs(ifany)areskipped.3.Theresultingpositionindicatorsettingisthatfollowingthelastcharacterofthematchedword;InItemtextprocedureInItem(FileRef);ref(File)FileRef;!reftoopenInfile(orDirectfile)object.;
Same as getItem, but for Infiles and DirectFiles. LastItem
is called first and then the result of GetItem(Image) is
returned. Notext is returned if only blanks or tabs are
left in the file or if Endfile is TRUE. Note that since the
Item:s are not copied, a call on InItem may cause Inimage
and thus overwrite of previously located items (in Image),
if they have not been copied by the program.
SimIdtextprocedureSimId(T);nameT;textT;!Posisusedandupdated,returnssub-stringofT.;
Locates and returns the subtext of the next SIMULA
identifier in T. Starting at T.Pos it skips any blanks or
tabs. If T.More still holds, an identifier is found if the
next character is a valid identifier starter according to
the Simula syntax. The value of SimId is a subtext
reference to the identifier found within T (or Notext if no
identifier was found). T.Pos is updated to past the
identifier.