- Fixed text in info panel for multibyte (Seiichi SATO <ssato@sh.rim.or.jp>)
[wmaker-crm.git] / util / geticonset.c
blob0ed73dcaf21beed937bb64123efa4ce77f045c09
1 /* geticonset.c - outputs icon configuration from WindowMaker to stdout
3 * Window Maker window manager
4 *
5 * Copyright (c) 1997-2002 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 "geticonset (Window Maker) 0.1"
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
30 #include <WINGs/WUtil.h>
32 #include "../src/wconfig.h"
36 char *ProgName;
39 char*
40 defaultsPathForDomain(char *domain)
42 static char path[1024];
43 char *gspath;
45 gspath = getenv("GNUSTEP_USER_ROOT");
46 if (gspath) {
47 strcpy(path, gspath);
48 strcat(path, "/");
49 } else {
50 char *home;
52 home = getenv("HOME");
53 if (!home) {
54 printf("%s:could not get HOME environment variable!\n", ProgName);
55 exit(0);
57 strcpy(path, home);
58 strcat(path, "/GNUstep/");
60 strcat(path, DEFAULTS_DIR);
61 strcat(path, "/");
62 strcat(path, domain);
64 return path;
67 void
68 print_help()
70 printf("Usage: %s [OPTIONS] [FILE]\n", ProgName);
71 puts("Retrieves program icon configuration and output to FILE or to stdout");
72 puts("");
73 puts(" --help display this help and exit");
74 puts(" --version output version information and exit");
78 int
79 main(int argc, char **argv)
81 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
82 WMPropList *all_windows, *iconset, *keylist;
83 char *path;
84 int i;
87 ProgName = argv[0];
89 for (i = 1; i < argc; i++) {
90 if (strcmp(argv[i], "-h")==0
91 || strcmp(argv[i], "--help")==0) {
92 print_help();
93 exit(0);
94 } else if (strcmp(argv[i], "--version")==0) {
95 puts(PROG_VERSION);
96 exit(0);
100 path = defaultsPathForDomain("WMWindowAttributes");
102 all_windows = WMReadPropListFromFile(path);
103 if (!all_windows) {
104 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
105 ProgName, path);
106 exit(1);
109 iconset = WMCreatePLDictionary(NULL, NULL, NULL);
111 keylist = WMGetPLDictionaryKeys(all_windows);
112 icon_key = WMCreatePLString("Icon");
114 for (i=0; i<WMGetPropListItemCount(keylist); i++) {
115 WMPropList *icondic;
117 window_name = WMGetFromPLArray(keylist, i);
118 if (!WMIsPLString(window_name))
119 continue;
121 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
122 if (window_attrs && WMIsPLDictionary(window_attrs)) {
123 icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
124 if (icon_value) {
126 icondic = WMCreatePLDictionary(icon_key, icon_value,
127 NULL);
129 WMPutInPLDictionary(iconset, window_name, icondic);
135 if (argc==2) {
136 WMWritePropListToFile(iconset, argv[1], False);
137 } else {
138 puts(WMGetPropListDescription(iconset, True));
140 exit(0);