14 const char *filename,
const loc_t loc,
const uint error_code,
15 const enum libprettyerr_errtype errtype);
21 const loc_t loc NUSED) {
22 gw_err(
"{-}hint:{0} %s\n",
main);
44 FILE * f = fopen(filename,
"r");
46 fseek(f, 0, SEEK_SET);
48 while ((ret = getline(&line, &len, f)) != -1 && ++i < loc.
first.
line);
50 if (ret != -1)
return line;
56#ifndef BUILD_ON_WINDOWS
57 const char *pwd = getenv(
"PWD");
58 if(!pwd)
return filename;
61 GetCurrentDirectory(MAX_PATH, pwd);
63 size_t sz = strlen(pwd);
64 return !strncmp(pwd, filename, sz - 1) ? filename + sz + 1 : filename;
68static
void nosrc(const perr_printer_t *printer, const perr_t *err,
69 const
char *
main, const
char *explain) {
74 const int status = tcol_color_parse(color, 16, base, 2, &len);
75 if (status != TermColorErrorNone)
79 gw_err(
"[internal]\n");
80 perr_print_line_number(printer, err, color);
82 if (explain) gw_err(
"%s\n", explain);
86 const char *filename,
const loc_t loc,
const uint error_code,
87 const enum libprettyerr_errtype errtype) {
91 char *line =
get_src(filename, loc);
93 perr_printer_t printer;
94 perr_printer_init(&printer, stderr, line,
96 perr_runner_basic_style);
98 printer.rounded =
true;
103 const perr_t err = PERR_Error(
109 perr_print_error(&printer, &err);
116 const char *filename,
const loc_t loc,
const uint error_code) {
117 _error(
main, explain, filename, loc, error_code, PERR_ERROR);
121 const enum libprettyerr_errtype type,
123 perr_printer_t printer;
124 char * line =
get_src(filename, loc);
126 perr_printer_init(&printer, stderr, line,
128 perr_runner_secondary_style);
129 printer.rounded =
true;
131 const perr_t err = PERR_Secondary(
136 perr_print_error(&printer, &err);
include this file to use gwion-ast library
static gwlog_warning_function_t _related
ANN void gwlog_related(const char *main, const char *filename, const loc_t loc)
static ANN void _gwlog_secondary(const char *main, const char *filename, const enum libprettyerr_errtype type, const loc_t loc)
static gwlog_warning_function_t _hint
void gwlog_error(const char *main, const char *explain, const char *filename, const loc_t loc, const uint error_code)
static ANN char * get_src(const char *filename, const loc_t loc)
ANN void pos_ini(pos_t *pos)
static ANN void _gwlog_warning(const char *main, const char *filename, const loc_t loc)
static gwlog_error_function_t _error
static void _gwlog_error(const char *main, const char *explain, const char *filename, const loc_t loc, const uint error_code, const enum libprettyerr_errtype errtype)
ANN void gwlog_set_func(gwlog_error_function_t error, gwlog_warning_function_t warning, gwlog_warning_function_t related, gwlog_warning_function_t hint)
static gwlog_warning_function_t _warning
static const char * get_filename(const char *filename)
static ANN void _gwlog_related(const char *main, const char *filename, const loc_t loc)
ANN void gwlog_warning(const char *main, const char *filename, const loc_t loc)
static ANN void _gwlog_hint(const char *main, const char *filename NUSED, const loc_t loc NUSED)
void gwion_parser_set_default_pos(const pos_t pos)
static void nosrc(const perr_printer_t *printer, const perr_t *err, const char *main, const char *explain)
ANN void gwlog_hint(const char *main, const char *filename, const loc_t loc)
void(* gwlog_warning_function_t)(const char *main, const char *filename, const loc_t loc)
void(* gwlog_error_function_t)(const char *, const char *, const char *, const loc_t, const uint, const enum libprettyerr_errtype)
int main(int argc, char **argv)
short unsigned int column