54 lines · 1.9 KB · Text
RawDownload
= complete: file name completion     include "complete.m";    complete := load Complete Complete->PATH;     Completion: adt {        advance:  int;    # whether forward progress has been made        complete: int;    # whether the completion now represents a file or directory        str:      string; # string to advance, suffixed " " (file) or "/" (directory)        nmatch:   int;    # number of files that matched        filename: array of string;    # their names    };        init:     fn();    complete: fn(dir, s: string): (ref Completion, string);    Complete implements file name completion. Init must be called before any other operation of the module. Given  a  directory  dir  and  a string s, complete returns atuple (c, err), where c is an analysis of the file  names  inthat  directory  that  begin  with  the  string s.  The fieldnmatch will be set to the number of files that match the pre‐fix  and filename will be filled in with their names.  If thefile named is a directory, a slash character will be appendedto it.  On an error, c is nil and err is a diagnostic string. If  no  files match the string, nmatch will be zero, but com‐plete will return the full set of files in the directory. The flag advance reports whether the string s can be extendedwithout  changing  the set of files that match.  If true, strwill be set to the extension; that is, the value of  str  maybe  appended  to s by the caller to extend the embryonic filename unambiguously. The flag complete reports  whether  the  extended  file  nameuniquely  identifies  a  file.  If true, str will be suffixedwith a blank, or a slash and a blank,  depending  on  whetherthe  resulting  file name identifies a plain file or a direc‐tory. == source/appl/lib/complete.b == see ALSOnames(2) == diagnosticsThe complete function returns a nil reference and a  diagnos‐tic  string  if  the directory is unreadable or there is someother error.