1 /* geticonset.c - outputs icon configuration from WindowMaker to stdout
3 * Window Maker window manager
5 * Copyright (c) 1997-2003 Alfredo K. Kojima
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #define _GNU_SOURCE /* getopt_long */
33 #ifdef HAVE_STDNORETURN
34 #include <stdnoreturn.h>
37 #include <WINGs/WUtil.h>
39 #include "../src/wconfig.h"
41 static const char *prog_name
;
43 static noreturn
void print_help(int print_usage
, int exitval
)
45 printf("Usage: %s [-h] [-v] [file]\n", prog_name
);
47 puts("Retrieves program icon configuration and output to FILE or to stdout");
49 puts(" -h, --help display this help and exit");
50 puts(" -v, --version output version information and exit");
55 int main(int argc
, char **argv
)
57 WMPropList
*window_name
, *icon_key
, *window_attrs
, *icon_value
;
58 WMPropList
*all_windows
, *iconset
, *keylist
;
62 struct option longopts
[] = {
63 { "version", no_argument
, NULL
, 'v' },
64 { "help", no_argument
, NULL
, 'h' },
69 while ((ch
= getopt_long(argc
, argv
, "hv", longopts
, NULL
)) != -1)
72 printf("%s (Window Maker %s)\n", prog_name
, VERSION
);
88 path
= wdefaultspathfordomain("WMWindowAttributes");
90 all_windows
= WMReadPropListFromFile(path
);
92 printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name
, path
);
96 iconset
= WMCreatePLDictionary(NULL
, NULL
);
98 keylist
= WMGetPLDictionaryKeys(all_windows
);
99 icon_key
= WMCreatePLString("Icon");
101 for (i
= 0; i
< WMGetPropListItemCount(keylist
); i
++) {
104 window_name
= WMGetFromPLArray(keylist
, i
);
105 if (!WMIsPLString(window_name
))
108 window_attrs
= WMGetFromPLDictionary(all_windows
, window_name
);
109 if (window_attrs
&& WMIsPLDictionary(window_attrs
)) {
110 icon_value
= WMGetFromPLDictionary(window_attrs
, icon_key
);
112 icondic
= WMCreatePLDictionary(icon_key
, icon_value
, NULL
);
113 WMPutInPLDictionary(iconset
, window_name
, icondic
);
119 WMWritePropListToFile(iconset
, argv
[0]);
121 puts(WMGetPropListDescription(iconset
, True
));