mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
Instead of using a temporary buffer to store a "reason" string which is later printf()'ed by abortar(), use wwarning() directly and do the small cleanup done by abortar() on the spot. As this was the only call site for abortar() it can now be removed. The resulting object code gets smaller as a side effect. Thanks to Christophe <christophe.curis@free.fr> for finding a mistake in the first version of this patch.
412 lines
9.4 KiB
C
412 lines
9.4 KiB
C
/* getstyle.c - outputs style related options from WindowMaker to stdout
|
|
*
|
|
* WindowMaker window manager
|
|
*
|
|
* Copyright (c) 1997-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
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* 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.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#ifdef __GLIBC__
|
|
#define _GNU_SOURCE /* getopt_long */
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <getopt.h>
|
|
#include <libgen.h>
|
|
#include <limits.h>
|
|
#include <pwd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
#include <unistd.h>
|
|
|
|
#include <WINGs/WUtil.h>
|
|
|
|
#define RETRY( x ) do { \
|
|
x; \
|
|
} while (errno == EINTR);
|
|
|
|
#ifndef PATH_MAX
|
|
#define PATH_MAX 1024
|
|
#endif
|
|
|
|
#include "../src/wconfig.h"
|
|
|
|
#ifndef GLOBAL_DEFAULTS_SUBDIR
|
|
#define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
|
|
#endif
|
|
|
|
/* table of style related options */
|
|
static char *options[] = {
|
|
"TitleJustify",
|
|
"ClipTitleFont",
|
|
"WindowTitleFont",
|
|
"MenuTitleFont",
|
|
"MenuTextFont",
|
|
"IconTitleFont",
|
|
"DisplayFont",
|
|
"LargeDisplayFont",
|
|
"WindowTitleExtendSpace",
|
|
"MenuTitleExtendSpace",
|
|
"MenuTextExtendSpace",
|
|
"HighlightColor",
|
|
"HighlightTextColor",
|
|
"ClipTitleColor",
|
|
"CClipTitleColor",
|
|
"FTitleColor",
|
|
"PTitleColor",
|
|
"UTitleColor",
|
|
"FTitleBack",
|
|
"PTitleBack",
|
|
"UTitleBack",
|
|
"ResizebarBack",
|
|
"MenuTitleColor",
|
|
"MenuTextColor",
|
|
"MenuDisabledColor",
|
|
"MenuTitleBack",
|
|
"MenuTextBack",
|
|
"IconBack",
|
|
"IconTitleColor",
|
|
"IconTitleBack",
|
|
"MenuStyle",
|
|
"WindowTitleExtendSpace",
|
|
"MenuTitleExtendSpace",
|
|
"MenuTextExtendSpace",
|
|
NULL
|
|
};
|
|
|
|
/* table of theme related options */
|
|
static char *theme_options[] = {
|
|
"WorkspaceBack",
|
|
"NormalCursor",
|
|
"ArrowCursor",
|
|
"MoveCursor",
|
|
"ResizeCursor",
|
|
"TopLeftResizeCursor",
|
|
"TopRightResizeCursor",
|
|
"BottomLeftResizeCursor",
|
|
"BottomRightResizeCursor",
|
|
"VerticalResizeCursor",
|
|
"HorizontalResizeCursor",
|
|
"WaitCursor",
|
|
"QuestionCursor",
|
|
"TextCursor",
|
|
"SelectCursor",
|
|
NULL
|
|
};
|
|
|
|
/* table of style related fonts */
|
|
|
|
static char *font_options[] = {
|
|
"ClipTitleFont",
|
|
"WindowTitleFont",
|
|
"MenuTitleFont",
|
|
"MenuTextFont",
|
|
"IconTitleFont",
|
|
"DisplayFont",
|
|
"LargeDisplayFont",
|
|
NULL
|
|
};
|
|
|
|
extern char *__progname;
|
|
|
|
WMPropList *PixmapPath = NULL;
|
|
|
|
char *ThemePath = NULL;
|
|
|
|
extern char *convertFont(char *font, Bool keepXLFD);
|
|
|
|
void print_help(int print_usage, int exitval)
|
|
{
|
|
printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname);
|
|
if (print_usage) {
|
|
puts("Retrieves style/theme configuration and outputs to ~/GNUstep/Library/WindowMaker/Themes/file.themed/style or to stdout");
|
|
puts("");
|
|
puts(" -h, --help display this help and exit");
|
|
puts(" -v, --version output version information and exit");
|
|
puts(" -t, --theme-options output theme related options when producing a style file");
|
|
puts(" -p, --pack produce output as a theme pack");
|
|
}
|
|
exit(exitval);
|
|
}
|
|
|
|
static Bool isFontOption(char *option)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; font_options[i] != NULL; i++) {
|
|
if (strcasecmp(option, font_options[i]) == 0) {
|
|
return True;
|
|
}
|
|
}
|
|
|
|
return False;
|
|
}
|
|
|
|
void findCopyFile(char *dir, char *file)
|
|
{
|
|
char *fullPath;
|
|
|
|
fullPath = wfindfileinarray(PixmapPath, file);
|
|
if (!fullPath) {
|
|
wwarning("Could not find file %s", file);
|
|
if (ThemePath)
|
|
(void)wrmdirhier(ThemePath);
|
|
}
|
|
copy_file(dir, fullPath, fullPath);
|
|
free(fullPath);
|
|
}
|
|
|
|
void makeThemePack(WMPropList * style, char *themeName)
|
|
{
|
|
WMPropList *keys;
|
|
WMPropList *key;
|
|
WMPropList *value;
|
|
int i;
|
|
size_t themeNameLen;
|
|
char *themeDir, *t;
|
|
|
|
if ((t = wusergnusteppath()) == NULL)
|
|
return;
|
|
themeNameLen = strlen(t) + strlen(themeName) + 50;
|
|
themeDir = wmalloc(themeNameLen);
|
|
snprintf(themeDir, themeNameLen, "%s/Library/WindowMaker/Themes/%s.themed/", t, themeName);
|
|
ThemePath = themeDir;
|
|
|
|
if (!wmkdirhier(themeDir)) {
|
|
wwarning("Could not make theme dir %s\n", themeDir);
|
|
return;
|
|
}
|
|
|
|
keys = WMGetPLDictionaryKeys(style);
|
|
|
|
for (i = 0; i < WMGetPropListItemCount(keys); i++) {
|
|
key = WMGetFromPLArray(keys, i);
|
|
|
|
value = WMGetFromPLDictionary(style, key);
|
|
if (value && WMIsPLArray(value) && WMGetPropListItemCount(value) > 2) {
|
|
WMPropList *type;
|
|
char *t;
|
|
|
|
type = WMGetFromPLArray(value, 0);
|
|
t = WMGetFromPLString(type);
|
|
if (t == NULL)
|
|
continue;
|
|
|
|
if (strcasecmp(t, "tpixmap") == 0 ||
|
|
strcasecmp(t, "spixmap") == 0 ||
|
|
strcasecmp(t, "cpixmap") == 0 ||
|
|
strcasecmp(t, "mpixmap") == 0 ||
|
|
strcasecmp(t, "tdgradient") == 0 ||
|
|
strcasecmp(t, "tvgradient") == 0 ||
|
|
strcasecmp(t, "thgradient") == 0) {
|
|
|
|
WMPropList *file;
|
|
char *p;
|
|
char *newPath;
|
|
|
|
file = WMGetFromPLArray(value, 1);
|
|
|
|
p = strrchr(WMGetFromPLString(file), '/');
|
|
if (p) {
|
|
copy_file(themeDir, WMGetFromPLString(file), WMGetFromPLString(file));
|
|
|
|
newPath = wstrdup(p + 1);
|
|
WMDeleteFromPLArray(value, 1);
|
|
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
|
|
free(newPath);
|
|
} else {
|
|
findCopyFile(themeDir, WMGetFromPLString(file));
|
|
}
|
|
} else if (strcasecmp(t, "bitmap") == 0) {
|
|
|
|
WMPropList *file;
|
|
char *p;
|
|
char *newPath;
|
|
|
|
file = WMGetFromPLArray(value, 1);
|
|
|
|
p = strrchr(WMGetFromPLString(file), '/');
|
|
if (p) {
|
|
copy_file(themeDir, WMGetFromPLString(file), WMGetFromPLString(file));
|
|
|
|
newPath = wstrdup(p + 1);
|
|
WMDeleteFromPLArray(value, 1);
|
|
WMInsertInPLArray(value, 1, WMCreatePLString(newPath));
|
|
free(newPath);
|
|
} else {
|
|
findCopyFile(themeDir, WMGetFromPLString(file));
|
|
}
|
|
|
|
file = WMGetFromPLArray(value, 2);
|
|
|
|
p = strrchr(WMGetFromPLString(file), '/');
|
|
if (p) {
|
|
copy_file(themeDir, WMGetFromPLString(file), WMGetFromPLString(file));
|
|
|
|
newPath = wstrdup(p + 1);
|
|
WMDeleteFromPLArray(value, 2);
|
|
WMInsertInPLArray(value, 2, WMCreatePLString(newPath));
|
|
free(newPath);
|
|
} else {
|
|
findCopyFile(themeDir, WMGetFromPLString(file));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
WMPropList *prop, *style, *key, *val;
|
|
char *path, *p;
|
|
int i, ch, theme_too = 0, make_pack = 0;
|
|
char *style_file = NULL;
|
|
|
|
struct option longopts[] = {
|
|
{ "pack", no_argument, NULL, 'p' },
|
|
{ "theme-options", no_argument, NULL, 't' },
|
|
{ "version", no_argument, NULL, 'v' },
|
|
{ "help", no_argument, NULL, 'h' },
|
|
{ NULL, 0, NULL, 0 }
|
|
};
|
|
|
|
while ((ch = getopt_long(argc, argv, "ptvh", longopts, NULL)) != -1)
|
|
switch(ch) {
|
|
case 'v':
|
|
printf("%s (Window Maker %s)\n", __progname, VERSION);
|
|
return 0;
|
|
/* NOTREACHED */
|
|
case 'h':
|
|
print_help(1, 0);
|
|
/* NOTREACHED */
|
|
case 'p':
|
|
make_pack = 1;
|
|
theme_too = 1;
|
|
break;
|
|
case 't':
|
|
theme_too = 1;
|
|
case 0:
|
|
break;
|
|
default:
|
|
print_help(0, 1);
|
|
/* NOTREACHED */
|
|
}
|
|
|
|
/* At most one non-option ARGV-element is accepted (the theme name) */
|
|
if (argc - optind > 1)
|
|
print_help(0, 1);
|
|
|
|
if (argc - optind == 1) {
|
|
style_file = argv[argc - 1];
|
|
while ((p = strchr(style_file, '/')) != NULL)
|
|
*p = '_';
|
|
}
|
|
|
|
/* A theme name was given but the option to create it (-p) was not */
|
|
if (style_file && !make_pack)
|
|
print_help(0, 1);
|
|
|
|
if (make_pack && !style_file) {
|
|
printf("%s: you must supply a name for the theme pack\n", __progname);
|
|
return 1;
|
|
}
|
|
|
|
WMPLSetCaseSensitive(False);
|
|
|
|
path = wdefaultspathfordomain("WindowMaker");
|
|
|
|
prop = WMReadPropListFromFile(path);
|
|
if (!prop) {
|
|
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
|
|
return 1;
|
|
}
|
|
|
|
/* get global value */
|
|
path = wglobaldefaultspathfordomain("WindowMaker");
|
|
|
|
val = WMReadPropListFromFile(path);
|
|
if (val) {
|
|
WMMergePLDictionaries(val, prop, True);
|
|
WMReleasePropList(prop);
|
|
prop = val;
|
|
}
|
|
|
|
style = WMCreatePLDictionary(NULL, NULL);
|
|
|
|
for (i = 0; options[i] != NULL; i++) {
|
|
key = WMCreatePLString(options[i]);
|
|
|
|
val = WMGetFromPLDictionary(prop, key);
|
|
if (val) {
|
|
WMRetainPropList(val);
|
|
if (isFontOption(options[i])) {
|
|
char *newfont, *oldfont;
|
|
|
|
oldfont = WMGetFromPLString(val);
|
|
newfont = convertFont(oldfont, False);
|
|
/* newfont is a reference to old if conversion is not needed */
|
|
if (newfont != oldfont) {
|
|
WMReleasePropList(val);
|
|
val = WMCreatePLString(newfont);
|
|
wfree(newfont);
|
|
}
|
|
}
|
|
WMPutInPLDictionary(style, key, val);
|
|
WMReleasePropList(val);
|
|
}
|
|
WMReleasePropList(key);
|
|
}
|
|
|
|
val = WMGetFromPLDictionary(prop, WMCreatePLString("PixmapPath"));
|
|
if (val)
|
|
PixmapPath = val;
|
|
|
|
if (theme_too) {
|
|
for (i = 0; theme_options[i] != NULL; i++) {
|
|
key = WMCreatePLString(theme_options[i]);
|
|
|
|
val = WMGetFromPLDictionary(prop, key);
|
|
if (val)
|
|
WMPutInPLDictionary(style, key, val);
|
|
}
|
|
}
|
|
|
|
if (make_pack) {
|
|
char *path;
|
|
|
|
makeThemePack(style, style_file);
|
|
|
|
path = wmalloc(strlen(ThemePath) + 32);
|
|
strcpy(path, ThemePath);
|
|
strcat(path, "/style");
|
|
WMWritePropListToFile(style, path);
|
|
wfree(path);
|
|
} else {
|
|
if (style_file) {
|
|
WMWritePropListToFile(style, style_file);
|
|
} else {
|
|
puts(WMGetPropListDescription(style, True));
|
|
}
|
|
}
|
|
return 0;
|
|
}
|