aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-30 22:31:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-30 22:31:26 +0000
commitc72c1ed93287d5a076ae7c74427959cea6274861 (patch)
tree902c4a7f10fc09d7d82e59b3ed29d0ee28dd84ca
parent0c886c65de93f860a54508be0df40d1a9c52ab6d (diff)
downloadbusybox-w32-c72c1ed93287d5a076ae7c74427959cea6274861.tar.gz
busybox-w32-c72c1ed93287d5a076ae7c74427959cea6274861.tar.bz2
busybox-w32-c72c1ed93287d5a076ae7c74427959cea6274861.zip
hush: now it's -Wwrite-strings clean
-rw-r--r--shell/hush.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 1ff9b7fd5..6d05c064b 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -221,7 +221,7 @@ static int last_return_code;
221extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */ 221extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */
222 222
223/* "globals" within this file */ 223/* "globals" within this file */
224static char *ifs; 224static const char *ifs;
225static unsigned char map[256]; 225static unsigned char map[256];
226static int fake_mode; 226static int fake_mode;
227static int interactive; 227static int interactive;
@@ -231,8 +231,8 @@ static struct pipe *job_list;
231static unsigned last_bg_pid; 231static unsigned last_bg_pid;
232static int last_jobid; 232static int last_jobid;
233static unsigned shell_terminal; 233static unsigned shell_terminal;
234static char *PS1; 234static const char *PS1;
235static char *PS2; 235static const char *PS2;
236static struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 }; 236static struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 };
237static struct variables *top_vars = &shell_ver; 237static struct variables *top_vars = &shell_ver;
238 238
@@ -466,8 +466,9 @@ static int builtin_cd(struct child_prog *child)
466static int builtin_env(struct child_prog *dummy ATTRIBUTE_UNUSED) 466static int builtin_env(struct child_prog *dummy ATTRIBUTE_UNUSED)
467{ 467{
468 char **e = environ; 468 char **e = environ;
469 if (e == NULL) return EXIT_FAILURE; 469 if (e == NULL)
470 for (*e) { 470 return EXIT_FAILURE;
471 while (*e) {
471 puts(*e++); 472 puts(*e++);
472 } 473 }
473 return EXIT_SUCCESS; 474 return EXIT_SUCCESS;
@@ -857,23 +858,27 @@ static void cmdedit_set_initial_prompt(void)
857#endif 858#endif
858} 859}
859 860
860static void setup_prompt_string(int promptmode, char **prompt_str) 861static const char* setup_prompt_string(int promptmode)
861{ 862{
862 debug_printf("setup_prompt_string %d ",promptmode); 863 const char *prompt_str;
864 debug_printf("setup_prompt_string %d ", promptmode);
863#if !ENABLE_FEATURE_EDITING_FANCY_PROMPT 865#if !ENABLE_FEATURE_EDITING_FANCY_PROMPT
864 /* Set up the prompt */ 866 /* Set up the prompt */
865 if (promptmode == 1) { 867 if (promptmode == 1) {
866 free(PS1); 868 char *ns;
867 PS1 = xmalloc(strlen(cwd)+4); 869 free((char*)PS1);
868 sprintf(PS1, "%s %s", cwd, (geteuid() != 0) ? "$ " : "# "); 870 ns = xmalloc(strlen(cwd)+4);
869 *prompt_str = PS1; 871 sprintf(ns, "%s %s", cwd, (geteuid() != 0) ? "$ " : "# ");
872 prompt_str = ns;
873 PS1 = ns;
870 } else { 874 } else {
871 *prompt_str = PS2; 875 prompt_str = PS2;
872 } 876 }
873#else 877#else
874 *prompt_str = (promptmode == 1) ? PS1 : PS2; 878 prompt_str = (promptmode == 1) ? PS1 : PS2;
875#endif 879#endif
876 debug_printf("result %s\n", *prompt_str); 880 debug_printf("result %s\n", prompt_str);
881 return prompt_str;
877} 882}
878 883
879#if ENABLE_FEATURE_EDITING 884#if ENABLE_FEATURE_EDITING
@@ -882,10 +887,10 @@ static line_input_t *line_input_state;
882 887
883static void get_user_input(struct in_str *i) 888static void get_user_input(struct in_str *i)
884{ 889{
885 char *prompt_str; 890 const char *prompt_str;
886 static char the_command[BUFSIZ]; 891 static char the_command[BUFSIZ];
887 892
888 setup_prompt_string(i->promptmode, &prompt_str); 893 prompt_str = setup_prompt_string(i->promptmode);
889#if ENABLE_FEATURE_EDITING 894#if ENABLE_FEATURE_EDITING
890 /* 895 /*
891 ** enable command line editing only while a command line 896 ** enable command line editing only while a command line
@@ -1979,7 +1984,7 @@ static void initialize_context(struct p_context *ctx)
1979static int reserved_word(o_string *dest, struct p_context *ctx) 1984static int reserved_word(o_string *dest, struct p_context *ctx)
1980{ 1985{
1981 struct reserved_combo { 1986 struct reserved_combo {
1982 char *literal; 1987 const char *literal;
1983 int code; 1988 int code;
1984 long flag; 1989 long flag;
1985 }; 1990 };
@@ -1988,7 +1993,7 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
1988 * to turn the compound list into a command. 1993 * to turn the compound list into a command.
1989 * FLAG_START means the word must start a new compound list. 1994 * FLAG_START means the word must start a new compound list.
1990 */ 1995 */
1991 static struct reserved_combo reserved_list[] = { 1996 static const struct reserved_combo reserved_list[] = {
1992 { "if", RES_IF, FLAG_THEN | FLAG_START }, 1997 { "if", RES_IF, FLAG_THEN | FLAG_START },
1993 { "then", RES_THEN, FLAG_ELIF | FLAG_ELSE | FLAG_FI }, 1998 { "then", RES_THEN, FLAG_ELIF | FLAG_ELSE | FLAG_FI },
1994 { "elif", RES_ELIF, FLAG_THEN }, 1999 { "elif", RES_ELIF, FLAG_THEN },
@@ -2001,8 +2006,9 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
2001 { "do", RES_DO, FLAG_DONE }, 2006 { "do", RES_DO, FLAG_DONE },
2002 { "done", RES_DONE, FLAG_END } 2007 { "done", RES_DONE, FLAG_END }
2003 }; 2008 };
2004 struct reserved_combo *r; 2009 const struct reserved_combo *r;
2005#define NRES sizeof(reserved_list)/sizeof(struct reserved_combo) 2010#define NRES sizeof(reserved_list)/sizeof(reserved_list[0])
2011
2006 for (r = reserved_list; r < reserved_list+NRES; r++) { 2012 for (r = reserved_list; r < reserved_list+NRES; r++) {
2007 if (strcmp(dest->data, r->literal) == 0) { 2013 if (strcmp(dest->data, r->literal) == 0) {
2008 debug_printf("found reserved word %s, code %d\n",r->literal,r->code); 2014 debug_printf("found reserved word %s, code %d\n",r->literal,r->code);
@@ -2314,7 +2320,7 @@ static const char *lookup_param(const char *src)
2314static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input) 2320static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input)
2315{ 2321{
2316 int i, advance=0; 2322 int i, advance=0;
2317 char sep[]=" "; 2323 char sep[] = " ";
2318 int ch = input->peek(input); /* first character after the $ */ 2324 int ch = input->peek(input); /* first character after the $ */
2319 debug_printf("handle_dollar: ch=%c\n",ch); 2325 debug_printf("handle_dollar: ch=%c\n",ch);
2320 if (isalpha(ch)) { 2326 if (isalpha(ch)) {
@@ -2570,17 +2576,17 @@ static void update_ifs_map(void)
2570{ 2576{
2571 /* char *ifs and char map[256] are both globals. */ 2577 /* char *ifs and char map[256] are both globals. */
2572 ifs = getenv("IFS"); 2578 ifs = getenv("IFS");
2573 if (ifs == NULL) ifs=" \t\n"; 2579 if (ifs == NULL) ifs = " \t\n";
2574 /* Precompute a list of 'flow through' behavior so it can be treated 2580 /* Precompute a list of 'flow through' behavior so it can be treated
2575 * quickly up front. Computation is necessary because of IFS. 2581 * quickly up front. Computation is necessary because of IFS.
2576 * Special case handling of IFS == " \t\n" is not implemented. 2582 * Special case handling of IFS == " \t\n" is not implemented.
2577 * The map[] array only really needs two bits each, and on most machines 2583 * The map[] array only really needs two bits each, and on most machines
2578 * that would be faster because of the reduced L1 cache footprint. 2584 * that would be faster because of the reduced L1 cache footprint.
2579 */ 2585 */
2580 memset(map,0,sizeof(map)); /* most characters flow through always */ 2586 memset(map, 0, sizeof(map)); /* most characters flow through always */
2581 mapset("\\$'\"`", 3); /* never flow through */ 2587 mapset("\\$'\"`", 3); /* never flow through */
2582 mapset("<>;&|(){}#", 1); /* flow through if quoted */ 2588 mapset("<>;&|(){}#", 1); /* flow through if quoted */
2583 mapset(ifs, 2); /* also flow through if quoted */ 2589 mapset(ifs, 2); /* also flow through if quoted */
2584} 2590}
2585 2591
2586/* most recursion does not come through here, the exception is 2592/* most recursion does not come through here, the exception is