Improve dockapp recognition
[wmaker-crm.git] / util / wdwrite.c
blob9317b19e910913dedb1e75412dfb3150b7347194
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 #ifdef __GLIBC__
24 #define _GNU_SOURCE /* getopt_long */
25 #endif
28 * WindowMaker defaults DB writer
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> <value>\n", __progname);
48 if (print_usage) {
49 puts("Write <value> for <key> in <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 *dom, *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 != 3)
89 print_help(0, 1);
91 dom = WMCreatePLString(argv[0]);
92 key = WMCreatePLString(argv[1]);
93 value = WMCreatePropListFromDescription(argv[2]);
94 if (!value) {
95 printf("%s: syntax error in value \"%s\"", __progname, argv[2]);
96 return 1;
99 snprintf(path, sizeof(path), "%s", wdefaultspathfordomain(argv[0]));
101 dict = WMReadPropListFromFile(path);
102 if (!dict) {
103 dict = WMCreatePLDictionary(key, value, NULL);
104 } else {
105 WMPutInPLDictionary(dict, key, value);
108 WMWritePropListToFile(dict, path);
110 return 0;