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"
42 #include "../src/wconfig.h"
44 /* table of style related options */
45 static char *options
[] = {
71 #ifdef TITLE_TEXT_SHADOW
81 /* table of theme related options */
82 static char *theme_options
[] = {
92 proplist_t PixmapPath
= NULL
;
94 char *ThemePath
= NULL
;
100 printf("Usage: %s [OPTIONS] [FILE]\n", ProgName
);
101 puts("Retrieves style/theme configuration and output to FILE or to stdout");
103 puts(" -t, --theme-options output theme related options when producing a style file");
104 puts(" -p, --pack produce output as a theme pack");
105 puts(" --help display this help and exit");
106 puts(" --version output version information and exit");
111 globalDefaultsPathForDomain(char *domain
)
116 sprintf(path
, "%s/%s", SYSCONFDIR
, domain
);
118 tmp
= malloc(strlen(path
)+2);
127 defaultsPathForDomain(char *domain
)
132 gspath
= getenv("GNUSTEP_USER_ROOT");
134 strcpy(path
, gspath
);
139 home
= getenv("HOME");
141 printf("%s:could not get HOME environment variable!\n", ProgName
);
145 strcat(path
, "/GNUstep/");
147 strcat(path
, DEFAULTS_DIR
);
149 strcat(path
, domain
);
151 tmp
= malloc(strlen(path
)+2);
159 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
163 str1
= PLGetString(pl1
);
164 str2
= PLGetString(pl2
);
166 if (strcasecmp(str1
, str2
)==0)
174 abortar(char *reason
)
178 printf("%s: %s\n", ProgName
, reason
);
181 printf("Removing unfinished theme pack\n");
182 sprintf(buffer
, "/bin/rm -fr %s", ThemePath
);
184 if (system(buffer
)!=0) {
185 printf("%s: could not execute command %s\n", ProgName
, buffer
);
197 char *home
= getenv("HOME");
203 user
= getpwuid(getuid());
207 sprintf(buffer
, "could not get password entry for UID %i", getuid());
226 abortar("out of memory");
238 tmp
= wmalloc(strlen(str
)+1);
247 getuserhomedir(char *username
)
251 user
= getpwnam(username
);
255 sprintf(buffer
,"could not get password entry for user %s", username
);
270 wexpandpath(char *path
)
272 char buffer2
[PATH_MAX
+2];
273 char buffer
[PATH_MAX
+2];
276 memset(buffer
, 0, PATH_MAX
+2);
282 if (*path
=='/' || *path
==0) {
283 home
= wgethomedir();
284 strcat(buffer
, home
);
288 while (*path
!=0 && *path
!='/') {
289 buffer2
[j
++] = *path
;
293 home
= getuserhomedir(buffer2
);
296 strcat(buffer
, home
);
308 /* expand $(HOME) or $HOME style environment variables */
311 while (*path
!=0 && *path
!=')') {
312 buffer2
[j
++] = *(path
++);
317 tmp
= getenv(buffer2
);
320 strcat(buffer
, "$(");
321 strcat(buffer
, buffer2
);
323 i
+= strlen(buffer2
)+3;
329 while (*path
!=0 && *path
!='/') {
330 buffer2
[j
++] = *(path
++);
333 tmp
= getenv(buffer2
);
336 strcat(buffer
, buffer2
);
337 i
+= strlen(buffer2
)+1;
349 return wstrdup(buffer
);
355 wfindfileinarray(proplist_t paths
, char *file
)
365 if (*file
=='/' || *file
=='~' || !paths
|| !PLIsArray(paths
)
366 || PLGetNumberOfElements(paths
)==0) {
367 if (access(file
, R_OK
)<0) {
368 fullpath
= wexpandpath(file
);
372 if (access(fullpath
, R_OK
)<0) {
379 return wstrdup(file
);
384 for (i
=0; i
< PLGetNumberOfElements(paths
); i
++) {
388 tmp
= PLGetArrayElement(paths
, i
);
389 if (!PLIsString(tmp
) || !(dir
= PLGetString(tmp
)))
393 path
= wmalloc(len
+flen
+2);
394 path
= memcpy(path
, dir
, len
);
399 fullpath
= wexpandpath(path
);
402 /* check if file is readable */
403 if (access(fullpath
, R_OK
)==0) {
416 copyFile(char *dir
, char *file
)
420 sprintf(buffer
, "/bin/cp %s %s", file
, dir
);
421 if (system(buffer
)!=0) {
422 printf("%s: could not copy file %s\n", ProgName
, file
);
428 findCopyFile(char *dir
, char *file
)
432 fullPath
= wfindfileinarray(PixmapPath
, file
);
436 sprintf(buffer
, "coould not find file %s", file
);
439 copyFile(dir
, fullPath
);
445 makeThemePack(proplist_t style
, char *themeName
)
453 themeDir
= wmalloc(strlen(themeName
)+50);
454 sprintf(themeDir
, "%s.themed", themeName
);
455 ThemePath
= themeDir
;
459 tmp
= wmalloc(strlen(themeDir
)+20);
460 sprintf(tmp
, "/bin/mkdir %s", themeDir
);
461 if (system(tmp
)!=0) {
462 printf("%s: could not create directory %s\n", ProgName
, themeDir
);
467 keys
= PLGetAllDictionaryKeys(style
);
469 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
470 key
= PLGetArrayElement(keys
, i
);
472 value
= PLGetDictionaryEntry(style
, key
);
473 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
477 type
= PLGetArrayElement(value
, 0);
478 t
= PLGetString(type
);
479 if (t
&& (strcasecmp(t
, "tpixmap")==0
480 || strcasecmp(t
, "spixmap")==0
481 || strcasecmp(t
, "cpixmap")==0
482 || strcasecmp(t
, "mpixmap")==0
483 || strcasecmp(t
, "tdgradient")==0
484 || strcasecmp(t
, "tvgradient")==0
485 || strcasecmp(t
, "thgradient")==0)) {
490 file
= PLGetArrayElement(value
, 1);
492 p
= strrchr(PLGetString(file
), '/');
494 copyFile(themeDir
, PLGetString(file
));
496 newPath
= wstrdup(p
+1);
497 PLRemoveArrayElement(value
, 1);
498 PLInsertArrayElement(value
, PLMakeString(newPath
), 1);
501 findCopyFile(themeDir
, PLGetString(file
));
512 main(int argc
, char **argv
)
514 proplist_t prop
, style
, key
, val
;
518 char *style_file
= NULL
;
524 for (i
=1; i
<argc
; i
++) {
525 if (strcmp(argv
[i
], "-p")==0
526 || strcmp(argv
[i
], "--pack")==0) {
529 } else if (strcmp(argv
[i
], "-t")==0
530 || strcmp(argv
[i
], "--theme-options")==0) {
532 } else if (strcmp(argv
[i
], "--help")==0) {
535 } else if (strcmp(argv
[i
], "--version")==0) {
539 if (style_file
!=NULL
) {
540 printf("%s: invalid argument '%s'\n", argv
[0],
541 style_file
[0]=='-' ? style_file
: argv
[i
]);
542 printf("Try '%s --help' for more information\n", argv
[0]);
545 style_file
= argv
[i
];
550 if (make_pack
&& !style_file
) {
551 printf("%s: you must supply a name for the theme pack\n", ProgName
);
555 PLSetStringCmpHook(StringCompareHook
);
557 path
= defaultsPathForDomain("WindowMaker");
559 prop
= PLGetProplistWithPath(path
);
561 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
567 /* get global value */
568 path
= globalDefaultsPathForDomain("WindowMaker");
569 val
= PLGetProplistWithPath(path
);
571 PLMergeDictionaries(val
, prop
);
576 style
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
579 for (i
=0; options
[i
]!=NULL
; i
++) {
580 key
= PLMakeString(options
[i
]);
582 val
= PLGetDictionaryEntry(prop
, key
);
584 PLInsertDictionaryEntry(style
, key
, val
);
587 val
= PLGetDictionaryEntry(prop
, PLMakeString("PixmapPath"));
592 for (i
=0; theme_options
[i
]!=NULL
; i
++) {
593 key
= PLMakeString(theme_options
[i
]);
595 val
= PLGetDictionaryEntry(prop
, key
);
597 PLInsertDictionaryEntry(style
, key
, val
);
604 makeThemePack(style
, style_file
);
606 path
= wmalloc(strlen(ThemePath
)+32);
607 strcpy(path
, ThemePath
);
608 strcat(path
, "/style");
609 PLSetFilename(style
, PLMakeString(path
));
613 val
= PLMakeString(style_file
);
614 PLSetFilename(style
, val
);
617 puts(PLGetDescriptionIndent(style
, 0));