summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-05-08 16:12:08 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-05-08 16:12:08 +0000
commitd0ad2e0bdb23789c261fe4d8636fb559f04c5f32 (patch)
treeccb56086cfef24caa20f4c31c80f31735ada65b7 /src
parentd89b9a1074ff2b8f7f9227d6e10a95808ef30129 (diff)
downloadttf2f-d0ad2e0bdb23789c261fe4d8636fb559f04c5f32.tar.gz
ttf2f-d0ad2e0bdb23789c261fe4d8636fb559f04c5f32.tar.bz2
More tidying
svn path=/trunk/tools/ttf2f/; revision=7446
Diffstat (limited to 'src')
-rw-r--r--src/cli.c10
-rw-r--r--src/glyph.h2
-rw-r--r--src/glyphs.c33
-rw-r--r--src/glyphs.h8
4 files changed, 27 insertions, 26 deletions
diff --git a/src/cli.c b/src/cli.c
index 1002a94..c21e759 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -27,8 +27,8 @@ int main(int argc, char **argv)
int fail;
ttf2f_result err = TTF2F_RESULT_OK;
int nglyphs;
- struct glyph *glist;
- struct font_metrics *metrics;
+ struct glyph *glist = NULL;
+ struct font_metrics *metrics = NULL;
if (argc != 3) {
fprintf(stderr, "Usage: %s <input.ttf> <output>\n", argv[0]);
@@ -36,7 +36,9 @@ int main(int argc, char **argv)
}
ft_init();
- load_glyph_list();
+
+ if ((err = glyph_load_list()) != TTF2F_RESULT_OK)
+ goto error_out;
fail = open_font(argv[1]);
if (fail) {
@@ -122,7 +124,7 @@ error_out:
close_font();
ft_fini();
- destroy_glyphs();
+ glyph_destroy_list();
exit(err == TTF2F_RESULT_OK ? EXIT_SUCCESS : EXIT_FAILURE);
}
diff --git a/src/glyph.h b/src/glyph.h
index fe91bc8..6a18b2d 100644
--- a/src/glyph.h
+++ b/src/glyph.h
@@ -24,7 +24,7 @@ struct composite {
struct glyph {
unsigned int code; /* glyph code */
- char *name; /* glyph name */
+ const char *name; /* glyph name */
int xMin:12, yMin:12;
int xMax:12, yMax:12; /* glyph control box */
int lsb; /* left side bearing of glyph,
diff --git a/src/glyphs.c b/src/glyphs.c
index f24cbd6..b66675b 100644
--- a/src/glyphs.c
+++ b/src/glyphs.c
@@ -10,9 +10,9 @@ struct glyph_entry {
struct glyph_entry *next;
};
-struct glyph_entry glyphs[256];
+static struct glyph_entry glyphs[256];
-void load_glyph_list(void)
+ttf2f_result glyph_load_list(void)
{
FILE *fp;
char line[1024];
@@ -24,10 +24,8 @@ void load_glyph_list(void)
#else
fp = fopen("Glyphs", "r");
#endif
- if (!fp) {
- fprintf(stderr, "Failed opening glyphs file\n");
- exit(255);
- }
+ if (fp == NULL)
+ return TTF2F_RESULT_OPEN;
while(fgets(line, 1024, fp)) {
/* skip comments & blank lines */
@@ -47,15 +45,15 @@ void load_glyph_list(void)
*semi = 0;
g = calloc(1, sizeof(struct glyph_entry));
- if (!g) {
- fprintf(stderr, "malloc failed\n");
- exit(255);
- }
+ if (g == NULL)
+ return TTF2F_RESULT_NOMEM;
g->code = (unsigned short)strtoul(line, NULL, 16);
g->name = strdup(name);
-
-// fprintf(stderr, "%04.4X: %s\n", g->code, g->name);
+ if (g->name == NULL) {
+ free(g);
+ return TTF2F_RESULT_NOMEM;
+ }
for (cur = &glyphs[g->code / 256];
cur->next && cur->code < g->code;
@@ -74,9 +72,11 @@ void load_glyph_list(void)
}
fclose(fp);
+
+ return TTF2F_RESULT_OK;
}
-char *glyph_name(unsigned short code)
+const char *glyph_name(unsigned short code)
{
struct glyph_entry *g;
@@ -84,13 +84,10 @@ char *glyph_name(unsigned short code)
if (g->code == code)
break;
- if (!g)
- return NULL;
-
- return g->name;
+ return g != NULL ? g->name : NULL;
}
-void destroy_glyphs(void)
+void glyph_destroy_list(void)
{
int i;
struct glyph_entry *a, *b;
diff --git a/src/glyphs.h b/src/glyphs.h
index 39c3426..5125f9e 100644
--- a/src/glyphs.h
+++ b/src/glyphs.h
@@ -1,8 +1,10 @@
#ifndef _TTF2F_GLYPHS_H_
#define _TTF2F_GLYPHS_H_
-void load_glyph_list(void);
-char *glyph_name(unsigned short code);
-void destroy_glyphs(void);
+#include "utils.h"
+
+ttf2f_result glyph_load_list(void);
+void glyph_destroy_list(void);
+const char *glyph_name(unsigned short code);
#endif