Appearance.c Removed fallthrough warning
[wmaker-crm.git] / util / geticonset.c
blob4505551ca1fb46b341d1928b14c67b6dbfa9024a
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 "config.h"
28 #include <getopt.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
33 #ifdef HAVE_STDNORETURN
34 #include <stdnoreturn.h>
35 #endif
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);
46 if (print_usage) {
47 puts("Retrieves program icon configuration and output to FILE or to stdout");
48 puts("");
49 puts(" -h, --help display this help and exit");
50 puts(" -v, --version output version information and exit");
52 exit(exitval);
55 int main(int argc, char **argv)
57 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
58 WMPropList *all_windows, *iconset, *keylist;
59 char *path;
60 int i, ch;
62 struct option longopts[] = {
63 { "version", no_argument, NULL, 'v' },
64 { "help", no_argument, NULL, 'h' },
65 { NULL, 0, NULL, 0 }
68 prog_name = argv[0];
69 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
70 switch(ch) {
71 case 'v':
72 printf("%s (Window Maker %s)\n", prog_name, VERSION);
73 return 0;
74 /* NOTREACHED */
75 case 'h':
76 print_help(1, 0);
77 /* NOTREACHED */
78 case 0:
79 break;
80 default:
81 print_help(0, 1);
82 /* NOTREACHED */
85 argc -= optind;
86 argv += optind;
88 path = wdefaultspathfordomain("WMWindowAttributes");
90 all_windows = WMReadPropListFromFile(path);
91 if (!all_windows) {
92 printf("%s: could not load WindowMaker configuration file \"%s\".\n", prog_name, path);
93 return 1;
96 iconset = WMCreatePLDictionary(NULL, NULL);
98 keylist = WMGetPLDictionaryKeys(all_windows);
99 icon_key = WMCreatePLString("Icon");
101 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
102 WMPropList *icondic;
104 window_name = WMGetFromPLArray(keylist, i);
105 if (!WMIsPLString(window_name))
106 continue;
108 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
109 if (window_attrs && WMIsPLDictionary(window_attrs)) {
110 icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
111 if (icon_value) {
112 icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
113 WMPutInPLDictionary(iconset, window_name, icondic);
118 if (argc == 1) {
119 WMWritePropListToFile(iconset, argv[0]);
120 } else {
121 puts(WMGetPropListDescription(iconset, True));
123 return 0;