tools/tparser.c
static void replace_tags(struct argtable_s *table, const char *buf, FILE *fp)
{
    size_t i;
    size_t start = 0;
    size_t rpl_len = 0, tag_len = 0;
    size_t end = strlen(buf);

    int result = -1;
    int flag = 0;

    // Fill in the span and replace the nearest tag
    while (1) {
        result = nearest_tag(&flag, buf+start);
        if (result == -1) break;

        const char *str_ptr = NULL;

        enum {SUFFIX=0, OUTPUT, INPUT};
        switch (flag) {
            case SUFFIX:
                rpl_len = 2;
                tag_len = strlen(suffix_tag);
                str_ptr = table->suffix;
                break;

            case OUTPUT:
                rpl_len = strlen(table->output_type);
                tag_len = strlen(output_tag);
                str_ptr = table->output_type;
                break;

            case INPUT:
                rpl_len = strlen(table->input_type);
                tag_len = strlen(input_tag);
                str_ptr = table->input_type;
                break;

            default:
                error_msg("Flag should never be in this state.");
        }

        for (i = 0; i < result; i++)
            fputc(buf[i+start], fp);

        for (i = 0; i < rpl_len; i++)
            fputc(str_ptr[i], fp);

        start += result + tag_len;
    }

    // Place the rest of the line
    size_t diff = end - start;
    for (i = 0; i < diff; i++)
        fputc(buf[i+start], fp);
}
// Replace the tags within the templated file
Replace the tags within the templated file
Replace the tags within the templated file
static void replace_tags(struct argtable_s *table, const char *buf, FILE *fp)
{
    size_t i;
    size_t start = 0;
    size_t rpl_len = 0, tag_len = 0;
    size_t end = strlen(buf);
    int result = -1;
    int flag = 0;
    while (1) {
        result = nearest_tag(&flag, buf+start);
        if (result == -1) break;
        const char *str_ptr = NULL;
        enum {SUFFIX=0, OUTPUT, INPUT};
        switch (flag) {
            case SUFFIX:
                rpl_len = 2;
                tag_len = strlen(suffix_tag);
                str_ptr = table->suffix;
                break;
            case OUTPUT:
                rpl_len = strlen(table->output_type);
                tag_len = strlen(output_tag);
                str_ptr = table->output_type;
                break;
            case INPUT:
                rpl_len = strlen(table->input_type);
                tag_len = strlen(input_tag);
                str_ptr = table->input_type;
                break;
            default:
                error_msg("Flag should never be in this state.");
        }
        for (i = 0; i < result; i++)
            fputc(buf[i+start], fp);
        for (i = 0; i < rpl_len; i++)
            fputc(str_ptr[i], fp);
        start += result + tag_len;
    }
    size_t diff = end - start;
    for (i = 0; i < diff; i++)
        fputc(buf[i+start], fp);
}
static void replace_tags ( struct argtable_s * table , const char * buf , FILE * fp ) { size_t i ; size_t start = 0 ; size_t rpl_len = 0 , tag_len = 0 ; size_t end = strlen ( buf ) ; int result = -1 ; int flag = 0 ; while ( 1 ) { result = nearest_tag ( & flag , buf + start ) ; if ( result == -1 ) break ; const char * str_ptr = NULL ; enum { SUFFIX = 0 , OUTPUT , INPUT } ; switch ( flag ) { case SUFFIX : rpl_len = 2 ; tag_len = strlen ( suffix_tag ) ; str_ptr = table -> suffix ; break ; case OUTPUT : rpl_len = strlen ( table -> output_type ) ; tag_len = strlen ( output_tag ) ; str_ptr = table -> output_type ; break ; case INPUT : rpl_len = strlen ( table -> input_type ) ; tag_len = strlen ( input_tag ) ; str_ptr = table -> input_type ; break ; default : error_msg ( " " ) ; } for ( i = 0 ; i < result ; i ++ ) fputc ( buf [ i + start ] , fp ) ; for ( i = 0 ; i < rpl_len ; i ++ ) fputc ( str_ptr [ i ] , fp ) ; start += result + tag_len ; } size_t diff = end - start ; for ( i = 0 ; i < diff ; i ++ ) fputc ( buf [ i + start ] , fp ) ; }
Replace the tags within the templated file
Replace the tags within the templated file
// Fill in the span and replace the nearest tag // Place the rest of the line