home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / sysutils / kornshel / tree.h < prev    next >
C/C++ Source or Header  |  1992-09-06  |  4KB  |  119 lines

  1. /*
  2.  * command trees for compile/execute
  3.  */
  4.  
  5. /* $Id: tree.h,v 1.3 1992/08/10 12:03:18 sjg Exp $ */
  6.  
  7. #define    NOBLOCK    ((struct op *)NULL)
  8. #define    NOWORD    ((char *)NULL)
  9. #define    NOWORDS    ((char **)NULL)
  10.  
  11. /*
  12.  * Description of a command or an operation on commands.
  13.  */
  14. struct op {
  15.     int    type;            /* operation type, see below */
  16.     char  **args;            /* arguments to a command */
  17.     char  **vars;            /* variable assignments */
  18.     struct ioword    **ioact;    /* IO actions (eg, < > >>) */
  19.     struct op *left, *right;     /* descendents */
  20.     char   *str;        /* identifier for case and for (use vars[0]) */
  21. };
  22.  
  23. /* Tree.type values */
  24. #define    TEOF    0
  25. #define    TCOM    1        /* command */
  26. #define    TPAREN    2        /* (c-list) */
  27. #define    TPIPE    3        /* a | b */
  28. #define    TLIST    4        /* a [&;] b */
  29. #define    TOR    5        /* || */
  30. #define    TAND    6        /* && */
  31. #define    TFOR    7
  32. #define    TCASE    9
  33. #define    TIF    10
  34. #define    TWHILE    11
  35. #define    TUNTIL    12
  36. #define    TELIF    13
  37. #define    TPAT    14        /* pattern in case */
  38. #define    TBRACE    15        /* {c-list} */
  39. #define    TASYNC    16        /* c & */
  40. #define    TFUNCT    17        /* function name { command; } */
  41. #define    TTIME    18        /* time pipeline */
  42. #define    TEXEC    19        /* fork/exec eval'd TCOM */
  43. #define TSELECT    20        /* select */
  44.  
  45. /*
  46.  * prefix codes for words in command tree
  47.  */
  48. #define    EOS    0        /* end of string */
  49. #define    CHAR    1        /* unquoted character */
  50. #define    QCHAR    2        /* quoted character */
  51. #define    COMSUB    3        /* $() substitution (0 terminated) */
  52. #define    OQUOTE    4        /* opening " or ' */
  53. #define    CQUOTE    5        /* closing " or ' */
  54. #define    OSUBST    6        /* opening ${ substitution */
  55. #define    CSUBST    7        /* closing } of above */
  56.  
  57. /*
  58.  * IO redirection
  59.  */
  60. struct ioword {
  61.     int    unit;    /* unit affected */
  62.     int    flag;    /* action (below) */
  63.     char   *name;    /* file name */
  64. };
  65.  
  66. /* ioword.flag - type of redirection */
  67. #define    IOTYPE    0xF        /* type: bits 0:3 */
  68. #define    IOREAD    0x1        /* < */
  69. #define    IOWRITE    0x2        /* > */
  70. #define    IORDWR    0x3        /* <>: todo */
  71. #define    IOHERE    0x4        /* << (here file) */
  72. #define    IOCAT    0x5        /* >> */
  73. #define    IODUP    0x6        /* <&/>& */
  74. #define    IOEVAL    BIT(4)        /* expand in << */
  75. #define    IOSKIP    BIT(5)        /* <<-, skip ^\t* */
  76. #define    IOCLOB    BIT(6)        /* >!, override -o noclob */
  77.  
  78. /* values for E_LOOP longjmp */
  79. #define    LBREAK    1
  80. #define    LCONTIN    2
  81.  
  82. /* execute/exchild flags */
  83. #define    XEXEC    BIT(0)        /* execute without forking */
  84. #define    XFORK    BIT(5)        /* fork before executing */
  85. #define    XBGND    BIT(1)        /* command & */
  86. #define    XPIPEI    BIT(2)        /* input is pipe */
  87. #define    XPIPEO    BIT(3)        /* output is pipe */
  88. #define    XPIPE    (XPIPEI|XPIPEO)    /* member of pipe */
  89. #define    XXCOM    BIT(4)        /* dup2 xcomfd to 1 */
  90. #define XXWHL    BIT(6)        /* don't flush stdin before fork */
  91.  
  92. /*
  93.  * flags to control expansion of words
  94.  */
  95. #define    DOBLANK    BIT(1)        /* perform blank interpretation */
  96. #define    DOGLOB    BIT(2)        /* expand [?* */
  97. #define    DOPAT    BIT(3)        /* quote *?[ */
  98. #define    DOTILDE    BIT(5)        /* expand ~ */
  99.  
  100. #if 0
  101. /* job.c: job control primatives */
  102. int    execute ARGS((struct op *, int flags));    /* execute tree */
  103. int    exchild ARGS((struct op *, int flags));    /* execute tree as child */
  104. int    waitfor ARGS((int job));         /* wait for job completion */
  105. int    waitlast ARGS((void));            /* wait for last job */
  106.  
  107. /* eval.c: word expansion */
  108. char  **eval ARGS((char **wv, int flag));     /* expand words */
  109. char   *evalstr ARGS((char *wp, int flags));    /* expand word */
  110. char   *substitute ARGS((const char *s, int flags)); /* compile and expand string */
  111.  
  112. /* tree.c: command trees */
  113. void    ptree ARGS((struct op *t, FILE *f));    /* print tree */
  114. char   *wdscan ARGS((char *wp, int c));        /* scan word for prefix */
  115. char   *wdcopy ARGS((char *wp, Area *));    /* copy word */
  116. struct op *tcopy ARGS((struct op *t, Area *));    /* copy tree */
  117. void    tfree ARGS((struct op *t, Area *));    /* free tree */
  118. #endif
  119.