diff options
| author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-09-15 14:22:37 +0000 |
|---|---|---|
| committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-09-15 14:22:37 +0000 |
| commit | bea1942a5068cd1a2e83545d71c832ec58d6738d (patch) | |
| tree | 80eabc02e35df39454c6c7965169457f005afb50 | |
| parent | 181bdaae4881009126ff34892ceb1fba0575b3d4 (diff) | |
| download | busybox-w32-bea1942a5068cd1a2e83545d71c832ec58d6738d.tar.gz busybox-w32-bea1942a5068cd1a2e83545d71c832ec58d6738d.tar.bz2 busybox-w32-bea1942a5068cd1a2e83545d71c832ec58d6738d.zip | |
Patch from Tito, Reduces the size of busybox's strings applet from 1900 to
1788 bytes (for strings.o).
git-svn-id: svn://busybox.net/trunk/busybox@7530 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | miscutils/strings.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/miscutils/strings.c b/miscutils/strings.c index 1231a93bd..4778cfb5f 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c | |||
| @@ -37,10 +37,11 @@ | |||
| 37 | 37 | ||
| 38 | int strings_main(int argc, char **argv) | 38 | int strings_main(int argc, char **argv) |
| 39 | { | 39 | { |
| 40 | int n=4, c, i, opt=0, a=0, status=EXIT_SUCCESS; | 40 | int n=4, c, i, opt=0, status=EXIT_SUCCESS; |
| 41 | long t=0, count; | 41 | long t=0, count; |
| 42 | FILE *file; | 42 | FILE *file = stdin; |
| 43 | char *string=NULL; | 43 | char *string=NULL; |
| 44 | const char *fmt="%s: "; | ||
| 44 | 45 | ||
| 45 | while ((i = getopt(argc, argv, "afon:")) > 0) | 46 | while ((i = getopt(argc, argv, "afon:")) > 0) |
| 46 | switch(i) | 47 | switch(i) |
| @@ -66,18 +67,19 @@ int strings_main(int argc, char **argv) | |||
| 66 | i=0; | 67 | i=0; |
| 67 | 68 | ||
| 68 | string=xmalloc(n+1); | 69 | string=xmalloc(n+1); |
| 69 | string[n]='\0'; | 70 | /*string[n]='\0';*/ |
| 70 | n-=1; | 71 | n-=1; |
| 71 | 72 | ||
| 72 | if(!argc ) | 73 | if(argc==0) |
| 73 | { | 74 | { |
| 74 | file = stdin; | 75 | fmt="{%s}: "; |
| 76 | *argv=(char *)bb_msg_standard_input; | ||
| 75 | goto pipe; | 77 | goto pipe; |
| 76 | } | 78 | } |
| 77 | 79 | ||
| 78 | for(a=0;a<argc;a++) | 80 | for( ;*argv!=NULL;*argv++) |
| 79 | { | 81 | { |
| 80 | if((file=fopen(argv[a],"r"))) | 82 | if((file=bb_wfopen(*argv,"r"))) |
| 81 | { | 83 | { |
| 82 | pipe: | 84 | pipe: |
| 83 | 85 | ||
| @@ -93,7 +95,7 @@ pipe: | |||
| 93 | if(i==n) | 95 | if(i==n) |
| 94 | { | 96 | { |
| 95 | if(opt == 1 || opt == 3 ) | 97 | if(opt == 1 || opt == 3 ) |
| 96 | printf("%s: ", (!argv[a])? "{stdin}" : argv[a]); | 98 | printf(fmt,*argv); |
| 97 | if(opt >= 2 ) | 99 | if(opt >= 2 ) |
| 98 | printf("%7lo ", t); | 100 | printf("%7lo ", t); |
| 99 | printf("%s", string); | 101 | printf("%s", string); |
| @@ -114,12 +116,9 @@ pipe: | |||
| 114 | bb_fclose_nonstdin(file); | 116 | bb_fclose_nonstdin(file); |
| 115 | } | 117 | } |
| 116 | else | 118 | else |
| 117 | { | ||
| 118 | bb_perror_msg("%s",argv[a]); | ||
| 119 | status=EXIT_FAILURE; | 119 | status=EXIT_FAILURE; |
| 120 | } | ||
| 121 | } | 120 | } |
| 122 | free(string); | 121 | /*free(string);*/ |
| 123 | exit(status); | 122 | exit(status); |
| 124 | } | 123 | } |
| 125 | 124 | ||
