From 88ce2c2d5734269b65120fc42a10d07068a5b3a1 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sun, 21 Aug 2011 12:41:55 -0700 Subject: [PATCH] sh: Various updates to the TOUR document. Obtained-From: FreeBSD 222362 --- bin/sh/TOUR | 39 +++++++++------------------------------ 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/bin/sh/TOUR b/bin/sh/TOUR index a6114f1350..b97491f2cd 100644 --- a/bin/sh/TOUR +++ b/bin/sh/TOUR @@ -1,5 +1,5 @@ # @(#)TOUR 8.1 (Berkeley) 5/31/93 -# $FreeBSD: src/bin/sh/TOUR,v 1.8 2011/02/04 22:47:55 jilles Exp $ +# $FreeBSD: src/bin/sh/TOUR,v 1.9 2011/05/27 16:00:37 jilles Exp $ NOTE -- This is the original TOUR paper distributed with ash and does not represent the current state of the shell. It is provided anyway @@ -27,10 +27,8 @@ programs is: mkbuiltins builtins builtins.h builtins.c mkinit *.c init.c mknodes nodetypes nodes.h nodes.c - mksignames - signames.h signames.c mksyntax - syntax.h syntax.c mktokens - token.h - bltin/mkexpr unary_op binary_op operators.h operators.c There are undoubtedly too many of these. Mkinit searches all the C source files for entries looking like: @@ -64,14 +62,6 @@ tion: Preprocessor #define statements are copied to init.c without any special action to request this. -INDENTATION: The ash source is indented in multiples of six -spaces. The only study that I have heard of on the subject con- -cluded that the optimal amount to indent is in the range of four -to six spaces. I use six spaces since it is not too big a jump -from the widely used eight spaces. If you really hate six space -indentation, use the adjind (source included) program to change -it to something else. - EXCEPTIONS: Code for dealing with exceptions appears in exceptions.c. The C language doesn't include exception handling, so I implement it using setjmp and longjmp. The global variable @@ -115,7 +105,7 @@ repeatedly parses and executes commands. OPTIONS.C: This file contains the option processing code. It is called from main to parse the shell arguments when the shell is -invoked, and it also contains the set builtin. The -i and -j op- +invoked, and it also contains the set builtin. The -i and -m op- tions (the latter turns on job control) require changes in signal handling. The routines setjobctl (in jobs.c) and setinteractive (in trap.c) are called to handle changes to these options. @@ -123,10 +113,11 @@ handling. The routines setjobctl (in jobs.c) and setinteractive PARSING: The parser code is all in parser.c. A recursive des- cent parser is used. Syntax tables (generated by mksyntax) are used to classify characters during lexical analysis. There are -three tables: one for normal use, one for use when inside single -quotes, and one for use when inside double quotes. The tables -are machine dependent because they are indexed by character vari- -ables and the range of a char varies from machine to machine. +four tables: one for normal use, one for use when inside single +quotes and dollar single quotes, one for use when inside double +quotes and one for use in arithmetic. The tables are machine +dependent because they are indexed by character variables and +the range of a char varies from machine to machine. PARSE OUTPUT: The output of the parser consists of a tree of nodes. The various types of nodes are defined in the file node- @@ -242,12 +233,7 @@ The routine shellexec is the interface to the exec system call. EXPAND.C: Arguments are processed in three passes. The first (performed by the routine argstr) performs variable and command substitution. The second (ifsbreakup) performs word splitting -and the third (expandmeta) performs file name generation. If the -"/u" directory is simulated, then when "/u/username" is replaced -by the user's home directory, the flag "didudir" is set. This -tells the cd command that it should print out the directory name, -just as it would if the "/u" directory were implemented using -symbolic links. +and the third (expandmeta) performs file name generation. VAR.C: Variables are stored in a hash table. Probably we should switch to extensible hashing. The variable name is stored in the @@ -292,14 +278,7 @@ 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. +CD.C: This file defines the cd and pwd builtins. SIGNALS: Trap.c implements the trap command. The routine set- signal figures out what action should be taken when a signal is -- 2.41.0