kbuild: Lindent genksyms.c

No fix-ups applied yet. Just the raw Lindent output.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
This commit is contained in:
Sam Ravnborg 2006-03-12 22:59:36 +01:00
parent c79c7b0923
commit 78c041530a

View File

@ -51,14 +51,13 @@ static int nsyms;
static struct symbol *expansion_trail;
static const char * const symbol_type_name[] = {
static const char *const symbol_type_name[] = {
"normal", "typedef", "enum", "struct", "union"
};
/*----------------------------------------------------------------------*/
static const unsigned int crctab32[] =
{
static const unsigned int crctab32[] = {
0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
@ -119,25 +118,21 @@ partial_crc32_one(unsigned char c, unsigned long crc)
return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
}
static inline unsigned long
partial_crc32(const char *s, unsigned long crc)
static inline unsigned long partial_crc32(const char *s, unsigned long crc)
{
while (*s)
crc = partial_crc32_one(*s++, crc);
return crc;
}
static inline unsigned long
crc32(const char *s)
static inline unsigned long crc32(const char *s)
{
return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
}
/*----------------------------------------------------------------------*/
static inline enum symbol_type
map_to_ns(enum symbol_type t)
static inline enum symbol_type map_to_ns(enum symbol_type t)
{
if (t == SYM_TYPEDEF)
t = SYM_NORMAL;
@ -146,29 +141,28 @@ map_to_ns(enum symbol_type t)
return t;
}
struct symbol *
find_symbol(const char *name, enum symbol_type ns)
struct symbol *find_symbol(const char *name, enum symbol_type ns)
{
unsigned long h = crc32(name) % HASH_BUCKETS;
struct symbol *sym;
for (sym = symtab[h]; sym ; sym = sym->hash_next)
if (map_to_ns(sym->type) == map_to_ns(ns) && strcmp(name, sym->name) == 0)
for (sym = symtab[h]; sym; sym = sym->hash_next)
if (map_to_ns(sym->type) == map_to_ns(ns)
&& strcmp(name, sym->name) == 0)
break;
return sym;
}
struct symbol *
add_symbol(const char *name, enum symbol_type type, struct string_list *defn, int is_extern)
struct symbol *add_symbol(const char *name, enum symbol_type type,
struct string_list *defn, int is_extern)
{
unsigned long h = crc32(name) % HASH_BUCKETS;
struct symbol *sym;
for (sym = symtab[h]; sym ; sym = sym->hash_next)
for (sym = symtab[h]; sym; sym = sym->hash_next)
if (map_to_ns(sym->type) == map_to_ns(type)
&& strcmp(name, sym->name) == 0)
{
&& strcmp(name, sym->name) == 0) {
if (!equal_list(sym->defn, defn))
error_with_pos("redefinition of %s", name);
return sym;
@ -184,9 +178,9 @@ add_symbol(const char *name, enum symbol_type type, struct string_list *defn, in
sym->hash_next = symtab[h];
symtab[h] = sym;
if (flag_debug)
{
fprintf(debugfile, "Defn for %s %s == <", symbol_type_name[type], name);
if (flag_debug) {
fprintf(debugfile, "Defn for %s %s == <",
symbol_type_name[type], name);
if (is_extern)
fputs("extern ", debugfile);
print_list(debugfile, defn);
@ -197,29 +191,24 @@ add_symbol(const char *name, enum symbol_type type, struct string_list *defn, in
return sym;
}
/*----------------------------------------------------------------------*/
inline void
free_node(struct string_list *node)
inline void free_node(struct string_list *node)
{
free(node->string);
free(node);
}
void
free_list(struct string_list *s, struct string_list *e)
void free_list(struct string_list *s, struct string_list *e)
{
while (s != e)
{
while (s != e) {
struct string_list *next = s->next;
free_node(s);
s = next;
}
}
inline struct string_list *
copy_node(struct string_list *node)
inline struct string_list *copy_node(struct string_list *node)
{
struct string_list *newnode;
@ -230,8 +219,7 @@ copy_node(struct string_list *node)
return newnode;
}
struct string_list *
copy_list(struct string_list *s, struct string_list *e)
struct string_list *copy_list(struct string_list *s, struct string_list *e)
{
struct string_list *h, *p;
@ -246,11 +234,9 @@ copy_list(struct string_list *s, struct string_list *e)
return h;
}
int
equal_list(struct string_list *a, struct string_list *b)
int equal_list(struct string_list *a, struct string_list *b)
{
while (a && b)
{
while (a && b) {
if (a->tag != b->tag || strcmp(a->string, b->string))
return 0;
a = a->next;
@ -260,11 +246,9 @@ equal_list(struct string_list *a, struct string_list *b)
return !a && !b;
}
static inline void
print_node(FILE *f, struct string_list *list)
static inline void print_node(FILE * f, struct string_list *list)
{
switch (list->tag)
{
switch (list->tag) {
case SYM_STRUCT:
putc('s', f);
goto printit;
@ -286,21 +270,19 @@ print_node(FILE *f, struct string_list *list)
}
}
void
print_list(FILE *f, struct string_list *list)
void print_list(FILE * f, struct string_list *list)
{
struct string_list **e, **b;
struct string_list *tmp, **tmp2;
int elem = 1;
if (list == NULL)
{
if (list == NULL) {
fputs("(nil)", f);
return;
}
tmp = list;
while((tmp = tmp->next) != NULL)
while ((tmp = tmp->next) != NULL)
elem++;
b = alloca(elem * sizeof(*e));
@ -308,11 +290,10 @@ print_list(FILE *f, struct string_list *list)
tmp2 = e - 1;
(*tmp2--) = list;
while((list = list->next) != NULL)
while ((list = list->next) != NULL)
*(tmp2--) = list;
while (b != e)
{
while (b != e) {
print_node(f, *b++);
putc(' ', f);
}
@ -329,7 +310,7 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
return crc;
tmp = list;
while((tmp = tmp->next) != NULL)
while ((tmp = tmp->next) != NULL)
elem++;
b = alloca(elem * sizeof(*e));
@ -340,14 +321,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
while ((list = list->next) != NULL)
*(tmp2--) = list;
while (b != e)
{
while (b != e) {
struct string_list *cur;
struct symbol *subsym;
cur = *(b++);
switch (cur->tag)
{
switch (cur->tag) {
case SYM_NORMAL:
if (flag_dump_defs)
fprintf(debugfile, "%s ", cur->string);
@ -357,15 +336,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
case SYM_TYPEDEF:
subsym = find_symbol(cur->string, cur->tag);
if (subsym->expansion_trail)
{
if (subsym->expansion_trail) {
if (flag_dump_defs)
fprintf(debugfile, "%s ", cur->string);
crc = partial_crc32(cur->string, crc);
crc = partial_crc32_one(' ', crc);
}
else
{
} else {
subsym->expansion_trail = expansion_trail;
expansion_trail = subsym;
crc = expand_and_crc_list(subsym->defn, crc);
@ -376,12 +352,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
case SYM_UNION:
case SYM_ENUM:
subsym = find_symbol(cur->string, cur->tag);
if (!subsym)
{
if (!subsym) {
struct string_list *n, *t = NULL;
error_with_pos("expand undefined %s %s",
symbol_type_name[cur->tag], cur->string);
symbol_type_name[cur->tag],
cur->string);
n = xmalloc(sizeof(*n));
n->string = xstrdup(symbol_type_name[cur->tag]);
@ -400,23 +376,23 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
n->tag = SYM_NORMAL;
n->next = t;
subsym = add_symbol(cur->string, cur->tag, n, 0);
subsym =
add_symbol(cur->string, cur->tag, n, 0);
}
if (subsym->expansion_trail)
{
if (flag_dump_defs)
{
fprintf(debugfile, "%s %s ", symbol_type_name[cur->tag],
if (subsym->expansion_trail) {
if (flag_dump_defs) {
fprintf(debugfile, "%s %s ",
symbol_type_name[cur->tag],
cur->string);
}
crc = partial_crc32(symbol_type_name[cur->tag], crc);
crc =
partial_crc32(symbol_type_name[cur->tag],
crc);
crc = partial_crc32_one(' ', crc);
crc = partial_crc32(cur->string, crc);
crc = partial_crc32_one(' ', crc);
}
else
{
} else {
subsym->expansion_trail = expansion_trail;
expansion_trail = subsym;
crc = expand_and_crc_list(subsym->defn, crc);
@ -428,16 +404,14 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
return crc;
}
void
export_symbol(const char *name)
void export_symbol(const char *name)
{
struct symbol *sym;
sym = find_symbol(name, SYM_NORMAL);
if (!sym)
error_with_pos("export undefined symbol %s", name);
else
{
else {
unsigned long crc;
if (flag_dump_defs)
@ -448,8 +422,7 @@ export_symbol(const char *name)
crc = expand_and_crc_list(sym->defn, 0xffffffff) ^ 0xffffffff;
sym = expansion_trail;
while (sym != (struct symbol *)-1L)
{
while (sym != (struct symbol *)-1L) {
struct symbol *n = sym->expansion_trail;
sym->expansion_trail = 0;
sym = n;
@ -465,13 +438,11 @@ export_symbol(const char *name)
/*----------------------------------------------------------------------*/
void
error(const char *fmt, ...)
void error(const char *fmt, ...)
{
va_list args;
if (flag_warnings)
{
if (flag_warnings) {
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
@ -481,14 +452,13 @@ error(const char *fmt, ...)
}
}
void
error_with_pos(const char *fmt, ...)
void error_with_pos(const char *fmt, ...)
{
va_list args;
if (flag_warnings)
{
fprintf(stderr, "%s:%d: ", cur_filename ? : "<stdin>", cur_line);
if (flag_warnings) {
fprintf(stderr, "%s:%d: ", cur_filename ? : "<stdin>",
cur_line);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
@ -499,12 +469,9 @@ error_with_pos(const char *fmt, ...)
}
}
void genksyms_usage(void)
{
fputs("Usage:\n"
"genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n"
"\n"
fputs("Usage:\n" "genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n" "\n"
#ifdef __GNU_LIBRARY__
" -d, --debug Increment the debug level (repeatable)\n"
" -D, --dump Dump expanded symbol defs (for debugging only)\n"
@ -523,8 +490,7 @@ void genksyms_usage(void)
, stderr);
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int o;
@ -545,8 +511,7 @@ main(int argc, char **argv)
#else /* __GNU_LIBRARY__ */
while ((o = getopt(argc, argv, "a:dwqVDk:p:")) != EOF)
#endif /* __GNU_LIBRARY__ */
switch (o)
{
switch (o) {
case 'a':
arch = optarg;
break;
@ -572,8 +537,7 @@ main(int argc, char **argv)
genksyms_usage();
return 1;
}
if ((strcmp(arch, "v850") == 0) ||
(strcmp(arch, "h8300") == 0))
if ((strcmp(arch, "v850") == 0) || (strcmp(arch, "h8300") == 0))
mod_prefix = "_";
{
extern int yydebug;
@ -588,10 +552,10 @@ main(int argc, char **argv)
yyparse();
if (flag_debug)
{
if (flag_debug) {
fprintf(debugfile, "Hash table occupancy %d/%d = %g\n",
nsyms, HASH_BUCKETS, (double)nsyms / (double)HASH_BUCKETS);
nsyms, HASH_BUCKETS,
(double)nsyms / (double)HASH_BUCKETS);
}
return errors != 0;