8000 minix/bin/sh/TOUR at master · sestissi16/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
357 lines (305 loc) · 16.8 KB

TOUR

File metadata and controls

357 lines (305 loc) · 16.8 KB
argv to it. Builtin routines can also call error. This routine
normally terminates the shell (or returns to the main command
loop if the shell is interactive), but when called from a builtin
command it causes the builtin command to terminate with an exit
status of 2.
The directory bltins contains commands which can be compiled in-
dependently but can also be built into the shell for efficiency
reasons. The makefile in this directory compiles these programs
in the normal fashion (so that they can be run regardless of
whether the invoker is ash), but also creates a library named
bltinlib.a which can be linked with ash. The header file bltin.h
takes care of most of the differences between the ash and the
stand-alone environment. The user should call the main routine
"main", and #define main to be the name of the routine to use
when the program is linked into ash. This #define should appear
before bltin.h is included; bltin.h will #undef main if the pro-
gram is to be compiled stand-alone.
CD.C: This file defines the cd and pwd builtins. The pwd com-
mand runs /bin/pwd the first time it is invoked (unless the user
has already done a cd to an absolute pathname), but then
remembers the current directory and updates it when the cd com-
mand is run, so subsequent pwd commands run very fast. The main
complication in the cd command is in the docd command, which
resolves symbolic links into actual names and informs the user
where the user ended up if he crossed a symbolic link.
SIGNALS: Trap.c implements the trap command. The routine set-
signal figures out what action should be taken when a signal is
received and invokes the signal system call to set the signal ac-
tion appropriately. When a signal that a user has set a trap for
is caught, the routine "onsig" sets a flag. The routine dotrap
is called at appropriate points to actually handle the signal.
When an interrupt is caught and no trap has been set for that
signal, the routine "onint" in error.c is called.
OUTPUT: Ash uses its own output routines. There are three out-
put structures allocated. "Output" represents the standard out-
put, "errout" the standard error, and "memout" contains output
which is to be stored in memory. This last is used when a buil-
tin command appears in backquotes, to allow its output to be col-
lected without doing any I/O through the UNIX operating system.
The variables out1 and out2 normally point to output and errout,
respectively, but they are set to point to memout when appropri-
ate inside backquotes.
INPUT: The basic input routine is pgetc, which reads from the
current input file. There is a stack of input files; the current
input file is the top file on this stack. The code allows the
input to come from a string rather than a file. (This is for the
-c option and the "." and eval builtin commands.) The global
variable plinno is saved and restored when files are pushed and
popped from the stack. The parser routines store the number of
the current line in this variable.
DEBUGGING: If DEBUG is defined in shell.h, then the shell will
write debugging information to the file $HOME/trace. Most of
this is done using the TRACE macro, which takes a set of printf
arguments inside two sets of parenthesis. Example:
"TRACE(("n=%d0, n))". The double parenthesis are necessary be-
cause the preprocessor can't handle functions with a variable
number of arguments. Defining DEBUG also causes the shell to
generate a core dump if it is sent a quit signal. The tracing
code is in show.c.
0