diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-02 12:51:26 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-02 12:51:26 +0000 |
commit | fb29038b59fa639b79de99c4edddfa6462918765 (patch) | |
tree | a527be76248ef6d10a5861a2e423d6f049b9d51a /shell | |
parent | 509697f00df5286674fdbdf7b02a57fea83636d0 (diff) | |
download | busybox-w32-fb29038b59fa639b79de99c4edddfa6462918765.tar.gz busybox-w32-fb29038b59fa639b79de99c4edddfa6462918765.tar.bz2 busybox-w32-fb29038b59fa639b79de99c4edddfa6462918765.zip |
libbb: inntroduce and use bb_pstrcmp() and qsort_string_vector()
msh: glob0/glob1/glob2/glob3 are just a sorting routine! remove them.
bb_pstrcmp - 25 +25
qsort_string_vector - 24 +24
expand 2209 2227 +18
getopt32 1359 1370 +11
passwd_main 1072 1074 +2
handle_incoming_and_exit 2737 2735 -2
UNSPEC_print 66 64 -2
forkexec 1343 1339 -4
input_tab 3338 3330 -8
get_dir 185 177 -8
expmeta 481 473 -8
cmdputs 405 397 -8
xstrcmp 12 - -12
find_pair 187 167 -20
match_compare 25 - -25
dir_strcmp 25 - -25
glob2 27 - -27
glob3 34 - -34
glob1 256 - -256
------------------------------------------------------------------------------
(add/remove: 2/6 grow/shrink: 3/8 up/down: 80/-439) Total: -359 bytes
Diffstat (limited to 'shell')
-rw-r--r-- | shell/msh.c | 131 |
1 files changed, 9 insertions, 122 deletions
diff --git a/shell/msh.c b/shell/msh.c index cde18d08f..52a11bc48 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -527,9 +527,6 @@ static int grave(int quoted); | |||
527 | static void globname(char *we, char *pp); | 527 | static void globname(char *we, char *pp); |
528 | static char *generate(char *start1, char *end1, char *middle, char *end); | 528 | static char *generate(char *start1, char *end1, char *middle, char *end); |
529 | static int anyspcl(struct wdblock *wb); | 529 | static int anyspcl(struct wdblock *wb); |
530 | static int xstrcmp(char *p1, char *p2); | ||
531 | static void glob0(char *a0, unsigned a1 | ||
532 | /*, int item_sz, int (*f)(char *, char *) */); | ||
533 | static void readhere(char **name, char *s, int ec); | 530 | static void readhere(char **name, char *s, int ec); |
534 | static int xxchar(struct ioarg *ap); | 531 | static int xxchar(struct ioarg *ap); |
535 | 532 | ||
@@ -4269,11 +4266,11 @@ static struct wdblock *glob(char *cp, struct wdblock *wb) | |||
4269 | DELETE(cl->w_words[i]); | 4266 | DELETE(cl->w_words[i]); |
4270 | DELETE(cl); | 4267 | DELETE(cl); |
4271 | } | 4268 | } |
4272 | for (i = 0; i < cl->w_nword; i++) | ||
4273 | unquote(cl->w_words[i]); | ||
4274 | glob0((char *) cl->w_words, cl->w_nword /*, sizeof(char *), xstrcmp*/); | ||
4275 | if (cl->w_nword) { | 4269 | if (cl->w_nword) { |
4276 | for (i = 0; i < cl->w_nword; i++) | 4270 | for (i = 0; i < cl->w_nword; i++) |
4271 | unquote(cl->w_words[i]); | ||
4272 | qsort_string_vector(cl->w_words, cl->w_nword); | ||
4273 | for (i = 0; i < cl->w_nword; i++) | ||
4277 | wb = addword(cl->w_words[i], wb); | 4274 | wb = addword(cl->w_words[i], wb); |
4278 | DELETE(cl); | 4275 | DELETE(cl); |
4279 | return wb; | 4276 | return wb; |
@@ -4296,11 +4293,13 @@ static void globname(char *we, char *pp) | |||
4296 | for (np = we; np != pp; pp--) | 4293 | for (np = we; np != pp; pp--) |
4297 | if (pp[-1] == '/') | 4294 | if (pp[-1] == '/') |
4298 | break; | 4295 | break; |
4299 | for (dp = cp = get_space((int) (pp - np) + 3); np < pp;) | 4296 | dp = cp = get_space((int) (pp - np) + 3); |
4297 | while (np < pp) | ||
4300 | *cp++ = *np++; | 4298 | *cp++ = *np++; |
4301 | *cp++ = '.'; | 4299 | *cp++ = '.'; |
4302 | *cp = '\0'; | 4300 | *cp = '\0'; |
4303 | for (gp = cp = get_space(strlen(pp) + 1); *np && *np != '/';) | 4301 | gp = cp = get_space(strlen(pp) + 1); |
4302 | while (*np && *np != '/') | ||
4304 | *cp++ = *np++; | 4303 | *cp++ = *np++; |
4305 | *cp = '\0'; | 4304 | *cp = '\0'; |
4306 | dirp = opendir(dp); | 4305 | dirp = opendir(dp); |
@@ -4372,11 +4371,6 @@ static int anyspcl(struct wdblock *wb) | |||
4372 | return 0; | 4371 | return 0; |
4373 | } | 4372 | } |
4374 | 4373 | ||
4375 | static int xstrcmp(char *p1, char *p2) | ||
4376 | { | ||
4377 | return strcmp(*(char **) p1, *(char **) p2); | ||
4378 | } | ||
4379 | |||
4380 | 4374 | ||
4381 | /* -------- word.c -------- */ | 4375 | /* -------- word.c -------- */ |
4382 | 4376 | ||
@@ -4423,118 +4417,11 @@ static char **getwords(struct wdblock *wb) | |||
4423 | } | 4417 | } |
4424 | nb = sizeof(*wd) * wb->w_nword; | 4418 | nb = sizeof(*wd) * wb->w_nword; |
4425 | wd = get_space(nb); | 4419 | wd = get_space(nb); |
4426 | memcpy((char *) wd, (char *) wb->w_words, nb); | 4420 | memcpy(wd, wb->w_words, nb); |
4427 | DELETE(wb); /* perhaps should done by caller */ | 4421 | DELETE(wb); /* perhaps should done by caller */ |
4428 | return wd; | 4422 | return wd; |
4429 | } | 4423 | } |
4430 | 4424 | ||
4431 | /*static int (*cmp_func) (char *, char *);*/ | ||
4432 | /*static int glob_item_sz;*/ | ||
4433 | #define cmp_func xstrcmp | ||
4434 | enum { glob_item_sz = sizeof(char *) }; | ||
4435 | |||
4436 | static void glob3(char *index1, char *index2, char *index3) | ||
4437 | { | ||
4438 | int m = glob_item_sz; | ||
4439 | do { | ||
4440 | char c = *index1; | ||
4441 | *index1++ = *index3; | ||
4442 | *index3++ = *index2; | ||
4443 | *index2++ = c; | ||
4444 | } while (--m); | ||
4445 | } | ||
4446 | |||
4447 | static void glob2(char *index1, char *index2) | ||
4448 | { | ||
4449 | int m = glob_item_sz; | ||
4450 | do { | ||
4451 | char c = *index1; | ||
4452 | *index1++ = *index2; | ||
4453 | *index2++ = c; | ||
4454 | } while (--m); | ||
4455 | } | ||
4456 | |||
4457 | static void glob1(char *base, char *lim) | ||
4458 | { | ||
4459 | char *i, *j; | ||
4460 | int v2; | ||
4461 | char *lptr, *hptr; | ||
4462 | int c; | ||
4463 | unsigned n; | ||
4464 | |||
4465 | v2 = glob_item_sz; | ||
4466 | top: | ||
4467 | n = (int) (lim - base); | ||
4468 | if (n <= v2) | ||
4469 | return; | ||
4470 | n = v2 * (n / (2 * v2)); | ||
4471 | hptr = lptr = base + n; | ||
4472 | i = base; | ||
4473 | j = lim - v2; | ||
4474 | for (;;) { | ||
4475 | if (i < lptr) { | ||
4476 | c = cmp_func(i, lptr); | ||
4477 | if (c == 0) { | ||
4478 | lptr -= v2; | ||
4479 | glob2(i, lptr); | ||
4480 | continue; | ||
4481 | } | ||
4482 | if (c < 0) { | ||
4483 | i += v2; | ||
4484 | continue; | ||
4485 | } | ||
4486 | } | ||
4487 | begin: | ||
4488 | if (j > hptr) { | ||
4489 | c = cmp_func(hptr, j); | ||
4490 | if (c == 0) { | ||
4491 | hptr += v2; | ||
4492 | glob2(hptr, j); | ||
4493 | goto begin; | ||
4494 | } | ||
4495 | if (c > 0) { | ||
4496 | if (i == lptr) { | ||
4497 | hptr += v2; | ||
4498 | glob3(i, hptr, j); | ||
4499 | lptr += v2; | ||
4500 | i = lptr; | ||
4501 | goto begin; | ||
4502 | } | ||
4503 | glob2(i, j); | ||
4504 | j -= v2; | ||
4505 | i += v2; | ||
4506 | continue; | ||
4507 | } | ||
4508 | j -= v2; | ||
4509 | goto begin; | ||
4510 | } | ||
4511 | |||
4512 | if (i == lptr) { | ||
4513 | if (lptr - base >= lim - hptr) { | ||
4514 | glob1(hptr + v2, lim); | ||
4515 | lim = lptr; | ||
4516 | } else { | ||
4517 | glob1(base, lptr); | ||
4518 | base = hptr + v2; | ||
4519 | } | ||
4520 | goto top; | ||
4521 | } | ||
4522 | |||
4523 | lptr -= v2; | ||
4524 | glob3(j, lptr, i); | ||
4525 | hptr -= v2; | ||
4526 | j = hptr; | ||
4527 | } | ||
4528 | } | ||
4529 | |||
4530 | static void glob0(char *a0, unsigned a1 | ||
4531 | /*, int item_sz, int (*f) (char *, char *) */) | ||
4532 | { | ||
4533 | /*cmp_func = f; - always xstrcmp */ | ||
4534 | /*glob_item_sz = item_sz; - always sizeof(char*) */ | ||
4535 | glob1(a0, a0 + a1 * /*item_sz:*/ sizeof(char*)); | ||
4536 | } | ||
4537 | |||
4538 | 4425 | ||
4539 | /* -------- io.c -------- */ | 4426 | /* -------- io.c -------- */ |
4540 | 4427 | ||