aded new stuffs
[wmaker-crm.git] / util / wdread.c
blobd0e84558fbe43a34d8cb657431fdcf980a62df03
1 /* wdread.c - read value from defaults database
3 * WindowMaker window manager
4 *
5 * Copyright (c) 1997, 1998 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 <proplist.h>
40 #include <pwd.h>
43 char *ProgName;
45 char*
46 gethomedir()
48 char *home = getenv("HOME");
49 struct passwd *user;
51 if (home)
52 return home;
54 user = getpwuid(getuid());
55 if (!user) {
56 perror(ProgName);
57 return "/";
59 if (!user->pw_dir) {
60 return "/";
61 } else {
62 return user->pw_dir;
68 void wAbort()
70 exit(0);
73 void help()
75 printf("Syntax:\n%s [OPTIONS] <domain> <option>\n", ProgName);
76 puts("");
77 puts(" --help display this help message");
78 puts(" --version output version information and exit");
79 exit(1);
83 int main(int argc, char **argv)
85 char path[256];
86 proplist_t key, value, dict;
87 char *gsdir;
88 int i;
90 ProgName = argv[0];
92 for (i = 1; i < argc; i++) {
93 if (strcmp("--help", argv[i])==0) {
94 help();
95 exit(0);
96 } else if (strcmp("--version", argv[i])==0) {
97 puts(PROG_VERSION);
98 exit(0);
102 if (argc<3) {
103 printf("%s: invalid argument format\n", ProgName);
104 printf("Try '%s --help' for more information\n", ProgName);
105 exit(1);
108 key = PLMakeString(argv[2]);
110 gsdir = getenv("GNUSTEP_USER_ROOT");
111 if (gsdir) {
112 strcpy(path, gsdir);
113 } else {
114 strcpy(path, gethomedir());
115 strcat(path, "/GNUstep");
117 strcat(path, "/");
118 strcat(path, DEFAULTS_DIR);
119 strcat(path, "/");
120 strcat(path, argv[1]);
122 if ((dict = PLGetProplistWithPath(path)) == NULL)
123 return 1; // bad domain
124 if ((value = PLGetDictionaryEntry(dict, key)) == NULL)
125 return 2; // bad key
127 printf("%s\n", PLGetString(value));
128 return 0;