From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/OR_PRACTICAL_C/fonts.c | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 reference/C/CONTRIB/OR_PRACTICAL_C/fonts.c (limited to 'reference/C/CONTRIB/OR_PRACTICAL_C/fonts.c') diff --git a/reference/C/CONTRIB/OR_PRACTICAL_C/fonts.c b/reference/C/CONTRIB/OR_PRACTICAL_C/fonts.c new file mode 100644 index 0000000..61f1496 --- /dev/null +++ b/reference/C/CONTRIB/OR_PRACTICAL_C/fonts.c @@ -0,0 +1,65 @@ +/******************************************************** + * fonts -- handle font-related data structures * + * * + * Functions * + * load_fonts -- load a font file * + ********************************************************/ +#include +#include "gen.h" +#include "symbol.h" +#include +#include + +/* the top of the symbol table */ +struct symbol *font_symbol_ptr = NULL; +/******************************************************** + * load_fonts -- load fonts into symbol table * + * * + * Parameters * + * file_name -- filename of file to load * + * * + * Aborts on error. * + ********************************************************/ +void load_fonts(char *file_name) +{ + FILE *in_file; /* Input file */ + char name[3]; /* Name of the current font */ + /* We have to point to something for our data */ + static char *an_object = "an object"; + + in_file = fopen(file_name, "r"); + if (in_file == NULL) { + (void) fprintf(stderr, "Error:Can't open %s for reading\n", file_name); + exit(8); + } + + while (1) { + char line[80]; /* Input line from data file */ + char *cur_char; /* Pointer to current input character */ + + if (fgets(line, sizeof(line), in_file) == NULL) { + (void) fclose(in_file); + return; + } + cur_char = line; + + while (*cur_char != '\0') { + SKIP_WHITESPACE(cur_char); + + if (*cur_char == '\0') + break; + + /* Copy two-character macro name */ + name[0] = *cur_char; + cur_char++; + if (*cur_char > ' ') { + name[1] = *cur_char; + cur_char++; + name[2] = '\0'; + } else + name[1] = '\0'; + + enter(&font_symbol_ptr, name, (generic *) an_object); + } + } +} -- cgit v1.2.3-54-g00ecf