mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
speed up * 2
This commit is contained in:
parent
1a2f4d9af7
commit
d128b71820
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Another fast dependencies generator for Makefiles, Version 2.2
|
* Another fast dependencies generator for Makefiles, Version 2.3
|
||||||
*
|
*
|
||||||
* Copyright (C) 2005 by Vladimir Oleynik <dzo@simtreas.ru>
|
* Copyright (C) 2005 by Vladimir Oleynik <dzo@simtreas.ru>
|
||||||
* mmaping file may be originally by Linus Torvalds.
|
* mmaping file may be originally by Linus Torvalds.
|
||||||
@ -18,6 +18,7 @@
|
|||||||
* path/file.o: include/config/key*.h found_include_*.h
|
* path/file.o: include/config/key*.h found_include_*.h
|
||||||
* path/inc.h: include/config/key*.h found_included_include_*.h
|
* path/inc.h: include/config/key*.h found_included_include_*.h
|
||||||
* This program does not generate dependencies for #include <...>
|
* This program does not generate dependencies for #include <...>
|
||||||
|
* BUG: all includes name must unique
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LOCAL_INCLUDE_PATH "include"
|
#define LOCAL_INCLUDE_PATH "include"
|
||||||
@ -37,7 +38,6 @@
|
|||||||
"[-k path_for_stored_keys] [dirs]"
|
"[-k path_for_stored_keys] [dirs]"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -55,14 +55,15 @@
|
|||||||
|
|
||||||
typedef struct BB_KEYS {
|
typedef struct BB_KEYS {
|
||||||
char *keyname;
|
char *keyname;
|
||||||
|
size_t key_sz;
|
||||||
const char *value;
|
const char *value;
|
||||||
char *stored_path;
|
char *stored_path;
|
||||||
int checked;
|
char *checked;
|
||||||
struct BB_KEYS *next;
|
struct BB_KEYS *next;
|
||||||
} bb_key_t;
|
} bb_key_t;
|
||||||
|
|
||||||
static bb_key_t *check_key(bb_key_t *k, const char *nk);
|
static bb_key_t *check_key(bb_key_t *k, const char *nk, size_t key_sz);
|
||||||
static bb_key_t *make_new_key(bb_key_t *k, const char *nk);
|
static bb_key_t *make_new_key(bb_key_t *k, const char *nk, size_t key_sz);
|
||||||
|
|
||||||
/* partial and simplified libbb routine */
|
/* partial and simplified libbb routine */
|
||||||
static void bb_error_d(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
|
static void bb_error_d(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
|
||||||
@ -88,8 +89,9 @@ static int mode;
|
|||||||
#define CONFIG_MODE 0
|
#define CONFIG_MODE 0
|
||||||
#define SOURCES_MODE 1
|
#define SOURCES_MODE 1
|
||||||
|
|
||||||
static void parse_inc(const char *include, const char *fname);
|
static void parse_inc(const char *include, const char *fname, size_t key_sz);
|
||||||
static void parse_conf_opt(char *opt, const char *val, size_t rsz);
|
static void parse_conf_opt(const char *opt, const char *val,
|
||||||
|
size_t rsz, size_t key_sz);
|
||||||
|
|
||||||
/* for speed tricks */
|
/* for speed tricks */
|
||||||
static char first_chars[257]; /* + L_EOF */
|
static char first_chars[257]; /* + L_EOF */
|
||||||
@ -102,7 +104,6 @@ static size_t mema_id = 128; /* first allocated for id */
|
|||||||
static char *id_s;
|
static char *id_s;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define yy_error_d(s) bb_error_d("%s:%d hmm, %s", fname, line, s)
|
#define yy_error_d(s) bb_error_d("%s:%d hmm, %s", fname, line, s)
|
||||||
|
|
||||||
/* state */
|
/* state */
|
||||||
@ -150,6 +151,7 @@ static void c_lex(const char *fname, long fsize)
|
|||||||
char *val = NULL;
|
char *val = NULL;
|
||||||
unsigned char *optr, *oend;
|
unsigned char *optr, *oend;
|
||||||
unsigned char *start = NULL; /* stupid initialize */
|
unsigned char *start = NULL; /* stupid initialize */
|
||||||
|
size_t opt_len = 0; /* stupid initialize */
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
char *map;
|
char *map;
|
||||||
@ -176,19 +178,6 @@ static void c_lex(const char *fname, long fsize)
|
|||||||
called = state = S;
|
called = state = S;
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
if(state == LI || state == DV) {
|
|
||||||
/* store "include.h" or config mode #define KEY "|'..."|' */
|
|
||||||
if(state == LI) {
|
|
||||||
put_id(0);
|
|
||||||
parse_inc(id, fname);
|
|
||||||
} else {
|
|
||||||
/* #define KEY "[VAL]" */
|
|
||||||
put_id(c); /* #define KEY "VALUE"<- */
|
|
||||||
put_id(0);
|
|
||||||
parse_conf_opt(id, val, (optr - start));
|
|
||||||
}
|
|
||||||
state = S;
|
|
||||||
}
|
|
||||||
if(prev_state != state) {
|
if(prev_state != state) {
|
||||||
prev_state = state;
|
prev_state = state;
|
||||||
getc1();
|
getc1();
|
||||||
@ -260,8 +249,7 @@ static void c_lex(const char *fname, long fsize)
|
|||||||
put_id(c);
|
put_id(c);
|
||||||
getc1();
|
getc1();
|
||||||
} while(isalnums[c]);
|
} while(isalnums[c]);
|
||||||
put_id(0);
|
check_key(key_top, id, id_len);
|
||||||
check_key(key_top, id);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* <S>\\ */
|
/* <S>\\ */
|
||||||
@ -316,7 +304,15 @@ static void c_lex(const char *fname, long fsize)
|
|||||||
put_id(c);
|
put_id(c);
|
||||||
} else if(c == state) {
|
} else if(c == state) {
|
||||||
/* <STR>\" or <CHR>\' */
|
/* <STR>\" or <CHR>\' */
|
||||||
state = called;
|
if(called == LI) {
|
||||||
|
/* store "include.h" */
|
||||||
|
parse_inc(id, fname, id_len);
|
||||||
|
} else if(called == DV) {
|
||||||
|
put_id(c); /* config mode #define KEY "VAL"<- */
|
||||||
|
put_id(0);
|
||||||
|
parse_conf_opt(id, val, (optr - start), opt_len);
|
||||||
|
}
|
||||||
|
state = S;
|
||||||
break;
|
break;
|
||||||
} else if(val)
|
} else if(val)
|
||||||
put_id(c);
|
put_id(c);
|
||||||
@ -346,18 +342,18 @@ static void c_lex(const char *fname, long fsize)
|
|||||||
if(state == POUND) {
|
if(state == POUND) {
|
||||||
/* tricks */
|
/* tricks */
|
||||||
static const char * const preproc[] = {
|
static const char * const preproc[] = {
|
||||||
/* 0-4 */
|
/* 0-3 */
|
||||||
"", "", "", "", "",
|
"", "", "", "",
|
||||||
/* 5 */ /* 6 */ /* 7 */
|
/* 4 */ /* 5 */ /* 6 */
|
||||||
"undef", "define", "include",
|
"ndef", "efine", "nclude",
|
||||||
};
|
};
|
||||||
size_t diu = first_chars_diu[c]; /* strlen and preproc ptr */
|
size_t diu = first_chars_diu[c]; /* strlen and preproc ptr */
|
||||||
const unsigned char *p = optr - 1;
|
const unsigned char *p = optr;
|
||||||
|
|
||||||
while(isalnums[c]) getc1();
|
while(isalnums[c]) getc1();
|
||||||
/* have str begined with c, readed == strlen key and compared */
|
/* have str begined with c, readed == strlen key and compared */
|
||||||
if(diu != S && diu == (optr-p-1) && !memcmp(p, preproc[diu], diu)) {
|
if(diu != S && diu == (optr-p-1) && !memcmp(p, preproc[diu], diu)) {
|
||||||
state = *p;
|
state = p[-1];
|
||||||
id_len = 0; /* common for save */
|
id_len = 0; /* common for save */
|
||||||
} else {
|
} else {
|
||||||
state = S;
|
state = S;
|
||||||
@ -392,12 +388,12 @@ static void c_lex(const char *fname, long fsize)
|
|||||||
}
|
}
|
||||||
if(!id_len)
|
if(!id_len)
|
||||||
yy_error_d("expected identifier");
|
yy_error_d("expected identifier");
|
||||||
put_id(0);
|
|
||||||
if(state == U) {
|
if(state == U) {
|
||||||
parse_conf_opt(id, NULL, (optr - start));
|
parse_conf_opt(id, NULL, (optr - start), id_len);
|
||||||
state = S;
|
state = S;
|
||||||
} else {
|
} else {
|
||||||
/* D -> DK */
|
/* D -> DK */
|
||||||
|
opt_len = id_len;
|
||||||
state = DK;
|
state = DK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -419,9 +415,10 @@ static void c_lex(const char *fname, long fsize)
|
|||||||
put_id(c);
|
put_id(c);
|
||||||
getc1();
|
getc1();
|
||||||
}
|
}
|
||||||
c = 0;
|
put_id(0);
|
||||||
|
parse_conf_opt(id, val, (optr - start), opt_len);
|
||||||
|
state = S;
|
||||||
ungetc1();
|
ungetc1();
|
||||||
state = DV;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -440,28 +437,28 @@ static llist_t *Iop;
|
|||||||
static bb_key_t *Ifound;
|
static bb_key_t *Ifound;
|
||||||
static int noiwarning;
|
static int noiwarning;
|
||||||
|
|
||||||
static bb_key_t *check_key(bb_key_t *k, const char *nk)
|
static bb_key_t *check_key(bb_key_t *k, const char *nk, size_t key_sz)
|
||||||
{
|
{
|
||||||
bb_key_t *cur;
|
bb_key_t *cur;
|
||||||
|
|
||||||
for(cur = k; cur; cur = cur->next) {
|
for(cur = k; cur; cur = cur->next) {
|
||||||
if(strcmp(cur->keyname, nk) == 0) {
|
if(key_sz == cur->key_sz && memcmp(cur->keyname, nk, key_sz) == 0) {
|
||||||
cur->checked = 1;
|
cur->checked = cur->stored_path;
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bb_key_t *make_new_key(bb_key_t *k, const char *nk)
|
static bb_key_t *make_new_key(bb_key_t *k, const char *nk, size_t key_sz)
|
||||||
{
|
{
|
||||||
bb_key_t *cur;
|
bb_key_t *cur;
|
||||||
size_t nk_size;
|
|
||||||
|
|
||||||
nk_size = strlen(nk) + 1;
|
cur = xmalloc(sizeof(bb_key_t) + key_sz + 1);
|
||||||
cur = xmalloc(sizeof(bb_key_t) + nk_size);
|
cur->keyname = memcpy(cur + 1, nk, key_sz);
|
||||||
cur->keyname = memcpy(cur + 1, nk, nk_size);
|
cur->keyname[key_sz] = '\0';
|
||||||
cur->checked = 0;
|
cur->key_sz = key_sz;
|
||||||
|
cur->checked = NULL;
|
||||||
cur->next = k;
|
cur->next = k;
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
@ -472,7 +469,7 @@ static inline char *store_include_fullpath(char *p_i, bb_key_t *li)
|
|||||||
|
|
||||||
if(access(p_i, F_OK) == 0) {
|
if(access(p_i, F_OK) == 0) {
|
||||||
ok = li->stored_path = bb_simplify_path(p_i);
|
ok = li->stored_path = bb_simplify_path(p_i);
|
||||||
li->checked = 1;
|
li->checked = ok;
|
||||||
} else {
|
} else {
|
||||||
ok = NULL;
|
ok = NULL;
|
||||||
}
|
}
|
||||||
@ -480,33 +477,28 @@ static inline char *store_include_fullpath(char *p_i, bb_key_t *li)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_inc(const char *include, const char *fname)
|
static void parse_inc(const char *include, const char *fname, size_t key_sz)
|
||||||
{
|
{
|
||||||
bb_key_t *li;
|
bb_key_t *li;
|
||||||
char *p_i;
|
char *p_i;
|
||||||
llist_t *lo;
|
llist_t *lo;
|
||||||
|
|
||||||
li = check_key(Ifound, include);
|
li = check_key(Ifound, include, key_sz);
|
||||||
if(li)
|
if(li)
|
||||||
return;
|
return;
|
||||||
Ifound = li = make_new_key(Ifound, include);
|
Ifound = li = make_new_key(Ifound, include, key_sz);
|
||||||
|
include = li->keyname;
|
||||||
if(include[0] != '/') {
|
if(include[0] != '/') {
|
||||||
/* relative */
|
/* relative */
|
||||||
int w;
|
int w;
|
||||||
const char *p;
|
|
||||||
|
|
||||||
p_i = strrchr(fname, '/');
|
p_i = strrchr(fname, '/'); /* fname have absolute pathname */
|
||||||
if(p_i == NULL) {
|
w = (p_i-fname);
|
||||||
p = ".";
|
/* find from current directory of source file */
|
||||||
w = 1;
|
p_i = bb_asprint("%.*s/%s", w, fname, include);
|
||||||
} else {
|
|
||||||
w = (p_i-fname);
|
|
||||||
p = fname;
|
|
||||||
}
|
|
||||||
p_i = bb_asprint("%.*s/%s", w, p, include);
|
|
||||||
if(store_include_fullpath(p_i, li))
|
if(store_include_fullpath(p_i, li))
|
||||||
return;
|
return;
|
||||||
|
/* find from "-I include" specified directories */
|
||||||
for(lo = Iop; lo; lo = lo->link) {
|
for(lo = Iop; lo; lo = lo->link) {
|
||||||
p_i = bb_asprint("%s/%s", lo->data, include);
|
p_i = bb_asprint("%s/%s", lo->data, include);
|
||||||
if(store_include_fullpath(p_i, li))
|
if(store_include_fullpath(p_i, li))
|
||||||
@ -515,8 +507,7 @@ static void parse_inc(const char *include, const char *fname)
|
|||||||
} else {
|
} else {
|
||||||
/* absolute include pathname */
|
/* absolute include pathname */
|
||||||
if(access(include, F_OK) == 0) {
|
if(access(include, F_OK) == 0) {
|
||||||
li->stored_path = bb_xstrdup(include);
|
li->checked = li->stored_path = bb_xstrdup(include);
|
||||||
li->checked = 1;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,89 +516,91 @@ static void parse_inc(const char *include, const char *fname)
|
|||||||
fprintf(stderr, "%s: Warning: #include \"%s\" not found in specified paths\n", fname, include);
|
fprintf(stderr, "%s: Warning: #include \"%s\" not found in specified paths\n", fname, include);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_conf_opt(char *opt, const char *val, size_t recordsz)
|
static void parse_conf_opt(const char *opt, const char *val,
|
||||||
|
size_t recordsz, size_t key_sz)
|
||||||
{
|
{
|
||||||
bb_key_t *cur;
|
bb_key_t *cur;
|
||||||
|
char *k;
|
||||||
char *s, *p;
|
char *s, *p;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int fd;
|
int fd;
|
||||||
int cmp_ok = 0;
|
int cmp_ok = 0;
|
||||||
static char *record_buf;
|
static char *record_buf;
|
||||||
static char *r_cmp;
|
|
||||||
static size_t r_sz;
|
static size_t r_sz;
|
||||||
ssize_t rw_ret;
|
ssize_t rw_ret;
|
||||||
|
|
||||||
cur = check_key(key_top, opt);
|
cur = check_key(key_top, opt, key_sz);
|
||||||
if(cur != NULL) {
|
if(cur != NULL) {
|
||||||
/* present already */
|
/* present already */
|
||||||
cur->checked = 0; /* store only */
|
cur->checked = NULL; /* store only */
|
||||||
if(cur->value == NULL && val == NULL)
|
if(cur->value == NULL && val == NULL)
|
||||||
return;
|
return;
|
||||||
if(cur->value != NULL && val != NULL && strcmp(cur->value, val) == 0)
|
if(cur->value != NULL && val != NULL && !strcmp(cur->value, val))
|
||||||
return;
|
return;
|
||||||
fprintf(stderr, "Warning: redefined %s\n", opt);
|
k = cur->keyname;
|
||||||
|
fprintf(stderr, "Warning: redefined %s\n", k);
|
||||||
} else {
|
} else {
|
||||||
key_top = cur = make_new_key(key_top, opt);
|
key_top = cur = make_new_key(key_top, opt, key_sz);
|
||||||
|
k = cur->keyname;
|
||||||
}
|
}
|
||||||
/* do generate record */
|
/* do generate record */
|
||||||
recordsz += 2; /* \n\0 */
|
recordsz += 2; /* \n\0 */
|
||||||
if(recordsz > r_sz) {
|
if(recordsz > r_sz)
|
||||||
record_buf = xrealloc(record_buf, r_sz=recordsz);
|
record_buf = xrealloc(record_buf, (r_sz = recordsz) * 2);
|
||||||
r_cmp = xrealloc(r_cmp, recordsz);
|
|
||||||
}
|
|
||||||
s = record_buf;
|
s = record_buf;
|
||||||
/* may be short count " " */
|
/* may be short count " " */
|
||||||
if(val) {
|
if(val) {
|
||||||
if(*val == '\0') {
|
if(*val == '\0') {
|
||||||
cur->value = "";
|
cur->value = "";
|
||||||
recordsz = sprintf(s, "#define %s\n", opt);
|
recordsz = sprintf(s, "#define %s\n", k);
|
||||||
} else {
|
} else {
|
||||||
cur->value = bb_xstrdup(val);
|
cur->value = bb_xstrdup(val);
|
||||||
recordsz = sprintf(s, "#define %s %s\n", opt, val);
|
recordsz = sprintf(s, "#define %s %s\n", k, val);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cur->value = NULL;
|
cur->value = NULL;
|
||||||
recordsz = sprintf(s, "#undef %s\n", opt);
|
recordsz = sprintf(s, "#undef %s\n", k);
|
||||||
}
|
}
|
||||||
/* size_t -> ssize_t :( */
|
/* size_t -> ssize_t :( */
|
||||||
rw_ret = (ssize_t)recordsz;
|
rw_ret = (ssize_t)recordsz;
|
||||||
/* trick, save first char KEY for do fast identify id */
|
/* trick, save first char KEY for do fast identify id */
|
||||||
first_chars[(int)*opt] = *opt;
|
first_chars[(int)*k] = *k;
|
||||||
|
|
||||||
|
cur->stored_path = k = bb_asprint("%s/%s.h", kp, k);
|
||||||
/* key converting [A-Z_] -> [a-z/] */
|
/* key converting [A-Z_] -> [a-z/] */
|
||||||
for(p = opt; *p; p++) {
|
for(p = k + kp_len + 1; *p; p++) {
|
||||||
if(*p >= 'A' && *p <= 'Z')
|
if(*p >= 'A' && *p <= 'Z')
|
||||||
*p = *p - 'A' + 'a';
|
*p = *p - 'A' + 'a';
|
||||||
else if(*p == '_' && p[1] > '9') /* do not change A_1 to A/1 */
|
else if(*p == '_' && p[1] > '9') /* do not change A_1 to A/1 */
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
/* check kp/key.h if present after previous usage */
|
/* check kp/key.h if present after previous usage */
|
||||||
cur->stored_path = opt = bb_asprint("%s/%s.h", kp, opt);
|
if(stat(k, &st)) {
|
||||||
if(stat(opt, &st)) {
|
for(p = k + kp_len + 1; *p; p++) {
|
||||||
p = opt + kp_len;
|
|
||||||
while(*++p) {
|
|
||||||
/* Auto-create directories. */
|
/* Auto-create directories. */
|
||||||
if (*p == '/') {
|
if (*p == '/') {
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (access(opt, F_OK) != 0 && mkdir(opt, 0755) != 0)
|
if (access(k, F_OK) != 0 && mkdir(k, 0755) != 0)
|
||||||
bb_error_d("mkdir(%s): %m", opt);
|
bb_error_d("mkdir(%s): %m", k);
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* found */
|
/* found */
|
||||||
if(st.st_size == (off_t)recordsz) {
|
if(st.st_size == (off_t)recordsz) {
|
||||||
fd = open(opt, O_RDONLY);
|
char *r_cmp = s + recordsz;
|
||||||
|
|
||||||
|
fd = open(k, O_RDONLY);
|
||||||
if(fd < 0 || read(fd, r_cmp, recordsz) < rw_ret)
|
if(fd < 0 || read(fd, r_cmp, recordsz) < rw_ret)
|
||||||
bb_error_d("%s: %m", opt);
|
bb_error_d("%s: %m", k);
|
||||||
close(fd);
|
close(fd);
|
||||||
cmp_ok = memcmp(s, r_cmp, recordsz) == 0;
|
cmp_ok = memcmp(s, r_cmp, recordsz) == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!cmp_ok) {
|
if(!cmp_ok) {
|
||||||
fd = open(opt, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
fd = open(k, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
||||||
if(fd < 0 || write(fd, s, recordsz) < rw_ret)
|
if(fd < 0 || write(fd, s, recordsz) < rw_ret)
|
||||||
bb_error_d("%s: %m", opt);
|
bb_error_d("%s: %m", k);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -617,16 +610,16 @@ static int show_dep(int first, bb_key_t *k, const char *name)
|
|||||||
bb_key_t *cur;
|
bb_key_t *cur;
|
||||||
|
|
||||||
for(cur = k; cur; cur = cur->next) {
|
for(cur = k; cur; cur = cur->next) {
|
||||||
if(cur->checked && cur->stored_path) {
|
if(cur->checked) {
|
||||||
if(first) {
|
if(first) {
|
||||||
printf("\n%s:", name);
|
printf("\n%s:", name);
|
||||||
first = 0;
|
first = 0;
|
||||||
} else {
|
} else {
|
||||||
printf(" \\\n ");
|
printf(" \\\n ");
|
||||||
}
|
}
|
||||||
printf(" %s", cur->stored_path);
|
printf(" %s", cur->checked);
|
||||||
}
|
}
|
||||||
cur->checked = 0;
|
cur->checked = NULL;
|
||||||
}
|
}
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
@ -643,9 +636,6 @@ parse_chd(const char *fe, const char *p, size_t dirlen)
|
|||||||
static char *dir_and_entry;
|
static char *dir_and_entry;
|
||||||
static size_t dir_and_entry_sz;
|
static size_t dir_and_entry_sz;
|
||||||
|
|
||||||
if (*fe == '.')
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
df_sz = dirlen + strlen(fe) + 2; /* dir/file\0 */
|
df_sz = dirlen + strlen(fe) + 2; /* dir/file\0 */
|
||||||
if(df_sz > dir_and_entry_sz)
|
if(df_sz > dir_and_entry_sz)
|
||||||
dir_and_entry = xrealloc(dir_and_entry, dir_and_entry_sz = df_sz);
|
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)
|
|||||||
sprintf(fp, "%s/%s", p, fe);
|
sprintf(fp, "%s/%s", p, fe);
|
||||||
|
|
||||||
if(stat(fp, &st)) {
|
if(stat(fp, &st)) {
|
||||||
fprintf(stderr, "Warning: stat(%s): %m", fp);
|
fprintf(stderr, "Warning: stat(%s): %m\n", fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(S_ISREG(st.st_mode)) {
|
if(S_ISREG(st.st_mode)) {
|
||||||
@ -677,17 +667,14 @@ parse_chd(const char *fe, const char *p, size_t dirlen)
|
|||||||
int first;
|
int first;
|
||||||
|
|
||||||
c_lex(fp, st.st_size);
|
c_lex(fp, st.st_size);
|
||||||
fp = bb_simplify_path(fp);
|
|
||||||
if(*e == 'c') {
|
if(*e == 'c') {
|
||||||
/* *.c -> *.o */
|
/* *.c -> *.o */
|
||||||
e = strrchr(fp, '.') + 1;
|
|
||||||
*e = 'o';
|
*e = 'o';
|
||||||
}
|
}
|
||||||
first = show_dep(1, Ifound, fp);
|
first = show_dep(1, Ifound, fp);
|
||||||
first = show_dep(first, key_top, fp);
|
first = show_dep(first, key_top, fp);
|
||||||
if(first == 0)
|
if(first == 0)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
free(fp);
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if(S_ISDIR(st.st_mode)) {
|
} 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)
|
|||||||
return(new_head);
|
return(new_head);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scan_dir_find_ch_files(char *p)
|
static void scan_dir_find_ch_files(const char *p)
|
||||||
{
|
{
|
||||||
llist_t *dirs;
|
llist_t *dirs;
|
||||||
llist_t *d_add;
|
llist_t *d_add;
|
||||||
@ -723,24 +710,26 @@ static void scan_dir_find_ch_files(char *p)
|
|||||||
DIR *dir;
|
DIR *dir;
|
||||||
size_t dirlen;
|
size_t dirlen;
|
||||||
|
|
||||||
dirs = llist_add_to(NULL, p);
|
dirs = llist_add_to(NULL, bb_simplify_path(p));
|
||||||
/* emulate recursive */
|
/* emulate recursive */
|
||||||
while(dirs) {
|
while(dirs) {
|
||||||
d_add = NULL;
|
d_add = NULL;
|
||||||
while(dirs) {
|
while(dirs) {
|
||||||
dir = opendir(dirs->data);
|
dir = opendir(dirs->data);
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
fprintf(stderr, "Warning: opendir(%s): %m", dirs->data);
|
fprintf(stderr, "Warning: opendir(%s): %m\n", dirs->data);
|
||||||
dirlen = strlen(dirs->data);
|
dirlen = strlen(dirs->data);
|
||||||
while ((de = readdir(dir)) != NULL) {
|
while ((de = readdir(dir)) != NULL) {
|
||||||
char *found_dir = parse_chd(de->d_name, dirs->data, dirlen);
|
char *found_dir;
|
||||||
|
|
||||||
|
if (de->d_name[0] == '.')
|
||||||
|
continue;
|
||||||
|
found_dir = parse_chd(de->d_name, dirs->data, dirlen);
|
||||||
if(found_dir)
|
if(found_dir)
|
||||||
d_add = llist_add_to(d_add, found_dir);
|
d_add = llist_add_to(d_add, found_dir);
|
||||||
}
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
if(dirs->data != p)
|
free(dirs->data);
|
||||||
free(dirs->data);
|
|
||||||
d = dirs;
|
d = dirs;
|
||||||
dirs = dirs->link;
|
dirs = dirs->link;
|
||||||
free(d);
|
free(d);
|
||||||
@ -824,9 +813,9 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
first_chars[i] = '-'; /* L_EOF */
|
first_chars[i] = '-'; /* L_EOF */
|
||||||
/* trick for fast find "define", "include", "undef" */
|
/* trick for fast find "define", "include", "undef" */
|
||||||
first_chars_diu[(int)'d'] = (char)6; /* strlen("define"); */
|
first_chars_diu[(int)'d'] = (char)5; /* strlen("define") - 1; */
|
||||||
first_chars_diu[(int)'i'] = (char)7; /* strlen("include"); */
|
first_chars_diu[(int)'i'] = (char)6; /* strlen("include") - 1; */
|
||||||
first_chars_diu[(int)'u'] = (char)5; /* strlen("undef"); */
|
first_chars_diu[(int)'u'] = (char)4; /* strlen("undef") - 1; */
|
||||||
|
|
||||||
/* parse configs */
|
/* parse configs */
|
||||||
for(fl = configs; fl; fl = fl->link) {
|
for(fl = configs; fl; fl = fl->link) {
|
||||||
|
Loading…
Reference in New Issue
Block a user