1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-22 22:28:02 +01:00

Idle fixes

- add new wglobaldefaultspathfordomain() to wings (replaces several
  hand-rolled individual implementations in utils/)
- make all of 'em handle -h|--help, -v|--version
- try making them not to nothing silently
- change various ways of knowing thyselves to using __progname
- generally try to make them feel similar (NOT right, similar --
  right is a completely different matter)
This commit is contained in:
Tamas TEVESZ
2010-03-18 23:14:23 +01:00
committed by Carlos R. Mafra
parent 9dadfe7a68
commit 118a93808a
13 changed files with 198 additions and 378 deletions

View File

@@ -298,6 +298,7 @@ WMRange wmkrange(int start, int count);
char* wusergnusteppath();
char* wdefaultspathfordomain(char *domain);
char* wglobaldefaultspathfordomain(const char *domain);
void wusleep(unsigned int microsec);

View File

@@ -80,6 +80,22 @@ char *wdefaultspathfordomain(char *domain)
return path;
}
/* XXX: doesn't quite belong to *user*defaults.c */
#ifndef GLOBAL_DEFAULTS_SUBDIR
#define GLOBAL_DEFAULTS_SUBDIR "WindowMaker"
#endif
char *wglobaldefaultspathfordomain(const char *domain)
{
char *t = NULL;
size_t len;
len = strlen( SYSCONFDIR ) + strlen( GLOBAL_DEFAULTS_SUBDIR ) + strlen(domain) + 3;
t = wmalloc(len);
snprintf(t, len, "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
return t;
}
static void
#ifdef HAVE_ATEXIT
saveDefaultsChanges(void)

View File

@@ -44,17 +44,17 @@ char *FontOptions[] = {
NULL
};
char *ProgName;
extern char *__progname;
extern char *convertFont(char *font, Bool keepXLFD);
void print_help()
{
printf("\nUsage: %s <style_file>\n\n", ProgName);
printf("\nUsage: %s <style_file>\n\n", __progname);
puts("Converts fonts in a style file into fontconfig format");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
puts(" to the font name. This property is not used by the fontconfig");
puts(" matching engine to find the font, but it is useful as a hint");
@@ -72,25 +72,23 @@ int main(int argc, char **argv)
Bool keepXLFD = False;
int i;
ProgName = argv[0];
if (argc < 2) {
print_help();
exit(0);
}
for (i = 1; i < argc; i++) {
if (strcmp("--version", argv[i]) == 0) {
if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp("--help", argv[i]) == 0) {
} else if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else if (strcmp("--keep-xlfd", argv[i]) == 0) {
keepXLFD = True;;
} else if (argv[i][0] == '-') {
printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
} else {
file = argv[i];
@@ -110,12 +108,12 @@ int main(int argc, char **argv)
style = WMReadPropListFromFile(file);
if (!style) {
perror(file);
printf("%s: could not load style file.\n", ProgName);
printf("%s: could not load style file.\n", __progname);
exit(1);
}
if (!WMIsPLDictionary(style)) {
printf("%s: '%s' is not a well formatted style file\n", ProgName, file);
printf("%s: '%s' is not a well formatted style file\n", __progname, file);
exit(1);
}

View File

@@ -30,42 +30,15 @@
#include "../src/wconfig.h"
char *ProgName;
char *defaultsPathForDomain(char *domain)
{
static char path[1024];
char *gspath;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
return path;
}
extern char *__progname;
void print_help()
{
printf("Usage: %s [OPTIONS] [FILE]\n", ProgName);
printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
puts("Retrieves program icon configuration and output to FILE or to stdout");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
}
int main(int argc, char **argv)
@@ -75,23 +48,21 @@ int main(int argc, char **argv)
char *path;
int i;
ProgName = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
}
}
path = defaultsPathForDomain("WMWindowAttributes");
path = wdefaultspathfordomain("WMWindowAttributes");
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path);
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
exit(1);
}

View File

