~strahinja/slweb

a4f216d645955c86727ccfa5b5701c1d3ed072ea — Страхиња Радић 6 days ago 2b94582
Small documentation and code style corrections

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

M index.html
M slweb.1.in
M slweb.c
M index.html => index.html +1 -1
@@ 153,7 153,7 @@ this program. If not, see &lt;<a href="https://www.gnu.org/licenses">https://www

<div id="git-log">
Previous commit:
index.slw 0ff23c0 2021-04-07 15:32:22 +0200 (Страхиња Радић)  (HEAD -> master, origin/master, origin/HEAD)
index.slw 2b94582 2021-04-08 10:54:05 +0200 (Страхиња Радић)  (HEAD -> master, origin/master, origin/HEAD)
</div><!--git-log-->



M slweb.1.in => slweb.1.in +2 -2
@@ 206,8 206,8 @@ encounters both footnote types in the same document, a warning will be issued to
.BR Headings .
A line starting with \fC#\fP followed by space will be put inside
\fC<h?></h?>\fP, where \fC?\fP stands for 1-4, depending on the number of
hash signs. Tags will have \fCid\fP attributes set to \fCh\f[CI]?\fR, with
\f[CI]?\fP set to the number representing its position within the list of all
hash signs. Tags will have \fCid\fP attributes set to \fCheading-?\fP, with
\fC?\fP set to the number representing its position within the list of all
headings.
.
.IP \[bu]

M slweb.c => slweb.c +69 -48
@@ 483,11 483,9 @@ print_meta_var(FILE* output, uint8_t** csv_header, uint8_t** csv_register)
}

int
process_heading_start(FILE* output, UBYTE heading_level, ULONG* heading_count)
process_heading_start(FILE* output, UBYTE heading_level, ULONG heading_count)
{
    (*heading_count)++;
    print_output(output, "<h%d id=\"heading-%lu\">", heading_level, *heading_count);
    output_firstcol = FALSE;
    print_output(output, "<h%d id=\"heading-%lu\">", heading_level, heading_count);
    return 0;
}



@@ 499,7 497,6 @@ process_heading(uint8_t* token, FILE* output, UBYTE heading_level)

    print_output(output, "%s</h%d>", 
            token ? (char*)token : "", heading_level);
    output_firstcol = FALSE;

    return 0;
}


@@ 985,7 982,6 @@ int
process_list_item_start(FILE* output)
{
    fprintf(output, "%s<li><p>", output_firstcol ? "" : "\n");
    state |= ST_PARA_OPEN;
    return 0;
}



@@ 1564,7 1560,6 @@ int
process_blockquote(FILE* output, BOOL end_tag)
{
    print_output(output, "<%sblockquote>", end_tag ? "/" : "");
    output_firstcol = FALSE;
    return 0;
}



@@ 1572,23 1567,14 @@ int
process_kbd(FILE* output, BOOL end_tag)
{
    print_output(output, "<%skbd>", end_tag ? "/" : "");
    output_firstcol = FALSE;
    return 0;
}

int
process_table_start(FILE* output)
{
    print_output(output, "<table>\n");
    output_firstcol = TRUE;
    return 0;
}

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



@@ 1596,7 1582,6 @@ int
process_table_header_cell(FILE* output)
{
    print_output(output, "</th><th>");
    output_firstcol = FALSE;
    return 0;
}



@@ 1604,7 1589,6 @@ int
process_table_header_end(FILE* output)
{
    print_output(output, "</th></tr>\n</thead>\n");
    output_firstcol = TRUE;
    return 0;
}



@@ 1614,7 1598,6 @@ process_table_body_start(FILE* output, BOOL start_row)
    print_output(output, "<tbody>\n");
    if (start_row)
        print_output(output, "<tr><td>");
    output_firstcol = !start_row;
    return 0;
}



@@ 1622,7 1605,6 @@ int
process_table_body_row_start(FILE* output)
{
    print_output(output, "<tr><td>");
    output_firstcol = FALSE;
    return 0;
}



@@ 1630,7 1612,6 @@ int
process_table_body_cell(FILE* output)
{
    print_output(output, "</td><td>");
    output_firstcol = FALSE;
    return 0;
}



@@ 1638,7 1619,6 @@ int
process_table_body_row_end(FILE* output)
{
    print_output(output, "</td></tr>\n");
    output_firstcol = TRUE;
    return 0;
}



@@ 1646,7 1626,6 @@ int
process_table_end(FILE* output)
{
    print_output(output, "</tbody>\n</table>\n");
    output_firstcol = TRUE;
    return 0;
}



@@ 1968,7 1947,6 @@ begin_html_and_head(FILE* output)
    uint8_t* canonical   = get_value(vars, vars_count, (uint8_t*)"canonical", NULL);
    uint8_t* favicon_url = get_value(vars, vars_count, (uint8_t*)"favicon-url", NULL);
    uint8_t* meta        = get_value(vars, vars_count, (uint8_t*)"meta", NULL);

    uint8_t* feed        = get_value(vars, vars_count, (uint8_t*)"feed", NULL);
    uint8_t* feed_desc   = get_value(vars, vars_count, (uint8_t*)"feed-desc", NULL);



@@ 2210,8 2188,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
        exit(error(1, (uint8_t*)"Empty buffer"));

    title                  = get_value(vars, vars_count, (uint8_t*)"title", NULL);
    title_heading_level    = get_value(vars, vars_count,
            (uint8_t*)"title-heading-level", NULL);
    title_heading_level    = get_value(vars, vars_count, (uint8_t*)"title-heading-level", NULL);
    header_text            = get_value(vars, vars_count, (uint8_t*)"header-text", NULL);
    author                 = get_value(vars, vars_count, (uint8_t*)"author", NULL);
    date                   = get_value(vars, vars_count, (uint8_t*)"date", NULL);


