home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff291.lzh / SKsh / docs / TechNotes.doc < prev    next >
Text File  |  1989-12-12  |  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.2
  23.  
  24.  
  25.                                   (Copyright) 1989 
  26.  
  27.                                      Steve Koren
  28.  
  29.                                   November 19, 1989
  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 3 month's  of  evening  and  weekend
  76.             work on an Amiga 2000 with a Xetec hard disk  controller,  85mb
  77.             Seagate drive, and 3mb of ram.  The parser,  lexical  analyzer,
  78.             and program architecture were completed very quickly;  most  of
  79.             the time was spent  trying  to  figure  out  how  to  do  Amiga
  80.             specific things (like directories) and working around  compiler
  81.             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 49 .c files ranging  from  100  to
  88.             1100 lines, 21 .h files, and one .y file.
  89.  
  90.             Internally, SKsh uses hash tables to keep track  of  variables,
  91.             aliases, functions, and keywords.  A stack of  hash  tables  is
  92.             maintained, and each time a function  is  called,  a  new  hash
  93.             table  is  pushed  onto  the  stack.   Then,  when  a  name  is
  94.             referenced, it is looked up in the hash  table  stack  starting
  95.             with the most recent hash table.  When a  function  exits,  the
  96.             most recent  hash  table  is  popped  off  the  stack  and  its
  97.             contents are freed.  Hash  table  entries  have  an  associated
  98.             type (variable, function, etc),  and  a  value,  which  can  be
  99.             either a text  string  (such  as  an  alias  definition)  or  a
  100.             pointer to a parse tree (for a function).
  101.  
  102.             SKsh was written  to  be  reentrant,  so  that  in  the  future
  103.             interprocess pipes may be used between  internal  and  external
  104.             commands.  Thus, all evaluation is done using only  information
  105.             passed around in an "EVAL_PACKET" structure so that no  globals
  106.             are referenced.  Each  execution  of  the  command  interpreter
  107.             generates its own hash table stack, its own  pointer  to  input
  108.             and output files, etc.  The few parts of  SKsh  which  are  not
  109.             reentrant  are  written   using   a   semaphore-based   locking
  110.             mechanism.  This locking mechanism is intelligent; it does  not
  111.             lock out all other tasks  from  the  system  (as  Forbit()  and
  112.             Permit() do), but simply allows only a single task  to  execute
  113.             a given section of program code at one time.
  114.  
  115.             All output is done through a single low  level  routine  which,
  116.             given an EVAL_PACKET and some text, will route it to  either  a
  117.             file or a string (in the  case  of  command  substition).   The
  118.             length of the space allocated for this string is  kept  in  the
  119.             EVAL_PACKET, and if the new text  would  cause  the  string  to
  120.             overflow its allocated space, more space is allocated  and  the
  121.             original  is  copied  into  the  new  space.    Thus,   command
  122.             substition and variables can  deal  with  text  of  any  length
  123.             limited only by free memory.
  124.  
  125.             There are no hard-coded  branches  to  routines  which  execute
  126.             SKsh  builtin  commands.   A  single  structure  contains   all
  127.  
  128.  
  129.           SKSH Amiga Shell             Page 2              Technical Notes
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.             necessary information for  builtin  commands,  including  their
  140.             name, a pointer to their execution routine,  and  a  few  other
  141.             things.  This architecture makes it trivial to add new  builtin
  142.             commands.  Keywords are dealt with in the same way.
  143.  
  144.             A series of test scripts  is  run  whenever  SKsh  is  changed.
  145.             These scripts test all  the  SKsh  commands  and  syntax.   The
  146.             output of these tests are compared against known  good  results
  147.             to verify that  no  previously  working  commands  were  broken
  148.             inadvertantly.  The entire series  of  21  test  scripts  takes
  149.             about 10 minutes to run on a stock 7.x mHz Amiga 2000.
  150.  
  151.             Since the entire SKsh project was implemented on an Amiga,  and
  152.             SKsh was designed for Amigas, it  currently  runs  only  there.
  153.             It was, however, designed with machine  independence  in  mind.
  154.             The  machine  specific  code  is  enclosed  in   #ifdef   AMIGA
  155.             statements,  and  could  conceivably  be  replaced  with   code
  156.             specific to another machine.
  157.  
  158.  
  159.  
  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.