home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Technical Notes
-
- SKSH
-
- A ksh-like Shell for the Amiga
-
- Version 1.2
-
-
- (Copyright) 1989
-
- Steve Koren
-
- November 19, 1989
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Implementation Notes
-
- SKsh is the result of over 3 month's of evening and weekend
- work on an Amiga 2000 with a Xetec hard disk controller, 85mb
- Seagate drive, and 3mb of ram. The parser, lexical analyzer,
- and program architecture 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 49 .c files ranging from 100 to
- 1100 lines, 21 .h files, and one .y file.
-
- 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
- referenced, 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
- Permit() 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
- substition and variables can deal with text of any length
- limited only by free memory.
-
- There are no hard-coded branches to routines which execute
- SKsh builtin commands. A single structure contains all
-
-
- SKSH Amiga Shell Page 2 Technical Notes
-
-
-
-
-
-
-
-
-
- necessary 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
- output of these tests are compared against known good results
- to verify that no previously working commands were broken
- inadvertantly. The entire series of 21 test scripts takes
- about 10 minutes to run on a stock 7.x mHz Amiga 2000.
-
- 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
- statements, and could conceivably be replaced with code
- specific to another machine.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- SKSH Amiga Shell Page 3 Technical Notes
-
-
-
-