2005-09-12 18:03:27 +05:30
|
|
|
/*
|
2006-02-16 21:10:24 +05:30
|
|
|
* Another fast dependencies generator for Makefiles, Version 4.2
|
2005-09-12 18:03:27 +05:30
|
|
|
*
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
* Copyright (C) 2005,2006 by Vladimir Oleynik <dzo@simtreas.ru>
|
2005-10-10 17:05:17 +05:30
|
|
|
*
|
2005-09-16 19:27:33 +05:30
|
|
|
* mmaping file may be originally by Linus Torvalds.
|
|
|
|
*
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
* infix parser/evaluator for #if expression
|
|
|
|
* Copyright (c) 2001 Aaron Lehmann <aaronl@vitelus.com>
|
|
|
|
* Copyright (c) 2001 Manuel Novoa III <mjn3@codepoet.org>
|
|
|
|
* Copyright (c) 2003 Vladimir Oleynik <dzo@simtreas.ru>
|
|
|
|
*
|
2005-10-10 17:05:17 +05:30
|
|
|
* bb_simplify_path()
|
|
|
|
* Copyright (C) 2005 Manuel Novoa III <mjn3@codepoet.org>
|
|
|
|
*
|
|
|
|
* xmalloc() bb_xstrdup() bb_error_d():
|
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
|
|
|
*
|
|
|
|
* llist routine
|
|
|
|
* Copyright (C) 2003 Glenn McGrath
|
|
|
|
* Copyright (C) Vladimir Oleynik <dzo@simtreas.ru>
|
|
|
|
*
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
* (c) 2005,2006 Bernhard Fischer:
|
2005-09-16 19:27:33 +05:30
|
|
|
* - commentary typos,
|
|
|
|
* - move "memory exhausted" into msg_enomem,
|
|
|
|
* - more verbose --help output.
|
2005-09-12 18:03:27 +05:30
|
|
|
*
|
2005-09-14 20:39:06 +05:30
|
|
|
* This program does:
|
2006-02-15 17:59:37 +05:30
|
|
|
* 1) find #define KEY VALUE or #undef KEY from include/bb_config.h
|
2005-10-10 17:05:17 +05:30
|
|
|
* 2) recursive find and scan *.[ch] files, but skips scan of include/config/
|
|
|
|
* 3) find #include "*.h" and KEYs using, if not as #define and #undef
|
|
|
|
* 4) generate dependencies to stdout
|
2005-10-06 20:23:43 +05:30
|
|
|
* pwd/file.o: include/config/key*.h found_include_*.h
|
2005-09-12 18:03:27 +05:30
|
|
|
* path/inc.h: include/config/key*.h found_included_include_*.h
|
2005-10-10 17:05:17 +05:30
|
|
|
* 5) save include/config/key*.h if changed after previous usage
|
2005-09-16 19:27:33 +05:30
|
|
|
* This program does not generate dependencies for #include <...>
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
* Config file can have #if #elif #else #ifdef #ifndef #endif lines
|
2005-09-14 20:39:06 +05:30
|
|
|
*/
|
2005-09-12 18:03:27 +05:30
|
|
|
|
|
|
|
#define LOCAL_INCLUDE_PATH "include"
|
|
|
|
#define INCLUDE_CONFIG_PATH LOCAL_INCLUDE_PATH"/config"
|
2006-02-15 17:59:37 +05:30
|
|
|
#define INCLUDE_CONFIG_KEYS_PATH LOCAL_INCLUDE_PATH"/bb_config.h"
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
#define bb_mkdep_full_options \
|
|
|
|
"\nOptions:" \
|
|
|
|
"\n\t-I local_include_path include paths, default: \"" LOCAL_INCLUDE_PATH "\"" \
|
|
|
|
"\n\t-d don't generate depend" \
|
|
|
|
"\n\t-w show warning if include files not found" \
|
|
|
|
"\n\t-k include/config default: \"" INCLUDE_CONFIG_PATH "\"" \
|
|
|
|
"\n\t-c include/config.h configs, default: \"" INCLUDE_CONFIG_KEYS_PATH "\"" \
|
|
|
|
"\n\tdirs_to_scan default \".\""
|
|
|
|
|
|
|
|
#define bb_mkdep_terse_options "Usage: [-I local_include_paths] [-dw] " \
|
|
|
|
"[-k path_for_stored_keys] [dirs]"
|
|
|
|
|
|
|
|
|
2005-09-12 18:03:27 +05:30
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2005-10-10 17:05:17 +05:30
|
|
|
#include <limits.h>
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2006-05-27 01:28:58 +05:30
|
|
|
#ifdef __GNUC__
|
|
|
|
#define ATTRIBUTE __attribute__
|
|
|
|
#else
|
|
|
|
#define ATTRIBUTE(a) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !(defined __USE_ISOC99 || (defined __GLIBC_HAVE_LONG_LONG && defined __USE_MISC))
|
|
|
|
#define strtoll strtol
|
|
|
|
#endif
|
2005-09-14 20:39:06 +05:30
|
|
|
|
|
|
|
/* partial and simplified libbb routine */
|
2006-05-27 01:28:58 +05:30
|
|
|
static void bb_error_d(const char *s, ...) ATTRIBUTE ((noreturn, format (printf, 1, 2)));
|
|
|
|
static char * bb_asprint(const char *format, ...) ATTRIBUTE ((format (printf, 1, 2)));
|
2005-10-10 17:05:17 +05:30
|
|
|
static char *bb_simplify_path(const char *path);
|
2005-09-12 18:03:27 +05:30
|
|
|
|
|
|
|
/* stolen from libbb as is */
|
|
|
|
typedef struct llist_s {
|
|
|
|
char *data;
|
|
|
|
struct llist_s *link;
|
|
|
|
} llist_t;
|
2005-10-10 17:05:17 +05:30
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
static const char msg_enomem[] = "memory exhausted";
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
/* inline realization for fast works */
|
|
|
|
static inline void *xmalloc(size_t size)
|
|
|
|
{
|
|
|
|
void *p = malloc(size);
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
if(p == NULL)
|
|
|
|
bb_error_d(msg_enomem);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *bb_xstrdup(const char *s)
|
|
|
|
{
|
|
|
|
char *r = strdup(s);
|
2005-09-14 20:39:06 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
if(r == NULL)
|
|
|
|
bb_error_d(msg_enomem);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dontgenerate_dep; /* flag -d usaged */
|
|
|
|
static int noiwarning; /* flag -w usaged */
|
|
|
|
static llist_t *configs; /* list of -c usaged and them stat() after parsed */
|
|
|
|
static llist_t *Iop; /* list of -I include usaged */
|
|
|
|
|
|
|
|
static char *pwd; /* current work directory */
|
2006-02-14 16:13:40 +05:30
|
|
|
static size_t replace; /* replace current work directory with build dir */
|
2005-10-10 17:05:17 +05:30
|
|
|
|
2006-02-14 14:53:25 +05:30
|
|
|
static const char *kp; /* KEY path, argument of -k used */
|
2005-10-10 17:05:17 +05:30
|
|
|
static size_t kp_len;
|
|
|
|
static struct stat st_kp; /* stat(kp) */
|
|
|
|
|
|
|
|
typedef struct BB_KEYS {
|
|
|
|
char *keyname;
|
|
|
|
size_t key_sz;
|
|
|
|
const char *value;
|
|
|
|
const char *checked;
|
|
|
|
char *stored_path;
|
|
|
|
const char *src_have_this_key;
|
|
|
|
struct BB_KEYS *next;
|
|
|
|
} bb_key_t;
|
|
|
|
|
|
|
|
static bb_key_t *key_top; /* list of found KEYs */
|
|
|
|
static bb_key_t *Ifound; /* list of parsed includes */
|
|
|
|
|
|
|
|
|
|
|
|
static void parse_conf_opt(const char *opt, const char *val, size_t key_sz);
|
|
|
|
static void parse_inc(const char *include, const char *fname);
|
|
|
|
|
|
|
|
static inline bb_key_t *check_key(bb_key_t *k, const char *nk, size_t key_sz)
|
|
|
|
{
|
|
|
|
bb_key_t *cur;
|
|
|
|
|
|
|
|
for(cur = k; cur; cur = cur->next) {
|
|
|
|
if(key_sz == cur->key_sz && memcmp(cur->keyname, nk, key_sz) == 0) {
|
|
|
|
cur->checked = cur->stored_path;
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
static inline const char *lookup_key(const char *nk, size_t key_sz)
|
|
|
|
{
|
|
|
|
bb_key_t *cur;
|
|
|
|
|
|
|
|
for(cur = key_top; cur; cur = cur->next) {
|
|
|
|
if(key_sz == cur->key_sz && memcmp(cur->keyname, nk, key_sz) == 0) {
|
|
|
|
return cur->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
/* for lexical analyser */
|
|
|
|
static int pagesizem1; /* padding mask = getpagesize() - 1 */
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
/* for speed tricks */
|
2005-10-10 17:05:17 +05:30
|
|
|
static char first_chars[1+UCHAR_MAX]; /* + L_EOF */
|
|
|
|
static char isalnums[1+UCHAR_MAX]; /* + L_EOF */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
|
|
|
|
/* trick for fast find "define", "include", "undef",
|
|
|
|
"if((n)def)" "else", "endif" */
|
|
|
|
static const char * const preproc[] = {
|
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 */
|
|
|
|
"", "efine", "lif", "lse", "ndif", "f", "fdef", "fndef", "nclude", "ndef" };
|
|
|
|
static const unsigned char first_chars_deiu[UCHAR_MAX] = {
|
|
|
|
[(int)'d'] = (unsigned char)(1|0x10), /* define */
|
|
|
|
[(int)'e'] = (unsigned char)(2|0x40), /* elif, else, endif */
|
|
|
|
[(int)'i'] = (unsigned char)(5|0x80), /* if ifdef ifndef include */
|
|
|
|
[(int)'u'] = (unsigned char)(9|0x90), /* undef */
|
2005-10-07 21:06:26 +05:30
|
|
|
};
|
2005-09-12 22:09:47 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
#define CONFIG_MODE 0
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
#define IF0_MODE 1 /* #if 0 */
|
|
|
|
#define IF1_MODE 2 /* #if 1 */
|
|
|
|
#define ELSE0_MODE 4 /* #else found after #if 0 */
|
|
|
|
#define ELSE1_MODE 8 /* #else found after #if 1 */
|
|
|
|
#define ELIF1_MODE 16 /* #elif found after #if 1 */
|
|
|
|
#define FALSE_MODES (IF0_MODE|ELSE1_MODE|ELIF1_MODE)
|
2005-09-14 20:39:06 +05:30
|
|
|
|
2005-09-12 18:03:27 +05:30
|
|
|
#define yy_error_d(s) bb_error_d("%s:%d hmm, %s", fname, line, s)
|
|
|
|
|
|
|
|
/* state */
|
|
|
|
#define S 0 /* start state */
|
|
|
|
#define STR '"' /* string */
|
|
|
|
#define CHR '\'' /* char */
|
2005-09-13 22:20:53 +05:30
|
|
|
#define REM '/' /* block comment */
|
|
|
|
#define BS '\\' /* back slash */
|
2005-09-12 18:03:27 +05:30
|
|
|
#define POUND '#' /* # */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
#define D '1' /* #define preprocessor's directive */
|
|
|
|
#define EI '2' /* #elif preprocessor's directive */
|
|
|
|
#define E '3' /* #else preprocessor's directive */
|
|
|
|
#define EF '4' /* #endif preprocessor's directive */
|
|
|
|
#define F '5' /* #if preprocessor's directive */
|
|
|
|
#define IFD '6' /* #ifdef preprocessor's directive */
|
|
|
|
#define IFND '7' /* #ifndef preprocessor's directive */
|
|
|
|
#define I '8' /* #include preprocessor's directive */
|
|
|
|
#define U '9' /* #undef preprocessor's directive */
|
2005-09-12 18:03:27 +05:30
|
|
|
#define DK 'K' /* #define KEY... (config mode) */
|
2005-09-13 22:20:53 +05:30
|
|
|
#define ANY '*' /* any unparsed chars */
|
2005-09-12 18:03:27 +05:30
|
|
|
|
|
|
|
/* [A-Z_a-z] */
|
|
|
|
#define ID(c) ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_')
|
|
|
|
/* [A-Z_a-z0-9] */
|
|
|
|
#define ISALNUM(c) (ID(c) || (c >= '0' && c <= '9'))
|
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
#define L_EOF (1+UCHAR_MAX)
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
#define getc0() do { c = (optr >= oend) ? L_EOF : *optr++; } while(0)
|
|
|
|
|
|
|
|
#define getc1() do { getc0(); if(c == BS) { getc0(); \
|
|
|
|
if(c == '\n') { line++; continue; } \
|
|
|
|
else { optr--; c = BS; } \
|
|
|
|
} break; } while(1)
|
|
|
|
|
|
|
|
static char id_s[4096];
|
|
|
|
#define put_id(ic) do { if(id_len == sizeof(id_s)) goto too_long; \
|
|
|
|
id[id_len++] = ic; } while(0)
|
2005-09-12 18:03:27 +05:30
|
|
|
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
static char ifcpp_stack[1024];
|
|
|
|
static int ptr_ifcpp_stack;
|
|
|
|
#define push_mode() do { \
|
|
|
|
if(ptr_ifcpp_stack == (int)sizeof(ifcpp_stack)) \
|
|
|
|
yy_error_d("#if* stack overflow"); \
|
|
|
|
ifcpp_stack[ptr_ifcpp_stack++] = (char)mode; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define pop_mode() do { \
|
|
|
|
if(ptr_ifcpp_stack == 0) \
|
|
|
|
yy_error_d("unexpected #endif"); \
|
|
|
|
mode = ifcpp_stack[--ptr_ifcpp_stack]; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/* #if expression */
|
|
|
|
typedef long long arith_t;
|
|
|
|
|
|
|
|
static arith_t arith (const char *expr, int *perrcode);
|
|
|
|
|
|
|
|
/* The code uses a simple two-stack algorithm. See
|
|
|
|
* http://www.onthenet.com.au/~grahamis/int2008/week02/lect02.html
|
|
|
|
* for a detailed explanation of the infix-to-postfix algorithm on which
|
|
|
|
* this is based (this code differs in that it applies operators immediately
|
|
|
|
* to the stack instead of adding them to a queue to end up with an
|
|
|
|
* expression). */
|
|
|
|
|
|
|
|
#define arith_isspace(arithval) \
|
|
|
|
(arithval == ' ' || arithval == '\v' || arithval == '\t' || arithval == '\f')
|
|
|
|
|
|
|
|
|
|
|
|
typedef unsigned char operator;
|
|
|
|
|
|
|
|
/* An operator's token id is a bit of a bitfield. The lower 5 bits are the
|
|
|
|
* precedence, and 3 high bits are an ID unique across operators of that
|
|
|
|
* precedence. The ID portion is so that multiple operators can have the
|
|
|
|
* same precedence, ensuring that the leftmost one is evaluated first.
|
|
|
|
* Consider * and /. */
|
|
|
|
|
|
|
|
#define tok_decl(prec,id) (((id)<<5)|(prec))
|
|
|
|
#define PREC(op) ((op) & 0x1F)
|
|
|
|
|
|
|
|
#define TOK_LPAREN tok_decl(0,0)
|
|
|
|
|
|
|
|
#define TOK_COMMA tok_decl(1,0)
|
|
|
|
|
|
|
|
/* conditional is right associativity too */
|
|
|
|
#define TOK_CONDITIONAL tok_decl(2,0)
|
|
|
|
#define TOK_CONDITIONAL_SEP tok_decl(2,1)
|
|
|
|
|
|
|
|
#define TOK_OR tok_decl(3,0)
|
|
|
|
|
|
|
|
#define TOK_AND tok_decl(4,0)
|
|
|
|
|
|
|
|
#define TOK_BOR tok_decl(5,0)
|
|
|
|
|
|
|
|
#define TOK_BXOR tok_decl(6,0)
|
|
|
|
|
|
|
|
#define TOK_BAND tok_decl(7,0)
|
|
|
|
|
|
|
|
#define TOK_EQ tok_decl(8,0)
|
|
|
|
#define TOK_NE tok_decl(8,1)
|
|
|
|
|
|
|
|
#define TOK_LT tok_decl(9,0)
|
|
|
|
#define TOK_GT tok_decl(9,1)
|
|
|
|
#define TOK_GE tok_decl(9,2)
|
|
|
|
#define TOK_LE tok_decl(9,3)
|
|
|
|
|
|
|
|
#define TOK_LSHIFT tok_decl(10,0)
|
|
|
|
#define TOK_RSHIFT tok_decl(10,1)
|
|
|
|
|
|
|
|
#define TOK_ADD tok_decl(11,0)
|
|
|
|
#define TOK_SUB tok_decl(11,1)
|
|
|
|
|
|
|
|
#define TOK_MUL tok_decl(12,0)
|
|
|
|
#define TOK_DIV tok_decl(12,1)
|
|
|
|
#define TOK_REM tok_decl(12,2)
|
|
|
|
|
|
|
|
/* For now unary operators. */
|
|
|
|
#define UNARYPREC 13
|
|
|
|
#define TOK_BNOT tok_decl(UNARYPREC,0)
|
|
|
|
#define TOK_NOT tok_decl(UNARYPREC,1)
|
|
|
|
|
|
|
|
#define TOK_UMINUS tok_decl(UNARYPREC+1,0)
|
|
|
|
#define TOK_UPLUS tok_decl(UNARYPREC+1,1)
|
|
|
|
|
2006-02-15 17:59:37 +05:30
|
|
|
#define SPEC_PREC (UNARYPREC+2)
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
|
|
|
|
#define TOK_NUM tok_decl(SPEC_PREC, 0)
|
|
|
|
#define TOK_RPAREN tok_decl(SPEC_PREC, 1)
|
2005-09-14 20:39:06 +05:30
|
|
|
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
#define NUMPTR (*numstackptr)
|
|
|
|
|
|
|
|
typedef struct ARITCH_VAR_NUM {
|
|
|
|
arith_t val;
|
|
|
|
arith_t contidional_second_val;
|
|
|
|
char contidional_second_val_initialized;
|
|
|
|
} v_n_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct CHK_VAR_RECURSIVE_LOOPED {
|
|
|
|
const char *var;
|
|
|
|
size_t var_sz;
|
|
|
|
struct CHK_VAR_RECURSIVE_LOOPED *next;
|
|
|
|
} chk_var_recursive_looped_t;
|
|
|
|
|
|
|
|
static chk_var_recursive_looped_t *prev_chk_var_recursive;
|
|
|
|
|
|
|
|
|
|
|
|
static int arith_lookup_val(const char *var, size_t key_sz, arith_t *pval)
|
|
|
|
{
|
|
|
|
const char * p = lookup_key(var, key_sz);
|
|
|
|
|
|
|
|
if(p) {
|
|
|
|
int errcode;
|
|
|
|
|
|
|
|
/* recursive try as expression */
|
|
|
|
chk_var_recursive_looped_t *cur;
|
|
|
|
chk_var_recursive_looped_t cur_save;
|
|
|
|
|
|
|
|
for(cur = prev_chk_var_recursive; cur; cur = cur->next) {
|
|
|
|
if(cur->var_sz == key_sz && memcmp(cur->var, var, key_sz) == 0) {
|
|
|
|
/* expression recursion loop detected */
|
|
|
|
return -5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* save current lookuped var name */
|
|
|
|
cur = prev_chk_var_recursive;
|
|
|
|
cur_save.var = var;
|
|
|
|
cur_save.var_sz = key_sz;
|
|
|
|
cur_save.next = cur;
|
|
|
|
prev_chk_var_recursive = &cur_save;
|
|
|
|
|
|
|
|
*pval = arith (p, &errcode);
|
|
|
|
/* restore previous ptr after recursiving */
|
|
|
|
prev_chk_var_recursive = cur;
|
|
|
|
return errcode;
|
|
|
|
} else {
|
|
|
|
/* disallow undefined var */
|
|
|
|
fprintf(stderr, "%.*s ", (int)key_sz, var);
|
|
|
|
return -4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "applying" a token means performing it on the top elements on the integer
|
|
|
|
* stack. For a unary operator it will only change the top element, but a
|
|
|
|
* binary operator will pop two arguments and push a result */
|
|
|
|
static inline int
|
|
|
|
arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
|
|
|
|
{
|
|
|
|
v_n_t *numptr_m1;
|
|
|
|
arith_t numptr_val, rez;
|
|
|
|
|
|
|
|
if (NUMPTR == numstack) goto err; /* There is no operator that can work
|
|
|
|
without arguments */
|
|
|
|
numptr_m1 = NUMPTR - 1;
|
|
|
|
|
|
|
|
rez = numptr_m1->val;
|
|
|
|
if (op == TOK_UMINUS)
|
|
|
|
rez *= -1;
|
|
|
|
else if (op == TOK_NOT)
|
|
|
|
rez = !rez;
|
|
|
|
else if (op == TOK_BNOT)
|
|
|
|
rez = ~rez;
|
|
|
|
else if (op != TOK_UPLUS) {
|
|
|
|
/* Binary operators */
|
|
|
|
|
|
|
|
/* check and binary operators need two arguments */
|
|
|
|
if (numptr_m1 == numstack) goto err;
|
|
|
|
|
|
|
|
/* ... and they pop one */
|
|
|
|
--NUMPTR;
|
|
|
|
numptr_val = rez;
|
|
|
|
if (op == TOK_CONDITIONAL) {
|
|
|
|
if(! numptr_m1->contidional_second_val_initialized) {
|
|
|
|
/* protect $((expr1 ? expr2)) without ": expr" */
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
rez = numptr_m1->contidional_second_val;
|
|
|
|
} else if(numptr_m1->contidional_second_val_initialized) {
|
|
|
|
/* protect $((expr1 : expr2)) without "expr ? " */
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
numptr_m1 = NUMPTR - 1;
|
|
|
|
if (op == TOK_CONDITIONAL) {
|
|
|
|
numptr_m1->contidional_second_val = rez;
|
|
|
|
}
|
|
|
|
rez = numptr_m1->val;
|
|
|
|
if (op == TOK_BOR)
|
|
|
|
rez |= numptr_val;
|
|
|
|
else if (op == TOK_OR)
|
|
|
|
rez = numptr_val || rez;
|
|
|
|
else if (op == TOK_BAND)
|
|
|
|
rez &= numptr_val;
|
|
|
|
else if (op == TOK_BXOR)
|
|
|
|
rez ^= numptr_val;
|
|
|
|
else if (op == TOK_AND)
|
|
|
|
rez = rez && numptr_val;
|
|
|
|
else if (op == TOK_EQ)
|
|
|
|
rez = (rez == numptr_val);
|
|
|
|
else if (op == TOK_NE)
|
|
|
|
rez = (rez != numptr_val);
|
|
|
|
else if (op == TOK_GE)
|
|
|
|
rez = (rez >= numptr_val);
|
|
|
|
else if (op == TOK_RSHIFT)
|
|
|
|
rez >>= numptr_val;
|
|
|
|
else if (op == TOK_LSHIFT)
|
|
|
|
rez <<= numptr_val;
|
|
|
|
else if (op == TOK_GT)
|
|
|
|
rez = (rez > numptr_val);
|
|
|
|
else if (op == TOK_LT)
|
|
|
|
rez = (rez < numptr_val);
|
|
|
|
else if (op == TOK_LE)
|
|
|
|
rez = (rez <= numptr_val);
|
|
|
|
else if (op == TOK_MUL)
|
|
|
|
rez *= numptr_val;
|
|
|
|
else if (op == TOK_ADD)
|
|
|
|
rez += numptr_val;
|
|
|
|
else if (op == TOK_SUB)
|
|
|
|
rez -= numptr_val;
|
|
|
|
else if (op == TOK_COMMA)
|
|
|
|
rez = numptr_val;
|
|
|
|
else if (op == TOK_CONDITIONAL_SEP) {
|
|
|
|
if (numptr_m1 == numstack) {
|
|
|
|
/* protect $((expr : expr)) without "expr ? " */
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
numptr_m1->contidional_second_val_initialized = op;
|
|
|
|
numptr_m1->contidional_second_val = numptr_val;
|
|
|
|
}
|
|
|
|
else if (op == TOK_CONDITIONAL) {
|
|
|
|
rez = rez ?
|
|
|
|
numptr_val : numptr_m1->contidional_second_val;
|
|
|
|
}
|
|
|
|
else if(numptr_val==0) /* zero divisor check */
|
|
|
|
return -2;
|
|
|
|
else if (op == TOK_DIV)
|
|
|
|
rez /= numptr_val;
|
|
|
|
else if (op == TOK_REM)
|
|
|
|
rez %= numptr_val;
|
|
|
|
}
|
|
|
|
numptr_m1->val = rez;
|
|
|
|
return 0;
|
|
|
|
err: return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* longest must first */
|
|
|
|
static const char op_tokens[] = {
|
|
|
|
'<','<', 0, TOK_LSHIFT,
|
|
|
|
'>','>', 0, TOK_RSHIFT,
|
|
|
|
'|','|', 0, TOK_OR,
|
|
|
|
'&','&', 0, TOK_AND,
|
|
|
|
'!','=', 0, TOK_NE,
|
|
|
|
'<','=', 0, TOK_LE,
|
|
|
|
'>','=', 0, TOK_GE,
|
|
|
|
'=','=', 0, TOK_EQ,
|
|
|
|
'!', 0, TOK_NOT,
|
|
|
|
'<', 0, TOK_LT,
|
|
|
|
'>', 0, TOK_GT,
|
|
|
|
'|', 0, TOK_BOR,
|
|
|
|
'&', 0, TOK_BAND,
|
|
|
|
'*', 0, TOK_MUL,
|
|
|
|
'/', 0, TOK_DIV,
|
|
|
|
'%', 0, TOK_REM,
|
|
|
|
'+', 0, TOK_ADD,
|
|
|
|
'-', 0, TOK_SUB,
|
|
|
|
'^', 0, TOK_BXOR,
|
|
|
|
'~', 0, TOK_BNOT,
|
|
|
|
',', 0, TOK_COMMA,
|
|
|
|
'?', 0, TOK_CONDITIONAL,
|
|
|
|
':', 0, TOK_CONDITIONAL_SEP,
|
|
|
|
')', 0, TOK_RPAREN,
|
|
|
|
'(', 0, TOK_LPAREN,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
/* ptr to ")" */
|
|
|
|
#define endexpression &op_tokens[sizeof(op_tokens)-7]
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return of a legal variable name (a letter or underscore followed by zero or
|
|
|
|
* more letters, underscores, and digits).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline char *
|
|
|
|
endofname(const char *name)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = (char *) name;
|
|
|
|
if (! ID(*p))
|
|
|
|
return p;
|
|
|
|
while (*++p) {
|
|
|
|
if (! ISALNUM(*p))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static arith_t arith (const char *expr, int *perrcode)
|
|
|
|
{
|
|
|
|
char arithval; /* Current character under analysis */
|
|
|
|
operator lasttok, op;
|
|
|
|
operator prec;
|
|
|
|
|
|
|
|
const char *p = endexpression;
|
|
|
|
int errcode;
|
|
|
|
|
|
|
|
size_t datasizes = strlen(expr) + 2;
|
|
|
|
|
|
|
|
/* Stack of integers */
|
|
|
|
/* The proof that there can be no more than strlen(startbuf)/2+1 integers
|
|
|
|
* in any given correct or incorrect expression is left as an exercise to
|
|
|
|
* the reader. */
|
|
|
|
v_n_t *numstack = alloca(((datasizes)/2)*sizeof(v_n_t)),
|
|
|
|
*numstackptr = numstack;
|
|
|
|
/* Stack of operator tokens */
|
|
|
|
operator *stack = alloca((datasizes) * sizeof(operator)),
|
|
|
|
*stackptr = stack;
|
|
|
|
|
|
|
|
*stackptr++ = lasttok = TOK_LPAREN; /* start off with a left paren */
|
|
|
|
*perrcode = errcode = 0;
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if ((arithval = *expr) == 0) {
|
|
|
|
if (p == endexpression) {
|
|
|
|
/* Null expression. */
|
|
|
|
err:
|
|
|
|
return (*perrcode = -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is only reached after all tokens have been extracted from the
|
|
|
|
* input stream. If there are still tokens on the operator stack, they
|
|
|
|
* are to be applied in order. At the end, there should be a final
|
|
|
|
* result on the integer stack */
|
|
|
|
|
|
|
|
if (expr != endexpression + 1) {
|
|
|
|
/* If we haven't done so already, */
|
|
|
|
/* append a closing right paren */
|
|
|
|
expr = endexpression;
|
|
|
|
/* and let the loop process it. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* At this point, we're done with the expression. */
|
|
|
|
if (numstackptr != numstack+1) {
|
|
|
|
/* ... but if there isn't, it's bad */
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
ret:
|
|
|
|
*perrcode = errcode;
|
|
|
|
return numstack->val;
|
|
|
|
} else {
|
|
|
|
/* Continue processing the expression. */
|
|
|
|
if (arith_isspace(arithval)) {
|
|
|
|
/* Skip whitespace */
|
|
|
|
goto prologue;
|
|
|
|
}
|
|
|
|
if((p = endofname(expr)) != expr) {
|
|
|
|
size_t var_name_size = (p-expr);
|
|
|
|
|
|
|
|
if(var_name_size == 7 &&
|
|
|
|
strncmp(expr, "defined", var_name_size) == 0) {
|
|
|
|
int brace_form = 0;
|
|
|
|
const char *v;
|
|
|
|
|
|
|
|
while(arith_isspace(*p)) p++;
|
|
|
|
if(*p == '(') {
|
|
|
|
p++;
|
|
|
|
while(arith_isspace(*p)) p++;
|
|
|
|
brace_form = 1;
|
|
|
|
}
|
|
|
|
expr = p;
|
|
|
|
if((p = endofname(expr)) == expr)
|
|
|
|
goto err;
|
|
|
|
var_name_size = (p-expr);
|
|
|
|
while(arith_isspace(*p)) p++;
|
|
|
|
if(brace_form && *p++ != ')')
|
|
|
|
goto err;
|
|
|
|
v = lookup_key(expr, var_name_size);
|
|
|
|
numstackptr->val = (v != NULL) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
errcode = arith_lookup_val(expr, var_name_size,
|
|
|
|
&(numstackptr->val));
|
|
|
|
if(errcode) goto ret;
|
|
|
|
}
|
|
|
|
expr = p;
|
|
|
|
num:
|
|
|
|
numstackptr->contidional_second_val_initialized = 0;
|
|
|
|
numstackptr++;
|
|
|
|
lasttok = TOK_NUM;
|
|
|
|
continue;
|
|
|
|
} else if (arithval >= '0' && arithval <= '9') {
|
|
|
|
numstackptr->val = strtoll(expr, (char **) &expr, 0);
|
|
|
|
while(*expr == 'l' || *expr == 'L' || *expr == 'u' ||
|
|
|
|
*expr == 'U')
|
|
|
|
expr++;
|
|
|
|
goto num;
|
|
|
|
}
|
|
|
|
for(p = op_tokens; ; p++) {
|
|
|
|
const char *o;
|
|
|
|
|
|
|
|
if(*p == 0) {
|
|
|
|
/* strange operator not found */
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
for(o = expr; *p && *o == *p; p++)
|
|
|
|
o++;
|
|
|
|
if(! *p) {
|
|
|
|
/* found */
|
|
|
|
expr = o - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* skip tail uncompared token */
|
|
|
|
while(*p)
|
|
|
|
p++;
|
|
|
|
/* skip zero delim */
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
op = p[1];
|
|
|
|
|
|
|
|
/* Plus and minus are binary (not unary) _only_ if the last
|
|
|
|
* token was as number, or a right paren (which pretends to be
|
|
|
|
* a number, since it evaluates to one). Think about it.
|
|
|
|
* It makes sense. */
|
|
|
|
if (lasttok != TOK_NUM) {
|
|
|
|
if(op == TOK_ADD)
|
|
|
|
op = TOK_UPLUS;
|
|
|
|
else if(op == TOK_SUB)
|
|
|
|
op = TOK_UMINUS;
|
|
|
|
}
|
|
|
|
/* We don't want a unary operator to cause recursive descent on the
|
|
|
|
* stack, because there can be many in a row and it could cause an
|
|
|
|
* operator to be evaluated before its argument is pushed onto the
|
|
|
|
* integer stack. */
|
|
|
|
/* But for binary operators, "apply" everything on the operator
|
|
|
|
* stack until we find an operator with a lesser priority than the
|
|
|
|
* one we have just extracted. */
|
|
|
|
/* Left paren is given the lowest priority so it will never be
|
|
|
|
* "applied" in this way.
|
|
|
|
* if associativity is right and priority eq, applied also skip
|
|
|
|
*/
|
|
|
|
prec = PREC(op);
|
|
|
|
if ((prec > 0 && prec < UNARYPREC) || prec == SPEC_PREC) {
|
|
|
|
/* not left paren or unary */
|
|
|
|
if (lasttok != TOK_NUM) {
|
|
|
|
/* binary op must be preceded by a num */
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
while (stackptr != stack) {
|
|
|
|
if (op == TOK_RPAREN) {
|
|
|
|
/* The algorithm employed here is simple: while we don't
|
|
|
|
* hit an open paren nor the bottom of the stack, pop
|
|
|
|
* tokens and apply them */
|
|
|
|
if (stackptr[-1] == TOK_LPAREN) {
|
|
|
|
--stackptr;
|
|
|
|
/* Any operator directly after a */
|
|
|
|
lasttok = TOK_NUM;
|
|
|
|
/* close paren should consider itself binary */
|
|
|
|
goto prologue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
operator prev_prec = PREC(stackptr[-1]);
|
|
|
|
|
|
|
|
if (prev_prec < prec)
|
|
|
|
break;
|
|
|
|
/* check right assoc */
|
|
|
|
if(prev_prec == prec && prec == PREC(TOK_CONDITIONAL))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
errcode = arith_apply(*--stackptr, numstack, &numstackptr);
|
|
|
|
if(errcode) goto ret;
|
|
|
|
}
|
|
|
|
if (op == TOK_RPAREN) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push this operator to the stack and remember it. */
|
|
|
|
*stackptr++ = lasttok = op;
|
|
|
|
|
|
|
|
prologue:
|
|
|
|
++expr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stupid C lexical analyser for configs.h */
|
|
|
|
static void c_lex_config(const char *fname, long fsize)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
2005-10-10 17:05:17 +05:30
|
|
|
int c;
|
2005-09-12 18:03:27 +05:30
|
|
|
int state;
|
|
|
|
int line;
|
2005-09-13 22:20:53 +05:30
|
|
|
char *id = id_s;
|
2006-02-14 14:53:25 +05:30
|
|
|
size_t id_len = 0; /* stupid initialization */
|
2005-09-12 18:03:27 +05:30
|
|
|
unsigned char *optr, *oend;
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
int mode = CONFIG_MODE;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
|
|
|
int fd;
|
|
|
|
char *map;
|
|
|
|
int mapsize;
|
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
if(fsize == 0) {
|
|
|
|
fprintf(stderr, "Warning: %s is empty\n", fname);
|
|
|
|
return;
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
fd = open(fname, O_RDONLY);
|
|
|
|
if(fd < 0) {
|
2005-09-12 18:03:27 +05:30
|
|
|
perror(fname);
|
|
|
|
return;
|
2005-09-13 22:20:53 +05:30
|
|
|
}
|
|
|
|
mapsize = (fsize+pagesizem1) & ~pagesizem1;
|
|
|
|
map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
|
if ((long) map == -1)
|
2005-09-12 18:03:27 +05:30
|
|
|
bb_error_d("%s: mmap: %m", fname);
|
|
|
|
|
2005-09-13 22:20:53 +05:30
|
|
|
optr = (unsigned char *)map;
|
|
|
|
oend = optr + fsize;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
|
|
|
line = 1;
|
2005-10-10 17:05:17 +05:30
|
|
|
state = S;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
|
|
|
for(;;) {
|
2005-10-10 17:05:17 +05:30
|
|
|
getc1();
|
|
|
|
for(;;) {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* [ \t]+ eat first space */
|
|
|
|
while(c == ' ' || c == '\t')
|
|
|
|
getc1();
|
|
|
|
|
|
|
|
if(state == S) {
|
2005-09-13 22:20:53 +05:30
|
|
|
while(first_chars[c] == ANY) {
|
|
|
|
/* <S>unparsed */
|
2005-09-12 18:03:27 +05:30
|
|
|
if(c == '\n')
|
|
|
|
line++;
|
|
|
|
getc1();
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
if(c == L_EOF) {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* <S><<EOF>> */
|
|
|
|
munmap(map, mapsize);
|
|
|
|
close(fd);
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
if(mode != CONFIG_MODE)
|
|
|
|
yy_error_d("expected #endif");
|
2005-09-12 18:03:27 +05:30
|
|
|
return;
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
if(c == REM) {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* <S>/ */
|
2005-10-10 17:05:17 +05:30
|
|
|
getc0();
|
2005-09-13 22:20:53 +05:30
|
|
|
if(c == REM) {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* <S>"//"[^\n]* */
|
2005-10-10 17:05:17 +05:30
|
|
|
do getc0(); while(c != '\n' && c != L_EOF);
|
2005-09-12 18:03:27 +05:30
|
|
|
} else if(c == '*') {
|
2005-10-10 17:05:17 +05:30
|
|
|
/* <S>[/][*] goto parse block comments */
|
|
|
|
break;
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
} else if(c == POUND) {
|
|
|
|
/* <S># */
|
2005-09-12 18:03:27 +05:30
|
|
|
state = c;
|
2005-10-10 17:05:17 +05:30
|
|
|
getc1();
|
2005-09-12 18:03:27 +05:30
|
|
|
} else if(c == STR || c == CHR) {
|
2005-09-13 22:20:53 +05:30
|
|
|
/* <S>\"|\' */
|
2005-10-10 17:05:17 +05:30
|
|
|
int qc = c;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
/* <STR,CHR>. */
|
|
|
|
getc1();
|
|
|
|
if(c == qc) {
|
|
|
|
/* <STR>\" or <CHR>\' */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(c == BS) {
|
|
|
|
/* <STR,CHR>\\ but is not <STR,CHR>\\\n */
|
|
|
|
getc0();
|
|
|
|
}
|
|
|
|
if(c == '\n' || c == L_EOF)
|
|
|
|
yy_error_d("unterminated");
|
|
|
|
}
|
|
|
|
getc1();
|
|
|
|
} else {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* <S>[A-Z_a-z0-9] */
|
2005-09-12 22:09:47 +05:30
|
|
|
|
|
|
|
/* trick for fast drop id
|
|
|
|
if key with this first char undefined */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
if(first_chars[c] == 0 || (mode & FALSE_MODES) != 0) {
|
2005-09-12 22:09:47 +05:30
|
|
|
/* skip <S>[A-Z_a-z0-9]+ */
|
2005-09-16 19:27:33 +05:30
|
|
|
do getc1(); while(isalnums[c]);
|
2005-09-12 22:09:47 +05:30
|
|
|
} else {
|
|
|
|
id_len = 0;
|
|
|
|
do {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* <S>[A-Z_a-z0-9]+ */
|
|
|
|
put_id(c);
|
|
|
|
getc1();
|
2005-09-16 19:27:33 +05:30
|
|
|
} while(isalnums[c]);
|
2005-10-03 15:38:46 +05:30
|
|
|
check_key(key_top, id, id_len);
|
2005-09-12 22:09:47 +05:30
|
|
|
}
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* begin preprocessor states */
|
2005-09-13 22:20:53 +05:30
|
|
|
if(c == L_EOF)
|
2005-09-12 18:03:27 +05:30
|
|
|
yy_error_d("unexpected EOF");
|
2005-09-13 22:20:53 +05:30
|
|
|
if(c == REM) {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* <#.*>/ */
|
2005-10-10 17:05:17 +05:30
|
|
|
getc0();
|
2005-09-13 22:20:53 +05:30
|
|
|
if(c == REM)
|
2005-09-14 20:39:06 +05:30
|
|
|
yy_error_d("detected // in preprocessor line");
|
2005-09-12 18:03:27 +05:30
|
|
|
if(c == '*') {
|
2005-10-10 17:05:17 +05:30
|
|
|
/* <#.*>[/][*] goto parse block comments */
|
|
|
|
break;
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
/* hmm, #.*[/] */
|
|
|
|
yy_error_d("strange preprocessor line");
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
if(state == POUND) {
|
2005-09-14 20:39:06 +05:30
|
|
|
/* tricks */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
int diu = (int)first_chars_deiu[c]; /* preproc ptr */
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
state = S;
|
|
|
|
if(diu != S) {
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
int p_num_str, p_num_max;
|
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
getc1();
|
|
|
|
id_len = 0;
|
|
|
|
while(isalnums[c]) {
|
|
|
|
put_id(c);
|
|
|
|
getc1();
|
|
|
|
}
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
put_id(0);
|
|
|
|
p_num_str = diu & 0xf;
|
|
|
|
p_num_max = diu >> 4;
|
|
|
|
for(diu = p_num_str; diu <= p_num_max; diu++)
|
|
|
|
if(!strcmp(id, preproc[diu])) {
|
|
|
|
state = (diu + '0');
|
|
|
|
/* common */
|
|
|
|
id_len = 0;
|
|
|
|
break;
|
2005-10-10 17:05:17 +05:30
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
} else {
|
2005-10-10 17:05:17 +05:30
|
|
|
while(isalnums[c]) getc1();
|
2005-09-13 22:20:53 +05:30
|
|
|
}
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
} else if(state == EF) {
|
|
|
|
/* #endif */
|
|
|
|
pop_mode();
|
|
|
|
state = S;
|
2005-10-10 17:05:17 +05:30
|
|
|
} else if(state == I) {
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
if(c == STR && (mode & FALSE_MODES) == 0) {
|
2005-09-12 18:03:27 +05:30
|
|
|
/* <I>\" */
|
2005-10-10 17:05:17 +05:30
|
|
|
for(;;) {
|
|
|
|
getc1();
|
|
|
|
if(c == STR)
|
|
|
|
break;
|
|
|
|
if(c == L_EOF)
|
|
|
|
yy_error_d("unexpected EOF");
|
|
|
|
put_id(c);
|
|
|
|
}
|
|
|
|
put_id(0);
|
|
|
|
/* store "include.h" */
|
|
|
|
parse_inc(id, fname);
|
|
|
|
getc1();
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
/* else another (may be wrong) #include ... */
|
|
|
|
state = S;
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
} else if(state == F) {
|
|
|
|
arith_t t;
|
|
|
|
int errcode;
|
|
|
|
|
|
|
|
while(c != '\n' && c != L_EOF) {
|
|
|
|
put_id(c);
|
|
|
|
getc1();
|
|
|
|
}
|
|
|
|
put_id(0);
|
|
|
|
t = arith(id, &errcode);
|
|
|
|
if (errcode < 0) {
|
|
|
|
if (errcode == -2)
|
|
|
|
yy_error_d("divide by zero");
|
|
|
|
else if (errcode == -4)
|
|
|
|
yy_error_d("undefined");
|
|
|
|
else if (errcode == -5)
|
|
|
|
yy_error_d("expression recursion loop detected");
|
|
|
|
else
|
|
|
|
yy_error_d("syntax error");
|
|
|
|
}
|
|
|
|
push_mode();
|
|
|
|
mode = t != 0 ? IF1_MODE : IF0_MODE;
|
|
|
|
state = S;
|
|
|
|
} else if(state == IFD || state == IFND) {
|
|
|
|
/* save KEY from #if(n)def KEY ... */
|
|
|
|
const char *v;
|
|
|
|
|
|
|
|
push_mode();
|
|
|
|
while(isalnums[c]) {
|
|
|
|
put_id(c);
|
|
|
|
getc1();
|
|
|
|
}
|
|
|
|
if(!id_len)
|
|
|
|
yy_error_d("expected identifier");
|
|
|
|
v = lookup_key(id, id_len);
|
|
|
|
mode = IF1_MODE;
|
|
|
|
if(state == IFD && v == NULL)
|
|
|
|
mode = IF0_MODE;
|
|
|
|
else if(state == IFND && v != NULL)
|
|
|
|
mode = IF0_MODE;
|
|
|
|
state = S;
|
|
|
|
} else if(state == EI) {
|
|
|
|
/* #elif */
|
|
|
|
if(mode == CONFIG_MODE || mode == ELSE0_MODE || mode == ELSE1_MODE)
|
|
|
|
yy_error_d("unexpected #elif");
|
|
|
|
if(mode == IF0_MODE) {
|
|
|
|
pop_mode();
|
|
|
|
state = F;
|
|
|
|
} else {
|
|
|
|
mode = ELIF1_MODE;
|
|
|
|
state = S;
|
|
|
|
}
|
|
|
|
} else if(state == E) {
|
|
|
|
if(mode == CONFIG_MODE || mode == ELSE0_MODE || mode == ELSE1_MODE)
|
|
|
|
yy_error_d("unexpected #else");
|
|
|
|
if(mode == IF0_MODE)
|
|
|
|
mode = ELSE0_MODE;
|
|
|
|
else if(mode == IF1_MODE)
|
|
|
|
mode = ELSE1_MODE;
|
|
|
|
state = S;
|
2005-10-10 17:05:17 +05:30
|
|
|
} else if(state == D || state == U) {
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
/* save KEY from #"define"|"undef" ... */
|
|
|
|
while(isalnums[c]) {
|
|
|
|
put_id(c);
|
|
|
|
getc1();
|
|
|
|
}
|
|
|
|
if(!id_len)
|
|
|
|
yy_error_d("expected identifier");
|
|
|
|
if(state == U) {
|
|
|
|
if((mode & FALSE_MODES) == 0)
|
|
|
|
parse_conf_opt(id, NULL, id_len);
|
2005-09-12 18:03:27 +05:30
|
|
|
state = S;
|
|
|
|
} else {
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
/* D -> DK */
|
|
|
|
state = DK;
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
} else {
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
/* state==<DK> #define KEY[ ] */
|
2005-10-10 17:05:17 +05:30
|
|
|
size_t opt_len = id_len;
|
|
|
|
char *val = id + opt_len;
|
|
|
|
char *sp;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
if(c == L_EOF || c == '\n')
|
|
|
|
break;
|
2005-09-12 18:03:27 +05:30
|
|
|
put_id(c);
|
|
|
|
getc1();
|
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
sp = id + id_len;
|
2005-10-03 15:38:46 +05:30
|
|
|
put_id(0);
|
2005-10-10 17:05:17 +05:30
|
|
|
/* trim tail spaces */
|
|
|
|
while(--sp >= val && (*sp == ' ' || *sp == '\t'
|
|
|
|
|| *sp == '\f' || *sp == '\v'))
|
|
|
|
*sp = '\0';
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
if((mode & FALSE_MODES) == 0)
|
|
|
|
parse_conf_opt(id, val, opt_len);
|
2005-10-03 15:38:46 +05:30
|
|
|
state = S;
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
|
|
|
|
/* <REM> */
|
|
|
|
getc0();
|
|
|
|
for(;;) {
|
|
|
|
/* <REM>[^*]+ */
|
|
|
|
while(c != '*') {
|
|
|
|
if(c == '\n') {
|
|
|
|
/* <REM>\n */
|
|
|
|
if(state != S)
|
|
|
|
yy_error_d("unexpected newline");
|
|
|
|
line++;
|
|
|
|
} else if(c == L_EOF)
|
|
|
|
yy_error_d("unexpected EOF");
|
|
|
|
getc0();
|
|
|
|
}
|
|
|
|
/* <REM>[*] */
|
|
|
|
getc0();
|
|
|
|
if(c == REM) {
|
|
|
|
/* <REM>[*][/] */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
too_long:
|
|
|
|
yy_error_d("phrase too long");
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
/* trick for fast find "define", "include", "undef" */
|
|
|
|
static const char first_chars_diu[UCHAR_MAX] = {
|
|
|
|
[(int)'d'] = (char)5, /* strlen("define") - 1; */
|
|
|
|
[(int)'i'] = (char)6, /* strlen("include") - 1; */
|
|
|
|
[(int)'u'] = (char)4, /* strlen("undef") - 1; */
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef D
|
|
|
|
#undef I
|
|
|
|
#undef U
|
|
|
|
#define D '5' /* #define preprocessor's directive */
|
|
|
|
#define I '6' /* #include preprocessor's directive */
|
|
|
|
#define U '4' /* #undef preprocessor's directive */
|
|
|
|
|
|
|
|
/* stupid C lexical analyser for sources */
|
|
|
|
static void c_lex_src(const char *fname, long fsize)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int state;
|
|
|
|
int line;
|
|
|
|
char *id = id_s;
|
2006-02-14 14:53:25 +05:30
|
|
|
size_t id_len = 0; /* stupid initialization */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
unsigned char *optr, *oend;
|
|
|
|
|
|
|
|
int fd;
|
|
|
|
char *map;
|
|
|
|
int mapsize;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
if(fsize == 0) {
|
|
|
|
fprintf(stderr, "Warning: %s is empty\n", fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fd = open(fname, O_RDONLY);
|
|
|
|
if(fd < 0) {
|
|
|
|
perror(fname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mapsize = (fsize+pagesizem1) & ~pagesizem1;
|
|
|
|
map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
|
if ((long) map == -1)
|
|
|
|
bb_error_d("%s: mmap: %m", fname);
|
|
|
|
|
|
|
|
optr = (unsigned char *)map;
|
|
|
|
oend = optr + fsize;
|
|
|
|
|
|
|
|
line = 1;
|
|
|
|
state = S;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
getc1();
|
|
|
|
for(;;) {
|
|
|
|
/* [ \t]+ eat first space */
|
|
|
|
while(c == ' ' || c == '\t')
|
|
|
|
getc1();
|
|
|
|
|
|
|
|
if(state == S) {
|
|
|
|
while(first_chars[c] == ANY) {
|
|
|
|
/* <S>unparsed */
|
|
|
|
if(c == '\n')
|
|
|
|
line++;
|
|
|
|
getc1();
|
|
|
|
}
|
|
|
|
if(c == L_EOF) {
|
|
|
|
/* <S><<EOF>> */
|
|
|
|
munmap(map, mapsize);
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(c == REM) {
|
|
|
|
/* <S>/ */
|
|
|
|
getc0();
|
|
|
|
if(c == REM) {
|
|
|
|
/* <S>"//"[^\n]* */
|
|
|
|
do getc0(); while(c != '\n' && c != L_EOF);
|
|
|
|
} else if(c == '*') {
|
|
|
|
/* <S>[/][*] goto parse block comments */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if(c == POUND) {
|
|
|
|
/* <S># */
|
|
|
|
state = c;
|
|
|
|
getc1();
|
|
|
|
} else if(c == STR || c == CHR) {
|
|
|
|
/* <S>\"|\' */
|
|
|
|
int qc = c;
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
/* <STR,CHR>. */
|
|
|
|
getc1();
|
|
|
|
if(c == qc) {
|
|
|
|
/* <STR>\" or <CHR>\' */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(c == BS) {
|
|
|
|
/* <STR,CHR>\\ but is not <STR,CHR>\\\n */
|
|
|
|
getc0();
|
|
|
|
}
|
|
|
|
if(c == '\n' || c == L_EOF)
|
|
|
|
yy_error_d("unterminated");
|
|
|
|
}
|
|
|
|
getc1();
|
|
|
|
} else {
|
|
|
|
/* <S>[A-Z_a-z0-9] */
|
|
|
|
|
|
|
|
/* trick for fast drop id
|
|
|
|
if key with this first char undefined */
|
|
|
|
if(first_chars[c] == 0) {
|
|
|
|
/* skip <S>[A-Z_a-z0-9]+ */
|
|
|
|
do getc1(); while(isalnums[c]);
|
|
|
|
} else {
|
|
|
|
id_len = 0;
|
|
|
|
do {
|
|
|
|
/* <S>[A-Z_a-z0-9]+ */
|
|
|
|
put_id(c);
|
|
|
|
getc1();
|
|
|
|
} while(isalnums[c]);
|
|
|
|
check_key(key_top, id, id_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* begin preprocessor states */
|
|
|
|
if(c == L_EOF)
|
|
|
|
yy_error_d("unexpected EOF");
|
|
|
|
if(c == REM) {
|
|
|
|
/* <#.*>/ */
|
|
|
|
getc0();
|
|
|
|
if(c == REM)
|
|
|
|
yy_error_d("detected // in preprocessor line");
|
|
|
|
if(c == '*') {
|
|
|
|
/* <#.*>[/][*] goto parse block comments */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* hmm, #.*[/] */
|
|
|
|
yy_error_d("strange preprocessor line");
|
|
|
|
}
|
|
|
|
if(state == POUND) {
|
|
|
|
/* tricks */
|
|
|
|
static const char * const p_preproc[] = {
|
|
|
|
/* 0 1 2 3 4 5 6 */
|
|
|
|
"", "", "", "", "ndef", "efine", "nclude"
|
|
|
|
};
|
|
|
|
size_t diu = first_chars_diu[c]; /* strlen and p_preproc ptr */
|
|
|
|
|
|
|
|
state = S;
|
|
|
|
if(diu != S) {
|
|
|
|
getc1();
|
|
|
|
id_len = 0;
|
|
|
|
while(isalnums[c]) {
|
|
|
|
put_id(c);
|
|
|
|
getc1();
|
|
|
|
}
|
2006-02-14 14:53:25 +05:30
|
|
|
/* str begins with c, read == strlen key and compared */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
if(diu == id_len && !memcmp(id, p_preproc[diu], diu)) {
|
|
|
|
state = diu + '0';
|
|
|
|
id_len = 0; /* common for save */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while(isalnums[c]) getc1();
|
|
|
|
}
|
|
|
|
} else if(state == I) {
|
|
|
|
if(c == STR) {
|
|
|
|
/* <I>\" */
|
|
|
|
for(;;) {
|
|
|
|
getc1();
|
|
|
|
if(c == STR)
|
|
|
|
break;
|
|
|
|
if(c == L_EOF)
|
|
|
|
yy_error_d("unexpected EOF");
|
|
|
|
put_id(c);
|
|
|
|
}
|
|
|
|
put_id(0);
|
|
|
|
/* store "include.h" */
|
|
|
|
parse_inc(id, fname);
|
|
|
|
getc1();
|
|
|
|
}
|
|
|
|
/* else another (may be wrong) #include ... */
|
|
|
|
state = S;
|
|
|
|
} else /* if(state == D || state == U) */ {
|
|
|
|
/* ignore depend with #define or #undef KEY */
|
|
|
|
while(isalnums[c]) getc1();
|
|
|
|
state = S;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <REM> */
|
|
|
|
getc0();
|
|
|
|
for(;;) {
|
|
|
|
/* <REM>[^*]+ */
|
|
|
|
while(c != '*') {
|
|
|
|
if(c == '\n') {
|
|
|
|
/* <REM>\n */
|
|
|
|
if(state != S)
|
|
|
|
yy_error_d("unexpected newline");
|
|
|
|
line++;
|
|
|
|
} else if(c == L_EOF)
|
|
|
|
yy_error_d("unexpected EOF");
|
|
|
|
getc0();
|
|
|
|
}
|
|
|
|
/* <REM>[*] */
|
|
|
|
getc0();
|
|
|
|
if(c == REM) {
|
|
|
|
/* <REM>[*][/] */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
too_long:
|
|
|
|
yy_error_d("phrase too long");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-14 14:53:25 +05:30
|
|
|
/* bb_simplify_path special variant for absolute pathname */
|
2005-10-10 17:05:17 +05:30
|
|
|
static size_t bb_qa_simplify_path(char *path)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
2005-10-10 17:05:17 +05:30
|
|
|
char *s, *p;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
p = s = path;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
do {
|
|
|
|
if (*p == '/') {
|
|
|
|
if (*s == '/') { /* skip duplicate (or initial) slash */
|
|
|
|
continue;
|
|
|
|
} else if (*s == '.') {
|
|
|
|
if (s[1] == '/' || s[1] == 0) { /* remove extra '.' */
|
|
|
|
continue;
|
|
|
|
} else if ((s[1] == '.') && (s[2] == '/' || s[2] == 0)) {
|
|
|
|
++s;
|
|
|
|
if (p > path) {
|
|
|
|
while (*--p != '/'); /* omit previous dir */
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*++p = *s;
|
|
|
|
} while (*++s);
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
if ((p == path) || (*p != '/')) { /* not a trailing slash */
|
|
|
|
++p; /* so keep last character */
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
*p = 0;
|
2005-09-13 22:20:53 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
return (p - path);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
static void parse_inc(const char *include, const char *fname)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
2005-10-10 17:05:17 +05:30
|
|
|
bb_key_t *cur;
|
|
|
|
const char *p_i;
|
|
|
|
llist_t *lo;
|
|
|
|
char *ap;
|
|
|
|
size_t key_sz;
|
2006-02-16 21:10:24 +05:30
|
|
|
struct stat st;
|
2005-10-10 17:05:17 +05:30
|
|
|
|
|
|
|
if(*include == '/') {
|
|
|
|
lo = NULL;
|
|
|
|
ap = bb_xstrdup(include);
|
2005-09-13 22:20:53 +05:30
|
|
|
} else {
|
2005-10-10 17:05:17 +05:30
|
|
|
int w;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
lo = Iop;
|
2006-02-14 14:53:25 +05:30
|
|
|
p = strrchr(fname, '/'); /* fname has absolute pathname */
|
2005-10-10 17:05:17 +05:30
|
|
|
w = (p-fname);
|
|
|
|
/* find from current directory of source file */
|
|
|
|
ap = bb_asprint("%.*s/%s", w, fname, include);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
for(;;) {
|
|
|
|
key_sz = bb_qa_simplify_path(ap);
|
|
|
|
cur = check_key(Ifound, ap, key_sz);
|
|
|
|
if(cur) {
|
|
|
|
cur->checked = cur->value;
|
|
|
|
free(ap);
|
2005-09-12 18:03:27 +05:30
|
|
|
return;
|
|
|
|
}
|
2006-02-16 21:10:24 +05:30
|
|
|
if(stat(ap, &st) == 0) {
|
2005-10-10 17:05:17 +05:30
|
|
|
/* found */
|
2006-02-16 21:10:24 +05:30
|
|
|
llist_t *cfl;
|
|
|
|
|
|
|
|
for(cfl = configs; cfl; cfl = cfl->link) {
|
|
|
|
struct stat *config = (struct stat *)cfl->data;
|
|
|
|
|
|
|
|
if (st.st_dev == config->st_dev && st.st_ino == config->st_ino) {
|
|
|
|
/* skip depend with bb_configs.h */
|
2006-02-17 14:35:41 +05:30
|
|
|
return;
|
2006-02-16 21:10:24 +05:30
|
|
|
}
|
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
p_i = ap;
|
|
|
|
break;
|
|
|
|
} else if(lo == NULL) {
|
|
|
|
p_i = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find from "-I include" specified directories */
|
|
|
|
free(ap);
|
2006-02-14 14:53:25 +05:30
|
|
|
/* lo->data has absolute pathname */
|
2005-10-10 17:05:17 +05:30
|
|
|
ap = bb_asprint("%s/%s", lo->data, include);
|
|
|
|
lo = lo->link;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur = xmalloc(sizeof(bb_key_t));
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
cur->keyname = ap;
|
2005-10-10 17:05:17 +05:30
|
|
|
cur->key_sz = key_sz;
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
cur->stored_path = ap;
|
2005-10-10 17:05:17 +05:30
|
|
|
cur->value = cur->checked = p_i;
|
|
|
|
if(p_i == NULL && noiwarning)
|
|
|
|
fprintf(stderr, "%s: Warning: #include \"%s\" not found\n", fname, include);
|
|
|
|
cur->next = Ifound;
|
|
|
|
Ifound = cur;
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
static size_t max_rec_sz;
|
|
|
|
|
|
|
|
static void parse_conf_opt(const char *opt, const char *val, size_t key_sz)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
2005-09-13 22:20:53 +05:30
|
|
|
bb_key_t *cur;
|
2005-10-03 15:38:46 +05:30
|
|
|
char *k;
|
2005-10-10 17:05:17 +05:30
|
|
|
char *p;
|
|
|
|
size_t val_sz = 0;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-03 15:38:46 +05:30
|
|
|
cur = check_key(key_top, opt, key_sz);
|
2005-09-14 20:39:06 +05:30
|
|
|
if(cur != NULL) {
|
2006-02-14 14:53:25 +05:30
|
|
|
/* already present */
|
2005-10-03 15:38:46 +05:30
|
|
|
cur->checked = NULL; /* store only */
|
2005-09-14 20:39:06 +05:30
|
|
|
if(cur->value == NULL && val == NULL)
|
|
|
|
return;
|
2005-10-03 15:38:46 +05:30
|
|
|
if(cur->value != NULL && val != NULL && !strcmp(cur->value, val))
|
2005-09-14 20:39:06 +05:30
|
|
|
return;
|
2005-10-03 15:38:46 +05:30
|
|
|
k = cur->keyname;
|
|
|
|
fprintf(stderr, "Warning: redefined %s\n", k);
|
2005-09-16 19:27:33 +05:30
|
|
|
} else {
|
2005-10-10 17:05:17 +05:30
|
|
|
size_t recordsz;
|
|
|
|
|
|
|
|
if(val && *val)
|
|
|
|
val_sz = strlen(val) + 1;
|
|
|
|
recordsz = key_sz + val_sz + 1;
|
|
|
|
if(max_rec_sz < recordsz)
|
|
|
|
max_rec_sz = recordsz;
|
|
|
|
cur = xmalloc(sizeof(bb_key_t) + recordsz);
|
|
|
|
k = cur->keyname = memcpy(cur + 1, opt, key_sz);
|
|
|
|
cur->keyname[key_sz] = '\0';
|
|
|
|
cur->key_sz = key_sz;
|
|
|
|
cur->checked = NULL;
|
|
|
|
cur->src_have_this_key = NULL;
|
|
|
|
cur->next = key_top;
|
|
|
|
key_top = cur;
|
2005-09-14 20:39:06 +05:30
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
/* save VAL */
|
2005-09-14 20:39:06 +05:30
|
|
|
if(val) {
|
|
|
|
if(*val == '\0') {
|
|
|
|
cur->value = "";
|
2005-09-13 22:20:53 +05:30
|
|
|
} else {
|
2005-10-10 17:05:17 +05:30
|
|
|
cur->value = p = cur->keyname + key_sz + 1;
|
|
|
|
memcpy(p, val, val_sz);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
} else {
|
|
|
|
cur->value = NULL;
|
|
|
|
}
|
|
|
|
/* trick, save first char KEY for do fast identify id */
|
2005-10-03 15:38:46 +05:30
|
|
|
first_chars[(int)*k] = *k;
|
2005-09-14 20:39:06 +05:30
|
|
|
|
2005-10-03 15:38:46 +05:30
|
|
|
cur->stored_path = k = bb_asprint("%s/%s.h", kp, k);
|
2006-02-14 14:53:25 +05:30
|
|
|
/* key conversion [A-Z_] -> [a-z/] */
|
2005-10-03 15:38:46 +05:30
|
|
|
for(p = k + kp_len + 1; *p; p++) {
|
2005-09-14 20:39:06 +05:30
|
|
|
if(*p >= 'A' && *p <= 'Z')
|
|
|
|
*p = *p - 'A' + 'a';
|
2005-09-16 19:27:33 +05:30
|
|
|
else if(*p == '_' && p[1] > '9') /* do not change A_1 to A/1 */
|
2005-09-14 20:39:06 +05:30
|
|
|
*p = '/';
|
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void store_keys(void)
|
|
|
|
{
|
|
|
|
bb_key_t *cur;
|
|
|
|
char *k;
|
|
|
|
struct stat st;
|
|
|
|
int cmp_ok;
|
|
|
|
ssize_t rw_ret;
|
|
|
|
size_t recordsz = max_rec_sz * 2 + 10 * 2 + 16;
|
|
|
|
/* buffer for double "#define KEY VAL\n" */
|
|
|
|
char *record_buf = xmalloc(recordsz);
|
|
|
|
|
|
|
|
for(cur = key_top; cur; cur = cur->next) {
|
|
|
|
if(cur->src_have_this_key) {
|
|
|
|
/* do generate record */
|
|
|
|
k = cur->keyname;
|
|
|
|
if(cur->value == NULL) {
|
|
|
|
recordsz = sprintf(record_buf, "#undef %s\n", k);
|
|
|
|
} else {
|
|
|
|
const char *val = cur->value;
|
|
|
|
if(*val == '\0') {
|
|
|
|
recordsz = sprintf(record_buf, "#define %s\n", k);
|
|
|
|
} else {
|
2006-02-15 17:59:37 +05:30
|
|
|
if(val[0] != '(')
|
|
|
|
recordsz = sprintf(record_buf, "#define %s %s\n", k, val);
|
|
|
|
else
|
|
|
|
recordsz = sprintf(record_buf, "#define %s%s\n", k, val);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
/* size_t -> ssize_t :( */
|
|
|
|
rw_ret = (ssize_t)recordsz;
|
2006-02-14 14:53:25 +05:30
|
|
|
/* check kp/key.h, compare after previous use */
|
2005-10-10 17:05:17 +05:30
|
|
|
cmp_ok = 0;
|
|
|
|
k = cur->stored_path;
|
|
|
|
if(stat(k, &st)) {
|
|
|
|
char *p;
|
|
|
|
for(p = k + kp_len + 1; *p; p++) {
|
|
|
|
/* Auto-create directories. */
|
|
|
|
if (*p == '/') {
|
|
|
|
*p = '\0';
|
|
|
|
if (access(k, F_OK) != 0 && mkdir(k, 0755) != 0)
|
|
|
|
bb_error_d("mkdir(%s): %m", k);
|
|
|
|
*p = '/';
|
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
} else {
|
|
|
|
/* found */
|
|
|
|
if(st.st_size == (off_t)recordsz) {
|
|
|
|
char *r_cmp;
|
|
|
|
int fd;
|
|
|
|
size_t padded = recordsz;
|
|
|
|
|
|
|
|
/* 16-byte padding for read(2) and memcmp(3) */
|
|
|
|
padded = (padded+15) & ~15;
|
|
|
|
r_cmp = record_buf + padded;
|
|
|
|
fd = open(k, O_RDONLY);
|
|
|
|
if(fd < 0 || read(fd, r_cmp, recordsz) < rw_ret)
|
|
|
|
bb_error_d("%s: %m", k);
|
|
|
|
close(fd);
|
|
|
|
cmp_ok = memcmp(record_buf, r_cmp, recordsz) == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!cmp_ok) {
|
|
|
|
int fd = open(k, O_WRONLY|O_CREAT|O_TRUNC, 0644);
|
|
|
|
if(fd < 0 || write(fd, record_buf, recordsz) < rw_ret)
|
|
|
|
bb_error_d("%s: %m", k);
|
|
|
|
close(fd);
|
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
}
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
|
2005-10-07 21:06:26 +05:30
|
|
|
static int show_dep(int first, bb_key_t *k, const char *name, const char *f)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
|
|
|
bb_key_t *cur;
|
|
|
|
|
|
|
|
for(cur = k; cur; cur = cur->next) {
|
2005-10-03 15:38:46 +05:30
|
|
|
if(cur->checked) {
|
2005-10-10 17:05:17 +05:30
|
|
|
if(first >= 0) {
|
|
|
|
if(first) {
|
|
|
|
if(f == NULL)
|
2005-10-07 21:06:26 +05:30
|
|
|
printf("\n%s:", name);
|
2005-10-10 17:05:17 +05:30
|
|
|
else
|
2005-10-07 21:06:26 +05:30
|
|
|
printf("\n%s/%s:", pwd, name);
|
2005-10-10 17:05:17 +05:30
|
|
|
first = 0;
|
|
|
|
} else {
|
|
|
|
printf(" \\\n ");
|
|
|
|
}
|
|
|
|
printf(" %s", cur->checked);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
cur->src_have_this_key = cur->checked;
|
|
|
|
cur->checked = NULL;
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
2005-09-13 22:20:53 +05:30
|
|
|
static char *
|
2005-09-14 20:39:06 +05:30
|
|
|
parse_chd(const char *fe, const char *p, size_t dirlen)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char *fp;
|
2005-09-13 22:20:53 +05:30
|
|
|
size_t df_sz;
|
2005-10-10 17:05:17 +05:30
|
|
|
static char dir_and_entry[4096];
|
|
|
|
size_t fe_sz = strlen(fe) + 1;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-10 17:05:17 +05:30
|
|
|
df_sz = dirlen + fe_sz + 1; /* dir/file\0 */
|
|
|
|
if(df_sz > sizeof(dir_and_entry))
|
|
|
|
bb_error_d("%s: file name too long", fe);
|
2005-09-13 22:20:53 +05:30
|
|
|
fp = dir_and_entry;
|
2005-10-10 17:05:17 +05:30
|
|
|
/* sprintf(fp, "%s/%s", p, fe); */
|
|
|
|
memcpy(fp, p, dirlen);
|
|
|
|
fp[dirlen] = '/';
|
|
|
|
memcpy(fp + dirlen + 1, fe, fe_sz);
|
2005-09-13 22:20:53 +05:30
|
|
|
|
2005-09-12 18:03:27 +05:30
|
|
|
if(stat(fp, &st)) {
|
2005-10-03 15:38:46 +05:30
|
|
|
fprintf(stderr, "Warning: stat(%s): %m\n", fp);
|
2005-09-12 18:03:27 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
2005-09-12 22:09:47 +05:30
|
|
|
if(S_ISREG(st.st_mode)) {
|
2005-09-14 20:39:06 +05:30
|
|
|
llist_t *cfl;
|
|
|
|
char *e = fp + df_sz - 3;
|
|
|
|
|
|
|
|
if(*e++ != '.' || (*e != 'c' && *e != 'h')) {
|
2005-09-12 22:09:47 +05:30
|
|
|
/* direntry is regular file, but is not *.[ch] */
|
2005-09-12 18:03:27 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
for(cfl = configs; cfl; cfl = cfl->link) {
|
|
|
|
struct stat *config = (struct stat *)cfl->data;
|
|
|
|
|
|
|
|
if (st.st_dev == config->st_dev && st.st_ino == config->st_ino) {
|
2006-02-16 21:10:24 +05:30
|
|
|
/* skip already parsed bb_configs.h */
|
2005-09-12 22:09:47 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
/* direntry is *.[ch] regular file and is not configs */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
c_lex_src(fp, st.st_size);
|
2005-09-14 20:39:06 +05:30
|
|
|
if(!dontgenerate_dep) {
|
|
|
|
int first;
|
|
|
|
if(*e == 'c') {
|
|
|
|
/* *.c -> *.o */
|
|
|
|
*e = 'o';
|
2005-10-07 21:06:26 +05:30
|
|
|
/* /src_dir/path/file.o to path/file.o */
|
|
|
|
fp += replace;
|
|
|
|
if(*fp == '/')
|
2005-10-10 17:05:17 +05:30
|
|
|
fp++;
|
2005-10-06 20:17:16 +05:30
|
|
|
} else {
|
|
|
|
e = NULL;
|
2005-09-14 20:39:06 +05:30
|
|
|
}
|
2005-10-07 21:06:26 +05:30
|
|
|
first = show_dep(1, Ifound, fp, e);
|
|
|
|
first = show_dep(first, key_top, fp, e);
|
2005-09-14 20:39:06 +05:30
|
|
|
if(first == 0)
|
|
|
|
putchar('\n');
|
2005-10-10 17:05:17 +05:30
|
|
|
} else {
|
|
|
|
show_dep(-1, key_top, NULL, NULL);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
return NULL;
|
|
|
|
} else if(S_ISDIR(st.st_mode)) {
|
|
|
|
if (st.st_dev == st_kp.st_dev && st.st_ino == st_kp.st_ino)
|
|
|
|
return NULL; /* drop scan kp/ directory */
|
2005-10-10 17:05:17 +05:30
|
|
|
/* direntry is directory. buff is returned */
|
|
|
|
return bb_xstrdup(fp);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
/* hmm, direntry is device! */
|
2005-09-12 18:03:27 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-02-14 14:53:25 +05:30
|
|
|
/* from libbb but inlined for speed considerations */
|
2005-09-14 20:39:06 +05:30
|
|
|
static inline llist_t *llist_add_to(llist_t *old_head, char *new_item)
|
|
|
|
{
|
|
|
|
llist_t *new_head;
|
|
|
|
|
|
|
|
new_head = xmalloc(sizeof(llist_t));
|
|
|
|
new_head->data = new_item;
|
|
|
|
new_head->link = old_head;
|
|
|
|
|
|
|
|
return(new_head);
|
|
|
|
}
|
|
|
|
|
2005-10-03 15:38:46 +05:30
|
|
|
static void scan_dir_find_ch_files(const char *p)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
|
|
|
llist_t *dirs;
|
|
|
|
llist_t *d_add;
|
|
|
|
llist_t *d;
|
|
|
|
struct dirent *de;
|
|
|
|
DIR *dir;
|
2005-09-13 22:20:53 +05:30
|
|
|
size_t dirlen;
|
2005-09-12 18:03:27 +05:30
|
|
|
|
2005-10-03 15:38:46 +05:30
|
|
|
dirs = llist_add_to(NULL, bb_simplify_path(p));
|
2005-10-07 21:06:26 +05:30
|
|
|
replace = strlen(dirs->data);
|
2006-02-14 14:53:25 +05:30
|
|
|
/* emulate recursion */
|
2005-09-12 18:03:27 +05:30
|
|
|
while(dirs) {
|
|
|
|
d_add = NULL;
|
|
|
|
while(dirs) {
|
|
|
|
dir = opendir(dirs->data);
|
|
|
|
if (dir == NULL)
|
2005-10-03 15:38:46 +05:30
|
|
|
fprintf(stderr, "Warning: opendir(%s): %m\n", dirs->data);
|
2005-09-13 22:20:53 +05:30
|
|
|
dirlen = strlen(dirs->data);
|
2005-09-12 18:03:27 +05:30
|
|
|
while ((de = readdir(dir)) != NULL) {
|
2005-10-03 15:38:46 +05:30
|
|
|
char *found_dir;
|
2005-09-13 22:20:53 +05:30
|
|
|
|
2005-10-03 15:38:46 +05:30
|
|
|
if (de->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
found_dir = parse_chd(de->d_name, dirs->data, dirlen);
|
2005-09-13 22:20:53 +05:30
|
|
|
if(found_dir)
|
|
|
|
d_add = llist_add_to(d_add, found_dir);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
closedir(dir);
|
2005-10-03 15:38:46 +05:30
|
|
|
free(dirs->data);
|
2005-09-12 18:03:27 +05:30
|
|
|
d = dirs;
|
|
|
|
dirs = dirs->link;
|
|
|
|
free(d);
|
|
|
|
}
|
|
|
|
dirs = d_add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-27 01:28:58 +05:30
|
|
|
static void show_usage(void) ATTRIBUTE ((noreturn));
|
2005-10-10 17:05:17 +05:30
|
|
|
static void show_usage(void)
|
|
|
|
{
|
|
|
|
bb_error_d("%s\n%s\n", bb_mkdep_terse_options, bb_mkdep_full_options);
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
|
2005-09-12 18:03:27 +05:30
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int i;
|
|
|
|
llist_t *fl;
|
|
|
|
|
2005-09-13 22:20:53 +05:30
|
|
|
{
|
2006-02-14 16:13:40 +05:30
|
|
|
/* for bb_simplify_path, this program has no chdir() */
|
2005-10-10 17:05:17 +05:30
|
|
|
/* libbb-like my xgetcwd() */
|
2005-09-13 22:20:53 +05:30
|
|
|
unsigned path_max = 512;
|
|
|
|
|
|
|
|
s = xmalloc (path_max);
|
|
|
|
while (getcwd (s, path_max) == NULL) {
|
|
|
|
if(errno != ERANGE)
|
|
|
|
bb_error_d("getcwd: %m");
|
2005-10-10 17:05:17 +05:30
|
|
|
free(s);
|
|
|
|
s = xmalloc(path_max *= 2);
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
pwd = s;
|
|
|
|
}
|
|
|
|
|
2005-09-12 18:03:27 +05:30
|
|
|
while ((i = getopt(argc, argv, "I:c:dk:w")) > 0) {
|
|
|
|
switch(i) {
|
|
|
|
case 'I':
|
2005-10-10 17:05:17 +05:30
|
|
|
s = bb_simplify_path(optarg);
|
|
|
|
Iop = llist_add_to(Iop, s);
|
2005-09-12 18:03:27 +05:30
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
s = bb_simplify_path(optarg);
|
|
|
|
configs = llist_add_to(configs, s);
|
|
|
|
break;
|
|
|
|
case 'd':
|
2005-09-14 20:39:06 +05:30
|
|
|
dontgenerate_dep = 1;
|
2005-09-12 18:03:27 +05:30
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
if(kp)
|
|
|
|
bb_error_d("Hmm, why multiple -k?");
|
|
|
|
kp = bb_simplify_path(optarg);
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
noiwarning = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
show_usage();
|
|
|
|
}
|
|
|
|
}
|
2005-09-14 20:39:06 +05:30
|
|
|
/* default kp */
|
2005-09-12 18:03:27 +05:30
|
|
|
if(kp == NULL)
|
|
|
|
kp = bb_simplify_path(INCLUDE_CONFIG_PATH);
|
2005-09-14 20:39:06 +05:30
|
|
|
/* globals initialize */
|
|
|
|
kp_len = strlen(kp);
|
|
|
|
if(stat(kp, &st_kp))
|
|
|
|
bb_error_d("stat(%s): %m", kp);
|
|
|
|
if(!S_ISDIR(st_kp.st_mode))
|
|
|
|
bb_error_d("%s is not directory", kp);
|
|
|
|
/* defaults */
|
2005-09-12 18:03:27 +05:30
|
|
|
if(Iop == NULL)
|
2005-10-10 17:05:17 +05:30
|
|
|
Iop = llist_add_to(Iop, bb_simplify_path(LOCAL_INCLUDE_PATH));
|
2005-09-12 18:03:27 +05:30
|
|
|
if(configs == NULL) {
|
|
|
|
s = bb_simplify_path(INCLUDE_CONFIG_KEYS_PATH);
|
|
|
|
configs = llist_add_to(configs, s);
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
/* for c_lex */
|
|
|
|
pagesizem1 = getpagesize() - 1;
|
2005-10-10 17:05:17 +05:30
|
|
|
for(i = 0; i < UCHAR_MAX; i++) {
|
2005-09-16 19:27:33 +05:30
|
|
|
if(ISALNUM(i))
|
|
|
|
isalnums[i] = i;
|
2006-02-14 14:53:25 +05:30
|
|
|
/* set unparsed chars to speed up the parser */
|
2005-10-10 17:05:17 +05:30
|
|
|
else if(i != CHR && i != STR && i != POUND && i != REM)
|
2005-09-13 22:20:53 +05:30
|
|
|
first_chars[i] = ANY;
|
|
|
|
}
|
|
|
|
first_chars[i] = '-'; /* L_EOF */
|
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
/* parse configs */
|
|
|
|
for(fl = configs; fl; fl = fl->link) {
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if(stat(fl->data, &st))
|
|
|
|
bb_error_d("stat(%s): %m", fl->data);
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
c_lex_config(fl->data, st.st_size);
|
2005-10-10 17:05:17 +05:30
|
|
|
free(fl->data);
|
2005-09-14 20:39:06 +05:30
|
|
|
/* trick for fast comparing found files with configs */
|
2005-10-10 17:05:17 +05:30
|
|
|
fl->data = xmalloc(sizeof(struct stat));
|
2005-09-14 20:39:06 +05:30
|
|
|
memcpy(fl->data, &st, sizeof(struct stat));
|
|
|
|
}
|
2005-09-13 22:20:53 +05:30
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
/* main loop */
|
2005-09-13 22:20:53 +05:30
|
|
|
argv += optind;
|
|
|
|
if(*argv) {
|
|
|
|
while(*argv)
|
|
|
|
scan_dir_find_ch_files(*argv++);
|
|
|
|
} else {
|
|
|
|
scan_dir_find_ch_files(".");
|
|
|
|
}
|
2005-10-10 17:05:17 +05:30
|
|
|
store_keys();
|
2005-09-12 18:03:27 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
/* partial and simplified libbb routine */
|
2005-09-12 22:09:47 +05:30
|
|
|
static void bb_error_d(const char *s, ...)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
|
|
|
va_list p;
|
|
|
|
|
|
|
|
va_start(p, s);
|
|
|
|
vfprintf(stderr, s, p);
|
|
|
|
va_end(p);
|
|
|
|
putc('\n', stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2005-09-12 22:09:47 +05:30
|
|
|
static char *bb_asprint(const char *format, ...)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
|
|
|
va_list p;
|
|
|
|
int r;
|
|
|
|
char *out;
|
|
|
|
|
2006-05-27 01:28:58 +05:30
|
|
|
#ifdef __USE_GNU
|
2005-09-12 18:03:27 +05:30
|
|
|
va_start(p, format);
|
|
|
|
r = vasprintf(&out, format, p);
|
|
|
|
va_end(p);
|
2006-05-27 01:28:58 +05:30
|
|
|
#else
|
|
|
|
out = xmalloc(BUFSIZ);
|
|
|
|
va_start(p, format);
|
|
|
|
r = vsprintf(out, format, p);
|
|
|
|
va_end(p);
|
|
|
|
#endif
|
2005-09-12 18:03:27 +05:30
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
bb_error_d("bb_asprint: %m");
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2005-09-14 20:39:06 +05:30
|
|
|
/* partial libbb routine as is */
|
New USE() macros
For each CONFIG_SYMBOL, include/bb_config.h now has both ENABLE_SYMBOL
and USE_SYMBOL(x). ENABLE_SYMBOL is still always defined (1 or 0) so that
if(ENABLE) should optimize out when it's zero. The USE_SYMBOL(X) will only
splice in X if the symbol is defined, otherwise it'll be empty.
Thus we can convert this:
#ifdef CONFIG_ARGS
opt = bb_getopt_ulflags(argc, argv, "ab:c"
#ifdef CONFIG_THINGY
"d:"
#endif
, &bvalue
#ifdef CONFIG_THINGY
, &thingy
#endif
);
#endif
into this:
if (ENABLE_ARGS) {
opt = bb_getopt_ulflags(argc, argv, "ab:c" USE_THINGY("d:"), &bvalue
USE_THINGY(, &thingy));
}
And it should produce the same code.
Unlike the old versions in include/_usage.h, the new USE_SYMBOL(x) can handle
commas in its arguments (as shown above). (The _usage.h file is obsolete and
no longer generated.)
Nobody should need to include config.h directly anymore, bb_config.h should
define all the configuration stuff we need. Someday, the CONFIG_SYMBOL
versions should go away in favor of ENABLE_SYMBOL and USE_SYMBOL().
Thanks to vodz for the new version of bb_mkdep.c that works with function
macros.
2006-02-14 00:46:41 +05:30
|
|
|
|
2005-09-12 22:09:47 +05:30
|
|
|
static char *bb_simplify_path(const char *path)
|
2005-09-12 18:03:27 +05:30
|
|
|
{
|
|
|
|
char *s, *start, *p;
|
|
|
|
|
|
|
|
if (path[0] == '/')
|
2005-09-13 22:20:53 +05:30
|
|
|
start = bb_xstrdup(path);
|
2005-09-12 18:03:27 +05:30
|
|
|
else {
|
2006-02-14 16:13:40 +05:30
|
|
|
/* is not libbb, but this program has no chdir() */
|
2005-09-13 22:20:53 +05:30
|
|
|
start = bb_asprint("%s/%s", pwd, path);
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
p = s = start;
|
|
|
|
|
|
|
|
do {
|
2005-09-12 22:09:47 +05:30
|
|
|
if (*p == '/') {
|
|
|
|
if (*s == '/') { /* skip duplicate (or initial) slash */
|
|
|
|
continue;
|
|
|
|
} else if (*s == '.') {
|
|
|
|
if (s[1] == '/' || s[1] == 0) { /* remove extra '.' */
|
|
|
|
continue;
|
|
|
|
} else if ((s[1] == '.') && (s[2] == '/' || s[2] == 0)) {
|
|
|
|
++s;
|
|
|
|
if (p > start) {
|
|
|
|
while (*--p != '/'); /* omit previous dir */
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-09-12 22:09:47 +05:30
|
|
|
continue;
|
|
|
|
}
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
2005-09-12 22:09:47 +05:30
|
|
|
}
|
|
|
|
*++p = *s;
|
2005-09-12 18:03:27 +05:30
|
|
|
} while (*++s);
|
|
|
|
|
2005-09-12 22:09:47 +05:30
|
|
|
if ((p == start) || (*p != '/')) { /* not a trailing slash */
|
|
|
|
++p; /* so keep last character */
|
2005-09-12 18:03:27 +05:30
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|