Initial revision
[wmaker-crm.git] / util / geticonset.c
blob7fe60ec0698699b9f8d720d240a628552e8d4f12
1 /* geticonset.c - outputs icon configuration from WindowMaker to stdout
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>
27 #include <string.h>
29 #include "../src/wconfig.h"
34 char *ProgName;
37 char*
38 defaultsPathForDomain(char *domain)
40 char path[1024];
41 char *gspath, *tmp;
43 gspath = getenv("GNUSTEP_USER_ROOT");
44 if (gspath) {
45 strcpy(path, gspath);
46 strcat(path, "/");
47 } else {
48 char *home;
50 home = getenv("HOME");
51 if (!home) {
52 printf("%s:could not get HOME environment variable!\n", ProgName);
53 exit(0);
55 strcpy(path, home);
56 strcat(path, "/GNUstep/");
58 strcat(path, DEFAULTS_DIR);
59 strcat(path, "/");
60 strcat(path, domain);
62 tmp = malloc(strlen(path)+2);
63 strcpy(tmp, path);
65 return tmp;
69 int
70 main(int argc, char **argv)
72 proplist_t window_name, icon_key, window_attrs, icon_value;
73 proplist_t all_windows, iconset;
74 proplist_t keylist;
75 char *path;
76 int i;
79 ProgName = argv[0];
81 if (argc>2 || (argc==2 && strcmp(argv[1], "-h")==0)) {
82 printf("Syntax:\n%s [<iconset file>]\n", argv[0]);
83 exit(1);
86 path = defaultsPathForDomain("WMWindowAttributes");
88 all_windows = PLGetProplistWithPath(path);
89 if (!all_windows) {
90 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
91 ProgName, path);
92 exit(1);
95 iconset = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
97 keylist = PLGetAllDictionaryKeys(all_windows);
98 icon_key = PLMakeString("Icon");
100 for (i=0; i<PLGetNumberOfElements(keylist); i++) {
101 proplist_t icondic;
103 window_name = PLGetArrayElement(keylist, i);
104 if (!PLIsString(window_name))
105 continue;
107 window_attrs = PLGetDictionaryEntry(all_windows, window_name);
108 if (window_attrs && PLIsDictionary(window_attrs)) {
109 icon_value = PLGetDictionaryEntry(window_attrs, icon_key);
110 if (icon_value) {
112 icondic = PLMakeDictionaryFromEntries(icon_key, icon_value,
113 NULL);
115 PLInsertDictionaryEntry(iconset, window_name, icondic);
121 if (argc==2) {
122 proplist_t val;
123 val = PLMakeString(argv[1]);
124 PLSetFilename(iconset, val);
125 PLSave(iconset, NO);
126 } else {
127 puts(PLGetDescriptionIndent(iconset, 0));
129 exit(0);