Changeset 6ea9a1d in mainline
- Timestamp:
- 2011-06-11T22:32:24Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36ab7c7
- Parents:
- ae45201
- Location:
- uspace/app/bdsh
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/builtin_cmds.c
rae45201 r6ea9a1d 38 38 #include "cmds.h" 39 39 #include "builtin_aliases.h" 40 #include "scli.h" 40 41 41 42 extern volatile unsigned int cli_interactive; … … 101 102 } 102 103 103 int run_builtin(int builtin, char *argv[], cliuser_t *usr )104 int run_builtin(int builtin, char *argv[], cliuser_t *usr, iostate_t *new_iostate) 104 105 { 106 int rc; 105 107 builtin_t *cmd = builtins; 106 108 107 109 cmd += builtin; 110 111 iostate_t *old_iostate = get_iostate(); 112 set_iostate(new_iostate); 113 114 if (NULL != cmd->entry) { 115 rc = ((int)cmd->entry(argv, usr)); 116 } 117 else { 118 rc = CL_ENOENT; 119 } 120 121 set_iostate(old_iostate); 108 122 109 if (NULL != cmd->entry) 110 return((int)cmd->entry(argv, usr)); 111 112 return CL_ENOENT; 123 return rc; 113 124 } -
uspace/app/bdsh/cmds/cmds.h
rae45201 r6ea9a1d 59 59 extern char *alias_for_module(const char *); 60 60 extern int help_module(int, unsigned int); 61 extern int run_module(int, char *[] );61 extern int run_module(int, char *[], iostate_t *); 62 62 63 63 /* Prototypes for builtin launchers */ … … 67 67 extern char *alias_for_builtin(const char *); 68 68 extern int help_builtin(int, unsigned int); 69 extern int run_builtin(int, char *[], cliuser_t * );69 extern int run_builtin(int, char *[], cliuser_t *, iostate_t *); 70 70 71 71 #endif -
uspace/app/bdsh/cmds/mod_cmds.c
rae45201 r6ea9a1d 124 124 /* Invokes the module entry point modules[module], passing argv[] as an argument 125 125 * stack. */ 126 int run_module(int module, char *argv[] )126 int run_module(int module, char *argv[], iostate_t *new_iostate) 127 127 { 128 int rc; 128 129 module_t *mod = modules; 129 130 130 131 mod += module; 132 133 iostate_t *old_iostate = get_iostate(); 134 set_iostate(new_iostate); 131 135 132 if (NULL != mod->entry) 133 return ((int)mod->entry(argv)); 136 if (NULL != mod->entry) { 137 rc = ((int)mod->entry(argv)); 138 } 139 else { 140 rc = CL_ENOENT; 141 } 142 143 set_iostate(old_iostate); 134 144 135 return CL_ENOENT;145 return rc; 136 146 } -
uspace/app/bdsh/errors.c
rae45201 r6ea9a1d 38 38 #include "errors.h" 39 39 #include "errstr.h" 40 #include "scli.h" 40 41 41 42 volatile int cli_errno = CL_EOK; -
uspace/app/bdsh/exec.c
rae45201 r6ea9a1d 112 112 } 113 113 114 unsigned int try_exec(char *cmd, char **argv, FILE **files)114 unsigned int try_exec(char *cmd, char **argv, iostate_t *io) 115 115 { 116 116 task_id_t tid; … … 120 120 fdi_node_t file_nodes[3]; 121 121 fdi_node_t *file_nodes_p[4]; 122 FILE *files[3]; 122 123 123 124 tmp = str_dup(find_command(cmd)); 124 125 free(found); 126 127 files[0] = io->stdin; 128 files[1] = io->stdout; 129 files[2] = io->stderr; 125 130 126 131 for (i = 0; i < 3 && files[i] != NULL; i++) { -
uspace/app/bdsh/exec.h
rae45201 r6ea9a1d 3 3 4 4 #include <task.h> 5 #include "scli.h" 5 6 6 extern unsigned int try_exec(char *, char **, FILE **);7 extern unsigned int try_exec(char *, char **, iostate_t *); 7 8 8 9 #endif -
uspace/app/bdsh/input.c
rae45201 r6ea9a1d 58 58 59 59 /* Private helpers */ 60 static int run_command(char **, cliuser_t *, FILE **);60 static int run_command(char **, cliuser_t *, iostate_t *); 61 61 static void print_pipe_usage(void); 62 62 … … 140 140 } 141 141 142 FILE *files[4]; 143 files[0] = stdin; 144 files[1] = stdout; 145 files[2] = stderr; 146 files[3] = 0; 142 iostate_t new_iostate = { 143 .stdin = stdin, 144 .stdout = stdout, 145 .stderr = stderr 146 }; 147 148 FILE *from = NULL; 149 FILE *to = NULL; 147 150 148 151 if (redir_from) { 149 FILE *from = fopen(redir_from, "r");152 from = fopen(redir_from, "r"); 150 153 if (from == NULL) { 151 154 printf("Cannot open file %s\n", redir_from); 152 155 rc = errno; 153 goto finit ;156 goto finit_with_files; 154 157 } 155 files[0] = from; 156 } 158 new_iostate.stdin = from; 159 } 160 157 161 158 162 if (redir_to) { 159 FILE *to = fopen(redir_to, "w");163 to = fopen(redir_to, "w"); 160 164 if (to == NULL) { 161 165 printf("Cannot open file %s\n", redir_to); 162 166 rc = errno; 163 goto finit ;167 goto finit_with_files; 164 168 } 165 files[1] = to; 166 } 167 168 rc = run_command(cmd, usr, files); 169 new_iostate.stdout = to; 170 } 171 172 rc = run_command(cmd, usr, &new_iostate); 173 174 finit_with_files: 175 if (from != NULL) { 176 fclose(from); 177 } 178 if (to != NULL) { 179 fclose(to); 180 } 169 181 170 182 finit: … … 188 200 } 189 201 190 int run_command(char **cmd, cliuser_t *usr, FILE *files[])202 int run_command(char **cmd, cliuser_t *usr, iostate_t *new_iostate) 191 203 { 192 204 int id = 0; … … 199 211 /* Is it a builtin command ? */ 200 212 if ((id = (is_builtin(cmd[0]))) > -1) { 201 return run_builtin(id, cmd, usr );213 return run_builtin(id, cmd, usr, new_iostate); 202 214 } 203 215 204 216 /* Is it a module ? */ 205 217 if ((id = (is_module(cmd[0]))) > -1) { 206 return run_module(id, cmd );218 return run_module(id, cmd, new_iostate); 207 219 } 208 220 209 221 /* See what try_exec thinks of it */ 210 return try_exec(cmd[0], cmd, files);222 return try_exec(cmd[0], cmd, new_iostate); 211 223 } 212 224 -
uspace/app/bdsh/scli.c
rae45201 r6ea9a1d 42 42 /* See scli.h */ 43 43 static cliuser_t usr; 44 static iostate_t *iostate; 45 static iostate_t stdiostate; 44 46 45 47 /* Globals that are modified during start-up that modules/builtins … … 82 84 } 83 85 86 iostate_t *get_iostate(void) 87 { 88 return iostate; 89 } 90 91 92 void set_iostate(iostate_t *ios) 93 { 94 iostate = ios; 95 stdin = ios->stdin; 96 stdout = ios->stdout; 97 stderr = ios->stderr; 98 } 99 84 100 int main(int argc, char *argv[]) 85 101 { 86 102 int ret = 0; 103 104 stdiostate.stdin = stdin; 105 stdiostate.stdout = stdout; 106 stdiostate.stderr = stderr; 107 iostate = &stdiostate; 87 108 88 109 if (cli_init(&usr)) -
uspace/app/bdsh/scli.h
rae45201 r6ea9a1d 13 13 } cliuser_t; 14 14 15 typedef struct { 16 FILE *stdin; 17 FILE *stdout; 18 FILE *stderr; 19 } iostate_t; 20 15 21 extern const char *progname; 16 22 23 extern iostate_t *get_iostate(void); 24 extern void set_iostate(iostate_t *); 25 17 26 #endif
Note:
See TracChangeset
for help on using the changeset viewer.