Idle fixes
[wmaker-crm.git] / util / convertfonts.c
blob2aa79c7556038bedafd1a4b3a7a9eae380e6b1fb
1 /* convertfonts.c - converts fonts in a style file to fontconfig format
3 * WindowMaker window manager
5 * Copyright (c) 2004 Dan Pascu
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,
20 * USA.
23 #define PROG_VERSION "convertfonts (Window Maker) 1.0"
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <sys/stat.h>
28 #include <string.h>
29 #include <locale.h>
30 #include <WINGs/WUtil.h>
32 #include "../src/wconfig.h"
34 char *FontOptions[] = {
35 "IconTitleFont",
36 "ClipTitleFont",
37 "DisplayFont",
38 "LargeDisplayFont",
39 "MenuTextFont",
40 "MenuTitleFont",
41 "WindowTitleFont",
42 "SystemFont",
43 "BoldSystemFont",
44 NULL
47 extern char *__progname;
49 extern char *convertFont(char *font, Bool keepXLFD);
51 void print_help()
53 printf("\nUsage: %s <style_file>\n\n", __progname);
54 puts("Converts fonts in a style file into fontconfig format");
55 puts("");
56 puts(" -h, --help display this help and exit");
57 puts(" -v, --version output version information and exit");
58 puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
59 puts(" to the font name. This property is not used by the fontconfig");
60 puts(" matching engine to find the font, but it is useful as a hint");
61 puts(" about what the original font was to allow hand tuning the");
62 puts(" result or restoring the xlfd. The default is to not add it");
63 puts(" as it results in long, unreadable and confusing names.");
64 puts("");
67 int main(int argc, char **argv)
69 WMPropList *style, *key, *val;
70 char *file = NULL, *oldfont, *newfont;
71 struct stat statbuf;
72 Bool keepXLFD = False;
73 int i;
75 if (argc < 2) {
76 print_help();
77 exit(0);
80 for (i = 1; i < argc; i++) {
81 if (strcmp("-v", argv[i]) == 0 || strcmp("--version", argv[i]) == 0) {
82 puts(PROG_VERSION);
83 exit(0);
84 } else if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
85 print_help();
86 exit(0);
87 } else if (strcmp("--keep-xlfd", argv[i]) == 0) {
88 keepXLFD = True;;
89 } else if (argv[i][0] == '-') {
90 printf("%s: invalid argument '%s'\n", __progname, argv[i]);
91 printf("Try '%s --help' for more information\n", __progname);
92 exit(1);
93 } else {
94 file = argv[i];
98 /* we need this in order for MB_CUR_MAX to work */
99 setlocale(LC_ALL, "");
101 WMPLSetCaseSensitive(False);
103 if (stat(file, &statbuf) < 0) {
104 perror(file);
105 exit(1);
108 style = WMReadPropListFromFile(file);
109 if (!style) {
110 perror(file);
111 printf("%s: could not load style file.\n", __progname);
112 exit(1);
115 if (!WMIsPLDictionary(style)) {
116 printf("%s: '%s' is not a well formatted style file\n", __progname, file);
117 exit(1);
120 for (i = 0; FontOptions[i] != NULL; i++) {
121 key = WMCreatePLString(FontOptions[i]);
122 val = WMGetFromPLDictionary(style, key);
123 if (val) {
124 oldfont = WMGetFromPLString(val);
125 newfont = convertFont(oldfont, keepXLFD);
126 if (oldfont != newfont) {
127 val = WMCreatePLString(newfont);
128 WMPutInPLDictionary(style, key, val);
129 WMReleasePropList(val);
130 wfree(newfont);
133 WMReleasePropList(key);
136 WMWritePropListToFile(style, file);
138 exit(0);