home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
TPKERMIT
/
UTILITY.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1987-03-25
|
6KB
|
143 lines
(* +FILE+ UTILITY.PASMSCPM *)
(* ============ Begining of U T I L I T Y Procedures ============ *)
Type String2 = String[2];
(* ----------------------------------------------------------------- *)
(* GETTOKEN - Function *)
(* ----------------------------------------------------------------- *)
Function GETTOKEN ( var instring : comstring) : comstring ;
Var
pt : byte ;
Begin (* GETTOKEN *)
While (instring[1] = ' ') and (length(instring)>1) do
Delete(instring,1,1); (* eliminate leading blanks *)
pt := POS(' ',instring);
if pt = 0 then pt := length(instring)+1 ;
GETTOKEN := copy(instring,1,pt-1);
DELETE(instring,1,pt);
End ; (* GETTOKEN *)
(* ----------------------------------------------------------------- *)
(* UpperCase - Function *)
(* ----------------------------------------------------------------- *)
Function UpperCase ( instring : comstring) : comstring ;
Var
ix,slen : integer ;
Begin (* UpperCase *)
slen := length(instring) ;
for ix := 1 to slen do
IF instring[ix] IN ['a'..'z'] THEN
instring[ix] := chr(ord(instring[ix])-32);
UpperCase := instring ;
End ; (* UpperCase *)
(* ----------------------------------------------------------------- *)
(* CRCheck - Procedure - generates a CCITT CRC using the polynominal *)
(* X^16 + X^12 + X^5 + 1 *)
(* Side Effects : Updates the global variable CRC which should be *)
(* initialized to 0. It is call only once for each *)
(* byte to be checked and all 8 bits are included. *)
(* No terminating calls are necessary. *)
(* ----------------------------------------------------------------- *)
Procedure CRCheck ( Abyte : byte ) ;
Var j,temp : integer ;
Begin (* CRCheck *)
For j := 0 to 7 do
Begin (* check all 8 bits *)
temp := CRC xor Abyte ;
CRC := CRC shr 1 ; (* shift right *)
If Odd(temp) then CRC := CRC xor $8408 ;
abyte := abyte shr 1 ;
End ; (* check all 8 bits *)
End ; (* CRCheck *)
(* ----------------------------------------------------------------- *)
(* Prefixof Function - Returns a char string of the dir prefix. *)
(* ----------------------------------------------------------------- *)
function Prefixof(afilename:comstring) : comstring;
var i :integer;
label exit ;
begin (* Prefixof *)
while length(afilename)>0 do
If afilename[length(afilename)] in [':','\','/']
then goto exit
else delete(afilename,length(afilename),1);
exit:
Prefixof := afilename ;
end; (* Prefixof *)
(* ----------------------------------------------------------------- *)
(* NewAsFile - returns a new ASFILE name in the parameter AsFile. *)
(* MyFiles - is the wild char name. *)
(* Filename - is the filename to be renamed . *)
(* AsFiles - is the wild char name of new file. *)
(* AsFile - is the new file name. *)
(* returns TRUE if AsFile correctly assigned. *)
(* returns FALSE if AsFile detected an error in assignment *)
(* There is a BUG in the MsDoS Call to get next Directory Entry *)
(* therefore this function may return FALSE. *)
(* *)
(* ----------------------------------------------------------------- *)
Function NewAsFile (MyFiles,Filename,AsFiles: comstring;
var AsFile : comstring ): boolean;
var
temp : comstring ;
si,ix,iy : integer ;
star : packed array[1..8] of string[20];
Label Subdir,Exit;
Begin (* NewAsFile Function *)
for si := 1 to 8 do star[si] := '*';
si := 0 ;
MyFiles := Uppercase(Myfiles);
FileName := Uppercase(Filename);
AsFiles := Uppercase(AsFiles);
ix := Pos(':',MyFiles) ;
If ix > 1 then delete(MyFiles,1,ix) ; (* Eliminate filemode prefix *)
subdir:
ix := Pos('\',MyFiles) ;
If ix > 1 then delete(MyFiles,1,ix) ; (* Eliminate sub-dir prefixs *)
if ix > 1 then goto subdir ;
ix := Pos(':',AsFiles) ;
If ix > 1 then delete(AsFiles,1,ix) ; (* Eliminate filemode prefix *)
While (length(Filename) > 0) and (length(Myfiles)>0) Do
Begin (* Scan filename *)
If MyFiles[1] = Filename[1] then
Begin delete(MyFiles,1,1) ; delete(Filename,1,1); end
else
Begin (* get star string *)
si:=si+1 ;
delete(MyFiles,1,1);
ix := Pos('*',MyFiles) - 1 ; (* Next wild char *)
if ix <= 0 then temp := MyFiles
else temp := copy(Myfiles,1,ix);
iy := Pos(temp,Filename)-1 ;
if iy < 0 then
begin NEWASFILE:=FALSE; Asfile:='temp.dat'; Goto exit ; end;
if iy = 0 then star[si] := filename
else star[si] := copy(filename,1,iy);
delete(FileName,1,iy);
End ;(* get star string *)
End; (* Scan filename *)
ix := 1 ;
si := 1 ;
AsFile := '';
While ix <= length(AsFiles) do
Begin (* Create AsFile name *)
If AsFiles[ix] in ['*','?'] then
Begin (* wild char *)
AsFile := Concat(AsFile,star[si]);
si := si + 1 ;
End
else
AsFile := Concat(AsFile,Asfiles[ix]);
ix := ix + 1 ;
End ; (* Create AsFile name *)
NewAsFile := True ;
Exit:
End; (* NewASFile Function *)
(* ============ End of U T I L I T Y Procedures =================== *)