- Fixed crashing bug in menu.c
[wmaker-crm.git] / util / wdread.c
blob68dfda6e9fa082f988a64cfff4baa3c0e59e662f
1 /* wdread.c - read value from defaults database
3 * WindowMaker window manager
4 *
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * (cowardly remade from wdwrite.c; by judas@hell on Jan 26 2001)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 * USA.
24 #define PROG_VERSION "wdread (Window Maker) 0.2"
28 * WindowMaker defaults DB reader
32 #include "../src/wconfig.h"
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <unistd.h>
39 #include <WINGs/WUtil.h>
41 #include <pwd.h>
44 char *ProgName;
46 char*
47 gethomedir()
49 char *home = getenv("HOME");
50 struct passwd *user;
52 if (home)
53 return home;
55 user = getpwuid(getuid());
56 if (!user) {
57 perror(ProgName);
58 return "/";
60 if (!user->pw_dir) {
61 return "/";
62 } else {
63 return user->pw_dir;
69 void wAbort()
71 exit(0);
74 void help()
76 printf("Syntax:\n%s [OPTIONS] <domain> <option>\n", ProgName);
77 puts("");
78 puts(" --help display this help message");
79 puts(" --version output version information and exit");
80 exit(1);
84 int main(int argc, char **argv)
86 char path[256];
87 WMPropList *key, *value, *dict;
88 char *gsdir;
89 int i;
91 ProgName = argv[0];
93 for (i = 1; i < argc; i++) {
94 if (strcmp("--help", argv[i])==0) {
95 help();
96 exit(0);
97 } else if (strcmp("--version", argv[i])==0) {
98 puts(PROG_VERSION);
99 exit(0);
103 if (argc<3) {
104 printf("%s: invalid argument format\n", ProgName);
105 printf("Try '%s --help' for more information\n", ProgName);
106 exit(1);
109 key = WMCreatePLString(argv[2]);
111 gsdir = getenv("GNUSTEP_USER_ROOT");
112 if (gsdir) {
113 strcpy(path, gsdir);
114 } else {
115 strcpy(path, gethomedir());
116 strcat(path, "/GNUstep");
118 strcat(path, "/");
119 strcat(path, DEFAULTS_DIR);
120 strcat(path, "/");
121 strcat(path, argv[1]);
123 if ((dict = WMReadPropListFromFile(path)) == NULL)
124 return 1; /* bad domain */
125 if ((value = WMGetFromPLDictionary(dict, key)) == NULL)
126 return 2; /* bad key */
128 printf("%s\n", WMGetPropListDescription(value, True));
129 return 0;