Fix non-I18N build
[wmaker-crm.git] / util / wdwrite.c
blob494cd7f4eb0275f2c172237f5f28581ed4dec09e
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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #define PROG_VERSION "wdwrite (Window Maker) 0.2"
26 * WindowMaker defaults DB writer
29 #include "../src/wconfig.h"
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdio.h>
34 #include <unistd.h>
36 #include <WINGs/WUtil.h>
38 #include <pwd.h>
40 extern char *__progname;
42 void wAbort()
44 exit(0);
47 void print_help()
49 printf("Usage: %s [OPTIONS] <domain> <option> <value>\n", __progname);
50 puts("");
51 puts(" -h, --help display this help message");
52 puts(" -v, --version output version information and exit");
53 exit(1);
56 int main(int argc, char **argv)
58 char path[256];
59 WMPropList *dom, *key, *value, *dict;
60 int i;
62 for (i = 1; i < argc; i++) {
63 if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
64 print_help();
65 exit(0);
66 } else if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
67 puts(PROG_VERSION);
68 exit(0);
72 if (argc < 4) {
73 printf("%s: invalid argument format\n", __progname);
74 printf("Try '%s --help' for more information\n", __progname);
75 exit(1);
78 dom = WMCreatePLString(argv[1]);
79 key = WMCreatePLString(argv[2]);
80 value = WMCreatePropListFromDescription(argv[3]);
81 if (!value) {
82 printf("%s: syntax error in value \"%s\"", __progname, argv[3]);
83 exit(1);
86 snprintf(path, sizeof(path), wdefaultspathfordomain(argv[1]));
88 dict = WMReadPropListFromFile(path);
89 if (!dict) {
90 dict = WMCreatePLDictionary(key, value, NULL);
91 } else {
92 WMPutInPLDictionary(dict, key, value);
95 WMWritePropListToFile(dict, path);
97 return 0;