Initial revision
[wmaker-crm.git] / util / getstyle.c
blob53b2159d00b8f5334919fc11d5463c69089764f7
1 /* getstyle.c - outputs style related options from WindowMaker to stdout
3 * WindowMaker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
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.
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <proplist.h>
27 #include <string.h>
29 #include "../src/wconfig.h"
31 /* table of style related options */
32 static char *options[] = {
33 "TitleJustify",
34 "WindowTitleFont",
35 "MenuTitleFont",
36 "MenuTextFont",
37 "IconTitleFont",
38 "ClipTitleFont",
39 "DisplayFont",
40 "HighlightColor",
41 "HighlightTextColor",
42 "ClipTitleColor",
43 "CClipTitleColor",
44 "FTitleColor",
45 "PTitleColor",
46 "UTitleColor",
47 "FTitleBack",
48 "PTitleBack",
49 "UTitleBack",
50 "MenuTitleColor",
51 "MenuTextColor",
52 "MenuDisabledColor",
53 "MenuTitleBack",
54 "MenuTextBack",
55 "IconBack",
56 NULL
60 /* table of theme related options */
61 static char *theme_options[] = {
62 "WorkspaceBack",
63 NULL
69 char *ProgName;
72 void
73 print_help()
75 printf("usage: %s [-options] [<style file>]\n", ProgName);
76 puts("options:");
77 puts(" -h print help");
78 puts(" -t get theme options too");
82 char*
83 defaultsPathForDomain(char *domain)
85 char path[1024];
86 char *gspath, *tmp;
88 gspath = getenv("GNUSTEP_USER_ROOT");
89 if (gspath) {
90 strcpy(path, gspath);
91 strcat(path, "/");
92 } else {
93 char *home;
95 home = getenv("HOME");
96 if (!home) {
97 printf("%s:could not get HOME environment variable!\n", ProgName);
98 exit(0);
100 strcpy(path, home);
101 strcat(path, "/GNUstep/");
103 strcat(path, DEFAULTS_DIR);
104 strcat(path, "/");
105 strcat(path, domain);
107 tmp = malloc(strlen(path)+2);
108 strcpy(tmp, path);
110 return tmp;
114 int
115 main(int argc, char **argv)
117 proplist_t prop, style, key, val;
118 char *path;
119 int i, theme_too=0;
120 char *style_file = NULL;
123 ProgName = argv[0];
125 if (argc>1) {
126 for (i=1; i<argc; i++) {
127 if (strcmp(argv[i], "-t")==0) {
128 theme_too++;;
129 } else if (argv[i][0] != '-') {
130 style_file = argv[i];
131 } else {
132 print_help();
133 exit(1);
138 path = defaultsPathForDomain("WindowMaker");
140 prop = PLGetProplistWithPath(path);
141 if (!prop) {
142 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
143 ProgName, path);
144 exit(1);
147 style = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
150 for (i=0; options[i]!=NULL; i++) {
151 key = PLMakeString(options[i]);
153 val = PLGetDictionaryEntry(prop, key);
154 if (val)
155 PLInsertDictionaryEntry(style, key, val);
158 if (theme_too) {
159 for (i=0; theme_options[i]!=NULL; i++) {
160 key = PLMakeString(theme_options[i]);
162 val = PLGetDictionaryEntry(prop, key);
163 if (val)
164 PLInsertDictionaryEntry(style, key, val);
168 if (style_file) {
169 val = PLMakeString(style_file);
170 PLSetFilename(style, val);
171 PLSave(style, NO);
172 } else {
173 puts(PLGetDescriptionIndent(style, 0));
175 exit(0);