00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00089
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
00097
00098
00099
00100 typedef struct g_list {
00101 struct g_list *next;
00102 } GENERIC_LIST;
00103
00104
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
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
00120 typedef struct word_desc {
00121 char *word;
00122 int dollar_present;
00123 int quoted;
00124
00125 int assignment;
00126
00127 } WORD_DESC;
00128
00129
00130 typedef struct word_list {
00131 struct word_list *next;
00132 WORD_DESC *word;
00133 } WORD_LIST;
00134
00135
00136
00137
00138
00139
00140 typedef union {
00141 long dest;
00142 WORD_DESC *filename;
00143 } REDIRECTEE;
00144
00145 typedef struct redirect {
00146 struct redirect *next;
00147 int redirector;
00148 int flags;
00149 enum r_instruction instruction;
00150 REDIRECTEE redirectee;
00151 char *here_doc_eof;
00152 } REDIRECT;
00153
00154
00155
00156 typedef struct element {
00157 WORD_DESC *word;
00158 REDIRECT *redirect;
00159 } ELEMENT;
00160
00161
00162 #define CMD_WANT_SUBSHELL 0x01
00163 #define CMD_FORCE_SUBSHELL 0x02
00164 #define CMD_INVERT_RETURN 0x04
00165 #define CMD_IGNORE_RETURN 0x08
00166 #define CMD_NO_FUNCTIONS 0x10
00167 #define CMD_INHIBIT_EXPANSION 0x20
00168 #define CMD_NO_FORK 0x40
00169
00170
00171 typedef struct command {
00172 enum command_type type;
00173 int flags;
00174 int line;
00175 REDIRECT *redirects;
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
00189 typedef struct connection {
00190 int ignore;
00191 COMMAND *first;
00192 COMMAND *second;
00193 int connector;
00194 } CONNECTION;
00195
00196
00197
00198
00199 typedef struct pattern_list {
00200 struct pattern_list *next;
00201 WORD_LIST *patterns;
00202 COMMAND *action;
00203 } PATTERN_LIST;
00204
00205
00206 typedef struct case_com {
00207 int flags;
00208 WORD_DESC *word;
00209 PATTERN_LIST *clauses;
00210 } CASE_COM;
00211
00212
00213 typedef struct for_com {
00214 int flags;
00215 WORD_DESC *name;
00216 WORD_LIST *map_list;
00217 COMMAND *action;
00218
00219
00220 } FOR_COM;
00221
00222
00223 typedef struct if_com {
00224 int flags;
00225 COMMAND *test;
00226 COMMAND *true_case;
00227 COMMAND *false_case;
00228 } IF_COM;
00229
00230
00231 typedef struct while_com {
00232 int flags;
00233 COMMAND *test;
00234 COMMAND *action;
00235 } WHILE_COM;
00236
00237
00238 typedef struct simple_com {
00239 int flags;
00240 WORD_LIST *words;
00241
00242 REDIRECT *redirects;
00243 int line;
00244 } SIMPLE_COM;
00245
00246
00247
00248
00249
00250
00251 typedef struct function_def {
00252 int ignore;
00253 WORD_DESC *name;
00254 COMMAND *command;
00255 } FUNCTION_DEF;
00256
00257
00258
00259 typedef struct group_com {
00260 int ignore;
00261 COMMAND *command;
00262 } GROUP_COM;
00263
00264
00265
00266
00267 VEXTERNC int cmdKey;
00268 VEXTERNC Vsh *Vsh_thee;
00269 VEXTERNC COMMAND *global_command;
00270
00271
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
00280 VEXTERNC int Vsh_builtIn(Vsh *thee, int argc, char **argv);
00281 VEXTERNC int Vsh_isInteractive(Vsh *thee);
00282
00283
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
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
00298