{$A-}
PROGRAM TOOLS;
{$I TOOLU.PAS}
{$I INITCMD.PAS}
VAR CMDPTR:FILE;
  STR,STR1:STRING80;
  COMMAND:XSTRING;
  DONE:BOOLEAN;
  I:INTEGER;



PROCEDURE SETCHAIN(S:STRING80);
BEGIN
  ASSIGN(CMDPTR,CONCAT(S,'.CHN'));DONE:=TRUE
END;
BEGIN
  DONE:=FALSE;
  WHILE NOT DONE DO BEGIN
    INITCMD;
    IF GETARG(1,COMMAND,MAXSTR) THEN BEGIN
      STR:='';
      STR1:='X';
      FOR I:=1 TO XLENGTH(COMMAND) DO BEGIN
        if COMMAND[I]in[97..122]then str1[1]:=chr(command[i]-32)
        ELSE STR1[1]:=chr(COMMAND[I]);
        STR:=CONCAT(STR,STR1)
      END;
      writeln(str);
      IF(STR='CHARCOUNT')OR
      (STR='COPY')OR
      (STR='LINECOUNT')OR
      (STR='WORDCOUNT')OR
      (STR='DETAB')OR
      (STR='DIR')
      THEN BEGIN
      SETCHAIN('CHAPTER1')
      END
      ELSE IF (STR='ENTAB')OR
            (STR='OVERSTRIKE')OR
            (STR='COMPRESS')OR
            (STR='EXPAND')OR
            (STR='ECHO')OR
            (STR='TRANSLIT')THEN BEGIN
      SETCHAIN('CHAPTER2') END
      ELSE IF (STR='COMPARE')OR
            (STR='INCLUDE')OR
            (STR='CONCAT')OR
            (STR='PRINT')OR
            (STR='MAKECOPY')OR
            (STR='ARCHIVE')THEN BEGIN
      SETCHAIN('CHAPTER3') END
      ELSE IF (STR='SORT')OR
            (STR='UNIQUE')OR
            (STR='KWIC')OR
            (STR='ROTATE')OR
            (STR='UNROTATE')THEN BEGIN
      SETCHAIN('CHAPTER4') END
      ELSE IF (STR='FIND')OR
            (STR='CHANGE')THEN BEGIN
      SETCHAIN('CHAPTER5') END
      ELSE IF (STR='EDIT')THEN BEGIN
      SETCHAIN('CHAPTER6') END
      ELSE IF (STR='FORMAT')THEN BEGIN
      SETCHAIN('CHAPTER7') END
      ELSE IF (STR='DEFINE')OR
            (STR='MACRO')THEN BEGIN
      SETCHAIN('CHAPTER8') END

      ELSE IF (STR='QUIT')THEN {BDOS(0,0)} HALT  {N.J.R}
    END
    ELSE BEGIN WRITELN('?');DONE:=FALSE END

  END;
  CHAIN(CMDPTR)
END.


