home *** CD-ROM | disk | FTP | other *** search
- (************************************************************
- The original version of this program was supplied by
- Wolfgang Siebeck, Aachen, W.Germany (72446,415), written
- for Turbo Version 3.
-
- It can be used to find any file using the set
- PATH, so you can open and use your TURBO *.COM
- programs together with their data files from any
- subdirectory, if they are located in a PATH-directory.
- -------------------------------------------------------------
- MODIFICATION LOG
- DATE AUTHOR CONTACT INFO
- 09/15/85 Roy J. Collins P.O.B. 1192, Leesburg, Va 22075
- or TechMail BBS (703) 430-2535
-
- I modified the program for use under Turbo Version 2,
- by adding Turbo routines to retrieve and modify the current
- drive and directory.
- I also added a routine to take the file name to search for
- from the command line.
-
- *************************************************************)
-
- type
- filename_type = string[64];
- regpack = record
- ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
- end;
- line = string[255];
- var
- regs : regpack;
- input : line;
-
- function current_drive:char;
- var
- reg : regpack;
- begin
- reg.ax := $19 shl 8;
- MSDOS(reg);
- current_drive := chr((reg.ax and $00FF) + 65);
- end; (* func current_drive *)
-
- procedure change_drive(drive:char);
- var
- reg : regpack;
- begin
- reg.ax := $E shl 8;
- reg.dx := ord(upcase(drive)) - 65;
- MSDOS(reg);
- end; (* proc change_drive *)
-
- function current_directory(drive:char; var error:byte):filename_type;
- var
- reg : regpack;
- dir : filename_type;
- begin
- with reg do begin
- DX := ord(UpCase(drive))-64;
- DS := seg(dir);
- SI := ofs(dir)+1;
- AX := $47 shl 8;
- MSDOS(reg);
- if Flags and 1 = 1 then begin
- error := AX and $00FF;
- current_directory := '';
- end
- else begin
- error := 0;
- current_directory := drive + ':\' + copy(dir,1,pos(#0,dir)-1);
- end;
- end; {with}
- end; (* proc current_directory *)
-
- procedure change_directory(drive:char; dir:filename_type; var error:byte);
- var
- reg : regpack;
- begin
- with reg do begin
- dir[length(dir)+1] := #0;
- DS := seg(dir);
- DX := ofs(dir)+1;
- AX := $3B shl 8;
- MSDOS(reg);
- if Flags and 1 = 1 then
- error := AX and $00FF
- else
- error := 0;
- end; {with}
- end; (* proc change_directory *)
-
- (****************************************************************************)
-
- Procedure getparm(Var s:line); { Get command line parameter }
- Var
- parms : line Absolute Cseg:$80;
- p : Integer;
- Begin
- While (parms <> '') And (parms[1]=' ') Do
- Delete(parms,1,1);
- p := pos(' ',parms);
- if p = 0 then
- p := length(parms)+1;
- s := copy(parms,1,p-1);
- End;
-
- function exist (filename : line) : boolean;
- const
- new_drive:char = ' ';
- old_drive:char = ' ';
- new_dir:filename_type = '';
- old_dir:filename_type = '';
- filex:filename_type = '';
- var
- found : boolean;
- testfile : file;
- err : byte;
- i : integer;
- begin
- {writeln;}
- {writeln('file=',filename);}
- i := length(filename);
- while ((filename[i] <> '\') and (i>=1)) do
- i := i - 1;
- if i = 3 then
- new_dir := copy(filename,1,i)
- else
- if i > 0 then
- new_dir := copy(filename,1,i-1);
- filex := copy(filename,i+1,99);
- old_drive := current_drive;
- if pos(':',filename)=2 then begin
- new_drive := filename[1];
- change_drive(new_drive);
- end
- else
- new_drive := old_drive;
- {writeln('old: drive=',old_drive,' dir=',old_dir);}
- {writeln('new: drive=',new_drive,' dir=',new_dir);}
- old_dir := current_directory(new_drive,err);
- change_directory(new_drive, new_dir, err);
- found := FALSE;
- assign (testfile,filex);
- {$I-} reset (testfile); {$I+}
- found := (IOResult = 0);
- if found then
- close (testfile);
- exist := found;
- change_directory(new_drive, old_dir, err);
- if new_drive <> old_drive then
- change_drive(old_drive);
- end; (* exist *)
-
- function path_finder : line;
- const
- name = 'PATH';
- type
- carray = array[1..1024] of char;
- var
- found : boolean;
- environ_string : string[255];
- environ : ^carray;
- len,
- start,
- equal_pos,
- null_pos : integer;
- begin
- found := false;
- environ := ptr(memw[cseg:$2C],$0);
- start := 1;
- repeat
- null_pos := start;
- while environ^[null_pos]<>#0 do
- null_pos := null_pos + 1;
- len := null_pos - start;
- environ_string[0] := chr(len);
- move(environ^[start],environ_string[1],len);
- equal_pos := pos('=',environ_string);
- if equal_pos > 0 then
- if name = copy(environ_string,1,equal_pos-1) then begin
- path_finder := copy(environ_string,equal_pos+1,999);
- found := true;
- end;
- start := null_pos + 1;
- until ((found) or (environ^[start]=#0));
- end; (* func path_finder *)
-
- function suche_file (var filename: line) : boolean;
- var
- delim_pos : byte;
- sub_path,full_path : line;
- ok : boolean;
- drive : char;
- dir : filename_type;
- begin
- ok := FALSE;
- delim_pos := 0;
- sub_path := '';
- drive := current_drive;
- dir := current_directory(drive,delim_pos);
- if exist (dir+filename) then begin
- ok := TRUE;
- filename := dir+filename;
- end
- else begin
- full_path := path_finder;
- delim_pos := pos (';',full_path);
- repeat
- sub_path := '';
- if (delim_pos>0) then begin
- sub_path := copy (full_path,1,delim_pos-1);
- delete (full_path,1,delim_pos);
- end
- else begin
- sub_path := full_path;
- full_path := '';
- end;
- if (copy (sub_path,length(sub_path),1) <> '\') then
- sub_path := sub_path + '\';
- delim_pos := 0;
- delim_pos := pos (';',full_path);
- ok := exist (sub_path+filename);
- until ok or (full_path='');
- if ok then
- filename := sub_path + filename;
- suche_file := ok;
- end;
- end; (* suche_file *)
-
- (********************** A little demonstration ... **************************)
- begin
- getparm(input);
- write('file? ');
- readln(input);
- if (input <> '') then
- if suche_file (input) then
- writeln ('Your file was found as "',input,'"')
- else
- writeln ('The file "',input,'" cannot be found on PATH.');
- halt;
- intr($20,regs);
- end.