@@ 2231,13 2208,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
    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;
    pfootnotes = footnotes;
    lineno = 0;
    heading_count = 0;
    lineno     = 0;

    if (!read_yaml_macros_and_links && !body_only)
    {


@@ 2328,6 2304,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        else
                            process_list_item_end(output);
                        process_list_item_start(output);
                        state |= ST_PARA_OPEN;
                    }

                    processed_start_of_line = TRUE;


@@ 2627,6 2604,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        else
                            process_list_item_end(output);
                        process_list_item_start(output);
                        state |= ST_PARA_OPEN;
                    }

                    processed_start_of_line = TRUE;


@@ 2693,6 2671,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        else
                            process_list_item_end(output);
                        process_list_item_start(output);
                        state |= ST_PARA_OPEN;
                    }

                    processed_start_of_line = TRUE;


@@ 2796,8 2775,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                if ((state & ST_HEADING) && !(state & ST_HEADING_TEXT))
                {
                    if (!read_yaml_macros_and_links)
                    {
                        heading_count++;
                        process_heading_start(output, heading_level,
                                &heading_count);
                                heading_count);
                        output_firstcol = FALSE;
                    }
                    state |= ST_HEADING_TEXT;
                    pline++;
                    colno++;


@@ 2996,6 2979,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        {
                            state ^= ST_KBD;
                            process_kbd(output, !(state & ST_KBD));
                            output_firstcol = FALSE;
                        }
                    }



@@ 3017,7 3001,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_start(output);
                            process_table_header_start(output);
                            output_firstcol = FALSE;
                        }
                        pline = NULL;
                        break;


@@ 3031,19 3015,26 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                    case '-':
                        state &= ~ST_TABLE_HEADER;
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_body_start(output, FALSE);
                            output_firstcol = TRUE;
                        }
                        pline = NULL;
                        break;

                    case ' ':
                        state |= ST_TABLE;
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_body_row_start(output);
                            output_firstcol = FALSE;
                        }
                        break;

                    case '/':
                        state &= ~ST_TABLE;
                        process_table_end(output);
                        output_firstcol = TRUE;
                        pline = NULL;
                        break;



@@ 3070,12 3061,18 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        state &= ~ST_TABLE_LINE;
                        state |= ST_TABLE;
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_body_start(output, TRUE);
                            output_firstcol = FALSE;
                        }
                    }
                    else if (state & ST_TABLE)
                    {
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_body_row_start(output);
                            output_firstcol = FALSE;
                        }
                    }
                    else
                    {


@@ 3083,7 3080,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        if (!read_yaml_macros_and_links)
                        {
                            process_table_start(output);
                            process_table_header_start(output);
                            output_firstcol = FALSE;
                        }
                    }



@@ 3099,9 3096,15 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        if (*token)
                            output_firstcol = FALSE;
                        if (u8_strlen(pline) > 1)
                        {
                            process_table_header_cell(output);
                            output_firstcol = FALSE;
                        }
                        else
                        {
                            process_table_header_end(output);
                            output_firstcol = TRUE;
                        }
                    }
                    RESET_TOKEN(token, ptoken, token_size)
                    pline++;


@@ 3116,9 3119,15 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        if (*token)
                            output_firstcol = FALSE;
                        if (u8_strlen(pline) > 1)
                        {
                            process_table_body_cell(output);
                            output_firstcol = FALSE;
                        }
                        else
                        {
                            process_table_body_row_end(output);
                            output_firstcol = TRUE;
                        }
                    }
                    RESET_TOKEN(token, ptoken, token_size)
                    pline++;


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

                    state |= ST_BLOCKQUOTE;



@@ 3704,6 3716,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                        else
                            process_list_item_end(output);
                        process_list_item_start(output);
                        state |= ST_PARA_OPEN;
                    }

                    processed_start_of_line = TRUE;


@@ 3855,7 3868,10 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                {
                    state &= ~(ST_HEADING | ST_HEADING_TEXT);
                    if (!read_yaml_macros_and_links)
                    {
                        process_heading(token, output, heading_level);
                        output_firstcol = FALSE;
                    }
                    first_line_in_doc = FALSE;
                    RESET_TOKEN(token, ptoken, token_size)
                    heading_level = 0;


@@ 3947,6 3963,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
            {
                state &= ~ST_BLOCKQUOTE;
                process_blockquote(output, TRUE);
                output_firstcol = FALSE;
            }

            if (ANY(state, ST_TABLE_HEADER | ST_TABLE_LINE) 


@@ 3956,6 3973,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
                {
                    warning(1, (uint8_t*)"Malformed table");
                    process_table_end(output);
                    output_firstcol = TRUE;
                }
                state &= ~(ST_TABLE_HEADER | ST_TABLE_LINE);
            }


@@ 3963,7 3981,10 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
            if ((state & ST_TABLE) && (!line_len || !*pbuffer))
            {
                if (!read_yaml_macros_and_links)
                {
                    process_table_end(output);
                    output_firstcol = TRUE;
                }
                state &= ~ST_TABLE;
            }



@@ 4016,9 4037,9 @@ int
main(int argc, char** argv)
{
    char* arg;
    Command cmd = CMD_NONE;
    Command cmd    = CMD_NONE;
    BOOL body_only = FALSE;
    int result = 0;
    int result     = 0;

    basedir_size = 2;
    CALLOC(basedir, char, basedir_size)


@@ 4151,16 4172,16 @@ main(int argc, char** argv)
        free(bufline);
    }

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

    inline_footnotes = NULL;
    inline_footnotes      = NULL;
    inline_footnote_count = 0;

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


@@ 4174,7 4195,7 @@ main(int argc, char** argv)
    }

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

    /* Second pass: parse and output */