home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mm / ccmd / ccmd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  8.7 KB  |  240 lines

  1. /*
  2.  Copyright (c) 1986, 1990 by The Trustees of Columbia University in
  3.  the City of New York.  Permission is granted to any individual or
  4.  institution to use, copy, or redistribute this software so long as it
  5.  is not sold for profit, provided this copyright notice is retained.
  6.  
  7.  Author: Andrew Lowry
  8. */
  9.  
  10. /* ccmd.h
  11.  *
  12.  * Include this file if your program will make use of the CCMD
  13.  * command parsing routines.  Included here are function and
  14.  * flag definitions, error codes, and parsing structure declarations.
  15.  * As much as possible, symbols are patterned after corresponding
  16.  * TOPS-20 symbols, with non-alphameric characters (. and %) replaced
  17.  * by underscores.
  18.  */
  19.  
  20. #ifndef stdin
  21. #include <stdio.h>
  22. #endif
  23. #ifndef _JBLEN
  24. #include <setjmp.h>
  25. #endif
  26. #include "cmfnc.h"        /* get function-specific symbols */
  27. #include "ccmdmd.h"        /* get machine dependent symbols */
  28.  
  29. /*
  30.  * BRKTAB is a pair of 128-bit arrays specifying the break characteristics
  31.  * of the ASCII characters.  The _br1st array specifies characters which
  32.  * will break field input when they are typed as the first character of
  33.  * a field.  The _brrest array specifies characters that break in other
  34.  * than the first position.  Each array contains one bit per ASCII 
  35.  * code, ordered according to the ASCII sequence.  The leftmost (most
  36.  * significant) bit of the first byte corresponds to ASCII code 0, and
  37.  * the rightmost bit of that same byte corresponds to ASCII code 7.
  38.  * Leftmost bit of the second bit is for ASCII code 8, and so on.
  39.  * When a bit is on, the corresponding character will act as a break
  40.  * character, otherwise it will not.
  41.  *
  42.  * Routines in module cmutil can be used to construct and maintain
  43.  * break tables.
  44.  */
  45.  
  46. typedef struct BRKTAB {
  47.     char _br1st[16];    /* Bit array for initial character breaks */
  48.     char _brrest[16];    /* Bit array for subsequent breaks */
  49. } brktab;
  50.  
  51. /*
  52.  * FDB structures hold information required to parse specific fields of
  53.  * a command line.
  54.  */
  55.  
  56. typedef struct FDB {
  57.     int    _cmfnc;        /* Function code for this field */
  58.     int    _cmffl;        /* Function specific parse flags */
  59.     struct FDB * _cmlst;    /* Link to alternate FDB */
  60.     pdat    _cmdat;        /* Function specific parsing data */
  61.     char *    _cmhlp;        /* pointer to help string */
  62.     char *    _cmdef;        /* pointer to default string */
  63.     brktab * _cmbrk;    /* pointer to special break table */
  64.     char *    _cmest;        /* specialized error string */
  65. } fdb;
  66.  
  67. /* Common flag defined for all parse functions */
  68. #define    CM_SDH    0x8000        /* Suppress default help message */
  69. #define CM_SDE    0x4000        /* Supress default error msg */
  70. #define CM_NLH  0x2000        /* Extra newline help for multi fdbs */
  71. #define CM_NEOF 0x1000        /* parser handles eof itself. */
  72.  
  73. typedef struct histbuf {
  74.     int *buf;
  75.     int len;
  76. } cmhistbuf;
  77.  
  78.  
  79.  
  80. typedef struct hist {
  81.     cmhistbuf *bufs;        /* array of history buffers */
  82.     int  len;            /* how many buffers there are */
  83.     int  next;            /* index of next buffer to write into */
  84.     int  current;        /* index of current point in history */
  85.     int  enabled;        /* tell if we should remember */
  86. } cmhist;
  87. /*
  88.  * CSB structure holds information on the state of parsing a command
  89.  * line, as well as pointers to required buffers.
  90.  */
  91.  
  92. typedef struct CSB {
  93.     int     _cmflg;        /* flags describing parse state */
  94.     int    _cmflg2;    /* more flags */
  95.     FILE *  _cmij;        /* file for command input */
  96.     FILE *    _cmoj;        /* file for command output */
  97.     FILE *  _cmej;        /* file for error output */
  98.     char *    _cmrty;        /* pointer to prompt string */
  99.     int *    _cmbfp;        /* pointer to beginning of user input */
  100.     int *    _cmptr;        /* pointer to beg of next field to parse */
  101.     int     _cmcnt;        /* # of chars in buffer past _cmptr */
  102.     int    _cminc;        /* number of unparsed chars after _cmptr */
  103.     int *    _cmhst;        /* history parse point */
  104.     char *    _cmabp;        /* pointer to beginning of atom buffer */
  105.     int    _cmabc;        /* size of atom buffer */
  106.     char *    _cmwbp;        /* pointer to beginning of work buffer */
  107.     int    _cmwbc;        /* size of work buffer */
  108.     int (** _cmact)();    /* table of character action routines */
  109.     int     _cmbkc;            /* break character that caused deferred */
  110.                 /*  action or confirmation */
  111.     int    _cmcmx;        /* maximum column position on terminal */
  112.     int    _cmcol;        /* current column position on terminal */
  113.     int    _cmerr;        /* most recent parse error */
  114.     fdb *    _cmifd;        /* ptr to FDB giving an incomplete parse */
  115.     int     (* _cmrph)();    /* function to call when reparse is needed */
  116.     int     (* _cmerh)();    /* function to call on parse error */
  117.     char *  _cmntb;        /* comment to eol string */
  118.     char *    _cmnts;        /* delimited comment beginning */
  119.     char *    _cmnte;        /* delimited comment end */
  120.     int     _cmmax;        /* maximum number of help tokens to display */
  121.     int     (* _cmblh)();    /* function to call nonblocking and no data */
  122.     int     _cmwrp;        /* column to wrap at */
  123.     cmhist *_cmhist;    /* command history  structure */
  124.     int     _cmrmx;        /* max number of rows */
  125.     int *    _cmcur;        /* current position in cmd buffer */
  126.     int (** _cmpract)();    /* table of actions after prefix character */
  127. } csb;
  128.  
  129. typedef struct cmacttab {    /* table of action chars */
  130.     char actionchar;        /* action character */
  131.     int (* actionfunc)();    /* action routine */
  132. } cmacttab;
  133.  
  134. /*
  135.  * major command line editing modes up to 16
  136.  */
  137. #define CMaNOSET 0        /* used to not set a field */
  138.  
  139. #define CMaEMACS 0x0001        /* emacs like actions */
  140. #define CMaGMACS 0x0002        /* gnuemacs like actions */
  141. #define CMaVI    0x0003        /* vi like actions (not implemented) */
  142.  
  143. /*
  144.  * modifiers to cmd line editor
  145.  */
  146. #define CMaFCASE 0x0010        /* forward casing */
  147. #define CMaBCASE 0x0020        /* backward casing */
  148. #define CMaEOF   0x0040        /* handle eof */
  149. #define CMaIEOF  0x0080        /* ignore eof */
  150.  
  151. /* Flags that can be set in individual character entries (each an int) in
  152. ** the _cmbfp buffer of the CSB.  The CC_QUO flag is the high order bit in
  153. ** the right half, all the rest are in the left half.  CC_QUO is left in
  154. ** the right half so that parse routines can see it, since the parse routines
  155. ** get their data as character strings, without the left half flags.
  156. **/
  157.  
  158. #define    CC_CHR    0x007f        /* character data field */
  159. #define CC_QUO    0x0080        /* character was quoted */
  160. #define    CC_QCH    0x00ff        /* character data with quote flag */
  161. #define    CC_NEC    0x0100        /* character was not echoed */
  162. #define CC_HID    0x0200        /* character is hidden from user */
  163. #define CC_SKP    0x0400        /* character is to be skipped (not */
  164.                 /*  considered input for parsing) */
  165. #define    CC_CSK    0x0800        /* char is conditionally skipped, */
  166.                 /*  meaning that it is skipped as */
  167.                 /*  long as it is followed by a (possibly */
  168.                 /*  empty) string of characters with the */
  169.                 /*  CC_CSK flag, and eventually a character */
  170.                 /*  with the CC_SKP flag. */
  171. #define CC_ACT    0x1000        /* char should be treated as an action char */
  172.                 /*  on reparse. */
  173.  
  174. /* Flag values for _cmflg field of CSB */
  175.  
  176. /*   Settable by user... */
  177. #define    CM_RAI    0x0001        /* Convert to uppercase before parsing */
  178. #define    CM_WKF    0x0002        /* Wake up as each field is terminated */
  179. #define    CM_NEC    0x0004        /* Do not echo tty input as it is typed */
  180.  
  181. /*   Maintained by ccmd routines */
  182. #define CM_ESC    0x0008        /* This field got completion to successful */
  183.                 /*  parse */
  184. #define    CM_NOP    0x0010        /* Field could not be parsed */
  185. #define    CM_RPT    0x0020        /* Reparse needed -- previously parsed */
  186.                 /*  input has been edited */
  187. #define    CM_SWT    0x0040        /* Switch was terminated with a colon */
  188. #define    CM_PFE    0x0080        /* Previous field got completion (for */
  189.                 /*  noise word handling) */
  190. #define    CM_DRT    0x0100        /* New input has been typed (and possibly */
  191.                 /*  erased) since the last cmini call on */
  192.                 /*  this CSB. */
  193. #define CM_CFM    0x0200        /* This field was terminated by a newline */
  194. #define    CM_ACT    0x0400            /* Deferred action is set, waiting for a */
  195.                 /*  field to run out of input */
  196. #define    CM_PRS    0x0800        /* Data has been parsed in this cmd line */
  197.                 /*  (used to ignore confirms following only */
  198.                 /*  white space) */
  199. #define CM_ITTY 0x1000        /* input is a terminal */
  200. #define CM_OTTY 0x2000        /* output is a terminal */
  201. #define    CM_TTY    0x3000        /* Command source is a terminal */
  202.  
  203. #define    CM_NAC    0x4000        /* Do not copy parsed text to atom buffer */
  204. #define CM_CMT    0x8000        /* Currently inside a comment */
  205.  
  206. /*
  207.  * flags bits for the second flag word.
  208.  */
  209.  
  210. /* 
  211.  * user settable bits.
  212.  */
  213. #define CM_NIN    0x0001        /* don't do indirections */
  214. #define CM_NHM  0x0002        /* don't use "more" code during help */
  215.                 /* a specialized help string */
  216. /*
  217.  * CCMD maintained bits
  218.  */
  219. #define CM_IND    0x0004        /* currently in an indirect parse */
  220. #define CM_EOF  0x0008        /* flag EOF condition */
  221. #define    CM_CRT    0x0010        /* Command source is a video terminal */
  222.  
  223. extern csb cmcsb;        /* CSB for all parses (ccmd) */
  224.  
  225. /* Forward declarations for routines that return anything other than int */
  226.  
  227. fdb *fdbchn();
  228.  
  229. /* Miscellaneous definitions */
  230.  
  231. #ifndef TRUE
  232. #define    TRUE    -1
  233. #define    FALSE    0
  234. #endif
  235.  
  236. #ifndef NULL
  237. #define NULL 0
  238. #endif
  239. extern char *cmrealloc();
  240.