-- CatalogComm.Mesa
-- last edit, Schroeder, February 3, 1983 2:09 pm

  DIRECTORY
    IO USING [Handle],
    Rope USING [ROPE],
    STP USING [ErrorCode, FileInfo, Handle],
    UECP USING [Argv],
    UserExec USING [ExecHandle, HistoryEvent];
    
CatalogComm: DEFINITIONS = {

Handle: TYPE = REF CatalogObject;

CatalogErrorType: TYPE = { nilDirectory, nilFilename, cantFindDirectory,
  badDirectoryName, parentNotFound, unknownTopLevelDirectory,
  topLevelDirectoryFoundTwice, cantCreateLocalFile, unKnownError,
  implementationRestriction, cantEnumerate, dirdirFoundTwice, catalogAbort, cantResume
  };
  
CatalogError: ERROR[e: CatalogErrorType];

ThingType: TYPE = {directory, file, link};
  
Node: TYPE = RECORD [
  what: ThingType,
  directory: Rope.ROPE ← NIL,
  name: Rope.ROPE ← NIL,
  target: Rope.ROPE ← NIL,
  comment: Rope.ROPE ← NIL
  ];
  
Directory: TYPE = RECORD [
  name: Rope.ROPE,
  entryMade: BOOL ← FALSE,
  oldDirExists: BOOL ← FALSE,
  fileCount: INT ← 0,
  directoryCount: INT ← 0,
  linkCount: INT ← 0,
  commentCount: INT ← 0,
  chain: LIST OF REF  -- Node
  ];
  
CatalogObject: TYPE = RECORD [
  argv: UECP.Argv,
  cmdindex: NAT ← 1,
  root: LIST OF REF Directory,
  filesystem: Rope.ROPE,
  directory: Rope.ROPE,
  locEnumFileName: Rope.ROPE,
  reportSignals: BOOL ← FALSE,
  doStoreRemote: BOOL ← TRUE,
  listLocal: BOOL ← FALSE,
  readLocal: BOOL ← FALSE,
  listDirsOnly: BOOL ← FALSE,
  saveLinksComments: BOOL ← TRUE,
  verbose: BOOL ← FALSE,
  current: REF Directory,
  fCount: NAT,
  in, out: IO.Handle,
  eh: UserExec.ExecHandle,
  he: UserExec.HistoryEvent,
  oldWorkingDir: Rope.ROPE,
  oldSearchRules: LIST OF Rope.ROPE,
  name: Rope.ROPE,
  password: Rope.ROPE
  ];

NoneFound: SIGNAL;

GetLine: PROC[h: Handle, sh: IO.Handle, line: LONG STRING] RETURNS[noteof: BOOL];
FindFirst: PROC [s: Rope.ROPE, c: CHAR, start: INT] RETURNS [loc: INT];
FindLast: PROC [s: Rope.ROPE, c: CHAR] RETURNS [loc: INT];
SubStringCopy: PROC [s: Rope.ROPE, start, stop: INT] RETURNS [ns: Rope.ROPE];
LFindFirst: PROC [s: LONG STRING, c: CHAR, start: NAT] RETURNS [loc: NAT];
LFindLast: PROC [s: LONG STRING, c: CHAR] RETURNS [loc: NAT];
LSubStringAppend: PROC [from, to: LONG STRING, start, stop: NAT];
CatalogList: PROC [h: Handle, key: Rope.ROPE, entry: Rope.ROPE, depth: INTEGER, dirsOnly: BOOL, comment: Rope.ROPE ← NIL];
FreeWorld: PROC [h: Handle];
CatalogErrorString: PROC [error: CatalogErrorType] RETURNS [Rope.ROPE];
HandleSTPError: PROC[h: Handle, stphandle: STP.Handle, stpError: STP.ErrorCode, 
	message: STRING] RETURNS [retryit: BOOL];
CheckForAbort: PROC [h: Handle] RETURNS [BOOL];
Connect: PROC [h: Handle, host: Rope.ROPE] RETURNS[stphandle: STP.Handle];
EnumFromRemoteFile: PROC [h: Handle];
EnumFromLocalFile: PROC [h: Handle];
ParseFile: PROC [h: Handle, vf: STP.FileInfo];
}.