{ This UNIT should be portable into any Pascal currently used WITH the exception of the use IF a TYPE 'str255' which is nothing but a 255 character STRING ( STRING[255] ). INTEGER is a 16 bit signed INTEGER LONGINT is a 32 bit signed INTEGER } UNIT TextStuff; INTERFACE USES MacTypes; { for the str255 definition only } VAR HexCode : str255; DecCode : str255; ALine : str255; PROCEDURE Decit(DecValue:LONGINT); { take DecCode AND insert commas every 3 characters for easily displaying numbers } PROCEDURE Comma; { take in a long INTEGER AND convert it to a hexadecimal number into HexCode } PROCEDURE Hexit(HexValue:LONGINT); { Convert HexCode into 2,4,8 nybbles respectfully } PROCEDURE MakeByte; PROCEDURE MakeWord; PROCEDURE MakeLong; { Remove all excess spaces from ALine } PROCEDURE TrimEndingPadding; PROCEDURE TrimBeginningPadding; IMPLEMENTATION {----------------------------------------------------------------------------} PROCEDURE comma; VAR temps : STRING; count1 : INTEGER; BEGIN count1 := length(DecCode); temps := ''; WHILE count1>3 DO BEGIN count1 := count1-3; temps := concat(',',copy(DecCode,count1+1,3),temps); END; IF count1>0 THEN temps := concat(copy(DecCode,1,count1),temps) ELSE delete(temps,1,1); DecCode := temps; END; {----------------------------------------------------------------------------} PROCEDURE Hexit(HexValue:LONGINT); PROCEDURE hex(a:LONGINT); VAR b : INTEGER; h : STRING; BEGIN IF a>0 THEN BEGIN b := a MOD 16; CASE b of 0 : h := '0'; 1 : h := '1'; 2 : h := '2'; 3 : h := '3'; 4 : h := '4'; 5 : h := '5'; 6 : h := '6'; 7 : h := '7'; 8 : h := '8'; 9 : h := '9'; 10 : h := 'A'; 11 : h := 'B'; 12 : h := 'C'; 13 : h := 'D'; 14 : h := 'E'; 15 : h := 'F'; OTHERWISE h := ''; END; {CASE} HexCode := concat(h,HexCode); hex(a DIV 16); END; END; BEGIN HexCode := ''; IF HexValue >= 0 THEN BEGIN hex(HexValue); IF HexCode = '' THEN { handle HexValue of 0 } HexCode := '0'; END; END; PROCEDURE Decit(DecValue:LONGINT); PROCEDURE dec(a:LONGINT); VAR b : INTEGER; h : STRING; BEGIN IF a>0 THEN BEGIN b := a MOD 10; CASE b of 0 : h := '0'; 1 : h := '1'; 2 : h := '2'; 3 : h := '3'; 4 : h := '4'; 5 : h := '5'; 6 : h := '6'; 7 : h := '7'; 8 : h := '8'; 9 : h := '9'; 10 : h := 'A'; 11 : h := 'B'; 12 : h := 'C'; 13 : h := 'D'; 14 : h := 'E'; 15 : h := 'F'; OTHERWISE h := ''; END; {CASE} DecCode := concat(h,DecCode); dec(a DIV 10); END; END; BEGIN DecCode := ''; IF DecValue >= 0 THEN BEGIN dec(DecValue); IF DecCode='' THEN { handle DecValue of 0 } DecCode := '0'; END; END; PROCEDURE makeLong; BEGIN HexCode := concat('00000000',HexCode); { add 8 zeros to the beginning AND THEN trim off the excess to make sure we have 8 characters } WHILE length(HexCode)>8 DO delete(HexCode,1,1); { Standard STRING processing routine that has been in Pascal since UCSD Pascal } END; PROCEDURE makeword; BEGIN HexCode := concat('0000',HexCode); { add 4 zeros to the beginning AND THEN trim off the excess to make sure we have 4 characters } WHILE length(HexCode)>4 DO delete(HexCode,1,1); { Standard STRING processing routine that has been in Pascal since UCSD Pascal } END; PROCEDURE makebyte; BEGIN HexCode := concat('00',HexCode); { add 2 zeros to the beginning AND THEN trim off the excess to make sure we have 2 characters } WHILE length(HexCode)>2 DO delete(HexCode,1,1); { Standard STRING processing routine that has been in Pascal since UCSD Pascal } END; PROCEDURE TrimEndingPadding; { remove all excessive padding (spaces) from the END of the line } VAR LineLength : INTEGER; BEGIN LineLength := length(ALine); WHILE ((LineLength>0) AND (ALine[LineLength]=' ')) DO BEGIN delete(ALine,LineLength,1); LineLength := length(ALine); END; END; PROCEDURE TrimBeginningPadding; { remove all excessive padding (spaces) from the beginning of the line } BEGIN WHILE ((length(ALine)>0) AND (ALine[1]=' ')) DO delete(ALine,1,1); END; END.