@@ -119,7 +119,7 @@ static char *font_options[] = {
NULL
};
char *ProgName;
extern char *__progname;
WMPropList *PixmapPath = NULL;
@@ -129,54 +129,18 @@ extern char *convertFont(char *font, Bool keepXLFD);
void print_help()
{
printf("Usage: %s [OPTIONS] [FILE]\n", ProgName);
printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
puts("Retrieves style/theme configuration and output to FILE or to stdout");
puts("");
puts(" -t, --theme-options output theme related options when producing a style file");
puts(" -p, --pack produce output as a theme pack");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
}
char *globalDefaultsPathForDomain(char *domain)
{
static char path[1024];
sprintf(path, "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
return path;
}
char *defaultsPathForDomain(char *domain)
{
static char path[1024];
char *gspath;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
return path;
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
}
void abortar(char *reason)
{
printf("%s: %s\n", ProgName, reason);
printf("%s: %s\n", __progname, reason);
if (ThemePath) {
printf("Removing unfinished theme pack\n");
(void)wrmdirhier(ThemePath);
@@ -356,26 +320,24 @@ int main(int argc, char **argv)
int i, theme_too = 0, make_pack = 0;
char *style_file = NULL;
ProgName = argv[0];
if (argc > 1) {
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--pack") == 0) {
make_pack = 1;
theme_too = 1;
} else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--theme-options") == 0) {
theme_too++;
} else if (strcmp(argv[i], "--help") == 0) {
theme_too = 1;
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
} else {
if (style_file != NULL) {
printf("%s: invalid argument '%s'\n", argv[0],
printf("%s: invalid argument '%s'\n", __progname,
style_file[0] == '-' ? style_file : argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
style_file = argv[i];
@@ -385,23 +347,29 @@ int main(int argc, char **argv)
}
}
if (style_file && !make_pack) {
print_help();
exit(1);
}
if (make_pack && !style_file) {
printf("%s: you must supply a name for the theme pack\n", ProgName);
printf("%s: you must supply a name for the theme pack\n", __progname);
exit(1);
}
WMPLSetCaseSensitive(False);
path = defaultsPathForDomain("WindowMaker");
path = wdefaultspathfordomain("WindowMaker");
prop = WMReadPropListFromFile(path);
if (!prop) {
printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path);
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
exit(1);
}
/* get global value */
path = globalDefaultsPathForDomain("WindowMaker");
path = wglobaldefaultspathfordomain("WindowMaker");
val = WMReadPropListFromFile(path);
if (val) {
WMMergePLDictionaries(val, prop, True);

View File

@@ -29,43 +29,15 @@
#include "../src/wconfig.h"
char *ProgName;
char *defaultsPathForDomain(char *domain)
{
static char path[1024];
char *gspath;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
return path;
}
extern char *__progname;
void print_help()
{
printf("Usage: %s [OPTIONS] FILE\n", ProgName);
printf("Usage: %s [OPTIONS] FILE\n", __progname);
puts("Reads icon configuration from FILE and updates Window Maker.");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
}
int main(int argc, char **argv)
@@ -75,41 +47,40 @@ int main(int argc, char **argv)
int i;
char *path = NULL;
ProgName = argv[0];
if (argc < 2) {
printf("%s: missing argument\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: missing argument\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
} else {
if (path) {
printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
path = argv[i];
}
}
path = defaultsPathForDomain("WMWindowAttributes");
path = wdefaultspathfordomain("WMWindowAttributes");
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path);
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
exit(1);
}
iconset = WMReadPropListFromFile(argv[1]);
if (!iconset) {
printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
printf("%s: could not load icon set file \"%s\".\n", __progname, argv[1]);
exit(1);
}

View File

@@ -63,7 +63,7 @@ char *CursorOptions[] = {
NULL
};
char *ProgName;
extern char *__progname;
int ignoreFonts = 0;
int ignoreCursors = 0;
@@ -71,8 +71,6 @@ Display *dpy;
extern char *convertFont(char *font, Bool keepXLFD);
WMPropList *readBlackBoxStyle(char *path);
static Bool isCursorOption(char *option)
{
int i;
@@ -99,34 +97,6 @@ static Bool isFontOption(char *option)
return False;
}
char *defaultsPathForDomain(char *domain)
{
static char path[1024];
char *gspath;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
return path;
}
void hackPathInTexture(WMPropList * texture, char *prefix)
{
WMPropList *type;
@@ -366,14 +336,14 @@ void hackStyle(WMPropList * style)
void print_help()
{
printf("Usage: %s [OPTIONS] FILE\n", ProgName);
printf("Usage: %s [OPTIONS] FILE\n", __progname);
puts("Reads style/theme configuration from FILE and updates Window Maker.");
puts("");
puts(" --no-fonts ignore font related options");
puts(" --no-cursors ignore cursor related options");
puts(" --ignore <option> ignore changes in the specified option");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
}
int main(int argc, char **argv)
@@ -388,11 +358,9 @@ int main(int argc, char **argv)
dpy = XOpenDisplay("");
ProgName = argv[0];
if (argc < 2) {
printf("%s: missing argument\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: missing argument\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
@@ -400,7 +368,7 @@ int main(int argc, char **argv)
if (strcmp("--ignore", argv[i]) == 0) {
i++;
if (i == argc) {
printf("%s: missing argument for option --ignore\n", ProgName);
printf("%s: missing argument for option --ignore\n", __progname);
exit(1);
}
ignoreList[ignoreCount++] = argv[i];
@@ -409,16 +377,16 @@ int main(int argc, char **argv)
ignoreFonts = 1;
} else if (strcmp("--no-cursors", argv[i]) == 0) {
ignoreCursors = 1;
} else if (strcmp("--version", argv[i]) == 0) {
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp("--help", argv[i]) == 0) {
} else if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else {
if (file) {
printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
file = argv[i];
@@ -427,12 +395,12 @@ int main(int argc, char **argv)
WMPLSetCaseSensitive(False);
path = defaultsPathForDomain("WindowMaker");
path = wdefaultspathfordomain("WindowMaker");
prop = WMReadPropListFromFile(path);
if (!prop) {
perror(path);
printf("%s:could not load WindowMaker configuration file.\n", ProgName);
printf("%s: could not load WindowMaker configuration file.\n", __progname);
exit(1);
}
@@ -447,11 +415,11 @@ int main(int argc, char **argv)
if (*argv[argc - 1] != '/') {
if (!getcwd(buffer, 4000)) {
printf("%s: complete path for %s is too long\n", ProgName, file);
printf("%s: complete path for %s is too long\n", __progname, file);
exit(1);
}
if (strlen(buffer) + strlen(file) > 4000) {
printf("%s: complete path for %s is too long\n", ProgName, file);
printf("%s: complete path for %s is too long\n", __progname, file);
exit(1);
}
strcat(buffer, "/");
@@ -462,7 +430,7 @@ int main(int argc, char **argv)
prefix = malloc(strlen(buffer) + 10);
if (!prefix) {
printf("%s: out of memory\n", ProgName);
printf("%s: out of memory\n", __progname);
exit(1);
}
strcpy(prefix, buffer);
@@ -472,7 +440,7 @@ int main(int argc, char **argv)
style = WMReadPropListFromFile(buffer);
if (!style) {
perror(buffer);
printf("%s:could not load style file.\n", ProgName);
printf("%s: could not load style file.\n", __progname);
exit(1);
}
@@ -484,13 +452,13 @@ int main(int argc, char **argv)
style = WMReadPropListFromFile(file);
if (!style) {
perror(file);
printf("%s:could not load style file.\n", ProgName);
printf("%s:could not load style file.\n", __progname);
exit(1);
}
}
if (!WMIsPLDictionary(style)) {
printf("%s: '%s' is not a style file/theme\n", ProgName, file);
printf("%s: '%s' is not a style file/theme\n", __progname, file);
exit(1);
}

View File

@@ -38,39 +38,19 @@
#include <pwd.h>
char *ProgName;
char *gethomedir()
{
char *home = getenv("HOME");
struct passwd *user;
if (home)
return home;
user = getpwuid(getuid());
if (!user) {
perror(ProgName);
return "/";
}
if (!user->pw_dir) {
return "/";
} else {
return user->pw_dir;
}
}
extern char *__progname;
void wAbort()
{
exit(0);
}
void help()
void print_help()
{
printf("Syntax:\n%s [OPTIONS] <domain> <option>\n", ProgName);
printf("Usage: %s [OPTIONS] <domain> <option>\n", __progname);
puts("");
puts(" --help display this help message");
puts(" --version output version information and exit");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
exit(1);
}
@@ -78,40 +58,27 @@ int main(int argc, char **argv)
{
char path[256];
WMPropList *key, *value, *dict;
char *gsdir;
int i;
ProgName = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp("--help", argv[i]) == 0) {
help();
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else if (strcmp("--version", argv[i]) == 0) {
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
}
}
if (argc < 3) {
printf("%s: invalid argument format\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: invalid argument format\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
key = WMCreatePLString(argv[2]);
gsdir = getenv("GNUSTEP_USER_ROOT");
if (gsdir) {
strcpy(path, gsdir);
} else {
strcpy(path, gethomedir());
strcat(path, "/GNUstep");
}
strcat(path, "/");
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, argv[1]);
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
if ((dict = WMReadPropListFromFile(path)) == NULL)
return 1; /* bad domain */

View File

@@ -37,64 +37,41 @@
#include <pwd.h>
char *ProgName;
char *gethomedir()
{
char *home = getenv("HOME");
struct passwd *user;
if (home)
return home;
user = getpwuid(getuid());
if (!user) {
perror(ProgName);
return "/";
}
if (!user->pw_dir) {
return "/";
} else {
return user->pw_dir;
}
}
extern char *__progname;
void wAbort()
{
exit(0);
}
void help()
void print_help()
{
printf("Syntax:\n%s [OPTIONS] <domain> <option> <value>\n", ProgName);
printf("Usage: %s [OPTIONS] <domain> <option> <value>\n", __progname);
puts("");
puts(" --help display this help message");
puts(" --version output version information and exit");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
exit(1);
}
int main(int argc, char **argv)
{
char *path;
char path[256];
WMPropList *dom, *key, *value, *dict;
char *gsdir;
int i;
ProgName = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp("--help", argv[i]) == 0) {
help();
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else if (strcmp("--version", argv[i]) == 0) {
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
}
}
if (argc < 4) {
printf("%s: invalid argument format\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: invalid argument format\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
@@ -102,20 +79,11 @@ int main(int argc, char **argv)
key = WMCreatePLString(argv[2]);
value = WMCreatePropListFromDescription(argv[3]);
if (!value) {
printf("%s:syntax error in value \"%s\"", ProgName, argv[3]);
printf("%s: syntax error in value \"%s\"", __progname, argv[3]);
exit(1);
}
gsdir = getenv("GNUSTEP_USER_ROOT");
if (gsdir) {
path = wstrdup(gsdir);
} else {
path = wstrdup(gethomedir());
path = wstrappend(path, "/GNUstep");
}
path = wstrappend(path, "/");
path = wstrappend(path, DEFAULTS_DIR);
path = wstrappend(path, "/");
path = wstrappend(path, argv[1]);
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
dict = WMReadPropListFromFile(path);
if (!dict) {
@@ -125,7 +93,6 @@ int main(int argc, char **argv)
}
WMWritePropListToFile(dict, path);
wfree(path);
return 0;
}

View File

@@ -437,7 +437,7 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
help:
printf("Syntax: %s [options]\n", argv[0]);
printf("Usage: %s [options]\n", argv[0]);
puts("Options:");
puts(" -display <display> display that should be used");
puts(" -m <number> change magnification factor (default 2)");
@@ -454,14 +454,14 @@ int main(int argc, char **argv)
dpy = XOpenDisplay(display);
if (!dpy) {
puts("couldnt open display");
puts("could not open display");
exit(1);
}
if (vdisplay) {
vdpy = XOpenDisplay(vdisplay);
if (!vdpy) {
puts("couldnt open display to be viewed");
puts("could not open display to be viewed");
exit(1);
}
} else {

View File

@@ -88,6 +88,7 @@ Pixmap CurrentPixmap = None;
char *PixmapPath = NULL;
extern Pixmap LoadJPEG(RContext * rc, char *file_name, int *width, int *height);
extern char *__progname;
typedef struct BackgroundTexture {
int refcount;
@@ -1057,15 +1058,6 @@ void updateDomain(char *domain, char *key, char *texture)
wwarning("warning could not run \"%s\"", program);
}
char *globalDefaultsPathForDomain(char *domain)
{
char path[1024];
sprintf(path, "%s/%s/%s", SYSCONFDIR, GLOBAL_DEFAULTS_SUBDIR, domain);
return wstrdup(path);
}
static WMPropList *getValueForKey(char *domain, char *keyName)
{
char *path;
@@ -1092,7 +1084,7 @@ static WMPropList *getValueForKey(char *domain, char *keyName)
}
/* try to find PixmapPath in global defaults */
if (!val) {
path = globalDefaultsPathForDomain(domain);
path = wglobaldefaultspathfordomain(domain);
if (!path) {
wwarning("could not locate file for domain %s", domain);
d = NULL;
@@ -1207,32 +1199,31 @@ void wAbort()
exit(1);
}
void print_help(char *ProgName)
void print_help()
{
printf("Usage: %s [options] [image]\n", ProgName);
puts("Sets the workspace background to the specified image or a texture and optionally update Window Maker configuration");
printf("Usage: %s [options] [image]\n", __progname);
puts("Sets the workspace background to the specified image or a texture and");
puts("optionally update Window Maker configuration");
puts("");
#define P(m) puts(m)
P(" -display display to use");
P(" -d, --dither dither image");
P(" -m, --match match colors");
P(" -S, --smooth smooth scaled image");
puts(" -display display to use");
puts(" -d, --dither dither image");
puts(" -m, --match match colors");
puts(" -S, --smooth smooth scaled image");
#ifdef XINERAMA
P(" -X, --xinerama stretch image across Xinerama heads");
puts(" -X, --xinerama stretch image across Xinerama heads");
#endif
P(" -b, --back-color <color> background color");
P(" -t, --tile tile image");
P(" -e, --center center image");
P(" -s, --scale scale image (default)");
P(" -a, --maxscale scale image and keep aspect ratio");
P(" -u, --update-wmaker update WindowMaker domain database");
P(" -D, --update-domain <domain> update <domain> database");
P(" -c, --colors <cpc> colors per channel to use");
P(" -p, --parse <texture> proplist style texture specification");
P(" -w, --workspace <workspace> update background for the specified workspace");
P(" --version show version of wmsetbg and exit");
P(" --help show this help and exit");
#undef P
puts(" -b, --back-color <color> background color");
puts(" -t, --tile tile image");
puts(" -e, --center center image");
puts(" -s, --scale scale image (default)");
puts(" -a, --maxscale scale image and keep aspect ratio");
puts(" -u, --update-wmaker update WindowMaker domain database");
puts(" -D, --update-domain <domain> update <domain> database");
puts(" -c, --colors <cpc> colors per channel to use");
puts(" -p, --parse <texture> proplist style texture specification");
puts(" -w, --workspace <workspace> update background for the specified workspace");
puts(" -v, --version show version of wmsetbg and exit");
puts(" -h, --help show this help and exit");
}
void changeTextureForWorkspace(char *domain, char *texture, int workspace)
@@ -1373,31 +1364,30 @@ int main(int argc, char **argv)
wfatal("bad value for workspace number: \"%s\"", argv[i]);
exit(1);
}
} else if (strcmp(argv[i], "--version") == 0) {
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
printf(PROG_VERSION);
exit(0);
} else if (strcmp(argv[i], "--help") == 0) {
print_help(argv[0]);
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
} else if (argv[i][0] != '-') {
image_name = argv[i];
} else {
printf("%s: invalid argument '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
}
if (!image_name && !texture && !helperMode) {
printf("%s: you must specify a image file name or a texture\n", argv[0]);
printf("Try '%s --help' for more information\n", argv[0]);
printf("%s: you must specify a image file name or a texture\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
PixmapPath = getPixmapPath(domain);
if (!smooth) {
WMPropList *val;
/* carlos, don't remove this */
#if 0 /* some problem with Alpha... TODO: check if its right */
val = WMGetFromPLDictionary(domain, WMCreatePLString("SmoothWorkspaceBack"));
#else

View File

@@ -30,17 +30,19 @@
#define LINESIZE (4*1024)
#define MAXDATA (64*1024)
void help(char *progn)
extern char *__progname;
void print_help()
{
printf("Usage: %s [OPTIONS] [FILE]\n", progn);
printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
puts("Copies data from FILE or stdin into X cut buffer.");
puts("");
puts(" -display <display> display to use");
puts(" --cutbuffer <number> cutbuffer number to put data");
puts(" --no-limit do not limit size of input data");
puts(" --clear-selection clears the current PRIMARY selection");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
}
static int errorHandler(Display * dpy, XErrorEvent * err)
@@ -65,10 +67,10 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (strcmp(argv[i], "--help") == 0) {
help(argv[0]);
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) {
@@ -76,24 +78,24 @@ int main(int argc, char **argv)
i++;
if (sscanf(argv[i], "%i", &buffer) != 1) {
fprintf(stderr, "%s: could not convert '%s' to int\n",
argv[0], argv[i]);
__progname, argv[i]);
exit(1);
}
if (buffer < 0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n", argv[0], buffer);
fprintf(stderr, "%s: invalid buffer number %i\n", __progname, buffer);
exit(1);
}
} else {
printf("%s: missing argument for '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
printf("%s: missing argument for '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
} else if (strcmp(argv[i], "-display") == 0) {
if (i < argc - 1) {
display_name = argv[++i];
} else {
printf("%s: missing argument for '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
printf("%s: missing argument for '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
} else if (strcmp(argv[i], "-clearselection") == 0
@@ -102,8 +104,8 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "-nolimit") == 0 || strcmp(argv[i], "--no-limit") == 0) {
limit_check = 0;
} else {
printf("%s: invalid argument '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
} else {
@@ -114,7 +116,7 @@ int main(int argc, char **argv)
file = fopen(filename, "rb");
if (!file) {
char line[1024];
sprintf(line, "%s: could not open \"%s\"", argv[0], filename);
sprintf(line, "%s: could not open \"%s\"", __progname, filename);
perror(line);
exit(1);
}
@@ -123,7 +125,7 @@ int main(int argc, char **argv)
dpy = XOpenDisplay(display_name);
XSetErrorHandler(errorHandler);
if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", argv[0], XDisplayName(display_name));
fprintf(stderr, "%s: could not open display \"%s\"\n", __progname, XDisplayName(display_name));
exit(1);
}
@@ -208,7 +210,7 @@ int main(int argc, char **argv)
nbuf = buf;
}
if (!nbuf) {
fprintf(stderr, "%s: out of memory\n", argv[0]);
fprintf(stderr, "%s: out of memory\n", __progname);
exit(1);
}
buf = nbuf;
@@ -222,7 +224,7 @@ int main(int argc, char **argv)
fprintf
(stderr,
"%s: too much data in input - more than %d bytes\n"
" use the -nolimit argument to remove the limit check.\n", argv[0], MAXDATA);
" use the -nolimit argument to remove the limit check.\n", __progname, MAXDATA);
exit(1);
}
}

View File

@@ -36,17 +36,18 @@
#define MAXDATA (4*1024*1024)
void help(char *progn)
extern char *__progname;
void print_help()
{
printf("Usage: %s [OPTIONS] [FILE]\n", progn);
printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
puts("Copies data from X selection or cutbuffer to FILE or stdout.");
puts("");
puts(" -display display display to use");
puts(" --cutbuffer number cutbuffer number to get data from");
puts(" --selection [selection] reads data from named selection instead of\n"
" cutbuffer");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" --selection [selection] reads data from named selection instead of cutbuffer");
puts(" -h, --help display this help and exit");
puts(" -v, --version output version information and exit");
}
Time getTimestamp(Display * dpy, Window win)
@@ -160,9 +161,9 @@ int main(int argc, char **argv)
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (argv[i][1] == 'h' || strcmp(argv[i], "--help") == 0) {
help(argv[0]);
print_help();
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
} else if (argv[i][1] == 'v' || strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp(argv[i], "-selection") == 0 || strcmp(argv[i], "--selection") == 0) {
@@ -175,7 +176,7 @@ int main(int argc, char **argv)
if (i < argc - 1) {
display_name = argv[++i];
} else {
help(argv[0]);
print_help();
exit(0);
}
} else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) {
@@ -183,33 +184,33 @@ int main(int argc, char **argv)
i++;
if (sscanf(argv[i], "%i", &buffer) != 1) {
fprintf(stderr, "%s: could not convert \"%s\" to int\n",
argv[0], argv[i]);
__progname, argv[i]);
exit(1);
}
if (buffer < 0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n", argv[0], buffer);
fprintf(stderr, "%s: invalid buffer number %i\n", __progname, buffer);
exit(1);
}
} else {
fprintf(stderr, "%s: invalid argument '%s'\n", argv[0], argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
fprintf(stderr, "%s: invalid argument '%s'\n", __progname, argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", __progname);
exit(1);
}
}
} else {
fprintf(stderr, "%s: invalid argument '%s'\n", argv[0], argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
fprintf(stderr, "%s: invalid argument '%s'\n", __progname, argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", __progname);
exit(1);
}
}
dpy = XOpenDisplay(display_name);
if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", argv[0], XDisplayName(display_name));
fprintf(stderr, "%s: could not open display \"%s\"\n", __progname, XDisplayName(display_name));
exit(1);
}
if (selection_name) {
buf = fetchSelection(dpy, selection_name, argv[0]);
buf = fetchSelection(dpy, selection_name, __progname);
} else {
buf = NULL;
}