mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 20:38:08 +01:00
Style stuff up
- convert hand-rolled arg parsers to getopt_long - sort headers, get rid of some duplicates in the process - in fontconv, replace magic numbers with constants (there's little practical value to this here, but it's much nicer) - slightly redo fontconv.c:strToInt()
This commit is contained in:
committed by
Carlos R. Mafra
parent
444de5e6b6
commit
6bf7994520
@@ -22,8 +22,13 @@
|
||||
|
||||
#define PROG_VERSION "geticonset (Window Maker) 0.1"
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifdef __GLIBC__
|
||||
#define _GNU_SOURCE /* getopt_long */
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <WINGs/WUtil.h>
|
||||
@@ -32,13 +37,16 @@
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
void print_help()
|
||||
void print_help(int print_usage, int exitval)
|
||||
{
|
||||
printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
|
||||
puts("Retrieves program icon configuration and output to FILE or to stdout");
|
||||
puts("");
|
||||
puts(" -h, --help display this help and exit");
|
||||
puts(" -v, --version output version information and exit");
|
||||
printf("Usage: %s [-h] [-v] [file]\n", __progname);
|
||||
if (print_usage) {
|
||||
puts("Retrieves program icon configuration and output to FILE or to stdout");
|
||||
puts("");
|
||||
puts(" -h, --help display this help and exit");
|
||||
puts(" -v, --version output version information and exit");
|
||||
}
|
||||
exit(exitval);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -46,24 +54,39 @@ int main(int argc, char **argv)
|
||||
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
|
||||
WMPropList *all_windows, *iconset, *keylist;
|
||||
char *path;
|
||||
int i;
|
||||
int i, ch;
|
||||
|
||||
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], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
|
||||
puts(PROG_VERSION);
|
||||
exit(0);
|
||||
struct option longopts[] = {
|
||||
{ "version", no_argument, NULL, 'v' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
|
||||
switch(ch) {
|
||||
case 'v':
|
||||
puts(PROG_VERSION);
|
||||
return 0;
|
||||
/* NOTREACHED */
|
||||
case 'h':
|
||||
print_help(1, 0);
|
||||
/* NOTREACHED */
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
print_help(0, 1);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
path = wdefaultspathfordomain("WMWindowAttributes");
|
||||
|
||||
all_windows = WMReadPropListFromFile(path);
|
||||
if (!all_windows) {
|
||||
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
iconset = WMCreatePLDictionary(NULL, NULL);
|
||||
@@ -88,10 +111,10 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
WMWritePropListToFile(iconset, argv[1]);
|
||||
if (argc == 1) {
|
||||
WMWritePropListToFile(iconset, argv[0]);
|
||||
} else {
|
||||
puts(WMGetPropListDescription(iconset, True));
|
||||
}
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user