nfs-ganesha 1.4
|
00001 00035 #ifndef _SHELL_H 00036 #define _SHELL_H 00037 00038 #include "shell_types.h" 00039 00040 #define MAX_LINE_LEN 1024 00041 #define MAX_ARGS 256 00042 00043 /*------------------------------------------------------------------ 00044 * Internal error codes. 00045 *-----------------------------------------------------------------*/ 00046 00047 #define SHELL_SUCCESS 0 00048 #define SHELL_ERROR -1 00049 #define SHELL_NOT_FOUND -2 00050 #define SHELL_SYNTAX_ERROR -22 00051 00052 /*------------------------------------------------------------------ 00053 * Main shell routines. 00054 *-----------------------------------------------------------------*/ 00055 00061 int shell_Init(int verbose, char *input_file, char *prompt, int shell_index); 00062 00066 int shell_Launch(); 00067 00072 int shell_BarrierInit(int nb_threads); 00073 00074 /*------------------------------------------------------------------ 00075 * Parsing and execution routines. 00076 *-----------------------------------------------------------------*/ 00077 00089 int shell_ParseLine(char *in_out_line, char **out_arglist, int *p_argcount); 00090 00102 void shell_CleanArgs(int argc, char **in_out_argv, int *in_allocated); 00103 00115 int shell_SolveArgs(int argc, char **in_out_argv, int *out_allocated); 00116 00127 int shell_Execute(int argc, char **argv, FILE * output); 00128 00129 /*------------------------------------------------------------------ 00130 * Shell ouput routines. 00131 *-----------------------------------------------------------------*/ 00132 00137 void shell_PrintError(shell_state_t * context, char *error_msg); 00138 00143 void shell_PrintTrace(shell_state_t * context, char *msg); 00144 00145 /*------------------------------------------------------------------ 00146 * Shell state management routines. 00147 *-----------------------------------------------------------------*/ 00148 00151 extern char *shell_special_vars[]; 00152 00159 int shell_SetLayer(shell_state_t * context, char *layer_name); 00160 00165 layer_def_t *shell_GetLayer(shell_state_t * context); 00166 00171 int shell_SetStatus(shell_state_t * context, int returned_status); 00172 00177 int shell_GetStatus(shell_state_t * context); 00178 00183 int shell_SetVerbose(shell_state_t * context, char *str_verbose); 00184 00189 int shell_GetVerbose(shell_state_t * context); 00190 00195 int shell_SetDbgLvl(shell_state_t * context, char *str_debug_level); 00196 00201 int shell_GetDbgLvl(shell_state_t * context); 00202 00207 FILE *shell_GetInputStream(shell_state_t * context); 00208 00217 int shell_SetInput(shell_state_t * context, char *file_name); 00218 00223 int shell_SetPrompt(shell_state_t * context, char *str_prompt); 00224 00229 char *shell_GetPrompt(shell_state_t * context); 00230 00235 int shell_SetShellId(shell_state_t * context, int shell_index); 00236 00241 int shell_SetLine(shell_state_t * context, int lineno); 00242 00247 int shell_GetLine(shell_state_t * context); 00248 00249 /*------------------------------------------------------------------ 00250 * Shell commands. 00251 *-----------------------------------------------------------------*/ 00252 00253 int shellcmd_help(int argc, /* IN : number of args in argv */ 00254 char **argv, /* IN : arg list */ 00255 FILE * output /* IN : output stream */ 00256 ); 00257 00258 int shellcmd_if(int argc, /* IN : number of args in argv */ 00259 char **argv, /* IN : arg list */ 00260 FILE * output /* IN : output stream */ 00261 ); 00262 00263 int shellcmd_interactive(int argc, /* IN : number of args in argv */ 00264 char **argv, /* IN : arg list */ 00265 FILE * output /* IN : output stream */ 00266 ); 00267 00268 int shellcmd_set(int argc, /* IN : number of args in argv */ 00269 char **argv, /* IN : arg list */ 00270 FILE * output /* IN : output stream */ 00271 ); 00272 00273 int shellcmd_unset(int argc, /* IN : number of args in argv */ 00274 char **argv, /* IN : arg list */ 00275 FILE * output /* IN : output stream */ 00276 ); 00277 00278 int shellcmd_print(int argc, /* IN : number of args in argv */ 00279 char **argv, /* IN : arg list */ 00280 FILE * output /* IN : output stream */ 00281 ); 00282 00283 int shellcmd_varlist(int argc, /* IN : number of args in argv */ 00284 char **argv, /* IN : arg list */ 00285 FILE * output /* IN : output stream */ 00286 ); 00287 00288 int shellcmd_time(int argc, /* IN : number of args in argv */ 00289 char **argv, /* IN : arg list */ 00290 FILE * output /* IN : output stream */ 00291 ); 00292 00293 int shellcmd_quit(int argc, /* IN : number of args in argv */ 00294 char **argv, /* IN : arg list */ 00295 FILE * output /* IN : output stream */ 00296 ); 00297 00298 int shellcmd_barrier(int argc, /* IN : number of args in argv */ 00299 char **argv, /* IN : arg list */ 00300 FILE * output /* IN : output stream */ 00301 ); 00302 00305 static command_def_t __attribute__ ((__unused__)) shell_commands[] = 00306 { 00307 00308 { 00309 "barrier", shellcmd_barrier, "synchronization in a multi-thread shell"}, 00310 { 00311 "echo", shellcmd_print, "print one or more arguments"}, 00312 { 00313 "exit", shellcmd_quit, "exit this shell"}, 00314 { 00315 "help", shellcmd_help, "print this help"}, 00316 { 00317 "if", shellcmd_if, "conditionnal execution"}, 00318 { 00319 "interactive", shellcmd_interactive, "close script file and start interactive mode"}, 00320 { 00321 "print", shellcmd_print, "print one or more arguments"}, 00322 { 00323 "quit", shellcmd_quit, "exit this shell"}, 00324 { 00325 "set", shellcmd_set, "set the value of a shell variable"}, 00326 { 00327 "time", shellcmd_time, "measures the time for executing a command"}, 00328 { 00329 "unset", shellcmd_unset, "free a shell variable"}, 00330 { 00331 "varlist", shellcmd_varlist, "print the list of shell variables"}, 00332 { 00333 NULL, NULL, NULL} /* End of command list */ 00334 }; 00335 00336 /* @todo: if, source */ 00337 00338 #endif