Changeset 7c3fb9b in mainline for uspace/app/bdsh
- Timestamp:
- 2018-05-17T08:29:01Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ff23ff
- Parents:
- fac0ac7
- git-author:
- Jiri Svoboda <jiri@…> (2018-05-16 17:28:17)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-05-17 08:29:01)
- Location:
- uspace/app/bdsh
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/builtin_cmds.c
rfac0ac7 r7c3fb9b 27 27 */ 28 28 29 /* Almost identical (for now) to mod_cmds.c , however this will not be the case 30 * soon as builtin_t is going to grow way beyond module_t */ 29 /* 30 * Almost identical (for now) to mod_cmds.c, however this will not be the case 31 * soon as builtin_t is going to grow way beyond module_t 32 */ 31 33 32 34 #include <stdio.h> -
uspace/app/bdsh/cmds/builtins/batch/batch.c
rfac0ac7 r7c3fb9b 66 66 } 67 67 68 /* Main entry point for batch, accepts an array of arguments and a 69 * pointer to the cliuser_t structure */ 68 /** Main entry point for batch, accepts an array of arguments and a 69 * pointer to the cliuser_t structure 70 */ 70 71 int cmd_batch(char **argv, cliuser_t *usr) 71 72 { -
uspace/app/bdsh/cmds/builtins/cd/cd.c
rfac0ac7 r7c3fb9b 41 41 static const char *cmdname = "cd"; 42 42 43 /* Previous directory variables. 43 /* 44 * Previous directory variables. 44 45 * 45 46 * Declaring them static to avoid many "== NULL" checks. … … 101 102 } 102 103 103 /* We don't yet play nice with whitespace, a getopt implementation should 104 /* 105 * We don't yet play nice with whitespace, a getopt implementation should 104 106 * protect "quoted\ destination" as a single argument. Its not our job to 105 107 * look for && || or redirection as the tokenizer should have done that 106 * (currently, it does not) */ 108 * (currently, it does not) 109 */ 107 110 108 111 if (argc > 2) { -
uspace/app/bdsh/cmds/builtins/exit/exit.c
rfac0ac7 r7c3fb9b 44 44 } 45 45 46 /* Quits the program and returns the status of whatever command 47 * came before invoking 'quit' */ 46 /** Quits the program and returns the status of whatever command 47 * came before invoking 'quit' 48 */ 48 49 int cmd_exit(char *argv[], cliuser_t *usr) 49 50 { -
uspace/app/bdsh/cmds/cmds.h
rfac0ac7 r7c3fb9b 76 76 } builtin_t; 77 77 78 /* Declared in cmds/modules/modules.h and cmds/builtins/builtins.h 79 * respectively */ 78 /* 79 * Declared in cmds/modules/modules.h and cmds/builtins/builtins.h 80 * respectively 81 */ 80 82 extern module_t modules[]; 81 83 extern builtin_t builtins[]; -
uspace/app/bdsh/cmds/mod_cmds.c
rfac0ac7 r7c3fb9b 27 27 */ 28 28 29 /* NOTES: 29 /* 30 * NOTES: 30 31 * module_* functions are pretty much identical to builtin_* functions at this 31 32 * point. On the surface, it would appear that making each function dual purpose … … 37 38 * 38 39 * To keep things easy to hack, everything is separated. In reality this only adds 39 * 6 - 8 extra functions, but keeps each function very easy to read and modify. */ 40 * 6 - 8 extra functions, but keeps each function very easy to read and modify. 41 */ 40 42 41 /* TODO: 43 /* 44 * TODO: 42 45 * Many of these could be unsigned, provided the modules and builtins themselves 43 * can follow suit. Long term goal. */ 46 * can follow suit. Long term goal. 47 */ 44 48 45 49 #include <stdio.h> … … 53 57 extern volatile unsigned int cli_interactive; 54 58 55 /* Checks if an entry function matching command exists in modules[], if so 56 * its position in the array is returned */ 59 /** Checks if an entry function matching command exists in modules[] 60 * 61 * If so, its position in the array is returned 62 */ 57 63 int is_module(const char *command) 58 64 { … … 71 77 } 72 78 73 /* Checks if a module is an alias (sharing an entry point with another 74 * module). Returns 1 if so */ 79 /* 80 * Checks if a module is an alias (sharing an entry point with another 81 * module). Returns 1 if so 82 */ 75 83 int is_module_alias(const char *command) 76 84 { … … 105 113 106 114 107 /* Invokes the 'help' entry function for the module at position (int) module, 108 * which wants an unsigned int to determine brief or extended display. */ 115 /** Invokes the 'help' entry function for the module at position (int) module 116 * 117 * which wants an unsigned int to determine brief or extended display. 118 */ 109 119 int help_module(int module, unsigned int extended) 110 120 { … … 121 131 } 122 132 123 /* Invokes the module entry point modules[module], passing argv[] as an argument 124 * stack. */ 133 /** Invokes the module entry point modules[module] 134 * 135 * passing argv[] as an argument stack. 136 */ 125 137 int run_module(int module, char *argv[], iostate_t *new_iostate) 126 138 { -
uspace/app/bdsh/cmds/modules/cat/cat.c
rfac0ac7 r7c3fb9b 274 274 break; 275 275 } else if (c == U_SPECIAL && offset + 2 >= (size_t)bytes) { 276 /* If an extended character is cut off due to the size of the buffer, 277 we will copy it over to the next buffer so it can be read correctly. */ 276 /* 277 * If an extended character is cut off due to the size of the buffer, 278 * we will copy it over to the next buffer so it can be read correctly. 279 */ 278 280 copied_bytes = bytes - offset + 1; 279 281 memcpy(buff, buff + offset - 1, copied_bytes); -
uspace/app/bdsh/cmds/modules/cp/cp.c
rfac0ac7 r7c3fb9b 207 207 /* e.g. cp file_name /data/ */ 208 208 209 /* dest is a directory, 209 /* 210 * dest is a directory, 210 211 * append the src filename to it. 211 212 */ … … 231 232 /* e.g. cp file_name existing_file */ 232 233 233 /* dest already exists, 234 /* 235 * dest already exists, 234 236 * if force is set we will try to remove it. 235 237 * if interactive is set user input is required. … … 298 300 if (str_cmp(src_dirname, "..") && 299 301 str_cmp(src_dirname, ".")) { 300 /* The last component of src_path is 302 /* 303 * The last component of src_path is 301 304 * not '.' or '..' 302 305 */ … … 314 317 default: 315 318 case TYPE_NONE: 316 /* dest does not exists, this means the user wants 319 /* 320 * dest does not exists, this means the user wants 317 321 * to specify the name of the destination directory 318 322 * … … 336 340 } 337 341 338 /* Copy every single directory entry of src into the 342 /* 343 * Copy every single directory entry of src into the 339 344 * destination directory. 340 345 */ -
uspace/app/bdsh/cmds/modules/ls/ls.c
rfac0ac7 r7c3fb9b 27 27 */ 28 28 29 /* NOTE: 29 /* 30 * NOTE: 30 31 * This is a bit of an ugly hack, working around the absence of fstat / etc. 31 * As more stuff is completed and exposed in libc, this will improve */ 32 * As more stuff is completed and exposed in libc, this will improve 33 */ 32 34 33 35 #include <errno.h> -
uspace/app/bdsh/cmds/modules/module_aliases.h
rfac0ac7 r7c3fb9b 30 30 #define MODULE_ALIASES_H 31 31 32 /* Modules that declare multiple names for themselves but use the 32 /* 33 * Modules that declare multiple names for themselves but use the 33 34 * same entry functions are aliases. This array helps to determine if 34 35 * a module is an alias, as such it can be invoked differently. 35 * format is alias , real_name */ 36 * format is alias , real_name 37 */ 36 38 37 /* So far, this is only used in the help display but could be used to 39 /* 40 * So far, this is only used in the help display but could be used to 38 41 * handle a module differently even prior to reaching its entry code. 39 42 * For instance, 'exit' could behave differently than 'quit', prior to 40 * the entry point being reached. */ 43 * the entry point being reached. 44 */ 41 45 42 46 const char *mod_aliases[] = { -
uspace/app/bdsh/cmds/modules/modules.h
rfac0ac7 r7c3fb9b 30 30 #define MODULES_H 31 31 32 /* Each built in function has two files, one being an entry.h file which 32 /* 33 * Each built in function has two files, one being an entry.h file which 33 34 * prototypes the run/help entry functions, the other being a .def file 34 35 * which fills the modules[] array according to the cmd_t structure … … 40 41 * 41 42 * NOTE: See module_ aliases.h as well, this is where aliases (commands that 42 * share an entry point with others) are indexed */ 43 * share an entry point with others) are indexed 44 */ 43 45 44 46 #include "config.h" … … 64 66 #include "cmp/entry.h" 65 67 66 /* Each .def function fills the module_t struct with the individual name, entry 68 /* 69 * Each .def function fills the module_t struct with the individual name, entry 67 70 * point, help entry point, etc. You can use config.h to control what modules 68 * are loaded based on what libraries exist on the system. */ 71 * are loaded based on what libraries exist on the system. 72 */ 69 73 70 74 module_t modules[] = { -
uspace/app/bdsh/cmds/modules/rm/rm.c
rfac0ac7 r7c3fb9b 95 95 rm->safe = 0; 96 96 97 /* Make sure we can allocate enough memory to store 98 * what is needed in the job structure */ 97 /* 98 * Make sure we can allocate enough memory to store 99 * what is needed in the job structure 100 */ 99 101 if (NULL == (rm->nwd = (char *) malloc(PATH_MAX))) 100 102 return 0; -
uspace/app/bdsh/compl.c
rfac0ac7 r7c3fb9b 219 219 cs->path_list[0] = dirname; 220 220 cs->path_list[1] = NULL; 221 /* The second const ensures that we can't assign a const 222 * string to the non-const array. */ 221 /* 222 * The second const ensures that we can't assign a const 223 * string to the non-const array. 224 */ 223 225 cs->path = (const char *const *) cs->path_list; 224 226 -
uspace/app/bdsh/config.h
rfac0ac7 r7c3fb9b 27 27 */ 28 28 29 /* Various things that are used in many places including a few 30 * tidbits left over from autoconf prior to the HelenOS port */ 29 /* 30 * Various things that are used in many places including a few 31 * tidbits left over from autoconf prior to the HelenOS port 32 */ 31 33 32 34 /* Specific port work-arounds : */ … … 44 46 #define LARGE_BUFLEN 1024 45 47 46 /* How many words (arguments) are permitted, how big can a whole 47 * sentence be? Similar to ARG_MAX */ 48 /* 49 * How many words (arguments) are permitted, how big can a whole 50 * sentence be? Similar to ARG_MAX 51 */ 48 52 #define WORD_MAX 1023 49 53 #define INPUT_MAX 4096 -
uspace/app/bdsh/errors.c
rfac0ac7 r7c3fb9b 44 44 45 45 46 /* Look up errno in cl_errors and return the corresponding string. 47 * Return NULL if not found */ 46 /** Look up errno in cl_errors and return the corresponding string. 47 * 48 * Return NULL if not found 49 */ 48 50 static const char *err2str(int err) 49 51 { … … 55 57 } 56 58 57 /* Print an error report signifying errno, which is translated to 58 * its corresponding human readable string. If errno > 0, raise the 59 * cli_quit int that tells the main program loop to exit immediately */ 60 59 /** Print an error report signifying errno 60 * 61 * errno is translated to its corresponding human readable string. 62 * If errno > 0, raise the cli_quit int that tells the main program loop 63 * to exit immediately 64 */ 61 65 void cli_error(int err, const char *fmt, ...) 62 66 { … … 71 75 printf(" (Unknown Error %d)\n", err); 72 76 73 /* If fatal, raise cli_quit so that we try to exit 77 /* 78 * If fatal, raise cli_quit so that we try to exit 74 79 * gracefully. This will break the main loop and 75 * invoke the destructor */ 80 * invoke the destructor 81 */ 76 82 if (err == CL_EFATAL) 77 83 cli_quit = 1; -
uspace/app/bdsh/exec.c
rfac0ac7 r7c3fb9b 27 27 */ 28 28 29 /* The VERY basics of execute in place support. These are buggy, leaky 29 /* 30 * The VERY basics of execute in place support. These are buggy, leaky 30 31 * and not nearly done. Only here for beta testing!! You were warned!! 31 32 * TODO: 32 33 * Hash command lookups to save time 33 * Create a running pointer to **path and advance/rewind it as we go */ 34 * Create a running pointer to **path and advance/rewind it as we go 35 */ 34 36 35 37 #include <stdio.h> … … 66 68 } 67 69 68 /* Returns the full path of "cmd" if cmd is found, else just hand back 69 * cmd as it was presented */ 70 /** Returns the full path of "cmd" if cmd is found 71 * 72 * else just hand back cmd as it was presented 73 */ 70 74 static char *find_command(char *cmd) 71 75 { -
uspace/app/bdsh/input.c
rfac0ac7 r7c3fb9b 62 62 static void print_pipe_usage(void); 63 63 64 /* Tokenizes input from console, sees if the first word is a built-in, if so 64 /* 65 * Tokenizes input from console, sees if the first word is a built-in, if so 65 66 * invokes the built-in entry point (a[0]) passing all arguments in a[] to 66 * the handler */ 67 * the handler 68 */ 67 69 errno_t process_input(cliuser_t *usr) 68 70 { … … 105 107 } 106 108 107 /* Until full support for pipes is implemented, allow for a simple case: 109 /* 110 * Until full support for pipes is implemented, allow for a simple case: 108 111 * [from <file> |] command [| to <file>] 109 112 * -
uspace/app/bdsh/scli.c
rfac0ac7 r7c3fb9b 43 43 static iostate_t stdiostate; 44 44 45 /* Globals that are modified during start-up that modules/builtins 46 * should be aware of. */ 45 /* 46 * Globals that are modified during start-up that modules/builtins 47 * should be aware of. 48 */ 47 49 volatile unsigned int cli_quit = 0; 48 50 volatile unsigned int cli_verbocity = 1; 49 51 50 /* The official name of this program 51 * (change to your liking in configure.ac and re-run autoconf) */ 52 /* 53 * The official name of this program 54 * (change to your liking in configure.ac and re-run autoconf) 55 */ 52 56 const char *progname = PACKAGE_NAME; 53 57 -
uspace/app/bdsh/tok.c
rfac0ac7 r7c3fb9b 97 97 while ((next_char = tok_look_char(tok)) != 0) { 98 98 if (next_char == ' ') { 99 /* Push the token if there is any. 99 /* 100 * Push the token if there is any. 100 101 * There may not be any pending char for a token in case 101 102 * there are several spaces in the input. … … 115 116 116 117 } else if (next_char == '|') { 117 /* Pipes are tokens that are delimiters and should be 118 /* 119 * Pipes are tokens that are delimiters and should be 118 120 * output as a separate token 119 121 */ … … 137 139 } 138 140 } else if (next_char == '\'') { 139 /* A string starts with a quote (') and ends again with a quote. 141 /* 142 * A string starts with a quote (') and ends again with a quote. 140 143 * A literal quote is written as '' 141 144 */ … … 151 154 tok_start_token(tok, TOKTYPE_TEXT); 152 155 } 153 /* If we are handling any other character, just append it to 156 /* 157 * If we are handling any other character, just append it to 154 158 * the current token. 155 159 */ -
uspace/app/bdsh/util.c
rfac0ac7 r7c3fb9b 52 52 } 53 53 54 /* (re)allocates memory to store the current working directory, gets 54 /* 55 * (re)allocates memory to store the current working directory, gets 55 56 * and updates the current working directory, formats the prompt 56 * string */ 57 * string 58 */ 57 59 unsigned int cli_set_prompt(cliuser_t *usr) 58 60 {
Note:
See TracChangeset
for help on using the changeset viewer.