home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / BASH_112.ZIP / BASH-112.TAR / bash-1.12 / command.h < prev    next >
C/C++ Source or Header  |  1992-01-21  |  7KB  |  179 lines

  1. /* command.h -- The structures used internally to represent commands, and
  2.    the extern declarations of the functions used to create them. */
  3.  
  4. #if !defined (_COMMAND_H)
  5. #define _COMMAND_H
  6.  
  7. /* Instructions describing what kind of thing to do for a redirection. */
  8. enum r_instruction {
  9.   r_output_direction, r_input_direction, r_inputa_direction,
  10.   r_appending_to, r_reading_until, r_duplicating_input,
  11.   r_duplicating_output, r_deblank_reading_until, r_close_this,
  12.   r_err_and_out, r_input_output, r_output_force,
  13.   r_duplicating_input_word, r_duplicating_output_word
  14. };
  15.  
  16. /* Command Types: */
  17. enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple,
  18.             cm_connection, cm_function_def, cm_until, cm_group };
  19.  
  20. /* A structure which represents a word. */
  21. typedef struct word_desc {
  22.   char *word;        /* Zero terminated string. */
  23.   int dollar_present;    /* Non-zero means dollar sign present. */
  24.   int quoted;        /* Non-zero means single, double, or back quote
  25.                or backslash is present. */
  26.   int assignment;    /* Non-zero means that this word contains an
  27.                assignment. */
  28. } WORD_DESC;
  29.  
  30. /* A linked list of words. */
  31. typedef struct word_list {
  32.   struct word_list *next;
  33.   WORD_DESC *word;
  34. } WORD_LIST;
  35.  
  36.  
  37. /* **************************************************************** */
  38. /*                                    */
  39. /*            Shell Command Structs                */
  40. /*                                    */
  41. /* **************************************************************** */
  42.  
  43. /* What a redirection descriptor looks like.  If FLAGS is IS_DESCRIPTOR,
  44.    then we use REDIRECTEE.DEST, else we use the file specified. */
  45. typedef struct redirect {
  46.   struct redirect *next;    /* Next element, or NULL. */
  47.   int redirector;        /* Descriptor to be redirected. */
  48.   int flags;            /* Flag value for `open'. */
  49.   enum r_instruction  instruction; /* What to do with the information. */
  50.   union {
  51.     int dest;            /* Place to redirect REDIRECTOR to, or ... */
  52.     WORD_DESC *filename;    /* filename to redirect to. */
  53.   } redirectee;
  54.   char *here_doc_eof;        /* The word that appeared in <<foo. */
  55. } REDIRECT;
  56.  
  57. /* An element used in parsing.  A single word or a single redirection.
  58.    This is an ephemeral construct. */
  59. typedef struct element {
  60.   WORD_DESC *word;
  61.   REDIRECT *redirect;
  62. } ELEMENT;
  63.  
  64. /* Possible values for command->flags. */
  65. #define CMD_WANT_SUBSHELL  0x01    /* User wants a subshell: ( command ) */
  66. #define CMD_FORCE_SUBSHELL 0x02    /* Shell needs to force a subshell. */
  67. #define CMD_INVERT_RETURN  0x04    /* Invert the exit value. */
  68. #define CMD_IGNORE_RETURN  0x08    /* Ignore the exit value.  For set -e. */
  69. #define CMD_NO_FUNCTIONS   0x10 /* Ignore functions during command lookup. */
  70. #define CMD_INHIBIT_EXPANSION 0x20 /* Do not expand the command words. */
  71.  
  72. /* What a command looks like. */
  73. typedef struct command {
  74.   enum command_type type;    /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
  75.   int flags;            /* Flags controlling execution environment. */
  76.   REDIRECT *redirects;        /* Special redirects for FOR CASE, etc. */
  77.   union {
  78.     struct for_com *For;
  79.     struct case_com *Case;
  80.     struct while_com *While;
  81.     struct if_com *If;
  82.     struct connection *Connection;
  83.     struct simple_com *Simple;
  84.     struct function_def *Function_def;
  85.     struct group_com *Group;
  86.   } value;
  87. } COMMAND;
  88.  
  89. /* Structure used to represent the CONNECTION type. */
  90. typedef struct connection {
  91.   int ignore;            /* Unused; simplifies make_command (). */
  92.   COMMAND *first;        /* Pointer to the first command. */
  93.   COMMAND *second;        /* Pointer to the second command. */
  94.   int connector;        /* What separates this command from others. */
  95. } CONNECTION;
  96.  
  97. /* Structures used to represent the CASE command. */
  98.  
  99. /* Pattern/action structure for CASE_COM. */
  100. typedef struct pattern_list {
  101.   struct pattern_list *next;    /* Clause to try in case this one failed. */
  102.   WORD_LIST *patterns;        /* Linked list of patterns to test. */
  103.   COMMAND *action;        /* Thing to execute if a pattern matches. */
  104. } PATTERN_LIST;
  105.  
  106. /* The CASE command. */
  107. typedef struct case_com {
  108.   int flags;            /* See description of CMD flags. */
  109.   WORD_DESC *word;        /* The thing to test. */
  110.   PATTERN_LIST *clauses;    /* The clauses to test against, or NULL. */
  111. } CASE_COM;
  112.  
  113. /* FOR command. */
  114. typedef struct for_com {
  115.   int flags;        /* See description of CMD flags. */
  116.   WORD_DESC *name;    /* The variable name to get mapped over. */
  117.   WORD_LIST *map_list;    /* The things to map over.  This is never NULL. */
  118.   COMMAND *action;    /* The action to execute.
  119.                During execution, NAME is bound to successive
  120.                members of MAP_LIST. */
  121. } FOR_COM;
  122.  
  123. /* IF command. */
  124. typedef struct if_com {
  125.   int flags;            /* See description of CMD flags. */
  126.   COMMAND *test;        /* Thing to test. */
  127.   COMMAND *true_case;        /* What to do if the test returned non-zero. */
  128.   COMMAND *false_case;        /* What to do if the test returned zero. */
  129. } IF_COM;
  130.  
  131. /* WHILE command. */
  132. typedef struct while_com {
  133.   int flags;            /* See description of CMD flags. */
  134.   COMMAND *test;        /* Thing to test. */
  135.   COMMAND *action;        /* Thing to do while test is non-zero. */
  136. } WHILE_COM;
  137.  
  138. /* The "simple" command.  Just a collection of words and redirects. */
  139. typedef struct simple_com {
  140.   int flags;            /* See description of CMD flags. */
  141.   WORD_LIST *words;        /* The program name, the arguments,
  142.                    variable assignments, etc. */
  143.   REDIRECT *redirects;        /* Redirections to perform. */
  144. } SIMPLE_COM;
  145.  
  146. /* The "function_def" command.  This isn't really a command, but it is
  147.    represented as such for now.  If the function def appears within 
  148.    `(' `)' the parser tries to set the SUBSHELL bit of the command.  That
  149.    means that FUNCTION_DEF has to be run through the executor.  Maybe this
  150.    command should be defined in a subshell.  Who knows or cares. */
  151. typedef struct function_def {
  152.   int ignore;            /* See description of CMD flags. */
  153.   WORD_DESC *name;        /* The name of the function. */
  154.   COMMAND *command;        /* The parsed execution tree. */
  155. } FUNCTION_DEF;
  156.  
  157. /* A command that is `grouped' allows pipes to take effect over
  158.    the entire command structure. */
  159. typedef struct group_com {
  160.   int ignore;            /* See description of CMD flags. */
  161.   COMMAND *command;
  162. } GROUP_COM;
  163.  
  164. /* Forward declarations of functions called by the grammer. */
  165. extern REDIRECT *make_redirection ();
  166. extern WORD_LIST *make_word_list ();
  167. extern WORD_DESC *make_word ();
  168.  
  169. extern COMMAND
  170.   *make_for_command (), *make_case_command (), *make_if_command (),
  171.   *make_while_command (), *command_connect (), *make_simple_command (),
  172.   *make_function_def (), *clean_simple_command (), *make_until_command (),
  173.   *make_group_command ();
  174.  
  175. extern PATTERN_LIST *make_pattern_list ();
  176. extern COMMAND *global_command, *copy_command ();
  177.  
  178. #endif /* _COMMAND_H */
  179.