next up previous
Next: libsimchario Up: libsim Previous: libsimtexts

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.

     EXAMPLE
	     external text procedure CheckReal;
	     text T; long real r;
	       inimage;
	     T:-intext(20);
	     if	CheckReal(T) then
		r:=T.GetReal
	     else Error( Bad number");"

     AUTHOR
	  Various people at QZ and FOA,	Stockholm.

     DETAILED INTERFACE
     CheckReal
	     integer procedure CheckReal(T);
	     name T; text T; ! Pos used	and updated. ;
	  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).

     CheckInt
	     integer procedure CheckInt(T);
	     name T; text T; ! Pos used	and updated. ;
	  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).

     ScanReal
	     long real procedure ScanReal(T);
	     name T; text T; ! Pos is used and updated.	;

	  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').

     ScanInt
	     integer procedure ScanInt(T);
	     name T; text T; ! Pos is used and updated.	;
	  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').

     GetRadix
	     integer procedure GetRadix(Base,T);
	     integer Base;  ! Base used	for representation of ..;
	     text T; ! ... the textual representation of an integer.
	     Pos not used.;
	  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.

     Radix
	     text procedure Radix(Base,I);
	     integer Base; ! radix base	to use,	8, 10, 16 are popular;
	     integer I;	! integer to represent in '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.

     PutIntAtPos
	     boolean procedure PutIntAtPos(T,I);
	     name T; text T; ! Pos used	and updated, text changed. ;
	     integer I;	! Integer to convert to	text. ;
	  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.

     PutRealAtPos
	     boolean procedure PutRealAtPos(T,L,N);
	     name T; text T; ! Pos used	and updated, text changed. ;
	     long real L; ! Real to convert to text. ;
	     integer N;	! Number of digits in result. ;

	  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.

     PutText
	     boolean procedure PutText(T, String);
	     name T; text T; ! Pos used	and updated, text changed. ;
	     text String; ! characters to insert. ;
	  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.

     GetItem
	     text procedure GetItem(T);
	     name T; text T; ! Pos is used and updated.	Result is
	     sub-text of T;
	  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.  The position of the parameter starts from current pos.
	   2.  Preceding blanks	or tabs	(if any) are skipped.
	   3.  The resulting position indicator	setting	is that
	       following the last character of the matched word;

     GetSimItem
	     text procedure GetSimItem(T);
	     name T; text T; ! Pos is used and updated.	Result is
	     sub-text of T;
	  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.  The position of the parameter starts from current pos.
	   2.  Preceding blanks	or tabs	(if any) are skipped.
	   3.  The resulting position indicator	setting	is that
	       following the last character of the matched word;

     InItem
	     text procedure InItem(FileRef);
	     ref(File) FileRef;	! ref to open Infile (or Directfile)
	     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.

     SimId
	     text procedure SimId(T);
	     name T; text T; ! Pos is used and updated,	returns	sub-
	     string of T.;
	  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.