diff --git a/.gitignore b/.gitignore index 634a205..dcb7563 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.o *.a +.d gwfmt diff --git a/include/gwfmt.h b/include/gwfmt.h index c4516af..66ea45d 100644 --- a/include/gwfmt.h +++ b/include/gwfmt.h @@ -68,7 +68,8 @@ typedef struct GwfmtState { bool header; bool use_tabs; bool error; - bool fix; + bool fix_case; + bool check_case; } GwfmtState; void gwfmt_state_init(GwfmtState *ls); diff --git a/src/gwfmt.c b/src/gwfmt.c index 7e66882..fadb4c0 100644 --- a/src/gwfmt.c +++ b/src/gwfmt.c @@ -84,7 +84,8 @@ enum { // MARK, EXPAND, MINIFY, - CASING, + FIX_CASING, + CHECK_CASING, CONFIG, COLOR, NOPTIONS @@ -110,7 +111,9 @@ static void setup_options(cmdapp_t *app, cmdopt_t *opt) { cmdapp_set(app, 'm', "minify", CMDOPT_TAKESARG, NULL, "minimize input", "bool", &opt[MINIFY]); cmdapp_set(app, 'f', "fix", CMDOPT_TAKESARG, NULL, "fix casing", - "bool", &opt[CASING]); + "bool", &opt[FIX_CASING]); + cmdapp_set(app, 'w', "fix", CMDOPT_TAKESARG, NULL, "check casing", + "bool", &opt[CHECK_CASING]); cmdapp_set(app, 'C', "config", CMDOPT_TAKESARG, NULL, "config file", "filename", &opt[CONFIG]); cmdapp_set(app, 'c', "color", CMDOPT_TAKESARG, NULL, "enable or disable {R}c{G}o{B}l{M}o{Y}r{C}s{0}", @@ -179,7 +182,10 @@ static void myproc(void *data, cmdopt_t *option, const char *arg) { ls->minimize = arg2bool(option->value); break; case 'f': - ls->fix = arg2bool(option->value); + ls->fix_case = arg2bool(option->value); + break; + case 'w': + ls->check_case = arg2bool(option->value); break; case 'C': run_config(ls, option->value); @@ -221,7 +227,14 @@ int main(int argc, char **argv) { SymTable * st = new_symbol_table(mp, 65347); // could be smaller PPArg ppa = {.fmt = 1}; pparg_ini(mp, &ppa); - struct GwfmtState ls = {.color = isatty(1) ? COLOR_AUTO : COLOR_NEVER, .show_line = true, .header = true, .nindent = 2, .ppa = &ppa, .minimize = false }; + struct GwfmtState ls = { + .color = isatty(1) ? COLOR_AUTO : COLOR_NEVER, + .show_line = true, + .header = true, + .nindent = 2, + .ppa = &ppa, + .minimize = false, + .check_case = true}; tcol_override_color_checks(ls.color); gwfmt_state_init(&ls); text_init(&ls.text, mp); diff --git a/src/gwion_config.c b/src/gwion_config.c index 76ae043..4b9e2d5 100644 --- a/src/gwion_config.c +++ b/src/gwion_config.c @@ -24,7 +24,8 @@ runtime_bool_func(pretty, pretty); runtime_bool_func(show_lines, show_line); runtime_bool_func(header, header); runtime_bool_func(use_tabs, use_tabs); -runtime_bool_func(fix, fix); +runtime_bool_func(fix_case, fix_case); +runtime_bool_func(check_case, check_case); static MFUN(fmt_color) { struct GwfmtState *ls = **(struct GwfmtState***)MEM(0); @@ -93,7 +94,8 @@ GWION_IMPORT(GwFmt) { import_bool_fun(header); import_bool_fun(show_lines); import_bool_fun(use_tabs); - import_bool_fun(fix); + import_bool_fun(fix_case); + import_bool_fun(check_case); GWI_B(gwi_func_ini(gwi, "void", "color")); GWI_B(gwi_func_arg(gwi, "ColorWhen", "arg")); diff --git a/src/lint.c b/src/lint.c index 3dbc5ae..04daf58 100644 --- a/src/lint.c +++ b/src/lint.c @@ -68,14 +68,15 @@ void flow(Gwfmt *a, const char *kw) { ANN static void check_tag(Gwfmt *a, const Tag * tag, const CaseType ct, char* color) { const Casing casing = a->ls->config->cases[ct]; - if(!casing.check(s_name(tag->sym))) { + if(a->ls->check_case && !casing.check(s_name(tag->sym))) { a->ls->error = true; - if(!a->ls->fix) { + if(!a->ls->fix_case) { char main[256]; char info[256]; snprintf(main, sizeof(main) - 1, "invalid {Y+}%s{0} casing", ct_name[ct]); snprintf(info, sizeof(info) - 1, "should be {W+}%s{0} case", casing.name); - gwlog_error(main, info, a->filename, tag->loc, 0); + printf("filename: %s\n", a->filename); + gwlog_error(main, info, a->filename ?: "/dev/null", tag->loc, 0); } else { char buf[256]; const char *name = s_name(tag->sym);