чување c3a96ca62595e89e806316acc789ecb7858b919a
родитељ 2b945828e88657fbd71e6ecd13e89897877a31c9
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 8 Apr 2021 11:26:22 +0200
Small documentation and code style corrections
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 3, додавања: 82(+), брисања: 57(-)
diff --git a/index.html b/index.html
@@ -153,7 +153,7 @@ this program. If not, see <<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 a4f216d 2021-04-08 11:26:22 +0200 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD)
</div><!--git-log-->
diff --git a/slweb.1.in b/slweb.1.in
@@ -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]
diff --git a/slweb.c b/slweb.c
@@ -270,18 +270,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;
}
@@ -483,11 +488,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 +502,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 +987,6 @@ int
process_list_item_start(FILE* output)
{
fprintf(output, "%s<li><p>", output_firstcol ? "" : "\n");
- state |= ST_PARA_OPEN;
return 0;
}
@@ -1564,7 +1565,6 @@ int
process_blockquote(FILE* output, BOOL end_tag)
{
print_output(output, "<%sblockquote>", end_tag ? "/" : "");
- output_firstcol = FALSE;
return 0;
}
@@ -1572,23 +1572,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 +1587,6 @@ int
process_table_header_cell(FILE* output)
{
print_output(output, "</th><th>");
- output_firstcol = FALSE;
return 0;
}
@@ -1604,7 +1594,6 @@ int
process_table_header_end(FILE* output)
{
print_output(output, "</th></tr>\n</thead>\n");
- output_firstcol = TRUE;
return 0;
}
@@ -1614,7 +1603,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 +1610,6 @@ int
process_table_body_row_start(FILE* output)
{
print_output(output, "<tr><td>");
- output_firstcol = FALSE;
return 0;
}
@@ -1630,7 +1617,6 @@ int
process_table_body_cell(FILE* output)
{
print_output(output, "</td><td>");
- output_firstcol = FALSE;
return 0;
}
@@ -1638,7 +1624,6 @@ int
process_table_body_row_end(FILE* output)
{
print_output(output, "</td></tr>\n");
- output_firstcol = TRUE;
return 0;
}
@@ -1646,7 +1631,6 @@ int
process_table_end(FILE* output)
{
print_output(output, "</tbody>\n</table>\n");
- output_firstcol = TRUE;
return 0;
}
@@ -1968,7 +1952,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 +2193,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 +2213,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 +2309,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 +2609,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 +2676,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 +2780,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 +2984,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 +3006,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 +3020,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 +3066,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 +3085,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 +3101,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 +3124,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 +3190,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 +3721,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 +3873,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 +3968,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 +3978,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 +3986,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 +4042,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 +4177,15 @@ main(int argc, char** argv)
free(bufline);
}
- vars = NULL;
- vars_count = 0;
- macros = NULL;
- macros_count = 0;
- links = NULL;
- links_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;
+ footnotes = NULL;
+ footnote_count = 0;
+ inline_footnotes = NULL;
inline_footnote_count = 0;
/* First pass: read YAML, macros and links */
@@ -4173,8 +4198,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 */