~strahinja/slw2gmi

118469fc957114e0829b6b9e2cd951ac053c3ab8 — Страхиња Радић 6 days ago 7c4dfa6
Small code style corrections

Signed-off-by: Страхиња Радић <contact@strahinja.org>
1 files changed, 64 insertions(+), 82 deletions(-)

M slw2gmi.c
M slw2gmi.c => slw2gmi.c +64 -82
@@ 253,18 253,23 @@ set_global_link_prefix(char* arg, char** global_link_prefix,
char*
strip_ext(const char* fn)
{
    char* newname = NULL;
    char* pnewname = NULL;
    char* newname   = NULL;
    char* pnewname  = NULL;
    const char* pfn = NULL;
    char* dot = NULL;
    char* dot       = NULL;

    dot = strrchr(fn, '.');

    if (!dot)
        return NULL;

    CALLOC(newname, char, strlen(fn)+1)
    pnewname = newname;
    pfn = fn;

    while (pfn != dot && *pfn)
        *pnewname++ = *pfn++;

    return newname;
}



@@ 1258,16 1263,6 @@ process_incdir(uint8_t* token, const uint8_t* link_prefix, FILE* output,
            &reverse_alphacompare)) < 0)
    {
        perror("scandir");
        /*
         *pnamelist = namelist;
         *while (pnamelist && *pnamelist)
         *{
         *    free(*pnamelist);
         *    pnamelist++;
         *}
         *free(namelist);
         *free(incdir);
         */
        exit(error(errno, (uint8_t*)"incdir: scandir '%s' error", incdir));
    }



