module wildcard; const setdma = 26; {set dma address and segment} findfirst = 17; {search for first bdos function} findnext = 18; {search for next bdos function} type filename = packed array [1..14] of char; {a file name} fileptr = ^filedescr; filedescr = record nametext: filename; {name of the file} next: fileptr; {next in the list} end; filepart = packed array [1..8] of char; {file name part} typepart = packed array [1..3] of char; {file type part} fileblock = record case boolean of true: (drive: byte; {byte code} name: filepart; {file name} typ: typepart; {file type} extent: byte; {current extent} s1, s2: byte; {unknown} reccount: byte; {record count for current extent} dn: packed array [16..31] of char; {system use} ); false: (init: array [1..16] of integer); end; dirblock = array [0..3] of fileblock; fileblptr = ^fileblock; dirblkptr = ^dirblock; external function @bdos(func: integer; {function to perform} parm: fileblptr {file block} ): integer; procedure expandwild(prototype: filename; {prototype for files} var firstfile: fileptr {first file found} ); { Create an alphabetized list of files which match the prototype provided by the caller } var searchblk: fileblock; {block for search} answerblk: dirblock; {block to receive file name} i, j: integer; {induction vars} procedure insertfile(drive: byte; {drive designation} name: filepart; {file name} typ: typepart; {file type} var first: fileptr); { Insert a new file name in an alphabetic chain } var f: fileptr; {file name entry being created} i, j: integer; {induction vars} this, last: fileptr; {followers for insertion} found: boolean; {controls iteration} begin new(f); with f^ do begin nametext := ' '; i := 1; for j := 1 to 8 do if name[j] <> ' ' then begin nametext[i] := name[j]; i := i + 1; end; nametext[i] := '.'; i := i + 1; for j := 1 to 3 do if typ[j] <> ' ' then begin nametext[i] := typ[j]; i := i + 1; end; end; last := nil; this := first; repeat if this = nil then found := true else found := this^.nametext > f^.nametext; if not found then begin last := this; this := this^.next; end; until found; f^.next := this; if last = nil then first := f else last^.next := f; end; {insertfile} begin firstfile := nil; for i := 1 to 16 do searchblk.init[i] := 0; i := 1; j := 1; with searchblk do begin drive := 0; name := ' '; typ := ' '; if prototype[2] = ':' then begin drive := ord(prototype[1]) - ord('A') + 1; i := 3; end; repeat begin if prototype[i] = '*' then while j <= 8 do begin name[j] := '?'; j := j + 1; end else begin name[j] := prototype[i]; j := j + 1; end; end; i := i + 1; until (j > 8) or (prototype[i] = '.'); while (prototype[i] <> '.') and (prototype[i] <> ' ') do i := i + 1; i := i + 1; j := 1; repeat begin if prototype[i] = '*' then while j <= 3 do begin typ[j] := '?'; j := j + 1; end else begin typ[j] := prototype[i]; j := j + 1; end; end; i := i + 1; until (j > 3) or (prototype[i] = '.'); end; i := @bdos(setdma, addr(answerblk)); i := @bdos(findfirst, addr(searchblk)); while i <> 255 do begin with answerblk[i] do insertfile(drive, name, typ, firstfile); i := @bdos(findnext, addr(searchblk)); end; end; {filestring} modend .