Changeset 81bc309 in mainline
- Timestamp:
- 2011-08-20T17:03:29Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c8f70eb
- Parents:
- c916dfc
- Location:
- uspace/app/bdsh
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/Makefile
rc916dfc r81bc309 50 50 cmds/modules/unmount/unmount.c \ 51 51 cmds/modules/kcon/kcon.c \ 52 cmds/builtins/batch/batch.c \ 52 53 cmds/builtins/exit/exit.c \ 53 54 cmds/builtins/cd/cd.c \ -
uspace/app/bdsh/cmds/builtins/builtins.h
rc916dfc r81bc309 4 4 #include "config.h" 5 5 6 #include "batch/entry.h" 6 7 #include "cd/entry.h" 7 8 #include "exit/entry.h" 8 9 9 10 builtin_t builtins[] = { 11 #include "batch/batch_def.h" 10 12 #include "cd/cd_def.h" 11 13 #include "exit/exit_def.h" -
uspace/app/bdsh/cmds/modules/help/help.c
rc916dfc r81bc309 43 43 extern const char *progname; 44 44 45 #define HELP_IS_BATCH 346 45 #define HELP_IS_COMMANDS 2 47 46 #define HELP_IS_MODULE 1 … … 55 54 { 56 55 int rc = HELP_IS_RUBBISH; 57 58 if (str_cmp(cmd, "batch") == 0)59 return HELP_IS_BATCH;60 56 61 57 if (str_cmp(cmd, "commands") == 0) … … 96 92 } 97 93 98 static void help_batch(unsigned int level)99 {100 if (level == HELP_SHORT) {101 printf(102 "\n batch [filename]\n"103 " Issues commands stored in the file.\n"104 " Each command must correspond to the single line in the file.\n\n");105 } else {106 printf(107 "\n `batch' - issues a batch of commands\n"108 " Issues commands stored in the file. Each command must correspond\n"109 " to the single line in the file. Empty lines can be used to visually\n"110 " separate groups of commands. There is no support for comments,\n"111 " variables, recursion or other programming constructs - the `batch'\n"112 " command is indeed very trivial.\n\n");113 }114 115 return;116 }117 118 94 static void help_commands(void) 119 95 { … … 145 121 } 146 122 147 printf(" %-16s\t%s\n", "batch", "Issue batch of commands");148 123 printf("\n Try %s %s for more information on how `%s' works.\n\n", 149 124 cmdname, cmdname, cmdname); … … 207 182 help_commands(); 208 183 return CMD_SUCCESS; 209 case HELP_IS_BATCH:210 help_batch(level);211 return CMD_SUCCESS;212 184 case HELP_IS_MODULE: 213 185 help_module(mod_switch, level); -
uspace/app/bdsh/input.c
rc916dfc r81bc309 193 193 } 194 194 195 if (str_cmp(cmd[0], "batch") == 0 && cmd[1] != NULL) { 196 FILE *batch = fopen(cmd[1], "r"); 197 if (batch == NULL) { 198 printf("Cannot open file %s\n", cmd[1]); 199 rc = errno; 200 } else { 201 cliuser_t fusr; 202 fusr.name = usr->name; 203 fusr.cwd = usr->cwd; 204 fusr.prompt = usr->prompt; 205 fusr.line = malloc(INPUT_MAX + 1); 206 char *cur = fusr.line; 207 char *end = fusr.line + INPUT_MAX; 208 int c = fgetc(batch); 209 while (fusr.line != NULL) { 210 if (c == '\n' || c == EOF || cur == end) { 211 *cur = '\0'; 212 if (cur == fusr.line) { 213 /* skip empty line */ 214 rc = 0; 215 free(cur); 216 } else { 217 printf(">%s\n", fusr.line); 218 rc = process_input(&fusr); 219 /* fusr->line was freed by process_input() */ 220 } 221 if (rc == 0 && c != EOF) { 222 fusr.line = malloc(INPUT_MAX + 1); 223 cur = fusr.line; 224 end = fusr.line + INPUT_MAX; 225 } else { 226 break; 227 } 228 } else { 229 *cur++ = c; 230 } 231 c = fgetc(batch); 232 } 233 fclose(batch); 234 } 235 } else { 236 rc = run_command(cmd, usr, &new_iostate); 237 } 195 rc = run_command(cmd, usr, &new_iostate); 238 196 239 197 finit_with_files:
Note:
See TracChangeset
for help on using the changeset viewer.