@@ 1275,7 1270,7 @@ process_incdir(uint8_t* token, const uint8_t* link_prefix, FILE* output,
    print_output(output, "\n");
    if (names_total < num)
        num = names_total;
    while (current_name < num)// && pnamelist && *pnamelist)
    while (current_name < num)
    {
        process_incdir_subdir(namelist[current_name]->d_name, link_prefix,
                output, details_open, macro_body);


@@ 1480,13 1475,9 @@ process_tag(uint8_t* token, const uint8_t* link_prefix, FILE* output,
        *skip_eol = TRUE;
        if (end_tag)
        {
            /*print_output(output, "ET");*/
            process_para_end(link_prefix, previous_line_blank, output);
            output_firstcol = TRUE;
        }
        /*
         *else
         *    print_output(output, "!ET!");
         */
    }

    return 0;


@@ 1514,15 1505,9 @@ int
process_blockquote(FILE* output, BOOL end_tag)
{
    if (end_tag)
    {
        print_output(output, "\n\n");
        output_firstcol = TRUE;
    }
    else
    {
        print_output(output, "%s>", output_firstcol ? "" : "\n");
        output_firstcol = FALSE;
    }
    return 0;
}



@@ 1538,63 1523,45 @@ process_table_start(FILE* output)
    return 0;
}

int 
process_table_header_start(FILE* output)
{
    /*print_output(output, "<thead>\n<tr><th>");*/
    return 0;
}

int
process_table_header_cell(FILE* output)
{
    /*print_output(output, "</th><th>");*/
    return 0;
}

int 
process_table_header_end(FILE* output)
{
    /*print_output(output, "</th></tr>\n</thead>\n");*/
    return 0;
}

int
process_table_body_start(FILE* output, BOOL start_row)
{
    /*
     *print_output(output, "<tbody>\n");
     *if (start_row)
     *    print_output(output, "<tr><td>");
     */
    return 0;
}

int
process_table_body_row_start(FILE* output)
{
    /*print_output(output, "<tr><td>");*/
    return 0;
}

int
process_table_body_cell(FILE* output)
{
    /*print_output(output, "</td><td>");*/
    return 0;
}

int
process_table_body_row_end(FILE* output)
{
    /*print_output(output, "</td></tr>\n");*/
    return 0;
}

int
process_table_end(FILE* output)
{
    /*print_output(output, "</tbody>\n</table>\n");*/
    return 0;
}



@@ 1652,8 1619,6 @@ process_inline_link(uint8_t* link_text, uint8_t* link_macro_body,
        uint8_t* link_url, FILE* output)
{
    print_output(output, "%s", link_text);
    if (*link_text)
        output_firstcol = FALSE;
    return 0;
}



@@ 1671,8 1636,6 @@ process_inline_image(uint8_t* image_text, uint8_t* image_url, FILE* output,
        BOOL add_link, BOOL add_figcaption)
{
    print_output(output, "%s ", image_text);
    if (*image_text)
        output_firstcol = FALSE;
    return 0;
}



@@ 1726,7 1689,6 @@ process_para_end(const uint8_t* link_prefix, BOOL previous_line_blank, FILE* out
{
    if (!skip_para_end)
        print_output(output, "\n");
    output_firstcol = TRUE;
    process_paralinks(link_prefix, output);

    return 0;


@@ 1766,7 1728,10 @@ process_line_start(uint8_t* line, const uint8_t* link_prefix,
            if (state & ST_FOOTNOTE_TEXT)
            {
                if (!read_yaml_macros_and_links && (state & ST_PARA_OPEN))
                {
                    process_para_end(link_prefix, previous_line_blank, output);
                    output_firstcol = TRUE;
                }
                state &= ~(ST_FOOTNOTE_TEXT | ST_PARA_OPEN);
            }
        }


@@ 1893,15 1858,13 @@ process_horizontal_rule(const uint8_t* link_prefix, BOOL previous_line_blank,
    print_output(output, "————————————————————\n");
    if (state & ST_PARA_OPEN)
        print_output(output, "\n");
    output_firstcol = TRUE;
    return 0;
}

int
process_formula(FILE* output, const uint8_t* token, BOOL display_formula)
{
    int result           = 0;
    return result;
    return 0;
}

int


@@ 1958,6 1921,7 @@ end_footnotes(FILE* output, const uint8_t* link_prefix, BOOL add_footnote_div,
    }

    process_horizontal_rule(link_prefix, previous_line_blank, output);
    output_firstcol = TRUE;

    for (footnote = 0; footnote < inline_footnote_count; footnote++)
    {


@@ 2044,13 2008,13 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
    CALLOC(token, uint8_t, BUFSIZE)
    CALLOC(link_macro, uint8_t, BUFSIZE)

    pbuffer = buffer;
    pvars = vars;
    pmacros = macros;
    plinks = links;
    pbuffer    = buffer;
    pvars      = vars;
    pmacros    = macros;
    plinks     = links;
    pparalinks = paralinks;
    pfootnotes = footnotes;
    lineno = 0;
    lineno     = 0;

    if (!read_yaml_macros_and_links)
        begin_article(output, 


@@ 2076,12 2040,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
        line_len = u8_strlen(line);

        lineno++;
        colno = 1;
        output_firstcol = TRUE;
        colno                   = 1;
        output_firstcol         = TRUE;
        processed_start_of_line = FALSE;
        skip_eol = FALSE;
        /*list_item = FALSE;*/
        list_para = FALSE;
        skip_eol                = FALSE;
        /*list_item             = FALSE;*/
        list_para               = FALSE;

        while (pline && *pline)
        {


@@ 2108,8 2072,11 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)

                    if (!(state & ST_YAML) && lineno > 1
                            && !read_yaml_macros_and_links)
                    {
                        process_horizontal_rule(link_prefix, previous_line_blank,
                            output);
                        output_firstcol = TRUE;
                    }
                    else
                    {
                        if (lineno == 1)


@@ 2464,8 2431,11 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                {
                    skip_eol = TRUE;
                    if (!read_yaml_macros_and_links)
                    {
                        process_horizontal_rule(link_prefix, previous_line_blank, 
                            output);
                        output_firstcol = TRUE;
                    }
                    pline = NULL;
                }
                else if (colno == 1 


@@ 2776,10 2746,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                    {
                    case '\\':
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_start(output);
                            process_table_header_start(output);
                        }
                        pline = NULL;
                        break;



@@ 2842,10 2809,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                    {
                        state |= ST_TABLE_HEADER;
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_start(output);
                            process_table_header_start(output);
                        }
                    }

                    pline++;


@@ 2903,7 2867,6 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                }

                state |= ST_HTML_TAG;
                /*CHECKCOPY(token, ptoken, token_size, pline)*/
                pline++;
                colno++;
                break;


@@ 2931,7 2894,10 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                {
                    if (!read_yaml_macros_and_links 
                            && !(state & ST_BLOCKQUOTE))
                    {
                        process_blockquote(output, FALSE);
                        output_firstcol = FALSE;
                    }

                    state |= ST_BLOCKQUOTE;



@@ 3036,7 3002,10 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                if (state & ST_FOOTNOTE_TEXT)
                {
                    if (!read_yaml_macros_and_links && (state & ST_PARA_OPEN))
                    {
                        process_para_end(link_prefix, previous_line_blank, output);
                        output_firstcol = TRUE;
                    }
                    state &= ~(ST_FOOTNOTE_TEXT | ST_PARA_OPEN);
                }



@@ 3162,6 3131,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                            else
                                process_inline_image(link_text, token, output, 
                                        add_image_links, add_figcaption);
                            output_firstcol = !*link_text;
                        }
                    }
                    RESET_TOKEN(token, ptoken, token_size)


@@ 3257,10 3227,13 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                            pline = NULL;
                        }
                        else
                        {
                            process_link(link_text, 
                                    get_value(macros, macros_count, 
                                        link_macro, NULL), 
                                    token, output);
                            output_firstcol = !*link_text;
                        }
                    }
                    RESET_TOKEN(token, ptoken, token_size)
                    state &= ~(ST_LINK | ST_LINK_SECOND_ARG);


@@ 3298,8 3271,11 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                            pline = NULL;
                        }
                        else
                        {
                            process_image(link_text, token, output, 
                                    add_image_links, add_figcaption);
                            output_firstcol = !*link_text;
                        }
                    }
                    RESET_TOKEN(token, ptoken, token_size)
                    state &= ~(ST_IMAGE | ST_IMAGE_SECOND_ARG);


