Ignore:
Timestamp:
May 18, 2006, 9:56:54 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Elite trick in the font generator to cope with C89's string length limitation of 509 characters. Instead of doing:

char foo[10] = "abcdefghij";

we now do:

struct { char f1[4], f2[4], f3[2]; } foo = { "abcd", "efgh", "ij" };

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/tools/makefont.c

    r948 r960  
    3434#include <pango/pangoft2.h>
    3535
     36/* Split our big strings into chunks of 480 characters, because it is
     37 * the multiple of 32 directly below 509, which is the maximum allowed
     38 * string size in C89. */
     39#define STRING_CHUNKS 480
     40
    3641/* This list is built so that it includes all of ASCII, Latin-1, CP-437,
    3742 * and the UTF-8 glyphs necessary for canvas rotation and mirroring. */
    38 static int const blocklist[] =
     43static unsigned int const blocklist[] =
    3944{
    4045    0x0000, 0x0080, /* Basic latin: A, B, C, a, b, c */
     
    7075static int printf_u16(char const *, uint16_t);
    7176
     77/* Counter for written bytes */
     78static int written = 0;
     79
    7280int main(int argc, char *argv[])
    7381{
     
    7987
    8088    FT_Bitmap img;
    81     int width, height, b, i, blocks, glyphs;
    82     unsigned int n, index, glyph_size, control_size, data_size;
     89    int width, height, blocks, glyphs;
     90    unsigned int n, b, i, index, glyph_size, control_size, data_size;
    8391    uint8_t *glyph_data;
    8492    struct glyph *gtab;
     
    166174    printf("static unsigned int const %s_size = %i;\n",
    167175           prefix, 8 + control_size + data_size);
    168     printf("static unsigned char const %s_data[] =\n", prefix);
     176    printf("static struct {\n");
     177    printf("char ");
     178    for(i = 0; (i + 1) * STRING_CHUNKS < 8 + control_size + data_size; i++)
     179        printf("d%x[%i],%c", i, STRING_CHUNKS, (i % 6) == 5 ? '\n' : ' ');
     180    printf("d%x[%i];\n", i, 8 + control_size + data_size - i * STRING_CHUNKS);
     181    printf("} %s_data = {\n", prefix);
     182    printf("\n");
    169183
    170184    printf("/* file: */\n");
    171185    printf("\"CACA\" /* caca_header */\n");
     186    written += 4;
    172187    printf("\"FONT\" /* caca_file_type */\n");
     188    written += 4;
    173189    printf("\n");
    174190
     
    291307    }
    292308
    293     printf(";\n");
     309    printf("};\n");
    294310
    295311    free(img.buffer);
     
    414430    {
    415431        uint8_t ch = *data++;
     432
     433        if(written == STRING_CHUNKS)
     434        {
     435            parser += sprintf(parser, "\", \"");
     436            written = 0;
     437            rewind = 0;
     438        }
     439
    416440        if(ch == '\\' || ch == '"')
    417441        {
     
    431455            rewind = ch ? 0 : 2;
    432456        }
     457
     458        written++;
    433459    }
    434460
Note: See TracChangeset for help on using the changeset viewer.