Vincent Béron : Add an error() function to fnt2fon and sfnt2fnt.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Dec 7 06:38:11 CST 2005


Module: wine
Branch: refs/heads/master
Commit: 2e5da5f4214b075e85e4e26b21f418b34c60e179
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=2e5da5f4214b075e85e4e26b21f418b34c60e179

Author: Vincent Béron <vberon at mecano.gme.usherb.ca>
Date:   Wed Dec  7 12:44:17 2005 +0100

Add an error() function to fnt2fon and sfnt2fnt.

---

 tools/fnt2fon.c  |   20 ++++++++++++++++++--
 tools/sfnt2fnt.c |   47 +++++++++++++++++++++++++++--------------------
 2 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/tools/fnt2fon.c b/tools/fnt2fon.c
index 77a1f31..88c93ad 100644
--- a/tools/fnt2fon.c
+++ b/tools/fnt2fon.c
@@ -61,6 +61,23 @@ static void usage(char **argv)
     return;
 }
 
+#ifndef __GNUC__
+#define __attribute__(X)
+#endif
+
+static void error(const char *s, ...) __attribute__((format (printf, 1, 2)));
+
+static void error(const char *s, ...)
+{
+	va_list ap;
+	va_start(ap, s);
+	fprintf(stderr, "Error: ");
+	vfprintf(stderr, s, ap);
+	fprintf(stderr, "\n");
+	va_end(ap);
+	exit(1);
+}
+
 int main(int argc, char **argv)
 {
     int i, j;
@@ -99,8 +116,7 @@ int main(int argc, char **argv)
         }
         fread(&ver, sizeof(short), 1, fp);
         if(ver != 0x200 && ver != 0x300) {
-            fprintf(stderr, "invalid fnt file %s ver %d\n", argv[i+1], ver);
-            exit(1);
+            error("invalid fnt file %s ver %d", argv[i+1], ver);
         }
         fread(file_lens + i, sizeof(int), 1, fp);
         fseek(fp, 0x44, SEEK_SET);
diff --git a/tools/sfnt2fnt.c b/tools/sfnt2fnt.c
index 974f222..4d894e6 100644
--- a/tools/sfnt2fnt.c
+++ b/tools/sfnt2fnt.c
@@ -61,6 +61,23 @@ static void usage(char **argv)
     return;
 }
 
+#ifndef __GNUC__
+#define __attribute__(X)
+#endif
+
+static void error(const char *s, ...) __attribute__((format (printf, 1, 2)));
+
+static void error(const char *s, ...)
+{
+    va_list ap;
+    va_start(ap, s);
+    fprintf(stderr, "Error: ");
+    vfprintf(stderr, s, ap);
+    fprintf(stderr, "\n");
+    va_end(ap);
+    exit(1);
+}
+
 static int lookup_charset(int enc)
 {
     /* FIXME: make winelib app and use TranslateCharsetInfo */
@@ -130,33 +147,25 @@ static void fill_fontinfo(FT_Face face, 
     FT_SfntName sfntname;
     TT_OS2 *os2;
     cptable = wine_cp_get_table(enc);
-    if(!cptable) {
-        fprintf(stderr, "Can't find codepage %d\n", enc);
-        exit(1);
-    }
+    if(!cptable)
+        error("Can't find codepage %d\n", enc);
 
     if(cptable->info.char_size != 1) {
         /* for double byte charsets we actually want to use cp1252 */
         cptable = wine_cp_get_table(1252);
-        if(!cptable) {
-            fprintf(stderr, "Can't find codepage 1252\n");
-            exit(1);
-        }
+        if(!cptable)
+            error("Can't find codepage 1252\n");
     }
 
     ppem = face->size->metrics.y_ppem;
     start = sizeof(FNT_HEADER) + sizeof(FONTINFO16);
 
-    if(FT_Load_Char(face, 0xc5, FT_LOAD_DEFAULT)) {
-        fprintf(stderr, "Can't find Aring\n");
-        exit(1);
-    }
+    if(FT_Load_Char(face, 0xc5, FT_LOAD_DEFAULT))
+        error("Can't find Aring\n");
     ascent = face->glyph->metrics.height >> 6;
     descent = ppem - ascent;
-    if(FT_Load_Char(face, 'M', FT_LOAD_DEFAULT)) {
-        fprintf(stderr, "Can't find M\n");
-        exit(1);
-    }
+    if(FT_Load_Char(face, 'M', FT_LOAD_DEFAULT))
+        error("Can't find M\n");
     il = ascent - (face->glyph->metrics.height >> 6);
 
     /* Hack: Courier has no internal leading, nor do any Chinese fonts */
@@ -344,10 +353,8 @@ int main(int argc, char **argv)
     def_char = atoi(argv[5]);
     avg_width = atoi(argv[6]);
 
-    if(FT_Init_FreeType(&lib)) {
-        fprintf(stderr, "ft init failure\n");
-        exit(1);
-    }
+    if(FT_Init_FreeType(&lib))
+        error("ft init failure\n");
 
     if(FT_New_Face(lib, argv[1], 0, &face)) {
         fprintf(stderr, "Can't open face\n");




More information about the wine-cvs mailing list