Idle fixes
[wmaker-crm.git] / util / seticons.c
blob96baf9841b91a3a4cfe24e3ceffa0658325d1478
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
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 "seticons (Window Maker) 0.1"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <WINGs/WUtil.h>
30 #include "../src/wconfig.h"
32 extern char *__progname;
34 void print_help()
36 printf("Usage: %s [OPTIONS] FILE\n", __progname);
37 puts("Reads icon configuration from FILE and updates Window Maker.");
38 puts("");
39 puts(" -h, --help display this help and exit");
40 puts(" -v, --version output version information and exit");
43 int main(int argc, char **argv)
45 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
46 WMPropList *all_windows, *iconset, *keylist;
47 int i;
48 char *path = NULL;
50 if (argc < 2) {
51 printf("%s: missing argument\n", __progname);
52 printf("Try '%s --help' for more information\n", __progname);
53 exit(1);
56 for (i = 1; i < argc; i++) {
57 if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
58 print_help();
59 exit(0);
60 } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
61 puts(PROG_VERSION);
62 exit(0);
63 } else {
64 if (path) {
65 printf("%s: invalid argument '%s'\n", __progname, argv[i]);
66 printf("Try '%s --help' for more information\n", __progname);
67 exit(1);
69 path = argv[i];
73 path = wdefaultspathfordomain("WMWindowAttributes");
75 all_windows = WMReadPropListFromFile(path);
76 if (!all_windows) {
77 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
78 exit(1);
81 iconset = WMReadPropListFromFile(argv[1]);
82 if (!iconset) {
83 printf("%s: could not load icon set file \"%s\".\n", __progname, argv[1]);
84 exit(1);
87 keylist = WMGetPLDictionaryKeys(iconset);
88 icon_key = WMCreatePLString("Icon");
90 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
91 window_name = WMGetFromPLArray(keylist, i);
92 if (!WMIsPLString(window_name))
93 continue;
95 icon_value = WMGetFromPLDictionary(iconset, window_name);
96 if (!icon_value || !WMIsPLDictionary(icon_value))
97 continue;
99 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
100 if (window_attrs) {
101 if (WMIsPLDictionary(window_attrs)) {
102 WMMergePLDictionaries(window_attrs, icon_value, True);
104 } else {
105 WMPutInPLDictionary(all_windows, window_name, icon_value);
109 WMWritePropListToFile(all_windows, path);
111 exit(0);