-- ListInterface.mesa; modified by Bruce, July 8, 1980  9:34 AM

DIRECTORY
  CommanderDefs USING [AddCommand, CommandBlockHandle],
  IODefs USING [CR, WriteString],
  ListerDefs USING [
    IncorrectVersion, Load, MultipleModules, NoCode, NoFGT, NoSymbols, PrintSei,
    SetRoutineSymbols, WriteFileID],
  OutputDefs USING [
    CloseOutput, NumberFormat, OpenOutput, PutChar, PutNumber, PutString],
  SegmentDefs USING [
    DeleteFileSegment, FileNameError, FileSegmentHandle, SwapError],
  String USING [AppendString],
  Symbols USING [ISEIndex, ISENull, TransferMode],
  SymbolTable USING [Acquire, Base, Release, TableForSegment];

ListInterface: PROGRAM
  IMPORTS
    CommanderDefs, IODefs, ListerDefs, OutputDefs, SegmentDefs, String,
    SymbolTable
  EXPORTS ListerDefs =
  BEGIN OPEN ListerDefs, OutputDefs, Symbols;
  
  symbols: SymbolTable.Base;
  
  PrintInterface: PROCEDURE =
    BEGIN OPEN symbols;
    sei: ISEIndex;
    FOR sei ← FirstCtxSe[stHandle.outerCtx], NextSe[sei] UNTIL sei = ISENull DO
      SELECT LinkMode[
	sei] FROM
	val =>
	  BEGIN
	  PutValue[seb[sei].idValue, sei];
	  PutModeName[XferMode[seb[sei].idType]];
	  PutChar[IODefs.CR];
	  END;
	ref =>
	  BEGIN
	  PutValue[seb[sei].idValue, sei];
	  PutString["EXPORTED Variable"L];
	  PutChar[IODefs.CR];
	  END;
	manifest => NULL; -- constant
	
	ENDCASE;
      ENDLOOP;
    RETURN
    END;
    
  PutValue: PROCEDURE [u: UNSPECIFIED, sei: ISEIndex] =
    BEGIN
    number: NumberFormat = NumberFormat[10, FALSE, FALSE, 4];
    PutNumber[u, number];
    PutString[" -- "L];
    PrintSei[sei];
    PutString[": "L];
    END;
    
  ModePrintName: ARRAY TransferMode OF STRING =
    ["PROCEDURE", "PORT", "SIGNAL", "ERROR", "PROCESS", "PROGRAM", "NONE"];
  
  PutModeName: PROCEDURE [n: TransferMode] =
    BEGIN PutString[ModePrintName[n]]; RETURN END;
    
  Interface: PROCEDURE [root: STRING] =
    BEGIN OPEN String, SegmentDefs;
    i: CARDINAL;
    defs: BOOLEAN ← FALSE;
    bcdFile: STRING ← [40];
    sseg: FileSegmentHandle;
    AppendString[bcdFile, root];
    FOR i IN [0..bcdFile.length) DO
      IF bcdFile[i] = '. THEN EXIT;
      REPEAT FINISHED => AppendString[bcdFile, ".bcd"];
      ENDLOOP;
    BEGIN
    [symbols: sseg] ← Load[
      bcdFile ! NoFGT => RESUME ; NoCode => BEGIN defs ← TRUE; RESUME END;
      NoSymbols, IncorrectVersion, MultipleModules => GOTO badformat;
      SegmentDefs.FileNameError => GOTO badname];
    IF ~defs THEN GOTO badformat;
    symbols ← SymbolTable.Acquire[SymbolTable.TableForSegment[sseg]];
    ListerDefs.SetRoutineSymbols[symbols];
    OpenOutput[root, ".il"];
    WriteFileID[];
    PrintInterface[];
    SymbolTable.Release[symbols];
    SegmentDefs.DeleteFileSegment[sseg ! SegmentDefs.SwapError => CONTINUE];
    CloseOutput[];
    EXITS
      badformat => IODefs.WriteString["Bad Format!"];
      badname => IODefs.WriteString["File Not Found!"];
    END;
    END;
    
  command: CommanderDefs.CommandBlockHandle;
  
  command ← CommanderDefs.AddCommand["Interface", LOOPHOLE[Interface], 1];
  command.params[0] ← [type: string, prompt: "Filename"];
  
  END...