mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
wmaker: merge reading menu duplicate code
This patch is adding a readMenu function to be called from readMenuPipe and readMenuFile, saving about 20 lines of code. Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
committed by
Carlos R. Mafra
parent
09761a75f0
commit
0399d70868
@@ -4,6 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1997-2003 Alfredo K. Kojima
|
* Copyright (c) 1997-2003 Alfredo K. Kojima
|
||||||
* Copyright (c) 1998-2003 Dan Pascu
|
* Copyright (c) 1998-2003 Dan Pascu
|
||||||
|
* Copyright (c) 2014 Window Maker Team
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -60,7 +61,6 @@
|
|||||||
|
|
||||||
#define MAX_SHORTCUT_LENGTH 32
|
#define MAX_SHORTCUT_LENGTH 32
|
||||||
|
|
||||||
|
|
||||||
static WMenu *readMenuPipe(WScreen * scr, char **file_name);
|
static WMenu *readMenuPipe(WScreen * scr, char **file_name);
|
||||||
static WMenu *readPLMenuPipe(WScreen * scr, char **file_name);
|
static WMenu *readPLMenuPipe(WScreen * scr, char **file_name);
|
||||||
static WMenu *readMenuFile(WScreen *scr, const char *file_name);
|
static WMenu *readMenuFile(WScreen *scr, const char *file_name);
|
||||||
@@ -1048,19 +1048,13 @@ static WMenu *parseCascade(WScreen * scr, WMenu * menu, WMenuParser parser)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WMenu *readMenuFile(WScreen *scr, const char *file_name)
|
static WMenu *readMenu(WScreen *scr, const char *flat_file, FILE *file)
|
||||||
{
|
{
|
||||||
WMenu *menu = NULL;
|
WMenu *menu = NULL;
|
||||||
FILE *file = NULL;
|
|
||||||
WMenuParser parser;
|
WMenuParser parser;
|
||||||
char *command, *params, *shortcut, *title;
|
char *title, *command, *params, *shortcut;
|
||||||
|
|
||||||
file = fopen(file_name, "rb");
|
parser = WMenuParserCreate(flat_file, file, DEF_CONFIG_PATHS);
|
||||||
if (!file) {
|
|
||||||
werror(_("%s:could not open menu file"), file_name);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
parser = WMenuParserCreate(file_name, file, DEF_CONFIG_PATHS);
|
|
||||||
menu_parser_register_macros(parser);
|
menu_parser_register_macros(parser);
|
||||||
|
|
||||||
while (WMenuParserGetLine(parser, &title, &command, ¶ms, &shortcut)) {
|
while (WMenuParserGetLine(parser, &title, &command, ¶ms, &shortcut)) {
|
||||||
@@ -1080,14 +1074,29 @@ static WMenu *readMenuFile(WScreen *scr, const char *file_name)
|
|||||||
freeline(title, command, params, shortcut);
|
freeline(title, command, params, shortcut);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
WMenuParserError(parser, _("invalid menu file, MENU command is missing") );
|
WMenuParserError(parser, _("invalid menu, no menu title given") );
|
||||||
freeline(title, command, params, shortcut);
|
freeline(title, command, params, shortcut);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeline(title, command, params, shortcut);
|
freeline(title, command, params, shortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
WMenuParserDelete(parser);
|
WMenuParserDelete(parser);
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
static WMenu *readMenuFile(WScreen *scr, const char *file_name)
|
||||||
|
{
|
||||||
|
WMenu *menu = NULL;
|
||||||
|
FILE *file = NULL;
|
||||||
|
|
||||||
|
file = fopen(file_name, "rb");
|
||||||
|
if (!file) {
|
||||||
|
werror(_("%s:could not open menu file"), file_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
menu = readMenu(scr, file_name, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
@@ -1130,8 +1139,6 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name)
|
|||||||
{
|
{
|
||||||
WMenu *menu = NULL;
|
WMenu *menu = NULL;
|
||||||
FILE *file = NULL;
|
FILE *file = NULL;
|
||||||
WMenuParser parser;
|
|
||||||
char *command, *params, *shortcut, *title;
|
|
||||||
char *filename;
|
char *filename;
|
||||||
char flat_file[MAXLINE];
|
char flat_file[MAXLINE];
|
||||||
int i;
|
int i;
|
||||||
@@ -1149,35 +1156,7 @@ static WMenu *readMenuPipe(WScreen * scr, char **file_name)
|
|||||||
werror(_("%s:could not open menu file"), filename);
|
werror(_("%s:could not open menu file"), filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
parser = WMenuParserCreate(flat_file, file, DEF_CONFIG_PATHS);
|
menu = readMenu(scr, flat_file, file);
|
||||||
menu_parser_register_macros(parser);
|
|
||||||
|
|
||||||
while (WMenuParserGetLine(parser, &title, &command, ¶ms, &shortcut)) {
|
|
||||||
|
|
||||||
if (command == NULL || !command[0]) {
|
|
||||||
WMenuParserError(parser, _("missing command in menu config") );
|
|
||||||
freeline(title, command, params, shortcut);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (strcasecmp(command, "MENU") == 0) {
|
|
||||||
menu = wMenuCreate(scr, M_(title), True);
|
|
||||||
menu->on_destroy = removeShortcutsForMenu;
|
|
||||||
if (!parseCascade(scr, menu, parser)) {
|
|
||||||
wMenuDestroy(menu, True);
|
|
||||||
menu = NULL;
|
|
||||||
}
|
|
||||||
freeline(title, command, params, shortcut);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
WMenuParserError(parser, _("no title given for the root menu") );
|
|
||||||
freeline(title, command, params, shortcut);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
freeline(title, command, params, shortcut);
|
|
||||||
}
|
|
||||||
|
|
||||||
WMenuParserDelete(parser);
|
|
||||||
pclose(file);
|
pclose(file);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
|
|||||||
Reference in New Issue
Block a user