1*d90bee97SLionel Sambuc# $NetBSD: TOUR,v 1.10 2008/11/15 17:01:38 snj Exp $ 2*d90bee97SLionel Sambuc# @(#)TOUR 8.1 (Berkeley) 5/31/93 3*d90bee97SLionel Sambuc 4*d90bee97SLionel SambucNOTE -- This is the original TOUR paper distributed with ash and 5*d90bee97SLionel Sambucdoes not represent the current state of the shell. It is provided anyway 6*d90bee97SLionel Sambucsince it provides helpful information for how the shell is structured, 7*d90bee97SLionel Sambucbut be warned that things have changed -- the current shell is 8*d90bee97SLionel Sambucstill under development. 9*d90bee97SLionel Sambuc 10*d90bee97SLionel Sambuc================================================================ 11*d90bee97SLionel Sambuc 12*d90bee97SLionel Sambuc A Tour through Ash 13*d90bee97SLionel Sambuc 14*d90bee97SLionel Sambuc Copyright 1989 by Kenneth Almquist. 15*d90bee97SLionel Sambuc 16*d90bee97SLionel Sambuc 17*d90bee97SLionel SambucDIRECTORIES: The subdirectory bltin contains commands which can 18*d90bee97SLionel Sambucbe compiled stand-alone. The rest of the source is in the main 19*d90bee97SLionel Sambucash directory. 20*d90bee97SLionel Sambuc 21*d90bee97SLionel SambucSOURCE CODE GENERATORS: Files whose names begin with "mk" are 22*d90bee97SLionel Sambucprograms that generate source code. A complete list of these 23*d90bee97SLionel Sambucprograms is: 24*d90bee97SLionel Sambuc 25*d90bee97SLionel Sambuc program input files generates 26*d90bee97SLionel Sambuc ------- ------------ --------- 27*d90bee97SLionel Sambuc mkbuiltins builtins builtins.h builtins.c 28*d90bee97SLionel Sambuc mkinit *.c init.c 29*d90bee97SLionel Sambuc mknodes nodetypes nodes.h nodes.c 30*d90bee97SLionel Sambuc mksignames - signames.h signames.c 31*d90bee97SLionel Sambuc mksyntax - syntax.h syntax.c 32*d90bee97SLionel Sambuc mktokens - token.h 33*d90bee97SLionel Sambuc bltin/mkexpr unary_op binary_op operators.h operators.c 34*d90bee97SLionel Sambuc 35*d90bee97SLionel SambucThere are undoubtedly too many of these. Mkinit searches all the 36*d90bee97SLionel SambucC source files for entries looking like: 37*d90bee97SLionel Sambuc 38*d90bee97SLionel Sambuc INIT { 39*d90bee97SLionel Sambuc x = 1; /* executed during initialization */ 40*d90bee97SLionel Sambuc } 41*d90bee97SLionel Sambuc 42*d90bee97SLionel Sambuc RESET { 43*d90bee97SLionel Sambuc x = 2; /* executed when the shell does a longjmp 44*d90bee97SLionel Sambuc back to the main command loop */ 45*d90bee97SLionel Sambuc } 46*d90bee97SLionel Sambuc 47*d90bee97SLionel Sambuc SHELLPROC { 48*d90bee97SLionel Sambuc x = 3; /* executed when the shell runs a shell procedure */ 49*d90bee97SLionel Sambuc } 50*d90bee97SLionel Sambuc 51*d90bee97SLionel SambucIt pulls this code out into routines which are when particular 52*d90bee97SLionel Sambucevents occur. The intent is to improve modularity by isolating 53*d90bee97SLionel Sambucthe information about which modules need to be explicitly 54*d90bee97SLionel Sambucinitialized/reset within the modules themselves. 55*d90bee97SLionel Sambuc 56*d90bee97SLionel SambucMkinit recognizes several constructs for placing declarations in 57*d90bee97SLionel Sambucthe init.c file. 58*d90bee97SLionel Sambuc INCLUDE "file.h" 59*d90bee97SLionel Sambucincludes a file. The storage class MKINIT makes a declaration 60*d90bee97SLionel Sambucavailable in the init.c file, for example: 61*d90bee97SLionel Sambuc MKINIT int funcnest; /* depth of function calls */ 62*d90bee97SLionel SambucMKINIT alone on a line introduces a structure or union declara- 63*d90bee97SLionel Sambuction: 64*d90bee97SLionel Sambuc MKINIT 65*d90bee97SLionel Sambuc struct redirtab { 66*d90bee97SLionel Sambuc short renamed[10]; 67*d90bee97SLionel Sambuc }; 68*d90bee97SLionel SambucPreprocessor #define statements are copied to init.c without any 69*d90bee97SLionel Sambucspecial action to request this. 70*d90bee97SLionel Sambuc 71*d90bee97SLionel SambucINDENTATION: The ash source is indented in multiples of six 72*d90bee97SLionel Sambucspaces. The only study that I have heard of on the subject con- 73*d90bee97SLionel Sambuccluded that the optimal amount to indent is in the range of four 74*d90bee97SLionel Sambucto six spaces. I use six spaces since it is not too big a jump 75*d90bee97SLionel Sambucfrom the widely used eight spaces. If you really hate six space 76*d90bee97SLionel Sambucindentation, use the adjind (source included) program to change 77*d90bee97SLionel Sambucit to something else. 78*d90bee97SLionel Sambuc 79*d90bee97SLionel SambucEXCEPTIONS: Code for dealing with exceptions appears in 80*d90bee97SLionel Sambucexceptions.c. The C language doesn't include exception handling, 81*d90bee97SLionel Sambucso I implement it using setjmp and longjmp. The global variable 82*d90bee97SLionel Sambucexception contains the type of exception. EXERROR is raised by 83*d90bee97SLionel Sambuccalling error. EXINT is an interrupt. EXSHELLPROC is an excep- 84*d90bee97SLionel Sambuction which is raised when a shell procedure is invoked. The pur- 85*d90bee97SLionel Sambucpose of EXSHELLPROC is to perform the cleanup actions associated 86*d90bee97SLionel Sambucwith other exceptions. After these cleanup actions, the shell 87*d90bee97SLionel Sambuccan interpret a shell procedure itself without exec'ing a new 88*d90bee97SLionel Sambuccopy of the shell. 89*d90bee97SLionel Sambuc 90*d90bee97SLionel SambucINTERRUPTS: In an interactive shell, an interrupt will cause an 91*d90bee97SLionel SambucEXINT exception to return to the main command loop. (Exception: 92*d90bee97SLionel SambucEXINT is not raised if the user traps interrupts using the trap 93*d90bee97SLionel Sambuccommand.) The INTOFF and INTON macros (defined in exception.h) 94*d90bee97SLionel Sambucprovide uninterruptible critical sections. Between the execution 95*d90bee97SLionel Sambucof INTOFF and the execution of INTON, interrupt signals will be 96*d90bee97SLionel Sambucheld for later delivery. INTOFF and INTON can be nested. 97*d90bee97SLionel Sambuc 98*d90bee97SLionel SambucMEMALLOC.C: Memalloc.c defines versions of malloc and realloc 99*d90bee97SLionel Sambucwhich call error when there is no memory left. It also defines a 100*d90bee97SLionel Sambucstack oriented memory allocation scheme. Allocating off a stack 101*d90bee97SLionel Sambucis probably more efficient than allocation using malloc, but the 102*d90bee97SLionel Sambucbig advantage is that when an exception occurs all we have to do 103*d90bee97SLionel Sambucto free up the memory in use at the time of the exception is to 104*d90bee97SLionel Sambucrestore the stack pointer. The stack is implemented using a 105*d90bee97SLionel Sambuclinked list of blocks. 106*d90bee97SLionel Sambuc 107*d90bee97SLionel SambucSTPUTC: If the stack were contiguous, it would be easy to store 108*d90bee97SLionel Sambucstrings on the stack without knowing in advance how long the 109*d90bee97SLionel Sambucstring was going to be: 110*d90bee97SLionel Sambuc p = stackptr; 111*d90bee97SLionel Sambuc *p++ = c; /* repeated as many times as needed */ 112*d90bee97SLionel Sambuc stackptr = p; 113*d90bee97SLionel SambucThe following three macros (defined in memalloc.h) perform these 114*d90bee97SLionel Sambucoperations, but grow the stack if you run off the end: 115*d90bee97SLionel Sambuc STARTSTACKSTR(p); 116*d90bee97SLionel Sambuc STPUTC(c, p); /* repeated as many times as needed */ 117*d90bee97SLionel Sambuc grabstackstr(p); 118*d90bee97SLionel Sambuc 119*d90bee97SLionel SambucWe now start a top-down look at the code: 120*d90bee97SLionel Sambuc 121*d90bee97SLionel SambucMAIN.C: The main routine performs some initialization, executes 122*d90bee97SLionel Sambucthe user's profile if necessary, and calls cmdloop. Cmdloop is 123*d90bee97SLionel Sambucrepeatedly parses and executes commands. 124*d90bee97SLionel Sambuc 125*d90bee97SLionel SambucOPTIONS.C: This file contains the option processing code. It is 126*d90bee97SLionel Sambuccalled from main to parse the shell arguments when the shell is 127*d90bee97SLionel Sambucinvoked, and it also contains the set builtin. The -i and -j op- 128*d90bee97SLionel Sambuctions (the latter turns on job control) require changes in signal 129*d90bee97SLionel Sambuchandling. The routines setjobctl (in jobs.c) and setinteractive 130*d90bee97SLionel Sambuc(in trap.c) are called to handle changes to these options. 131*d90bee97SLionel Sambuc 132*d90bee97SLionel SambucPARSING: The parser code is all in parser.c. A recursive des- 133*d90bee97SLionel Sambuccent parser is used. Syntax tables (generated by mksyntax) are 134*d90bee97SLionel Sambucused to classify characters during lexical analysis. There are 135*d90bee97SLionel Sambucthree tables: one for normal use, one for use when inside single 136*d90bee97SLionel Sambucquotes, and one for use when inside double quotes. The tables 137*d90bee97SLionel Sambucare machine dependent because they are indexed by character vari- 138*d90bee97SLionel Sambucables and the range of a char varies from machine to machine. 139*d90bee97SLionel Sambuc 140*d90bee97SLionel SambucPARSE OUTPUT: The output of the parser consists of a tree of 141*d90bee97SLionel Sambucnodes. The various types of nodes are defined in the file node- 142*d90bee97SLionel Sambuctypes. 143*d90bee97SLionel Sambuc 144*d90bee97SLionel SambucNodes of type NARG are used to represent both words and the con- 145*d90bee97SLionel Sambuctents of here documents. An early version of ash kept the con- 146*d90bee97SLionel Sambuctents of here documents in temporary files, but keeping here do- 147*d90bee97SLionel Sambuccuments in memory typically results in significantly better per- 148*d90bee97SLionel Sambucformance. It would have been nice to make it an option to use 149*d90bee97SLionel Sambuctemporary files for here documents, for the benefit of small 150*d90bee97SLionel Sambucmachines, but the code to keep track of when to delete the tem- 151*d90bee97SLionel Sambucporary files was complex and I never fixed all the bugs in it. 152*d90bee97SLionel Sambuc(AT&T has been maintaining the Bourne shell for more than ten 153*d90bee97SLionel Sambucyears, and to the best of my knowledge they still haven't gotten 154*d90bee97SLionel Sambucit to handle temporary files correctly in obscure cases.) 155*d90bee97SLionel Sambuc 156*d90bee97SLionel SambucThe text field of a NARG structure points to the text of the 157*d90bee97SLionel Sambucword. The text consists of ordinary characters and a number of 158*d90bee97SLionel Sambucspecial codes defined in parser.h. The special codes are: 159*d90bee97SLionel Sambuc 160*d90bee97SLionel Sambuc CTLVAR Variable substitution 161*d90bee97SLionel Sambuc CTLENDVAR End of variable substitution 162*d90bee97SLionel Sambuc CTLBACKQ Command substitution 163*d90bee97SLionel Sambuc CTLBACKQ|CTLQUOTE Command substitution inside double quotes 164*d90bee97SLionel Sambuc CTLESC Escape next character 165*d90bee97SLionel Sambuc 166*d90bee97SLionel SambucA variable substitution contains the following elements: 167*d90bee97SLionel Sambuc 168*d90bee97SLionel Sambuc CTLVAR type name '=' [ alternative-text CTLENDVAR ] 169*d90bee97SLionel Sambuc 170*d90bee97SLionel SambucThe type field is a single character specifying the type of sub- 171*d90bee97SLionel Sambucstitution. The possible types are: 172*d90bee97SLionel Sambuc 173*d90bee97SLionel Sambuc VSNORMAL $var 174*d90bee97SLionel Sambuc VSMINUS ${var-text} 175*d90bee97SLionel Sambuc VSMINUS|VSNUL ${var:-text} 176*d90bee97SLionel Sambuc VSPLUS ${var+text} 177*d90bee97SLionel Sambuc VSPLUS|VSNUL ${var:+text} 178*d90bee97SLionel Sambuc VSQUESTION ${var?text} 179*d90bee97SLionel Sambuc VSQUESTION|VSNUL ${var:?text} 180*d90bee97SLionel Sambuc VSASSIGN ${var=text} 181*d90bee97SLionel Sambuc VSASSIGN|VSNUL ${var=text} 182*d90bee97SLionel Sambuc 183*d90bee97SLionel SambucIn addition, the type field will have the VSQUOTE flag set if the 184*d90bee97SLionel Sambucvariable is enclosed in double quotes. The name of the variable 185*d90bee97SLionel Sambuccomes next, terminated by an equals sign. If the type is not 186*d90bee97SLionel SambucVSNORMAL, then the text field in the substitution follows, ter- 187*d90bee97SLionel Sambucminated by a CTLENDVAR byte. 188*d90bee97SLionel Sambuc 189*d90bee97SLionel SambucCommands in back quotes are parsed and stored in a linked list. 190*d90bee97SLionel SambucThe locations of these commands in the string are indicated by 191*d90bee97SLionel SambucCTLBACKQ and CTLBACKQ+CTLQUOTE characters, depending upon whether 192*d90bee97SLionel Sambucthe back quotes were enclosed in double quotes. 193*d90bee97SLionel Sambuc 194*d90bee97SLionel SambucThe character CTLESC escapes the next character, so that in case 195*d90bee97SLionel Sambucany of the CTL characters mentioned above appear in the input, 196*d90bee97SLionel Sambucthey can be passed through transparently. CTLESC is also used to 197*d90bee97SLionel Sambucescape '*', '?', '[', and '!' characters which were quoted by the 198*d90bee97SLionel Sambucuser and thus should not be used for file name generation. 199*d90bee97SLionel Sambuc 200*d90bee97SLionel SambucCTLESC characters have proved to be particularly tricky to get 201*d90bee97SLionel Sambucright. In the case of here documents which are not subject to 202*d90bee97SLionel Sambucvariable and command substitution, the parser doesn't insert any 203*d90bee97SLionel SambucCTLESC characters to begin with (so the contents of the text 204*d90bee97SLionel Sambucfield can be written without any processing). Other here docu- 205*d90bee97SLionel Sambucments, and words which are not subject to splitting and file name 206*d90bee97SLionel Sambucgeneration, have the CTLESC characters removed during the vari- 207*d90bee97SLionel Sambucable and command substitution phase. Words which are subject 208*d90bee97SLionel Sambucsplitting and file name generation have the CTLESC characters re- 209*d90bee97SLionel Sambucmoved as part of the file name phase. 210*d90bee97SLionel Sambuc 211*d90bee97SLionel SambucEXECUTION: Command execution is handled by the following files: 212*d90bee97SLionel Sambuc eval.c The top level routines. 213*d90bee97SLionel Sambuc redir.c Code to handle redirection of input and output. 214*d90bee97SLionel Sambuc jobs.c Code to handle forking, waiting, and job control. 215*d90bee97SLionel Sambuc exec.c Code to to path searches and the actual exec sys call. 216*d90bee97SLionel Sambuc expand.c Code to evaluate arguments. 217*d90bee97SLionel Sambuc var.c Maintains the variable symbol table. Called from expand.c. 218*d90bee97SLionel Sambuc 219*d90bee97SLionel SambucEVAL.C: Evaltree recursively executes a parse tree. The exit 220*d90bee97SLionel Sambucstatus is returned in the global variable exitstatus. The alter- 221*d90bee97SLionel Sambucnative entry evalbackcmd is called to evaluate commands in back 222*d90bee97SLionel Sambucquotes. It saves the result in memory if the command is a buil- 223*d90bee97SLionel Sambuctin; otherwise it forks off a child to execute the command and 224*d90bee97SLionel Sambucconnects the standard output of the child to a pipe. 225*d90bee97SLionel Sambuc 226*d90bee97SLionel SambucJOBS.C: To create a process, you call makejob to return a job 227*d90bee97SLionel Sambucstructure, and then call forkshell (passing the job structure as 228*d90bee97SLionel Sambucan argument) to create the process. Waitforjob waits for a job 229*d90bee97SLionel Sambucto complete. These routines take care of process groups if job 230*d90bee97SLionel Sambuccontrol is defined. 231*d90bee97SLionel Sambuc 232*d90bee97SLionel SambucREDIR.C: Ash allows file descriptors to be redirected and then 233*d90bee97SLionel Sambucrestored without forking off a child process. This is accom- 234*d90bee97SLionel Sambucplished by duplicating the original file descriptors. The redir- 235*d90bee97SLionel Sambuctab structure records where the file descriptors have been dupli- 236*d90bee97SLionel Sambuccated to. 237*d90bee97SLionel Sambuc 238*d90bee97SLionel SambucEXEC.C: The routine find_command locates a command, and enters 239*d90bee97SLionel Sambucthe command in the hash table if it is not already there. The 240*d90bee97SLionel Sambucthird argument specifies whether it is to print an error message 241*d90bee97SLionel Sambucif the command is not found. (When a pipeline is set up, 242*d90bee97SLionel Sambucfind_command is called for all the commands in the pipeline be- 243*d90bee97SLionel Sambucfore any forking is done, so to get the commands into the hash 244*d90bee97SLionel Sambuctable of the parent process. But to make command hashing as 245*d90bee97SLionel Sambuctransparent as possible, we silently ignore errors at that point 246*d90bee97SLionel Sambucand only print error messages if the command cannot be found 247*d90bee97SLionel Sambuclater.) 248*d90bee97SLionel Sambuc 249*d90bee97SLionel SambucThe routine shellexec is the interface to the exec system call. 250*d90bee97SLionel Sambuc 251*d90bee97SLionel SambucEXPAND.C: Arguments are processed in three passes. The first 252*d90bee97SLionel Sambuc(performed by the routine argstr) performs variable and command 253*d90bee97SLionel Sambucsubstitution. The second (ifsbreakup) performs word splitting 254*d90bee97SLionel Sambucand the third (expandmeta) performs file name generation. If the 255*d90bee97SLionel Sambuc"/u" directory is simulated, then when "/u/username" is replaced 256*d90bee97SLionel Sambucby the user's home directory, the flag "didudir" is set. This 257*d90bee97SLionel Sambuctells the cd command that it should print out the directory name, 258*d90bee97SLionel Sambucjust as it would if the "/u" directory were implemented using 259*d90bee97SLionel Sambucsymbolic links. 260*d90bee97SLionel Sambuc 261*d90bee97SLionel SambucVAR.C: Variables are stored in a hash table. Probably we should 262*d90bee97SLionel Sambucswitch to extensible hashing. The variable name is stored in the 263*d90bee97SLionel Sambucsame string as the value (using the format "name=value") so that 264*d90bee97SLionel Sambucno string copying is needed to create the environment of a com- 265*d90bee97SLionel Sambucmand. Variables which the shell references internally are preal- 266*d90bee97SLionel Sambuclocated so that the shell can reference the values of these vari- 267*d90bee97SLionel Sambucables without doing a lookup. 268*d90bee97SLionel Sambuc 269*d90bee97SLionel SambucWhen a program is run, the code in eval.c sticks any environment 270*d90bee97SLionel Sambucvariables which precede the command (as in "PATH=xxx command") in 271*d90bee97SLionel Sambucthe variable table as the simplest way to strip duplicates, and 272*d90bee97SLionel Sambucthen calls "environment" to get the value of the environment. 273*d90bee97SLionel SambucThere are two consequences of this. First, if an assignment to 274*d90bee97SLionel SambucPATH precedes the command, the value of PATH before the assign- 275*d90bee97SLionel Sambucment must be remembered and passed to shellexec. Second, if the 276*d90bee97SLionel Sambucprogram turns out to be a shell procedure, the strings from the 277*d90bee97SLionel Sambucenvironment variables which preceded the command must be pulled 278*d90bee97SLionel Sambucout of the table and replaced with strings obtained from malloc, 279*d90bee97SLionel Sambucsince the former will automatically be freed when the stack (see 280*d90bee97SLionel Sambucthe entry on memalloc.c) is emptied. 281*d90bee97SLionel Sambuc 282*d90bee97SLionel SambucBUILTIN COMMANDS: The procedures for handling these are scat- 283*d90bee97SLionel Sambuctered throughout the code, depending on which location appears 284*d90bee97SLionel Sambucmost appropriate. They can be recognized because their names al- 285*d90bee97SLionel Sambucways end in "cmd". The mapping from names to procedures is 286*d90bee97SLionel Sambucspecified in the file builtins, which is processed by the mkbuil- 287*d90bee97SLionel Sambuctins command. 288*d90bee97SLionel Sambuc 289*d90bee97SLionel SambucA builtin command is invoked with argc and argv set up like a 290*d90bee97SLionel Sambucnormal program. A builtin command is allowed to overwrite its 291*d90bee97SLionel Sambucarguments. Builtin routines can call nextopt to do option pars- 292*d90bee97SLionel Sambucing. This is kind of like getopt, but you don't pass argc and 293*d90bee97SLionel Sambucargv to it. Builtin routines can also call error. This routine 294*d90bee97SLionel Sambucnormally terminates the shell (or returns to the main command 295*d90bee97SLionel Sambucloop if the shell is interactive), but when called from a builtin 296*d90bee97SLionel Sambuccommand it causes the builtin command to terminate with an exit 297*d90bee97SLionel Sambucstatus of 2. 298*d90bee97SLionel Sambuc 299*d90bee97SLionel SambucThe directory bltins contains commands which can be compiled in- 300*d90bee97SLionel Sambucdependently but can also be built into the shell for efficiency 301*d90bee97SLionel Sambucreasons. The makefile in this directory compiles these programs 302*d90bee97SLionel Sambucin the normal fashion (so that they can be run regardless of 303*d90bee97SLionel Sambucwhether the invoker is ash), but also creates a library named 304*d90bee97SLionel Sambucbltinlib.a which can be linked with ash. The header file bltin.h 305*d90bee97SLionel Sambuctakes care of most of the differences between the ash and the 306*d90bee97SLionel Sambucstand-alone environment. The user should call the main routine 307*d90bee97SLionel Sambuc"main", and #define main to be the name of the routine to use 308*d90bee97SLionel Sambucwhen the program is linked into ash. This #define should appear 309*d90bee97SLionel Sambucbefore bltin.h is included; bltin.h will #undef main if the pro- 310*d90bee97SLionel Sambucgram is to be compiled stand-alone. 311*d90bee97SLionel Sambuc 312*d90bee97SLionel SambucCD.C: This file defines the cd and pwd builtins. The pwd com- 313*d90bee97SLionel Sambucmand runs /bin/pwd the first time it is invoked (unless the user 314*d90bee97SLionel Sambuchas already done a cd to an absolute pathname), but then 315*d90bee97SLionel Sambucremembers the current directory and updates it when the cd com- 316*d90bee97SLionel Sambucmand is run, so subsequent pwd commands run very fast. The main 317*d90bee97SLionel Sambuccomplication in the cd command is in the docd command, which 318*d90bee97SLionel Sambucresolves symbolic links into actual names and informs the user 319*d90bee97SLionel Sambucwhere the user ended up if he crossed a symbolic link. 320*d90bee97SLionel Sambuc 321*d90bee97SLionel SambucSIGNALS: Trap.c implements the trap command. The routine set- 322*d90bee97SLionel Sambucsignal figures out what action should be taken when a signal is 323*d90bee97SLionel Sambucreceived and invokes the signal system call to set the signal ac- 324*d90bee97SLionel Sambuction appropriately. When a signal that a user has set a trap for 325*d90bee97SLionel Sambucis caught, the routine "onsig" sets a flag. The routine dotrap 326*d90bee97SLionel Sambucis called at appropriate points to actually handle the signal. 327*d90bee97SLionel SambucWhen an interrupt is caught and no trap has been set for that 328*d90bee97SLionel Sambucsignal, the routine "onint" in error.c is called. 329*d90bee97SLionel Sambuc 330*d90bee97SLionel SambucOUTPUT: Ash uses its own output routines. There are three out- 331*d90bee97SLionel Sambucput structures allocated. "Output" represents the standard out- 332*d90bee97SLionel Sambucput, "errout" the standard error, and "memout" contains output 333*d90bee97SLionel Sambucwhich is to be stored in memory. This last is used when a buil- 334*d90bee97SLionel Sambuctin command appears in backquotes, to allow its output to be col- 335*d90bee97SLionel Sambuclected without doing any I/O through the UNIX operating system. 336*d90bee97SLionel SambucThe variables out1 and out2 normally point to output and errout, 337*d90bee97SLionel Sambucrespectively, but they are set to point to memout when appropri- 338*d90bee97SLionel Sambucate inside backquotes. 339*d90bee97SLionel Sambuc 340*d90bee97SLionel SambucINPUT: The basic input routine is pgetc, which reads from the 341*d90bee97SLionel Sambuccurrent input file. There is a stack of input files; the current 342*d90bee97SLionel Sambucinput file is the top file on this stack. The code allows the 343*d90bee97SLionel Sambucinput to come from a string rather than a file. (This is for the 344*d90bee97SLionel Sambuc-c option and the "." and eval builtin commands.) The global 345*d90bee97SLionel Sambucvariable plinno is saved and restored when files are pushed and 346*d90bee97SLionel Sambucpopped from the stack. The parser routines store the number of 347*d90bee97SLionel Sambucthe current line in this variable. 348*d90bee97SLionel Sambuc 349*d90bee97SLionel SambucDEBUGGING: If DEBUG is defined in shell.h, then the shell will 350*d90bee97SLionel Sambucwrite debugging information to the file $HOME/trace. Most of 351*d90bee97SLionel Sambucthis is done using the TRACE macro, which takes a set of printf 352*d90bee97SLionel Sambucarguments inside two sets of parenthesis. Example: 353*d90bee97SLionel Sambuc"TRACE(("n=%d0, n))". The double parenthesis are necessary be- 354*d90bee97SLionel Sambuccause the preprocessor can't handle functions with a variable 355*d90bee97SLionel Sambucnumber of arguments. Defining DEBUG also causes the shell to 356*d90bee97SLionel Sambucgenerate a core dump if it is sent a quit signal. The tracing 357*d90bee97SLionel Sambuccode is in show.c. 358