Initial revision
[wmaker-crm.git] / util / seticons.c
blob136ae1e2aa7002ea8d337f8cd017e5a902eb6d68
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.
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <proplist.h>
28 #include <string.h>
30 #include "../src/wconfig.h"
32 char *ProgName;
34 char*
35 defaultsPathForDomain(char *domain)
37 char path[1024];
38 char *gspath, *tmp;
40 gspath = getenv("GNUSTEP_USER_ROOT");
41 if (gspath) {
42 strcpy(path, gspath);
43 strcat(path, "/");
44 } else {
45 char *home;
47 home = getenv("HOME");
48 if (!home) {
49 printf("%s:could not get HOME environment variable!\n", ProgName);
50 exit(0);
53 strcpy(path, home);
54 strcat(path, "/GNUstep/");
56 strcat(path, DEFAULTS_DIR);
57 strcat(path, "/");
58 strcat(path, domain);
60 tmp = malloc(strlen(path)+2);
61 strcpy(tmp, path);
63 return tmp;
67 int
68 main(int argc, char **argv)
70 proplist_t window_name, icon_key, window_attrs, icon_value;
71 proplist_t all_windows, iconset;
72 proplist_t keylist;
73 int i;
74 char *path;
76 ProgName = argv[0];
78 if (argc!=2) {
79 printf("Syntax:\n%s <iconset file>\n", argv[0]);
80 exit(1);
83 path = defaultsPathForDomain("WMWindowAttributes");
85 all_windows = PLGetProplistWithPath(path);
86 if (!all_windows) {
87 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
88 ProgName, path);
89 exit(1);
92 iconset = PLGetProplistWithPath(argv[1]);
93 if (!iconset) {
94 printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
95 exit(1);
99 keylist = PLGetAllDictionaryKeys(iconset);
100 icon_key = PLMakeString("Icon");
102 for (i=0; i<PLGetNumberOfElements(keylist); i++) {
103 window_name = PLGetArrayElement(keylist, i);
104 if (!PLIsString(window_name))
105 continue;
107 icon_value = PLGetDictionaryEntry(iconset, window_name);
108 if (!icon_value || !PLIsDictionary(icon_value))
109 continue;
111 window_attrs = PLGetDictionaryEntry(all_windows, window_name);
112 if (window_attrs) {
113 if (PLIsDictionary(window_attrs)) {
114 PLMergeDictionaries(window_attrs, icon_value);
116 } else {
117 PLInsertDictionaryEntry(all_windows, window_name, icon_value);
121 PLSave(all_windows, YES);
123 exit(0);