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:
committed by
Carlos R. Mafra
parent
859338fd83
commit
7dc767ae78
@@ -29,7 +29,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
@@ -286,12 +285,14 @@ void makeThemePack(WMPropList * style, char *themeName)
|
|||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strcasecmp(t, "tpixmap") == 0
|
if (strcasecmp(t, "tpixmap") == 0 ||
|
||||||
|| strcasecmp(t, "spixmap") == 0
|
strcasecmp(t, "spixmap") == 0 ||
|
||||||
|| strcasecmp(t, "cpixmap") == 0
|
strcasecmp(t, "cpixmap") == 0 ||
|
||||||
|| strcasecmp(t, "mpixmap") == 0
|
strcasecmp(t, "mpixmap") == 0 ||
|
||||||
|| strcasecmp(t, "tdgradient") == 0
|
strcasecmp(t, "tdgradient") == 0 ||
|
||||||
|| strcasecmp(t, "tvgradient") == 0 || strcasecmp(t, "thgradient") == 0) {
|
strcasecmp(t, "tvgradient") == 0 ||
|
||||||
|
strcasecmp(t, "thgradient") == 0) {
|
||||||
|
|
||||||
WMPropList *file;
|
WMPropList *file;
|
||||||
char *p;
|
char *p;
|
||||||
char *newPath;
|
char *newPath;
|
||||||
@@ -310,6 +311,7 @@ void makeThemePack(WMPropList * style, char *themeName)
|
|||||||
findCopyFile(themeDir, WMGetFromPLString(file));
|
findCopyFile(themeDir, WMGetFromPLString(file));
|
||||||
}
|
}
|
||||||
} else if (strcasecmp(t, "bitmap") == 0) {
|
} else if (strcasecmp(t, "bitmap") == 0) {
|
||||||
|
|
||||||
WMPropList *file;
|
WMPropList *file;
|
||||||
char *p;
|
char *p;
|
||||||
char *newPath;
|
char *newPath;
|
||||||
|
|||||||
@@ -89,13 +89,13 @@ int main(int argc, char **argv)
|
|||||||
all_windows = WMReadPropListFromFile(path);
|
all_windows = WMReadPropListFromFile(path);
|
||||||
if (!all_windows) {
|
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);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
iconset = WMReadPropListFromFile(argv[0]);
|
iconset = WMReadPropListFromFile(argv[0]);
|
||||||
if (!iconset) {
|
if (!iconset) {
|
||||||
printf("%s: could not load icon set file \"%s\".\n", __progname, argv[0]);
|
printf("%s: could not load icon set file \"%s\".\n", __progname, argv[0]);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
keylist = WMGetPLDictionaryKeys(iconset);
|
keylist = WMGetPLDictionaryKeys(iconset);
|
||||||
@@ -122,5 +122,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
WMWritePropListToFile(all_windows, path);
|
WMWritePropListToFile(all_windows, path);
|
||||||
|
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,66 +23,83 @@
|
|||||||
|
|
||||||
#define PROG_VERSION "wdread (Window Maker) 0.2"
|
#define PROG_VERSION "wdread (Window Maker) 0.2"
|
||||||
|
|
||||||
|
#ifdef __GLIBC__
|
||||||
|
#define _GNU_SOURCE /* getopt_long */
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WindowMaker defaults DB reader
|
* WindowMaker defaults DB reader
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../src/wconfig.h"
|
#include <getopt.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
#include <WINGs/WUtil.h>
|
||||||
|
|
||||||
#include <pwd.h>
|
#include "../src/wconfig.h"
|
||||||
|
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
|
||||||
void wAbort()
|
void print_help(int print_usage, int exitval)
|
||||||
{
|
{
|
||||||
exit(0);
|
printf("Usage: %s [OPTIONS] <domain> <key>\n", __progname);
|
||||||
}
|
if (print_usage) {
|
||||||
|
puts("Read <key> from <domain>'s database");
|
||||||
void print_help()
|
puts("");
|
||||||
{
|
puts(" -h, --help display this help message");
|
||||||
printf("Usage: %s [OPTIONS] <domain> <option>\n", __progname);
|
puts(" -v, --version output version information and exit");
|
||||||
puts("");
|
}
|
||||||
puts(" -h, --help display this help message");
|
exit(exitval);
|
||||||
puts(" -v, --version output version information and exit");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char path[256];
|
char path[PATH_MAX];
|
||||||
WMPropList *key, *value, *dict;
|
WMPropList *key, *value, *dict;
|
||||||
int i;
|
int ch;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
struct option longopts[] = {
|
||||||
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
|
{ "version", no_argument, NULL, 'v' },
|
||||||
print_help();
|
{ "help", no_argument, NULL, 'h' },
|
||||||
exit(0);
|
{ NULL, 0, NULL, 0 }
|
||||||
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
|
};
|
||||||
puts(PROG_VERSION);
|
|
||||||
exit(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) {
|
argc -= optind;
|
||||||
printf("%s: invalid argument format\n", __progname);
|
argv += optind;
|
||||||
printf("Try '%s --help' for more information\n", __progname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 */
|
return 1; /* bad domain */
|
||||||
if ((value = WMGetFromPLDictionary(dict, key)) == NULL)
|
|
||||||
|
value = WMGetFromPLDictionary(dict, key);
|
||||||
|
if (value == NULL)
|
||||||
return 2; /* bad key */
|
return 2; /* bad key */
|
||||||
|
|
||||||
printf("%s\n", WMGetPropListDescription(value, True));
|
printf("%s\n", WMGetPropListDescription(value, True));
|
||||||
|
|||||||
@@ -22,68 +22,83 @@
|
|||||||
|
|
||||||
#define PROG_VERSION "wdwrite (Window Maker) 0.2"
|
#define PROG_VERSION "wdwrite (Window Maker) 0.2"
|
||||||
|
|
||||||
|
#ifdef __GLIBC__
|
||||||
|
#define _GNU_SOURCE /* getopt_long */
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WindowMaker defaults DB writer
|
* WindowMaker defaults DB writer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../src/wconfig.h"
|
|
||||||
|
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
#include <WINGs/WUtil.h>
|
||||||
|
|
||||||
#include <pwd.h>
|
#include "../src/wconfig.h"
|
||||||
|
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
|
||||||
void wAbort()
|
void print_help(int print_usage, int exitval)
|
||||||
{
|
{
|
||||||
exit(0);
|
printf("Usage: %s [OPTIONS] <domain> <key> <value>\n", __progname);
|
||||||
}
|
if (print_usage) {
|
||||||
|
puts("Write <value> for <key> in <domain>'s database");
|
||||||
void print_help()
|
puts("");
|
||||||
{
|
puts(" -h, --help display this help message");
|
||||||
printf("Usage: %s [OPTIONS] <domain> <option> <value>\n", __progname);
|
puts(" -v, --version output version information and exit");
|
||||||
puts("");
|
}
|
||||||
puts(" -h, --help display this help message");
|
exit(exitval);
|
||||||
puts(" -v, --version output version information and exit");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char path[256];
|
char path[PATH_MAX];
|
||||||
WMPropList *dom, *key, *value, *dict;
|
WMPropList *dom, *key, *value, *dict;
|
||||||
int i;
|
int ch;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
struct option longopts[] = {
|
||||||
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
|
{ "version", no_argument, NULL, 'v' },
|
||||||
print_help();
|
{ "help", no_argument, NULL, 'h' },
|
||||||
exit(0);
|
{ NULL, 0, NULL, 0 }
|
||||||
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
|
};
|
||||||
puts(PROG_VERSION);
|
|
||||||
exit(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) {
|
argc -= optind;
|
||||||
printf("%s: invalid argument format\n", __progname);
|
argv += optind;
|
||||||
printf("Try '%s --help' for more information\n", __progname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
dom = WMCreatePLString(argv[1]);
|
if (argc != 3)
|
||||||
key = WMCreatePLString(argv[2]);
|
print_help(0, 1);
|
||||||
value = WMCreatePropListFromDescription(argv[3]);
|
|
||||||
|
dom = WMCreatePLString(argv[0]);
|
||||||
|
key = WMCreatePLString(argv[1]);
|
||||||
|
value = WMCreatePropListFromDescription(argv[2]);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
printf("%s: syntax error in value \"%s\"", __progname, argv[3]);
|
printf("%s: syntax error in value \"%s\"", __progname, argv[2]);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
|
snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
|
||||||
|
|
||||||
dict = WMReadPropListFromFile(path);
|
dict = WMReadPropListFromFile(path);
|
||||||
if (!dict) {
|
if (!dict) {
|
||||||
|
|||||||
Reference in New Issue
Block a user