hush: now it's -Wwrite-strings clean

This commit is contained in:
Denis Vlasenko
2007-01-30 22:31:26 +00:00
parent 0c886c65de
commit c72c1ed932

View File

@@ -221,7 +221,7 @@ static int last_return_code;
extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */ extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */
/* "globals" within this file */ /* "globals" within this file */
static char *ifs; static const char *ifs;
static unsigned char map[256]; static unsigned char map[256];
static int fake_mode; static int fake_mode;
static int interactive; static int interactive;
@@ -231,8 +231,8 @@ static struct pipe *job_list;
static unsigned last_bg_pid; static unsigned last_bg_pid;
static int last_jobid; static int last_jobid;
static unsigned shell_terminal; static unsigned shell_terminal;
static char *PS1; static const char *PS1;
static char *PS2; static const char *PS2;
static struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 }; static struct variables shell_ver = { "HUSH_VERSION", "0.01", 1, 1, 0 };
static struct variables *top_vars = &shell_ver; static struct variables *top_vars = &shell_ver;
@@ -466,8 +466,9 @@ static int builtin_cd(struct child_prog *child)
static int builtin_env(struct child_prog *dummy ATTRIBUTE_UNUSED) static int builtin_env(struct child_prog *dummy ATTRIBUTE_UNUSED)
{ {
char **e = environ; char **e = environ;
if (e == NULL) return EXIT_FAILURE; if (e == NULL)
for (*e) { return EXIT_FAILURE;
while (*e) {
puts(*e++); puts(*e++);
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
@@ -857,23 +858,27 @@ static void cmdedit_set_initial_prompt(void)
#endif #endif
} }
static void setup_prompt_string(int promptmode, char **prompt_str) static const char* setup_prompt_string(int promptmode)
{ {
const char *prompt_str;
debug_printf("setup_prompt_string %d ", promptmode); debug_printf("setup_prompt_string %d ", promptmode);
#if !ENABLE_FEATURE_EDITING_FANCY_PROMPT #if !ENABLE_FEATURE_EDITING_FANCY_PROMPT
/* Set up the prompt */ /* Set up the prompt */
if (promptmode == 1) { if (promptmode == 1) {
free(PS1); char *ns;
PS1 = xmalloc(strlen(cwd)+4); free((char*)PS1);
sprintf(PS1, "%s %s", cwd, (geteuid() != 0) ? "$ " : "# "); ns = xmalloc(strlen(cwd)+4);
*prompt_str = PS1; sprintf(ns, "%s %s", cwd, (geteuid() != 0) ? "$ " : "# ");
prompt_str = ns;
PS1 = ns;
} else { } else {
*prompt_str = PS2; prompt_str = PS2;
} }
#else #else
*prompt_str = (promptmode == 1) ? PS1 : PS2; prompt_str = (promptmode == 1) ? PS1 : PS2;
#endif #endif
debug_printf("result %s\n", *prompt_str); debug_printf("result %s\n", prompt_str);
return prompt_str;
} }
#if ENABLE_FEATURE_EDITING #if ENABLE_FEATURE_EDITING
@@ -882,10 +887,10 @@ static line_input_t *line_input_state;
static void get_user_input(struct in_str *i) static void get_user_input(struct in_str *i)
{ {
char *prompt_str; const char *prompt_str;
static char the_command[BUFSIZ]; static char the_command[BUFSIZ];
setup_prompt_string(i->promptmode, &prompt_str); prompt_str = setup_prompt_string(i->promptmode);
#if ENABLE_FEATURE_EDITING #if ENABLE_FEATURE_EDITING
/* /*
** enable command line editing only while a command line ** enable command line editing only while a command line
@@ -1979,7 +1984,7 @@ static void initialize_context(struct p_context *ctx)
static int reserved_word(o_string *dest, struct p_context *ctx) static int reserved_word(o_string *dest, struct p_context *ctx)
{ {
struct reserved_combo { struct reserved_combo {
char *literal; const char *literal;
int code; int code;
long flag; long flag;
}; };
@@ -1988,7 +1993,7 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
* to turn the compound list into a command. * to turn the compound list into a command.
* FLAG_START means the word must start a new compound list. * FLAG_START means the word must start a new compound list.
*/ */
static struct reserved_combo reserved_list[] = { static const struct reserved_combo reserved_list[] = {
{ "if", RES_IF, FLAG_THEN | FLAG_START }, { "if", RES_IF, FLAG_THEN | FLAG_START },
{ "then", RES_THEN, FLAG_ELIF | FLAG_ELSE | FLAG_FI }, { "then", RES_THEN, FLAG_ELIF | FLAG_ELSE | FLAG_FI },
{ "elif", RES_ELIF, FLAG_THEN }, { "elif", RES_ELIF, FLAG_THEN },
@@ -2001,8 +2006,9 @@ static int reserved_word(o_string *dest, struct p_context *ctx)
{ "do", RES_DO, FLAG_DONE }, { "do", RES_DO, FLAG_DONE },
{ "done", RES_DONE, FLAG_END } { "done", RES_DONE, FLAG_END }
}; };
struct reserved_combo *r; const struct reserved_combo *r;
#define NRES sizeof(reserved_list)/sizeof(struct reserved_combo) #define NRES sizeof(reserved_list)/sizeof(reserved_list[0])
for (r = reserved_list; r < reserved_list+NRES; r++) { for (r = reserved_list; r < reserved_list+NRES; r++) {
if (strcmp(dest->data, r->literal) == 0) { if (strcmp(dest->data, r->literal) == 0) {
debug_printf("found reserved word %s, code %d\n",r->literal,r->code); debug_printf("found reserved word %s, code %d\n",r->literal,r->code);