mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +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,11 +22,18 @@
|
|||||||
|
|
||||||
#define PROG_VERSION "convertfonts (Window Maker) 1.0"
|
#define PROG_VERSION "convertfonts (Window Maker) 1.0"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#ifdef __GLIBC__
|
||||||
#include <stdio.h>
|
#define _GNU_SOURCE /* getopt_long */
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
|
||||||
|
#include <getopt.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
#include <WINGs/WUtil.h>
|
||||||
|
|
||||||
#include "../src/wconfig.h"
|
#include "../src/wconfig.h"
|
||||||
@@ -48,73 +55,89 @@ extern char *__progname;
|
|||||||
|
|
||||||
extern char *convertFont(char *font, Bool keepXLFD);
|
extern char *convertFont(char *font, Bool keepXLFD);
|
||||||
|
|
||||||
void print_help()
|
void print_help(int print_usage, int exitval)
|
||||||
{
|
{
|
||||||
printf("\nUsage: %s <style_file>\n\n", __progname);
|
printf("Usage: %s [-h] [-v] [--keep-xlfd] <style_file>\n", __progname);
|
||||||
puts("Converts fonts in a style file into fontconfig format");
|
if (print_usage) {
|
||||||
puts("");
|
puts("Converts fonts in a style file into fontconfig format");
|
||||||
puts(" -h, --help display this help and exit");
|
puts("");
|
||||||
puts(" -v, --version output version information and exit");
|
puts(" -h, --help display this help and exit");
|
||||||
puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
|
puts(" -v, --version output version information and exit");
|
||||||
puts(" to the font name. This property is not used by the fontconfig");
|
puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
|
||||||
puts(" matching engine to find the font, but it is useful as a hint");
|
puts(" to the font name. This property is not used by the fontconfig");
|
||||||
puts(" about what the original font was to allow hand tuning the");
|
puts(" matching engine to find the font, but it is useful as a hint");
|
||||||
puts(" result or restoring the xlfd. The default is to not add it");
|
puts(" about what the original font was to allow hand tuning the");
|
||||||
puts(" as it results in long, unreadable and confusing names.");
|
puts(" result or restoring the xlfd. The default is to not add it");
|
||||||
puts("");
|
puts(" as it results in long, unreadable and confusing names.");
|
||||||
|
}
|
||||||
|
exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
WMPropList *style, *key, *val;
|
WMPropList *style, *key, *val;
|
||||||
char *file = NULL, *oldfont, *newfont;
|
char *file = NULL, *oldfont, *newfont;
|
||||||
struct stat statbuf;
|
struct stat st;
|
||||||
Bool keepXLFD = False;
|
Bool keepXLFD = False;
|
||||||
int i;
|
int i, ch;
|
||||||
|
|
||||||
if (argc < 2) {
|
struct option longopts[] = {
|
||||||
print_help();
|
{ "version", no_argument, NULL, 'v' },
|
||||||
exit(0);
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ "keep-xlfd", no_argument, &keepXLFD, True },
|
||||||
|
{ 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;
|
||||||
|
|
||||||
|
if (argc != 1)
|
||||||
|
print_help(0, 1);
|
||||||
|
|
||||||
|
file = argv[0];
|
||||||
|
|
||||||
|
if (stat(file, &st) != 0) {
|
||||||
|
perror(file);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
if (!S_ISREG(st.st_mode)) { /* maybe symlink too? */
|
||||||
if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
|
fprintf(stderr, "%s: `%s' is not a regular file\n", __progname, file);
|
||||||
puts(PROG_VERSION);
|
return 1;
|
||||||
exit(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);
|
|
||||||
exit(1);
|
|
||||||
} else {
|
|
||||||
file = argv[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we need this in order for MB_CUR_MAX to work */
|
/* we need this in order for MB_CUR_MAX to work */
|
||||||
|
/* this contradicts big time with getstyle */
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
WMPLSetCaseSensitive(False);
|
WMPLSetCaseSensitive(False);
|
||||||
|
|
||||||
if (stat(file, &statbuf) < 0) {
|
|
||||||
perror(file);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
style = WMReadPropListFromFile(file);
|
style = WMReadPropListFromFile(file);
|
||||||
if (!style) {
|
if (!style) {
|
||||||
perror(file);
|
perror(file);
|
||||||
printf("%s: could not load style file.\n", __progname);
|
printf("%s: could not load style file\n", __progname);
|
||||||
exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!WMIsPLDictionary(style)) {
|
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);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; FontOptions[i] != NULL; i++) {
|
for (i = 0; FontOptions[i] != NULL; i++) {
|
||||||
@@ -135,5 +158,5 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
WMWritePropListToFile(style, file);
|
WMWritePropListToFile(style, file);
|
||||||
|
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,32 @@
|
|||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
#include <WINGs/WUtil.h>
|
||||||
|
|
||||||
#include "../src/wconfig.h"
|
#include "../src/wconfig.h"
|
||||||
|
|
||||||
#define DEFAULT_FONT "sans serif:pixelsize=12"
|
#define DEFAULT_FONT "sans serif:pixelsize=12"
|
||||||
|
|
||||||
|
/* X Font Name Suffix field names */
|
||||||
|
enum {
|
||||||
|
FOUNDRY,
|
||||||
|
FAMILY_NAME,
|
||||||
|
WEIGHT_NAME,
|
||||||
|
SLANT,
|
||||||
|
SETWIDTH_NAME,
|
||||||
|
ADD_STYLE_NAME,
|
||||||
|
PIXEL_SIZE,
|
||||||
|
POINT_SIZE,
|
||||||
|
RESOLUTION_X,
|
||||||
|
RESOLUTION_Y,
|
||||||
|
SPACING,
|
||||||
|
AVERAGE_WIDTH,
|
||||||
|
CHARSET_REGISTRY,
|
||||||
|
CHARSET_ENCODING
|
||||||
|
};
|
||||||
|
|
||||||
static int countChar(char *str, char c)
|
static int countChar(char *str, char c)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@@ -26,7 +45,7 @@ static int countChar(char *str, char c)
|
|||||||
|
|
||||||
typedef struct str {
|
typedef struct str {
|
||||||
char *str;
|
char *str;
|
||||||
int len;
|
size_t len;
|
||||||
} str;
|
} str;
|
||||||
|
|
||||||
#define XLFD_TOKENS 14
|
#define XLFD_TOKENS 14
|
||||||
@@ -37,6 +56,7 @@ static str *getXLFDTokens(char *xlfd)
|
|||||||
int i, len, size;
|
int i, len, size;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
|
||||||
|
/* XXX: why does this assume there can't ever be XFNextPrefix? */
|
||||||
if (!xlfd || *xlfd != '-' || countChar(xlfd, '-') != XLFD_TOKENS)
|
if (!xlfd || *xlfd != '-' || countChar(xlfd, '-') != XLFD_TOKENS)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -62,26 +82,25 @@ static str *getXLFDTokens(char *xlfd)
|
|||||||
|
|
||||||
static int strToInt(str * token)
|
static int strToInt(str * token)
|
||||||
{
|
{
|
||||||
int res = 0, pos, c;
|
static char buf[32]; /* enough for an Incredibly Big Number */
|
||||||
|
|
||||||
if (token->len == 0 || token->str[0] == '*') {
|
if (token->len == 0 ||
|
||||||
|
token->str[0] == '*' ||
|
||||||
|
token->len >= sizeof(buf))
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
for (res = 0, pos = 0; pos < token->len; pos++) {
|
memset(buf, 0, sizeof(buf));
|
||||||
c = token->str[pos] - '0';
|
strncpy(buf, token->str, token->len);
|
||||||
if (c < 0 || c > 9)
|
|
||||||
break;
|
/* the code using this will gracefully handle overflows */
|
||||||
res = res * 10 + c;
|
return (int)strtol(buf, NULL, 10);
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *mapWeightToName(str * weight)
|
static char *mapWeightToName(str * weight)
|
||||||
{
|
{
|
||||||
char *normalNames[] = { "medium", "normal", "regular" };
|
char *normalNames[] = { "medium", "normal", "regular" };
|
||||||
static char buf[32];
|
static char buf[32];
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
if (weight->len == 0)
|
if (weight->len == 0)
|
||||||
return "";
|
return "";
|
||||||
@@ -123,11 +142,11 @@ char *xlfdToFc(char *xlfd, char *useFamily, Bool keepXLFD)
|
|||||||
if (!tokens)
|
if (!tokens)
|
||||||
return wstrdup(DEFAULT_FONT);
|
return wstrdup(DEFAULT_FONT);
|
||||||
|
|
||||||
family = &(tokens[1]);
|
family = &(tokens[FAMILY_NAME]);
|
||||||
weight = &(tokens[2]);
|
weight = &(tokens[WEIGHT_NAME]);
|
||||||
slant = &(tokens[3]);
|
slant = &(tokens[SLANT]);
|
||||||
pixelsize = strToInt(&tokens[6]);
|
pixelsize = strToInt(&tokens[PIXEL_SIZE]);
|
||||||
size = strToInt(&tokens[7]);
|
size = strToInt(&tokens[POINT_SIZE]);
|
||||||
|
|
||||||
if (useFamily) {
|
if (useFamily) {
|
||||||
name = wstrdup(useFamily);
|
name = wstrdup(useFamily);
|
||||||
|
|||||||
@@ -22,8 +22,13 @@
|
|||||||
|
|
||||||
#define PROG_VERSION "geticonset (Window Maker) 0.1"
|
#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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
#include <WINGs/WUtil.h>
|
||||||
@@ -32,13 +37,16 @@
|
|||||||
|
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
|
||||||
void print_help()
|
void print_help(int print_usage, int exitval)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
|
printf("Usage: %s [-h] [-v] [file]\n", __progname);
|
||||||
puts("Retrieves program icon configuration and output to FILE or to stdout");
|
if (print_usage) {
|
||||||
puts("");
|
puts("Retrieves program icon configuration and output to FILE or to stdout");
|
||||||
puts(" -h, --help display this help and exit");
|
puts("");
|
||||||
puts(" -v, --version output version information and exit");
|
puts(" -h, --help display this help and exit");
|
||||||
|
puts(" -v, --version output version information and exit");
|
||||||
|
}
|
||||||
|
exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
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 *window_name, *icon_key, *window_attrs, *icon_value;
|
||||||
WMPropList *all_windows, *iconset, *keylist;
|
WMPropList *all_windows, *iconset, *keylist;
|
||||||
char *path;
|
char *path;
|
||||||
int i;
|
int i, ch;
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
struct option longopts[] = {
|
||||||
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
{ "version", no_argument, NULL, 'v' },
|
||||||
print_help();
|
{ "help", no_argument, NULL, 'h' },
|
||||||
exit(0);
|
{ NULL, 0, NULL, 0 }
|
||||||
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 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 */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
path = wdefaultspathfordomain("WMWindowAttributes");
|
path = wdefaultspathfordomain("WMWindowAttributes");
|
||||||
|
|
||||||
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 = WMCreatePLDictionary(NULL, NULL);
|
iconset = WMCreatePLDictionary(NULL, NULL);
|
||||||
@@ -88,10 +111,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 1) {
|
||||||
WMWritePropListToFile(iconset, argv[1]);
|
WMWritePropListToFile(iconset, argv[0]);
|
||||||
} else {
|
} else {
|
||||||
puts(WMGetPropListDescription(iconset, True));
|
puts(WMGetPropListDescription(iconset, True));
|
||||||
}
|
}
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
107
util/getstyle.c
107
util/getstyle.c
@@ -22,20 +22,25 @@
|
|||||||
|
|
||||||
#define PROG_VERSION "getstyle (Window Maker) 0.6"
|
#define PROG_VERSION "getstyle (Window Maker) 0.6"
|
||||||
|
|
||||||
|
#ifdef __GLIBC__
|
||||||
|
#define _GNU_SOURCE /* getopt_long */
|
||||||
|
#endif
|
||||||
|
|
||||||
#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 <stdlib.h>
|
#include <getopt.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <libgen.h>
|
|
||||||
#include <WINGs/WUtil.h>
|
#include <WINGs/WUtil.h>
|
||||||
|
|
||||||
#define RETRY( x ) do { \
|
#define RETRY( x ) do { \
|
||||||
@@ -132,15 +137,18 @@ char *ThemePath = NULL;
|
|||||||
|
|
||||||
extern char *convertFont(char *font, Bool keepXLFD);
|
extern char *convertFont(char *font, Bool keepXLFD);
|
||||||
|
|
||||||
void print_help()
|
void print_help(int print_usage, int exitval)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
|
printf("Usage: %s [-t] [-p] [-h] [-v] [file]\n", __progname);
|
||||||
puts("Retrieves style/theme configuration and output to FILE or to stdout");
|
if (print_usage) {
|
||||||
puts("");
|
puts("Retrieves style/theme configuration and output to FILE or to stdout");
|
||||||
puts(" -t, --theme-options output theme related options when producing a style file");
|
puts("");
|
||||||
puts(" -p, --pack produce output as a theme pack");
|
puts(" -h, --help display this help and exit");
|
||||||
puts(" -h, --help display this help and exit");
|
puts(" -v, --version output version information and exit");
|
||||||
puts(" -v, --version output version information and exit");
|
puts(" -t, --theme-options output theme related options when producing a style file");
|
||||||
|
puts(" -p, --pack produce output as a theme pack");
|
||||||
|
}
|
||||||
|
exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void abortar(char *reason)
|
void abortar(char *reason)
|
||||||
@@ -342,44 +350,55 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
WMPropList *prop, *style, *key, *val;
|
WMPropList *prop, *style, *key, *val;
|
||||||
char *path, *p;
|
char *path, *p;
|
||||||
int i, theme_too = 0, make_pack = 0;
|
int i, ch, theme_too = 0, make_pack = 0;
|
||||||
char *style_file = NULL;
|
char *style_file = NULL;
|
||||||
|
|
||||||
if (argc > 1) {
|
struct option longopts[] = {
|
||||||
for (i = 1; i < argc; i++) {
|
{ "pack", no_argument, NULL, 'p' },
|
||||||
if (strcmp(argv[i], "-p") == 0 || strcmp(argv[i], "--pack") == 0) {
|
{ "theme-options", no_argument, NULL, 't' },
|
||||||
|
{ "version", no_argument, NULL, 'v' },
|
||||||
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
while ((ch = getopt_long(argc, argv, "ptvh", longopts, NULL)) != -1)
|
||||||
|
switch(ch) {
|
||||||
|
case 'v':
|
||||||
|
puts(PROG_VERSION);
|
||||||
|
return 0;
|
||||||
|
/* NOTREACHED */
|
||||||
|
case 'h':
|
||||||
|
print_help(1, 0);
|
||||||
|
/* NOTREACHED */
|
||||||
|
case 'p':
|
||||||
make_pack = 1;
|
make_pack = 1;
|
||||||
theme_too = 1;
|
theme_too = 1;
|
||||||
} else if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--theme-options") == 0) {
|
break;
|
||||||
|
case 't':
|
||||||
theme_too = 1;
|
theme_too = 1;
|
||||||
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
case 0:
|
||||||
print_help();
|
break;
|
||||||
exit(0);
|
default:
|
||||||
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
|
print_help(0, 1);
|
||||||
puts(PROG_VERSION);
|
/* NOTREACHED */
|
||||||
exit(0);
|
|
||||||
} else {
|
|
||||||
if (style_file != NULL) {
|
|
||||||
printf("%s: invalid argument '%s'\n", __progname,
|
|
||||||
style_file[0] == '-' ? style_file : argv[i]);
|
|
||||||
printf("Try '%s --help' for more information\n", __progname);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
style_file = argv[i];
|
|
||||||
while ((p = strchr(style_file, '/')) != NULL)
|
|
||||||
*p = '_';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (style_file && !make_pack) {
|
argc -= optind;
|
||||||
print_help();
|
argv += optind;
|
||||||
exit(1);
|
|
||||||
}
|
if (argc != 1)
|
||||||
|
print_help(0, 1);
|
||||||
|
|
||||||
|
style_file = argv[0];
|
||||||
|
while ((p = strchr(style_file, '/')) != NULL)
|
||||||
|
*p = '_';
|
||||||
|
|
||||||
|
if (style_file && !make_pack) /* what's this? */
|
||||||
|
print_help(0, 1);
|
||||||
|
|
||||||
if (make_pack && !style_file) {
|
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);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
WMPLSetCaseSensitive(False);
|
WMPLSetCaseSensitive(False);
|
||||||
@@ -389,7 +408,7 @@ int main(int argc, char **argv)
|
|||||||
prop = WMReadPropListFromFile(path);
|
prop = WMReadPropListFromFile(path);
|
||||||
if (!prop) {
|
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);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get global value */
|
/* get global value */
|
||||||
@@ -459,5 +478,5 @@ int main(int argc, char **argv)
|
|||||||
puts(WMGetPropListDescription(style, True));
|
puts(WMGetPropListDescription(style, True));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,53 +22,67 @@
|
|||||||
|
|
||||||
#define PROG_VERSION "seticons (Window Maker) 0.1"
|
#define PROG_VERSION "seticons (Window Maker) 0.1"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#ifdef __GLIBC__
|
||||||
|
#define _GNU_SOURCE /* getopt_long */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <getopt.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <WINGs/WUtil.h>
|
#include <WINGs/WUtil.h>
|
||||||
|
|
||||||
#include "../src/wconfig.h"
|
#include "../src/wconfig.h"
|
||||||
|
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
|
||||||
void print_help()
|
void print_help(int print_usage, int exitval)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [OPTIONS] FILE\n", __progname);
|
printf("Usage: %s [-h] [-v] [file]\n", __progname);
|
||||||
puts("Reads icon configuration from FILE and updates Window Maker.");
|
if (print_usage) {
|
||||||
puts("");
|
puts("Reads icon configuration from FILE and updates Window Maker.");
|
||||||
puts(" -h, --help display this help and exit");
|
puts("");
|
||||||
puts(" -v, --version output version information and exit");
|
puts(" -h, --help display this help and exit");
|
||||||
|
puts(" -v, --version output version information and exit");
|
||||||
|
}
|
||||||
|
exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
|
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
|
||||||
WMPropList *all_windows, *iconset, *keylist;
|
WMPropList *all_windows, *iconset, *keylist;
|
||||||
int i;
|
int i, ch;
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
|
|
||||||
if (argc < 2) {
|
struct option longopts[] = {
|
||||||
printf("%s: missing argument\n", __progname);
|
{ "version", no_argument, NULL, 'v' },
|
||||||
printf("Try '%s --help' for more information\n", __progname);
|
{ "help", no_argument, NULL, 'h' },
|
||||||
exit(1);
|
{ NULL, 0, NULL, 0 }
|
||||||
}
|
};
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
|
||||||
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
|
switch(ch) {
|
||||||
print_help();
|
case 'v':
|
||||||
exit(0);
|
puts(PROG_VERSION);
|
||||||
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
|
return 0;
|
||||||
puts(PROG_VERSION);
|
/* NOTREACHED */
|
||||||
exit(0);
|
case 'h':
|
||||||
} else {
|
print_help(1, 0);
|
||||||
if (path) {
|
/* NOTREACHED */
|
||||||
printf("%s: invalid argument '%s'\n", __progname, argv[i]);
|
case 0:
|
||||||
printf("Try '%s --help' for more information\n", __progname);
|
break;
|
||||||
exit(1);
|
default:
|
||||||
}
|
print_help(0, 1);
|
||||||
path = argv[i];
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
argc -= optind;
|
||||||
|
argv += optind;
|
||||||
|
|
||||||
|
if (argc != 1)
|
||||||
|
print_help(0, 1);
|
||||||
|
|
||||||
path = wdefaultspathfordomain("WMWindowAttributes");
|
path = wdefaultspathfordomain("WMWindowAttributes");
|
||||||
|
|
||||||
@@ -78,9 +92,9 @@ int main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
iconset = WMReadPropListFromFile(argv[1]);
|
iconset = WMReadPropListFromFile(argv[0]);
|
||||||
if (!iconset) {
|
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[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user