Convert po/README from iso-8859-1 to utf-8
[wmaker-crm.git] / util / wdread.c
blob2351b2ddfaa531e848e4a94d626b37a9060d9d65
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 along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifdef __GLIBC__
24 #define _GNU_SOURCE /* getopt_long */
25 #endif
28 * WindowMaker defaults DB reader
30 #include "config.h"
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 #ifdef HAVE_STDNORETURN
40 #include <stdnoreturn.h>
41 #endif
43 #include <WINGs/WUtil.h>
45 #include "../src/wconfig.h"
47 static const char *prog_name;
49 static noreturn void print_help(int print_usage, int exitval)
51 printf("Usage: %s [OPTIONS] <domain> <key>\n", prog_name);
52 if (print_usage) {
53 puts("Read <key> from <domain>'s database");
54 puts("");
55 puts(" -h, --help display this help message");
56 puts(" -v, --version output version information and exit");
58 exit(exitval);
61 int main(int argc, char **argv)
63 char path[PATH_MAX];
64 WMPropList *key, *value, *dict;
65 int ch;
67 struct option longopts[] = {
68 { "version", no_argument, NULL, 'v' },
69 { "help", no_argument, NULL, 'h' },
70 { NULL, 0, NULL, 0 }
73 prog_name = argv[0];
74 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
75 switch(ch) {
76 case 'v':
77 printf("%s (Window Maker %s)\n", prog_name, VERSION);
78 return 0;
79 /* NOTREACHED */
80 case 'h':
81 print_help(1, 0);
82 /* NOTREACHED */
83 case 0:
84 break;
85 default:
86 print_help(0, 1);
87 /* NOTREACHED */
90 argc -= optind;
91 argv += optind;
93 if (argc != 2)
94 print_help(0, 1);
96 key = WMCreatePLString(argv[1]);
98 snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
100 dict = WMReadPropListFromFile(path);
101 if (dict == NULL)
102 return 1; /* bad domain */
104 value = WMGetFromPLDictionary(dict, key);
105 if (value == NULL)
106 return 2; /* bad key */
108 printf("%s\n", WMGetPropListDescription(value, True));
109 return 0;