Changeset 1200


Ignore:
Timestamp:
Oct 13, 2006, 3:19:45 PM (17 years ago)
Author:
Sam Hocevar
Message:
  • Use fgets() instead of fscanf(). Uses an additional memory buffer, but paves the way for custom IO functions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • toilet/trunk/src/figlet.c

    r1196 r1200  
    120120    char *data = NULL;
    121121    char path[2048];
     122    char buf[2048];
    122123    char hardblank[10];
    123124    cucul_buffer_t *b;
     
    145146    cx->full_layout = 0;
    146147    cx->codetag_count = 0;
    147     if(fscanf(f, "%*[ft]lf2a%6s %u %u %u %i %u %u %u %u\n", hardblank,
     148    fgets(buf, 2048, f);
     149    if(sscanf(buf, "%*[ft]lf2a%6s %u %u %u %i %u %u %u %u\n", hardblank,
    148150              &cx->height, &cx->baseline, &cx->max_length,
    149151              &cx->old_layout, &comment_lines, &cx->print_direction,
     
    159161    /* Skip comment lines */
    160162    for(i = 0; i < comment_lines; i++)
    161     {
    162         fscanf(f, "%*[^\n]");
    163         fscanf(f, "%*c");
    164     }
     163        fgets(buf, 2048, f);
    165164
    166165    /* Read mandatory characters (32-127, 196, 214, 220, 228, 246, 252, 223)
     
    186185        else
    187186        {
    188             char number[10];
    189             int ret = fscanf(f, "%s %*[^\n]", number);
    190 
    191             if(ret == EOF)
     187            if(fgets(buf, 2048, f) == NULL)
    192188                break;
    193189
    194             if(!ret)
     190            if(!buf[0])
    195191            {
    196192                free(data);
     
    201197            }
    202198
    203             if(number[1] == 'x')
    204                 sscanf(number, "%x", &cx->lookup[cx->glyphs * 2]);
     199            if(buf[1] == 'x')
     200                sscanf(buf, "%x", &cx->lookup[cx->glyphs * 2]);
    205201            else
    206                 sscanf(number, "%u", &cx->lookup[cx->glyphs * 2]);
    207 
    208             fscanf(f, "%*c");
     202                sscanf(buf, "%u", &cx->lookup[cx->glyphs * 2]);
    209203        }
    210204
Note: See TracChangeset for help on using the changeset viewer.