mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-08 23:04:15 +01:00
changed indentation to use spaces only
This commit is contained in:
369
src/menureader.c
369
src/menureader.c
@@ -1,9 +1,9 @@
|
||||
/* menureader.c- root menu definition readers
|
||||
*
|
||||
*
|
||||
* Window Maker window manager
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2000-2003 Alfredo K. Kojima
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
* USA.
|
||||
*/
|
||||
|
||||
@@ -39,11 +39,11 @@ typedef struct PLMenuReaderData {
|
||||
|
||||
WMPropList *pl;
|
||||
int curIndex;
|
||||
|
||||
|
||||
WMPropList **submenu;
|
||||
int *curSubIndex;
|
||||
int submenuDepth;
|
||||
|
||||
|
||||
} PLMenuReaderData;
|
||||
|
||||
|
||||
@@ -51,13 +51,13 @@ typedef struct TextMenuReaderData {
|
||||
WRootMenuReader *reader;
|
||||
|
||||
FILE *file;
|
||||
|
||||
|
||||
} TextMenuReaderData;
|
||||
|
||||
|
||||
typedef struct PipeMenuReaderData {
|
||||
WRootMenuReader *reader;
|
||||
|
||||
|
||||
} PipeMenuReaderData;
|
||||
|
||||
|
||||
@@ -70,9 +70,9 @@ typedef struct DirMenuReaderData {
|
||||
} DirMenuReaderData;
|
||||
|
||||
/*
|
||||
typedef struct GNOMEMenuReaderData {
|
||||
} GNOMEMenuReaderData;
|
||||
*/
|
||||
typedef struct GNOMEMenuReaderData {
|
||||
} GNOMEMenuReaderData;
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -81,10 +81,10 @@ typedef struct GNOMEMenuReaderData {
|
||||
static WRootMenuData *pl_openMenu(WMPropList *pl);
|
||||
static Bool pl_hasMoreData(WRootMenuData *data);
|
||||
static Bool pl_nextCommand(WRootMenuData *data,
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut);
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut);
|
||||
static void pl_closeMenuFile(WRootMenuData *data);
|
||||
|
||||
|
||||
@@ -92,20 +92,20 @@ static void pl_closeMenuFile(WRootMenuData *data);
|
||||
static WRootMenuData *text_openMenuFile(char *path);
|
||||
static Bool text_hasMoreData(WRootMenuData *data);
|
||||
static Bool text_nextCommand(WRootMenuData *data,
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut);
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut);
|
||||
static void text_closeMenuFile(WRootMenuData *data);
|
||||
|
||||
|
||||
static WRootMenuData *dir_openMenuFile(char *path);
|
||||
static Bool dir_hasMoreData(WRootMenuData *data);
|
||||
static Bool dir_nextCommand(WRootMenuData *data,
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut);
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut);
|
||||
static void dir_closeMenuFile(WRootMenuData *data);
|
||||
|
||||
|
||||
@@ -114,27 +114,27 @@ static void dir_closeMenuFile(WRootMenuData *data);
|
||||
|
||||
|
||||
static WRootMenuReader PLMenuReader = {
|
||||
pl_hasMoreData,
|
||||
pl_nextCommand,
|
||||
pl_closeMenuFile
|
||||
pl_hasMoreData,
|
||||
pl_nextCommand,
|
||||
pl_closeMenuFile
|
||||
};
|
||||
|
||||
static WRootMenuReader TextMenuReader = {
|
||||
text_hasMoreData,
|
||||
text_nextCommand,
|
||||
text_closeMenuFile
|
||||
text_hasMoreData,
|
||||
text_nextCommand,
|
||||
text_closeMenuFile
|
||||
};
|
||||
|
||||
static WRootMenuReader DirMenuReaderData = {
|
||||
dir_hasMoreData,
|
||||
dir_nextCommand,
|
||||
dir_closeMenuFile
|
||||
dir_hasMoreData,
|
||||
dir_nextCommand,
|
||||
dir_closeMenuFile
|
||||
};
|
||||
|
||||
/*
|
||||
WRootMenuReader GNOMEMenuReaderData = {
|
||||
};
|
||||
*/
|
||||
WRootMenuReader GNOMEMenuReaderData = {
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -148,7 +148,8 @@ static char linebuf[LINESIZE];
|
||||
/* ---------- proplist ---------- */
|
||||
|
||||
|
||||
static WRootMenuData *pl_openMenuFile(WMPropList *pl)
|
||||
static WRootMenuData*
|
||||
pl_openMenuFile(WMPropList *pl)
|
||||
{
|
||||
PLRootMenuData *data = wmalloc(sizeof(PLRootMenuData));
|
||||
|
||||
@@ -165,29 +166,29 @@ static WRootMenuData *pl_openMenuFile(WMPropList *pl)
|
||||
}
|
||||
|
||||
|
||||
static Bool pl_hasMoreData(WRootMenuData *data)
|
||||
static Bool
|
||||
pl_hasMoreData(WRootMenuData *data)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static Bool pl_nextCommand(WRootMenuData *data,
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut)
|
||||
static Bool
|
||||
pl_nextCommand(WRootMenuData *data, char **title, char **command,
|
||||
char **parameter, char **shortcut)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void pl_closeMenuFile(WRootMenuData *data)
|
||||
static void
|
||||
pl_closeMenuFile(WRootMenuData *data)
|
||||
{
|
||||
if (data->submenu)
|
||||
wfree(data->submenu);
|
||||
wfree(data->submenu);
|
||||
if (data->curSubIndex)
|
||||
wfree(data->curSubIndex);
|
||||
wfree(data->curSubIndex);
|
||||
|
||||
WMReleasePropList(data->pl);
|
||||
|
||||
|
||||
wfree(data);
|
||||
}
|
||||
|
||||
@@ -195,36 +196,37 @@ static void pl_closeMenuFile(WRootMenuData *data)
|
||||
/* ---------- text ---------- */
|
||||
|
||||
|
||||
static WRootMenuData *text_openMenuFile(char *path)
|
||||
static WRootMenuData*
|
||||
text_openMenuFile(char *path)
|
||||
{
|
||||
TextMenuReaderData *data;
|
||||
|
||||
|
||||
data = wmalloc(sizeof(TextMenuReaderData));
|
||||
data->reader = TextMenuReader;
|
||||
|
||||
|
||||
data->file = fopen(path, "rb");
|
||||
if (!data->file) {
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Bool text_hasMoreData(WRootMenuData *data)
|
||||
static Bool
|
||||
text_hasMoreData(WRootMenuData *data)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static Bool text_nextCommand(WRootMenuData *data,
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut)
|
||||
static Bool
|
||||
text_nextCommand(WRootMenuData *data, char **title, char **command,
|
||||
char **parameter, char **shortcut)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void text_closeMenuFile(WRootMenuData *data)
|
||||
static void
|
||||
text_closeMenuFile(WRootMenuData *data)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -232,7 +234,8 @@ static void text_closeMenuFile(WRootMenuData *data)
|
||||
/* ---------- directory ---------- */
|
||||
|
||||
|
||||
static WRootMenuData *dir_openMenuFile(char *paths, time_t *timestamp)
|
||||
static WRootMenuData*
|
||||
dir_openMenuFile(char *paths, time_t *timestamp)
|
||||
{
|
||||
DirMenuReaderData *data;
|
||||
char **dirs;
|
||||
@@ -245,119 +248,117 @@ static WRootMenuData *dir_openMenuFile(char *paths, time_t *timestamp)
|
||||
wtokensplit(paths, &dirs, &dirN);
|
||||
|
||||
if (dirN == 0) {
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (c = 0, i = 0; i < dirN; i++) {
|
||||
char *tmp;
|
||||
char *tmp;
|
||||
|
||||
if (strcmp(dirs[i], "-noext")==0) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(dirs[i], "-noext")==0) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp = wexpandpath(dirs[i]);
|
||||
wfree(dirs[i]);
|
||||
dirs[i] = tmp;
|
||||
tmp = wexpandpath(dirs[i]);
|
||||
wfree(dirs[i]);
|
||||
dirs[i] = tmp;
|
||||
|
||||
if (stat(dirs[i], &stat_buf)<0) {
|
||||
wsyserror(_("%s:could not stat menu"), dirs[i]);
|
||||
wfree(dirs[i]);
|
||||
dirs[i] = NULL;
|
||||
} else {
|
||||
c++;
|
||||
checksum += stat_buf.st_mtime;
|
||||
}
|
||||
if (stat(dirs[i], &stat_buf)<0) {
|
||||
wsyserror(_("%s:could not stat menu"), dirs[i]);
|
||||
wfree(dirs[i]);
|
||||
dirs[i] = NULL;
|
||||
} else {
|
||||
c++;
|
||||
checksum += stat_buf.st_mtime;
|
||||
}
|
||||
}
|
||||
|
||||
if (*timestamp == checksum && *timestamp != 0) {
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (c == 0) {
|
||||
for (i = 0; i < dirN; i++) {
|
||||
if (dirs[i])
|
||||
wfree(dirs[i]);
|
||||
}
|
||||
wfree(dirs);
|
||||
|
||||
return NULL;
|
||||
for (i = 0; i < dirN; i++) {
|
||||
if (dirs[i])
|
||||
wfree(dirs[i]);
|
||||
}
|
||||
wfree(dirs);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
data = wmalloc(sizeof(DirMenuReaderData));
|
||||
data->reader = DirMenuReader;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
static Bool dir_hasMoreData(WRootMenuData *data)
|
||||
static Bool
|
||||
dir_hasMoreData(WRootMenuData *data)
|
||||
{
|
||||
}
|
||||
|
||||
static Bool dir_nextCommand(WRootMenuData *data,
|
||||
char **title,
|
||||
char **command,
|
||||
char **parameter,
|
||||
char **shortcut)
|
||||
static Bool
|
||||
dir_nextCommand(WRootMenuData *data, char **title, char **command,
|
||||
char **parameter, char **shortcut)
|
||||
{
|
||||
}
|
||||
|
||||
static void dir_closeMenuFile(WRootMenuData *data)
|
||||
static void
|
||||
dir_closeMenuFile(WRootMenuData *data)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
WRootMenuData *OpenMenu(char *path, time_t *menuTime)
|
||||
WRootMenuData*
|
||||
OpenMenu(char *path, time_t *menuTime)
|
||||
{
|
||||
proplist pl;
|
||||
struct stat stat_buf;
|
||||
WRootMenuData *data;
|
||||
|
||||
|
||||
/* check whether it's a piped menu */
|
||||
if (*path == '|') {
|
||||
/* piped menus have the following semantics for menuTime:
|
||||
* if it's 0, then it wasnt loaded yet
|
||||
* if it's 1, it was already loaded, so do not reload
|
||||
* (would be too slow)
|
||||
* now, menuTime will only be set to 1 if the pipe command is
|
||||
* specified as ||command instead of |command
|
||||
* in other words ||command means force the submenu to always refresh
|
||||
*/
|
||||
if (*menuTime == 0) {
|
||||
data = pipe_openMenu(path);
|
||||
}
|
||||
if (path[1] != '|') {
|
||||
*menuTime = 1;
|
||||
}
|
||||
return data;
|
||||
/* piped menus have the following semantics for menuTime:
|
||||
* if it's 0, then it wasnt loaded yet
|
||||
* if it's 1, it was already loaded, so do not reload
|
||||
* (would be too slow)
|
||||
* now, menuTime will only be set to 1 if the pipe command is
|
||||
* specified as ||command instead of |command
|
||||
* in other words ||command means force the submenu to always refresh
|
||||
*/
|
||||
if (*menuTime == 0) {
|
||||
data = pipe_openMenu(path);
|
||||
}
|
||||
if (path[1] != '|') {
|
||||
*menuTime = 1;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
if (stat(path, &stat_buf) < 0) {
|
||||
wsyserror(_("could not stat() menu file '%s'"));
|
||||
return NULL;
|
||||
wsyserror(_("could not stat() menu file '%s'"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* check whether it's a directory */
|
||||
if (S_ISDIR(stat_buf.st_mode)) {
|
||||
return dir_openMenuFile(path, menuTime);
|
||||
return dir_openMenuFile(path, menuTime);
|
||||
}
|
||||
|
||||
|
||||
if (*menuTime >= stat_buf.st_mtime && *menuTime != 0) {
|
||||
/* no changes in the menu file */
|
||||
return NULL;
|
||||
/* no changes in the menu file */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* then check whether it's a proplist menu */
|
||||
pl = WMReadPropListFromFile(path);
|
||||
if (pl && WMIsPLArray(pl)) {
|
||||
*menuTime = stat_buf.st_mtime;
|
||||
return pl_openMenu(pl);
|
||||
*menuTime = stat_buf.st_mtime;
|
||||
return pl_openMenu(pl);
|
||||
}
|
||||
|
||||
*menuTime = stat_buf.st_mtime;
|
||||
@@ -366,97 +367,95 @@ WRootMenuData *OpenMenu(char *path, time_t *menuTime)
|
||||
}
|
||||
|
||||
|
||||
|
||||
WRootMenuData *ReopenRootMenu(time_t *checkTime,
|
||||
char **menuPath,
|
||||
time_t *menuTimestamp)
|
||||
WRootMenuData*
|
||||
ReopenRootMenu(time_t *checkTime, char **menuPath, time_t *menuTimestamp)
|
||||
{
|
||||
proplist pl;
|
||||
struct stat stat_buf;
|
||||
char *path;
|
||||
|
||||
|
||||
|
||||
if (stat(path, &stat_buf) < 0) {
|
||||
wsyserror(_("could not stat() menu file '%s'"));
|
||||
return NULL;
|
||||
wsyserror(_("could not stat() menu file '%s'"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*menuTime >= stat_buf.st_mtime && *checkTime != 0) {
|
||||
/* no changes in WMRootMenu, see if the contents changed */
|
||||
if (*menuPath != NULL) {
|
||||
return OpenMenu(*menuPath, menuTimestamp);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
/* no changes in WMRootMenu, see if the contents changed */
|
||||
if (*menuPath != NULL) {
|
||||
return OpenMenu(*menuPath, menuTimestamp);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
*checkTime = stat_buf.st_mtime;
|
||||
|
||||
pl = WMReadPropListFromFile(path);
|
||||
if (!pl) {
|
||||
wwarning(_("could not load domain %s from user defaults database"),
|
||||
"WMRootMenu");
|
||||
return NULL;
|
||||
wwarning(_("could not load domain %s from user defaults database"),
|
||||
"WMRootMenu");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (WMIsPLString(pl)) {
|
||||
char *tmp;
|
||||
char *path;
|
||||
Bool menu_is_default = False;
|
||||
char *tmp;
|
||||
char *path;
|
||||
Bool menu_is_default = False;
|
||||
|
||||
tmp = wexpandpath(WMGetFromPLString(pl));
|
||||
tmp = wexpandpath(WMGetFromPLString(pl));
|
||||
|
||||
path = getLocalizedMenuFile(tmp);
|
||||
path = getLocalizedMenuFile(tmp);
|
||||
|
||||
if (!path) {
|
||||
path = wfindfile(DEF_CONFIG_PATHS, tmp);
|
||||
}
|
||||
if (!path) {
|
||||
path = wfindfile(DEF_CONFIG_PATHS, tmp);
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
wwarning(_("could not find menu file '%s' referenced in WMRootMenu"),
|
||||
tmp);
|
||||
path = wfindfile(DEF_CONFIG_PATHS, DEF_MENU_FILE);
|
||||
menu_is_default = True;
|
||||
}
|
||||
if (!path) {
|
||||
wwarning(_("could not find menu file '%s' referenced in WMRootMenu"),
|
||||
tmp);
|
||||
path = wfindfile(DEF_CONFIG_PATHS, DEF_MENU_FILE);
|
||||
menu_is_default = True;
|
||||
}
|
||||
|
||||
if (!path) {
|
||||
wwarning(_("could not find any usable menu files. Please check '%s'"),
|
||||
tmp);
|
||||
wfree(tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wfree(tmp);
|
||||
|
||||
if (*menuPath) {
|
||||
if (strcmp(*menuPath, path) != 0) {
|
||||
*menuTimestamp = 0;
|
||||
wfree(*menuPath);
|
||||
*menuPath = path;
|
||||
|
||||
if (menu_is_default) {
|
||||
wwarning(_("using default menu file \"%s\" as the menu referenced in WMRootMenu could not be found "),
|
||||
path);
|
||||
}
|
||||
} else {
|
||||
/* the menu path didn't change, but the
|
||||
* pointed file might have changed, so we don't return
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
*menuPath = path;
|
||||
}
|
||||
if (!path) {
|
||||
wwarning(_("could not find any usable menu files. Please check '%s'"),
|
||||
tmp);
|
||||
wfree(tmp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return OpenMenu(*menuPath, menuTimestamp);
|
||||
wfree(tmp);
|
||||
|
||||
if (*menuPath) {
|
||||
if (strcmp(*menuPath, path) != 0) {
|
||||
*menuTimestamp = 0;
|
||||
wfree(*menuPath);
|
||||
*menuPath = path;
|
||||
|
||||
if (menu_is_default) {
|
||||
wwarning(_("using default menu file \"%s\" as the menu referenced in WMRootMenu could not be found "),
|
||||
path);
|
||||
}
|
||||
} else {
|
||||
/* the menu path didn't change, but the
|
||||
* pointed file might have changed, so we don't return
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
*menuPath = path;
|
||||
}
|
||||
|
||||
return OpenMenu(*menuPath, menuTimestamp);
|
||||
} else if (WMIsPLArray(pl)) {
|
||||
|
||||
*menuTimestamp = stat_buf.st_mtime;
|
||||
*menuTimestamp = stat_buf.st_mtime;
|
||||
|
||||
return pl_openMenu(pl);
|
||||
return pl_openMenu(pl);
|
||||
} else {
|
||||
wwarning(_("invalid content in menu file '%s'.\nIt should either be a property list menu or the path to the file, enclosed in \"."),
|
||||
path);
|
||||
return NULL;
|
||||
wwarning(_("invalid content in menu file '%s'.\nIt should either be a property list menu or the path to the file, enclosed in \"."),
|
||||
path);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user