Maximization regression
[wmaker-crm.git] / util / wdwrite.c
bloba2bb61fa15ccb7c3c9ba36a8529a1e9440b2ad80
1 /* wdwrite.c - write key/value to defaults database
3 * WindowMaker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifdef __GLIBC__
23 #define _GNU_SOURCE /* getopt_long */
24 #endif
27 * WindowMaker defaults DB writer
31 #include <getopt.h>
32 #include <limits.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <unistd.h>
38 #include <WINGs/WUtil.h>
40 #include "../src/wconfig.h"
42 extern char *__progname;
44 static void print_help(int print_usage, int exitval)
46 printf("Usage: %s [OPTIONS] <domain> <key> <value>\n", __progname);
47 if (print_usage) {
48 puts("Write <value> for <key> in <domain>'s database");
49 puts("");
50 puts(" -h, --help display this help message");
51 puts(" -v, --version output version information and exit");
53 exit(exitval);
56 int main(int argc, char **argv)
58 char path[PATH_MAX];
59 WMPropList *key, *value, *dict;
60 int ch;
62 struct option longopts[] = {
63 { "version", no_argument, NULL, 'v' },
64 { "help", no_argument, NULL, 'h' },
65 { NULL, 0, NULL, 0 }
68 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
69 switch(ch) {
70 case 'v':
71 printf("%s (Window Maker %s)\n", __progname, VERSION);
72 return 0;
73 /* NOTREACHED */
74 case 'h':
75 print_help(1, 0);
76 /* NOTREACHED */
77 case 0:
78 break;
79 default:
80 print_help(0, 1);
81 /* NOTREACHED */
84 argc -= optind;
85 argv += optind;
87 if (argc != 3)
88 print_help(0, 1);
90 key = WMCreatePLString(argv[1]);
91 value = WMCreatePropListFromDescription(argv[2]);
92 if (!value) {
93 printf("%s: syntax error in value \"%s\"", __progname, argv[2]);
94 return 1;
97 snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
99 dict = WMReadPropListFromFile(path);
100 if (!dict) {
101 dict = WMCreatePLDictionary(key, value, NULL);
102 } else {
103 WMPutInPLDictionary(dict, key, value);
106 WMWritePropListToFile(dict, path);
108 return 0;