- fixed problem with WINGs based apps exiting with a "X_RotateProperties"
[wmaker-crm.git] / util / seticons.c
blobfd5a171fb6b8bdf23f7882ca48f2261af738ecdf
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 <proplist.h>
30 #include <string.h>
32 #include "../src/wconfig.h"
34 char *ProgName;
36 char*
37 defaultsPathForDomain(char *domain)
39 static char path[1024];
40 char *gspath;
42 gspath = getenv("GNUSTEP_USER_ROOT");
43 if (gspath) {
44 strcpy(path, gspath);
45 strcat(path, "/");
46 } else {
47 char *home;
49 home = getenv("HOME");
50 if (!home) {
51 printf("%s:could not get HOME environment variable!\n", ProgName);
52 exit(0);
55 strcpy(path, home);
56 strcat(path, "/GNUstep/");
58 strcat(path, DEFAULTS_DIR);
59 strcat(path, "/");
60 strcat(path, domain);
62 return path;
66 void
67 print_help()
69 printf("Usage: %s [OPTIONS] FILE\n", ProgName);
70 puts("Reads icon configuration from FILE and updates Window Maker.");
71 puts("");
72 puts(" --help display this help and exit");
73 puts(" --version output version information and exit");
77 int
78 main(int argc, char **argv)
80 proplist_t window_name, icon_key, window_attrs, icon_value;
81 proplist_t all_windows, iconset;
82 proplist_t keylist;
83 int i;
84 char *path = NULL;
86 ProgName = argv[0];
89 if (argc < 2) {
90 printf("%s: missing argument\n", ProgName);
91 printf("Try '%s --help' for more information\n", ProgName);
94 for (i = 1; i < argc; i++) {
95 if (strcmp(argv[i], "-h")==0
96 || strcmp(argv[i], "--help")==0) {
97 print_help();
98 exit(0);
99 } else if (strcmp(argv[i], "--version")==0) {
100 puts(PROG_VERSION);
101 exit(0);
102 } else {
103 if (path) {
104 printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
105 printf("Try '%s --help' for more information\n", ProgName);
106 exit(1);
108 path = argv[i];
112 path = defaultsPathForDomain("WMWindowAttributes");
114 all_windows = PLGetProplistWithPath(path);
115 if (!all_windows) {
116 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
117 ProgName, path);
118 exit(1);
121 iconset = PLGetProplistWithPath(argv[1]);
122 if (!iconset) {
123 printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
124 exit(1);
128 keylist = PLGetAllDictionaryKeys(iconset);
129 icon_key = PLMakeString("Icon");
131 for (i=0; i<PLGetNumberOfElements(keylist); i++) {
132 window_name = PLGetArrayElement(keylist, i);
133 if (!PLIsString(window_name))
134 continue;
136 icon_value = PLGetDictionaryEntry(iconset, window_name);
137 if (!icon_value || !PLIsDictionary(icon_value))
138 continue;
140 window_attrs = PLGetDictionaryEntry(all_windows, window_name);
141 if (window_attrs) {
142 if (PLIsDictionary(window_attrs)) {
143 PLMergeDictionaries(window_attrs, icon_value);
145 } else {
146 PLInsertDictionaryEntry(all_windows, window_name, icon_value);
150 PLSave(all_windows, YES);
152 exit(0);