Improve dockapp recognition
[wmaker-crm.git] / util / wdread.c
blobce44fc5ac73f790ae104c1615f7f6f2caa738953
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 #ifdef __GLIBC__
25 #define _GNU_SOURCE /* getopt_long */
26 #endif
29 * WindowMaker defaults DB reader
32 #include <getopt.h>
33 #include <limits.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h>
39 #include <WINGs/WUtil.h>
41 #include "../src/wconfig.h"
43 extern char *__progname;
45 void print_help(int print_usage, int exitval)
47 printf("Usage: %s [OPTIONS] <domain> <key>\n", __progname);
48 if (print_usage) {
49 puts("Read <key> from <domain>'s database");
50 puts("");
51 puts(" -h, --help display this help message");
52 puts(" -v, --version output version information and exit");
54 exit(exitval);
57 int main(int argc, char **argv)
59 char path[PATH_MAX];
60 WMPropList *key, *value, *dict;
61 int ch;
63 struct option longopts[] = {
64 { "version", no_argument, NULL, 'v' },
65 { "help", no_argument, NULL, 'h' },
66 { NULL, 0, NULL, 0 }
69 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
70 switch(ch) {
71 case 'v':
72 printf("%s (Window Maker %s)\n", __progname, VERSION);
73 return 0;
74 /* NOTREACHED */
75 case 'h':
76 print_help(1, 0);
77 /* NOTREACHED */
78 case 0:
79 break;
80 default:
81 print_help(0, 1);
82 /* NOTREACHED */
85 argc -= optind;
86 argv += optind;
88 if (argc != 2)
89 print_help(0, 1);
91 key = WMCreatePLString(argv[1]);
93 snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
95 dict = WMReadPropListFromFile(path);
96 if (dict == NULL)
97 return 1; /* bad domain */
99 value = WMGetFromPLDictionary(dict, key);
100 if (value == NULL)
101 return 2; /* bad key */
103 printf("%s\n", WMGetPropListDescription(value, True));
104 return 0;