Menu translation support
[wmaker-crm.git] / util / geticonset.c
blobe8286cfcce5abbd271e3b8fe025232c7f0b1ff02
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 #ifdef __GLIBC__
24 #define _GNU_SOURCE /* getopt_long */
25 #endif
27 #include <getopt.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include <WINGs/WUtil.h>
34 #include "../src/wconfig.h"
36 extern char *__progname;
38 void print_help(int print_usage, int exitval)
40 printf("Usage: %s [-h] [-v] [file]\n", __progname);
41 if (print_usage) {
42 puts("Retrieves program icon configuration and output to FILE or to stdout");
43 puts("");
44 puts(" -h, --help display this help and exit");
45 puts(" -v, --version output version information and exit");
47 exit(exitval);
50 int main(int argc, char **argv)
52 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
53 WMPropList *all_windows, *iconset, *keylist;
54 char *path;
55 int i, ch;
57 struct option longopts[] = {
58 { "version", no_argument, NULL, 'v' },
59 { "help", no_argument, NULL, 'h' },
60 { NULL, 0, NULL, 0 }
63 while ((ch = getopt_long(argc, argv, "hv", longopts, NULL)) != -1)
64 switch(ch) {
65 case 'v':
66 printf("%s (Window Maker %s)\n", __progname, VERSION);
67 return 0;
68 /* NOTREACHED */
69 case 'h':
70 print_help(1, 0);
71 /* NOTREACHED */
72 case 0:
73 break;
74 default:
75 print_help(0, 1);
76 /* NOTREACHED */
79 argc -= optind;
80 argv += optind;
82 path = wdefaultspathfordomain("WMWindowAttributes");
84 all_windows = WMReadPropListFromFile(path);
85 if (!all_windows) {
86 printf("%s: could not load WindowMaker configuration file \"%s\".\n", __progname, path);
87 return 1;
90 iconset = WMCreatePLDictionary(NULL, NULL);
92 keylist = WMGetPLDictionaryKeys(all_windows);
93 icon_key = WMCreatePLString("Icon");
95 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
96 WMPropList *icondic;
98 window_name = WMGetFromPLArray(keylist, i);
99 if (!WMIsPLString(window_name))
100 continue;
102 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
103 if (window_attrs && WMIsPLDictionary(window_attrs)) {
104 icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
105 if (icon_value) {
106 icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
107 WMPutInPLDictionary(iconset, window_name, icondic);
112 if (argc == 1) {
113 WMWritePropListToFile(iconset, argv[0]);
114 } else {
115 puts(WMGetPropListDescription(iconset, True));
117 return 0;