Idle fixes
[wmaker-crm.git] / util / wdread.c
bloba72fb22eb6417274ea4909eae5a1a2c442b54ae1
1 /* wdread.c - read value from defaults database
3 * WindowMaker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
6 * (cowardly remade from wdwrite.c; by judas@hell on Jan 26 2001)
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"
27 * WindowMaker defaults DB reader
30 #include "../src/wconfig.h"
32 #include <stdlib.h>
33 #include <string.h>
34 #include <stdio.h>
35 #include <unistd.h>
37 #include <WINGs/WUtil.h>
39 #include <pwd.h>
41 extern char *__progname;
43 void wAbort()
45 exit(0);
48 void print_help()
50 printf("Usage: %s [OPTIONS] <domain> <option>\n", __progname);
51 puts("");
52 puts(" -h, --help display this help message");
53 puts(" -v, --version output version information and exit");
54 exit(1);
57 int main(int argc, char **argv)
59 char path[256];
60 WMPropList *key, *value, *dict;
61 int i;
63 for (i = 1; i < argc; i++) {
64 if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
65 print_help();
66 exit(0);
67 } else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
68 puts(PROG_VERSION);
69 exit(0);
73 if (argc < 3) {
74 printf("%s: invalid argument format\n", __progname);
75 printf("Try '%s --help' for more information\n", __progname);
76 exit(1);
79 key = WMCreatePLString(argv[2]);
81 snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
83 if ((dict = WMReadPropListFromFile(path)) == NULL)
84 return 1; /* bad domain */
85 if ((value = WMGetFromPLDictionary(dict, key)) == NULL)
86 return 2; /* bad key */
88 printf("%s\n", WMGetPropListDescription(value, True));
89 return 0;