diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-03-19 10:46:06 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-03-19 10:46:06 +0000 |
commit | 1dbe340ebab31aa85446e83e8bc42f184b59b25b (patch) | |
tree | 188b315b963daf910c60ee8a3796d15365e7243f | |
parent | c7c634bd88c57d910c6089de7f0091ca4e3d1843 (diff) | |
download | busybox-w32-1dbe340ebab31aa85446e83e8bc42f184b59b25b.tar.gz busybox-w32-1dbe340ebab31aa85446e83e8bc42f184b59b25b.tar.bz2 busybox-w32-1dbe340ebab31aa85446e83e8bc42f184b59b25b.zip |
more minor fixes
-Erik
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | archival/gunzip.c | 6 | ||||
-rw-r--r-- | cmdedit.c | 113 | ||||
-rw-r--r-- | gunzip.c | 6 | ||||
-rw-r--r-- | shell/cmdedit.c | 113 |
5 files changed, 139 insertions, 101 deletions
@@ -30,7 +30,7 @@ DODEBUG = false | |||
30 | # If you want a static binary, turn this on. I can't think | 30 | # If you want a static binary, turn this on. I can't think |
31 | # of many situations where anybody would ever want it static, | 31 | # of many situations where anybody would ever want it static, |
32 | # but... | 32 | # but... |
33 | DOSTATIC = false | 33 | DOSTATIC = true |
34 | 34 | ||
35 | # This will choke on a non-debian system | 35 | # This will choke on a non-debian system |
36 | ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'` | 36 | ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'` |
diff --git a/archival/gunzip.c b/archival/gunzip.c index e1c8ac06e..7aa896469 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
@@ -1291,12 +1291,6 @@ const char *reject; | |||
1291 | /* ======================================================================== | 1291 | /* ======================================================================== |
1292 | * Error handlers. | 1292 | * Error handlers. |
1293 | */ | 1293 | */ |
1294 | void warn(a, b) | ||
1295 | char *a, *b; /* message strings juxtaposed in output */ | ||
1296 | { | ||
1297 | WARN((stderr, "warning: %s%s\n", a, b)); | ||
1298 | } | ||
1299 | |||
1300 | void read_error() | 1294 | void read_error() |
1301 | { | 1295 | { |
1302 | fprintf(stderr, "\n"); | 1296 | fprintf(stderr, "\n"); |
@@ -184,19 +184,45 @@ char** username_completion_matches(char* command, int *num_matches) | |||
184 | fprintf(stderr, "\nin username_completion_matches\n"); | 184 | fprintf(stderr, "\nin username_completion_matches\n"); |
185 | return (matches); | 185 | return (matches); |
186 | } | 186 | } |
187 | |||
188 | #include <dirent.h> | ||
187 | char** find_path_executable_n_cwd_matches(char* command, int *num_matches) | 189 | char** find_path_executable_n_cwd_matches(char* command, int *num_matches) |
188 | { | 190 | { |
191 | char *dirName; | ||
189 | char **matches = (char **) NULL; | 192 | char **matches = (char **) NULL; |
190 | matches = malloc(sizeof(char*)*100); | 193 | DIR *dir; |
191 | 194 | struct dirent *next; | |
192 | matches[0] = malloc(sizeof(char)*50); | 195 | |
193 | matches[1] = malloc(sizeof(char)*50); | 196 | matches = malloc( sizeof(char*)*50); |
194 | 197 | ||
195 | sprintf(matches[0], "Hello"); | 198 | /* Stick a wildcard onto the command, for later use */ |
196 | sprintf(matches[1], "Howdy"); | 199 | strcat( command, "*"); |
197 | *num_matches=2; | 200 | |
201 | /* Now wall the current directory */ | ||
202 | dirName = get_current_dir_name(); | ||
203 | dir = opendir(dirName); | ||
204 | if (!dir) { | ||
205 | /* Don't print an error, just shut up and return */ | ||
206 | *num_matches=0; | ||
207 | return (matches); | ||
208 | } | ||
209 | while ((next = readdir(dir)) != NULL) { | ||
210 | |||
211 | /* Some quick sanity checks */ | ||
212 | if ((strcmp(next->d_name, "..") == 0) | ||
213 | || (strcmp(next->d_name, ".") == 0)) { | ||
214 | continue; | ||
215 | } | ||
216 | /* See if this matches */ | ||
217 | if (check_wildcard_match(next->d_name, command) == TRUE) { | ||
218 | /* Cool, found a match. Add it to the list */ | ||
219 | matches[*num_matches] = malloc(strlen(next->d_name)+1); | ||
220 | strcpy( matches[*num_matches], next->d_name); | ||
221 | ++*num_matches; | ||
222 | //matches = realloc( matches, sizeof(char*)*(*num_matches)); | ||
223 | } | ||
224 | } | ||
198 | 225 | ||
199 | // fprintf(stderr, "\nin find_path_executable_n_cwd_matches\n"); | ||
200 | return (matches); | 226 | return (matches); |
201 | } | 227 | } |
202 | 228 | ||
@@ -319,11 +345,11 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
319 | /* For now, we will not bother with trying to distinguish | 345 | /* For now, we will not bother with trying to distinguish |
320 | * whether the cursor is in/at a command extression -- we | 346 | * whether the cursor is in/at a command extression -- we |
321 | * will always try all possable matches. If you don't like | 347 | * will always try all possable matches. If you don't like |
322 | * that, feel free to fix it. | 348 | * that then feel free to fix it. |
323 | */ | 349 | */ |
324 | 350 | ||
325 | /* Make a local copy of the string -- up | 351 | /* Make a local copy of the string -- up |
326 | * to the the position of the cursor */ | 352 | * to the position of the cursor */ |
327 | matchBuf = (char *) calloc(BUFSIZ, sizeof(char)); | 353 | matchBuf = (char *) calloc(BUFSIZ, sizeof(char)); |
328 | strncpy(matchBuf, parsenextc, cursor); | 354 | strncpy(matchBuf, parsenextc, cursor); |
329 | tmp=matchBuf; | 355 | tmp=matchBuf; |
@@ -346,59 +372,58 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
346 | matches = (char **) NULL; | 372 | matches = (char **) NULL; |
347 | } | 373 | } |
348 | 374 | ||
349 | /* If the word starts in `~', and there is no slash in the word, | 375 | /* If the word starts with `~' and there is no slash in the word, |
350 | * then try completing this word as a username. */ | 376 | * then try completing this word as a username. */ |
377 | |||
378 | /* FIXME -- this check is broken! */ | ||
351 | if (*tmp == '~' && !strchr(tmp, '/')) | 379 | if (*tmp == '~' && !strchr(tmp, '/')) |
352 | matches = username_completion_matches(tmp, &num_matches); | 380 | matches = username_completion_matches(tmp, &num_matches); |
353 | 381 | ||
354 | /* Try to match any executable in our patch, and everything | 382 | /* Try to match any executable in our path and everything |
355 | * in the current working directory that matches. | 383 | * in the current working directory that matches. */ |
356 | */ | ||
357 | if (!matches) | 384 | if (!matches) |
358 | matches = find_path_executable_n_cwd_matches(tmp, &num_matches); | 385 | matches = find_path_executable_n_cwd_matches(tmp, &num_matches); |
386 | |||
387 | /* Don't leak memory */ | ||
388 | free( matchBuf); | ||
389 | |||
390 | /* Did we find exactly one match? */ | ||
391 | if (matches && num_matches==1) { | ||
392 | /* write out the matched command */ | ||
393 | strncpy(parsenextc+pos, matches[0]+pos, strlen(matches[0])-pos); | ||
394 | len=strlen(parsenextc); | ||
395 | cursor=len; | ||
396 | xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos); | ||
397 | break; | ||
398 | } | ||
359 | } else { | 399 | } else { |
400 | /* Ok -- the last char was a TAB. Since they | ||
401 | * just hit TAB again, print a list of all the | ||
402 | * available choices... */ | ||
360 | if ( matches && num_matches>0 ) { | 403 | if ( matches && num_matches>0 ) { |
361 | int i, col; | 404 | int i, col; |
362 | 405 | ||
363 | fprintf(stderr, "\nTabbing...\n"); | 406 | /* Go to the next line */ |
364 | 407 | xwrite(outputFd, "\n", 1); | |
365 | /* Make a list of the matches */ | 408 | /* Print the list of matches */ |
366 | col += xwrite(outputFd, "\n", 1); | ||
367 | for (i=0,col=0; i<num_matches; i++) { | 409 | for (i=0,col=0; i<num_matches; i++) { |
368 | col += xwrite(outputFd, prompt, strlen(matches[i])); | 410 | char foo[17]; |
411 | sprintf(foo, "%-14s ", matches[i]); | ||
412 | col += xwrite(outputFd, foo, strlen(foo)); | ||
369 | if (col > 60 && matches[i+1] != NULL) { | 413 | if (col > 60 && matches[i+1] != NULL) { |
370 | xwrite(outputFd, "\n", 1); | 414 | xwrite(outputFd, "\n", 1); |
371 | col = 0; | 415 | col = 0; |
372 | } | 416 | } |
373 | } | 417 | } |
418 | /* Go to the next line */ | ||
374 | xwrite(outputFd, "\n", 1); | 419 | xwrite(outputFd, "\n", 1); |
375 | 420 | /* Rewrite the prompt */ | |
376 | len+=strlen(prompt); | ||
377 | fprintf(stderr, "len=%d\n", len); | ||
378 | |||
379 | /* Move to the beginning of the line */ | ||
380 | input_home(outputFd, &len); | ||
381 | |||
382 | /* erase everything */ | ||
383 | for (j = 0; j < len; j++) | ||
384 | xwrite(outputFd, " ", 1); | ||
385 | |||
386 | /* return to begining of line */ | ||
387 | input_home(outputFd, &cursor); | ||
388 | |||
389 | /* Rewrite the prompt) */ | ||
390 | xwrite(outputFd, prompt, strlen(prompt)); | 421 | xwrite(outputFd, prompt, strlen(prompt)); |
391 | |||
392 | /* Rewrite the command */ | 422 | /* Rewrite the command */ |
393 | len = strlen(parsenextc); | ||
394 | xwrite(outputFd, parsenextc, len); | 423 | xwrite(outputFd, parsenextc, len); |
395 | 424 | /* Put the cursor back to where it used to be */ | |
396 | /* Move back to where the cursor used to be */ | 425 | for (cursor=len; cursor > pos; cursor--) |
397 | for (cursor=pos; cursor > 0; cursor--) | ||
398 | xwrite(outputFd, "\b", 1); | 426 | xwrite(outputFd, "\b", 1); |
399 | cursor = pos; | ||
400 | |||
401 | //fprintf(stderr, "\nprompt='%s'\n", prompt); | ||
402 | } | 427 | } |
403 | } | 428 | } |
404 | break; | 429 | break; |
@@ -451,7 +476,6 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
451 | /* return to begining of line */ | 476 | /* return to begining of line */ |
452 | for (; cursor > 0; cursor--) | 477 | for (; cursor > 0; cursor--) |
453 | xwrite(outputFd, "\b", 1); | 478 | xwrite(outputFd, "\b", 1); |
454 | xwrite(outputFd, parsenextc, len); | ||
455 | 479 | ||
456 | /* erase old command */ | 480 | /* erase old command */ |
457 | for (j = 0; j < len; j++) | 481 | for (j = 0; j < len; j++) |
@@ -462,6 +486,7 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
462 | xwrite(outputFd, "\b", 1); | 486 | xwrite(outputFd, "\b", 1); |
463 | 487 | ||
464 | memset(parsenextc, 0, BUFSIZ); | 488 | memset(parsenextc, 0, BUFSIZ); |
489 | len = strlen(parsenextc); | ||
465 | /* write new command */ | 490 | /* write new command */ |
466 | strcpy(parsenextc, hp->s); | 491 | strcpy(parsenextc, hp->s); |
467 | len = strlen(hp->s); | 492 | len = strlen(hp->s); |
@@ -1291,12 +1291,6 @@ const char *reject; | |||
1291 | /* ======================================================================== | 1291 | /* ======================================================================== |
1292 | * Error handlers. | 1292 | * Error handlers. |
1293 | */ | 1293 | */ |
1294 | void warn(a, b) | ||
1295 | char *a, *b; /* message strings juxtaposed in output */ | ||
1296 | { | ||
1297 | WARN((stderr, "warning: %s%s\n", a, b)); | ||
1298 | } | ||
1299 | |||
1300 | void read_error() | 1294 | void read_error() |
1301 | { | 1295 | { |
1302 | fprintf(stderr, "\n"); | 1296 | fprintf(stderr, "\n"); |
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index 8a7a5fb03..b3e7fd58c 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
@@ -184,19 +184,45 @@ char** username_completion_matches(char* command, int *num_matches) | |||
184 | fprintf(stderr, "\nin username_completion_matches\n"); | 184 | fprintf(stderr, "\nin username_completion_matches\n"); |
185 | return (matches); | 185 | return (matches); |
186 | } | 186 | } |
187 | |||
188 | #include <dirent.h> | ||
187 | char** find_path_executable_n_cwd_matches(char* command, int *num_matches) | 189 | char** find_path_executable_n_cwd_matches(char* command, int *num_matches) |
188 | { | 190 | { |
191 | char *dirName; | ||
189 | char **matches = (char **) NULL; | 192 | char **matches = (char **) NULL; |
190 | matches = malloc(sizeof(char*)*100); | 193 | DIR *dir; |
191 | 194 | struct dirent *next; | |
192 | matches[0] = malloc(sizeof(char)*50); | 195 | |
193 | matches[1] = malloc(sizeof(char)*50); | 196 | matches = malloc( sizeof(char*)*50); |
194 | 197 | ||
195 | sprintf(matches[0], "Hello"); | 198 | /* Stick a wildcard onto the command, for later use */ |
196 | sprintf(matches[1], "Howdy"); | 199 | strcat( command, "*"); |
197 | *num_matches=2; | 200 | |
201 | /* Now wall the current directory */ | ||
202 | dirName = get_current_dir_name(); | ||
203 | dir = opendir(dirName); | ||
204 | if (!dir) { | ||
205 | /* Don't print an error, just shut up and return */ | ||
206 | *num_matches=0; | ||
207 | return (matches); | ||
208 | } | ||
209 | while ((next = readdir(dir)) != NULL) { | ||
210 | |||
211 | /* Some quick sanity checks */ | ||
212 | if ((strcmp(next->d_name, "..") == 0) | ||
213 | || (strcmp(next->d_name, ".") == 0)) { | ||
214 | continue; | ||
215 | } | ||
216 | /* See if this matches */ | ||
217 | if (check_wildcard_match(next->d_name, command) == TRUE) { | ||
218 | /* Cool, found a match. Add it to the list */ | ||
219 | matches[*num_matches] = malloc(strlen(next->d_name)+1); | ||
220 | strcpy( matches[*num_matches], next->d_name); | ||
221 | ++*num_matches; | ||
222 | //matches = realloc( matches, sizeof(char*)*(*num_matches)); | ||
223 | } | ||
224 | } | ||
198 | 225 | ||
199 | // fprintf(stderr, "\nin find_path_executable_n_cwd_matches\n"); | ||
200 | return (matches); | 226 | return (matches); |
201 | } | 227 | } |
202 | 228 | ||
@@ -319,11 +345,11 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
319 | /* For now, we will not bother with trying to distinguish | 345 | /* For now, we will not bother with trying to distinguish |
320 | * whether the cursor is in/at a command extression -- we | 346 | * whether the cursor is in/at a command extression -- we |
321 | * will always try all possable matches. If you don't like | 347 | * will always try all possable matches. If you don't like |
322 | * that, feel free to fix it. | 348 | * that then feel free to fix it. |
323 | */ | 349 | */ |
324 | 350 | ||
325 | /* Make a local copy of the string -- up | 351 | /* Make a local copy of the string -- up |
326 | * to the the position of the cursor */ | 352 | * to the position of the cursor */ |
327 | matchBuf = (char *) calloc(BUFSIZ, sizeof(char)); | 353 | matchBuf = (char *) calloc(BUFSIZ, sizeof(char)); |
328 | strncpy(matchBuf, parsenextc, cursor); | 354 | strncpy(matchBuf, parsenextc, cursor); |
329 | tmp=matchBuf; | 355 | tmp=matchBuf; |
@@ -346,59 +372,58 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
346 | matches = (char **) NULL; | 372 | matches = (char **) NULL; |
347 | } | 373 | } |
348 | 374 | ||
349 | /* If the word starts in `~', and there is no slash in the word, | 375 | /* If the word starts with `~' and there is no slash in the word, |
350 | * then try completing this word as a username. */ | 376 | * then try completing this word as a username. */ |
377 | |||
378 | /* FIXME -- this check is broken! */ | ||
351 | if (*tmp == '~' && !strchr(tmp, '/')) | 379 | if (*tmp == '~' && !strchr(tmp, '/')) |
352 | matches = username_completion_matches(tmp, &num_matches); | 380 | matches = username_completion_matches(tmp, &num_matches); |
353 | 381 | ||
354 | /* Try to match any executable in our patch, and everything | 382 | /* Try to match any executable in our path and everything |
355 | * in the current working directory that matches. | 383 | * in the current working directory that matches. */ |
356 | */ | ||
357 | if (!matches) | 384 | if (!matches) |
358 | matches = find_path_executable_n_cwd_matches(tmp, &num_matches); | 385 | matches = find_path_executable_n_cwd_matches(tmp, &num_matches); |
386 | |||
387 | /* Don't leak memory */ | ||
388 | free( matchBuf); | ||
389 | |||
390 | /* Did we find exactly one match? */ | ||
391 | if (matches && num_matches==1) { | ||
392 | /* write out the matched command */ | ||
393 | strncpy(parsenextc+pos, matches[0]+pos, strlen(matches[0])-pos); | ||
394 | len=strlen(parsenextc); | ||
395 | cursor=len; | ||
396 | xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos); | ||
397 | break; | ||
398 | } | ||
359 | } else { | 399 | } else { |
400 | /* Ok -- the last char was a TAB. Since they | ||
401 | * just hit TAB again, print a list of all the | ||
402 | * available choices... */ | ||
360 | if ( matches && num_matches>0 ) { | 403 | if ( matches && num_matches>0 ) { |
361 | int i, col; | 404 | int i, col; |
362 | 405 | ||
363 | fprintf(stderr, "\nTabbing...\n"); | 406 | /* Go to the next line */ |
364 | 407 | xwrite(outputFd, "\n", 1); | |
365 | /* Make a list of the matches */ | 408 | /* Print the list of matches */ |
366 | col += xwrite(outputFd, "\n", 1); | ||
367 | for (i=0,col=0; i<num_matches; i++) { | 409 | for (i=0,col=0; i<num_matches; i++) { |
368 | col += xwrite(outputFd, prompt, strlen(matches[i])); | 410 | char foo[17]; |
411 | sprintf(foo, "%-14s ", matches[i]); | ||
412 | col += xwrite(outputFd, foo, strlen(foo)); | ||
369 | if (col > 60 && matches[i+1] != NULL) { | 413 | if (col > 60 && matches[i+1] != NULL) { |
370 | xwrite(outputFd, "\n", 1); | 414 | xwrite(outputFd, "\n", 1); |
371 | col = 0; | 415 | col = 0; |
372 | } | 416 | } |
373 | } | 417 | } |
418 | /* Go to the next line */ | ||
374 | xwrite(outputFd, "\n", 1); | 419 | xwrite(outputFd, "\n", 1); |
375 | 420 | /* Rewrite the prompt */ | |
376 | len+=strlen(prompt); | ||
377 | fprintf(stderr, "len=%d\n", len); | ||
378 | |||
379 | /* Move to the beginning of the line */ | ||
380 | input_home(outputFd, &len); | ||
381 | |||
382 | /* erase everything */ | ||
383 | for (j = 0; j < len; j++) | ||
384 | xwrite(outputFd, " ", 1); | ||
385 | |||
386 | /* return to begining of line */ | ||
387 | input_home(outputFd, &cursor); | ||
388 | |||
389 | /* Rewrite the prompt) */ | ||
390 | xwrite(outputFd, prompt, strlen(prompt)); | 421 | xwrite(outputFd, prompt, strlen(prompt)); |
391 | |||
392 | /* Rewrite the command */ | 422 | /* Rewrite the command */ |
393 | len = strlen(parsenextc); | ||
394 | xwrite(outputFd, parsenextc, len); | 423 | xwrite(outputFd, parsenextc, len); |
395 | 424 | /* Put the cursor back to where it used to be */ | |
396 | /* Move back to where the cursor used to be */ | 425 | for (cursor=len; cursor > pos; cursor--) |
397 | for (cursor=pos; cursor > 0; cursor--) | ||
398 | xwrite(outputFd, "\b", 1); | 426 | xwrite(outputFd, "\b", 1); |
399 | cursor = pos; | ||
400 | |||
401 | //fprintf(stderr, "\nprompt='%s'\n", prompt); | ||
402 | } | 427 | } |
403 | } | 428 | } |
404 | break; | 429 | break; |
@@ -451,7 +476,6 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
451 | /* return to begining of line */ | 476 | /* return to begining of line */ |
452 | for (; cursor > 0; cursor--) | 477 | for (; cursor > 0; cursor--) |
453 | xwrite(outputFd, "\b", 1); | 478 | xwrite(outputFd, "\b", 1); |
454 | xwrite(outputFd, parsenextc, len); | ||
455 | 479 | ||
456 | /* erase old command */ | 480 | /* erase old command */ |
457 | for (j = 0; j < len; j++) | 481 | for (j = 0; j < len; j++) |
@@ -462,6 +486,7 @@ extern int cmdedit_read_input(char* prompt, int inputFd, int outputFd, | |||
462 | xwrite(outputFd, "\b", 1); | 486 | xwrite(outputFd, "\b", 1); |
463 | 487 | ||
464 | memset(parsenextc, 0, BUFSIZ); | 488 | memset(parsenextc, 0, BUFSIZ); |
489 | len = strlen(parsenextc); | ||
465 | /* write new command */ | 490 | /* write new command */ |
466 | strcpy(parsenextc, hp->s); | 491 | strcpy(parsenextc, hp->s); |
467 | len = strlen(hp->s); | 492 | len = strlen(hp->s); |