Changeset 1433ecda in mainline for uspace/app/bdsh/cmds
- Timestamp:
- 2018-04-04T15:42:37Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2c4e1cc
- Parents:
- 47b2d7e3
- Location:
- uspace/app/bdsh/cmds
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/builtin_cmds.c
r47b2d7e3 r1433ecda 64 64 return -1; 65 65 66 for (i=0; builtin_aliases[i] != NULL; i+=2) {66 for (i = 0; builtin_aliases[i] != NULL; i += 2) { 67 67 if (!str_cmp(builtin_aliases[i], command)) 68 68 return 1; … … 79 79 return (char *)NULL; 80 80 81 for (i=0; builtin_aliases[i] != NULL; i+=2) {81 for (i = 0; builtin_aliases[i] != NULL; i += 2) { 82 82 if (!str_cmp(builtin_aliases[i], command)) 83 return (char *)builtin_aliases[i +1];83 return (char *)builtin_aliases[i + 1]; 84 84 } 85 85 -
uspace/app/bdsh/cmds/builtins/batch/batch.c
r47b2d7e3 r1433ecda 48 48 if (level == HELP_SHORT) { 49 49 printf( 50 "\n batch [filename] [-c]\n"51 " Issues commands stored in the file.\n"52 " Each command must correspond to the single line in the file.\n\n");50 "\n batch [filename] [-c]\n" 51 " Issues commands stored in the file.\n" 52 " Each command must correspond to the single line in the file.\n\n"); 53 53 } else { 54 54 printf( 55 "\n `batch' - issues a batch of commands\n"56 " Issues commands stored in the file. Each command must correspond\n"57 " to the single line in the file. Empty lines can be used to visually\n"58 " separate groups of commands. There is no support for comments,\n"59 " variables, recursion or other programming constructs - the `batch'\n"60 " command is indeed very trivial.\n"61 " If the filename is followed by -c, execution continues even if some\n"62 " of the commands failed.\n\n");55 "\n `batch' - issues a batch of commands\n" 56 " Issues commands stored in the file. Each command must correspond\n" 57 " to the single line in the file. Empty lines can be used to visually\n" 58 " separate groups of commands. There is no support for comments,\n" 59 " variables, recursion or other programming constructs - the `batch'\n" 60 " command is indeed very trivial.\n" 61 " If the filename is followed by -c, execution continues even if some\n" 62 " of the commands failed.\n\n"); 63 63 } 64 64 -
uspace/app/bdsh/cmds/builtins/builtins.h
r47b2d7e3 r1433ecda 12 12 #include "cd/cd_def.inc" 13 13 #include "exit/exit_def.inc" 14 { NULL, NULL, NULL, NULL, 0}14 { NULL, NULL, NULL, NULL, 0 } 15 15 }; 16 16 -
uspace/app/bdsh/cmds/builtins/cd/cd.c
r47b2d7e3 r1433ecda 72 72 } else { 73 73 printf( 74 " %s <directory>\n"75 " Change directory to <directory>, e.g `%s /sbin'\n",76 74 " %s <directory>\n" 75 " Change directory to <directory>, e.g `%s /sbin'\n", 76 cmdname, cmdname); 77 77 } 78 78 … … 113 113 if (argc < 2) { 114 114 printf("%s - no directory specified. Try `help %s extended'\n", 115 115 cmdname, cmdname); 116 116 return CMD_FAILURE; 117 117 } -
uspace/app/bdsh/cmds/cmds.h
r47b2d7e3 r1433ecda 52 52 53 53 /* Types for module command entry and help */ 54 typedef int (* 55 typedef void (* 54 typedef int (*mod_entry_t)(char **); 55 typedef void (*mod_help_t)(unsigned int); 56 56 57 57 /* Built-in commands need to be able to modify cliuser_t */ 58 typedef int (* 59 typedef void (* 58 typedef int (*builtin_entry_t)(char **, cliuser_t *); 59 typedef void (*builtin_help_t)(unsigned int); 60 60 61 61 /* Module structure */ -
uspace/app/bdsh/cmds/mod_cmds.c
r47b2d7e3 r1433ecda 80 80 return -1; 81 81 82 for (i=0; mod_aliases[i] != NULL; i+=2) {82 for (i = 0; mod_aliases[i] != NULL; i += 2) { 83 83 if (!str_cmp(mod_aliases[i], command)) 84 84 return 1; … … 96 96 return (char *)NULL; 97 97 98 for (i=0; mod_aliases[i] != NULL; i+=2) {98 for (i = 0; mod_aliases[i] != NULL; i += 2) { 99 99 if (!str_cmp(mod_aliases[i], command)) 100 return (char *)mod_aliases[i +1];100 return (char *)mod_aliases[i + 1]; 101 101 } 102 102 -
uspace/app/bdsh/cmds/modules/cat/cat.c
r47b2d7e3 r1433ecda 88 88 help_cmd_cat(HELP_SHORT); 89 89 printf( 90 "Usage: %s [options] <file1> [file2] [...]\n"91 "Options:\n"92 " -h, --help A short option summary\n"93 " -v, --version Print version information and exit\n"94 " -H, --head ## Print only the first ## bytes\n"95 " -t, --tail ## Print only the last ## bytes\n"96 " -b, --buffer ## Set the read buffer size to ##\n"97 " -m, --more Pause after each screen full\n"98 " -x, --hex Print bytes as hex values\n"99 " -s, --stdin Treat `-' in file list as standard input\n"100 " -n, --number Number all output lines\n"101 "Currently, %s is under development, some options don't work.\n",102 cmdname, cmdname);90 "Usage: %s [options] <file1> [file2] [...]\n" 91 "Options:\n" 92 " -h, --help A short option summary\n" 93 " -v, --version Print version information and exit\n" 94 " -H, --head ## Print only the first ## bytes\n" 95 " -t, --tail ## Print only the last ## bytes\n" 96 " -b, --buffer ## Set the read buffer size to ##\n" 97 " -m, --more Pause after each screen full\n" 98 " -x, --hex Print bytes as hex values\n" 99 " -s, --stdin Treat `-' in file list as standard input\n" 100 " -n, --number Number all output lines\n" 101 "Currently, %s is under development, some options don't work.\n", 102 cmdname, cmdname); 103 103 } 104 104 … … 108 108 static void waitprompt(void) 109 109 { 110 console_set_pos(console, 0, console_rows -1);110 console_set_pos(console, 0, console_rows - 1); 111 111 console_set_color(console, COLOR_WHITE, COLOR_BLUE, 0); 112 112 113 113 printf("ENTER/SPACE/PAGE DOWN - next page, " 114 114 "ESC/Q - quit, C - continue unpaged"); 115 115 fflush(stdout); 116 116 … … 265 265 for (i = 0; i < bytes && !should_quit; i++) { 266 266 if (hex) { 267 paged_char(hexchars[((uint8_t)buff[i])/16]); 268 paged_char(hexchars[((uint8_t)buff[i])%16]); 269 paged_char(((count+i+1) & 0xf) == 0 ? '\n' : ' '); 270 } 271 else { 267 paged_char(hexchars[((uint8_t)buff[i]) / 16]); 268 paged_char(hexchars[((uint8_t)buff[i]) % 16]); 269 paged_char(((count + i + 1) & 0xf) == 0 ? '\n' : ' '); 270 } else { 272 271 wchar_t c = str_decode(buff, &offset, bytes); 273 272 if (c == 0) { … … 353 352 return CMD_SUCCESS; 354 353 case 'H': 355 if (!optarg || str_uint64_t(optarg, NULL, 10, false, &head) != EOK 354 if (!optarg || str_uint64_t(optarg, NULL, 10, false, &head) != EOK) { 356 355 puts("Invalid head size\n"); 357 356 return CMD_FAILURE; … … 359 358 break; 360 359 case 't': 361 if (!optarg || str_uint64_t(optarg, NULL, 10, false, &tail) != EOK 360 if (!optarg || str_uint64_t(optarg, NULL, 10, false, &tail) != EOK) { 362 361 puts("Invalid tail size\n"); 363 362 return CMD_FAILURE; … … 367 366 break; 368 367 case 'b': 369 if (!optarg || str_size_t(optarg, NULL, 10, false, &buffer) != EOK 368 if (!optarg || str_size_t(optarg, NULL, 10, false, &buffer) != EOK) { 370 369 puts("Invalid buffer size\n"); 371 370 return CMD_FAILURE; … … 391 390 if (argc < 1) { 392 391 printf("%s - incorrect number of arguments. Try `%s --help'\n", 393 392 cmdname, cmdname); 394 393 return CMD_FAILURE; 395 394 } -
uspace/app/bdsh/cmds/modules/cp/cp.c
r47b2d7e3 r1433ecda 53 53 { "buffer", required_argument, 0, 'b' }, 54 54 { "force", no_argument, 0, 'f' }, 55 { "interactive", no_argument, 0, 'i' },55 { "interactive", no_argument, 0, 'i' }, 56 56 { "recursive", no_argument, 0, 'r' }, 57 57 { "help", no_argument, 0, 'h' }, … … 160 160 } 161 161 162 switch (ev.ev.key.key) {162 switch (ev.ev.key.key) { 163 163 case KC_Y: 164 164 printf("y\n"); … … 384 384 385 385 static int copy_file(const char *src, const char *dest, 386 386 size_t blen, int vb) 387 387 { 388 388 int fd1, fd2; -
uspace/app/bdsh/cmds/modules/echo/echo.c
r47b2d7e3 r1433ecda 57 57 unsigned int argc; 58 58 59 for (argc = 1; argv[argc] != NULL; argc 59 for (argc = 1; argv[argc] != NULL; argc++) { 60 60 printf("%s ", argv[argc]); 61 61 } -
uspace/app/bdsh/cmds/modules/help/help.c
r47b2d7e3 r1433ecda 79 79 if (level == HELP_SHORT) { 80 80 printf( 81 "\n %s [command] <extended>\n"82 " Use help [command] extended for detailed help on [command] "83 ", even `help'\n\n", cmdname);81 "\n %s [command] <extended>\n" 82 " Use help [command] extended for detailed help on [command] " 83 ", even `help'\n\n", cmdname); 84 84 } else { 85 85 printf( 86 "\n `%s' - shows help for commands\n"87 " Examples:\n"88 " %s [command] Show help for [command]\n"89 " %s [command] extended Show extended help for [command]\n"90 "\n If no argument is given to %s, a list of commands are shown\n\n",91 cmdname, cmdname, cmdname, cmdname);86 "\n `%s' - shows help for commands\n" 87 " Examples:\n" 88 " %s [command] Show help for [command]\n" 89 " %s [command] extended Show extended help for [command]\n" 90 "\n If no argument is given to %s, a list of commands are shown\n\n", 91 cmdname, cmdname, cmdname, cmdname); 92 92 } 93 93 … … 105 105 /* First, show a list of built in commands that are available in this mode */ 106 106 for (cmd = builtins; cmd->name != NULL; cmd++) { 107 108 109 110 111 107 if (is_builtin_alias(cmd->name)) 108 printf(" %-16s\tAlias for `%s'\n", cmd->name, 109 alias_for_builtin(cmd->name)); 110 else 111 printf(" %-16s\t%s\n", cmd->name, cmd->desc); 112 112 } 113 113 114 114 /* Now, show a list of module commands that are available in this mode */ 115 115 for (mod = modules; mod->name != NULL; mod++) { 116 117 118 119 120 116 if (is_module_alias(mod->name)) 117 printf(" %-16s\tAlias for `%s'\n", mod->name, 118 alias_for_module(mod->name)); 119 else 120 printf(" %-16s\t%s\n", mod->name, mod->desc); 121 121 } 122 122 123 123 printf("\n Try %s %s for more information on how `%s' works.\n\n", 124 124 cmdname, cmdname, cmdname); 125 125 } 126 126 -
uspace/app/bdsh/cmds/modules/ls/ls.c
r47b2d7e3 r1433ecda 216 216 217 217 out: 218 for (i = 0; i < nbdirs; i++)218 for (i = 0; i < nbdirs; i++) 219 219 free(tosort[i].name); 220 220 free(tosort); … … 240 240 struct dir_elem_t *dir_list; 241 241 242 const char * 242 const char *const trailing_slash = "/"; 243 243 244 244 nbdirs = 0; … … 264 264 if (str_size(subdir_path) + str_size(path) + 1 <= PATH_MAX) 265 265 str_append(subdir_path, PATH_MAX, path); 266 if (path[str_size(path) -1] != '/' &&266 if (path[str_size(path) - 1] != '/' && 267 267 str_size(subdir_path) + str_size(trailing_slash) + 1 <= PATH_MAX) 268 268 str_append(subdir_path, PATH_MAX, trailing_slash); … … 328 328 help_cmd_ls(HELP_SHORT); 329 329 printf( 330 "Usage: %s [options] [path]\n"331 "If not path is given, the current working directory is used.\n"332 "Options:\n"333 " -h, --help A short option summary\n"334 " -u, --unsort Do not sort directory entries\n"335 " -r, --recursive List subdirectories recursively\n",336 cmdname);330 "Usage: %s [options] [path]\n" 331 "If not path is given, the current working directory is used.\n" 332 "Options:\n" 333 " -h, --help A short option summary\n" 334 " -u, --unsort Do not sort directory entries\n" 335 " -r, --recursive List subdirectories recursively\n", 336 cmdname); 337 337 } 338 338 -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
r47b2d7e3 r1433ecda 53 53 54 54 static struct option const long_options[] = { 55 { "size", required_argument, 0, 's'},56 { "sparse", no_argument, 0, 'p'},57 { "help", no_argument, 0, 'h'},58 { 0, 0, 0, 0}55 { "size", required_argument, 0, 's' }, 56 { "sparse", no_argument, 0, 'p' }, 57 { "help", no_argument, 0, 'h' }, 58 { 0, 0, 0, 0 } 59 59 }; 60 60 … … 66 66 help_cmd_mkfile(HELP_SHORT); 67 67 printf( 68 "Usage: %s [options] <path>\n"69 "Options:\n"70 " -h, --help A short option summary\n"71 " -s, --size sz Size of the file\n"72 " -p, --sparse Create a sparse file\n"73 "\n"74 "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n"75 "E.g. 100k, 2m, 1g.\n",76 cmdname);68 "Usage: %s [options] <path>\n" 69 "Options:\n" 70 " -h, --help A short option summary\n" 71 " -s, --size sz Size of the file\n" 72 " -p, --sparse Create a sparse file\n" 73 "\n" 74 "Size is a number followed by 'k', 'm' or 'g' for kB, MB, GB.\n" 75 "E.g. 100k, 2m, 1g.\n", 76 cmdname); 77 77 } 78 78 … … 101 101 102 102 if (ep[1] != '\0') 103 103 return EINVAL; 104 104 105 105 switch (tolower(ep[0])) { 106 case 'k': unit = 1024; break; 107 case 'm': unit = 1024*1024; break; 108 case 'g': unit = 1024*1024*1024; break; 109 default: return EINVAL; 106 case 'k': 107 unit = 1024; 108 break; 109 case 'm': 110 unit = 1024 * 1024; 111 break; 112 case 'g': 113 unit = 1024 * 1024 * 1024; 114 break; 115 default: 116 return EINVAL; 110 117 } 111 118 … … 162 169 if (argc != 1) { 163 170 printf("%s: incorrect number of arguments. Try `%s --help'\n", 164 171 cmdname, cmdname); 165 172 return CMD_FAILURE; 166 173 } -
uspace/app/bdsh/cmds/modules/modules.h
r47b2d7e3 r1433ecda 87 87 #include "cmp/cmp_def.inc" 88 88 89 { NULL, NULL, NULL, NULL}89 { NULL, NULL, NULL, NULL } 90 90 }; 91 91 -
uspace/app/bdsh/cmds/modules/printf/printf.c
r47b2d7e3 r1433ecda 69 69 * @param arg string with data to print. 70 70 */ 71 static int print_arg(wchar_t ch, const char *arg)71 static int print_arg(wchar_t ch, const char *arg) 72 72 { 73 switch (ch) {73 switch (ch) { 74 74 case 'd': 75 75 printf("%d", (int)(strtol(arg, NULL, 10))); … … 96 96 static int process_ctl(wchar_t ch) 97 97 { 98 switch (ch) {98 switch (ch) { 99 99 case 'n': 100 100 printf("\n"); … … 120 120 { 121 121 unsigned int argc; 122 char *fmt;122 char *fmt; 123 123 size_t pos, fmt_sz; 124 124 wchar_t ch; … … 142 142 143 143 while ((ch = str_decode(fmt, &pos, fmt_sz))) { 144 switch (ch) {144 switch (ch) { 145 145 146 146 case '\\': -
uspace/app/bdsh/cmds/modules/pwd/pwd.c
r47b2d7e3 r1433ecda 61 61 if (vfs_cwd_get(buff, PATH_MAX) != EOK) { 62 62 cli_error(CL_EFAIL, 63 63 "Unable to determine the current working directory"); 64 64 free(buff); 65 65 return CMD_FAILURE; -
uspace/app/bdsh/cmds/modules/rm/rm.c
r47b2d7e3 r1433ecda 175 175 while ((dp = readdir(dirp))) { 176 176 int len = snprintf(buff, PATH_MAX - 1, "%s/%s", path, dp->d_name); 177 if (len > PATH_MAX -1) {177 if (len > PATH_MAX - 1) { 178 178 // TODO: Do not enforce arbitrary static limits. 179 179 cli_error(CL_EFAIL, "Path too long for %s/%s", path, dp->d_name); … … 229 229 help_cmd_rm(HELP_SHORT); 230 230 printf( 231 "Usage: %s [options] <path>\n"232 "Options:\n"233 " -h, --help A short option summary\n"234 " -v, --version Print version information and exit\n"235 " -r, --recursive Recursively remove sub directories\n"236 " -f, --force Do not prompt prior to removing files\n"237 " -s, --safe Stop if directories change during removal\n\n"238 "Currently, %s is under development, some options don't work.\n",239 cmdname, cmdname);231 "Usage: %s [options] <path>\n" 232 "Options:\n" 233 " -h, --help A short option summary\n" 234 " -v, --version Print version information and exit\n" 235 " -r, --recursive Recursively remove sub directories\n" 236 " -f, --force Do not prompt prior to removing files\n" 237 " -s, --safe Stop if directories change during removal\n\n" 238 "Currently, %s is under development, some options don't work.\n", 239 cmdname, cmdname); 240 240 } 241 241 return; … … 255 255 if (argc < 2) { 256 256 cli_error(CL_EFAIL, 257 257 "%s: insufficient arguments. Try %s --help", cmdname, cmdname); 258 258 return CMD_FAILURE; 259 259 } … … 293 293 if ((unsigned) optind == argc) { 294 294 cli_error(CL_EFAIL, 295 295 "%s: insufficient arguments. Try %s --help", cmdname, cmdname); 296 296 rm_end(&rm); 297 297 return CMD_FAILURE; … … 317 317 break; 318 318 case RM_DIR: 319 if (! 319 if (!rm.recursive) { 320 320 printf("%s is a directory, use -r to remove it.\n", buff); 321 ret 321 ret++; 322 322 } else { 323 323 ret += rm_recursive(buff);
Note:
See TracChangeset
for help on using the changeset viewer.