Make ProgName a local variable
[wmaker-crm.git] / util / geticonset.c
blob6ebac813f615982666c96f3a82c92455829f1c2a
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.
22 #ifdef __GLIBC__
23 #define _GNU_SOURCE /* getopt_long */
24 #endif
26 #include <getopt.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
31 #include <WINGs/WUtil.h>
33 #include "../src/wconfig.h"
35 extern char *__progname;
37 void print_help(int print_usage, int exitval)
39 printf("Usage: %s [-h] [-v] [file]\n", __progname);
40 if (print_usage) {
41 puts("Retrieves program icon configuration and output to FILE or to stdout");
42 puts("");
43 puts(" -h, --help display this help and exit");
44 puts(" -v, --version output version information and exit");
46 exit(exitval);
49 int main(int argc, char **argv)
51 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
52 WMPropList *all_windows, *iconset, *keylist;
53 char *path;
54 int i, ch;
56 struct option longopts[] = {
57 { "version", no_argument, NULL, 'v' },
58 { "help", no_argument, NULL, 'h' },
59 { NULL, 0, NULL, 0 }
62 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
63 switch(ch) {
64 case 'v':
65 printf("%s (Window Maker %s)\n", __progname, VERSION);
66 return 0;
67 /* NOTREACHED */
68 case 'h':
69 print_help(1, 0);
70 /* NOTREACHED */
71 case 0:
72 break;
73 default:
74 print_help(0, 1);
75 /* NOTREACHED */
78 argc -= optind;
79 argv += optind;
81 path = wdefaultspathfordomain("WMWindowAttributes");
83 all_windows = WMReadPropListFromFile(path);
84 if (!all_windows) {
85 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
86 return 1;
89 iconset = WMCreatePLDictionary(NULL, NULL);
91 keylist = WMGetPLDictionaryKeys(all_windows);
92 icon_key = WMCreatePLString("Icon");
94 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
95 WMPropList *icondic;
97 window_name = WMGetFromPLArray(keylist, i);
98 if (!WMIsPLString(window_name))
99 continue;
101 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
102 if (window_attrs && WMIsPLDictionary(window_attrs)) {
103 icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
104 if (icon_value) {
105 icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
106 WMPutInPLDictionary(iconset, window_name, icondic);
111 if (argc == 1) {
112 WMWritePropListToFile(iconset, argv[0]);
113 } else {
114 puts(WMGetPropListDescription(iconset, True));
116 return 0;