1 /* getstyle.c - outputs style related options from WindowMaker to stdout
3 * WindowMaker window manager
5 * Copyright (c) 1997, 1998 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,
37 #include "../src/wconfig.h"
39 /* table of style related options */
40 static char *options
[] = {
66 #ifdef TITLE_TEXT_SHADOW
76 /* table of theme related options */
77 static char *theme_options
[] = {
87 char *PixmapPath
= NULL
;
89 char *ThemePath
= NULL
;
95 printf("usage: %s [-options] [<style file>]\n", ProgName
);
97 puts(" -h print help");
98 puts(" -t get theme options too");
99 puts(" -p produce a theme pack");
104 globalDefaultsPathForDomain(char *domain
)
109 sprintf(path
, "%s/%s/%s", PKGDATADIR
, DEFAULTS_DIR
, domain
);
111 tmp
= malloc(strlen(path
)+2);
119 defaultsPathForDomain(char *domain
)
124 gspath
= getenv("GNUSTEP_USER_ROOT");
126 strcpy(path
, gspath
);
131 home
= getenv("HOME");
133 printf("%s:could not get HOME environment variable!\n", ProgName
);
137 strcat(path
, "/GNUstep/");
139 strcat(path
, DEFAULTS_DIR
);
141 strcat(path
, domain
);
143 tmp
= malloc(strlen(path
)+2);
151 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
155 str1
= PLGetString(pl1
);
156 str2
= PLGetString(pl2
);
158 if (strcasecmp(str1
, str2
)==0)
166 abortar(char *reason
)
170 printf("%s: %s\n", ProgName
, reason
);
173 printf("Removing unfinished theme pack\n");
174 sprintf(buffer
, "/bin/rm -fr %s", ThemePath
);
176 if (system(buffer
)!=0) {
177 printf("%s: could not execute command %s\n", ProgName
, buffer
);
189 char *home
= getenv("HOME");
195 user
= getpwuid(getuid());
199 sprintf(buffer
, "could not get password entry for UID %i", getuid());
218 abortar("out of memory");
230 tmp
= wmalloc(strlen(str
)+1);
239 getuserhomedir(char *username
)
243 user
= getpwnam(username
);
247 sprintf(buffer
,"could not get password entry for user %s", username
);
262 wexpandpath(char *path
)
264 char buffer2
[PATH_MAX
+2];
265 char buffer
[PATH_MAX
+2];
268 memset(buffer
, 0, PATH_MAX
+2);
274 if (*path
=='/' || *path
==0) {
275 home
= wgethomedir();
276 strcat(buffer
, home
);
280 while (*path
!=0 && *path
!='/') {
281 buffer2
[j
++] = *path
;
285 home
= getuserhomedir(buffer2
);
288 strcat(buffer
, home
);
300 /* expand $(HOME) or $HOME style environment variables */
303 while (*path
!=0 && *path
!=')') {
304 buffer2
[j
++] = *(path
++);
309 tmp
= getenv(buffer2
);
312 strcat(buffer
, "$(");
313 strcat(buffer
, buffer2
);
315 i
+= strlen(buffer2
)+3;
321 while (*path
!=0 && *path
!='/') {
322 buffer2
[j
++] = *(path
++);
325 tmp
= getenv(buffer2
);
328 strcat(buffer
, buffer2
);
329 i
+= strlen(buffer2
)+1;
341 return wstrdup(buffer
);
347 wfindfileinarray(proplist_t paths
, char *file
)
357 if (*file
=='/' || *file
=='~' || !paths
|| !PLIsArray(paths
)
358 || PLGetNumberOfElements(paths
)==0) {
359 if (access(file
, R_OK
)<0) {
360 fullpath
= wexpandpath(file
);
364 if (access(fullpath
, R_OK
)<0) {
371 return wstrdup(file
);
376 for (i
=0; i
< PLGetNumberOfElements(paths
); i
++) {
380 tmp
= PLGetArrayElement(paths
, i
);
381 if (!PLIsString(tmp
) || !(dir
= PLGetString(tmp
)))
385 path
= wmalloc(len
+flen
+2);
386 path
= memcpy(path
, dir
, len
);
391 fullpath
= wexpandpath(path
);
394 /* check if file is readable */
395 if (access(fullpath
, R_OK
)==0) {
408 copyFile(char *dir
, char *file
)
412 sprintf(buffer
, "/bin/cp %s %s", file
, dir
);
413 if (system(buffer
)!=0) {
414 printf("%s: could not copy file %s\n", ProgName
, file
);
420 findCopyFile(char *dir
, char *file
)
424 fullPath
= wfindfileinarray(PixmapPath
, file
);
428 sprintf(buffer
, "coould not find file %s", file
);
431 copyFile(dir
, fullPath
);
437 makeThemePack(proplist_t style
, char *themeName
)
445 themeDir
= wmalloc(strlen(themeName
)+50);
446 sprintf(themeDir
, "%s.themed", themeName
);
447 ThemePath
= themeDir
;
451 tmp
= wmalloc(strlen(themeDir
)+20);
452 sprintf(tmp
, "/bin/mkdir %s", themeDir
);
453 if (system(tmp
)!=0) {
454 printf("%s: could not create directory %s\n", ProgName
, themeDir
);
459 keys
= PLGetAllDictionaryKeys(style
);
461 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
462 key
= PLGetArrayElement(keys
, i
);
464 value
= PLGetDictionaryEntry(style
, key
);
465 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
469 type
= PLGetArrayElement(value
, 0);
470 t
= PLGetString(type
);
471 if (t
&& (strcasecmp(t
, "tpixmap")==0
472 || strcasecmp(t
, "spixmap")==0
473 || strcasecmp(t
, "cpixmap")==0
474 || strcasecmp(t
, "mpixmap")==0
475 || strcasecmp(t
, "tdgradient")==0
476 || strcasecmp(t
, "tvgradient")==0
477 || strcasecmp(t
, "thgradient")==0)) {
482 file
= PLGetArrayElement(value
, 1);
484 p
= strrchr(PLGetString(file
), '/');
486 copyFile(themeDir
, PLGetString(file
));
488 newPath
= wstrdup(p
+1);
489 PLRemoveArrayElement(value
, 1);
490 PLInsertArrayElement(value
, PLMakeString(newPath
), 1);
493 findCopyFile(themeDir
, PLGetString(file
));
504 main(int argc
, char **argv
)
506 proplist_t prop
, style
, key
, val
;
510 char *style_file
= NULL
;
516 for (i
=1; i
<argc
; i
++) {
517 if (strcmp(argv
[i
], "-p")==0) {
520 } else if (strcmp(argv
[i
], "-t")==0) {
522 } else if (argv
[i
][0] != '-') {
523 style_file
= argv
[i
];
531 if (make_pack
&& !style_file
) {
532 printf("%s: you must supply a name for the theme pack\n", ProgName
);
536 PLSetStringCmpHook(StringCompareHook
);
538 path
= defaultsPathForDomain("WindowMaker");
540 prop
= PLGetProplistWithPath(path
);
542 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
548 /* get global value */
549 path
= globalDefaultsPathForDomain("WindowMaker");
550 val
= PLGetProplistWithPath(path
);
552 PLMergeDictionaries(val
, prop
);
557 style
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
560 for (i
=0; options
[i
]!=NULL
; i
++) {
561 key
= PLMakeString(options
[i
]);
563 val
= PLGetDictionaryEntry(prop
, key
);
565 PLInsertDictionaryEntry(style
, key
, val
);
568 val
= PLGetDictionaryEntry(prop
, PLMakeString("PixmapPath"));
570 PixmapPath
= PLGetString(val
);
573 for (i
=0; theme_options
[i
]!=NULL
; i
++) {
574 key
= PLMakeString(theme_options
[i
]);
576 val
= PLGetDictionaryEntry(prop
, key
);
578 PLInsertDictionaryEntry(style
, key
, val
);
585 makeThemePack(style
, style_file
);
587 path
= wmalloc(strlen(ThemePath
)+32);
588 strcpy(path
, ThemePath
);
589 strcat(path
, "/style");
590 PLSetFilename(style
, PLMakeString(path
));
594 val
= PLMakeString(style_file
);
595 PLSetFilename(style
, val
);
598 puts(PLGetDescriptionIndent(style
, 0));