1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-08 23:04:15 +01:00

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)
This commit is contained in:
Tamas TEVESZ
2010-03-18 23:14:23 +01:00
committed by Carlos R. Mafra
parent 9dadfe7a68
commit 118a93808a
13 changed files with 198 additions and 378 deletions

View File

@@ -38,39 +38,19 @@
#include <pwd.h>
char *ProgName;
char *gethomedir()
{
char *home = getenv("HOME");
struct passwd *user;
if (home)
return home;
user = getpwuid(getuid());
if (!user) {
perror(ProgName);
return "/";
}
if (!user->pw_dir) {
return "/";
} else {
return user->pw_dir;
}
}
extern char *__progname;
void wAbort()
{
exit(0);
}
void help()
void print_help()
{
printf("Syntax:\n%s [OPTIONS] <domain> <option>\n", ProgName);
printf("Usage: %s [OPTIONS] <domain> <option>\n", __progname);
puts("");
puts(" --help display this help message");
puts(" --version output version information and exit");
puts(" -h, --help display this help message");
puts(" -v, --version output version information and exit");
exit(1);
}
@@ -78,40 +58,27 @@ int main(int argc, char **argv)
{
char path[256];
WMPropList *key, *value, *dict;
char *gsdir;
int i;
ProgName = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp("--help", argv[i]) == 0) {
help();
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else if (strcmp("--version", argv[i]) == 0) {
} else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
}
}
if (argc < 3) {
printf("%s: invalid argument format\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
printf("%s: invalid argument format\n", __progname);
printf("Try '%s --help' for more information\n", __progname);
exit(1);
}
key = WMCreatePLString(argv[2]);
gsdir = getenv("GNUSTEP_USER_ROOT");
if (gsdir) {
strcpy(path, gsdir);
} else {
strcpy(path, gethomedir());
strcat(path, "/GNUstep");
}
strcat(path, "/");
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, argv[1]);
snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
if ((dict = WMReadPropListFromFile(path)) == NULL)
return 1; /* bad domain */