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.2"
41 #include "../src/wconfig.h"
43 /* table of style related options */
44 static char *options
[] = {
70 #ifdef TITLE_TEXT_SHADOW
80 /* table of theme related options */
81 static char *theme_options
[] = {
91 proplist_t PixmapPath
= NULL
;
93 char *ThemePath
= NULL
;
99 printf("Usage: %s [OPTIONS] [FILE]\n", ProgName
);
100 puts("Retrieves style/theme configuration and output to FILE or to stdout");
102 puts(" -t, --theme-options output theme related options when producing a style file");
103 puts(" -p, --pack produce output as a theme pack");
104 puts(" --help display this help and exit");
105 puts(" --version output version information and exit");
110 globalDefaultsPathForDomain(char *domain
)
115 sprintf(path
, "%s/%s/%s", PKGDATADIR
, DEFAULTS_DIR
, domain
);
117 tmp
= malloc(strlen(path
)+2);
125 defaultsPathForDomain(char *domain
)
130 gspath
= getenv("GNUSTEP_USER_ROOT");
132 strcpy(path
, gspath
);
137 home
= getenv("HOME");
139 printf("%s:could not get HOME environment variable!\n", ProgName
);
143 strcat(path
, "/GNUstep/");
145 strcat(path
, DEFAULTS_DIR
);
147 strcat(path
, domain
);
149 tmp
= malloc(strlen(path
)+2);
157 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
161 str1
= PLGetString(pl1
);
162 str2
= PLGetString(pl2
);
164 if (strcasecmp(str1
, str2
)==0)
172 abortar(char *reason
)
176 printf("%s: %s\n", ProgName
, reason
);
179 printf("Removing unfinished theme pack\n");
180 sprintf(buffer
, "/bin/rm -fr %s", ThemePath
);
182 if (system(buffer
)!=0) {
183 printf("%s: could not execute command %s\n", ProgName
, buffer
);
195 char *home
= getenv("HOME");
201 user
= getpwuid(getuid());
205 sprintf(buffer
, "could not get password entry for UID %i", getuid());
224 abortar("out of memory");
236 tmp
= wmalloc(strlen(str
)+1);
245 getuserhomedir(char *username
)
249 user
= getpwnam(username
);
253 sprintf(buffer
,"could not get password entry for user %s", username
);
268 wexpandpath(char *path
)
270 char buffer2
[PATH_MAX
+2];
271 char buffer
[PATH_MAX
+2];
274 memset(buffer
, 0, PATH_MAX
+2);
280 if (*path
=='/' || *path
==0) {
281 home
= wgethomedir();
282 strcat(buffer
, home
);
286 while (*path
!=0 && *path
!='/') {
287 buffer2
[j
++] = *path
;
291 home
= getuserhomedir(buffer2
);
294 strcat(buffer
, home
);
306 /* expand $(HOME) or $HOME style environment variables */
309 while (*path
!=0 && *path
!=')') {
310 buffer2
[j
++] = *(path
++);
315 tmp
= getenv(buffer2
);
318 strcat(buffer
, "$(");
319 strcat(buffer
, buffer2
);
321 i
+= strlen(buffer2
)+3;
327 while (*path
!=0 && *path
!='/') {
328 buffer2
[j
++] = *(path
++);
331 tmp
= getenv(buffer2
);
334 strcat(buffer
, buffer2
);
335 i
+= strlen(buffer2
)+1;
347 return wstrdup(buffer
);
353 wfindfileinarray(proplist_t paths
, char *file
)
363 if (*file
=='/' || *file
=='~' || !paths
|| !PLIsArray(paths
)
364 || PLGetNumberOfElements(paths
)==0) {
365 if (access(file
, R_OK
)<0) {
366 fullpath
= wexpandpath(file
);
370 if (access(fullpath
, R_OK
)<0) {
377 return wstrdup(file
);
382 for (i
=0; i
< PLGetNumberOfElements(paths
); i
++) {
386 tmp
= PLGetArrayElement(paths
, i
);
387 if (!PLIsString(tmp
) || !(dir
= PLGetString(tmp
)))
391 path
= wmalloc(len
+flen
+2);
392 path
= memcpy(path
, dir
, len
);
397 fullpath
= wexpandpath(path
);
400 /* check if file is readable */
401 if (access(fullpath
, R_OK
)==0) {
414 copyFile(char *dir
, char *file
)
418 sprintf(buffer
, "/bin/cp %s %s", file
, dir
);
419 if (system(buffer
)!=0) {
420 printf("%s: could not copy file %s\n", ProgName
, file
);
426 findCopyFile(char *dir
, char *file
)
430 fullPath
= wfindfileinarray(PixmapPath
, file
);
434 sprintf(buffer
, "coould not find file %s", file
);
437 copyFile(dir
, fullPath
);
443 makeThemePack(proplist_t style
, char *themeName
)
451 themeDir
= wmalloc(strlen(themeName
)+50);
452 sprintf(themeDir
, "%s.themed", themeName
);
453 ThemePath
= themeDir
;
457 tmp
= wmalloc(strlen(themeDir
)+20);
458 sprintf(tmp
, "/bin/mkdir %s", themeDir
);
459 if (system(tmp
)!=0) {
460 printf("%s: could not create directory %s\n", ProgName
, themeDir
);
465 keys
= PLGetAllDictionaryKeys(style
);
467 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
468 key
= PLGetArrayElement(keys
, i
);
470 value
= PLGetDictionaryEntry(style
, key
);
471 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
475 type
= PLGetArrayElement(value
, 0);
476 t
= PLGetString(type
);
477 if (t
&& (strcasecmp(t
, "tpixmap")==0
478 || strcasecmp(t
, "spixmap")==0
479 || strcasecmp(t
, "cpixmap")==0
480 || strcasecmp(t
, "mpixmap")==0
481 || strcasecmp(t
, "tdgradient")==0
482 || strcasecmp(t
, "tvgradient")==0
483 || strcasecmp(t
, "thgradient")==0)) {
488 file
= PLGetArrayElement(value
, 1);
490 p
= strrchr(PLGetString(file
), '/');
492 copyFile(themeDir
, PLGetString(file
));
494 newPath
= wstrdup(p
+1);
495 PLRemoveArrayElement(value
, 1);
496 PLInsertArrayElement(value
, PLMakeString(newPath
), 1);
499 findCopyFile(themeDir
, PLGetString(file
));
510 main(int argc
, char **argv
)
512 proplist_t prop
, style
, key
, val
;
516 char *style_file
= NULL
;
522 for (i
=1; i
<argc
; i
++) {
523 if (strcmp(argv
[i
], "-p")==0
524 || strcmp(argv
[i
], "--pack")==0) {
527 } else if (strcmp(argv
[i
], "-t")==0
528 || strcmp(argv
[i
], "--theme-options")==0) {
530 } else if (strcmp(argv
[i
], "--help")==0) {
533 } else if (strcmp(argv
[i
], "--version")==0) {
537 style_file
= argv
[i
];
542 if (make_pack
&& !style_file
) {
543 printf("%s: you must supply a name for the theme pack\n", ProgName
);
547 PLSetStringCmpHook(StringCompareHook
);
549 path
= defaultsPathForDomain("WindowMaker");
551 prop
= PLGetProplistWithPath(path
);
553 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
559 /* get global value */
560 path
= globalDefaultsPathForDomain("WindowMaker");
561 val
= PLGetProplistWithPath(path
);
563 PLMergeDictionaries(val
, prop
);
568 style
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
571 for (i
=0; options
[i
]!=NULL
; i
++) {
572 key
= PLMakeString(options
[i
]);
574 val
= PLGetDictionaryEntry(prop
, key
);
576 PLInsertDictionaryEntry(style
, key
, val
);
579 val
= PLGetDictionaryEntry(prop
, PLMakeString("PixmapPath"));
584 for (i
=0; theme_options
[i
]!=NULL
; i
++) {
585 key
= PLMakeString(theme_options
[i
]);
587 val
= PLGetDictionaryEntry(prop
, key
);
589 PLInsertDictionaryEntry(style
, key
, val
);
596 makeThemePack(style
, style_file
);
598 path
= wmalloc(strlen(ThemePath
)+32);
599 strcpy(path
, ThemePath
);
600 strcat(path
, "/style");
601 PLSetFilename(style
, PLMakeString(path
));
605 val
= PLMakeString(style_file
);
606 PLSetFilename(style
, val
);
609 puts(PLGetDescriptionIndent(style
, 0));