Update Serbian translation from master branch
[wmaker-crm.git] / util / wdwrite.c
blob2ff16706fe3429b2987d7f68c98a3f234c9e4930
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
29 #include "config.h"
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 #ifdef HAVE_STDNORETURN
39 #include <stdnoreturn.h>
40 #endif
42 #include <WINGs/WUtil.h>
44 #include "../src/wconfig.h"
46 static const char *prog_name;
48 static noreturn void print_help(int print_usage, int exitval)
50 printf("Usage: %s [OPTIONS] <domain> <key> <value>\n", prog_name);
51 if (print_usage) {
52 puts("Write <value> for <key> in <domain>'s database");
53 puts("");
54 puts(" -h, --help display this help message");
55 puts(" -v, --version output version information and exit");
57 exit(exitval);
60 int main(int argc, char **argv)
62 char path[PATH_MAX];
63 WMPropList *key, *value, *dict;
64 int ch;
66 struct option longopts[] = {
67 { "version", no_argument, NULL, 'v' },
68 { "help", no_argument, NULL, 'h' },
69 { NULL, 0, NULL, 0 }
72 prog_name = argv[0];
73 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
74 switch(ch) {
75 case 'v':
76 printf("%s (Window Maker %s)\n", prog_name, VERSION);
77 return 0;
78 /* NOTREACHED */
79 case 'h':
80 print_help(1, 0);
81 /* NOTREACHED */
82 case 0:
83 break;
84 default:
85 print_help(0, 1);
86 /* NOTREACHED */
89 argc -= optind;
90 argv += optind;
92 if (argc != 3)
93 print_help(0, 1);
95 key = WMCreatePLString(argv[1]);
96 value = WMCreatePropListFromDescription(argv[2]);
97 if (!value) {
98 printf("%s: syntax error in value \"%s\"", prog_name, argv[2]);
99 return 1;
102 snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
104 dict = WMReadPropListFromFile(path);
105 if (!dict) {
106 dict = WMCreatePLDictionary(key, value, NULL);
107 } else {
108 WMPutInPLDictionary(dict, key, value);
111 WMWritePropListToFile(dict, path);
113 return 0;