-- File: CmFile.mesa - last edit:
  -- Evans: March 13, 1980  10:23 AM
  -- Tom: Aug 29, 1979 10:38 AM
  -- Mark: Sep 4, 1980 8:16 PM
  -- Smokey: Dec 29, 1978 5:13 PM
  
DIRECTORY
  Ascii USING [NUL],
  Compatibility USING [SHandle],
  String USING [SubString];
  
CmFile: DEFINITIONS =
  BEGIN
  
-- Routines to process any Cm file

  Open: PROCEDURE [fileName: STRING];
  Close: PROCEDURE [fileName: STRING];
  Line: PROCEDURE [fileName, title, name: STRING] RETURNS [STRING];
  
  NextItem: PROCEDURE RETURNS [name, args: STRING];
  OpenSection: PROCEDURE [fileName, title: STRING] RETURNS [BOOLEAN];
  
  -- Use "User.cm" as fileName in above
  
  UserDotCmOpen: PROCEDURE;
  UserDotCmClose: PROCEDURE;
  UserDotCmLine: PROCEDURE [title, name: STRING] RETURNS [STRING];
  
  UserDotCmNextItem: PROCEDURE RETURNS [name, args: STRING];
  UserDotCmOpenSection: PROCEDURE [title: STRING] RETURNS [BOOLEAN];
  
-- Utilities

  Lop: PROCEDURE [ss: String.SubString] RETURNS [c: CHARACTER] = INLINE
    BEGIN
    IF ss.length = 0 THEN c ← Ascii.NUL ELSE
      {c ← ss.base[ss.offset]; ss.offset ← ss.offset+1; ss.length ← ss.length-1};
    END;
  GetNextToken: PROCEDURE [source: String.SubString, token: STRING] RETURNS [valid: BOOLEAN];
  GetNextTokenAsABoolean: PROCEDURE [source: String.SubString] RETURNS [b: BOOLEAN];
  GetNextTokenAsANumber: PROCEDURE [source: String.SubString] RETURNS [i: INTEGER];
  ReadLineOrToken: PROCEDURE [
    sh: Compatibility.SHandle, buffer: STRING, terminator: CHARACTER]
    RETURNS [CHARACTER];
  TitleMatch: PROCEDURE [buffer, title: STRING] RETURNS [BOOLEAN];
  
-- SIGNALs (and their codes) that can be raised

  ErrorCode: TYPE = {multipleOpens, noneOpen, notOpen};
  Error: SIGNAL [code: ErrorCode];
  
END. -- of CmFile