diff options
Diffstat (limited to 'tail.c')
-rw-r--r-- | tail.c | 49 |
1 files changed, 25 insertions, 24 deletions
@@ -156,39 +156,38 @@ void add_file(char *name) | |||
156 | strcpy(files[n_files - 1], name); | 156 | strcpy(files[n_files - 1], name); |
157 | } | 157 | } |
158 | 158 | ||
159 | void checknumbers(const char* name) | ||
160 | { | ||
161 | int test=atoi(name); | ||
162 | if(test){ | ||
163 | units=test; | ||
164 | if(units<0) | ||
165 | units=units-1; | ||
166 | } else { | ||
167 | fatalError("Unrecognised number '%s'\n", name); | ||
168 | } | ||
169 | } | ||
159 | 170 | ||
160 | int tail_main(int argc, char **argv) | 171 | int tail_main(int argc, char **argv) |
161 | { | 172 | { |
162 | int show_headers = 1; | 173 | int show_headers = 1; |
163 | int test; | 174 | int test; |
164 | int opt; | 175 | int opt; |
165 | int optc=0; | ||
166 | char **optv=NULL; | ||
167 | char follow=0; | 176 | char follow=0; |
168 | int sleep_int=1; | 177 | int sleep_int=1; |
169 | int *fd; | 178 | int *fd; |
170 | 179 | ||
171 | opterr = 0; | 180 | opterr = 0; |
172 | 181 | ||
173 | for(opt=0;opt<argc;opt++){ | 182 | while ((opt=getopt(argc,argv,"c:fhn:s:q:v123456789+")) >0) { |
174 | test=atoi(argv[opt]); | ||
175 | if(test){ | ||
176 | units=test; | ||
177 | if(units<0) | ||
178 | units=units-1; | ||
179 | }else{ | ||
180 | optc++; | ||
181 | optv = realloc(optv, optc); | ||
182 | optv[optc - 1] = (char *) malloc(strlen(argv[opt]) + 1); | ||
183 | strcpy(optv[optc - 1], argv[opt]); | ||
184 | } | ||
185 | } | ||
186 | while ((opt=getopt(optc,optv,"c:fhn:s:q:v")) >0) { | ||
187 | 183 | ||
188 | switch (opt) { | 184 | switch (opt) { |
185 | case '1':case '2':case '3':case '4':case '5': | ||
186 | case '6':case '7':case '8':case '9':case '0': | ||
187 | checknumbers(argv[optind-1]); | ||
188 | break; | ||
189 | 189 | ||
190 | #ifndef BB_FEATURE_SIMPLE_TAIL | 190 | #ifndef BB_FEATURE_SIMPLE_TAIL |
191 | |||
192 | case 'c': | 191 | case 'c': |
193 | unit_type = BYTES; | 192 | unit_type = BYTES; |
194 | test = atoi(optarg); | 193 | test = atoi(optarg); |
@@ -248,17 +247,21 @@ int tail_main(int argc, char **argv) | |||
248 | usage(tail_usage); | 247 | usage(tail_usage); |
249 | } | 248 | } |
250 | } | 249 | } |
251 | while (optind <= optc) { | 250 | while (optind <= argc) { |
252 | if(optind==optc) { | 251 | if(optind==argc) { |
253 | if (n_files==0) | 252 | if (n_files==0) |
254 | add_file(STDIN); | 253 | add_file(STDIN); |
255 | else | 254 | else |
256 | break; | 255 | break; |
257 | }else { | 256 | }else { |
258 | if (!strcmp(optv[optind], "-")) | 257 | if (*argv[optind] == '+') { |
258 | checknumbers(argv[optind]); | ||
259 | } | ||
260 | else if (!strcmp(argv[optind], "-")) { | ||
259 | add_file(STDIN); | 261 | add_file(STDIN); |
260 | else | 262 | } else { |
261 | add_file(optv[optind]); | 263 | add_file(argv[optind]); |
264 | } | ||
262 | optind++; | 265 | optind++; |
263 | } | 266 | } |
264 | } | 267 | } |
@@ -325,8 +328,6 @@ int tail_main(int argc, char **argv) | |||
325 | free(buffer); | 328 | free(buffer); |
326 | if(files) | 329 | if(files) |
327 | free(files); | 330 | free(files); |
328 | if(optv) | ||
329 | free(optv); | ||
330 | return 0; | 331 | return 0; |
331 | } | 332 | } |
332 | 333 | ||