Change to the linux kernel coding style
[wmaker-crm.git] / util / geticonset.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* geticonset.c - outputs icon configuration from WindowMaker to stdout
2 *
931a37b1 dan1999-01-29 08:11:17 +00003 * Window Maker window manager
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1997-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * 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.
11 *
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.
16 *
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
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
931a37b1 dan1999-01-29 08:11:17 +000023#define PROG_VERSION "geticonset (Window Maker) 0.1"
24
9d2e6ef9 scottc1998-09-29 22:36:29 +000025#include <stdlib.h>
26#include <stdio.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000027#include <string.h>
28
33cc542e dan2001-10-04 03:07:34 +000029#include <WINGs/WUtil.h>
30
9d2e6ef9 scottc1998-09-29 22:36:29 +000031#include "../src/wconfig.h"
32
9d2e6ef9 scottc1998-09-29 22:36:29 +000033char *ProgName;
34
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020035char *defaultsPathForDomain(char *domain)
9d2e6ef9 scottc1998-09-29 22:36:29 +000036{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020037 static char path[1024];
38 char *gspath;
39
40 gspath = getenv("GNUSTEP_USER_ROOT");
41 if (gspath) {
42 strcpy(path, gspath);
43 strcat(path, "/");
44 } else {
45 char *home;
46
47 home = getenv("HOME");
48 if (!home) {
49 printf("%s:could not get HOME environment variable!\n", ProgName);
50 exit(0);
51 }
52 strcpy(path, home);
53 strcat(path, "/GNUstep/");
54 }
55 strcat(path, DEFAULTS_DIR);
56 strcat(path, "/");
57 strcat(path, domain);
58
59 return path;
9d2e6ef9 scottc1998-09-29 22:36:29 +000060}
61
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020062void print_help()
931a37b1 dan1999-01-29 08:11:17 +000063{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020064 printf("Usage: %s [OPTIONS] [FILE]\n", ProgName);
65 puts("Retrieves program icon configuration and output to FILE or to stdout");
66 puts("");
67 puts(" --help display this help and exit");
68 puts(" --version output version information and exit");
931a37b1 dan1999-01-29 08:11:17 +000069}
70
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020071int main(int argc, char **argv)
9d2e6ef9 scottc1998-09-29 22:36:29 +000072{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020073 WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
74 WMPropList *all_windows, *iconset, *keylist;
75 char *path;
76 int i;
77
78 ProgName = argv[0];
79
80 for (i = 1; i < argc; i++) {
81 if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
82 print_help();
83 exit(0);
84 } else if (strcmp(argv[i], "--version") == 0) {
85 puts(PROG_VERSION);
86 exit(0);
87 }
88 }
89
90 path = defaultsPathForDomain("WMWindowAttributes");
91
92 all_windows = WMReadPropListFromFile(path);
93 if (!all_windows) {
94 printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path);
95 exit(1);
96 }
97
98 iconset = WMCreatePLDictionary(NULL, NULL);
99
100 keylist = WMGetPLDictionaryKeys(all_windows);
101 icon_key = WMCreatePLString("Icon");
102
103 for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
104 WMPropList *icondic;
105
106 window_name = WMGetFromPLArray(keylist, i);
107 if (!WMIsPLString(window_name))
108 continue;
109
110 window_attrs = WMGetFromPLDictionary(all_windows, window_name);
111 if (window_attrs && WMIsPLDictionary(window_attrs)) {
112 icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
113 if (icon_value) {
114 icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
115 WMPutInPLDictionary(iconset, window_name, icondic);
116 }
117 }
118 }
119
120 if (argc == 2) {
121 WMWritePropListToFile(iconset, argv[1], False);
122 } else {
123 puts(WMGetPropListDescription(iconset, True));
124 }
125 exit(0);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000126}