From 118a93808ab81ae6133ac08650c0ce907e682126 Mon Sep 17 00:00:00 2001 From: Tamas TEVESZ Date: Thu, 18 Mar 2010 23:14:23 +0100 Subject: [PATCH] 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) --- WINGs/WINGs/WUtil.h | 1 + WINGs/userdefaults.c | 16 +++++++++++ util/convertfonts.c | 34 +++++++++++------------ util/geticonset.c | 43 +++++------------------------ util/getstyle.c | 76 +++++++++++++++------------------------------------- util/seticons.c | 55 +++++++++---------------------------- util/setstyle.c | 70 +++++++++++++---------------------------------- util/wdread.c | 55 ++++++++----------------------------- util/wdwrite.c | 61 ++++++++++------------------------------- util/wmagnify.c | 6 ++--- util/wmsetbg.c | 72 +++++++++++++++++++++---------------------------- util/wxcopy.c | 48 +++++++++++++++++---------------- util/wxpaste.c | 39 ++++++++++++++------------- 13 files changed, 198 insertions(+), 378 deletions(-) diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index f1335243..a0023ca3 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -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); diff --git a/WINGs/userdefaults.c b/WINGs/userdefaults.c index 742b614f..943f98c7 100644 --- a/WINGs/userdefaults.c +++ b/WINGs/userdefaults.c @@ -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) diff --git a/util/convertfonts.c b/util/convertfonts.c index 7fe4f197..2aa79c75 100644 --- a/util/convertfonts.c +++ b/util/convertfonts.c @@ -44,23 +44,23 @@ char *FontOptions[] = { NULL }; -char *ProgName; +extern char *__progname; extern char *convertFont(char *font, Bool keepXLFD); void print_help() { - printf("\nUsage: %s \n\n", ProgName); + printf("\nUsage: %s \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(" --keep-xlfd preserve the original xlfd by appending a ':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"); - puts(" about what the original font was to allow hand tuning the"); - puts(" result or restoring the xlfd. The default is to not add it"); - puts(" as it results in long, unreadable and confusing names."); + 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=' 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"); + puts(" about what the original font was to allow hand tuning the"); + puts(" result or restoring the xlfd. The default is to not add it"); + puts(" as it results in long, unreadable and confusing names."); puts(""); } @@ -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); } diff --git a/util/geticonset.c b/util/geticonset.c index dc9dec11..e21994b0 100644 --- a/util/geticonset.c +++ b/util/geticonset.c @@ -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); } diff --git a/util/getstyle.c b/util/getstyle.c index f9b78fac..69b37bbb 100644 --- a/util/getstyle.c +++ b/util/getstyle.c @@ -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(" -t, --theme-options output theme related options when producing a style file"); + puts(" -p, --pack produce output as a theme pack"); + 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); diff --git a/util/seticons.c b/util/seticons.c index ab5b1349..96baf984 100644 --- a/util/seticons.c +++ b/util/seticons.c @@ -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); } diff --git a/util/setstyle.c b/util/setstyle.c index cfa2b074..36224f58 100644 --- a/util/setstyle.c +++ b/util/setstyle.c @@ -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