home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / AZTEC-C / COMND004.ARK / COMND.DOC < prev    next >
Text File  |  1986-06-17  |  35KB  |  808 lines

  1.  
  2.  
  3.  
  4.  
  5.                                    C O M N D
  6.  
  7.                     A TOPS-20 style command parsing library
  8.                             for personal computers
  9.  
  10.  
  11.  
  12.  
  13.              Documentation  and  source  code Copyright (C) 1985 by Mark
  14.         E. Mallett;  permission is granted to distribute  this  document
  15.         and the  code  indiscriminately.  Please leave credits in place,
  16.         and add your own as appropriate.
  17.  
  18.  
  19.                                  A Disclaimer
  20.  
  21.  
  22.  
  23.              The code which implements this library takes up about  12Kb
  24.         of  space  on my CP/M system using Manx's AZTEC CII Z80 compiler
  25.         (10Kb with the date/time support stubbed out).   I  don't  claim
  26.         that  the  coding  is  very  efficient  nor  do I make any other
  27.         claims about the code  in  general.    I  do  believe  that  the
  28.         definition  of  the  call  interface  is reasonable, and for me,
  29.         this has made it quite usable.
  30.  
  31.  
  32.  
  33.  
  34.                                  This Document
  35.  
  36.  
  37.  
  38.              This document contains the following sections:
  39.  
  40.  
  41.          o Document overview (this here section)
  42.  
  43.          o Introduction and history
  44.  
  45.          o Functional overview
  46.  
  47.          o How to write programs using the subroutine library
  48.  
  49.          o How to make the library work on your system
  50.  
  51.  
  52.  
  53.  
  54.                            Introduction and History
  55.  
  56.  
  57.  
  58.              This document describes the COMND subroutine package for  C
  59.         programmers.    COMND   is   a   subroutine  library  to  effect
  60.         consistent parsing of user input, and in general is well  suited
  61.         for verb-argument   style   command  interfaces.    The  library
  62.         provides a consistent  user  interface  as  well  as  a  program
  63.         interface  which,  I believe, could well remain unchanged if the
  64.         parsing library were re-written to support  different  interface
  65.         requirements (such as menu interaction).
  66.  
  67.              The   COMND  interface  is  based  on  the  TOPS-20  model.
  68.         TOPS-20 is an operating system  which  is/was  used  by  Digital
  69.         Equipment Corporation  on  their  PDP-20  computer.  TOPS-20 was
  70.         based on TENEX, written by BBN (I  think,  I  think).    TOPS-20
  71.         COMND  is much more robust and consistent than the library which
  72.         this document describes;  this library being intended for  small
  73.         computer  applications,  it  provides  the  most  commonly  used
  74.         functions.
  75.  
  76.              This library was written on a Z-80 system  running  Digital
  77.         Research   Corporation's   CP/M  operating  system  version  3.0
  78.         (CPM+).  I have also compiled and  tried  it  on  a  VAX  11/780
  79.         running VMS.    It  is completely written in the C language, and
  80.         contains only a few operating system specific elements.
  81.  
  82.              The COMND JSYS section of the TOPS-20 Monitor Calls  manual
  83.         is probably a good thing to read.
  84.  
  85.              Please note:   while there are a few unimplemented sections
  86.         of this library, I felt that it was nevertheless  worthwhile  to
  87.         submit  it  to  public  domain since it is usable for almost all
  88.         general command parsing and since the  call  interface  is  well
  89.         defined.   I  have  used this library extensively since sometime
  90.         in 1984.
  91.  
  92.  
  93.  
  94.  
  95.                               Functional Overview
  96.  
  97.  
  98.  
  99.  
  100.              The COMND subroutine library  provides  a  command-oriented
  101.         user  interface  which is consistent at the programmer level and
  102.         at the  user  level.    At  the  program  level,  it  gives   an
  103.         algorithmically  controlled  parsing  flow,  where a call to the
  104.         library exists  for  each  field  or  choice  of  fields  to  be
  105.         parsed.
  106.  
  107.              At the user level, the interface provides:
  108.  
  109.  
  110.          o Command prompting.
  111.  
  112.          o Consistent  command  line  editing.  The user may use editing
  113.            keys to erase the last character or word,  and  to  echo  the
  114.            current input line and prompt.
  115.  
  116.          o Input  abbreviation  and  defaulting.    The  user  may  type
  117.            abbreviations of  keywords,  or  may  type  nothing  to  have
  118.            defaults applied.
  119.  
  120.          o Incremental  help.    By  pressing  a  known  key  (usually a
  121.            question mark), the user  can  find  out  what  choices  s/he
  122.            has.
  123.  
  124.          o Guide  strings.    Parenthesized guide words are shown at the
  125.            users option.
  126.  
  127.          o Command completion.  Where the subroutine library  can  judge
  128.            what  the  succesful  completion  of  a portion of user input
  129.            will be, the user can elect to have this input completed  and
  130.            shown automatically.
  131.  
  132.  
  133.  
  134.  
  135.                             Using the COMND Library
  136.  
  137.  
  138.  
  139.              While  you  read  this part of the document, you might want
  140.         to look at the  sample  program  named  TEST.C  which  has  been
  141.         included with  this  package.   It is an over-commented guide to
  142.         the use of the COMND library.
  143.  
  144.              Any module which makes use of this  library  shall  include
  145.         the definition   file  named  "comnd.h".    This  file  contains
  146.         definitions  which   are   necessary   to   the   caller-library
  147.         interface.   Mnemonics  (structures  and constants) mentioned in
  148.         relation to this interface are defined in this file.
  149.  
  150.              The philosophy of parsing with the COMND library is that  a
  151.         command  line  is  typed,  the  program  inspects  it,  then the
  152.         program acts on  the  directions  given  in  that  line.    This
  153.         process is  repeated  until  the  program  finishes.   The COMND
  154.         library assists the user in typing  the  command  line  and  the
  155.         program in  inspecting  it.    Acting  on  it  is left up to the
  156.         calling program.
  157.  
  158.              The typing and parsing of fields in  the  command  line  go
  159.         essentially hand-in-hand   with   this   library.    The  single
  160.         subroutine COMND() is used to effect all parsing.  This  routine
  161.         is  called  for  each  field  of  the  input  line to be parsed.
  162.         Parsing is done according to a current  parse  state,  which  is
  163.         maintained  in  a  parameter  block  passed  between  caller and
  164.         library.   The  state  block  contains  the  following  sort  of
  165.         information (described in detail later):
  166.  
  167.  
  168.          o What to use for a prompt string.
  169.  
  170.          o  Addresses  of  scratch  buffers  for  user  input  and  atom
  171.            storage.
  172.  
  173.          o How much the user has entered.
  174.  
  175.          o How much of the line the program has parsed.
  176.  
  177.  
  178.  
  179.  
  180.              An important thing to note is that the  indexes  (how  much
  181.         entered and  parsed)  are  both  variable.    The program begins
  182.         parsing of the input line upon a break signal by the user  (such
  183.         as the  typing  of  a carriage return, question mark, etc).  The
  184.         user may then resume typing  and  erase  characters  back  to  a
  185.         point BEFORE  that  already  parsed.   It is very important that
  186.         the program does not take any action on  what  has  been  parsed
  187.         until  the  line  has  been completely processed, otherwise that
  188.         action could be undesired.
  189.  
  190.              Since the user may back up the command  input  to  a  point
  191.         before  that  already  processed  by  the application program, a
  192.         mechanism must be provided to backup the program to the  correct
  193.         point.   Rather  than going to the point backed up to, the COMND
  194.         library  expects  the  application  program  to  return  to  the
  195.         beginning of  the  line,  and start again.  The user's input has
  196.         remained in the command line buffer, and the library  will  take
  197.         care  of  buffering  the rest of the input when that parse point
  198.         is again reached.  However, this means  that  there  must  be  a
  199.         method  of  communicating  to  the  calling  program  that  this
  200.         "reparse" is  necessary.    Actually  there  are   two   methods
  201.         provided, as follows:
  202.  
  203.  
  204.          o  Each  call  to  the command parsing routine COMND() yields a
  205.            result code.  The result may indicate that a reparse  has  to
  206.            take place.    The  program  shall  then back up to the point
  207.            where the parse of the line began, and start again.
  208.  
  209.          o The application program may specify the address of  a  setjmp
  210.            buffer which  identifies  the reparse point.  (Note setjmp is
  211.            a facility provided as part of  most  standard  C  libraries.
  212.            It  allows  you  to  mark a point in the procedure flow [call
  213.            frame,  registers,  and  whatever  else  is  involved  in   a
  214.            context],  and  return to that point from another part of the
  215.            program as if control  had  never  proceeded.    If  you  are
  216.            unfamiliar  with  this  facility,  you  might  want to find a
  217.            description in your C manual.) It is  up  to  the  caller  to
  218.            setup the setjmp environment at the reparse point.
  219.  
  220.  
  221.              In  either  case, the reparse point (the point at which the
  222.         parse will be restarted if necessary) is the point at which  the
  223.         first element  of the command line is parsed.  This is after the
  224.         initialization call which starts every parse.
  225.  
  226.  
  227.  
  228.  
  229.              Every  call  to  the  COMND()   subroutine   involves   two
  230.         arguments:   a  command  state  block, in which is kept track of
  231.         the parse state, and a command function block,  which  describes
  232.         what sort  of  thing  to parse next.  The command state block is
  233.         given a structure called "CSBs", and  a  typedef  called  "CSB".
  234.         Each  element  of  the structure is named with a form "CSB_xxx",
  235.         where "xxx" is representative of the  element's  purpose.    The
  236.         following  are  the  elements of the command state block, in the
  237.         order that they appear in the structure.
  238.  
  239.  
  240.          o CSB_PFL is a BYTE.  This contains flags which are set by  the
  241.            caller  to  indicate  specifics  of  the  command processing.
  242.            These flags are:
  243.  
  244.  
  245.             o _CFNEC:  Do not echo user input.
  246.  
  247.             o _CFRAI:  Convert lowercase input to uppercase.
  248.  
  249.  
  250.          o CSB_RFL, a BYTE value, contains flags which are kept  by  the
  251.            library in  the  performance  of the parse.  Generally, these
  252.            flags  are  of  no  interest  to  the  caller   since   their
  253.            information  can  be  gleaned  from  the  result  code of the
  254.            COMND() call.  However, they are:
  255.  
  256.  
  257.             o _CFNOP:  No  parse.    Nothing  matched,  i.e.,  an  error
  258.               occured.
  259.  
  260.             o _CFESC:  Field terminated by escape.
  261.  
  262.             o _CFEOC:  Field terminated by CR.
  263.  
  264.             o _CFRPT:  Reparse required.
  265.  
  266.             o _CRSWT:  Switch ended with colon.
  267.  
  268.             o _CFPFE:  Previous field terminated with escape.
  269.  
  270.  
  271.          o  CSB_RSB  is  the  address  of a setjmp buffer describing the
  272.            environment at  the  reparse  point.    If  this   value   is
  273.            non-NULL,   then  if  a  reparse  is  required,  a  longjmp()
  274.            operation is performed using this setjmp buffer.
  275.  
  276.          o CSB_INP is the address  of  the  input-character  routine  to
  277.            use.   If this value is non-NULL, then this routine is called
  278.            to get each character of input.  No line editing  or  special
  279.            interactive  characters are recognized in this mode, since it
  280.            is assumed that this will be  used  for  file  input.    Note
  281.  
  282.  
  283.  
  284.  
  285.            especially:   this  facility  is not yet implemented, however
  286.            the definition is provided for future expansion.  Thou  shalt
  287.            always leave this NULL, or write the facility thyself.
  288.  
  289.          o  CSB_OUT is the inverse correspondent to the previous element
  290.            (CSB_INP).  It is the address of a routine to process  output
  291.            from the  command  library.    Please  see the warning in the
  292.            CSB_INP description about not being implemented.
  293.  
  294.          o CSB_PMT is the address  of  the  prompt  string  to  use  for
  295.            command parsing.      The   command  library  takes  care  of
  296.            prompting, so make sure this is filled in.
  297.  
  298.          o CSB_BUF is the address of the buffer to put user  input  into
  299.            as s/he is typing it in.
  300.  
  301.          o  CSB_BSZ,  an int, is the number of bytes which can be stored
  302.            in CSB_BUF;  i.e., it is the buffer size.
  303.  
  304.          o CSB_ABF is the address of an atom buffer.  Some (if not  all)
  305.            parsing   functions   involve   extracting   some  number  of
  306.            characters from the input buffer and interpreting  or  simply
  307.            returning this  extracted  string.   This buffer is necessary
  308.            for those operations.  It should probably be as large as  the
  309.            input buffer (CSB_BUF), but it is really up to you.
  310.  
  311.          o  CSB_ASZ,  an  int,  is the number of characters which can be
  312.            stored in CSB_ABF;  i.e., it is the size of that buffer.
  313.  
  314.            ** Note ** CSB elements from here to the end do not  have  to
  315.            be initialized  by  the  calling  program.   They are used to
  316.            store state information and are initialized  as  required  by
  317.            the library.
  318.  
  319.          o CSB_PRS,  an  int,  contains  the  parse  index.  This is the
  320.            point in the command buffer up  to  which  parsing  has  been
  321.            achieved.
  322.  
  323.          o  CSB_FLN,  an  int,  is  the  filled  length  of  the command
  324.            buffer.  This is the number of  characters  which  have  been
  325.            typed by the user.
  326.  
  327.          o CSB_RCD,  an int, is a result code of the parse.  This is the
  328.            same value which is returned as the  result  of  the  COMND()
  329.            procedure call.
  330.  
  331.          o  CSB_RVL is a union which is used to contain either an int or
  332.            an address value.  The  names  of  the  union  elements  are:
  333.            _INT  for  int, _ADR for address (note that a typecast should
  334.            be used  for  proper  address  assignment).    This   element
  335.            contains  a  value  returned  from some parse functions which
  336.            return values which are single values.  For  example,  if  an
  337.  
  338.  
  339.  
  340.  
  341.            integer is parsed, its value is returned here.
  342.  
  343.          o  CSB_CFB is the address of a command function block for which
  344.            a parse was successful.  This is significant in  cases  where
  345.            there  are  alternative  possible interpretations of the next
  346.            command line field.
  347.  
  348.  
  349.  
  350.  
  351.         The parse of each element in a command line  involves,  as  well
  352.         as  the  Command  State Block just described, a Command Function
  353.         Block which identifies the sort of thing to  be  parsed.    This
  354.         block  is  defined  in  a  structure  named  "CFBs", which has a
  355.         corresponding typedef named "CFB".  Elements of the  CFB,  named
  356.         "CFB_xxx",  are  as  follows  (in  the  order they appear in the
  357.         structure):
  358.  
  359.  
  360.  
  361.          o CFB_FNC, a BYTE, is the function  code.    This  defines  the
  362.            function to  be  performed.    The function codes are listed,
  363.            and their actions described, a little later.
  364.  
  365.          o CFB_FLG, a BYTE, contains flags which  the  caller  specifies
  366.            to the  library.    These  are  very significant, and in most
  367.            cases affect the presentation to the user.    The  flag  bits
  368.            are:
  369.  
  370.  
  371.             o _CFHPP:    A  help  string has been supplied and should be
  372.               given when the user types the help character ("?").
  373.  
  374.             o _CFDPP:  A default string has been supplied, and shall  be
  375.               used  if  the  user  does  not type anything at this point
  376.               (typing  nothing  means  typing  a  return  or  requesting
  377.               command completion).     Note  that  this  flag  (and  the
  378.               default string) is ONLY significant for the CFB passed  in
  379.               the  call  to  the COMND() routine, and not for any others
  380.               referenced as alternatives by  that  CFB.    Note  further
  381.               that  a  default  specified by the first CFB is applied to
  382.               the input stream, and not to the parsing function.    That
  383.               means  that  the  default  is subject to interpretation by
  384.               alternate CFBs, and in fact, does  not  even  have  to  be
  385.               appropriate for the CFB which contains it.
  386.  
  387.             o _CFSDH:    The default help message should be supressed if
  388.               the user  types  the  help  character  ("?").    This   is
  389.               normally   used  in  conjunction  with  the  _CFHPP  flag.
  390.               However, if this flag is present and  the  _CFHPP  is  not
  391.               selected,  then  the  help operation is inhibited, and the
  392.               help character becomes insignificant (just like any  other
  393.  
  394.  
  395.  
  396.  
  397.               character).
  398.  
  399.             o _CFCC:      A  character  characteristic  table  has  been
  400.               provided.  A CC table identifies which characters  may  be
  401.               part of  the  element being recognized.  Not all functions
  402.               support this table (for example, it does  not  make  sense
  403.               to   re-specify   which  characters  may  compose  decimal
  404.               numbers).  This table also specifies which characters  are
  405.               break  characters,  causing  the  parser  to "wake up" the
  406.               calling program when one of them is typed.   If  this  bit
  407.               is  not  set  (as is usually the case), a default table is
  408.               associated according to the function code.
  409.  
  410.             o _CFDTD:  For parsing date and  time,  specifies  that  the
  411.               date should be parsed.
  412.  
  413.             o _CFDTT:    For  parsing  date and time, specifies that the
  414.               time should be parsed.
  415.  
  416.  
  417.          o CFB_CFB is the address of another CFB which  may  be  invoked
  418.            if the  user  input  does  not satisfy this CFB.  CFBs may be
  419.            chained in this manner at will.    Recognize,  however,  that
  420.            the  ORDER  of the chain plays an important part in how input
  421.            is handled, particularly in disambiguation of  input.    Note
  422.            also  that  only  the  first  CFB  of  the  chain is used for
  423.            specifying  a  default  string  and  CC  table  for   command
  424.            wake-up.
  425.  
  426.            CFB  chaining  is  a very important part of parsing with this
  427.            library.
  428.  
  429.          o CFB_DAT is defined as a long, since it  is  used  to  contain
  430.            address or   int   values.    It  should  be  referenced  via
  431.            typecast.  It is  not  defined  as  a  union  because  it  is
  432.            inconvenient  or  impossible  to initialize unions at compile
  433.            time with most (all?)  C  compilers,  and  initialization  of
  434.            these blocks  at  compile  time  is  very  desirable.    This
  435.            element contains data used in  parsing  of  a  field  in  the
  436.            command line.    For  instance,  in  parsing  an integer, the
  437.            caller specifies the default radix of the integer here.
  438.  
  439.          o CFB_HLP is the address  of  a  caller-supplied  help  string.
  440.            This  is  only  significant  if the flag bit _CFHPP is set in
  441.            the CFB_FLG byte.
  442.  
  443.          o CFB_DEF is the address of a caller-supplied  default  string.
  444.            This  is  only  significant  if the flag bit _CFDPP is set in
  445.            the CFB_FLG byte, and only for  the  first  CFB  in  the  CFB
  446.            chain.
  447.  
  448.          o  CFB_CC  is the address of a character characteristics table.
  449.  
  450.  
  451.  
  452.  
  453.            This is only significant if the flag bit _CFCC is set in  the
  454.            CFB_FLG byte.    This is the address of a 16-word table, each
  455.            word containing 16 bits which  are  interpreted  as  8  2-bit
  456.            characteristic entries.       The   most   significant   bits
  457.            correspond to the lower ASCII values, etc.  The 2-bit  binary
  458.            value has the following meaning, per character:
  459.  
  460.  
  461.             o 00:    Character  may  not  be  part  of the element being
  462.               parsed.
  463.  
  464.             o 01:  Character may be part of the element only  if  it  is
  465.               not the first character of that element.
  466.  
  467.             o 10:  Character may be part of the element.
  468.  
  469.             o 11:      Character   may  not  be  part  of  the  element;
  470.               furthermore, when it is typed, it  will  case  parsing  to
  471.               begin immediately (a  wake-up  character).  Note:  wake-up
  472.               via this mechanism is not implemented.
  473.  
  474.  
  475.  
  476.                 Don't hesitate to use CC tables;  they only take  up  16
  477.            bytes apiece.
  478.  
  479.  
  480.  
  481.  
  482.              The  function  code  in  the  CFB_FC element of the command
  483.         function block  specifies  the  operation  to  be  performed  on
  484.         behalf of that function block.  Functions are described now.
  485.  
  486.  
  487.  
  488.         CFB function _CMINI:  Initialize
  489.  
  490.              Every   parse   of  a  command  line  must  begin  with  an
  491.         initialization call.  This tells the command  library  to  reset
  492.         its indexes,  that the user must be prompted, etc.  There may be
  493.         NO other CFBs chained to this one, because  if  they  are,  they
  494.         are ignored.
  495.  
  496.  
  497.  
  498.  
  499.              The reparse  point  is the point right after this call.  If
  500.         the setjmp method is used, then the  setjmp  environment  should
  501.         be defined  here.    After  the reparse point, any variables etc
  502.         which may be the  victims  of  parsing  side-effects  should  be
  503.         initialized.
  504.  
  505.  
  506.  
  507.         CFB function _CMKEY:  Keyword parse
  508.  
  509.              _CMKEY parses  a  keyword  from  a given list.  The CFB_DAT
  510.         element of the function block should point to a table of  string
  511.         pointers, ending  with  a  NULL  pointer.  The user may type any
  512.         unique abbreviation of a keyword,  and  may  use  completion  to
  513.         fill out  the rest of a known match.  The address of the pointer
  514.         to the matching string is returned in  the  CSB_RVL  element  of
  515.         the command  state  block.    The  value is returned this way so
  516.         that the index can be  easily  calculated,  and  because  it  is
  517.         consistent   with   the   general   keyword   parsing  mechanism
  518.         (_CMGSK).
  519.  
  520.              The incremental help associated  with  keyword  parsing  is
  521.         somewhat special.    The  default  help  string is "Keyword, one
  522.         of:" followed  by  a  list  of  keywords  which  match  anything
  523.         already typed.    If  a help string has been supplied (indicated
  524.         by _CFHPP) and no suppression of the default help is  specified,
  525.         then  the  initial  part  ("Keyword,  ")  is  replaced  with the
  526.         supplied help string and the help is otherwise the same.   If  a
  527.         help   string  has  been  supplied  and  the  default  has  been
  528.         supressed, then the given help string is presented unaltered.
  529.  
  530.  
  531.  
  532.         CFB function _CMNUM:  number
  533.  
  534.              This parses a number.  The caller supplies a radix  in  the
  535.         CFB_DAT element  of  the  function  block.  The number parsed is
  536.         returned (as an  int)  in  the  CSB_RVL  element  of  the  state
  537.         block.
  538.  
  539.  
  540.  
  541.  
  542.         CFB function _CMNOI:  guide word string
  543.  
  544.              This  function  parses  a  guide word string (noise words).
  545.         Guide words appear between  significant  parts  of  the  command
  546.         line, if  they  are  in  parentheses.    They  do not have to be
  547.         typed, but if they are, they must match what is  expected.    If
  548.         the  previous  field  ended  with  command  completion, then the
  549.         guide words are shown automatically by the parser.
  550.  
  551.              An interesting use of guide  word  strings  is  to  provide
  552.         alternate sets  with  the  command  chaining feature.  The parse
  553.         (and program) flow can be altered depending on which string  was
  554.         matched.
  555.  
  556.  
  557.  
  558.         CFB function _CMCFM:  confirmation
  559.  
  560.              A confirmation  is  a  carriage  return.  The caller should
  561.         parse a confirmation as the last thing  before  processing  what
  562.         was parsed.    Since  carriage  return  is  by default a wake-up
  563.         character, requiring a confirmation will (if  you  don't  change
  564.         this  wake-up  attribute)  require  that  the parse be completed
  565.         with no extra characters typed.   A  parse  with  this  function
  566.         code returns only a status.
  567.  
  568.  
  569.  
  570.         CFB function _CMGSK:  General storage keyword
  571.  
  572.              This  call provides for parsing of one of a set of keywords
  573.         which are  not  arranged  in  a  table.    Often,  keywords  are
  574.         actually stored  in  a  file  or  in  a linked list.  The caller
  575.         fills in the CFB_DAT element of the command function block  with
  576.         the  address  of  a  structure  named  CGKs (typedef CGK), which
  577.         contains the following elements:
  578.  
  579.  
  580.          o CGK_BAS:  A base address to give to the fetch routine.   Does
  581.            not  matter  what  this  is,  as  long  as  the fetch routine
  582.            understands it.
  583.  
  584.          o CFK_CFR:  The address  of  a  keyword  fetch  routine.    The
  585.            routine  is called with the CGK_BAS value, and the address of
  586.            the pointer to the previous  keyword.    It  is  expected  to
  587.            return  the  address  of  the pointer to the next keyword, or
  588.            with the first one if  the  passed  value  for  the  previous
  589.            pointer is NULL.
  590.  
  591.  
  592.  
  593.  
  594.                 When  this  function  completes successfully, it returns
  595.            the address of the pointer  to  the  string  in  the  CSB_RVL
  596.            element in   the   command   state  block;    otherwise  (for
  597.            unsuccessful completion), it must return NULL.    Please  see
  598.            the   description   of   the   _CMKEY  function  code  for  a
  599.            description of help and other processing.
  600.  
  601.                 Note:  the General Keyword facility can be  used  to  do
  602.            special  pre-processing  of candidate strings, such as hiding
  603.            keywords which are not appropriate  for  the  program  state,
  604.            user, access, etc.
  605.  
  606.  
  607.  
  608.  
  609.         CFB function _CMSWI:  Parse a switch.
  610.  
  611.              This  is  intended  to  perform  switch  matching,  but  it
  612.         currently is not implemented  and  will  return  a  result  code
  613.         _CRIFC (invalid  function  code) if you try it.  Basically it is
  614.         a placeholder for an unimplemented function.
  615.  
  616.  
  617.  
  618.         CFB function _CMTXT:  Rest of line
  619.  
  620.              This function parses the text  to  the  end  of  the  line.
  621.         Note  that  this  does  not  parse  the trailing break character
  622.         (i.e. the carriage return).  The text is returned  in  the  atom
  623.         buffer  which  is  defined  (by  the  caller) by the CSB_ABF and
  624.         CSB_ASZ elements of the command state block.
  625.  
  626.  
  627.  
  628.         CFB function _CMTOK:  token
  629.  
  630.              This function will parse an exact  match  of  a  particular
  631.         token.   A  token  is  a  string of characters, whose address is
  632.         supplied by the caller in the CFB_DAT  element  of  the  command
  633.         function block.    This  function  is  mainly useful for parsing
  634.         such things as commas and other separators, especially where  it
  635.         is one  of  several  alternative parse functions.  It returns no
  636.         value other than its status.
  637.  
  638.  
  639.  
  640.  
  641.         CFB function _CMUQS:  unquoted string
  642.  
  643.              This function parses an unquoted string, consisting of  any
  644.         characters other  than  spaces,  tabs, slashes, or commas.  This
  645.         set may of course be changed by  supplying  a  CC  table.    The
  646.         unquoted  string  is returned in the atom buffer associated with
  647.         the command state block.
  648.  
  649.  
  650.  
  651.         CFB function _CMDAT:  parse date/time
  652.  
  653.              This function parses  a  date  and/or  time.    The  caller
  654.         specifies,  via  flag  bits  in  the CFB_FLG byte of the command
  655.         function block (as identified above) which  of  date,  time,  or
  656.         both, are  to  be parsed.  The date and time are returned as the
  657.         first two ints in the atom buffer which is associated  with  the
  658.         command state   block.    Note  that  both  date  and  time  are
  659.         returned, regardless of which were requested.
  660.  
  661.              Note  further  that  the  _CMDAT  function  is  not   fully
  662.         implemented as of this writing.
  663.  
  664.  
  665.  
  666.  
  667.                            Calling the COMND library
  668.  
  669.  
  670.              All  that  you need to know to use the above information is
  671.         how to call the  command  library.    Basically,  there  is  one
  672.         support routine:  COMND().  It is used like this:
  673.  
  674.                  status = COMND (csbp, cfbp);
  675.  
  676.              Here,  "csbp"  is  the  address of the command state block,
  677.         and "cfbp" is the address of the command function  block.    The
  678.         COMND()  routine  returns  an  int status value, which is one of
  679.         the following:
  680.  
  681.  
  682.          o _CROK:   The  call  succeeded;    a  requested  function  was
  683.            performed.   The  address  of  the matching function block is
  684.            returned in the CSB_CFB element of the command  state  block,
  685.            and other information is returned as described above.
  686.  
  687.          o _CRNOP:  The call did not succeed;  nothing matched.
  688.  
  689.          o _CRRPT:   The call did not succeed because the user took back
  690.            some of what had already been parsed.    In  other  words,  a
  691.            reparse  is  required,  and  your program must back up to the
  692.            reparse point.  Note that if  you  specify  a  setjmp  buffer
  693.  
  694.  
  695.  
  696.  
  697.            address  in  the  CSB_RSB element of the command state block,
  698.            you will never see this value because the COMND library  will
  699.            execute a longjmp() operation using that setjmp buffer.
  700.  
  701.          o _CRIFC:    The  call  failed  because you provided an invalid
  702.            function code in the command function block (or in one  which
  703.            is chained to it).  One of us has made a programming error.
  704.  
  705.          o _CRBOF:   Buffer  overflow.   The atom buffer is too small to
  706.            contain the parsed field.
  707.  
  708.          o _CRBAS:  Invalid radix for number parse.
  709.  
  710.          o _CRAGN:  You should not see this code.  It is reserved for  a
  711.            support-mode call to the subroutine library.
  712.  
  713.  
  714.  
  715.  
  716.              When  you use the setjmp method of command reparsing, it is
  717.         usually  enough  to  check  the  result  against   _CROK   only,
  718.         everything else being treated the same (error in input).
  719.  
  720.  
  721.  
  722.  
  723.                          Installing the COMND library
  724.  
  725.  
  726.  
  727.              This  part of the document describes the modules which come
  728.         with the COMND library kit, and what you might have to  look  at
  729.         if  the  code does not instantly work on your system (which will
  730.         probably be the case if your system is not the same kind as  the
  731.         one which you got it from).
  732.  
  733.              The files which come in the COMND kit are as follows:
  734.  
  735.  
  736.          o  COMND.R  -  Source for this document, in a form suitable for
  737.            the public domain formatting program called "roff4".
  738.  
  739.          o COMND.DOC - This document.
  740.  
  741.          o COMND.EDT - Edit history for the subroutine library.
  742.  
  743.          o MEM.H - A file of my (Mark  Mallett)  definitions  which  are
  744.            used by the code in the command subroutine library.
  745.  
  746.          o COMND.H - Command library interface definitions.
  747.  
  748.          o COMNDI.H - Command library implementation definitions.
  749.  
  750.          o COMND.C  -  Primary  module  of  the COMND library.  Contains
  751.            user input buffering and various library support routines.
  752.  
  753.          o  CMDPF1.C  -  First  module  of  parse  function   processing
  754.            routines.
  755.  
  756.          o  CMDPF2.C  -  Second  module  of  parse  function  processing
  757.            routines.
  758.  
  759.          o CMDPFD.C - Contains the date/time  parse  function  routines.
  760.            This  is  included  in  a  separate  module so that it can be
  761.            replaced with  a  stub,  since  few  programs  (that  I  have
  762.            written,  anyway)  use  this  function, and it does take up a
  763.            bit of code.
  764.  
  765.          o CMDPSD.C - A stub for the date/time parsing functions.   This
  766.            can  be  linked  with  programs which do not actually use the
  767.            date/time parse function.
  768.  
  769.          o CMDOSS.CPM - Operating system specific code which  works  for
  770.            CP/M.   This  is  provided  as a model for the routines which
  771.            you will have to write for your system.
  772.  
  773.          o DATE.CPM - Date/time support  routines  for  version  3.0  of
  774.            CP/M.   This  is a module containing routines to get the date
  775.  
  776.  
  777.  
  778.  
  779.            and time from the  operating  system,  and  to  encode/decode
  780.            these values  to and from internal form.  This is provided as
  781.            a model;  you will probably have to  rewrite  them  for  your
  782.            system.   Note,  you  don't  need these routines if you don't
  783.            use the date and time parsing function (if you use  the  stub
  784.            instead).
  785.  
  786.  
  787.  
  788.  
  789.                                Your Improvements
  790.  
  791.  
  792.  
  793.              If  you  improve  this  library  or  make  it work on a new
  794.         operating system, I'd appreciate hearing about it so that I  can
  795.         maintain a   proper   version.      Also   please  maintain  the
  796.         edit/version history in the file COMND.EDT.
  797.  
  798.  
  799.                                                 Mark E. Mallett
  800.                                                 c/o M-TEK
  801.                                                 P.O. box 6357
  802.                                                 Nashua NH 03114
  803.  
  804.                                                 voice: 603 424 8129
  805.                                                 data:  603 424 8124
  806.                                                    (1200 baud, allow system
  807.                                                     time to boot)
  808.