home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky alt.sources:2888 comp.lang.pascal:7694
- Path: sparky!uunet!munnari.oz.au!spool.mu.edu!yale.edu!yale!gumby!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!ersys!alpha3!news
- From: russell@alpha3.ersys.edmonton.ab.ca (Russell Schulz)
- Newsgroups: alt.sources,comp.lang.pascal
- Subject: ms-dog turbo pascal device detection
- Message-ID: <921227.135811.0f0.rusnews.w164w@alpha3.ersys.edmonton.ab.ca>
- Date: Sun, 27 Dec 92 13:58:11 MST
- Followup-To: alt.sources.d,comp.lang.pascal
- Organization: Private System, Edmonton, AB, Canada
- X-Newsreader: rusnews v0.97
- Lines: 120
-
- Archive-name: isdev.pas
- Submitted-by: russell@alpha3.ersys.edmonton.ab.ca
-
- as ms-dog doesn't keep devices in the /dev tree, and there is no small amount
- of grief that can result from writing to a dynamically reserved filename (it
- can be reserved on your system, but not on the one next to you) I wrote this
- function which will return true iff use of the filename would be intercepted
- as an attempt to access a device instead of a file.
-
- please don't repeat the comments that old ms-dog used to be able to restrict
- devices to \dev, and newer versions don't, unless it's something no one else
- has ever heard before... :-)
-
- isdev('con') should return true
- isdev('c:/faq/aux.faq') should return true
- isdev('..\emmxxxx0') could return true or false - thus this function
-
- I'm using turbo pascal 4 on dr-dos 6, and it's working here. please let
- me know if it fails on your system! thanks.
-
- followups redirected (barely).
-
- function unslash(s: string): string;
-
- var
- i: integer;
- result: string;
-
- begin
- result := s;
- for i := 1 to length(result) do
- if result[i]='/' then
- result[i] := '\';
- unslash := result;
- end;
-
- function upper(s: string): string;
-
- var
- result: string;
- i: integer;
-
- begin
- result := s;
- for i := 1 to length(s) do
- result[i] := upcase(result[i]);
- upper := result;
- end;
-
- function isdev(s: string): boolean;
-
- var
- offs: word;
- segm: word;
- oldsegm: word;
- foundnul: boolean;
- result: boolean;
- basename: string;
- i: integer;
-
- begin
- result := false;
- segm := 0;
- offs := $400;
-
- basename := upper(unslash(s));
-
- {handle lpt1: case}
- if copy(basename,length(basename),1)=':' then
- basename := copy(basename,1,length(basename)-1);
-
- {strip disk and path designators}
- while pos(':',basename)<>0 do
- basename := copy(basename,pos(':',basename)+1,255);
- while pos('\',basename)<>0 do
- basename := copy(basename,pos('\',basename)+1,255);
-
- {strip anything after the first period}
- if pos('.',basename)<>0 then
- basename := copy(basename,1,pos('.',basename)-1);
-
- {NUL is supposed to be the very last in the chain of installed drivers}
- foundnul := false;
- while (not foundnul) and (offs>0) do
- begin
- if (mem[segm:offs]=ord('N')) and (mem[segm:offs+1]=ord('U')) and
- (mem[segm:offs+2]=ord('L')) and (mem[segm:offs+3]=ord(' ')) and
- (mem[segm:offs+4]=ord(' ')) and (mem[segm:offs+5]=ord(' ')) and
- (mem[segm:offs+6]=ord(' ')) and (mem[segm:offs+7]=ord(' ')) then
- if memw[segm:offs-6]=$8004 then
- foundnul := true;
-
- if not foundnul then
- inc(offs);
- end;
-
- if foundnul then
- begin
-
- while length(basename)<8 do
- basename := basename+' ';
-
- while not result and (meml[segm:offs-10]<>$ffffffff) do
- begin
-
- result := true;
- for i := 0 to 7 do
- result := result and (chr(mem[segm:offs+i])=basename[1+i]);
-
- oldsegm := segm;
- segm := memw[oldsegm:offs-8];
- offs := memw[oldsegm:offs-10]+10;
-
- end;
-
- end;
- isdev := result;
- end;
- --
- Russell Schulz russell@alpha3.ersys.edmonton.ab.ca ersys!rschulz Shad 86c
-