- improved behaviour for the shared appicon thing.
[wmaker-crm.git] / util / seticons.c
blobd0b5e6ae14a6b7e34d6795369e6ee700c5bc3241
1 /* seticons.c - sets icon configuration in WindowMaker
3 * WindowMaker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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"
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <WINGs/WUtil.h>
31 #include "../src/wconfig.h"
33 char *ProgName;
35 char*
36 defaultsPathForDomain(char *domain)
38 static char path[1024];
39 char *gspath;
41 gspath = getenv("GNUSTEP_USER_ROOT");
42 if (gspath) {
43 strcpy(path, gspath);
44 strcat(path, "/");
45 } else {
46 char *home;
48 home = getenv("HOME");
49 if (!home) {
50 printf("%s:could not get HOME environment variable!\n", ProgName);
51 exit(0);
54 strcpy(path, home);
55 strcat(path, "/GNUstep/");
57 strcat(path, DEFAULTS_DIR);
58 strcat(path, "/");
59 strcat(path, domain);
61 return path;
65 void
66 print_help()
68 printf("Usage: %s [OPTIONS] FILE\n", ProgName);
69 puts("Reads icon configuration from FILE and updates Window Maker.");
70 puts("");
71 puts(" --help display this help and exit");
72 puts(" --version output version information and exit");
76 int
77 main(int argc, char **argv)
79 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
80 WMPropList *all_windows, *iconset, *keylist;
81 int i;
82 char *path = NULL;
84 ProgName = argv[0];
87 if (argc < 2) {
88 printf("%s: missing argument\n", ProgName);
89 printf("Try '%s --help' for more information\n", ProgName);
92 for (i = 1; i < argc; i++) {
93 if (strcmp(argv[i], "-h")==0
94 || strcmp(argv[i], "--help")==0) {
95 print_help();
96 exit(0);
97 } else if (strcmp(argv[i], "--version")==0) {
98 puts(PROG_VERSION);
99 exit(0);
100 } else {
101 if (path) {
102 printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
103 printf("Try '%s --help' for more information\n", ProgName);
104 exit(1);
106 path = argv[i];
110 path = defaultsPathForDomain("WMWindowAttributes");
112 all_windows = WMReadPropListFromFile(path);
113 if (!all_windows) {
114 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
115 ProgName, path);
116 exit(1);
119 iconset = WMReadPropListFromFile(argv[1]);
120 if (!iconset) {
121 printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
122 exit(1);
126 keylist = WMGetPLDictionaryKeys(iconset);
127 icon_key = WMCreatePLString("Icon");
129 for (i=0; i<WMGetPropListItemCount(keylist); i++) {
130 window_name = WMGetFromPLArray(keylist, i);
131 if (!WMIsPLString(window_name))
132 continue;
134 icon_value = WMGetFromPLDictionary(iconset, window_name);
135 if (!icon_value || !WMIsPLDictionary(icon_value))
136 continue;
138 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
139 if (window_attrs) {
140 if (WMIsPLDictionary(window_attrs)) {
141 WMMergePLDictionaries(window_attrs, icon_value, True);
143 } else {
144 WMPutInPLDictionary(all_windows, window_name, icon_value);
148 WMWritePropListToFile(all_windows, path, True);
150 exit(0);