mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 04:48:06 +01:00
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!)
This commit is contained in:
committed by
Carlos R. Mafra
parent
42cccb2313
commit
7d74648fc3
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user