WPrefs: add an image to represent the window in the Window Placement frame
[wmaker-crm.git] / util / seticons.c
blob4556d90451c075c930fdd0b85c2b2fc97e1e1b62
1 /* seticons.c - sets icon configuration in WindowMaker
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
26 #include "config.h"
28 #include <getopt.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #ifdef HAVE_STDNORETURN
34 #include <stdnoreturn.h>
35 #endif
37 #include <WINGs/WUtil.h>
39 #include "../src/wconfig.h"
41 static const char *prog_name;
43 static noreturn void print_help(int print_usage, int exitval)
45 printf("Usage: %s [-h] [-v] [file]\n", prog_name);
46 if (print_usage) {
47 puts("Reads icon configuration from FILE and updates Window Maker.");
48 puts("");
49 puts(" -h, --help display this help and exit");
50 puts(" -v, --version output version information and exit");
52 exit(exitval);
55 int main(int argc, char **argv)
57 WMPropList *window_name, *window_attrs, *icon_value;
58 WMPropList *all_windows, *iconset, *keylist;
59 int i, ch;
60 char *path = NULL;
62 struct option longopts[] = {
63 { "version", no_argument, NULL, 'v' },
64 { "help", no_argument, NULL, 'h' },
65 { NULL, 0, NULL, 0 }
68 prog_name = argv[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", prog_name, 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 != 1)
89 print_help(0, 1);
91 path = wdefaultspathfordomain("WMWindowAttributes");
93 all_windows = WMReadPropListFromFile(path);
94 if (!all_windows) {
95 printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path);
96 return 1;
99 iconset = WMReadPropListFromFile(argv[0]);
100 if (!iconset) {
101 printf("%s: could not load icon set file \"%s\".\n", prog_name, argv[0]);
102 return 1;
105 keylist = WMGetPLDictionaryKeys(iconset);
107 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
108 window_name = WMGetFromPLArray(keylist, i);
109 if (!WMIsPLString(window_name))
110 continue;
112 icon_value = WMGetFromPLDictionary(iconset, window_name);
113 if (!icon_value || !WMIsPLDictionary(icon_value))
114 continue;
116 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
117 if (window_attrs) {
118 if (WMIsPLDictionary(window_attrs)) {
119 WMMergePLDictionaries(window_attrs, icon_value, True);
121 } else {
122 WMPutInPLDictionary(all_windows, window_name, icon_value);
126 WMWritePropListToFile(all_windows, path);
128 return 0;