home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk381.lzh / SKsh / TechNotes.doc < prev    next >
Text File  |  1990-10-20  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.                                    Technical Notes
  17.  
  18.                                         SKsh
  19.  
  20.                            A ksh-like Shell for the Amiga
  21.  
  22.                                      Version 1.6
  23.  
  24.  
  25.                                (Copyright) 1989, 1990
  26.  
  27.                                      Steve Koren
  28.  
  29.                                    October 4, 1990
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.           Implementation Notes
  74.  
  75.             SKsh  is  the  result of over 5 month's of evening and  weekend
  76.             work on an Amiga  2000  with  a  Xetec hard disk controller, an
  77.             85mb Seagate drive, a CMI 14 mHz  68000  accelerator board, and
  78.             3mb of ram.  The  parser,  lexical analyzer, and program archi-
  79.             tecture  were  completed very quickly; most  of  the  time  was
  80.             spent  trying  to  figure out how to do  Amiga  specific things
  81.             (like directories) and working around compiler bugs.
  82.  
  83.             SKsh  has  a  parser  that  was  generated using Amiga yacc and
  84.             modified by hand to  deal  with  some  special features of SKsh
  85.             (such  as  command  substitution).   The   lexical analyzer was
  86.             written by hand, since I needed  some  capabilities not present
  87.             in Lex.   SKsh  is  composed of 86 .c files ranging from 100 to
  88.             1400 lines,  24  function prototype files, 23 .h files, and one
  89.             .y (yacc) file.   The  source  code  is  currently around 21000
  90.             lines, not including test scripts.
  91.  
  92.             Internally, SKsh uses hash tables to keep track  of  variables,
  93.             aliases,  functions, and keywords.  A stack of hash  tables  is
  94.             maintained,  and  each  time  a  function is called, a new hash
  95.             table is pushed onto the stack.  Then, when a  name  is  refer-
  96.             enced, it is looked up in the hash  table  stack  starting with
  97.             the  most  recent hash table.  When a  function exits, the most
  98.             recent hash table is popped off the stack and its  contents are
  99.             freed.  Hash  table  entries have an associated type (variable,
  100.             function, etc), and a value, which can be  either a text string
  101.             (such  as  an  alias  definition) or a pointer to a parse  tree
  102.             (for a function).
  103.  
  104.             SKsh  was  written  to  be  reentrant, so that  in  the  future
  105.             interprocess pipes may  be  used  between internal and external
  106.             commands.  Thus, all  evaluation is done using only information
  107.             passed around in an "EVAL_PACKET"  structure so that no globals
  108.             are  referenced.   Each   execution of the  command interpreter
  109.             generates its own hash table stack, its own  pointer  to  input
  110.             and  output files, etc.  The few parts of SKsh  which  are  not
  111.             reentrant   are   written   using  a  semaphore-based   locking
  112.             mechanism.  This  locking mechanism is intelligent; it does not
  113.             lock out all other tasks from the  system (as Forbit() and Per-
  114.             mit()  do),  but  simply allows only a single task to execute a
  115.             given section of program code at one time.
  116.  
  117.             All  output is done through a single low  level  routine which,
  118.             given an EVAL_PACKET and some text, will route it  to  either a
  119.             file or a string  (in  the  case  of  command substition).  The
  120.             length of  the  space  allocated for this string is kept in the
  121.             EVAL_PACKET, and if the new text  would  cause  the  string  to
  122.             overflow  its  allocated space, more space is allocated and the
  123.             original  is  copied into the new space.  Thus, command substi-
  124.             tion  and  variables can deal with text of any  length  limited
  125.             only by free memory.
  126.  
  127.  
  128.  
  129.           SKsh Amiga Shell             Page 2              Technical Notes
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.             There are  no  hard-coded  branches  to  routines which execute
  140.             SKsh  builtin commands.  A single structure contains all neces-
  141.             sary  information for builtin commands, including their name, a
  142.             pointer  to  their  execution  routine, and a few other things.
  143.             This   architecture  makes  it  trivial  to  add  new   builtin
  144.             commands.  Keywords are dealt with in the same way.
  145.  
  146.             A  series of  test  scripts  is  run  whenever SKsh is changed.
  147.             These scripts test all the SKsh  commands and syntax.  The out-
  148.             put of these tests  are  compared against known good results to
  149.             verify  that   no   previously  working  commands  were  broken
  150.             inadvertantly.   The   entire  series of 39 test scripts  takes
  151.             about  12  minutes to run on a stock 7.x mHz Amiga 2000.  There
  152.             are currently about 5000 lines of test scripts.
  153.  
  154.             Since the  entire SKsh project was implemented on an Amiga, and
  155.             SKsh  was  designed  for  Amigas, it currently runs only there.
  156.             It  was,  however,  designed with machine independence in mind.
  157.             The  machine  specific code is  enclosed in #ifdef AMIGA state-
  158.             ments, and could  conceivably be replaced with code specific to
  159.             another machine.
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.           SKsh Amiga Shell             Page 3              Technical Notes
  196.  
  197.  
  198.  
  199.