Idle fixes
[wmaker-crm.git] / util / geticonset.c
blobe21994b051c03dcb6d18314b5172ec97e65ba976
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
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"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
29 #include <WINGs/WUtil.h>
31 #include "../src/wconfig.h"
33 extern char *__progname;
35 void print_help()
37 printf("Usage: %s [OPTIONS] [FILE]\n", __progname);
38 puts("Retrieves program icon configuration and output to FILE or to stdout");
39 puts("");
40 puts(" -h, --help display this help and exit");
41 puts(" -v, --version output version information and exit");
44 int main(int argc, char **argv)
46 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
47 WMPropList *all_windows, *iconset, *keylist;
48 char *path;
49 int i;
51 for (i = 1; i < argc; i++) {
52 if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
53 print_help();
54 exit(0);
55 } else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
56 puts(PROG_VERSION);
57 exit(0);
61 path = wdefaultspathfordomain("WMWindowAttributes");
63 all_windows = WMReadPropListFromFile(path);
64 if (!all_windows) {
65 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
66 exit(1);
69 iconset = WMCreatePLDictionary(NULL, NULL);
71 keylist = WMGetPLDictionaryKeys(all_windows);
72 icon_key = WMCreatePLString("Icon");
74 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
75 WMPropList *icondic;
77 window_name = WMGetFromPLArray(keylist, i);
78 if (!WMIsPLString(window_name))
79 continue;
81 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
82 if (window_attrs && WMIsPLDictionary(window_attrs)) {
83 icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
84 if (icon_value) {
85 icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
86 WMPutInPLDictionary(iconset, window_name, icondic);
91 if (argc == 2) {
92 WMWritePropListToFile(iconset, argv[1]);
93 } else {
94 puts(WMGetPropListDescription(iconset, True));
96 exit(0);