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,
24 #define PROG_VERSION "getstyle (Window Maker) 0.3"
42 #include "../src/wconfig.h"
44 /* table of style related options */
45 static char *options
[] = {
73 #ifdef TITLE_TEXT_SHADOW
84 /* table of theme related options */
85 static char *theme_options
[] = {
95 proplist_t PixmapPath
= NULL
;
97 char *ThemePath
= NULL
;
103 printf("Usage: %s [OPTIONS] [FILE]\n", ProgName
);
104 puts("Retrieves style/theme configuration and output to FILE or to stdout");
106 puts(" -t, --theme-options output theme related options when producing a style file");
107 puts(" -p, --pack produce output as a theme pack");
108 puts(" --help display this help and exit");
109 puts(" --version output version information and exit");
114 globalDefaultsPathForDomain(char *domain
)
119 sprintf(path
, "%s/%s", SYSCONFDIR
, domain
);
121 tmp
= malloc(strlen(path
)+2);
130 defaultsPathForDomain(char *domain
)
135 gspath
= getenv("GNUSTEP_USER_ROOT");
137 strcpy(path
, gspath
);
142 home
= getenv("HOME");
144 printf("%s:could not get HOME environment variable!\n", ProgName
);
148 strcat(path
, "/GNUstep/");
150 strcat(path
, DEFAULTS_DIR
);
152 strcat(path
, domain
);
154 tmp
= malloc(strlen(path
)+2);
162 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
166 str1
= PLGetString(pl1
);
167 str2
= PLGetString(pl2
);
169 if (strcasecmp(str1
, str2
)==0)
177 abortar(char *reason
)
181 printf("%s: %s\n", ProgName
, reason
);
184 printf("Removing unfinished theme pack\n");
185 sprintf(buffer
, "/bin/rm -fr %s", ThemePath
);
187 if (system(buffer
)!=0) {
188 printf("%s: could not execute command %s\n", ProgName
, buffer
);
200 char *home
= getenv("HOME");
206 user
= getpwuid(getuid());
210 sprintf(buffer
, "could not get password entry for UID %i", getuid());
229 abortar("out of memory");
241 tmp
= wmalloc(strlen(str
)+1);
250 getuserhomedir(char *username
)
254 user
= getpwnam(username
);
258 sprintf(buffer
,"could not get password entry for user %s", username
);
273 wexpandpath(char *path
)
275 char buffer2
[PATH_MAX
+2];
276 char buffer
[PATH_MAX
+2];
279 memset(buffer
, 0, PATH_MAX
+2);
285 if (*path
=='/' || *path
==0) {
286 home
= wgethomedir();
287 strcat(buffer
, home
);
291 while (*path
!=0 && *path
!='/') {
292 buffer2
[j
++] = *path
;
296 home
= getuserhomedir(buffer2
);
299 strcat(buffer
, home
);
311 /* expand $(HOME) or $HOME style environment variables */
314 while (*path
!=0 && *path
!=')') {
315 buffer2
[j
++] = *(path
++);
320 tmp
= getenv(buffer2
);
323 strcat(buffer
, "$(");
324 strcat(buffer
, buffer2
);
326 i
+= strlen(buffer2
)+3;
332 while (*path
!=0 && *path
!='/') {
333 buffer2
[j
++] = *(path
++);
336 tmp
= getenv(buffer2
);
339 strcat(buffer
, buffer2
);
340 i
+= strlen(buffer2
)+1;
352 return wstrdup(buffer
);
358 wfindfileinarray(proplist_t paths
, char *file
)
368 if (*file
=='/' || *file
=='~' || !paths
|| !PLIsArray(paths
)
369 || PLGetNumberOfElements(paths
)==0) {
370 if (access(file
, R_OK
)<0) {
371 fullpath
= wexpandpath(file
);
375 if (access(fullpath
, R_OK
)<0) {
382 return wstrdup(file
);
387 for (i
=0; i
< PLGetNumberOfElements(paths
); i
++) {
391 tmp
= PLGetArrayElement(paths
, i
);
392 if (!PLIsString(tmp
) || !(dir
= PLGetString(tmp
)))
396 path
= wmalloc(len
+flen
+2);
397 path
= memcpy(path
, dir
, len
);
402 fullpath
= wexpandpath(path
);
405 /* check if file is readable */
406 if (access(fullpath
, R_OK
)==0) {
419 copyFile(char *dir
, char *file
)
423 sprintf(buffer
, "/bin/cp %s %s", file
, dir
);
424 if (system(buffer
)!=0) {
425 printf("%s: could not copy file %s\n", ProgName
, file
);
431 findCopyFile(char *dir
, char *file
)
435 fullPath
= wfindfileinarray(PixmapPath
, file
);
439 sprintf(buffer
, "coould not find file %s", file
);
442 copyFile(dir
, fullPath
);
448 makeThemePack(proplist_t style
, char *themeName
)
456 themeDir
= wmalloc(strlen(themeName
)+50);
457 sprintf(themeDir
, "%s.themed", themeName
);
458 ThemePath
= themeDir
;
462 tmp
= wmalloc(strlen(themeDir
)+20);
463 sprintf(tmp
, "/bin/mkdir %s", themeDir
);
464 if (system(tmp
)!=0) {
465 printf("%s: could not create directory %s. Probably there's already a theme with that name in this directory.\n", ProgName
, themeDir
);
470 keys
= PLGetAllDictionaryKeys(style
);
472 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
473 key
= PLGetArrayElement(keys
, i
);
475 value
= PLGetDictionaryEntry(style
, key
);
476 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
480 type
= PLGetArrayElement(value
, 0);
481 t
= PLGetString(type
);
482 if (t
&& (strcasecmp(t
, "tpixmap")==0
483 || strcasecmp(t
, "spixmap")==0
484 || strcasecmp(t
, "cpixmap")==0
485 || strcasecmp(t
, "mpixmap")==0
486 || strcasecmp(t
, "tdgradient")==0
487 || strcasecmp(t
, "tvgradient")==0
488 || strcasecmp(t
, "thgradient")==0)) {
493 file
= PLGetArrayElement(value
, 1);
495 p
= strrchr(PLGetString(file
), '/');
497 copyFile(themeDir
, PLGetString(file
));
499 newPath
= wstrdup(p
+1);
500 PLRemoveArrayElement(value
, 1);
501 PLInsertArrayElement(value
, PLMakeString(newPath
), 1);
504 findCopyFile(themeDir
, PLGetString(file
));
515 main(int argc
, char **argv
)
517 proplist_t prop
, style
, key
, val
;
521 char *style_file
= NULL
;
527 for (i
=1; i
<argc
; i
++) {
528 if (strcmp(argv
[i
], "-p")==0
529 || strcmp(argv
[i
], "--pack")==0) {
532 } else if (strcmp(argv
[i
], "-t")==0
533 || strcmp(argv
[i
], "--theme-options")==0) {
535 } else if (strcmp(argv
[i
], "--help")==0) {
538 } else if (strcmp(argv
[i
], "--version")==0) {
542 if (style_file
!=NULL
) {
543 printf("%s: invalid argument '%s'\n", argv
[0],
544 style_file
[0]=='-' ? style_file
: argv
[i
]);
545 printf("Try '%s --help' for more information\n", argv
[0]);
548 style_file
= argv
[i
];
553 if (make_pack
&& !style_file
) {
554 printf("%s: you must supply a name for the theme pack\n", ProgName
);
558 PLSetStringCmpHook(StringCompareHook
);
560 path
= defaultsPathForDomain("WindowMaker");
562 prop
= PLGetProplistWithPath(path
);
564 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
570 /* get global value */
571 path
= globalDefaultsPathForDomain("WindowMaker");
572 val
= PLGetProplistWithPath(path
);
574 PLMergeDictionaries(val
, prop
);
579 style
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
582 for (i
=0; options
[i
]!=NULL
; i
++) {
583 key
= PLMakeString(options
[i
]);
585 val
= PLGetDictionaryEntry(prop
, key
);
587 PLInsertDictionaryEntry(style
, key
, val
);
590 val
= PLGetDictionaryEntry(prop
, PLMakeString("PixmapPath"));
595 for (i
=0; theme_options
[i
]!=NULL
; i
++) {
596 key
= PLMakeString(theme_options
[i
]);
598 val
= PLGetDictionaryEntry(prop
, key
);
600 PLInsertDictionaryEntry(style
, key
, val
);
607 makeThemePack(style
, style_file
);
609 path
= wmalloc(strlen(ThemePath
)+32);
610 strcpy(path
, ThemePath
);
611 strcat(path
, "/style");
612 PLSetFilename(style
, PLMakeString(path
));
616 val
= PLMakeString(style_file
);
617 PLSetFilename(style
, val
);
620 puts(PLGetDescriptionIndent(style
, 0));