m3msh/derived/MiniShellBundle.m3


MODULE MiniShellBundle;
Generated by m3bundle; see its manpage.

IMPORT Bundle, BundleRep, Text;
IMPORT Thread, Wr, TextWr;

TYPE T = Bundle.T OBJECT OVERRIDES
           get      := LookUp;
           getNames := GetNames;
         END;

TYPE Texts = REF ARRAY OF TEXT;

VAR
  bundle: T     := NIL;
  names : Texts := NIL;

PROCEDURE Get(): Bundle.T =
  BEGIN
    IF (bundle = NIL) THEN bundle := NEW (T) END;
    RETURN bundle;
  END Get;

PROCEDURE GetNames (<*UNUSED*> self: T): Texts =
  BEGIN
    IF names = NIL THEN
      names := NEW (Texts, NUMBER (Names));
      names^ := Names;
    END;
    RETURN names;
  END GetNames;

PROCEDURE LookUp (<*UNUSED*> self: T;  element: TEXT): TEXT =
  BEGIN
    FOR i := 0 TO LAST (Names)-1 DO
      IF Text.Equal (Names[i], element) THEN
        IF Elements[i] = NIL THEN Elements[i] := GetElt (i) END;
        RETURN Elements[i];
      END;
    END;
    RETURN NIL;
  END LookUp;

CONST Names = ARRAY [0..2] OF TEXT {
  "m3msh.desc",
  "m3msh.help",
  NIL
};

VAR Elements := ARRAY [0..2] OF TEXT {
  NIL (* E0 .. E0_0 *),
  E1,
  NIL
};

PROCEDURE GetElt (n: INTEGER): TEXT =
  <*FATAL Thread.Alerted, Wr.Failure *>
  VAR wr := TextWr.New ();
  BEGIN
    CASE n OF
    | 0 =>
        Wr.PutText (wr, E0);
        Wr.PutText (wr, E0_0);
    ELSE (*skip*)
    END;
    RETURN TextWr.ToText (wr);
  END GetElt;

CONST E0 =
   "NAME\n\n  m3msh -- the Modula-3 Mini Shell (part of Elego ComPact (tm))"
 & "\n\nSYNTAX\n\n  m3msh ( -help | -h | -man | -desc | -cr)\n  m3msh [-v] "
 & "[-d] [-q] [-qc char] [-npc|-nopathnameconversion] \n        [-noic | -n"
 & "ointernalcmds] [--] <cmdlist>\n\n  <cmdlist> ::= <cmd>\n             | "
 & " <cmd> && <cmd>\n             |  <cmd> || <cmd>\n             |  <cmd> "
 & ";  <cmd>\n\nOPTIONS\n  -v         be verbose\n  -d         produce debu"
 & "g output\n  -q         run more quietly\n  -qc char   change the no-glo"
 & "bbing quote character    \n  -npc       do not convert pathnames on the"
 & " command line to the native\n             syntax of the current operati"
 & "ng system (win32 or posix)\n  -noic      do not use internal implementa"
 & "tions for commands touch,\n             mkdir, rmfile, rmdir, rmrec\n  "
 & "--         stop processing of arguments\n\nSEMANTICS\n\n  The Modula-3 "
 & "Mini Shell is a very simple shell that is used to\n  execute commands i"
 & "n a system (and system shell) independent manner.\n  It is not intended"
 & " to be a real useful interactive shell substitute,\n  though, but imple"
 & "mented to be called by programs of Elego ComPact\n  to execute lists of"
 & " external commands.\n\n  The shell either executes the commands passed "
 & "to it when invoked,\n  or reads commands from stdin until EOF is encoun"
 & "tered.\n\n  Every command may contain simple input and output redirecti"
 & "ons. \n  If a token inside a command is any of\n\n    `>\', `1>\', `<\'"
 & ", `2>\', `&>\', `>>\', `1>>\', `2>>\', `&>>\', \n \n  then the next tok"
 & "en is treated as the corresponding filename that is\n  to be used as so"
 & "urce or sink of bytes. The redirections have the\n  following meaning: "
 & "\n\n     < fn   : read stdin from file fn\n     > fn   : write stdout i"
 & "nto file fn\n     1> fn  : write stdout into file fn\n     2> fn  : wri"
 & "te stderr into file fn\n     &> fn  : write stdout and stderr into file"
 & " fn\n     >> fn  : append stdout to file fn\n     1>> fn : append stdou"
 & "t to file fn\n     2>> fn : append stderr to file fn\n     &>> fn : app"
 & "end stdout and stderr to file fn\n\n  Tokens are always separated by wh"
 & "itespa";

