{ SPX Library Version 2.0 Copyright 1993 Scott D. Ramsay } SPX_FNC contains general functions and procedures that are used by most of the units. トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function sgn(h:integer):integer; Returns -1 if H is less than zero 1 if H is greater than zero 0 if H is equal to zero トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function strint(s:string):longint; converts a four character string to a longint value; The characters are repesented at hi and lo byte values of the longint. EXAMPLE: var s : string; l : longint; begin s := 'AT'; l := strint(s); { l := 21569 or $00005441 } end; トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function intstr(l:longint):string; converts a longint to a four character string. EXAMPLE: var s : string; l : longint; begin s := intstr(21569); end; { s := 'AT'#0#0; } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function ups(s:string):string; returns S in all uppercase letters. トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function st(h:longint):string; converts H to a string EXAMPLE: var s : string; begin s := st(123); end; { s := '123'; トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function compare(s1,s2:string):boolean; Compares two strings returns true if they are equal up to the length of S1. EXAMPLE: compare('SPXLIB','SPX') returns FALSE compare('SPX','SPXLIB') returns TRUE トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function dtcmp(var s1,s2;size:word):boolean; Same as function CMP. Here for compatibility トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function cmp(var s1,s2;size:word):boolean; Compares to variables of unknown types. S1,S2: SIZE: objects of any type to compare size of objects Returns true if the bytes within S1 and S2 are equal トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function lz(i,w:longint):string; Converts a longint to a string with leading zeros. I: W: Integer to convert Number of spaces to place zeros EXAMPLE: var s : string; begin s := lz(1234,7); end; { s := '0001234'; } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function vl(h:string):longint; converts a string to a longint value H: string to convert トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function spaces(h:integer):string; Creates a string with H number of spaces EXAMPLE: s := spaces(10); { s := ' '; (* ten spaces *) } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function repstr(h:integer;ch:char):string; Creates a string with H number of the character ch. EXAMPLE: s := repstr(10,'A'); { s := 'AAAAAAAAAA'; } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function ifix(var a:integer;min,max:integer):boolean; Sets an integer to the range min..max. A: MIN: MAX: Value to change Minimum value A can be Maximum value A can be Returns TRUE if the variable was changed. EXAMPLE: {$X+ } { enable extended syntax } var a,b,c : integer; modified, didChange : boolean; begin a := -10; b := 112; c := 50; didChange := ifix(a,0,100); modified := ifix(c,0,100); ifix(b,0,100); { { { { { end; didChange := TRUE } modified := FALSE } a := 0 } b := 100 } c := 50 } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function rfix(var a:real;min,max:real):boolean; Sets a real to the range min..max. A: MIN: MAX: Value to change Minimum value A can be Maximum value A can be Returns TRUE if the variable was changed. EXAMPLE See function ifix トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function anything(s:string):boolean; Returns TRUE if the S is not an empty string or if any of the characters in S is in the range #32..#255 (ascii) トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function exist(f:string):boolean; Returns TRUE if the file exist on disk F: The file to check. Can have full file spec. トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function TPerror(errorcode:integer) : string; Returns an Turbo Pascal error string ERRORCODE: value generated by the funciton IOresult トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト procedure funpad(var s:string); Removes all leading spaces from the string S トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト procedure unpad(var s:string); Removes all trailing spaces from the string S トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト procedure munpad(var s:string;b:byte); Cuts string S to length B. Then removes all trailing charaters that are in the range #0..#31. トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function fpad(s:string;h:integer):string; Returns the string S with length H by adding trailing spaces if nessasary. トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト procedure pad(var s:string;h:integer); Same as fpad. if nessasary. Changes string S to length H by adding trailing spaces トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト procedure fix(var s:string;h:string); Adds an extension to the file name S if one does not exist. S: String to check for extenstion H: extension to add EXAMPLE: s1 := 'mypic'; s2 := 'mypic2.'; s3 := 'mypic3.dog'; s4 := 'mypic4.pcx'; fix(s1,'.PCX'); fix(s2,'.PCX'); fix(s3,'.PCX'); fix(s4,'.PCX'); { { { { s1 s2 s3 s4 := := := := 'mypic.PCX' 'mypic2.' 'mypic3.dog' 'mypic.pcx' } } } } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト procedure fixh(var s:string); Converts all characters in S that are in the range #0..#31 to spaces トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function range(x,y,x1,y1,x2,y2:integer) : boolean; Returns TRUE if the point (x,y) is in the rectangle (x1,y1,x2,y2) トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function rrange(x,y,x1,y1,x2,y2:real) : boolean; Returns TRUE if the point (x,y) is in the rectangle (x1,y1,x2,y2) トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function between(x,x1,x2:longint):boolean; Returns TRUE if X is between X1 and X2 トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function fspaces(s:string;skip:byte):string; Returns a string portion in S delimited by spaces. Returns an empty string if one is not found. S: SKIP: string to search number of strings to skip EXAMPLE: s := 'Now is the time for all good men to'; writeln(fspaces(s,0)); writeln(fspaces(s,3)); writeln(fspaces(s,9)); { outputs 'Now' } { outputs 'time' } { outputs '' } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function GetPtr(p:pointer;offset:longint):pointer; Creates a new pointer at P+offset. Adjusts for segment boundries. Returns the new pointer location. Note: offset MUST be positive or zero. P: OFFSET: pointer to adjust offset for the pointer (in bytes) EXAMPLE: var p : pointer; p := GetPtr(SomePointer,88000); { p points to 88000 bytes past SomePointer } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function sar(value:integer;shift:byte):integer; Shift arithmetic right. Same as SHR but maintains the signed (hi) bit. VALUE: integer value to shift. SHIFT: bits to shift note: I don't know why Borland never added this operator! I hate to type the typecast each time. ( integer(value shr shift) ) EXAMPLE: writeln(sar(10,1)); writeln(sar(-10,1)); { outputs 5 } { outputs -5 } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function sal(value:integer;shift:byte):integer; Shift arithmetic left. Same as SHL but maintains the signed (hi) bit. VALUE: integer value to shift. SHIFT: bits to shift EXAMPLE: writeln(sal(10,1)); writeln(sal(-10,1)); { outputs 20 } { outputs -20 } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function ptr2hex(p:pointer):string; Converts a pointer to a string in hexadecimal format P: pointer to convert p := ptr($a000,20); writeln(ptr2hex(p)); { outputs A000:0014 } トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function word2hex(w:word):string; Converts a word value to hexadecimal format トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト function byte2hex(b:byte):string; Converts a byte value to hexadecimal format トトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトトト procedure atexit(proc:QuitProc); Same as the function in C. Calls a quit procedure at exit. Can use many times. Chains multiple procedures. At the exit of the program the procedure are called in a LIFO fashion. (Last in-First out) The last atexit procedure is the first one to be called. PROC: procedure to call at the end of the program. Must be declared as a far procedure. EXAMPLE: Uses spx_fnc; {$F+ } procedure cleanup; begin { do my clean up routines here } end; procedure returnToTextMode; begin textmode(c80); end; begin atexit(cleanup); atexit(returnToTextMode); end.