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
[] = {
70 /* table of theme related options */
71 static char *theme_options
[] = {
81 char *PixmapPath
= NULL
;
83 char *ThemePath
= NULL
;
89 printf("usage: %s [-options] [<style file>]\n", ProgName
);
91 puts(" -h print help");
92 puts(" -t get theme options too");
93 puts(" -p produce a theme pack");
98 defaultsPathForDomain(char *domain
)
103 gspath
= getenv("GNUSTEP_USER_ROOT");
105 strcpy(path
, gspath
);
110 home
= getenv("HOME");
112 printf("%s:could not get HOME environment variable!\n", ProgName
);
116 strcat(path
, "/GNUstep/");
118 strcat(path
, DEFAULTS_DIR
);
120 strcat(path
, domain
);
122 tmp
= malloc(strlen(path
)+2);
130 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
134 str1
= PLGetString(pl1
);
135 str2
= PLGetString(pl2
);
137 if (strcasecmp(str1
, str2
)==0)
145 abortar(char *reason
)
149 printf("%s: %s\n", ProgName
, reason
);
152 printf("Removing unfinished theme pack\n");
153 sprintf(buffer
, "/bin/rm -fr %s", ThemePath
);
155 if (system(buffer
)!=0) {
156 printf("%s: could not execute command %s\n", ProgName
, buffer
);
168 char *home
= getenv("HOME");
174 user
= getpwuid(getuid());
178 sprintf(buffer
, "could not get password entry for UID %i", getuid());
197 abortar("out of memory");
209 tmp
= wmalloc(strlen(str
)+1);
218 getuserhomedir(char *username
)
222 user
= getpwnam(username
);
226 sprintf(buffer
,"could not get password entry for user %s", username
);
241 wexpandpath(char *path
)
243 char buffer2
[PATH_MAX
+2];
244 char buffer
[PATH_MAX
+2];
247 memset(buffer
, 0, PATH_MAX
+2);
253 if (*path
=='/' || *path
==0) {
254 home
= wgethomedir();
255 strcat(buffer
, home
);
259 while (*path
!=0 && *path
!='/') {
260 buffer2
[j
++] = *path
;
264 home
= getuserhomedir(buffer2
);
267 strcat(buffer
, home
);
279 /* expand $(HOME) or $HOME style environment variables */
282 while (*path
!=0 && *path
!=')') {
283 buffer2
[j
++] = *(path
++);
288 tmp
= getenv(buffer2
);
291 strcat(buffer
, "$(");
292 strcat(buffer
, buffer2
);
294 i
+= strlen(buffer2
)+3;
300 while (*path
!=0 && *path
!='/') {
301 buffer2
[j
++] = *(path
++);
304 tmp
= getenv(buffer2
);
307 strcat(buffer
, buffer2
);
308 i
+= strlen(buffer2
)+1;
320 return wstrdup(buffer
);
326 wfindfileinarray(proplist_t paths
, char *file
)
336 if (*file
=='/' || *file
=='~' || !paths
|| !PLIsArray(paths
)
337 || PLGetNumberOfElements(paths
)==0) {
338 if (access(file
, R_OK
)<0) {
339 fullpath
= wexpandpath(file
);
343 if (access(fullpath
, R_OK
)<0) {
350 return wstrdup(file
);
355 for (i
=0; i
< PLGetNumberOfElements(paths
); i
++) {
359 tmp
= PLGetArrayElement(paths
, i
);
360 if (!PLIsString(tmp
) || !(dir
= PLGetString(tmp
)))
364 path
= wmalloc(len
+flen
+2);
365 path
= memcpy(path
, dir
, len
);
370 fullpath
= wexpandpath(path
);
373 /* check if file is readable */
374 if (access(fullpath
, R_OK
)==0) {
387 copyFile(char *dir
, char *file
)
391 sprintf(buffer
, "/bin/cp %s %s", file
, dir
);
392 if (system(buffer
)!=0) {
393 printf("%s: could not copy file %s\n", ProgName
, file
);
399 findCopyFile(char *dir
, char *file
)
403 fullPath
= wfindfileinarray(PixmapPath
, file
);
404 copyFile(dir
, fullPath
);
410 makeThemePack(proplist_t style
, char *themeName
)
418 themeDir
= wmalloc(strlen(themeName
)+50);
419 sprintf(themeDir
, "%s.themed", themeName
);
420 ThemePath
= themeDir
;
424 tmp
= wmalloc(strlen(themeDir
)+20);
425 sprintf(tmp
, "/bin/mkdir %s", themeDir
);
426 if (system(tmp
)!=0) {
427 printf("%s: could not create directory %s\n", ProgName
, themeDir
);
432 keys
= PLGetAllDictionaryKeys(style
);
434 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
435 key
= PLGetArrayElement(keys
, i
);
437 value
= PLGetDictionaryEntry(style
, key
);
438 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
442 type
= PLGetArrayElement(value
, 0);
443 t
= PLGetString(type
);
444 if (t
&& (strcasecmp(t
, "tpixmap")==0
445 || strcasecmp(t
, "spixmap")==0
446 || strcasecmp(t
, "cpixmap")==0
447 || strcasecmp(t
, "tdgradient")==0
448 || strcasecmp(t
, "tvgradient")==0
449 || strcasecmp(t
, "thgradient")==0)) {
454 file
= PLGetArrayElement(value
, 1);
456 p
= strrchr(PLGetString(file
), '/');
458 copyFile(themeDir
, PLGetString(file
));
460 newPath
= wstrdup(p
+1);
461 PLRemoveArrayElement(value
, 1);
462 PLInsertArrayElement(value
, PLMakeString(newPath
), 1);
465 findCopyFile(themeDir
, PLGetString(file
));
476 main(int argc
, char **argv
)
478 proplist_t prop
, style
, key
, val
;
482 char *style_file
= NULL
;
488 for (i
=1; i
<argc
; i
++) {
489 if (strcmp(argv
[i
], "-p")==0) {
492 } else if (strcmp(argv
[i
], "-t")==0) {
494 } else if (argv
[i
][0] != '-') {
495 style_file
= argv
[i
];
503 if (make_pack
&& !style_file
) {
504 printf("%s: you must supply a name for the theme pack\n", ProgName
);
508 PLSetStringCmpHook(StringCompareHook
);
510 path
= defaultsPathForDomain("WindowMaker");
512 prop
= PLGetProplistWithPath(path
);
514 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
519 style
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
522 for (i
=0; options
[i
]!=NULL
; i
++) {
523 key
= PLMakeString(options
[i
]);
525 val
= PLGetDictionaryEntry(prop
, key
);
527 PLInsertDictionaryEntry(style
, key
, val
);
530 val
= PLGetDictionaryEntry(prop
, PLMakeString("PixmapPath"));
531 PixmapPath
= PLGetString(val
);
534 for (i
=0; theme_options
[i
]!=NULL
; i
++) {
535 key
= PLMakeString(theme_options
[i
]);
537 val
= PLGetDictionaryEntry(prop
, key
);
539 PLInsertDictionaryEntry(style
, key
, val
);
547 makeThemePack(style
, style_file
);
549 path
= wmalloc(strlen(ThemePath
)+32);
550 strcpy(path
, ThemePath
);
551 strcat(path
, "/style");
552 PLSetFilename(style
, PLMakeString(path
));
556 val
= PLMakeString(style_file
);
557 PLSetFilename(style
, val
);
560 puts(PLGetDescriptionIndent(style
, 0));