CONST E0_0 =
   "ce, so \"ls >foo\" won\'t work,\n  while \"ls > foo\" does.\n\n  Wildca"
 & "rd Expansion\n  ------------------\n\n  If a parameter to a command con"
 & "tains the characters `*\' or `?\',\n  it is considered to be a shell gl"
 & "obbing pattern. A `*\' expands\n  to an arbitrary sequence of any lengt"
 & "h, while a `?\' must be\n  matched by exactly one character. Leading pe"
 & "riods are not\n  matched by `*\'. If globbing is not desired, the argum"
 & "ent must\n  be quoted using the special quote character, which defaults"
 & " to\n  backquote (`). The quote character must immediately precede the\n"
 & "  argument; ending quotes are not necessary and will be treated as \n  "
 & "a literal.\n\n  Internal Commands\n  -----------------\n  \n  The follo"
 & "wing commands are internally implemented and are preferred\n  to any ex"
 & "ternal programs of the same name. Except for `echo\' this\n  may be dis"
 & "abled by the option `-noic\'.\n\n    touch   <pn>+        \n      -- cr"
 & "eate one or more empty files\n    mkdir   <pn>+\n      -- create one or"
 & " more directory hierarchies\n    rm [-r] <pn>+\n      -- remove [recurs"
 & "ively] one or more files or directories\n    rmdir   <pn>+\n      -- re"
 & "move one or more directories\n    echo    <arg>*\n      -- echo all arg"
 & "uments to stdout\n    list [-r] [-l] [-in] [-post] <pn>*\n      -- list"
 & " the names of one or more files [-r: recursively]\n         [-l: includ"
 & "e file type] [-in: inorder traversal]\n         [-post: postorder trave"
 & "rsal]\n\n  (Internal echo cannot be disabled.)\n\nVERSION\n\n This is t"
 & "he third version of m3msh.\n\nBUGS\n\n o Pipes are not yet implemented "
 & ":-(\n\nFILES AND RESOURCES\n\n  MiniShellBundle  -- m3msh documentation"
 & " bundle\n";

CONST E1 =
   "NAME\n\n  m3msh -- the Modula-3 Mini Shell (part of Elego ComPact (tm))"
 & "\n\nSHORT DESCRIPTION\n\n  The Modula-3 Mini Shell is a very simple she"
 & "ll that is used to\n  execute commands in a system (and system shell) i"
 & "ndependent manner.\n  It is not intended to be a real useful interactiv"
 & "e shell substitute,\n  though, but implemented to be called by programs"
 & " of Elego ComPact\n  to execute lists of external commands.\n\nUSE\n\n "
 & " m3msh ( -help | -h | -man | -desc | -cr )\n  m3msh [-v] [-d] [-q] [-qc"
 & " char] [-npc|-nopathnameconversion] \n        [-noic | -nointernalcmds]"
 & " [--] <cmdlist>\n\n  <cmdlist> ::= <cmd>\n             |  <cmd> && <cmd"
 & ">\n             |  <cmd> || <cmd>\n             |  <cmd> ;  <cmd>\n\n  "
 & "Internally implemented commands:\n\n    touch   <pn>+\n    mkdir   <pn>"
 & "+\n    rm [-r] <pn>+\n    rmdir   <pn>+\n    echo    <arg>*\n    list ["
 & "-r] [-l] [-in] [-post] <pn>*\n\n  (Internal echo cannot be disabled.)\n"
 & "\nFILES AND RESOURCES\n\n  MiniShellBundle  -- m3msh documentation bund"
 & "le\n";

BEGIN
END MiniShellBundle.