summaryrefslogtreecommitdiff
path: root/shell/cmdedit.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-01-04 11:08:45 +0000
committerEric Andersen <andersen@codepoet.org>2001-01-04 11:08:45 +0000
commitb3dc3b8990f3380d6dd3051ef75b5f6c8e13b319 (patch)
treea01a28e9279d800fdba2633e7fbb36d704a3befd /shell/cmdedit.c
parent70a7855980731a9605c5643720680f299d90a125 (diff)
downloadbusybox-w32-b3dc3b8990f3380d6dd3051ef75b5f6c8e13b319.tar.gz
busybox-w32-b3dc3b8990f3380d6dd3051ef75b5f6c8e13b319.tar.bz2
busybox-w32-b3dc3b8990f3380d6dd3051ef75b5f6c8e13b319.zip
Cleanup -- move win handling to cmdedit.c, static-ify many functions.
Diffstat (limited to '')
-rw-r--r--shell/cmdedit.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 0c9bda760..0765ca3ce 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -105,8 +105,7 @@ struct history {
105 * command-line when the user has typed more than the current width. This 105 * command-line when the user has typed more than the current width. This
106 * would allow the user to see a 'window' of what he has typed. 106 * would allow the user to see a 'window' of what he has typed.
107 */ 107 */
108void 108static void cmdedit_setwidth(int w)
109cmdedit_setwidth(int w)
110{ 109{
111 if (w > 20) { 110 if (w > 20) {
112 cmdedit_termw = w; 111 cmdedit_termw = w;
@@ -116,8 +115,17 @@ cmdedit_setwidth(int w)
116 } 115 }
117} 116}
118 117
118static void win_changed(int junk)
119{
120 struct winsize win = { 0, 0, 0, 0 };
121 ioctl(0, TIOCGWINSZ, &win);
122 if (win.ws_col > 0) {
123 cmdedit_setwidth( win.ws_col - 1);
124 }
125}
119 126
120void cmdedit_reset_term(void) 127
128static void cmdedit_reset_term(void)
121{ 129{
122 if (reset_term) 130 if (reset_term)
123 /* sparc and other have broken termios support: use old termio handling. */ 131 /* sparc and other have broken termios support: use old termio handling. */
@@ -136,7 +144,7 @@ void cmdedit_reset_term(void)
136#endif 144#endif
137} 145}
138 146
139void clean_up_and_die(int sig) 147static void clean_up_and_die(int sig)
140{ 148{
141 cmdedit_reset_term(); 149 cmdedit_reset_term();
142 fprintf(stdout, "\n"); 150 fprintf(stdout, "\n");
@@ -145,7 +153,7 @@ void clean_up_and_die(int sig)
145} 153}
146 154
147/* Go to HOME position */ 155/* Go to HOME position */
148void input_home(int outputFd, int *cursor) 156static void input_home(int outputFd, int *cursor)
149{ 157{
150 while (*cursor > 0) { 158 while (*cursor > 0) {
151 xwrite(outputFd, "\b", 1); 159 xwrite(outputFd, "\b", 1);
@@ -154,7 +162,7 @@ void input_home(int outputFd, int *cursor)
154} 162}
155 163
156/* Go to END position */ 164/* Go to END position */
157void input_end(int outputFd, int *cursor, int len) 165static void input_end(int outputFd, int *cursor, int len)
158{ 166{
159 while (*cursor < len) { 167 while (*cursor < len) {
160 xwrite(outputFd, "\033[C", 3); 168 xwrite(outputFd, "\033[C", 3);
@@ -163,7 +171,7 @@ void input_end(int outputFd, int *cursor, int len)
163} 171}
164 172
165/* Delete the char in back of the cursor */ 173/* Delete the char in back of the cursor */
166void input_backspace(char* command, int outputFd, int *cursor, int *len) 174static void input_backspace(char* command, int outputFd, int *cursor, int *len)
167{ 175{
168 int j = 0; 176 int j = 0;
169 177
@@ -196,7 +204,7 @@ void input_backspace(char* command, int outputFd, int *cursor, int *len)
196} 204}
197 205
198/* Delete the char in front of the cursor */ 206/* Delete the char in front of the cursor */
199void input_delete(char* command, int outputFd, int cursor, int *len) 207static void input_delete(char* command, int outputFd, int cursor, int *len)
200{ 208{
201 int j = 0; 209 int j = 0;
202 210
@@ -220,7 +228,7 @@ void input_delete(char* command, int outputFd, int cursor, int *len)
220} 228}
221 229
222/* Move forward one charactor */ 230/* Move forward one charactor */
223void input_forward(int outputFd, int *cursor, int len) 231static void input_forward(int outputFd, int *cursor, int len)
224{ 232{
225 if (*cursor < len) { 233 if (*cursor < len) {
226 xwrite(outputFd, "\033[C", 3); 234 xwrite(outputFd, "\033[C", 3);
@@ -229,7 +237,7 @@ void input_forward(int outputFd, int *cursor, int len)
229} 237}
230 238
231/* Move back one charactor */ 239/* Move back one charactor */
232void input_backward(int outputFd, int *cursor) 240static void input_backward(int outputFd, int *cursor)
233{ 241{
234 if (*cursor > 0) { 242 if (*cursor > 0) {
235 xwrite(outputFd, "\033[D", 3); 243 xwrite(outputFd, "\033[D", 3);
@@ -240,7 +248,7 @@ void input_backward(int outputFd, int *cursor)
240 248
241 249
242#ifdef BB_FEATURE_SH_TAB_COMPLETION 250#ifdef BB_FEATURE_SH_TAB_COMPLETION
243char** username_tab_completion(char* command, int *num_matches) 251static char** username_tab_completion(char* command, int *num_matches)
244{ 252{
245 char **matches = (char **) NULL; 253 char **matches = (char **) NULL;
246 *num_matches=0; 254 *num_matches=0;
@@ -249,7 +257,7 @@ char** username_tab_completion(char* command, int *num_matches)
249} 257}
250 258
251#include <dirent.h> 259#include <dirent.h>
252char** exe_n_cwd_tab_completion(char* command, int *num_matches) 260static char** exe_n_cwd_tab_completion(char* command, int *num_matches)
253{ 261{
254 char *dirName; 262 char *dirName;
255 char **matches; 263 char **matches;
@@ -289,7 +297,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
289 return (matches); 297 return (matches);
290} 298}
291 299
292void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len, int lastWasTab) 300static void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len, int lastWasTab)
293{ 301{
294 /* Do TAB completion */ 302 /* Do TAB completion */
295 static int num_matches=0; 303 static int num_matches=0;
@@ -387,7 +395,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len,
387} 395}
388#endif 396#endif
389 397
390void get_previous_history(struct history **hp, char* command) 398static void get_previous_history(struct history **hp, char* command)
391{ 399{
392 if ((*hp)->s) 400 if ((*hp)->s)
393 free((*hp)->s); 401 free((*hp)->s);
@@ -395,7 +403,7 @@ void get_previous_history(struct history **hp, char* command)
395 *hp = (*hp)->p; 403 *hp = (*hp)->p;
396} 404}
397 405
398void get_next_history(struct history **hp, char* command) 406static void get_next_history(struct history **hp, char* command)
399{ 407{
400 if ((*hp)->s) 408 if ((*hp)->s)
401 free((*hp)->s); 409 free((*hp)->s);
@@ -450,6 +458,9 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
450 458
451 memset(command, 0, BUFSIZ); 459 memset(command, 0, BUFSIZ);
452 460
461 /* Print out the command prompt */
462 xwrite(outputFd, prompt, strlen(prompt));
463
453 while (1) { 464 while (1) {
454 465
455 if ((ret = read(inputFd, &c, 1)) < 1) 466 if ((ret = read(inputFd, &c, 1)) < 1)
@@ -721,6 +732,9 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
721 732
722extern void cmdedit_init(void) 733extern void cmdedit_init(void)
723{ 734{
735 win_changed(0);
736 signal(SIGWINCH, win_changed);
737
724 if(exithandler_set == 0) { 738 if(exithandler_set == 0) {
725 atexit(cmdedit_reset_term); /* be sure to do this only once */ 739 atexit(cmdedit_reset_term); /* be sure to do this only once */
726 exithandler_set = 1; 740 exithandler_set = 1;
@@ -745,6 +759,7 @@ extern void cmdedit_terminate(void)
745 signal(SIGINT, SIG_DFL); 759 signal(SIGINT, SIG_DFL);
746 signal(SIGQUIT, SIG_DFL); 760 signal(SIGQUIT, SIG_DFL);
747 signal(SIGTERM, SIG_DFL); 761 signal(SIGTERM, SIG_DFL);
762 signal(SIGWINCH, SIG_DFL);
748} 763}
749 764
750 765