};
struct built_in_command {
- char *cmd; /* name */
- char *descr; /* description */
+ const char *cmd; /* name */
+ const char *descr; /* description */
int (*function) (struct child_prog *); /* function ptr */
};
/* Table of built-in functions (these are non-forking builtins, meaning they
* can change global variables in the parent shell process but they will not
* work with pipes and redirects; 'unset foo | whatever' will not work) */
-static struct built_in_command bltins[] = {
+static const struct built_in_command bltins[] = {
{"bg", "Resume a job in the background", builtin_fg_bg},
{"cd", "Change working directory", builtin_cd},
{"exec", "Exec command, replacing this shell with the exec'd process", builtin_exec},
static int last_bg_pid;
static unsigned int last_jobid;
static int shell_terminal;
-static char *PS1;
-static char *PS2 = "> ";
+static const char *PS1;
+static const char *PS2 = "> ";
#ifdef DEBUG_SHELL
/* built-in 'help' handler */
static int builtin_help(struct child_prog ATTRIBUTE_UNUSED *dummy)
{
- struct built_in_command *x;
+ const struct built_in_command *x;
printf("\nBuilt-in commands:\n"
"-------------------\n");
for (x = bltins; x->cmd; x++) {
- if (x->descr==NULL)
+ if (x->descr == NULL)
continue;
printf("%s\t%s\n", x->cmd, x->descr);
}
for (x = bltins_forking; x->cmd; x++) {
- if (x->descr==NULL)
+ if (x->descr == NULL)
continue;
printf("%s\t%s\n", x->cmd, x->descr);
}
static int builtin_jobs(struct child_prog *child)
{
struct job *job;
- char *status_string;
+ const char *status_string;
for (job = child->family->job_list->head; job; job = job->next) {
if (job->running_progs == job->stopped_progs)
#endif
}
-static inline void setup_prompt_string(char **prompt_str)
+static inline const char* setup_prompt_string(void)
{
#if !ENABLE_FEATURE_EDITING_FANCY_PROMPT
/* Set up the prompt */
if (shell_context == 0) {
- free(PS1);
- PS1=xmalloc(strlen(cwd)+4);
- sprintf(PS1, "%s %c ", cwd, ( geteuid() != 0 ) ? '$': '#');
- *prompt_str = PS1;
+ char *ns;
+ free((char*)PS1);
+ ns = xmalloc(strlen(cwd)+4);
+ sprintf(ns, "%s %c ", cwd, (geteuid() != 0) ? '$': '#');
+ PS1 = ns;
+ return ns;
} else {
- *prompt_str = PS2;
+ return PS2;
}
#else
- *prompt_str = (shell_context==0)? PS1 : PS2;
+ return (shell_context==0)? PS1 : PS2;
#endif
}
static int get_command(FILE * source, char *command)
{
- char *prompt_str;
+ const char *prompt_str;
if (source == NULL) {
if (local_pending_command) {
}
if (source == stdin) {
- setup_prompt_string(&prompt_str);
+ prompt_str = setup_prompt_string();
#if ENABLE_FEATURE_EDITING
/*
break;
case '!':
if (last_bg_pid==-1)
- *(var)='\0';
+ *var = '\0';
else
var = itoa(last_bg_pid);
break;
}
if (var == NULL) {
/* Seems we got an un-expandable variable. So delete it. */
- var = "";
+ var = (char*)"";
}
{
int subst_len = strlen(var);
*/
static int pseudo_exec(struct child_prog *child)
{
- struct built_in_command *x;
+ const struct built_in_command *x;
/* Check if the command matches any of the non-forking builtins.
* Depending on context, this might be redundant. But it's
int i;
int nextin, nextout;
int pipefds[2]; /* pipefd[0] is for reading */
- struct built_in_command *x;
+ const struct built_in_command *x;
struct child_prog *child;
nextin = 0, nextout = 1;