1 /* getstyle.c - outputs style related options from WindowMaker to stdout
3 * WindowMaker window manager
5 * Copyright (c) 1997~2000 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.6"
42 #include "../src/wconfig.h"
44 /* table of style related options */
45 static char *options
[] = {
54 "WindowTitleExtendSpace",
55 "MenuTitleExtendSpace",
56 "MenuTextExtendSpace",
77 "WindowTitleExtendSpace",
78 "MenuTitleExtendSpace",
79 "MenuTextExtendSpace",
84 /* table of theme related options */
85 static char *theme_options
[] = {
91 "TopLeftResizeCursor",
92 "TopRightResizeCursor",
93 "BottomLeftResizeCursor",
94 "BottomRightResizeCursor",
95 "VerticalResizeCursor",
96 "HorizontalResizeCursor",
109 proplist_t PixmapPath
= NULL
;
111 char *ThemePath
= NULL
;
117 printf("Usage: %s [OPTIONS] [FILE]\n", ProgName
);
118 puts("Retrieves style/theme configuration and output to FILE or to stdout");
120 puts(" -t, --theme-options output theme related options when producing a style file");
121 puts(" -p, --pack produce output as a theme pack");
122 puts(" --help display this help and exit");
123 puts(" --version output version information and exit");
128 globalDefaultsPathForDomain(char *domain
)
130 static char path
[1024];
132 sprintf(path
, "%s/WindowMaker/%s", SYSCONFDIR
, domain
);
139 defaultsPathForDomain(char *domain
)
141 static char path
[1024];
144 gspath
= getenv("GNUSTEP_USER_ROOT");
146 strcpy(path
, gspath
);
151 home
= getenv("HOME");
153 printf("%s:could not get HOME environment variable!\n", ProgName
);
157 strcat(path
, "/GNUstep/");
159 strcat(path
, DEFAULTS_DIR
);
161 strcat(path
, domain
);
168 StringCompareHook(proplist_t pl1
, proplist_t pl2
)
172 str1
= PLGetString(pl1
);
173 str2
= PLGetString(pl2
);
175 if (strcasecmp(str1
, str2
)==0)
183 abortar(char *reason
)
187 printf("%s: %s\n", ProgName
, reason
);
190 printf("Removing unfinished theme pack\n");
191 sprintf(buffer
, "/bin/rm -fr \"%s\"", ThemePath
);
193 if (system(buffer
)!=0) {
194 printf("%s: could not execute command %s\n", ProgName
, buffer
);
206 char *home
= getenv("HOME");
212 user
= getpwuid(getuid());
216 sprintf(buffer
, "could not get password entry for UID %i", getuid());
235 abortar("out of memory");
247 tmp
= wmalloc(strlen(str
)+1);
256 getuserhomedir(char *username
)
260 user
= getpwnam(username
);
264 sprintf(buffer
,"could not get password entry for user %s", username
);
279 wexpandpath(char *path
)
281 char buffer2
[PATH_MAX
+2];
282 char buffer
[PATH_MAX
+2];
285 memset(buffer
, 0, PATH_MAX
+2);
291 if (*path
=='/' || *path
==0) {
292 home
= wgethomedir();
293 strcat(buffer
, home
);
297 while (*path
!=0 && *path
!='/') {
298 buffer2
[j
++] = *path
;
302 home
= getuserhomedir(buffer2
);
305 strcat(buffer
, home
);
317 /* expand $(HOME) or $HOME style environment variables */
320 while (*path
!=0 && *path
!=')') {
321 buffer2
[j
++] = *(path
++);
326 tmp
= getenv(buffer2
);
329 strcat(buffer
, "$(");
330 strcat(buffer
, buffer2
);
332 i
+= strlen(buffer2
)+3;
338 while (*path
!=0 && *path
!='/') {
339 buffer2
[j
++] = *(path
++);
342 tmp
= getenv(buffer2
);
345 strcat(buffer
, buffer2
);
346 i
+= strlen(buffer2
)+1;
358 return wstrdup(buffer
);
364 wfindfileinarray(proplist_t paths
, char *file
)
374 if (*file
=='/' || *file
=='~' || !paths
|| !PLIsArray(paths
)
375 || PLGetNumberOfElements(paths
)==0) {
376 if (access(file
, R_OK
)<0) {
377 fullpath
= wexpandpath(file
);
381 if (access(fullpath
, R_OK
)<0) {
388 return wstrdup(file
);
393 for (i
=0; i
< PLGetNumberOfElements(paths
); i
++) {
397 tmp
= PLGetArrayElement(paths
, i
);
398 if (!PLIsString(tmp
) || !(dir
= PLGetString(tmp
)))
402 path
= wmalloc(len
+flen
+2);
403 path
= memcpy(path
, dir
, len
);
408 fullpath
= wexpandpath(path
);
411 /* check if file is readable */
412 if (access(fullpath
, R_OK
)==0) {
425 copyFile(char *dir
, char *file
)
429 sprintf(buffer
, "/bin/cp \"%s\" \"%s\"", file
, dir
);
430 if (system(buffer
)!=0) {
431 printf("%s: could not copy file %s\n", ProgName
, file
);
437 findCopyFile(char *dir
, char *file
)
441 fullPath
= wfindfileinarray(PixmapPath
, file
);
445 sprintf(buffer
, "coould not find file %s", file
);
448 copyFile(dir
, fullPath
);
454 makeThemePack(proplist_t style
, char *themeName
)
462 themeDir
= wmalloc(strlen(themeName
)+50);
463 sprintf(themeDir
, "%s.themed", themeName
);
464 ThemePath
= themeDir
;
468 tmp
= wmalloc(strlen(themeDir
)+20);
469 sprintf(tmp
, "/bin/mkdir \"%s\"", themeDir
);
470 if (system(tmp
)!=0) {
471 printf("%s: could not create directory %s. Probably there's already a theme with that name in this directory.\n", ProgName
, themeDir
);
476 keys
= PLGetAllDictionaryKeys(style
);
478 for (i
= 0; i
< PLGetNumberOfElements(keys
); i
++) {
479 key
= PLGetArrayElement(keys
, i
);
481 value
= PLGetDictionaryEntry(style
, key
);
482 if (value
&& PLIsArray(value
) && PLGetNumberOfElements(value
) > 2) {
486 type
= PLGetArrayElement(value
, 0);
487 t
= PLGetString(type
);
491 if (strcasecmp(t
, "tpixmap")==0
492 || strcasecmp(t
, "spixmap")==0
493 || strcasecmp(t
, "cpixmap")==0
494 || strcasecmp(t
, "mpixmap")==0
495 || strcasecmp(t
, "tdgradient")==0
496 || strcasecmp(t
, "tvgradient")==0
497 || strcasecmp(t
, "thgradient")==0) {
502 file
= PLGetArrayElement(value
, 1);
504 p
= strrchr(PLGetString(file
), '/');
506 copyFile(themeDir
, PLGetString(file
));
508 newPath
= wstrdup(p
+1);
509 PLRemoveArrayElement(value
, 1);
510 PLInsertArrayElement(value
, PLMakeString(newPath
), 1);
513 findCopyFile(themeDir
, PLGetString(file
));
515 } else if (strcasecmp(t
, "bitmap")==0) {
520 file
= PLGetArrayElement(value
, 1);
522 p
= strrchr(PLGetString(file
), '/');
524 copyFile(themeDir
, PLGetString(file
));
526 newPath
= wstrdup(p
+1);
527 PLRemoveArrayElement(value
, 1);
528 PLInsertArrayElement(value
, PLMakeString(newPath
), 1);
531 findCopyFile(themeDir
, PLGetString(file
));
535 file
= PLGetArrayElement(value
, 2);
537 p
= strrchr(PLGetString(file
), '/');
539 copyFile(themeDir
, PLGetString(file
));
541 newPath
= wstrdup(p
+1);
542 PLRemoveArrayElement(value
, 2);
543 PLInsertArrayElement(value
, PLMakeString(newPath
), 2);
546 findCopyFile(themeDir
, PLGetString(file
));
557 main(int argc
, char **argv
)
559 proplist_t prop
, style
, key
, val
;
563 char *style_file
= NULL
;
569 for (i
=1; i
<argc
; i
++) {
570 if (strcmp(argv
[i
], "-p")==0
571 || strcmp(argv
[i
], "--pack")==0) {
574 } else if (strcmp(argv
[i
], "-t")==0
575 || strcmp(argv
[i
], "--theme-options")==0) {
577 } else if (strcmp(argv
[i
], "--help")==0) {
580 } else if (strcmp(argv
[i
], "--version")==0) {
584 if (style_file
!=NULL
) {
585 printf("%s: invalid argument '%s'\n", argv
[0],
586 style_file
[0]=='-' ? style_file
: argv
[i
]);
587 printf("Try '%s --help' for more information\n", argv
[0]);
590 style_file
= argv
[i
];
595 if (make_pack
&& !style_file
) {
596 printf("%s: you must supply a name for the theme pack\n", ProgName
);
600 PLSetStringCmpHook(StringCompareHook
);
602 path
= defaultsPathForDomain("WindowMaker");
604 prop
= PLGetProplistWithPath(path
);
606 printf("%s:could not load WindowMaker configuration file \"%s\".\n",
611 /* get global value */
612 path
= globalDefaultsPathForDomain("WindowMaker");
613 val
= PLGetProplistWithPath(path
);
615 PLMergeDictionaries(val
, prop
);
620 style
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
623 for (i
=0; options
[i
]!=NULL
; i
++) {
624 key
= PLMakeString(options
[i
]);
626 val
= PLGetDictionaryEntry(prop
, key
);
628 PLInsertDictionaryEntry(style
, key
, val
);
631 val
= PLGetDictionaryEntry(prop
, PLMakeString("PixmapPath"));
636 for (i
=0; theme_options
[i
]!=NULL
; i
++) {
637 key
= PLMakeString(theme_options
[i
]);
639 val
= PLGetDictionaryEntry(prop
, key
);
641 PLInsertDictionaryEntry(style
, key
, val
);
648 makeThemePack(style
, style_file
);
650 path
= wmalloc(strlen(ThemePath
)+32);
651 strcpy(path
, ThemePath
);
652 strcat(path
, "/style");
653 PLSetFilename(style
, PLMakeString(path
));
657 val
= PLMakeString(style_file
);
658 PLSetFilename(style
, val
);
661 puts(PLGetDescriptionIndent(style
, 0));