aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-03 10:08:46 +0000
committer"Vladimir N. Oleynik" <dzo@simtreas.ru>2005-10-03 10:08:46 +0000
commitd128b7182082052626555331ca46b92e478a0cc5 (patch)
tree3ece18a083a04fd88fc9ea1a64503af416d9f8c0
parent1a2f4d9af7b8ec08db75f245e1b513a47c5535d8 (diff)
downloadbusybox-w32-d128b7182082052626555331ca46b92e478a0cc5.tar.gz
busybox-w32-d128b7182082052626555331ca46b92e478a0cc5.tar.bz2
busybox-w32-d128b7182082052626555331ca46b92e478a0cc5.zip
speed up * 2
-rw-r--r--scripts/bb_mkdep.c199
1 files changed, 94 insertions, 105 deletions
diff --git a/scripts/bb_mkdep.c b/scripts/bb_mkdep.c
index e1e4c6348..89b4e997e 100644
--- a/scripts/bb_mkdep.c
+++ b/scripts/bb_mkdep.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Another fast dependencies generator for Makefiles, Version 2.2 2 * Another fast dependencies generator for Makefiles, Version 2.3
3 * 3 *
4 * Copyright (C) 2005 by Vladimir Oleynik <dzo@simtreas.ru> 4 * Copyright (C) 2005 by Vladimir Oleynik <dzo@simtreas.ru>
5 * mmaping file may be originally by Linus Torvalds. 5 * mmaping file may be originally by Linus Torvalds.
@@ -18,6 +18,7 @@
18 * path/file.o: include/config/key*.h found_include_*.h 18 * path/file.o: include/config/key*.h found_include_*.h
19 * path/inc.h: include/config/key*.h found_included_include_*.h 19 * path/inc.h: include/config/key*.h found_included_include_*.h
20 * This program does not generate dependencies for #include <...> 20 * This program does not generate dependencies for #include <...>
21 * BUG: all includes name must unique
21 */ 22 */
22 23
23#define LOCAL_INCLUDE_PATH "include" 24#define LOCAL_INCLUDE_PATH "include"
@@ -37,7 +38,6 @@
37 "[-k path_for_stored_keys] [dirs]" 38 "[-k path_for_stored_keys] [dirs]"
38 39
39 40
40
41#define _GNU_SOURCE 41#define _GNU_SOURCE
42#include <sys/types.h> 42#include <sys/types.h>
43#include <sys/stat.h> 43#include <sys/stat.h>
@@ -55,14 +55,15 @@
55 55
56typedef struct BB_KEYS { 56typedef struct BB_KEYS {
57 char *keyname; 57 char *keyname;
58 size_t key_sz;
58 const char *value; 59 const char *value;
59 char *stored_path; 60 char *stored_path;
60 int checked; 61 char *checked;
61 struct BB_KEYS *next; 62 struct BB_KEYS *next;
62} bb_key_t; 63} bb_key_t;
63 64
64static bb_key_t *check_key(bb_key_t *k, const char *nk); 65static bb_key_t *check_key(bb_key_t *k, const char *nk, size_t key_sz);
65static bb_key_t *make_new_key(bb_key_t *k, const char *nk); 66static bb_key_t *make_new_key(bb_key_t *k, const char *nk, size_t key_sz);
66 67
67/* partial and simplified libbb routine */ 68/* partial and simplified libbb routine */
68static void bb_error_d(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); 69static void bb_error_d(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
@@ -88,8 +89,9 @@ static int mode;
88#define CONFIG_MODE 0 89#define CONFIG_MODE 0
89#define SOURCES_MODE 1 90#define SOURCES_MODE 1
90 91
91static void parse_inc(const char *include, const char *fname); 92static void parse_inc(const char *include, const char *fname, size_t key_sz);
92static void parse_conf_opt(char *opt, const char *val, size_t rsz); 93static void parse_conf_opt(const char *opt, const char *val,
94 size_t rsz, size_t key_sz);
93 95
94/* for speed tricks */ 96/* for speed tricks */
95static char first_chars[257]; /* + L_EOF */ 97static char first_chars[257]; /* + L_EOF */
@@ -102,7 +104,6 @@ static size_t mema_id = 128; /* first allocated for id */
102static char *id_s; 104static char *id_s;
103 105
104 106
105
106#define yy_error_d(s) bb_error_d("%s:%d hmm, %s", fname, line, s) 107#define yy_error_d(s) bb_error_d("%s:%d hmm, %s", fname, line, s)
107 108
108/* state */ 109/* state */
@@ -150,6 +151,7 @@ static void c_lex(const char *fname, long fsize)
150 char *val = NULL; 151 char *val = NULL;
151 unsigned char *optr, *oend; 152 unsigned char *optr, *oend;
152 unsigned char *start = NULL; /* stupid initialize */ 153 unsigned char *start = NULL; /* stupid initialize */
154 size_t opt_len = 0; /* stupid initialize */
153 155
154 int fd; 156 int fd;
155 char *map; 157 char *map;
@@ -176,19 +178,6 @@ static void c_lex(const char *fname, long fsize)
176 called = state = S; 178 called = state = S;
177 179
178 for(;;) { 180 for(;;) {
179 if(state == LI || state == DV) {
180 /* store "include.h" or config mode #define KEY "|'..."|' */
181 if(state == LI) {
182 put_id(0);
183 parse_inc(id, fname);
184 } else {
185 /* #define KEY "[VAL]" */
186 put_id(c); /* #define KEY "VALUE"<- */
187 put_id(0);
188 parse_conf_opt(id, val, (optr - start));
189 }
190 state = S;
191 }
192 if(prev_state != state) { 181 if(prev_state != state) {
193 prev_state = state; 182 prev_state = state;
194 getc1(); 183 getc1();
@@ -260,8 +249,7 @@ static void c_lex(const char *fname, long fsize)
260 put_id(c); 249 put_id(c);
261 getc1(); 250 getc1();
262 } while(isalnums[c]); 251 } while(isalnums[c]);
263 put_id(0); 252 check_key(key_top, id, id_len);
264 check_key(key_top, id);
265 } 253 }
266 } else { 254 } else {
267 /* <S>\\ */ 255 /* <S>\\ */
@@ -316,7 +304,15 @@ static void c_lex(const char *fname, long fsize)
316 put_id(c); 304 put_id(c);
317 } else if(c == state) { 305 } else if(c == state) {
318 /* <STR>\" or <CHR>\' */ 306 /* <STR>\" or <CHR>\' */
319 state = called; 307 if(called == LI) {
308 /* store "include.h" */
309 parse_inc(id, fname, id_len);
310 } else if(called == DV) {
311 put_id(c); /* config mode #define KEY "VAL"<- */
312 put_id(0);
313 parse_conf_opt(id, val, (optr - start), opt_len);
314 }
315 state = S;
320 break; 316 break;
321 } else if(val) 317 } else if(val)
322 put_id(c); 318 put_id(c);
@@ -346,18 +342,18 @@ static void c_lex(const char *fname, long fsize)
346 if(state == POUND) { 342 if(state == POUND) {
347 /* tricks */ 343 /* tricks */
348 static const char * const preproc[] = { 344 static const char * const preproc[] = {
349 /* 0-4 */ 345 /* 0-3 */
350 "", "", "", "", "", 346 "", "", "", "",
351 /* 5 */ /* 6 */ /* 7 */ 347 /* 4 */ /* 5 */ /* 6 */
352 "undef", "define", "include", 348 "ndef", "efine", "nclude",
353 }; 349 };
354 size_t diu = first_chars_diu[c]; /* strlen and preproc ptr */ 350 size_t diu = first_chars_diu[c]; /* strlen and preproc ptr */
355 const unsigned char *p = optr - 1; 351 const unsigned char *p = optr;
356 352
357 while(isalnums[c]) getc1(); 353 while(isalnums[c]) getc1();
358 /* have str begined with c, readed == strlen key and compared */ 354 /* have str begined with c, readed == strlen key and compared */
359 if(diu != S && diu == (optr-p-1) && !memcmp(p, preproc[diu], diu)) { 355 if(diu != S && diu == (optr-p-1) && !memcmp(p, preproc[diu], diu)) {
360 state = *p; 356 state = p[-1];
361 id_len = 0; /* common for save */ 357 id_len = 0; /* common for save */
362 } else { 358 } else {
363 state = S; 359 state = S;
@@ -392,12 +388,12 @@ static void c_lex(const char *fname, long fsize)
392 } 388 }
393 if(!id_len) 389 if(!id_len)
394 yy_error_d("expected identifier"); 390 yy_error_d("expected identifier");
395 put_id(0);
396 if(state == U) { 391 if(state == U) {
397 parse_conf_opt(id, NULL, (optr - start)); 392 parse_conf_opt(id, NULL, (optr - start), id_len);
398 state = S; 393 state = S;
399 } else { 394 } else {
400 /* D -> DK */ 395 /* D -> DK */
396 opt_len = id_len;
401 state = DK; 397 state = DK;
402 } 398 }
403 } 399 }
@@ -419,9 +415,10 @@ static void c_lex(const char *fname, long fsize)
419 put_id(c); 415 put_id(c);
420 getc1(); 416 getc1();
421 } 417 }
422 c = 0; 418 put_id(0);
419 parse_conf_opt(id, val, (optr - start), opt_len);
420 state = S;
423 ungetc1(); 421 ungetc1();
424 state = DV;
425 continue; 422 continue;
426 } 423 }
427 } 424 }
@@ -440,28 +437,28 @@ static llist_t *Iop;
440static bb_key_t *Ifound; 437static bb_key_t *Ifound;
441static int noiwarning; 438static int noiwarning;
442 439
443static bb_key_t *check_key(bb_key_t *k, const char *nk) 440static bb_key_t *check_key(bb_key_t *k, const char *nk, size_t key_sz)
444{ 441{
445 bb_key_t *cur; 442 bb_key_t *cur;
446 443
447 for(cur = k; cur; cur = cur->next) { 444 for(cur = k; cur; cur = cur->next) {
448 if(strcmp(cur->keyname, nk) == 0) { 445 if(key_sz == cur->key_sz && memcmp(cur->keyname, nk, key_sz) == 0) {
449 cur->checked = 1; 446 cur->checked = cur->stored_path;
450 return cur; 447 return cur;
451 } 448 }
452 } 449 }
453 return NULL; 450 return NULL;
454} 451}
455 452
456static bb_key_t *make_new_key(bb_key_t *k, const char *nk) 453static bb_key_t *make_new_key(bb_key_t *k, const char *nk, size_t key_sz)
457{ 454{
458 bb_key_t *cur; 455 bb_key_t *cur;
459 size_t nk_size;
460 456
461 nk_size = strlen(nk) + 1; 457 cur = xmalloc(sizeof(bb_key_t) + key_sz + 1);
462 cur = xmalloc(sizeof(bb_key_t) + nk_size); 458 cur->keyname = memcpy(cur + 1, nk, key_sz);
463 cur->keyname = memcpy(cur + 1, nk, nk_size); 459 cur->keyname[key_sz] = '\0';
464 cur->checked = 0; 460 cur->key_sz = key_sz;
461 cur->checked = NULL;
465 cur->next = k; 462 cur->next = k;
466 return cur; 463 return cur;
467} 464}
@@ -472,7 +469,7 @@ static inline char *store_include_fullpath(char *p_i, bb_key_t *li)
472 469
473 if(access(p_i, F_OK) == 0) { 470 if(access(p_i, F_OK) == 0) {
474 ok = li->stored_path = bb_simplify_path(p_i); 471 ok = li->stored_path = bb_simplify_path(p_i);
475 li->checked = 1; 472 li->checked = ok;
476 } else { 473 } else {
477 ok = NULL; 474 ok = NULL;
478 } 475 }
@@ -480,33 +477,28 @@ static inline char *store_include_fullpath(char *p_i, bb_key_t *li)
480 return ok; 477 return ok;
481} 478}
482 479
483static void parse_inc(const char *include, const char *fname) 480static void parse_inc(const char *include, const char *fname, size_t key_sz)
484{ 481{
485 bb_key_t *li; 482 bb_key_t *li;
486 char *p_i; 483 char *p_i;
487 llist_t *lo; 484 llist_t *lo;
488 485
489 li = check_key(Ifound, include); 486 li = check_key(Ifound, include, key_sz);
490 if(li) 487 if(li)
491 return; 488 return;
492 Ifound = li = make_new_key(Ifound, include); 489 Ifound = li = make_new_key(Ifound, include, key_sz);
493 490 include = li->keyname;
494 if(include[0] != '/') { 491 if(include[0] != '/') {
495 /* relative */ 492 /* relative */
496 int w; 493 int w;
497 const char *p;
498 494
499 p_i = strrchr(fname, '/'); 495 p_i = strrchr(fname, '/'); /* fname have absolute pathname */
500 if(p_i == NULL) { 496 w = (p_i-fname);
501 p = "."; 497 /* find from current directory of source file */
502 w = 1; 498 p_i = bb_asprint("%.*s/%s", w, fname, include);
503 } else {
504 w = (p_i-fname);
505 p = fname;
506 }
507 p_i = bb_asprint("%.*s/%s", w, p, include);
508 if(store_include_fullpath(p_i, li)) 499 if(store_include_fullpath(p_i, li))
509 return; 500 return;
501 /* find from "-I include" specified directories */
510 for(lo = Iop; lo; lo = lo->link) { 502 for(lo = Iop; lo; lo = lo->link) {
511 p_i = bb_asprint("%s/%s", lo->data, include); 503 p_i = bb_asprint("%s/%s", lo->data, include);
512 if(store_include_fullpath(p_i, li)) 504 if(store_include_fullpath(p_i, li))
@@ -515,8 +507,7 @@ static void parse_inc(const char *include, const char *fname)
515 } else { 507 } else {
516 /* absolute include pathname */ 508 /* absolute include pathname */
517 if(access(include, F_OK) == 0) { 509 if(access(include, F_OK) == 0) {
518 li->stored_path = bb_xstrdup(include); 510 li->checked = li->stored_path = bb_xstrdup(include);
519 li->checked = 1;
520 return; 511 return;
521 } 512 }
522 } 513 }
@@ -525,89 +516,91 @@ static void parse_inc(const char *include, const char *fname)
525 fprintf(stderr, "%s: Warning: #include \"%s\" not found in specified paths\n", fname, include); 516 fprintf(stderr, "%s: Warning: #include \"%s\" not found in specified paths\n", fname, include);
526} 517}
527 518
528static void parse_conf_opt(char *opt, const char *val, size_t recordsz) 519static void parse_conf_opt(const char *opt, const char *val,
520 size_t recordsz, size_t key_sz)
529{ 521{
530 bb_key_t *cur; 522 bb_key_t *cur;
523 char *k;
531 char *s, *p; 524 char *s, *p;
532 struct stat st; 525 struct stat st;
533 int fd; 526 int fd;
534 int cmp_ok = 0; 527 int cmp_ok = 0;
535 static char *record_buf; 528 static char *record_buf;
536 static char *r_cmp;
537 static size_t r_sz; 529 static size_t r_sz;
538 ssize_t rw_ret; 530 ssize_t rw_ret;
539 531
540 cur = check_key(key_top, opt); 532 cur = check_key(key_top, opt, key_sz);
541 if(cur != NULL) { 533 if(cur != NULL) {
542 /* present already */ 534 /* present already */
543 cur->checked = 0; /* store only */ 535 cur->checked = NULL; /* store only */
544 if(cur->value == NULL && val == NULL) 536 if(cur->value == NULL && val == NULL)
545 return; 537 return;
546 if(cur->value != NULL && val != NULL && strcmp(cur->value, val) == 0) 538 if(cur->value != NULL && val != NULL && !strcmp(cur->value, val))
547 return; 539 return;
548 fprintf(stderr, "Warning: redefined %s\n", opt); 540 k = cur->keyname;
541 fprintf(stderr, "Warning: redefined %s\n", k);
549 } else { 542 } else {
550 key_top = cur = make_new_key(key_top, opt); 543 key_top = cur = make_new_key(key_top, opt, key_sz);
544 k = cur->keyname;
551 } 545 }
552 /* do generate record */ 546 /* do generate record */
553 recordsz += 2; /* \n\0 */ 547 recordsz += 2; /* \n\0 */
554 if(recordsz > r_sz) { 548 if(recordsz > r_sz)
555 record_buf = xrealloc(record_buf, r_sz=recordsz); 549 record_buf = xrealloc(record_buf, (r_sz = recordsz) * 2);
556 r_cmp = xrealloc(r_cmp, recordsz);
557 }
558 s = record_buf; 550 s = record_buf;
559 /* may be short count " " */ 551 /* may be short count " " */
560 if(val) { 552 if(val) {
561 if(*val == '\0') { 553 if(*val == '\0') {
562 cur->value = ""; 554 cur->value = "";
563 recordsz = sprintf(s, "#define %s\n", opt); 555 recordsz = sprintf(s, "#define %s\n", k);
564 } else { 556 } else {
565 cur->value = bb_xstrdup(val); 557 cur->value = bb_xstrdup(val);
566 recordsz = sprintf(s, "#define %s %s\n", opt, val); 558 recordsz = sprintf(s, "#define %s %s\n", k, val);
567 } 559 }
568 } else { 560 } else {
569 cur->value = NULL; 561 cur->value = NULL;
570 recordsz = sprintf(s, "#undef %s\n", opt); 562 recordsz = sprintf(s, "#undef %s\n", k);
571 } 563 }
572 /* size_t -> ssize_t :( */ 564 /* size_t -> ssize_t :( */
573 rw_ret = (ssize_t)recordsz; 565 rw_ret = (ssize_t)recordsz;
574 /* trick, save first char KEY for do fast identify id */ 566 /* trick, save first char KEY for do fast identify id */
575 first_chars[(int)*opt] = *opt; 567 first_chars[(int)*k] = *k;
576 568
569 cur->stored_path = k = bb_asprint("%s/%s.h", kp, k);
577 /* key converting [A-Z_] -> [a-z/] */ 570 /* key converting [A-Z_] -> [a-z/] */
578 for(p = opt; *p; p++) { 571 for(p = k + kp_len + 1; *p; p++) {
579 if(*p >= 'A' && *p <= 'Z') 572 if(*p >= 'A' && *p <= 'Z')
580 *p = *p - 'A' + 'a'; 573 *p = *p - 'A' + 'a';
581 else if(*p == '_' && p[1] > '9') /* do not change A_1 to A/1 */ 574 else if(*p == '_' && p[1] > '9') /* do not change A_1 to A/1 */
582 *p = '/'; 575 *p = '/';
583 } 576 }
584 /* check kp/key.h if present after previous usage */ 577 /* check kp/key.h if present after previous usage */
585 cur->stored_path = opt = bb_asprint("%s/%s.h", kp, opt); 578 if(stat(k, &st)) {
586 if(stat(opt, &st)) { 579 for(p = k + kp_len + 1; *p; p++) {
587 p = opt + kp_len;
588 while(*++p) {
589 /* Auto-create directories. */ 580 /* Auto-create directories. */
590 if (*p == '/') { 581 if (*p == '/') {
591 *p = '\0'; 582 *p = '\0';
592 if (access(opt, F_OK) != 0 && mkdir(opt, 0755) != 0) 583 if (access(k, F_OK) != 0 && mkdir(k, 0755) != 0)
593 bb_error_d("mkdir(%s): %m", opt); 584 bb_error_d("mkdir(%s): %m", k);
594 *p = '/'; 585 *p = '/';
595 } 586 }
596 } 587 }
597 } else { 588 } else {
598 /* found */ 589 /* found */
599 if(st.st_size == (off_t)recordsz) { 590 if(st.st_size == (off_t)recordsz) {
600 fd = open(opt, O_RDONLY); 591 char *r_cmp = s + recordsz;
592
593 fd = open(k, O_RDONLY);
601 if(fd < 0 || read(fd, r_cmp, recordsz) < rw_ret) 594 if(fd < 0 || read(fd, r_cmp, recordsz) < rw_ret)
602 bb_error_d("%s: %m", opt); 595 bb_error_d("%s: %m", k);
603 close(fd); 596 close(fd);
604 cmp_ok = memcmp(s, r_cmp, recordsz) == 0; 597 cmp_ok = memcmp(s, r_cmp, recordsz) == 0;
605 } 598 }
606 } 599 }
607 if(!cmp_ok) { 600 if(!cmp_ok) {
608 fd = open(opt, O_WRONLY|O_CREAT|O_TRUNC, 0644); 601 fd = open(k, O_WRONLY|O_CREAT|O_TRUNC, 0644);
609 if(fd < 0 || write(fd, s, recordsz) < rw_ret) 602 if(fd < 0 || write(fd, s, recordsz) < rw_ret)
610 bb_error_d("%s: %m", opt); 603 bb_error_d("%s: %m", k);
611 close(fd); 604 close(fd);
612 } 605 }
613} 606}
@@ -617,16 +610,16 @@ static int show_dep(int first, bb_key_t *k, const char *name)
617 bb_key_t *cur; 610 bb_key_t *cur;
618 611
619 for(cur = k; cur; cur = cur->next) { 612 for(cur = k; cur; cur = cur->next) {
620 if(cur->checked && cur->stored_path) { 613 if(cur->checked) {
621 if(first) { 614 if(first) {
622 printf("\n%s:", name); 615 printf("\n%s:", name);
623 first = 0; 616 first = 0;
624 } else { 617 } else {
625 printf(" \\\n "); 618 printf(" \\\n ");
626 } 619 }
627 printf(" %s", cur->stored_path); 620 printf(" %s", cur->checked);
628 } 621 }
629 cur->checked = 0; 622 cur->checked = NULL;
630 } 623 }
631 return first; 624 return first;
632} 625}
@@ -643,9 +636,6 @@ parse_chd(const char *fe, const char *p, size_t dirlen)
643 static char *dir_and_entry; 636 static char *dir_and_entry;
644 static size_t dir_and_entry_sz; 637 static size_t dir_and_entry_sz;
645 638
646 if (*fe == '.')
647 return NULL;
648
649 df_sz = dirlen + strlen(fe) + 2; /* dir/file\0 */ 639 df_sz = dirlen + strlen(fe) + 2; /* dir/file\0 */
650 if(df_sz > dir_and_entry_sz) 640 if(df_sz > dir_and_entry_sz)
651 dir_and_entry = xrealloc(dir_and_entry, dir_and_entry_sz = df_sz); 641 dir_and_entry = xrealloc(dir_and_entry, dir_and_entry_sz = df_sz);
@@ -653,7 +643,7 @@ parse_chd(const char *fe, const char *p, size_t dirlen)
653 sprintf(fp, "%s/%s", p, fe); 643 sprintf(fp, "%s/%s", p, fe);
654 644
655 if(stat(fp, &st)) { 645 if(stat(fp, &st)) {
656 fprintf(stderr, "Warning: stat(%s): %m", fp); 646 fprintf(stderr, "Warning: stat(%s): %m\n", fp);
657 return NULL; 647 return NULL;
658 } 648 }
659 if(S_ISREG(st.st_mode)) { 649 if(S_ISREG(st.st_mode)) {
@@ -677,17 +667,14 @@ parse_chd(const char *fe, const char *p, size_t dirlen)
677 int first; 667 int first;
678 668
679 c_lex(fp, st.st_size); 669 c_lex(fp, st.st_size);
680 fp = bb_simplify_path(fp);
681 if(*e == 'c') { 670 if(*e == 'c') {
682 /* *.c -> *.o */ 671 /* *.c -> *.o */
683 e = strrchr(fp, '.') + 1;
684 *e = 'o'; 672 *e = 'o';
685 } 673 }
686 first = show_dep(1, Ifound, fp); 674 first = show_dep(1, Ifound, fp);
687 first = show_dep(first, key_top, fp); 675 first = show_dep(first, key_top, fp);
688 if(first == 0) 676 if(first == 0)
689 putchar('\n'); 677 putchar('\n');
690 free(fp);
691 } 678 }
692 return NULL; 679 return NULL;
693 } else if(S_ISDIR(st.st_mode)) { 680 } else if(S_ISDIR(st.st_mode)) {
@@ -714,7 +701,7 @@ static inline llist_t *llist_add_to(llist_t *old_head, char *new_item)
714 return(new_head); 701 return(new_head);
715} 702}
716 703
717static void scan_dir_find_ch_files(char *p) 704static void scan_dir_find_ch_files(const char *p)
718{ 705{
719 llist_t *dirs; 706 llist_t *dirs;
720 llist_t *d_add; 707 llist_t *d_add;
@@ -723,24 +710,26 @@ static void scan_dir_find_ch_files(char *p)
723 DIR *dir; 710 DIR *dir;
724 size_t dirlen; 711 size_t dirlen;
725 712
726 dirs = llist_add_to(NULL, p); 713 dirs = llist_add_to(NULL, bb_simplify_path(p));
727 /* emulate recursive */ 714 /* emulate recursive */
728 while(dirs) { 715 while(dirs) {
729 d_add = NULL; 716 d_add = NULL;
730 while(dirs) { 717 while(dirs) {
731 dir = opendir(dirs->data); 718 dir = opendir(dirs->data);
732 if (dir == NULL) 719 if (dir == NULL)
733 fprintf(stderr, "Warning: opendir(%s): %m", dirs->data); 720 fprintf(stderr, "Warning: opendir(%s): %m\n", dirs->data);
734 dirlen = strlen(dirs->data); 721 dirlen = strlen(dirs->data);
735 while ((de = readdir(dir)) != NULL) { 722 while ((de = readdir(dir)) != NULL) {
736 char *found_dir = parse_chd(de->d_name, dirs->data, dirlen); 723 char *found_dir;
737 724
725 if (de->d_name[0] == '.')
726 continue;
727 found_dir = parse_chd(de->d_name, dirs->data, dirlen);
738 if(found_dir) 728 if(found_dir)
739 d_add = llist_add_to(d_add, found_dir); 729 d_add = llist_add_to(d_add, found_dir);
740 } 730 }
741 closedir(dir); 731 closedir(dir);
742 if(dirs->data != p) 732 free(dirs->data);
743 free(dirs->data);
744 d = dirs; 733 d = dirs;
745 dirs = dirs->link; 734 dirs = dirs->link;
746 free(d); 735 free(d);
@@ -824,9 +813,9 @@ int main(int argc, char **argv)
824 } 813 }
825 first_chars[i] = '-'; /* L_EOF */ 814 first_chars[i] = '-'; /* L_EOF */
826 /* trick for fast find "define", "include", "undef" */ 815 /* trick for fast find "define", "include", "undef" */
827 first_chars_diu[(int)'d'] = (char)6; /* strlen("define"); */ 816 first_chars_diu[(int)'d'] = (char)5; /* strlen("define") - 1; */
828 first_chars_diu[(int)'i'] = (char)7; /* strlen("include"); */ 817 first_chars_diu[(int)'i'] = (char)6; /* strlen("include") - 1; */
829 first_chars_diu[(int)'u'] = (char)5; /* strlen("undef"); */ 818 first_chars_diu[(int)'u'] = (char)4; /* strlen("undef") - 1; */
830 819
831 /* parse configs */ 820 /* parse configs */
832 for(fl = configs; fl; fl = fl->link) { 821 for(fl = configs; fl; fl = fl->link) {