@@ 3781,7 3757,10 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                     *else print_output(output, "!SPE!");
                     */
                    if (!read_yaml_macros_and_links)
                    {
                        process_para_end(link_prefix, previous_line_blank, output);
                        output_firstcol = TRUE;
                    }

                    if (state & ST_LIST)
                        skip_eol = TRUE;


@@ 3832,6 3811,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
            {
                state &= ~ST_BLOCKQUOTE;
                process_blockquote(output, TRUE);
                output_firstcol = TRUE;
            }

            if (ANY(state, ST_TABLE_HEADER | ST_TABLE_LINE) 


@@ 3880,7 3860,10 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links)
                    if (state & ST_LIST)
                        process_list_item_end(link_prefix, output);
                    else
                    {
                        process_para_end(link_prefix, previous_line_blank, output);
                        output_firstcol = TRUE;
                    }
                }
                previous_line_blank = TRUE;
            }


@@ 4081,18 4064,17 @@ main(int argc, char** argv)
        free(bufline);
    }

    vars = NULL;
    vars_count = 0;
    macros = NULL;
    macros_count = 0;
    links = NULL;
    links_count = 0;
    paralinks = NULL;
    paralinks_count = 0;
    footnotes = NULL;
    footnote_count = 0;

    inline_footnotes = NULL;
    vars                  = NULL;
    vars_count            = 0;
    macros                = NULL;
    macros_count          = 0;
    links                 = NULL;
    links_count           = 0;
    paralinks             = NULL;
    paralinks_count       = 0;
    footnotes             = NULL;
    footnote_count        = 0;
    inline_footnotes      = NULL;
    inline_footnote_count = 0;

    /* First pass: read YAML, macros and links */


@@ 4105,8 4087,8 @@ main(int argc, char** argv)
        return result;
    }

    state = ST_NONE;
    current_footnote = 0;
    state                   = ST_NONE;
    current_footnote        = 0;
    current_inline_footnote = 0;

    /* Second pass: parse and output */