From 7d74648fc37037bb9d49a8f29d022454a36996e9 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 8 Jul 2012 02:12:36 +0200 Subject: [PATCH] Remove dependency to CPP: add function to report problems while parsing The default function used so far provides informations not so useful to user, like wmaker's source file, line number and function; it also cannot provide the line number from the parsed file because cpp messes this information. With this dedicated function we try to provide useful things which are being tracked by the parser internally, like valid line number and the name of the file being read (which can be convenient in the case of #include, for which we may also be able to provide the inclusion tree!) --- WINGs/WINGs/WUtil.h | 3 +++ WINGs/menuparser.c | 13 +++++++++++-- src/rootmenu.c | 12 ++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index c19a0af7..e62b72bc 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -874,6 +874,9 @@ typedef struct w_menu_parser *WMenuParser; WMenuParser WMenuParserCreate(const char *file_name, void *file); +void WMenuParserError(WMenuParser parser, const char *msg, ...) + __attribute__ ((format (printf, 2, 3))); + const char *WMenuParserGetFilename(WMenuParser parser); Bool WMenuParserGetLine(WMenuParser parser, char **title, char **command, char **parameter, char **shortcut); diff --git a/WINGs/menuparser.c b/WINGs/menuparser.c index f4a77a20..e36d1af3 100644 --- a/WINGs/menuparser.c +++ b/WINGs/menuparser.c @@ -63,6 +63,16 @@ const char *WMenuParserGetFilename(WMenuParser parser) return parser->file_name; } +void WMenuParserError(WMenuParser parser, const char *msg, ...) +{ + char buf[MAXLINE]; + va_list args; + + va_start(args, msg); + vsnprintf(buf, sizeof(buf), msg, args); + va_end(args); + __wmessage("WMenuParser", parser->file_name, parser->line_number, WMESSAGE_TYPE_WARNING, buf); +} /***** Read one line from file and split content *****/ Bool WMenuParserGetLine(WMenuParser top_parser, char **title, char **command, char **parameter, char **shortcut) @@ -111,8 +121,7 @@ again: result = NULL; goto again; } else if (result != NULL && strlen(result) >= MAXLINE) { - wwarning(_("%s:maximal line size exceeded in menu config: %s"), - cur_parser->file_name, line); + WMenuParserError(cur_parser, _("maximal line size exceeded in menu config") ); wfree(result); result = NULL; goto again; diff --git a/src/rootmenu.c b/src/rootmenu.c index 609079e4..932a3625 100644 --- a/src/rootmenu.c +++ b/src/rootmenu.c @@ -898,7 +898,7 @@ static WMenu *parseCascade(WScreen * scr, WMenu * menu, WMenuParser parser) while (WMenuParserGetLine(parser, &title, &command, ¶ms, &shortcut)) { if (command == NULL || !command[0]) { - wwarning(_("%s:missing command in menu config"), WMenuParserGetFilename(parser)); + WMenuParserError(parser, _("missing command in menu config") ); freeline(title, command, params, shortcut); goto error; } @@ -926,7 +926,7 @@ static WMenu *parseCascade(WScreen * scr, WMenu * menu, WMenuParser parser) freeline(title, command, params, shortcut); } - wwarning(_("%s:syntax error in menu file:END declaration missing"), WMenuParserGetFilename(parser)); + WMenuParserError(parser, _("syntax error in menu file: END declaration missing") ); error: return NULL; @@ -974,7 +974,7 @@ static WMenu *readMenuFile(WScreen * scr, char *file_name) while (WMenuParserGetLine(parser, &title, &command, ¶ms, &shortcut)) { if (command == NULL || !command[0]) { - wwarning(_("%s:missing command in menu config"), file_name); + WMenuParserError(parser, _("missing command in menu config") ); freeline(title, command, params, shortcut); break; } @@ -988,7 +988,7 @@ static WMenu *readMenuFile(WScreen * scr, char *file_name) freeline(title, command, params, shortcut); break; } else { - wwarning(_("%s:invalid menu file. MENU command is missing"), file_name); + WMenuParserError(parser, _("invalid menu file, MENU command is missing") ); freeline(title, command, params, shortcut); break; } @@ -1065,7 +1065,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name) while (WMenuParserGetLine(parser, &title, &command, ¶ms, &shortcut)) { if (command == NULL || !command[0]) { - wwarning(_("%s:missing command in menu config"), filename); + WMenuParserError(parser, _("missing command in menu config") ); freeline(title, command, params, shortcut); break; } @@ -1079,7 +1079,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name) freeline(title, command, params, shortcut); break; } else { - wwarning(_("%s:no title given for the root menu"), filename); + WMenuParserError(parser, _("no title given for the root menu") ); freeline(title, command, params, shortcut); break; } -- 2.11.4.GIT