diff options
author | katherine <shmibs@airen-no-jikken.icu> | 2019-05-26 18:21:31 -0700 |
---|---|---|
committer | katherine <shmibs@airen-no-jikken.icu> | 2019-05-26 18:21:31 -0700 |
commit | 551a8b3623eb9d89d850fed7a75c776d64f0cd4f (patch) | |
tree | 143ff880a9f6d6e8311e2777b5565ec1ed7a1282 /src | |
parent | 6804fd50fa107605d652c063c2ae0844b812d4df (diff) | |
download | confconf-551a8b3623eb9d89d850fed7a75c776d64f0cd4f.tar.gz |
add unused struct check
also switch err/warn printing from '\e' to '\x1B', for more-strict c99
compliance
Diffstat (limited to 'src')
-rw-r--r-- | src/err.h | 4 | ||||
-rw-r--r-- | src/parse.c | 36 | ||||
-rw-r--r-- | src/parse.h | 3 |
3 files changed, 32 insertions, 11 deletions
@@ -6,14 +6,14 @@ #define ERR(...) \ do { \ - fprintf(stderr, "\e[1;31merror:\e[0m " __VA_ARGS__); \ + fprintf(stderr, "\x1B[1;31merror:\x1B[0m " __VA_ARGS__); \ fprintf(stderr, "\n"); \ exit(EXIT_FAILURE); \ } while (0) #define WARN(...) \ do { \ - fprintf(stderr, "\e[1;35mwarning:\e[0m " __VA_ARGS__); \ + fprintf(stderr, "\x1B[1;35mwarning:\x1B[0m " __VA_ARGS__); \ fprintf(stderr, "\n"); \ } while (0) diff --git a/src/parse.c b/src/parse.c index 2b298d0..cb459e5 100644 --- a/src/parse.c +++ b/src/parse.c @@ -7,12 +7,13 @@ #include <stdlib.h> #include <string.h> #include <ctype.h> +#include <errno.h> static const char *curfname; #define ERR_AT(l, c, ...) \ do { \ - fprintf(stderr, "\e[1m%s:%zu:%zu:\e[0m ", \ + fprintf(stderr, "\x1B[1m%s:%zu:%zu:\x1B[0m ", \ curfname, (l), (c)); \ ERR(__VA_ARGS__); \ } while (0) @@ -25,7 +26,7 @@ static const char *curfname; #define WARN_AT(l, c, ...) \ do { \ - fprintf(stderr, "\e[1m%s:%zu:%zu:\e[0m ", \ + fprintf(stderr, "\x1B[1m%s:%zu:%zu:\x1B[0m ", \ curfname, (l), (c)); \ WARN(__VA_ARGS__); \ } while (0) @@ -109,6 +110,7 @@ static void sub_parse_deftype(size_t line, size_t col, bool is_union) struct parse_deftype_s dt = { .line = line, .col = col, + .is_used = false, .is_union = is_union, .member_list_len = 0, }; @@ -259,8 +261,15 @@ static bool sub_parse_op(void) if (t.type != TOK_UINT) ERR_AT(t.line, t.col, "invalid hkey_size `%s`", t.val); + errno = EILSEQ; r.hkey_size = strtoul(t.val, NULL, 10); + if (errno == ERANGE) + ERR_AT(t.line, t.col, "hkey_size `%s` too large", t.val); + + if (r.hkey_size == 0) + ERR_AT(t.line, t.col, "hkey_size cannot be 0"); + r.hkey_size_seen = true; return true; @@ -363,7 +372,7 @@ struct parse_result_s parse(FILE *f, const char *fname) struct tok_s t; struct parse_var_s *vcur, *vtmp; - struct parse_deftype_s *d; + struct parse_deftype_s *dcur, *dtmp; r.hkey_size = 16; strcpy(r.hkey_name, "key"); @@ -387,7 +396,7 @@ struct parse_result_s parse(FILE *f, const char *fname) } if (r.vars == NULL) { - fprintf(stderr, "\e[1m%s:\e[0m ", fname); + fprintf(stderr, "\x1B[1m%s:\x1B[0m ", fname); ERR("config must specify at fewest one variable rule"); } @@ -396,17 +405,26 @@ struct parse_result_s parse(FILE *f, const char *fname) case PARSE_TYPE_DEFTYPE: case PARSE_TYPE_ARRAY_DEFTYPE: case PARSE_TYPE_HASH_DEFTYPE: - HASH_FIND_STR(r.deftypes, vcur->deftype_name, d); - if (d == NULL) { + HASH_FIND_STR(r.deftypes, vcur->deftype_name, dcur); + if (dcur == NULL) { ERR_AT(vcur->line, vcur->col, "rule for variable `%s` references undefined type `%s`", vcur->name, vcur->deftype_name); } + dcur->is_used = true; default: continue; } } + HASH_ITER(hh, r.deftypes, dcur, dtmp) { + if (!dcur->is_used) { + WARN_AT(dcur->line, dcur->col, + "struct `%s` defined but not used", + dcur->name); + } + } + if (!r.fun_suf_seen) { j = 0; @@ -419,7 +437,7 @@ struct parse_result_s parse(FILE *f, const char *fname) for (i = j; fname[i] != '\0' && fname[i] != '.' && i - j < r.hkey_size; i++) { if (!isalnum(fname[i]) && fname[i] != '_') { - fprintf(stderr, "\e[1m%s:\e[0m ", fname); + fprintf(stderr, "\x1B[1m%s:\x1B[0m ", fname); ERR("no function suffix specified, and could not generate one"); } r.fun_suf[i - j] = fname[i]; @@ -428,11 +446,11 @@ struct parse_result_s parse(FILE *f, const char *fname) r.fun_suf[i - j] = '\0'; if (r.fun_suf[0] == '\0') { - fprintf(stderr, "\e[1m%s:\e[0m ", fname); + fprintf(stderr, "\x1B[1m%s:\x1B[0m ", fname); ERR("no function suffix specified, and could not generate one"); } - fprintf(stderr, "\e[1m%s:\e[0m ", fname); + fprintf(stderr, "\x1B[1m%s:\x1B[0m ", fname); WARN("no function suffix specified. using `%s`...", r.fun_suf); } diff --git a/src/parse.h b/src/parse.h index 09eed9f..b9f2ceb 100644 --- a/src/parse.h +++ b/src/parse.h @@ -9,6 +9,8 @@ #define PARSE_DEFTYPE_MAX_LEN 32 +/* very important these stay in order. + * things like ">= PARSE_TYPE_ARRAY_BOOL" used */ enum parse_type_e { PARSE_TYPE_BOOL = 0, PARSE_TYPE_STRING = 1, @@ -57,6 +59,7 @@ struct parse_deftype_s { char name[TOK_MAX_LEN]; size_t line; size_t col; + bool is_used; bool is_union; unsigned member_list_len; enum parse_type_e member_type_list[PARSE_DEFTYPE_MAX_LEN]; |