home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Technical Notes
-
- SKsh
-
- A ksh-like Shell for the Amiga
-
- Version 1.7
-
-
- (Copyright) 1988-1991
-
- Steve Koren
-
- May 4, 1991
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Implementation Notes
-
- SKsh is the result of over 5 month's of evening and weekend
- work on an Amiga 2000 with a Xetec hard disk controller, an
- 85mb Seagate drive, a Hurricane 2800 accelerator board, and
- 5mb of ram. The parser, lexical analyzer, and program archi-
- tecture were completed very quickly; most of the time was
- spent trying to figure out how to do Amiga specific things
- (like directories) and working around compiler bugs.
-
- SKsh has a parser that was generated using Amiga yacc and
- modified by hand to deal with some special features of SKsh
- (such as command substitution). The lexical analyzer was
- written by hand, since I needed some capabilities not present
- in Lex. SKsh is composed of 88 .c files ranging from 100 to
- 1400 lines, 24 function prototype files, 25 .h files, and one
- .y (yacc) file. The source code is currently around 21000
- lines, not including test scripts.
-
- Internally, SKsh uses hash tables to keep track of variables,
- aliases, functions, and keywords. A stack of hash tables is
- maintained, and each time a function is called, a new hash
- table is pushed onto the stack. Then, when a name is refer-
- enced, it is looked up in the hash table stack starting with
- the most recent hash table. When a function exits, the most
- recent hash table is popped off the stack and its contents are
- freed. Hash table entries have an associated type (variable,
- function, etc), and a value, which can be either a text string
- (such as an alias definition) or a pointer to a parse tree
- (for a function).
-
- SKsh was written to be reentrant, so that in the future
- interprocess pipes may be used between internal and external
- commands. Thus, all evaluation is done using only information
- passed around in an "EVAL_PACKET" structure so that no globals
- are referenced. Each execution of the command interpreter
- generates its own hash table stack, its own pointer to input
- and output files, etc. The few parts of SKsh which are not
- reentrant are written using a semaphore-based locking
- mechanism. This locking mechanism is intelligent; it does not
- lock out all other tasks from the system (as Forbit() and Per-
- mit() do), but simply allows only a single task to execute a
- given section of program code at one time.
-
- All output is done through a single low level routine which,
- given an EVAL_PACKET and some text, will route it to either a
- file or a string (in the case of command substition). The
- length of the space allocated for this string is kept in the
- EVAL_PACKET, and if the new text would cause the string to
- overflow its allocated space, more space is allocated and the
- original is copied into the new space. Thus, command substi-
- tion and variables can deal with text of any length limited
- only by free memory.
-
-
-
- SKsh Amiga Shell Page 2 Technical Notes
-
-
-
-
-
-
-
-
-
- There are no hard-coded branches to routines which execute
- SKsh builtin commands. A single structure contains all neces-
- sary information for builtin commands, including their name, a
- pointer to their execution routine, and a few other things.
- This architecture makes it trivial to add new builtin
- commands. Keywords are dealt with in the same way.
-
- A series of test scripts is run whenever SKsh is changed.
- These scripts test all the SKsh commands and syntax. The out-
- put of these tests are compared against known good results to
- verify that no previously working commands were broken
- inadvertantly. The entire series of 45 test scripts takes
- about 15 minutes to run on a stock 7.x mHz Amiga 2000. There
- are currently about 6000 lines of test scripts.
-
- Since the entire SKsh project was implemented on an Amiga, and
- SKsh was designed for Amigas, it currently runs only there.
- It was, however, designed with machine independence in mind.
- The machine specific code is enclosed in #ifdef AMIGA state-
- ments, and could conceivably be replaced with code specific to
- another machine.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- SKsh Amiga Shell Page 3 Technical Notes
-
-
-
-