aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-01-04 11:10:38 +0000
committerEric Andersen <andersen@codepoet.org>2001-01-04 11:10:38 +0000
commit09acc06c106e31841a4246532bbba39da97ce3b1 (patch)
treeea8f3ed4440ae9898c2f1a4847ec2c4ddf4cb2d0
parent849083c8862b1d7d1246e50b38f453edcec3a58c (diff)
downloadbusybox-w32-09acc06c106e31841a4246532bbba39da97ce3b1.tar.gz
busybox-w32-09acc06c106e31841a4246532bbba39da97ce3b1.tar.bz2
busybox-w32-09acc06c106e31841a4246532bbba39da97ce3b1.zip
Move window size handling to cmdedit.c. Move prompt setup to setup_prompt_string()
-rw-r--r--lash.c86
-rw-r--r--sh.c86
-rw-r--r--shell/lash.c86
3 files changed, 99 insertions, 159 deletions
diff --git a/lash.c b/lash.c
index 14571169b..dd1d3aa5c 100644
--- a/lash.c
+++ b/lash.c
@@ -184,10 +184,8 @@ static struct built_in_command bltins_forking[] = {
184 {NULL, NULL, NULL} 184 {NULL, NULL, NULL}
185}; 185};
186 186
187static char prompt[3];
188static char *cwd; 187static char *cwd;
189static char *local_pending_command = NULL; 188static char *local_pending_command = NULL;
190static char *prompt_str = NULL;
191static struct jobset job_list = { NULL, NULL }; 189static struct jobset job_list = { NULL, NULL };
192static int argc; 190static int argc;
193static char **argv; 191static char **argv;
@@ -212,19 +210,6 @@ static inline void debug_printf(const char *format, ...)
212static inline void debug_printf(const char *format, ...) { } 210static inline void debug_printf(const char *format, ...) { }
213#endif 211#endif
214 212
215#ifdef BB_FEATURE_SH_COMMAND_EDITING
216static inline void win_changed(int junk)
217{
218 struct winsize win = { 0, 0, 0, 0 };
219 ioctl(0, TIOCGWINSZ, &win);
220 if (win.ws_col > 0) {
221 cmdedit_setwidth( win.ws_col - 1);
222 }
223}
224#else
225static inline void win_changed(int junk) {}
226#endif
227
228/* 213/*
229 Most builtins need access to the struct child_prog that has 214 Most builtins need access to the struct child_prog that has
230 their arguments, previously coded as cmd->progs[0]. That coding 215 their arguments, previously coded as cmd->progs[0]. That coding
@@ -743,26 +728,18 @@ static void restore_redirects(int squirrel[])
743 } 728 }
744} 729}
745 730
746static int get_command(FILE * source, char *command) 731static char* setup_prompt_string(int state)
747{ 732{
748 char user[9],buf[255],*s; 733 char user[9],buf[255],*s;
749 734 char prompt[3];
750 if (source == NULL) { 735 char prompt_str[BUFSIZ];
751 if (local_pending_command) {
752 /* a command specified (-c option): return it & mark it done */
753 strcpy(command, local_pending_command);
754 free(local_pending_command);
755 local_pending_command = NULL;
756 return 0;
757 }
758 return 1;
759 }
760 736
761 if (shell_context == 0) { 737 /* Set up the prompt */
738 if (state == 0) {
762 /* get User Name and setup prompt */ 739 /* get User Name and setup prompt */
763 strcpy(prompt,( geteuid() != 0 ) ? "$ ":"# "); 740 strcpy(prompt,( geteuid() != 0 ) ? "$ ":"# ");
764 my_getpwuid(user, geteuid()); 741 my_getpwuid(user, geteuid());
765 742
766 /* get HostName */ 743 /* get HostName */
767 gethostname(buf, 255); 744 gethostname(buf, 255);
768 s = strchr(buf, '.'); 745 s = strchr(buf, '.');
@@ -772,11 +749,35 @@ static int get_command(FILE * source, char *command)
772 } else { 749 } else {
773 strcpy(prompt,"> "); 750 strcpy(prompt,"> ");
774 } 751 }
752
753 if (state == 0) {
754 snprintf(prompt_str, BUFSIZ-1, "[%s@%s %s]%s", user, buf,
755 get_last_path_component(cwd), prompt);
756 } else {
757 sprintf(prompt_str, "%s", prompt);
758 }
759 return(strdup(prompt_str)); /* Must free this memory */
760}
761
762static int get_command(FILE * source, char *command)
763{
764 char *prompt_str;
765
766 if (source == NULL) {
767 if (local_pending_command) {
768 /* a command specified (-c option): return it & mark it done */
769 strcpy(command, local_pending_command);
770 free(local_pending_command);
771 local_pending_command = NULL;
772 return 0;
773 }
774 return 1;
775 }
776
777 prompt_str = setup_prompt_string(shell_context);
775 778
776 if (source == stdin) { 779 if (source == stdin) {
777#ifdef BB_FEATURE_SH_COMMAND_EDITING 780#ifdef BB_FEATURE_SH_COMMAND_EDITING
778 int len;
779
780 /* 781 /*
781 ** enable command line editing only while a command line 782 ** enable command line editing only while a command line
782 ** is actually being read; otherwise, we'll end up bequeathing 783 ** is actually being read; otherwise, we'll end up bequeathing
@@ -784,32 +785,12 @@ static int get_command(FILE * source, char *command)
784 ** child processes (rob@sysgo.de) 785 ** child processes (rob@sysgo.de)
785 */ 786 */
786 cmdedit_init(); 787 cmdedit_init();
787 signal(SIGWINCH, win_changed);
788 debug_printf( "in get_command() -- job_context=%d\n", shell_context);
789 fflush(stdout);
790 if (shell_context == 0) {
791 len=fprintf(stdout, "[%s@%s %s]%s", user, buf,
792 get_last_path_component(cwd), prompt);
793 } else {
794 len=fprintf(stdout, "%s", prompt);
795 }
796 fflush(stdout);
797 prompt_str=(char*)xmalloc(sizeof(char)*(len+1));
798 if (shell_context == 0) {
799 sprintf(prompt_str, "[%s@%s %s]%s", user, buf,
800 get_last_path_component(cwd), prompt);
801 } else {
802 sprintf(prompt_str, "%s", prompt);
803 }
804 cmdedit_read_input(prompt_str, command); 788 cmdedit_read_input(prompt_str, command);
805 free( prompt_str); 789 free( prompt_str);
806 cmdedit_terminate(); 790 cmdedit_terminate();
807 signal(SIGWINCH, SIG_DFL);
808 return 0; 791 return 0;
809#else 792#else
810 fprintf(stdout, "[%s@%s %s]%s",user, buf, 793 fprintf(stdout, "%s", prompt_str);
811 get_last_path_component(cwd), prompt);
812 fflush(stdout);
813#endif 794#endif
814 } 795 }
815 796
@@ -1712,6 +1693,5 @@ int shell_main(int argc_l, char **argv_l)
1712 atexit(free_memory); 1693 atexit(free_memory);
1713#endif 1694#endif
1714 1695
1715 win_changed(0);
1716 return (busy_loop(input)); 1696 return (busy_loop(input));
1717} 1697}
diff --git a/sh.c b/sh.c
index 14571169b..dd1d3aa5c 100644
--- a/sh.c
+++ b/sh.c
@@ -184,10 +184,8 @@ static struct built_in_command bltins_forking[] = {
184 {NULL, NULL, NULL} 184 {NULL, NULL, NULL}
185}; 185};
186 186
187static char prompt[3];
188static char *cwd; 187static char *cwd;
189static char *local_pending_command = NULL; 188static char *local_pending_command = NULL;
190static char *prompt_str = NULL;
191static struct jobset job_list = { NULL, NULL }; 189static struct jobset job_list = { NULL, NULL };
192static int argc; 190static int argc;
193static char **argv; 191static char **argv;
@@ -212,19 +210,6 @@ static inline void debug_printf(const char *format, ...)
212static inline void debug_printf(const char *format, ...) { } 210static inline void debug_printf(const char *format, ...) { }
213#endif 211#endif
214 212
215#ifdef BB_FEATURE_SH_COMMAND_EDITING
216static inline void win_changed(int junk)
217{
218 struct winsize win = { 0, 0, 0, 0 };
219 ioctl(0, TIOCGWINSZ, &win);
220 if (win.ws_col > 0) {
221 cmdedit_setwidth( win.ws_col - 1);
222 }
223}
224#else
225static inline void win_changed(int junk) {}
226#endif
227
228/* 213/*
229 Most builtins need access to the struct child_prog that has 214 Most builtins need access to the struct child_prog that has
230 their arguments, previously coded as cmd->progs[0]. That coding 215 their arguments, previously coded as cmd->progs[0]. That coding
@@ -743,26 +728,18 @@ static void restore_redirects(int squirrel[])
743 } 728 }
744} 729}
745 730
746static int get_command(FILE * source, char *command) 731static char* setup_prompt_string(int state)
747{ 732{
748 char user[9],buf[255],*s; 733 char user[9],buf[255],*s;
749 734 char prompt[3];
750 if (source == NULL) { 735 char prompt_str[BUFSIZ];
751 if (local_pending_command) {
752 /* a command specified (-c option): return it & mark it done */
753 strcpy(command, local_pending_command);
754 free(local_pending_command);
755 local_pending_command = NULL;
756 return 0;
757 }
758 return 1;
759 }
760 736
761 if (shell_context == 0) { 737 /* Set up the prompt */
738 if (state == 0) {
762 /* get User Name and setup prompt */ 739 /* get User Name and setup prompt */
763 strcpy(prompt,( geteuid() != 0 ) ? "$ ":"# "); 740 strcpy(prompt,( geteuid() != 0 ) ? "$ ":"# ");
764 my_getpwuid(user, geteuid()); 741 my_getpwuid(user, geteuid());
765 742
766 /* get HostName */ 743 /* get HostName */
767 gethostname(buf, 255); 744 gethostname(buf, 255);
768 s = strchr(buf, '.'); 745 s = strchr(buf, '.');
@@ -772,11 +749,35 @@ static int get_command(FILE * source, char *command)
772 } else { 749 } else {
773 strcpy(prompt,"> "); 750 strcpy(prompt,"> ");
774 } 751 }
752
753 if (state == 0) {
754 snprintf(prompt_str, BUFSIZ-1, "[%s@%s %s]%s", user, buf,
755 get_last_path_component(cwd), prompt);
756 } else {
757 sprintf(prompt_str, "%s", prompt);
758 }
759 return(strdup(prompt_str)); /* Must free this memory */
760}
761
762static int get_command(FILE * source, char *command)
763{
764 char *prompt_str;
765
766 if (source == NULL) {
767 if (local_pending_command) {
768 /* a command specified (-c option): return it & mark it done */
769 strcpy(command, local_pending_command);
770 free(local_pending_command);
771 local_pending_command = NULL;
772 return 0;
773 }
774 return 1;
775 }
776
777 prompt_str = setup_prompt_string(shell_context);
775 778
776 if (source == stdin) { 779 if (source == stdin) {
777#ifdef BB_FEATURE_SH_COMMAND_EDITING 780#ifdef BB_FEATURE_SH_COMMAND_EDITING
778 int len;
779
780 /* 781 /*
781 ** enable command line editing only while a command line 782 ** enable command line editing only while a command line
782 ** is actually being read; otherwise, we'll end up bequeathing 783 ** is actually being read; otherwise, we'll end up bequeathing
@@ -784,32 +785,12 @@ static int get_command(FILE * source, char *command)
784 ** child processes (rob@sysgo.de) 785 ** child processes (rob@sysgo.de)
785 */ 786 */
786 cmdedit_init(); 787 cmdedit_init();
787 signal(SIGWINCH, win_changed);
788 debug_printf( "in get_command() -- job_context=%d\n", shell_context);
789 fflush(stdout);
790 if (shell_context == 0) {
791 len=fprintf(stdout, "[%s@%s %s]%s", user, buf,
792 get_last_path_component(cwd), prompt);
793 } else {
794 len=fprintf(stdout, "%s", prompt);
795 }
796 fflush(stdout);
797 prompt_str=(char*)xmalloc(sizeof(char)*(len+1));
798 if (shell_context == 0) {
799 sprintf(prompt_str, "[%s@%s %s]%s", user, buf,
800 get_last_path_component(cwd), prompt);
801 } else {
802 sprintf(prompt_str, "%s", prompt);
803 }
804 cmdedit_read_input(prompt_str, command); 788 cmdedit_read_input(prompt_str, command);
805 free( prompt_str); 789 free( prompt_str);
806 cmdedit_terminate(); 790 cmdedit_terminate();
807 signal(SIGWINCH, SIG_DFL);
808 return 0; 791 return 0;
809#else 792#else
810 fprintf(stdout, "[%s@%s %s]%s",user, buf, 793 fprintf(stdout, "%s", prompt_str);
811 get_last_path_component(cwd), prompt);
812 fflush(stdout);
813#endif 794#endif
814 } 795 }
815 796
@@ -1712,6 +1693,5 @@ int shell_main(int argc_l, char **argv_l)
1712 atexit(free_memory); 1693 atexit(free_memory);
1713#endif 1694#endif
1714 1695
1715 win_changed(0);
1716 return (busy_loop(input)); 1696 return (busy_loop(input));
1717} 1697}
diff --git a/shell/lash.c b/shell/lash.c
index 14571169b..dd1d3aa5c 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -184,10 +184,8 @@ static struct built_in_command bltins_forking[] = {
184 {NULL, NULL, NULL} 184 {NULL, NULL, NULL}
185}; 185};
186 186
187static char prompt[3];
188static char *cwd; 187static char *cwd;
189static char *local_pending_command = NULL; 188static char *local_pending_command = NULL;
190static char *prompt_str = NULL;
191static struct jobset job_list = { NULL, NULL }; 189static struct jobset job_list = { NULL, NULL };
192static int argc; 190static int argc;
193static char **argv; 191static char **argv;
@@ -212,19 +210,6 @@ static inline void debug_printf(const char *format, ...)
212static inline void debug_printf(const char *format, ...) { } 210static inline void debug_printf(const char *format, ...) { }
213#endif 211#endif
214 212
215#ifdef BB_FEATURE_SH_COMMAND_EDITING
216static inline void win_changed(int junk)
217{
218 struct winsize win = { 0, 0, 0, 0 };
219 ioctl(0, TIOCGWINSZ, &win);
220 if (win.ws_col > 0) {
221 cmdedit_setwidth( win.ws_col - 1);
222 }
223}
224#else
225static inline void win_changed(int junk) {}
226#endif
227
228/* 213/*
229 Most builtins need access to the struct child_prog that has 214 Most builtins need access to the struct child_prog that has
230 their arguments, previously coded as cmd->progs[0]. That coding 215 their arguments, previously coded as cmd->progs[0]. That coding
@@ -743,26 +728,18 @@ static void restore_redirects(int squirrel[])
743 } 728 }
744} 729}
745 730
746static int get_command(FILE * source, char *command) 731static char* setup_prompt_string(int state)
747{ 732{
748 char user[9],buf[255],*s; 733 char user[9],buf[255],*s;
749 734 char prompt[3];
750 if (source == NULL) { 735 char prompt_str[BUFSIZ];
751 if (local_pending_command) {
752 /* a command specified (-c option): return it & mark it done */
753 strcpy(command, local_pending_command);
754 free(local_pending_command);
755 local_pending_command = NULL;
756 return 0;
757 }
758 return 1;
759 }
760 736
761 if (shell_context == 0) { 737 /* Set up the prompt */
738 if (state == 0) {
762 /* get User Name and setup prompt */ 739 /* get User Name and setup prompt */
763 strcpy(prompt,( geteuid() != 0 ) ? "$ ":"# "); 740 strcpy(prompt,( geteuid() != 0 ) ? "$ ":"# ");
764 my_getpwuid(user, geteuid()); 741 my_getpwuid(user, geteuid());
765 742
766 /* get HostName */ 743 /* get HostName */
767 gethostname(buf, 255); 744 gethostname(buf, 255);
768 s = strchr(buf, '.'); 745 s = strchr(buf, '.');
@@ -772,11 +749,35 @@ static int get_command(FILE * source, char *command)
772 } else { 749 } else {
773 strcpy(prompt,"> "); 750 strcpy(prompt,"> ");
774 } 751 }
752
753 if (state == 0) {
754 snprintf(prompt_str, BUFSIZ-1, "[%s@%s %s]%s", user, buf,
755 get_last_path_component(cwd), prompt);
756 } else {
757 sprintf(prompt_str, "%s", prompt);
758 }
759 return(strdup(prompt_str)); /* Must free this memory */
760}
761
762static int get_command(FILE * source, char *command)
763{
764 char *prompt_str;
765
766 if (source == NULL) {
767 if (local_pending_command) {
768 /* a command specified (-c option): return it & mark it done */
769 strcpy(command, local_pending_command);
770 free(local_pending_command);
771 local_pending_command = NULL;
772 return 0;
773 }
774 return 1;
775 }
776
777 prompt_str = setup_prompt_string(shell_context);
775 778
776 if (source == stdin) { 779 if (source == stdin) {
777#ifdef BB_FEATURE_SH_COMMAND_EDITING 780#ifdef BB_FEATURE_SH_COMMAND_EDITING
778 int len;
779
780 /* 781 /*
781 ** enable command line editing only while a command line 782 ** enable command line editing only while a command line
782 ** is actually being read; otherwise, we'll end up bequeathing 783 ** is actually being read; otherwise, we'll end up bequeathing
@@ -784,32 +785,12 @@ static int get_command(FILE * source, char *command)
784 ** child processes (rob@sysgo.de) 785 ** child processes (rob@sysgo.de)
785 */ 786 */
786 cmdedit_init(); 787 cmdedit_init();
787 signal(SIGWINCH, win_changed);
788 debug_printf( "in get_command() -- job_context=%d\n", shell_context);
789 fflush(stdout);
790 if (shell_context == 0) {
791 len=fprintf(stdout, "[%s@%s %s]%s", user, buf,
792 get_last_path_component(cwd), prompt);
793 } else {
794 len=fprintf(stdout, "%s", prompt);
795 }
796 fflush(stdout);
797 prompt_str=(char*)xmalloc(sizeof(char)*(len+1));
798 if (shell_context == 0) {
799 sprintf(prompt_str, "[%s@%s %s]%s", user, buf,
800 get_last_path_component(cwd), prompt);
801 } else {
802 sprintf(prompt_str, "%s", prompt);
803 }
804 cmdedit_read_input(prompt_str, command); 788 cmdedit_read_input(prompt_str, command);
805 free( prompt_str); 789 free( prompt_str);
806 cmdedit_terminate(); 790 cmdedit_terminate();
807 signal(SIGWINCH, SIG_DFL);
808 return 0; 791 return 0;
809#else 792#else
810 fprintf(stdout, "[%s@%s %s]%s",user, buf, 793 fprintf(stdout, "%s", prompt_str);
811 get_last_path_component(cwd), prompt);
812 fflush(stdout);
813#endif 794#endif
814 } 795 }
815 796
@@ -1712,6 +1693,5 @@ int shell_main(int argc_l, char **argv_l)
1712 atexit(free_memory); 1693 atexit(free_memory);
1713#endif 1694#endif
1714 1695
1715 win_changed(0);
1716 return (busy_loop(input)); 1696 return (busy_loop(input));
1717} 1697}