1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

Remove dependency to CPP: added pre-defined macros

A number of macros are pre-defined by WindowMaker for CPP in the
function 'MakeCPPArgs', they are now available in the internal
parser too. CPP also had some predefined macros, a subset of them
have been added.
The definition have been split in two parts:
 - the macro that are dependant on WindowMaker parameters are
defined by WindowMaker (src/rootmenu.c)
 - those that are independant, which can be defined by the parser
itself (WINGs/menuparser_macros.c)
This commit is contained in:
Christophe CURIS
2012-06-23 15:21:43 +02:00
committed by Carlos R. Mafra
parent aaa4517df7
commit 9b792369cb
5 changed files with 226 additions and 0 deletions

View File

@@ -65,6 +65,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name);
static WMenu *readMenuFile(WScreen * scr, char *file_name);
static WMenu *readMenuDirectory(WScreen * scr, char *title, char **file_name, char *command);
static WMenu *configureMenu(WScreen * scr, WMPropList * definition, Bool includeGlobals);
static void menu_parser_register_macros(WMenuParser parser);
typedef struct Shortcut {
struct Shortcut *next;
@@ -970,6 +971,7 @@ static WMenu *readMenuFile(WScreen * scr, char *file_name)
}
}
parser = WMenuParserCreate(file_name, file, DEF_CONFIG_PATHS);
menu_parser_register_macros(parser);
while (WMenuParserGetLine(parser, &title, &command, &params, &shortcut)) {
@@ -1061,6 +1063,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name)
}
}
parser = WMenuParserCreate(flat_file, file, DEF_CONFIG_PATHS);
menu_parser_register_macros(parser);
while (WMenuParserGetLine(parser, &title, &command, &params, &shortcut)) {
@@ -1106,6 +1109,34 @@ static int myCompare(const void *d1, const void *d2)
return strcmp(p1->name, p2->name);
}
/***** Preset some macro for file parser *****/
static void menu_parser_register_macros(WMenuParser parser)
{
Visual *visual;
char buf[32];
// Used to return CPP verion, now returns wmaker's version
WMenuParserRegisterSimpleMacro(parser, "__VERSION__", VERSION);
// All macros below were historically defined by WindowMaker
visual = DefaultVisual(dpy, DefaultScreen(dpy));
snprintf(buf, sizeof(buf), "%d", visual->class);
WMenuParserRegisterSimpleMacro(parser, "VISUAL", buf);
snprintf(buf, sizeof(buf), "%d", DefaultDepth(dpy, DefaultScreen(dpy)) );
WMenuParserRegisterSimpleMacro(parser, "DEPTH", buf);
snprintf(buf, sizeof(buf), "%d", WidthOfScreen(DefaultScreenOfDisplay(dpy)) );
WMenuParserRegisterSimpleMacro(parser, "SCR_WIDTH", buf);
snprintf(buf, sizeof(buf), "%d", HeightOfScreen(DefaultScreenOfDisplay(dpy)) );
WMenuParserRegisterSimpleMacro(parser, "SCR_HEIGHT", buf);
WMenuParserRegisterSimpleMacro(parser, "DISPLAY", XDisplayName(DisplayString(dpy)) );
WMenuParserRegisterSimpleMacro(parser, "WM_VERSION", "\"" VERSION "\"");
}
/************ Menu Configuration From Directory *************/
static Bool isFilePackage(char *file)