home *** CD-ROM | disk | FTP | other *** search
- {
- [ENVIRONMENT('VaxTurbo')]
- MODULE VaxTurbo ( output );
- }
-
- TYPE LString = VARYING [2048] OF CHAR;
-
- { Suplementry String functions and procedures for Turbo Pascal }
- { Extended for VAX Pascal - wml }
- (*
- Written by: Tryg Helseth
- Minneapolis, Minnesota
-
- Last Revision: 1/4/85
-
- Revised for VAX Pascal by:
- Walter M. Lamia
- Digital Equipment Corp.
- Nashua, NH.
-
- May 8, 1986
-
-
- USAGE NOTES:
-
- The following routines provide common string functions that are
- not supplied with Turbo Pascal. Many are patterned (and named)
- after the General Electric Information Service COompany (GEISCO)
- FORTRAN 77 string routines; others mimic SNOBOL primatives.
-
- The general calling sequence is:
-
- OutString := Func(InpString[,Parms])
-
- where:
-
- OutString = the output or target string,
- Func = function name,
- InpStr = Input String,
- [Parms] = Additional parameter(s) used by some functions.
-
- AVAILABLE FUNCTIONS:
-
- # Copy Emulates Turbo Pascal Copy built-in.
- ## Pos_ Emulates Turbo Pascal Pos built-in.
- ** Str Converts numeric value to string -- INTEGER ONLY VERSION.
- ** Val Converts string expression to numeric value -- INTEGER ONLY.
-
- LoCase Convert a single character to lower case.
- # UpCase Convert a single character to upper case.
- LowerCase Convert a string to lower case.
- UpperCase Convert a string to upper case.
- TrimL Trim Left: remove leading spaces from a string.
- TrimR Trim Right: remove trailing spaces from a string.
- PadL Pad Left: Add leading spaces to give desired field length.
- PadR Pad Right: Add trailing spaces to give desired field length.
- JustL Left Justify a string within a desired field length.
- JustR Right Justify a string within a desired field length.
- Center Center a string within a desired field length.
- GetStr Get String: Extracts a substring up to a specified delimiter.
- Break Extracts a substring up to the first of several delimters.
- Span Extracts a substring of delimiters up to a NON delimiter.
- Compress Replaces whitespace (tabs and/or spaces) with single space.
- Squish Trims off leading, trailing spaces and compresses.
-
- Note: GetStr, Span, and Break, modify the input string. The other
- functions do not modify any parameters.
-
- AVAILABLE PROCEDURES:
-
- ## Delete_ Emulates Turbo Pascal Delete built-in.
-
- # Insert Emulates Turbo Pascal Insert built-in.
-
- GString Get String: Used by Span and Break functions. It performs
- both functions and allows more control by the programmer.
-
- Substitute Replace one substring with another in target string.
-
- ** RealStr Convert a value of type REAL to a string representation in
- ** any base from 2 to 36.
- **
- ** RealVal Convert a string representation of a number to a REAL value.
- ** The number may be in any base from 2 to 36.
- **
-
- # ==> emulations of Turbo built-in's in VAX Pascal
- ## ==> emulations, but with "_" appended to name to avoid VAX Pascal conflicts
- ** ==> changed in VAX Pascal version to use WRITEV and READV built-ins.
-
-
- TYPE DECLARATION:
-
- All strings are of the type, LString, which should be declared in the main
- program as:
-
- Type LString = string[n] <== for Turbo Pascal
- Type LString = VARYING [n] OF CHAR <== for VAX Pascal
-
- where n is a constant in the range of 1 to 255 for Turbo Pascal
- " " " " " " " " " 1 to 65535 for VAX Pascal.
-
- If you wish to use these functions with strings of different declared
- lengths, then you must use the compiler option, $V- (Turbo Pascal),
- or the [UNSAFE] VAX Pascal attribute on function and formal parameter
- declarations (not recommended).
-
- If you choose to do this, be sure that the defined length of LString is
- greater than or equal to the longest string you will be using.
- *)
- (* STRING FUNCTION DECLARATIONS: *)
- {===========================================}
- procedure Delete_ (VAR InpStr : LString;
- FieldPos : Integer;
- FieldLen : Integer); forward;
- {===========================================}
- {
- N.B. -- Name is "Delete_" to avoid conflict with VAX Delete I/O procedure.
-
- Purpose: Provide same function as Turbo Pascal Delete procedure.
-
- Remove substring starting at FieldPos, containing
- FieldLen characters.
-
- If FieldPos > length(InpStr), no characters are removed.
- If FieldLen extends beyond end-of-string, only characters
- within the string are deleted.
-
- St := 'ABCEDFG';
- Delete_(St,2,4); ==> St value of 'AFG'
- Delete_(St,2,10); ==> St value of 'A'
-
- Parameters:
- Input: InpStr = string from which substring will be removed.
- FieldPos = starting position of substring to remove.
- FieldLen = length of substring to remove.
-
- Output: Modified InpStr, with substring removed.
- }
-
- {===========================================}
- procedure Insert ( ObjStr : LString;
- VAR InpStr : LString;
- FieldPos : Integer); forward;
- {===========================================}
- {
- Purpose: Provide same function as Turbo Pascal Insert procedure.
-
- Inserts substring ObjStr into InpStr at FieldPos.
-
- If FieldPos > length(InpStr), ObjStr is appended to InpStr.
-
- St := 'ABCEDFG';
- Insert ('XX',St,3); ==> St value of 'ABXXCDEFG'
- Insert ('XX',St,1); ==> St value of 'XXABCDEFG'
- Insert ('XX',St,length(St)); ==> St value of 'ABCDEFXXG'
-
- Parameters:
- Input: ObjStr = substring to insert.
- InpStr = string in which substring will be inserted.
- FieldPos = position, left of which substring is inserted.
-
- Output: Modified InpStr, with substring inserted.
- }
-
- {===========================================}
- function Copy(InpStr: LString; FieldPos, FieldLen: integer): LString; forward;
- {===========================================}
- {
- Purpose: Provide same function as Turbo Pascal Copy function.
-
- Exactly same thing as VAX function
-
- Substr(InpStr, FieldPos, FieldLen)
-
- but with some extra error checking.
- }
- {===========================================}
- function Pos_( ObjStr, InpStr: LString): Integer; forward;
- {===========================================}
- {
- N.B. -- Name is "Pos_" to avoid conflict with VAX Pos function.
-
- Purpose: Provide same function as Turbo Pascal Pos procedure.
-
- Exactly same thing as VAX function
-
- Index(InpStr, ObjStr)
-
- but with the arguments reversed.
- }
- {===========================================}
- function LoCase(InChar: char): char; forward;
- {===========================================}
- {
- Purpose: Convert a single character to lower case.
-
- Parameters:
- Input: InChar = character to be converted.
- Output: none
-
- Function Value: LoCase = converted character.
- }
-
- {===========================================}
- function UpCase(InChar: char): char; forward;
- {===========================================}
- {
- Purpose: Convert a single character to upper case.
-
- Parameters:
- Input: InChar = character to be converted.
- Output: none
-
- Function Value: UpCase = converted character.
- }
-
- {====================================================}
- function LowerCase(InpStr: LString): LString; forward;
- {====================================================}
- {
- Purpose: Convert a string of characters to lower case.
-
- Parameters:
- Input: InpStr = string to be converted.
- Output: none
-
- Function Value: LowerCase = converted string.
- }
-
- {====================================================}
- function UpperCase(InpStr: LString): LString; forward;
- {====================================================}
- {
- Purpose: Convert a string of characters to upper case.
-
- Parameters:
- Input: InpStr = string to be converted.
- Output: none
-
- Function Value: UpperCase = converted string.
- }
-
- {================================================}
- function TrimL(InpStr: LString): LString; forward;
- {================================================}
- {
- Purpose: Trim Left: Remove leading spaces from a string.
-
- Parameters:
- Input: InpStr = string to be trimmed.
- Output: none
-
- Function Value: TrimL = trimmed string.
- }
-
- {================================================}
- function TrimR(InpStr: LString): LString; forward;
- {================================================}
- {
- Purpose: Trim Right: Remove trailing spaces from a string.
-
- Parameters:
- Input: InpStr = string to be trimmed.
- Output: none
-
- Function Value: TrimR = trimmed string.
- }
-
- {==================================================================}
- function PadL(InpStr: LString; FieldLen: integer): LString; forward;
- {==================================================================}
- {
- Purpose: Pad Left: Pad a string on the left with spaces to
- fill it to a desired field length. Trailing spaces
- are not removed.
- Parameters:
- Input: InpStr = string to be padded.
- Output: none
-
- Function Value: PadL = padded string.
- }
-
- {==================================================================}
- function PadR(InpStr: LString; FieldLen: integer): LString; forward;
- {==================================================================}
- {
- Purpose: Pad Right: Pad a string on the right with spaces to
- fill it to a desired field length. Leading spaces
- are not removed.
- Parameters:
- Input: InpStr = string to be padded.
- Output: none
-
- Function Value: PadR = padded string.
- }
-
- {===================================================================}
- function JustL(InpStr: LString; FieldLen: integer): LString; forward;
- {===================================================================}
- {
- Purpose: Left justify a string within a desired field length.
- First leading spaces are removed, then the string is
- padded with trailing spaces to the desired length.
- Parameters:
- Input: InpStr = string to be justified.
- Output: none
-
- Function Value: JustL = justified string.
- }
-
- {===================================================================}
- function JustR(InpStr: LString; FieldLen: integer): LString; forward;
- {===================================================================}
- {
- Purpose: Right justify a string within a desired field length.
- First trailing spaces are removed, then leading spaces
- are inserted fill to the desired length.
- Parameters:
- Input: InpStr = string to be justified.
- Output: none
-
- Function Value: JustR = justified string.
- }
-
- {====================================================================}
- function Center(InpStr: LString; FieldLen: integer): LString; forward;
- {====================================================================}
- {
- Purpose: Center a string within a desired field length. First
- the string is stripped of leading and trailing spaces,
- then the resultant string is padded equally with
- leading and trailing spaces.
- Parameters:
- Input: InpStr = string to be justified.
- Output: none
-
- Function Value: Center = centered string.
- }
-
- {==================================================================}
- function GetStr(var InpStr: LString; Delim: Char): LString; forward;
- {==================================================================}
- {
- Purpose: Strating at the first position of the input string,
- return a substring containing all characters up to
- (but not including) the fisrt occurence of the given
- delimiter. If the delimiter is not found, then the
- entire input string is returned. The substring and
- delimiter are then deleted from the input string.
-
- Parameters:
- Input: InpStr = string from which substring is removed.
- Delim = delimiter to be used.
- Output: InStr = remainder of input string.
-
- Function Value: GetStr = Extracted substring.
- }
-
- {=====================================================================}
- function Break(var InpStr: LString; DelStr: LString): LString; forward;
- {=====================================================================}
- {
- Purpose: Emulates the SNOBOL BREAK function. Operation is
- similar to GetStr except that several delimiters
- may be used. The substring returns all characters
- up to the first of any delimiter in DelStr. Unlike
- GetStr, the Delimiter found is NOT removed from
- the input string.
-
- Parameters:
- Input: InpStr = string from which substring is removed.
- DelStr = list of delimiters.
- Output: InStr = remainder of input string.
-
- Function Value: Break = Extracted substring (Break on delimiter).
- }
-
- {====================================================================}
- function Span(var InpStr: LString; DelStr: LString): LString; forward;
- {====================================================================}
- {
- Purpose: Emulates the SNOBOL Span function. Operation is
- is the reverse of Break; The input string is scanned
- for characters IN DelStr. It returns a substring
- containing ONLY delimiters found starting at the
- first position up the the first NON delimiter. That
- character is NOT removed from the input string.
-
- Parameters:
- Input: InpStr = string from which substring is removed.
- DelStr = list of delimiters.
- Output: InStr = remainder of input string.
-
- Function Value: Span = Extracted substring (Span of delimiters).
- }
-
- {====================================================================}
- function Compress(InpStr: LString): LString; forward;
- {====================================================================}
- {
- Purpose: Replace multiple tabs, spaces in string with single space.
-
- Parameters:
- Input: InpStr = string to be compressed.
- Output: none.
-
- Function Value: Compress = compressed string.
- }
-
- {====================================================================}
- function Squish(InpStr: LString): LString; forward;
- {====================================================================}
- {
- Purpose: Replace multiple tabs, spaces in string with single space,
- and delete leading and trailing spaces.
-
- Parameters:
- Input: InpStr = string to be squished.
- Output: none.
-
- Function Value: Squish = squished string.
- }
-
- {=======================================================================}
- procedure GString(InpStr, DelStr: LString; span: boolean;
- var cpos, dpos: integer; var OutStr: LString); forward;
- {=======================================================================}
- {
- Purpose: Emulates both the SPAN and BREAK functions of SNOBOL.
-
- SPAN: If span is true, then starting from position, cpos,
- the input string is scanned for characters in the string,
- DelStr. These characters are copied to the output string
- until either a character NOT in DelStr is found or the end
- of the string is reached. Position pointer, cpos, is reset
- to point at the break character. If the end of the string
- is reached, cpos is set to zero.
-
- BREAK: If span is false, then the input string is scanned
- for characters NOT in the string, DelStr. The output string
- contains all characters up to the first delimiter. Position
- pointer, cpos, is set to point at the delimiter found. If a
- delimiter was not found, cpos is set to zero.
-
- Dpos is set to position in DelStr of the delimiter found. If
- none found, dpos is set to zero.
-
- Parameters:
- Input: InpStr = string from which substring is Copied.
- DelStr = delimiters to be used.
- span = true = span, false = break.
- cpos = starting position in input string.
-
- Output: cpos = position past found delimiter.
- dpos = which delimiter was found.
- OutStr = substring copied from the input string.
- }
- {=================================================}
- Procedure Str( Valu: Integer;
- var OutStr: LString); forward;
- {=================================================}
- {
- Purpose: Emulates Turbo Pascal Str function, but only for integer values.
- Converts integer Valu to string representation in OutStr.
- In addition, the special formatting commands (:n) are
- NOT available in this version.
-
- Parameters:
- Input: Valu = integer value to convert to string expression.
-
- Output: OutStr = string that will receive string, with no leading
- or trailing spaces.
- }
- {=================================================}
- Procedure Val( InpStr: LString;
- var Valu: Integer;
- var OutCode: Integer); forward;
- {=================================================}
- {
- Purpose: Emulates Turbo Pascal Val function, but only for integer values.
- In addition, the return code OutCode is the VAX Pascal
- STATUSV, NOT the position of the first character in error.
-
- Parameters:
- Input: InpStr = string expression to convert to an integer value.
-
- Output: Valu = integer value of the expression.
-
- OutCode = result code, 0 if OK, otherwise value of STATUSV.
- }
- {=================================================}
- Procedure RealStr(Valu: Real; Trail: integer;
- var OutStr: LString); forward;
- {=================================================}
- {
- Purpose: Convert a real value to an equivalent string representation.
-
- Parameters:
-
- Input: Valu = Real value to be converted to a string.
- Trail = number of digits to the right of the radix point.
-
- Output: OutStr = string representation.
- }
-
- {===========================================================}
- Procedure RealVal(InpStr: LString;
- Var Err: integer; Var Valu: real); forward;
- {===========================================================}
- {
- Purpose: Convert a string representation of a number to a real value.
-
- If an illegial character is encounterd, conversion halts
- and the error condition returned by STATUSV is reported
- through the variable, Err.
-
- Parameters:
-
- Input: InpStr = String representation to be converted to a real value.
-
- Output: Err = error code, 0 if OK, otherwise value os STATUSV
- Valu = converted value.
- }
- {===========================================================}
- Procedure Substitute( Var line: LString;
- target, subst: LString); forward;
- {===========================================================}
- {
- Purpose: Find and replace target substring with subst in line.
-
- Parameters:
- Input: target = substring for which to look in line.
- subst = substring to replace target with, if found.
-
- Output: line = updated string.
- }
- {
- FUNCTION BODIES:
- }
-
- {==============}
- procedure Delete_;
- {==============}
- { remove substring starting at FieldPos, containing FieldLen chars }
- begin
- if FieldPos <= length(InpStr) then
- InpStr := Substr(InpStr, 1, FieldPos-1) +
- Substr(InpStr, min(FieldPos+FieldLen,length(InpStr)),
- max(length(InpStr)-FieldPos-FieldLen+1,0) );
- end;
-
- {================}
- procedure Insert;
- {================}
- { Insert string ObjStr into InpStr at position FieldPos }
- begin
- if FieldPos > length(InpStr) then
- InpStr := InpStr + ObjStr
- else
- InpStr := Substr(InpStr, 1, FieldPos-1) +
- ObjStr +
- Substr(InpStr, FieldPos, length(InpStr)-(FieldPos-1));
- end;
-
- {==============}
- function Copy;
- {==============}
- { extracts a substring from input string }
- begin
- If FieldPos > length(InpStr) then
- Copy := ''
- else
- Copy := SUBSTR( InpStr, FieldPos,
- MIN( FieldLen, length(InpStr)-FieldPos+1 ) );
- end;
-
- {==============}
- function Pos_;
- {==============}
- { find location of a substring in an input string }
- begin
- Pos_ := INDEX( InpStr, ObjStr )
- end;
-
- {==============}
- function UpCase;
- {==============}
- { convert a character to upper case }
- begin
- if InChar IN ['a'..'z'] then
- UpCase := Chr(Ord(Inchar)-32)
- else
- UpCase := InChar
- end;
-
- {==============}
- function LoCase;
- {==============}
- { convert a character to lower case }
- begin
- if InChar IN ['A'..'Z'] then
- LoCase := Chr(Ord(Inchar)+32)
- else
- LoCase := InChar
- end;
-
- {=================}
- function LowerCase;
- {=================}
-
- { convert a string to lower case characters }
-
- var i : integer;
-
- begin
- for i := 1 to Length(InpStr) do
- InpStr[i] := LoCase(InpStr[i]);
- LowerCase := InpStr
- end;
-
- {=================}
- function UpperCase;
- {=================}
-
- { convert a string to upper case characters }
-
- var i : integer;
-
- begin
- for i := 1 to Length(InpStr) do
- InpStr[i] := UpCase(InpStr[i]);
- UpperCase := InpStr
- end;
-
- {=============}
- function TrimL;
- {=============}
-
- { strip leading spaces from a string }
-
- var i,len : integer;
-
- begin
- len := length(InpStr);
- i := 1;
- while (i <= len) and (InpStr[i] = ' ') do
- i := i + 1;
- TrimL := Substr(InpStr,i,len-i+1)
- end;
-
- {=============}
- function TrimR;
- {=============}
-
- { strip trailing spaces from a string }
-
- var i : integer;
-
- begin
- i := length(InpStr);
- while (i >= 1) and (InpStr[i] = ' ') do
- i := i - 1;
- TrimR := Substr(InpStr,1,i)
- end;
-
- {============}
- function PadL;
- {============}
-
- { Pad string on left with spaces to fill to the desired field length }
-
- var STemp : LString;
- i : integer;
-
- begin
- If FieldLen >= Size(InpStr.body) then FieldLen := Size(InpStr.body);
- if length(InpStr) > FieldLen then
- PadL := Substr(InpStr,1,FieldLen)
- else begin
- STemp := InpStr;
- for i := Length(STemp)+1 to FieldLen do
- STemp := ' ' + STemp;
- PadL := STemp
- end
- end;
-
- {============}
- function PadR;
- {============}
-
- { Pad string on right with spaces to fill to the desired field length }
-
- var STemp : LString;
- i : integer;
-
- begin
- If FieldLen >= Size(InpStr.body) then FieldLen := Size(InpStr.body);
- if length(InpStr) > FieldLen then
- PadR := Substr(InpStr,1,FieldLen)
- else begin
- STemp := InpStr;
- for i := Length(STemp)+1 to FieldLen do
- STemp := STemp + ' ';
- PadR := STemp
- end
- end;
-
- {=============}
- function JustL;
- {=============}
-
- { Left justify the string within the given field length }
-
- begin
- JustL := PadR(TrimL(InpStr),FieldLen)
- end;
-
- {=============}
- function JustR;
- {=============}
-
- { Right justify the string within the given field length }
-
- begin
- JustR := PadL(TrimR(InpStr),FieldLen)
- end;
-
- {==============}
- function Center;
- {==============}
-
- { Center a string within a specified field length; the string
- is padded on both sides with spaces }
-
- var LeadSpaces : integer;
- STemp : LString;
- begin
- { strip leading and trailing spaces; determine the
- Number of spaces needed to center the string }
-
- STemp := TrimR(TrimL(InpStr));
- LeadSpaces := (FieldLen - Length(STemp) + 1) div 2;
-
- { insert leading spaces then trailing spaces }
- Center := PadR(PadL(STemp,FieldLen-LeadSpaces),FieldLen)
- end;
-
- {==============}
- function GetStr;
- {==============}
-
- { Return a string containing all characters starting at the
- first position of the source string up to the first delimiter.
- }
-
- var i : integer;
- begin
- i := Index(InpStr,Delim);
- if i = 0 then begin
- GetStr := InpStr;
- InpStr := ''
- end
- else begin
- GetStr := Substr(InpStr,1,i-1);
- {InpStr := Substr(InpStr,i+1,length(InpStr)-i)} Delete_(InpStr,1,i)
- end
- end;
-
- {=============}
- function Break;
- {=============}
-
- { Emulate SNOBOL BREAK function }
-
- var cp, dp : integer;
- OutStr : LString;
-
- begin
- cp := 1;
- GString(InpStr,DelStr,false,cp,dp,OutStr);
- Break := OutStr;
- if cp = 0 then
- InpStr := ''
- else
- {InpStr := Substr(InpStr,cp,length(InpStr)-cp-1)} Delete_(InpStr,1,cp-1)
- end;
-
- {============}
- function Span;
- {============}
-
- { Emulate SNOBOL SPAN function }
-
- var cp, dp : integer;
- OutStr : LString;
-
- begin
- cp := 1;
- GString(InpStr,DelStr,true,cp,dp,OutStr);
- Span := OutStr;
- if cp = 0 then
- InpStr := ''
- else
- {InpStr := Substr(InpStr,i+1,length(InpStr)-cp-1)}
- Delete_(InpStr,1,cp-1)
- end;
-
- {================}
- procedure GString;
- {================}
-
- { Return a string containing all characters starting at position, cpos,
- of the source string up to the first first occurence of any of several
- delimiters. The position of the found delimiter is returned as well
- as which delimiter.
- }
- var done : boolean;
-
- begin
- OutStr := ''; dpos := 0;
- if cpos > 0 then begin
- done := false;
- while (cpos <= Length(InpStr)) and not done do begin
- dpos := Index(DelStr,InpStr[cpos]);
- if {span xor (dpos = 0) }
- XOR( span, (dpos = 0))
- then begin
- OutStr := OutStr + InpStr[cpos];
- cpos := cpos + 1
- end
- else
- done := true
- end;
- if {(span xor (dpos = 0))}
- XOR( span, (dpos = 0) )
- or (cpos > length(InpStr))
- then cpos := 0
- end
- end;
-
- {================}
- procedure Substitute;
- {================}
-
- {replaces target with subst in line}
-
- var where : integer;
-
- begin
- where := Pos_(target, line);
- if where > 0 then
- begin
- delete_(line, where, length(target));
- insert(subst, line, where);
- end;
- end;
-
- {===============}
- function Compress;
- {===============}
-
- {replaces multiple nonprinting chars with single spaces}
-
- var i : integer;
-
- begin
- for i := 1 to length(InpStr) do
- if NOT( InpStr[i] IN [' '..'~'] ) then
- InpStr[i] := ' ';
- i := Pos_(' ',InpStr);
- while i <> 0 do
- begin
- Inpstr := Copy(Inpstr,1,i) +
- Copy(Inpstr,i+2,length(Inpstr)-i-1);
- i := Pos_(' ',Inpstr);
- end;
- Compress := Inpstr;
- end;
-
- {===============}
- function Squish;
- {===============}
-
- {trims leading and trailing spaces and compresses excess whitespace}
-
- begin
- Squish := Compress(TrimR(TrimL(InpStr)))
- end;
-
- {================}
- procedure Str;
- {================}
- { converts integer value to a string representation }
- begin
- WRITEV( OutStr, Valu:1 );
- end;
-
- {================}
- procedure Val;
- {================}
- { converts a string expression to an integer value, returning STATUSV code }
- begin
- READV( InpStr, Valu, ERROR := CONTINUE );
- OutCode := STATUSV;
- end;
-
- {================}
- procedure RealStr;
- {================}
- { converts real value to a string representation }
- begin
- WRITEV( OutStr, Valu:1:Trail )
- end;
-
- {================}
- procedure RealVal;
- {================}
- { converts a string expression to a real value, returning STATUSV code }
- begin
- READV( InpStr, Valu, ERROR := CONTINUE );
- Err := STATUSV
- end;
-
- (*
- Other VAX Pascal equivalents of Turbo Pascal features
- *)
-
- CONST { Terminal control sequences defined here }
- CSI_sequence = ''(27) + '['; {''(27) == ESCape char}
- ClrEol_sequence = CSI_sequence + 'K';
- ClrScr_sequence = CSI_sequence + ';H' + CSI_sequence + 'J';
- CrtInit_sequence= ''(27)+'<'+''(27)+'(B'+''(27)+')0'+
- CSI_sequence+'?1l'+CSI_sequence+'?3l'+''(27)+'>';
- CRTExit_sequence = CSI_sequence + 'm';
- DelLine_sequence = '';
- InsLine_sequence = '';
- LowVideo_sequence = CSI_sequence + 'm';
- NormVideo_sequence = CSI_sequence + 'm';
- HiVideo_sequence = CSI_sequence + '1m';
- UnderScoreVideo_sequence = CSI_sequence + '4m';
- BlinkVideo_sequence = CSI_sequence + '5m';
- ReverseVideo_sequence = CSI_sequence + '7m';
- DoubleHighTopVideo_sequence = ''(27)+'#3';
- DoubleHighBottomVideo_sequence = ''(27)+'#4';
- SingleHighVideo_sequence = ''(27)+'#5';
- DoubleWideVideo_sequence = ''(27)+'#6';
-
- { VAX Pascal equiv.'s to Turbo built-in CRT control routines }
-
- PROCEDURE ClrEol;
-
- BEGIN
- WRITE( output, ClrEol_sequence )
- END;
-
- PROCEDURE ClrScr;
-
- BEGIN
- WRITE( output, ClrScr_sequence )
- END;
-
- PROCEDURE CrtInit;
-
- BEGIN
- OPEN( output, RECORD_LENGTH := 65500 ); { open output for max. rec. size }
- WRITE( output, CrtInit_sequence )
- END;
-
- PROCEDURE CrtExit;
-
- BEGIN
- WRITE( output, CrtExit_sequence )
- END;
-
- PROCEDURE DelLine;
-
- BEGIN
- WRITE( output, DelLine_sequence )
- END;
-
- PROCEDURE InsLine;
-
- BEGIN
- WRITE( output, DelLine_sequence )
- END;
-
- PROCEDURE GoToXY( col, row : INTEGER );
-
- BEGIN
- WRITE( output, CSI_sequence, row:1, ';', col:1, 'H' )
- END;
-
- PROCEDURE LowVideo;
-
- BEGIN
- WRITE( output, LowVideo_sequence )
- END;
-
- PROCEDURE NormVideo;
-
- BEGIN
- WRITE( output, NormVideo_sequence )
- END;
-
- PROCEDURE HiVideo;
-
- BEGIN
- WRITE( output, HiVideo_sequence )
- END;
-
- PROCEDURE UnderScoreVideo;
-
- BEGIN
- WRITE( output, UnderScoreVideo_sequence )
- END;
-
- PROCEDURE BlinkVideo;
-
- BEGIN
- WRITE( output, BlinkVideo_sequence )
- END;
-
- PROCEDURE ReverseVideo;
-
- BEGIN
- WRITE( output, ReverseVideo_sequence )
- END;
-
- PROCEDURE DoubleHighVideo( line: LString );
-
- BEGIN
- WRITELN( output, DoubleHighTopVideo_sequence, line );
- WRITELN( output, DoubleHighBottomVideo_sequence, line );
- END;
-
- PROCEDURE SingleHighVideo;
-
- BEGIN
- WRITE( output, SingleHighVideo_sequence )
- END;
-
- PROCEDURE DoubleWideVideo;
-
- BEGIN
- WRITE( output, DoubleWideVideo_sequence )
- END;
-
- { VAX Pascal equivalents for Turbo arithmetic built-in's }
-
- FUNCTION Frac (x : REAL) : REAL;
-
- BEGIN
- Frac := x - Trunc( x )
- END;
-
- FUNCTION Hi (x : INTEGER) : INTEGER;
-
- BEGIN
- Hi := Int ( UAND( x, %X'FF00') DIV %X'FF' )
- END;
-
- FUNCTION Lo (x : INTEGER):INTEGER;
-
- BEGIN
- Lo := Int ( UAND( x, %X'FF') )
- END;
-
- FUNCTION Swap (x : INTEGER):INTEGER;
-
- BEGIN
- Swap := ( Lo(x) * %X'FF' ) + Hi(x)
- END;
-
- FUNCTION SHL( u1,u2 : UNSIGNED ) : UNSIGNED;
- { VAX replacement for Turbo SHL shift-left operator }
- BEGIN
- SHL := u1 * (2**u2)
- END;
-
- FUNCTION SHR( u1,u2 : UNSIGNED ) : UNSIGNED;
- { VAX replacement for Turbo SHR shift-right operator }
- BEGIN
- SHR := u1 DIV (2**u2)
- END;
-
-
- [HIDDEN] VAR
- seed : [STATIC] UNSIGNED;
-
- [HIDDEN,ASYNCHRONOUS,EXTERNAL(MTH$RANDOM)] FUNCTION MTH$RANDOM (
- VAR SEED : [VOLATILE]UNSIGNED) : REAL; EXTERNAL;
-
- PROCEDURE Randomize;
-
- VAR
- x : REAL;
-
- BEGIN
- seed := CLOCK * 2**10;
- x := MTH$Random ( seed )
- END;
-
- FUNCTION Random: REAL;
-
- BEGIN
- Random := MTH$Random( seed )
- END;
-
- PROCEDURE Delay (msecs : INTEGER);
-
- [ASYNCHRONOUS,EXTERNAL(SYS$HIBER)] FUNCTION $HIBER : INTEGER; EXTERNAL;
-
- TYPE $UQUAD = [QUAD] RECORD
- LO: UNSIGNED;
- HI: UNSIGNED;
- END;
-
- [ASYNCHRONOUS,EXTERNAL(SYS$SCHDWK)] FUNCTION $SCHDWK (
- VAR PIDADR : [VOLATILE]UNSIGNED := %IMMED 0;
- PRCNAM : [CLASS_S] PACKED ARRAY [$l2..$u2:INTEGER] OF CHAR := %IMMED 0;
- DAYTIM : $UQUAD;
- REPTIM : $UQUAD := %IMMED 0) : INTEGER; EXTERNAL;
-
- CONST
- Milliseconds = 10000;
-
- VAR
- sts : INTEGER;
- DAYTIM : $UQUAD;
-
- BEGIN
- { schedule a wakeup for msecs later }
- DAYTIM.LO := -(msecs * Milliseconds);
- DAYTIM.HI := -1;
- sts := $Schdwk( DAYTIM:=DAYTIM );
- { hibernate until then }
- sts := $Hiber;
- END;
-
- FUNCTION EXIST (fn : VARYING [l1] OF CHAR) : BOOLEAN;
-
- VAR
- fv : TEXT;
- BEGIN
- OPEN( FILE_VARIABLE := fv,
- FILE_NAME := fn,
- HISTORY := READONLY,
- ERROR := CONTINUE );
- EXIST := STATUS( fv ) < 1;
- CLOSE( FILE_VARIABLE := fv,
- ERROR := CONTINUE )
- END;
-
- FUNCTION GetTime : LString;
-
- VAR
- str : PACKED ARRAY [1..11] OF CHAR;
- BEGIN
- TIME( str );
- GetTime := str
- END;
-
- FUNCTION GetDate : LString;
-
- VAR
- str : PACKED ARRAY [1..11] OF CHAR;
- BEGIN
- DATE( str );
- GetDate := str
- END;
-
-
- { END. { end of VAXTURBO }
-