xref: /freebsd/bin/sh/TOUR (revision 3835f47c7e144fc73123f5d5706c6ec666cf3ae4)
14b88c807SRodney W. Grimes#	@(#)TOUR	8.1 (Berkeley) 5/31/93
22a456239SPeter Wemm# $FreeBSD$
34b88c807SRodney W. Grimes
44b88c807SRodney W. GrimesNOTE -- This is the original TOUR paper distributed with ash and
54b88c807SRodney W. Grimesdoes not represent the current state of the shell.  It is provided anyway
64b88c807SRodney W. Grimessince it provides helpful information for how the shell is structured,
74b88c807SRodney W. Grimesbut be warned that things have changed -- the current shell is
84b88c807SRodney W. Grimesstill under development.
94b88c807SRodney W. Grimes
104b88c807SRodney W. Grimes================================================================
114b88c807SRodney W. Grimes
124b88c807SRodney W. Grimes                       A Tour through Ash
134b88c807SRodney W. Grimes
144b88c807SRodney W. Grimes               Copyright 1989 by Kenneth Almquist.
154b88c807SRodney W. Grimes
164b88c807SRodney W. Grimes
174b88c807SRodney W. GrimesDIRECTORIES:  The subdirectory bltin contains commands which can
184b88c807SRodney W. Grimesbe compiled stand-alone.  The rest of the source is in the main
194b88c807SRodney W. Grimesash directory.
204b88c807SRodney W. Grimes
214b88c807SRodney W. GrimesSOURCE CODE GENERATORS:  Files whose names begin with "mk" are
224b88c807SRodney W. Grimesprograms that generate source code.  A complete list of these
234b88c807SRodney W. Grimesprograms is:
244b88c807SRodney W. Grimes
250ef05a46SJens Schweikhardt        program         input files         generates
260ef05a46SJens Schweikhardt        -------         -----------         ---------
274b88c807SRodney W. Grimes        mkbuiltins      builtins            builtins.h builtins.c
284b88c807SRodney W. Grimes        mkinit          *.c                 init.c
294b88c807SRodney W. Grimes        mknodes         nodetypes           nodes.h nodes.c
304b88c807SRodney W. Grimes        mksignames          -               signames.h signames.c
314b88c807SRodney W. Grimes        mksyntax            -               syntax.h syntax.c
32aa9caaf6SPeter Wemm        mktokens            -               token.h
334b88c807SRodney W. Grimes        bltin/mkexpr    unary_op binary_op  operators.h operators.c
344b88c807SRodney W. Grimes
354b88c807SRodney W. GrimesThere are undoubtedly too many of these.  Mkinit searches all the
364b88c807SRodney W. GrimesC source files for entries looking like:
374b88c807SRodney W. Grimes
384b88c807SRodney W. Grimes        INIT {
394b88c807SRodney W. Grimes              x = 1;    /* executed during initialization */
404b88c807SRodney W. Grimes        }
414b88c807SRodney W. Grimes
424b88c807SRodney W. Grimes        RESET {
434b88c807SRodney W. Grimes              x = 2;    /* executed when the shell does a longjmp
444b88c807SRodney W. Grimes                           back to the main command loop */
454b88c807SRodney W. Grimes        }
464b88c807SRodney W. Grimes
474b88c807SRodney W. GrimesIt pulls this code out into routines which are when particular
484b88c807SRodney W. Grimesevents occur.  The intent is to improve modularity by isolating
494b88c807SRodney W. Grimesthe information about which modules need to be explicitly
504b88c807SRodney W. Grimesinitialized/reset within the modules themselves.
514b88c807SRodney W. Grimes
524b88c807SRodney W. GrimesMkinit recognizes several constructs for placing declarations in
534b88c807SRodney W. Grimesthe init.c file.
544b88c807SRodney W. Grimes        INCLUDE "file.h"
554b88c807SRodney W. Grimesincludes a file.  The storage class MKINIT makes a declaration
564b88c807SRodney W. Grimesavailable in the init.c file, for example:
574b88c807SRodney W. Grimes        MKINIT int funcnest;    /* depth of function calls */
584b88c807SRodney W. GrimesMKINIT alone on a line introduces a structure or union declara-
594b88c807SRodney W. Grimestion:
604b88c807SRodney W. Grimes        MKINIT
614b88c807SRodney W. Grimes        struct redirtab {
624b88c807SRodney W. Grimes              short renamed[10];
634b88c807SRodney W. Grimes        };
644b88c807SRodney W. GrimesPreprocessor #define statements are copied to init.c without any
654b88c807SRodney W. Grimesspecial action to request this.
664b88c807SRodney W. Grimes
674b88c807SRodney W. GrimesINDENTATION:  The ash source is indented in multiples of six
684b88c807SRodney W. Grimesspaces.  The only study that I have heard of on the subject con-
694b88c807SRodney W. Grimescluded that the optimal amount to indent is in the range of four
704b88c807SRodney W. Grimesto six spaces.  I use six spaces since it is not too big a jump
714b88c807SRodney W. Grimesfrom the widely used eight spaces.  If you really hate six space
724b88c807SRodney W. Grimesindentation, use the adjind (source included) program to change
734b88c807SRodney W. Grimesit to something else.
744b88c807SRodney W. Grimes
754b88c807SRodney W. GrimesEXCEPTIONS:  Code for dealing with exceptions appears in
764b88c807SRodney W. Grimesexceptions.c.  The C language doesn't include exception handling,
774b88c807SRodney W. Grimesso I implement it using setjmp and longjmp.  The global variable
784b88c807SRodney W. Grimesexception contains the type of exception.  EXERROR is raised by
79*3835f47cSJilles Tjoelkercalling error.  EXINT is an interrupt.
804b88c807SRodney W. Grimes
814b88c807SRodney W. GrimesINTERRUPTS:  In an interactive shell, an interrupt will cause an
824b88c807SRodney W. GrimesEXINT exception to return to the main command loop.  (Exception:
834b88c807SRodney W. GrimesEXINT is not raised if the user traps interrupts using the trap
844b88c807SRodney W. Grimescommand.)  The INTOFF and INTON macros (defined in exception.h)
850ef05a46SJens Schweikhardtprovide uninterruptible critical sections.  Between the execution
864b88c807SRodney W. Grimesof INTOFF and the execution of INTON, interrupt signals will be
874b88c807SRodney W. Grimesheld for later delivery.  INTOFF and INTON can be nested.
884b88c807SRodney W. Grimes
894b88c807SRodney W. GrimesMEMALLOC.C:  Memalloc.c defines versions of malloc and realloc
904b88c807SRodney W. Grimeswhich call error when there is no memory left.  It also defines a
914b88c807SRodney W. Grimesstack oriented memory allocation scheme.  Allocating off a stack
924b88c807SRodney W. Grimesis probably more efficient than allocation using malloc, but the
934b88c807SRodney W. Grimesbig advantage is that when an exception occurs all we have to do
944b88c807SRodney W. Grimesto free up the memory in use at the time of the exception is to
954b88c807SRodney W. Grimesrestore the stack pointer.  The stack is implemented using a
964b88c807SRodney W. Grimeslinked list of blocks.
974b88c807SRodney W. Grimes
984b88c807SRodney W. GrimesSTPUTC:  If the stack were contiguous, it would be easy to store
994b88c807SRodney W. Grimesstrings on the stack without knowing in advance how long the
1004b88c807SRodney W. Grimesstring was going to be:
1014b88c807SRodney W. Grimes        p = stackptr;
1024b88c807SRodney W. Grimes        *p++ = c;       /* repeated as many times as needed */
1034b88c807SRodney W. Grimes        stackptr = p;
1040ef05a46SJens SchweikhardtThe following three macros (defined in memalloc.h) perform these
1054b88c807SRodney W. Grimesoperations, but grow the stack if you run off the end:
1064b88c807SRodney W. Grimes        STARTSTACKSTR(p);
1074b88c807SRodney W. Grimes        STPUTC(c, p);   /* repeated as many times as needed */
1084b88c807SRodney W. Grimes        grabstackstr(p);
1094b88c807SRodney W. Grimes
1104b88c807SRodney W. GrimesWe now start a top-down look at the code:
1114b88c807SRodney W. Grimes
1124b88c807SRodney W. GrimesMAIN.C:  The main routine performs some initialization, executes
1130ef05a46SJens Schweikhardtthe user's profile if necessary, and calls cmdloop.  Cmdloop
1144b88c807SRodney W. Grimesrepeatedly parses and executes commands.
1154b88c807SRodney W. Grimes
1164b88c807SRodney W. GrimesOPTIONS.C:  This file contains the option processing code.  It is
1174b88c807SRodney W. Grimescalled from main to parse the shell arguments when the shell is
1184b88c807SRodney W. Grimesinvoked, and it also contains the set builtin.  The -i and -j op-
1194b88c807SRodney W. Grimestions (the latter turns on job control) require changes in signal
1204b88c807SRodney W. Grimeshandling.  The routines setjobctl (in jobs.c) and setinteractive
1214b88c807SRodney W. Grimes(in trap.c) are called to handle changes to these options.
1224b88c807SRodney W. Grimes
1234b88c807SRodney W. GrimesPARSING:  The parser code is all in parser.c.  A recursive des-
1244b88c807SRodney W. Grimescent parser is used.  Syntax tables (generated by mksyntax) are
1254b88c807SRodney W. Grimesused to classify characters during lexical analysis.  There are
1264b88c807SRodney W. Grimesthree tables:  one for normal use, one for use when inside single
1274b88c807SRodney W. Grimesquotes, and one for use when inside double quotes.  The tables
1284b88c807SRodney W. Grimesare machine dependent because they are indexed by character vari-
1294b88c807SRodney W. Grimesables and the range of a char varies from machine to machine.
1304b88c807SRodney W. Grimes
1314b88c807SRodney W. GrimesPARSE OUTPUT:  The output of the parser consists of a tree of
1324b88c807SRodney W. Grimesnodes.  The various types of nodes are defined in the file node-
1334b88c807SRodney W. Grimestypes.
1344b88c807SRodney W. Grimes
1354b88c807SRodney W. GrimesNodes of type NARG are used to represent both words and the con-
1364b88c807SRodney W. Grimestents of here documents.  An early version of ash kept the con-
1374b88c807SRodney W. Grimestents of here documents in temporary files, but keeping here do-
1384b88c807SRodney W. Grimescuments in memory typically results in significantly better per-
1394b88c807SRodney W. Grimesformance.  It would have been nice to make it an option to use
1404b88c807SRodney W. Grimestemporary files for here documents, for the benefit of small
1414b88c807SRodney W. Grimesmachines, but the code to keep track of when to delete the tem-
1424b88c807SRodney W. Grimesporary files was complex and I never fixed all the bugs in it.
1434b88c807SRodney W. Grimes(AT&T has been maintaining the Bourne shell for more than ten
1444b88c807SRodney W. Grimesyears, and to the best of my knowledge they still haven't gotten
1454b88c807SRodney W. Grimesit to handle temporary files correctly in obscure cases.)
1464b88c807SRodney W. Grimes
1474b88c807SRodney W. GrimesThe text field of a NARG structure points to the text of the
1484b88c807SRodney W. Grimesword.  The text consists of ordinary characters and a number of
1494b88c807SRodney W. Grimesspecial codes defined in parser.h.  The special codes are:
1504b88c807SRodney W. Grimes
1514b88c807SRodney W. Grimes        CTLVAR              Variable substitution
1524b88c807SRodney W. Grimes        CTLENDVAR           End of variable substitution
1534b88c807SRodney W. Grimes        CTLBACKQ            Command substitution
1544b88c807SRodney W. Grimes        CTLBACKQ|CTLQUOTE   Command substitution inside double quotes
1554b88c807SRodney W. Grimes        CTLESC              Escape next character
1564b88c807SRodney W. Grimes
1574b88c807SRodney W. GrimesA variable substitution contains the following elements:
1584b88c807SRodney W. Grimes
1594b88c807SRodney W. Grimes        CTLVAR type name '=' [ alternative-text CTLENDVAR ]
1604b88c807SRodney W. Grimes
1614b88c807SRodney W. GrimesThe type field is a single character specifying the type of sub-
1624b88c807SRodney W. Grimesstitution.  The possible types are:
1634b88c807SRodney W. Grimes
1644b88c807SRodney W. Grimes        VSNORMAL            $var
1654b88c807SRodney W. Grimes        VSMINUS             ${var-text}
1664b88c807SRodney W. Grimes        VSMINUS|VSNUL       ${var:-text}
1674b88c807SRodney W. Grimes        VSPLUS              ${var+text}
1684b88c807SRodney W. Grimes        VSPLUS|VSNUL        ${var:+text}
1694b88c807SRodney W. Grimes        VSQUESTION          ${var?text}
1704b88c807SRodney W. Grimes        VSQUESTION|VSNUL    ${var:?text}
1714b88c807SRodney W. Grimes        VSASSIGN            ${var=text}
1720ef05a46SJens Schweikhardt        VSASSIGN|VSNUL      ${var:=text}
1734b88c807SRodney W. Grimes
1744b88c807SRodney W. GrimesIn addition, the type field will have the VSQUOTE flag set if the
1754b88c807SRodney W. Grimesvariable is enclosed in double quotes.  The name of the variable
1764b88c807SRodney W. Grimescomes next, terminated by an equals sign.  If the type is not
1774b88c807SRodney W. GrimesVSNORMAL, then the text field in the substitution follows, ter-
1784b88c807SRodney W. Grimesminated by a CTLENDVAR byte.
1794b88c807SRodney W. Grimes
1804b88c807SRodney W. GrimesCommands in back quotes are parsed and stored in a linked list.
1814b88c807SRodney W. GrimesThe locations of these commands in the string are indicated by
1824b88c807SRodney W. GrimesCTLBACKQ and CTLBACKQ+CTLQUOTE characters, depending upon whether
1834b88c807SRodney W. Grimesthe back quotes were enclosed in double quotes.
1844b88c807SRodney W. Grimes
1854b88c807SRodney W. GrimesThe character CTLESC escapes the next character, so that in case
1864b88c807SRodney W. Grimesany of the CTL characters mentioned above appear in the input,
1874b88c807SRodney W. Grimesthey can be passed through transparently.  CTLESC is also used to
1884b88c807SRodney W. Grimesescape '*', '?', '[', and '!' characters which were quoted by the
1894b88c807SRodney W. Grimesuser and thus should not be used for file name generation.
1904b88c807SRodney W. Grimes
1914b88c807SRodney W. GrimesCTLESC characters have proved to be particularly tricky to get
1924b88c807SRodney W. Grimesright.  In the case of here documents which are not subject to
1934b88c807SRodney W. Grimesvariable and command substitution, the parser doesn't insert any
1944b88c807SRodney W. GrimesCTLESC characters to begin with (so the contents of the text
1954b88c807SRodney W. Grimesfield can be written without any processing).  Other here docu-
1964b88c807SRodney W. Grimesments, and words which are not subject to splitting and file name
1974b88c807SRodney W. Grimesgeneration, have the CTLESC characters removed during the vari-
1980ef05a46SJens Schweikhardtable and command substitution phase.  Words which are subject to
1994b88c807SRodney W. Grimessplitting and file name generation have the CTLESC characters re-
2004b88c807SRodney W. Grimesmoved as part of the file name phase.
2014b88c807SRodney W. Grimes
2024b88c807SRodney W. GrimesEXECUTION:  Command execution is handled by the following files:
2034b88c807SRodney W. Grimes        eval.c     The top level routines.
2044b88c807SRodney W. Grimes        redir.c    Code to handle redirection of input and output.
2054b88c807SRodney W. Grimes        jobs.c     Code to handle forking, waiting, and job control.
2060ef05a46SJens Schweikhardt        exec.c     Code to do path searches and the actual exec sys call.
2074b88c807SRodney W. Grimes        expand.c   Code to evaluate arguments.
2084b88c807SRodney W. Grimes        var.c      Maintains the variable symbol table.  Called from expand.c.
2094b88c807SRodney W. Grimes
2104b88c807SRodney W. GrimesEVAL.C:  Evaltree recursively executes a parse tree.  The exit
2114b88c807SRodney W. Grimesstatus is returned in the global variable exitstatus.  The alter-
2124b88c807SRodney W. Grimesnative entry evalbackcmd is called to evaluate commands in back
2134b88c807SRodney W. Grimesquotes.  It saves the result in memory if the command is a buil-
2144b88c807SRodney W. Grimestin; otherwise it forks off a child to execute the command and
2154b88c807SRodney W. Grimesconnects the standard output of the child to a pipe.
2164b88c807SRodney W. Grimes
2174b88c807SRodney W. GrimesJOBS.C:  To create a process, you call makejob to return a job
2184b88c807SRodney W. Grimesstructure, and then call forkshell (passing the job structure as
2194b88c807SRodney W. Grimesan argument) to create the process.  Waitforjob waits for a job
2204b88c807SRodney W. Grimesto complete.  These routines take care of process groups if job
2214b88c807SRodney W. Grimescontrol is defined.
2224b88c807SRodney W. Grimes
2234b88c807SRodney W. GrimesREDIR.C:  Ash allows file descriptors to be redirected and then
2244b88c807SRodney W. Grimesrestored without forking off a child process.  This is accom-
2254b88c807SRodney W. Grimesplished by duplicating the original file descriptors.  The redir-
2260ef05a46SJens Schweikhardttab structure records where the file descriptors have been dupli-
2274b88c807SRodney W. Grimescated to.
2284b88c807SRodney W. Grimes
2294b88c807SRodney W. GrimesEXEC.C:  The routine find_command locates a command, and enters
2304b88c807SRodney W. Grimesthe command in the hash table if it is not already there.  The
2314b88c807SRodney W. Grimesthird argument specifies whether it is to print an error message
2324b88c807SRodney W. Grimesif the command is not found.  (When a pipeline is set up,
2334b88c807SRodney W. Grimesfind_command is called for all the commands in the pipeline be-
2344b88c807SRodney W. Grimesfore any forking is done, so to get the commands into the hash
2354b88c807SRodney W. Grimestable of the parent process.  But to make command hashing as
2364b88c807SRodney W. Grimestransparent as possible, we silently ignore errors at that point
2374b88c807SRodney W. Grimesand only print error messages if the command cannot be found
2384b88c807SRodney W. Grimeslater.)
2394b88c807SRodney W. Grimes
2404b88c807SRodney W. GrimesThe routine shellexec is the interface to the exec system call.
2414b88c807SRodney W. Grimes
2424b88c807SRodney W. GrimesEXPAND.C:  Arguments are processed in three passes.  The first
2434b88c807SRodney W. Grimes(performed by the routine argstr) performs variable and command
2444b88c807SRodney W. Grimessubstitution.  The second (ifsbreakup) performs word splitting
2454b88c807SRodney W. Grimesand the third (expandmeta) performs file name generation.  If the
2464b88c807SRodney W. Grimes"/u" directory is simulated, then when "/u/username" is replaced
2474b88c807SRodney W. Grimesby the user's home directory, the flag "didudir" is set.  This
2484b88c807SRodney W. Grimestells the cd command that it should print out the directory name,
2494b88c807SRodney W. Grimesjust as it would if the "/u" directory were implemented using
2504b88c807SRodney W. Grimessymbolic links.
2514b88c807SRodney W. Grimes
2524b88c807SRodney W. GrimesVAR.C:  Variables are stored in a hash table.  Probably we should
2534b88c807SRodney W. Grimesswitch to extensible hashing.  The variable name is stored in the
2544b88c807SRodney W. Grimessame string as the value (using the format "name=value") so that
2554b88c807SRodney W. Grimesno string copying is needed to create the environment of a com-
2564b88c807SRodney W. Grimesmand.  Variables which the shell references internally are preal-
2574b88c807SRodney W. Grimeslocated so that the shell can reference the values of these vari-
2584b88c807SRodney W. Grimesables without doing a lookup.
2594b88c807SRodney W. Grimes
2604b88c807SRodney W. GrimesWhen a program is run, the code in eval.c sticks any environment
2614b88c807SRodney W. Grimesvariables which precede the command (as in "PATH=xxx command") in
2624b88c807SRodney W. Grimesthe variable table as the simplest way to strip duplicates, and
2634b88c807SRodney W. Grimesthen calls "environment" to get the value of the environment.
2644b88c807SRodney W. Grimes
2654b88c807SRodney W. GrimesBUILTIN COMMANDS:  The procedures for handling these are scat-
2664b88c807SRodney W. Grimestered throughout the code, depending on which location appears
2674b88c807SRodney W. Grimesmost appropriate.  They can be recognized because their names al-
2684b88c807SRodney W. Grimesways end in "cmd".  The mapping from names to procedures is
2690ef05a46SJens Schweikhardtspecified in the file builtins, which is processed by the mkbuilt-
2700ef05a46SJens Schweikhardtins command.
2714b88c807SRodney W. Grimes
2724b88c807SRodney W. GrimesA builtin command is invoked with argc and argv set up like a
2734b88c807SRodney W. Grimesnormal program.  A builtin command is allowed to overwrite its
2744b88c807SRodney W. Grimesarguments.  Builtin routines can call nextopt to do option pars-
2754b88c807SRodney W. Grimesing.  This is kind of like getopt, but you don't pass argc and
2764b88c807SRodney W. Grimesargv to it.  Builtin routines can also call error.  This routine
2774b88c807SRodney W. Grimesnormally terminates the shell (or returns to the main command
2784b88c807SRodney W. Grimesloop if the shell is interactive), but when called from a builtin
2794b88c807SRodney W. Grimescommand it causes the builtin command to terminate with an exit
2804b88c807SRodney W. Grimesstatus of 2.
2814b88c807SRodney W. Grimes
2824b88c807SRodney W. GrimesThe directory bltins contains commands which can be compiled in-
2834b88c807SRodney W. Grimesdependently but can also be built into the shell for efficiency
2844b88c807SRodney W. Grimesreasons.  The makefile in this directory compiles these programs
2854b88c807SRodney W. Grimesin the normal fashion (so that they can be run regardless of
2864b88c807SRodney W. Grimeswhether the invoker is ash), but also creates a library named
2874b88c807SRodney W. Grimesbltinlib.a which can be linked with ash.  The header file bltin.h
2884b88c807SRodney W. Grimestakes care of most of the differences between the ash and the
2894b88c807SRodney W. Grimesstand-alone environment.  The user should call the main routine
2904b88c807SRodney W. Grimes"main", and #define main to be the name of the routine to use
2914b88c807SRodney W. Grimeswhen the program is linked into ash.  This #define should appear
2924b88c807SRodney W. Grimesbefore bltin.h is included; bltin.h will #undef main if the pro-
2934b88c807SRodney W. Grimesgram is to be compiled stand-alone.
2944b88c807SRodney W. Grimes
2954b88c807SRodney W. GrimesCD.C:  This file defines the cd and pwd builtins.  The pwd com-
2964b88c807SRodney W. Grimesmand runs /bin/pwd the first time it is invoked (unless the user
2974b88c807SRodney W. Grimeshas already done a cd to an absolute pathname), but then
2984b88c807SRodney W. Grimesremembers the current directory and updates it when the cd com-
2994b88c807SRodney W. Grimesmand is run, so subsequent pwd commands run very fast.  The main
3004b88c807SRodney W. Grimescomplication in the cd command is in the docd command, which
3014b88c807SRodney W. Grimesresolves symbolic links into actual names and informs the user
3024b88c807SRodney W. Grimeswhere the user ended up if he crossed a symbolic link.
3034b88c807SRodney W. Grimes
3044b88c807SRodney W. GrimesSIGNALS:  Trap.c implements the trap command.  The routine set-
3054b88c807SRodney W. Grimessignal figures out what action should be taken when a signal is
3064b88c807SRodney W. Grimesreceived and invokes the signal system call to set the signal ac-
3074b88c807SRodney W. Grimestion appropriately.  When a signal that a user has set a trap for
3084b88c807SRodney W. Grimesis caught, the routine "onsig" sets a flag.  The routine dotrap
3094b88c807SRodney W. Grimesis called at appropriate points to actually handle the signal.
3104b88c807SRodney W. GrimesWhen an interrupt is caught and no trap has been set for that
3114b88c807SRodney W. Grimessignal, the routine "onint" in error.c is called.
3124b88c807SRodney W. Grimes
3134b88c807SRodney W. GrimesOUTPUT:  Ash uses it's own output routines.  There are three out-
3144b88c807SRodney W. Grimesput structures allocated.  "Output" represents the standard out-
3154b88c807SRodney W. Grimesput, "errout" the standard error, and "memout" contains output
3164b88c807SRodney W. Grimeswhich is to be stored in memory.  This last is used when a buil-
3174b88c807SRodney W. Grimestin command appears in backquotes, to allow its output to be col-
3184b88c807SRodney W. Grimeslected without doing any I/O through the UNIX operating system.
3194b88c807SRodney W. GrimesThe variables out1 and out2 normally point to output and errout,
3204b88c807SRodney W. Grimesrespectively, but they are set to point to memout when appropri-
3214b88c807SRodney W. Grimesate inside backquotes.
3224b88c807SRodney W. Grimes
3234b88c807SRodney W. GrimesINPUT:  The basic input routine is pgetc, which reads from the
3244b88c807SRodney W. Grimescurrent input file.  There is a stack of input files; the current
3254b88c807SRodney W. Grimesinput file is the top file on this stack.  The code allows the
3264b88c807SRodney W. Grimesinput to come from a string rather than a file.  (This is for the
3274b88c807SRodney W. Grimes-c option and the "." and eval builtin commands.)  The global
3284b88c807SRodney W. Grimesvariable plinno is saved and restored when files are pushed and
3294b88c807SRodney W. Grimespopped from the stack.  The parser routines store the number of
3304b88c807SRodney W. Grimesthe current line in this variable.
3314b88c807SRodney W. Grimes
3324b88c807SRodney W. GrimesDEBUGGING:  If DEBUG is defined in shell.h, then the shell will
3334b88c807SRodney W. Grimeswrite debugging information to the file $HOME/trace.  Most of
3344b88c807SRodney W. Grimesthis is done using the TRACE macro, which takes a set of printf
3354b88c807SRodney W. Grimesarguments inside two sets of parenthesis.  Example:
3364b88c807SRodney W. Grimes"TRACE(("n=%d0, n))".  The double parenthesis are necessary be-
3374b88c807SRodney W. Grimescause the preprocessor can't handle functions with a variable
3384b88c807SRodney W. Grimesnumber of arguments.  Defining DEBUG also causes the shell to
3394b88c807SRodney W. Grimesgenerate a core dump if it is sent a quit signal.  The tracing
3404b88c807SRodney W. Grimescode is in show.c.
341