From a391e561e0ae974fbca1a861d24ac3de2264f5ce Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Mon, 10 Dec 2012 22:27:22 +0200 Subject: [PATCH] utils: added collect-symbols in an attempt to eliminate depending on ctags. collect-symbols is a primitive parser that tries to understand just enough of (preprocessed) C that it can extract symbols exported from header files. --- configure.ac | 1 + utils/Makefile.am | 6 + utils/collect-symbols.c | 818 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 825 insertions(+) create mode 100644 utils/Makefile.am create mode 100644 utils/collect-symbols.c diff --git a/configure.ac b/configure.ac index fbf08ad..a8691fd 100644 --- a/configure.ac +++ b/configure.ac @@ -528,6 +528,7 @@ fi AC_CONFIG_FILES([build-aux/shave build-aux/shave-libtool Makefile + utils/Makefile src/Makefile src/common/tests/Makefile src/core/tests/Makefile diff --git a/utils/Makefile.am b/utils/Makefile.am new file mode 100644 index 0000000..c6c6744 --- /dev/null +++ b/utils/Makefile.am @@ -0,0 +1,6 @@ +AM_CFLAGS = $(WARNING_CFLAGS) -I$(top_builddir) +noinst_PROGRAMS = collect-symbols + +collect_symbols_SOURCES = collect-symbols.c +collect_symbols_CFLAGS = $(AM_CFLAGS) +collect_symbols_LDADD = diff --git a/utils/collect-symbols.c b/utils/collect-symbols.c new file mode 100644 index 0000000..8aaced4 --- /dev/null +++ b/utils/collect-symbols.c @@ -0,0 +1,818 @@ +#include +#include +#include +#include +#include +#define _GNU_SOURCE +#include +#include +#include + +#include +#include + +#define RD 0 +#define WR 1 + +typedef enum { + TOKEN_ERROR = -1, + TOKEN_BLOCK, /* a block enclosed in {}/()/[] */ + TOKEN_WORD, /* a word */ + TOKEN_DQUOTED, /* a double-quoted sequence */ + TOKEN_SQUOTED, /* a single-quoted sequence */ + TOKEN_ASSIGN, /* '=' */ + TOKEN_SEMICOLON, /* ';' */ + TOKEN_COLON, /* ',' */ + TOKEN_OTHER, /* any other token */ +} token_type_t; + + +typedef struct { + token_type_t type; /* token type */ + char *value; /* token value */ +} token_t; + + +#define READBUF_SIZE ( 8 * 1024) +#define RINGBUF_SIZE (16 * 1024) +#define MAX_TOKEN (512) +#define MAX_TOKENS (64) + +typedef struct { + int fd; /* file descriptor to read */ + char buf[READBUF_SIZE]; /* data buffer */ + int len; /* amount of data in buffer */ + int rd; /* data buffer read offset */ + int nxt; /* pushed back data if non-zero */ +} input_t; + +typedef struct { + char buf[RINGBUF_SIZE]; /* data buffer */ + int wr; /* write offset */ +} ringbuf_t; + +typedef struct { + char *pattern; /* symbol pattern */ + char **files; /* files to parse for symbols */ + int nfile; /* number of files */ + char *cflags; /* compiler flags */ + char *output; /* output path */ + int gnuld; /* generate GNU ld script */ + int verbose; /* verbosity */ +} config_t; + +typedef struct { + char **syms; + int nsym; +} symtab_t; + + +static int verbosity = 0; + + +static void fatal_error(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + exit(1); +} + + +static void verbose_message(int level, const char *fmt, ...) +{ + va_list ap; + + if (verbosity >= level) { + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + } +} + + +static void print_usage(const char *argv0, int exit_code, const char *fmt, ...) +{ + va_list ap; + + if (fmt && *fmt) { + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + } + + printf("usage: %s [options]\n\n" + "The possible options are:\n" + " -c, --compiler-flags flags to pass to compiler\n" + " -p, --pattern symbol regexp pattern\n" + " -o, --output write output to the given file\n" + " -g, --gnu-ld