aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvodz <vodz@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-09-16 13:57:33 +0000
committervodz <vodz@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-09-16 13:57:33 +0000
commita3b0c4ff6be68fa7bf1b84b7241d067a7c07d8fd (patch)
treec94387a96f27745eb4cc6044e76125c335cec1bb
parentc31c55667e345d745fd1ffd13eb451488c78fd7d (diff)
downloadbusybox-w32-a3b0c4ff6be68fa7bf1b84b7241d067a7c07d8fd.tar.gz
busybox-w32-a3b0c4ff6be68fa7bf1b84b7241d067a7c07d8fd.tar.bz2
busybox-w32-a3b0c4ff6be68fa7bf1b84b7241d067a7c07d8fd.zip
speed up +10%, update (c), make CONFIG_FEATURE_MOD2_4 as config/feature/mod_2_4
git-svn-id: svn://busybox.net/trunk/busybox@11483 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--scripts/bb_mkdep.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/scripts/bb_mkdep.c b/scripts/bb_mkdep.c
index b2e0995ce..4af42b876 100644
--- a/scripts/bb_mkdep.c
+++ b/scripts/bb_mkdep.c
@@ -1,7 +1,13 @@
1/* 1/*
2 * Another fast dependencies generator for Makefiles, Version 2.0 2 * Another fast dependencies generator for Makefiles, Version 2.1
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.
6 *
7 * (c) 2005 Bernhard Fischer:
8 * - commentary typos,
9 * - move "memory exhausted" into msg_enomem,
10 * - more verbose --help output.
5 * 11 *
6 * This program does: 12 * This program does:
7 * 1) find #define KEY VALUE or #undef KEY from include/config.h 13 * 1) find #define KEY VALUE or #undef KEY from include/config.h
@@ -11,7 +17,7 @@
11 * 5) generate dependencies to stdout 17 * 5) generate dependencies to stdout
12 * path/file.o: include/config/key*.h found_include_*.h 18 * path/file.o: include/config/key*.h found_include_*.h
13 * path/inc.h: include/config/key*.h found_included_include_*.h 19 * path/inc.h: include/config/key*.h found_included_include_*.h
14 * This programm does not generate dependencies for #include <...> 20 * This program does not generate dependencies for #include <...>
15 */ 21 */
16 22
17#define LOCAL_INCLUDE_PATH "include" 23#define LOCAL_INCLUDE_PATH "include"
@@ -87,6 +93,7 @@ static void parse_conf_opt(char *opt, const char *val, size_t rsz);
87 93
88/* for speed tricks */ 94/* for speed tricks */
89static char first_chars[257]; /* + L_EOF */ 95static char first_chars[257]; /* + L_EOF */
96static char isalnums[257]; /* + L_EOF */
90/* trick for fast find "define", "include", "undef" */ 97/* trick for fast find "define", "include", "undef" */
91static char first_chars_diu[256]; 98static char first_chars_diu[256];
92 99
@@ -171,11 +178,13 @@ static void c_lex(const char *fname, long fsize)
171 for(;;) { 178 for(;;) {
172 if(state == LI || state == DV) { 179 if(state == LI || state == DV) {
173 /* store "include.h" or config mode #define KEY "|'..."|' */ 180 /* store "include.h" or config mode #define KEY "|'..."|' */
174 put_id(0);
175 if(state == LI) { 181 if(state == LI) {
182 put_id(0);
176 parse_inc(id, fname); 183 parse_inc(id, fname);
177 } else { 184 } else {
178 /* #define KEY "[VAL]" */ 185 /* #define KEY "[VAL]" */
186 put_id(c); /* #define KEY "VALUE"<- */
187 put_id(0);
179 parse_conf_opt(id, val, (optr - start)); 188 parse_conf_opt(id, val, (optr - start));
180 } 189 }
181 state = S; 190 state = S;
@@ -243,14 +252,14 @@ static void c_lex(const char *fname, long fsize)
243 if key with this first char undefined */ 252 if key with this first char undefined */
244 if(first_chars[c] == 0) { 253 if(first_chars[c] == 0) {
245 /* skip <S>[A-Z_a-z0-9]+ */ 254 /* skip <S>[A-Z_a-z0-9]+ */
246 do getc1(); while(ISALNUM(c)); 255 do getc1(); while(isalnums[c]);
247 } else { 256 } else {
248 id_len = 0; 257 id_len = 0;
249 do { 258 do {
250 /* <S>[A-Z_a-z0-9]+ */ 259 /* <S>[A-Z_a-z0-9]+ */
251 put_id(c); 260 put_id(c);
252 getc1(); 261 getc1();
253 } while(ISALNUM(c)); 262 } while(isalnums[c]);
254 put_id(0); 263 put_id(0);
255 check_key(key_top, id); 264 check_key(key_top, id);
256 } 265 }
@@ -307,8 +316,6 @@ static void c_lex(const char *fname, long fsize)
307 put_id(c); 316 put_id(c);
308 } else if(c == state) { 317 } else if(c == state) {
309 /* <STR>\" or <CHR>\' */ 318 /* <STR>\" or <CHR>\' */
310 if(called == DV)
311 put_id(c); /* #define KEY "VALUE"<- */
312 state = called; 319 state = called;
313 break; 320 break;
314 } else if(val) 321 } else if(val)
@@ -337,7 +344,6 @@ static void c_lex(const char *fname, long fsize)
337 yy_error_d("strange preprocessor line"); 344 yy_error_d("strange preprocessor line");
338 } 345 }
339 if(state == POUND) { 346 if(state == POUND) {
340 const unsigned char *p = optr - 1;
341 /* tricks */ 347 /* tricks */
342 static const char * const preproc[] = { 348 static const char * const preproc[] = {
343 /* 0-4 */ 349 /* 0-4 */
@@ -345,15 +351,12 @@ static void c_lex(const char *fname, long fsize)
345 /* 5 */ /* 6 */ /* 7 */ 351 /* 5 */ /* 6 */ /* 7 */
346 "undef", "define", "include", 352 "undef", "define", "include",
347 }; 353 };
348 size_t readed = 0;
349 size_t diu = first_chars_diu[c]; /* strlen and preproc ptr */ 354 size_t diu = first_chars_diu[c]; /* strlen and preproc ptr */
355 const unsigned char *p = optr - 1;
350 356
351 while(ISALNUM(c)) { 357 while(isalnums[c]) getc1();
352 readed++;
353 getc1();
354 }
355 /* have str begined with c, readed == strlen key and compared */ 358 /* have str begined with c, readed == strlen key and compared */
356 if(diu != S && diu == readed && !memcmp(p, preproc[diu], diu)) { 359 if(diu != S && diu == (optr-p-1) && !memcmp(p, preproc[diu], diu)) {
357 state = *p; 360 state = *p;
358 id_len = 0; /* common for save */ 361 id_len = 0; /* common for save */
359 } else { 362 } else {
@@ -378,12 +381,12 @@ static void c_lex(const char *fname, long fsize)
378 if(state == D || state == U) { 381 if(state == D || state == U) {
379 if(mode == SOURCES_MODE) { 382 if(mode == SOURCES_MODE) {
380 /* ignore depend with #define or #undef KEY */ 383 /* ignore depend with #define or #undef KEY */
381 while(ISALNUM(c)) 384 while(isalnums[c])
382 getc1(); 385 getc1();
383 state = S; 386 state = S;
384 } else { 387 } else {
385 /* save KEY from #"define"|"undef" ... */ 388 /* save KEY from #"define"|"undef" ... */
386 while(ISALNUM(c)) { 389 while(isalnums[c]) {
387 put_id(c); 390 put_id(c);
388 getc1(); 391 getc1();
389 } 392 }
@@ -411,7 +414,7 @@ static void c_lex(const char *fname, long fsize)
411 state = c; 414 state = c;
412 continue; 415 continue;
413 } 416 }
414 while(ISALNUM(c)) { 417 while(isalnums[c]) {
415 /* VALUE */ 418 /* VALUE */
416 put_id(c); 419 put_id(c);
417 getc1(); 420 getc1();
@@ -542,10 +545,10 @@ static void parse_conf_opt(char *opt, const char *val, size_t recordsz)
542 if(cur->value != NULL && val != NULL && strcmp(cur->value, val) == 0) 545 if(cur->value != NULL && val != NULL && strcmp(cur->value, val) == 0)
543 return; 546 return;
544 fprintf(stderr, "Warning: redefined %s\n", opt); 547 fprintf(stderr, "Warning: redefined %s\n", opt);
548 } else {
549 key_top = cur = make_new_key(key_top, opt);
545 } 550 }
546 /* new or redefined key, check old key if present after previous usage */ 551 /* do generate record */
547 key_top = cur = make_new_key(key_top, opt);
548
549 recordsz += 2; /* \n\0 */ 552 recordsz += 2; /* \n\0 */
550 if(recordsz > r_sz) { 553 if(recordsz > r_sz) {
551 record_buf = xrealloc(record_buf, r_sz=recordsz); 554 record_buf = xrealloc(record_buf, r_sz=recordsz);
@@ -574,13 +577,13 @@ static void parse_conf_opt(char *opt, const char *val, size_t recordsz)
574 for(p = opt; *p; p++) { 577 for(p = opt; *p; p++) {
575 if(*p >= 'A' && *p <= 'Z') 578 if(*p >= 'A' && *p <= 'Z')
576 *p = *p - 'A' + 'a'; 579 *p = *p - 'A' + 'a';
577 else if(*p == '_') 580 else if(*p == '_' && p[1] > '9') /* do not change A_1 to A/1 */
578 *p = '/'; 581 *p = '/';
579 } 582 }
580 p = bb_asprint("%s/%s.h", kp, opt); 583 /* check kp/key.h if present after previous usage */
581 cur->stored_path = opt = p; 584 cur->stored_path = opt = bb_asprint("%s/%s.h", kp, opt);
582 if(stat(opt, &st)) { 585 if(stat(opt, &st)) {
583 p += kp_len; 586 p = opt + kp_len;
584 while(*++p) { 587 while(*++p) {
585 /* Auto-create directories. */ 588 /* Auto-create directories. */
586 if (*p == '/') { 589 if (*p == '/') {
@@ -812,9 +815,10 @@ int main(int argc, char **argv)
812 pagesizem1 = getpagesize() - 1; 815 pagesizem1 = getpagesize() - 1;
813 id_s = xmalloc(mema_id); 816 id_s = xmalloc(mema_id);
814 for(i = 0; i < 256; i++) { 817 for(i = 0; i < 256; i++) {
818 if(ISALNUM(i))
819 isalnums[i] = i;
815 /* set unparsed chars for speed up of parser */ 820 /* set unparsed chars for speed up of parser */
816 if(!ISALNUM(i) && i != CHR && i != STR && 821 else if(i != CHR && i != STR && i != POUND && i != REM && i != BS)
817 i != POUND && i != REM && i != BS)
818 first_chars[i] = ANY; 822 first_chars[i] = ANY;
819 } 823 }
820 first_chars[i] = '-'; /* L_EOF */ 824 first_chars[i] = '-'; /* L_EOF */