1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 04:20:27 +01:00

Convert to getopt, continued

plus some assorted fixes:
 - sort headers, remove some unneeded ones
 - small bits of formatting and the like
This commit is contained in:
Tamas TEVESZ
2010-04-01 03:30:05 +02:00
committed by Carlos R. Mafra
parent 859338fd83
commit 7dc767ae78
4 changed files with 113 additions and 79 deletions

View File

@@ -29,7 +29,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
@@ -286,12 +285,14 @@ void makeThemePack(WMPropList * style, char *themeName)
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) {
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;
@@ -310,6 +311,7 @@ void makeThemePack(WMPropList * style, char *themeName)
findCopyFile(themeDir, WMGetFromPLString(file));
}
} else if (strcasecmp(t, "bitmap") == 0) {
WMPropList *file;
char *p;
char *newPath;

View File

@@ -89,13 +89,13 @@ int main(int argc, char **argv)
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
exit(1);
return 1;
}
iconset = WMReadPropListFromFile(argv[0]);
if (!iconset) {
printf("%s: could not load icon set file \"%s\".\n", __progname, argv[0]);
exit(1);
return 1;
}
keylist = WMGetPLDictionaryKeys(iconset);
@@ -122,5 +122,5 @@ int main(int argc, char **argv)
WMWritePropListToFile(all_windows, path);
exit(0);
return 0;
}

View File

@@ -23,66 +23,83 @@
#define PROG_VERSION "wdread (Window Maker) 0.2"
#ifdef __GLIBC__
#define _GNU_SOURCE /* getopt_long */
#endif
/*
* WindowMaker defaults DB reader
*/
#include "../src/wconfig.h"
#include <getopt.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <WINGs/WUtil.h>
#include <pwd.h>
#include "../src/wconfig.h"
extern char *__progname;
void wAbort()
void print_help(int print_usage, int exitval)
{
exit(0);
}
void print_help()
{
printf("Usage: %s [OPTIONS] <domain> <option>\n", __progname);
puts("");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
exit(1);
printf("Usage: %s [OPTIONS] <domain> <key>\n", __progname);
if (print_usage) {
puts("Read <key> from <domain>'s database");
puts("");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
}
exit(exitval);
}
int main(int argc, char **argv)
{
char path[256];
char path[PATH_MAX];
WMPropList *key, *value, *dict;
int i;
int ch;
for (i = 1; i < argc; i++) {
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 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 */
}
}
if (argc < 3) {
printf("%s: invalid argument format\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
argc -= optind;
argv += optind;
key = WMCreatePLString(argv[2]);
if (argc != 2)
print_help(0, 1);
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
key = WMCreatePLString(argv[1]);
if ((dict = WMReadPropListFromFile(path)) == NULL)
snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
dict = WMReadPropListFromFile(path);
if (dict == NULL)
return 1; /* bad domain */
if ((value = WMGetFromPLDictionary(dict, key)) == NULL)
value = WMGetFromPLDictionary(dict, key);
if (value == NULL)
return 2; /* bad key */
printf("%s\n", WMGetPropListDescription(value, True));

View File

@@ -22,68 +22,83 @@
#define PROG_VERSION "wdwrite (Window Maker) 0.2"
#ifdef __GLIBC__
#define _GNU_SOURCE /* getopt_long */
#endif
/*
* WindowMaker defaults DB writer
*/
#include "../src/wconfig.h"
#include <getopt.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <WINGs/WUtil.h>
#include <pwd.h>
#include "../src/wconfig.h"
extern char *__progname;
void wAbort()
void print_help(int print_usage, int exitval)
{
exit(0);
}
void print_help()
{
printf("Usage: %s [OPTIONS] <domain> <option> <value>\n", __progname);
puts("");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
exit(1);
printf("Usage: %s [OPTIONS] <domain> <key> <value>\n", __progname);
if (print_usage) {
puts("Write <value> for <key> in <domain>'s database");
puts("");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
}
exit(exitval);
}
int main(int argc, char **argv)
{
char path[256];
char path[PATH_MAX];
WMPropList *dom, *key, *value, *dict;
int i;
int ch;
for (i = 1; i < argc; i++) {
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 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 */
}
}
if (argc < 4) {
printf("%s: invalid argument format\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
argc -= optind;
argv += optind;
dom = WMCreatePLString(argv[1]);
key = WMCreatePLString(argv[2]);
value = WMCreatePropListFromDescription(argv[3]);
if (argc != 3)
print_help(0, 1);
dom = WMCreatePLString(argv[0]);
key = WMCreatePLString(argv[1]);
value = WMCreatePropListFromDescription(argv[2]);
if (!value) {
printf("%s: syntax error in value \"%s\"", __progname, argv[3]);
exit(1);
printf("%s: syntax error in value \"%s\"", __progname, argv[2]);
return 1;
}
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
dict = WMReadPropListFromFile(path);
if (!dict) {