Deleted Added
full compact
TOUR (157789) TOUR (218306)
1# @(#)TOUR 8.1 (Berkeley) 5/31/93
1# @(#)TOUR 8.1 (Berkeley) 5/31/93
2# $FreeBSD: head/bin/sh/TOUR 157789 2006-04-16 11:54:01Z schweikh $
2# $FreeBSD: head/bin/sh/TOUR 218306 2011-02-04 22:47:55Z jilles $
3
4NOTE -- This is the original TOUR paper distributed with ash and
5does not represent the current state of the shell. It is provided anyway
6since it provides helpful information for how the shell is structured,
7but be warned that things have changed -- the current shell is
8still under development.
9
10================================================================

--- 28 unchanged lines hidden (view full) ---

39 x = 1; /* executed during initialization */
40 }
41
42 RESET {
43 x = 2; /* executed when the shell does a longjmp
44 back to the main command loop */
45 }
46
3
4NOTE -- This is the original TOUR paper distributed with ash and
5does not represent the current state of the shell. It is provided anyway
6since it provides helpful information for how the shell is structured,
7but be warned that things have changed -- the current shell is
8still under development.
9
10================================================================

--- 28 unchanged lines hidden (view full) ---

39 x = 1; /* executed during initialization */
40 }
41
42 RESET {
43 x = 2; /* executed when the shell does a longjmp
44 back to the main command loop */
45 }
46
47 SHELLPROC {
48 x = 3; /* executed when the shell runs a shell procedure */
49 }
50
51It pulls this code out into routines which are when particular
52events occur. The intent is to improve modularity by isolating
53the information about which modules need to be explicitly
54initialized/reset within the modules themselves.
55
56Mkinit recognizes several constructs for placing declarations in
57the init.c file.
58 INCLUDE "file.h"

--- 16 unchanged lines hidden (view full) ---

75from the widely used eight spaces. If you really hate six space
76indentation, use the adjind (source included) program to change
77it to something else.
78
79EXCEPTIONS: Code for dealing with exceptions appears in
80exceptions.c. The C language doesn't include exception handling,
81so I implement it using setjmp and longjmp. The global variable
82exception contains the type of exception. EXERROR is raised by
47It pulls this code out into routines which are when particular
48events occur. The intent is to improve modularity by isolating
49the information about which modules need to be explicitly
50initialized/reset within the modules themselves.
51
52Mkinit recognizes several constructs for placing declarations in
53the init.c file.
54 INCLUDE "file.h"

--- 16 unchanged lines hidden (view full) ---

71from the widely used eight spaces. If you really hate six space
72indentation, use the adjind (source included) program to change
73it to something else.
74
75EXCEPTIONS: Code for dealing with exceptions appears in
76exceptions.c. The C language doesn't include exception handling,
77so I implement it using setjmp and longjmp. The global variable
78exception contains the type of exception. EXERROR is raised by
83calling error. EXINT is an interrupt. EXSHELLPROC is an excep-
84tion which is raised when a shell procedure is invoked. The pur-
85pose of EXSHELLPROC is to perform the cleanup actions associated
86with other exceptions. After these cleanup actions, the shell
87can interpret a shell procedure itself without exec'ing a new
88copy of the shell.
79calling error. EXINT is an interrupt.
89
90INTERRUPTS: In an interactive shell, an interrupt will cause an
91EXINT exception to return to the main command loop. (Exception:
92EXINT is not raised if the user traps interrupts using the trap
93command.) The INTOFF and INTON macros (defined in exception.h)
94provide uninterruptible critical sections. Between the execution
95of INTOFF and the execution of INTON, interrupt signals will be
96held for later delivery. INTOFF and INTON can be nested.

--- 168 unchanged lines hidden (view full) ---

265mand. Variables which the shell references internally are preal-
266located so that the shell can reference the values of these vari-
267ables without doing a lookup.
268
269When a program is run, the code in eval.c sticks any environment
270variables which precede the command (as in "PATH=xxx command") in
271the variable table as the simplest way to strip duplicates, and
272then calls "environment" to get the value of the environment.
80
81INTERRUPTS: In an interactive shell, an interrupt will cause an
82EXINT exception to return to the main command loop. (Exception:
83EXINT is not raised if the user traps interrupts using the trap
84command.) The INTOFF and INTON macros (defined in exception.h)
85provide uninterruptible critical sections. Between the execution
86of INTOFF and the execution of INTON, interrupt signals will be
87held for later delivery. INTOFF and INTON can be nested.

--- 168 unchanged lines hidden (view full) ---

256mand. Variables which the shell references internally are preal-
257located so that the shell can reference the values of these vari-
258ables without doing a lookup.
259
260When a program is run, the code in eval.c sticks any environment
261variables which precede the command (as in "PATH=xxx command") in
262the variable table as the simplest way to strip duplicates, and
263then calls "environment" to get the value of the environment.
273There are two consequences of this. First, if an assignment to
274PATH precedes the command, the value of PATH before the assign-
275ment must be remembered and passed to shellexec. Second, if the
276program turns out to be a shell procedure, the strings from the
277environment variables which preceded the command must be pulled
278out of the table and replaced with strings obtained from malloc,
279since the former will automatically be freed when the stack (see
280the entry on memalloc.c) is emptied.
281
282BUILTIN COMMANDS: The procedures for handling these are scat-
283tered throughout the code, depending on which location appears
284most appropriate. They can be recognized because their names al-
285ways end in "cmd". The mapping from names to procedures is
286specified in the file builtins, which is processed by the mkbuilt-
287ins command.
288

--- 69 unchanged lines hidden ---
264
265BUILTIN COMMANDS: The procedures for handling these are scat-
266tered throughout the code, depending on which location appears
267most appropriate. They can be recognized because their names al-
268ways end in "cmd". The mapping from names to procedures is
269specified in the file builtins, which is processed by the mkbuilt-
270ins command.
271

--- 69 unchanged lines hidden ---