• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/maloc/src/vsh/vsh_p.h

00001 /*
00002  * ***************************************************************************
00003  * MALOC = < Minimal Abstraction Layer for Object-oriented C >
00004  * Copyright (C) 1994--2008 Michael Holst
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019  *
00020  * rcsid="$Id: vsh_p.h,v 1.11 2008/03/12 05:13:58 fetk Exp $"
00021  * ***************************************************************************
00022  */
00023 
00024 /*
00025  * ***************************************************************************
00026  * File:     vsh_p.h
00027  *
00028  * Purpose:  PRIVATE header.
00029  *
00030  * Author:   Michael Holst
00031  * ***************************************************************************
00032  */
00033 
00034 #ifndef _VSH_P_H_
00035 #define _VSH_P_H_
00036 
00037 #include <maloc/vsh.h>
00038 #include "maloccf.h"
00039 
00040 #if defined(HAVE_UNISTD_H)
00041 #   include <unistd.h> 
00042 #endif
00043 
00044 #if defined(HAVE_SYS_TYPES_H)
00045 #   include <sys/types.h> 
00046 #endif
00047 
00048 #if defined(HAVE_SYS_TIME_H)
00049 #   include <sys/time.h> 
00050 #endif
00051 
00052 #if defined(HAVE_SYS_TIMES_H)
00053 #   include <sys/times.h> 
00054 #endif
00055 
00056 #if defined(HAVE_SYS_STAT_H)
00057 #   include <sys/stat.h> 
00058 #endif
00059 
00060 #if defined(HAVE_FCNTL_H)
00061 #   include <fcntl.h> 
00062 #endif
00063 
00064 #if defined(HAVE_SYS_WAIT_H)
00065 #   include <sys/wait.h>
00066 #endif
00067 
00068 #if defined(HAVE_DIRECT_H)
00069 #   include <direct.h>
00070 #endif
00071 
00072 #if defined(HAVE_PROCESS_H)
00073 #   include <process.h>
00074 #endif
00075 
00076 #if defined(HAVE_READLINE_READLINE_H)
00077 #   include <readline/readline.h>
00078 #endif
00079 
00080 #if defined(HAVE_READLINE_HISTORY_H)
00081 #   include <readline/history.h>
00082 #endif
00083 
00084 #if defined(HAVE_WINSOCK_H)
00085     VEXTERNC int isatty(int desc);
00086 #endif
00087 
00088 /* macros */
00089 /* define Vsh_TRACE */
00090 #define VSH_INPUT(buf,result,max_size) { result = Vsh_input((buf),(max_size)); }
00091 #define REVERSE_LIST(list, type) \
00092     ((list && list->next) ? (type)reverse_list ((GENERIC_LIST *)list) : \
00093     (type)(list))
00094 
00095 /*
00096  * All structs which contain a `next' field should have that field
00097  * as the first field in the struct.  This means that functions
00098  * can be written to handle the general case for linked lists.
00099  */
00100 typedef struct g_list {
00101     struct g_list *next;
00102 } GENERIC_LIST;
00103 
00104 /* Instructions describing what kind of thing to do for a redirection. */
00105 enum r_instruction {
00106   r_output_direction, r_input_direction, r_inputa_direction,
00107   r_appending_to, r_reading_until, r_duplicating_input,
00108   r_duplicating_output, r_deblank_reading_until, r_close_this,
00109   r_err_and_out, r_input_output, r_output_force,
00110   r_duplicating_input_word, r_duplicating_output_word
00111 };
00112 
00113 /* command types */
00114 enum command_type {
00115     cm_for, cm_case, cm_while, cm_if, cm_simple,
00116     cm_connection, cm_function_def, cm_until, cm_group
00117 };
00118 
00119 /* A structure which represents a word. */
00120 typedef struct word_desc {
00121   char *word;       /* Zero terminated string. */
00122   int dollar_present;   /* Non-zero means dollar sign present. */
00123   int quoted;       /* Non-zero means single, double, or back quote
00124                or backslash is present. */
00125   int assignment;   /* Non-zero means that this word contains an
00126                assignment. */
00127 } WORD_DESC;
00128 
00129 /* A linked list of words. */
00130 typedef struct word_list {
00131   struct word_list *next;
00132   WORD_DESC *word;
00133 } WORD_LIST;
00134 
00135 /* ************************************************************************ */
00136 
00137 /* What a redirection descriptor looks like.  If FLAGS is IS_DESCRIPTOR,
00138    then we use REDIRECTEE.DEST, else we use the file specified. */
00139 
00140 typedef union {
00141   long dest;            /* Place to redirect REDIRECTOR to, or ... */
00142   WORD_DESC *filename;      /* filename to redirect to. */
00143 } REDIRECTEE;
00144 
00145 typedef struct redirect {
00146   struct redirect *next;    /* Next element, or NULL. */
00147   int redirector;       /* Descriptor to be redirected. */
00148   int flags;            /* Flag value for `open'. */
00149   enum r_instruction  instruction; /* What to do with the information. */
00150   REDIRECTEE redirectee;    /* File descriptor or filename */
00151   char *here_doc_eof;       /* The word that appeared in <<foo. */
00152 } REDIRECT;
00153 
00154 /* An element used in parsing.  A single word or a single redirection.
00155    This is an ephemeral construct. */
00156 typedef struct element {
00157   WORD_DESC *word;
00158   REDIRECT *redirect;
00159 } ELEMENT;
00160 
00161 /* Possible values for command->flags. */
00162 #define CMD_WANT_SUBSHELL  0x01 /* User wants a subshell: ( command ) */
00163 #define CMD_FORCE_SUBSHELL 0x02 /* Shell needs to force a subshell. */
00164 #define CMD_INVERT_RETURN  0x04 /* Invert the exit value. */
00165 #define CMD_IGNORE_RETURN  0x08 /* Ignore the exit value.  For set -e. */
00166 #define CMD_NO_FUNCTIONS   0x10 /* Ignore functions during command lookup. */
00167 #define CMD_INHIBIT_EXPANSION 0x20 /* Do not expand the command words. */
00168 #define CMD_NO_FORK    0x40 /* Don't fork; just call execve */
00169 
00170 /* What a command looks like. */
00171 typedef struct command {
00172   enum command_type type;   /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
00173   int flags;            /* Flags controlling execution environment. */
00174   int line;         /* line number the command starts on */
00175   REDIRECT *redirects;      /* Special redirects for FOR CASE, etc. */
00176   union {
00177     struct for_com *For;
00178     struct case_com *Case;
00179     struct while_com *While;
00180     struct if_com *If;
00181     struct connection *Connection;
00182     struct simple_com *Simple;
00183     struct function_def *Function_def;
00184     struct group_com *Group;
00185   } value;
00186 } COMMAND;
00187 
00188 /* Structure used to represent the CONNECTION type. */
00189 typedef struct connection {
00190   int ignore;           /* Unused; simplifies make_command (). */
00191   COMMAND *first;       /* Pointer to the first command. */
00192   COMMAND *second;      /* Pointer to the second command. */
00193   int connector;        /* What separates this command from others. */
00194 } CONNECTION;
00195 
00196 /* Structures used to represent the CASE command. */
00197 
00198 /* Pattern/action structure for CASE_COM. */
00199 typedef struct pattern_list {
00200   struct pattern_list *next;    /* Clause to try in case this one failed. */
00201   WORD_LIST *patterns;      /* Linked list of patterns to test. */
00202   COMMAND *action;      /* Thing to execute if a pattern matches. */
00203 } PATTERN_LIST;
00204 
00205 /* The CASE command. */
00206 typedef struct case_com {
00207   int flags;            /* See description of CMD flags. */
00208   WORD_DESC *word;      /* The thing to test. */
00209   PATTERN_LIST *clauses;    /* The clauses to test against, or NULL. */
00210 } CASE_COM;
00211 
00212 /* FOR command. */
00213 typedef struct for_com {
00214   int flags;        /* See description of CMD flags. */
00215   WORD_DESC *name;  /* The variable name to get mapped over. */
00216   WORD_LIST *map_list;  /* The things to map over.  This is never NULL. */
00217   COMMAND *action;  /* The action to execute.
00218                During execution, NAME is bound to successive
00219                members of MAP_LIST. */
00220 } FOR_COM;
00221 
00222 /* IF command. */
00223 typedef struct if_com {
00224   int flags;            /* See description of CMD flags. */
00225   COMMAND *test;        /* Thing to test. */
00226   COMMAND *true_case;       /* What to do if the test returned non-zero. */
00227   COMMAND *false_case;      /* What to do if the test returned zero. */
00228 } IF_COM;
00229 
00230 /* WHILE command. */
00231 typedef struct while_com {
00232   int flags;            /* See description of CMD flags. */
00233   COMMAND *test;        /* Thing to test. */
00234   COMMAND *action;      /* Thing to do while test is non-zero. */
00235 } WHILE_COM;
00236 
00237 /* The "simple" command.  Just a collection of words and redirects. */
00238 typedef struct simple_com {
00239   int flags;            /* See description of CMD flags. */
00240   WORD_LIST *words;     /* The program name, the arguments,
00241                    variable assignments, etc. */
00242   REDIRECT *redirects;      /* Redirections to perform. */
00243   int line;         /* line number the command starts on */
00244 } SIMPLE_COM;
00245 
00246 /* The "function_def" command.  This isn't really a command, but it is
00247    represented as such for now.  If the function def appears within
00248    `(' `)' the parser tries to set the SUBSHELL bit of the command.  That
00249    means that FUNCTION_DEF has to be run through the executor.  Maybe this
00250    command should be defined in a subshell.  Who knows or cares. */
00251 typedef struct function_def {
00252   int ignore;           /* See description of CMD flags. */
00253   WORD_DESC *name;      /* The name of the function. */
00254   COMMAND *command;     /* The parsed execution tree. */
00255 } FUNCTION_DEF;
00256 
00257 /* A command that is `grouped' allows pipes to take effect over
00258    the entire command structure. */
00259 typedef struct group_com {
00260   int ignore;           /* See description of CMD flags. */
00261   COMMAND *command;
00262 } GROUP_COM;
00263 
00264 /* ************************************************************************ */
00265 
00266 /* global variables */
00267 VEXTERNC int cmdKey; 
00268 VEXTERNC Vsh *Vsh_thee;
00269 VEXTERNC COMMAND *global_command;
00270 
00271 /* prototypes for lex/yacc-generated functions */
00272 VEXTERNC char *yytext;
00273 VEXTERNC int yylex(void);
00274 VEXTERNC int yyparse(void);
00275 VEXTERNC void yyerror(const char *errmsg);
00276 VEXTERNC int yywrap(void);
00277 VEXTERNC void yyrestart(FILE *input_file);
00278 
00279 /* Vsh support */
00280 VEXTERNC int Vsh_builtIn(Vsh *thee, int argc, char **argv);
00281 VEXTERNC int Vsh_isInteractive(Vsh *thee);
00282 
00283 /* Vsh support */
00284 VEXTERNC void Vsh_trace(char *from, char *arg);
00285 VEXTERNC int Vsh_keepVariable(char *envi, char *valu);
00286 VEXTERNC void Vsh_addhist(char *buf, int buflen);
00287 VEXTERNC char *Vsh_readline(char *prompt, char *buf, int buflen, FILE *stream);
00288 VEXTERNC int Vsh_input(char *buf, int buflen);
00289 VEXTERNC void Vsh_execCmd(const char *PR, int argc, char **argv, char *inbuf);
00290 
00291 /* Vpars and lex/yacc support */
00292 VEXTERNC void Vsh_parse(void);
00293 VEXTERNC void Vsh_parseHandoff(char *buf);
00294 VEXTERNC void Vsh_execute(void);
00295 VEXTERNC void Vsh_yyexecute(COMMAND *cmd);
00296 
00297 #endif /* _VSH_P_H_ */
00298 

Generated on Wed Oct 20 2010 11:12:15 for APBS by  doxygen 1.7.2