чување 78d004ffbad979e9d099f6af9ec110e47d62c87c
родитељ 97b324d55a03301fe0b75287a62b5b209049bf58
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sat, 4 Sep 2021 13:58:16 +0200
Fix: extra lines in incdir output when reading YAML
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | slw2gmi.c | | | 165 | +++++++++++++++++++++++++++++++++---------------------------------------------- |
измењених датотека: 1, додавања: 69(+), брисања: 96(-)
diff --git a/slw2gmi.c b/slw2gmi.c
@@ -1267,12 +1267,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
}
int
-process_incdir(FILE* output, const u8* token, const u8* link_prefix,
- const BOOL read_yaml_macros_and_links)
+process_incdir(FILE* output, const u8* token, const u8* link_prefix)
{
- if (read_yaml_macros_and_links)
- return 0;
-
u8* saveptr = NULL;
/* skipping the first token (incdir) */
u8* arg = (u8*)strtok_r((char*)token, " ", (char**)&saveptr);
@@ -1340,7 +1336,7 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
}
current_name = 0;
- print_output(output, "\n");
+ /*print_output(output, "\n");*/
if (names_total < num)
num = names_total;
while (current_name < num)
@@ -1350,7 +1346,7 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
details_open = FALSE;
current_name++;
}
- print_output(output, "\n");
+ /*print_output(output, "\n");*/
output_firstcol = TRUE;
while (names_total--)
@@ -1379,77 +1375,52 @@ process_timestamp(FILE* output, const u8* link_prefix, const char* link,
CALLOC(formatted_date, u8, DATEBUFSIZE);
ptr = NULL;
year = (u8*)strtok_r((char*)date, "-", (char**)&ptr);
- if (year)
+ if (!year)
+ goto process_timestamp_cleanup;
+ month = (u8*)strtok_r((char*)NULL, "-", (char**)&ptr);
+ if (!month)
+ goto process_timestamp_cleanup;
+ day = (u8*)strtok_r((char*)NULL, "T", (char**)&ptr);
+ if (!day)
+ goto process_timestamp_cleanup;
+ ptimestamp_format = timestamp_format;
+ while (*ptimestamp_format)
{
- month = (u8*)strtok_r((char*)NULL, "-", (char**)&ptr);
- if (month)
- {
- day = (u8*)strtok_r((char*)NULL, "T", (char**)&ptr);
- if (day)
- {
- ptimestamp_format = timestamp_format;
- while (*ptimestamp_format)
- {
- if (*ptimestamp_format == 'd'
- || *ptimestamp_format == 'D')
- strncat((char*)formatted_date,
- (char*)day,
- DATEBUFSIZE
- - strlen((
- char*)formatted_date)
- - 1);
- else if (*ptimestamp_format == 'm'
- || *ptimestamp_format == 'M')
- strncat((char*)formatted_date,
- (char*)month,
- DATEBUFSIZE
- - strlen((
- char*)formatted_date)
- - 1);
- else if (*ptimestamp_format == 'y'
- || *ptimestamp_format == 'Y')
- strncat((char*)formatted_date,
- (char*)year,
- DATEBUFSIZE
- - strlen((
- char*)formatted_date)
- - 1);
- else
- *(formatted_date
- + strlen((
- char*)formatted_date))
- = *ptimestamp_format;
+ if (*ptimestamp_format == 'd' || *ptimestamp_format == 'D')
+ strncat((char*)formatted_date, (char*)day,
+ DATEBUFSIZE - strlen((char*)formatted_date) - 1);
+ else if (*ptimestamp_format == 'm' || *ptimestamp_format == 'M')
+ strncat((char*)formatted_date, (char*)month,
+ DATEBUFSIZE - strlen((char*)formatted_date) - 1);
+ else if (*ptimestamp_format == 'y' || *ptimestamp_format == 'Y')
+ strncat((char*)formatted_date, (char*)year,
+ DATEBUFSIZE - strlen((char*)formatted_date) - 1);
+ else
+ *(formatted_date + strlen((char*)formatted_date))
+ = *ptimestamp_format;
- ptimestamp_format++;
- }
- if (title)
- print_output(output,
- "=> %s%s%s.gmi\t%s %s\n",
- url_is_local(
- link) && global_link_prefix
- ? (const char*)
- global_link_prefix
- : "",
- url_is_local(link) && link_prefix
- ? (const char*)link_prefix
- : "",
- link, formatted_date, title);
- else
- print_output(output,
- "=> %s%s%s.gmi\t%s\n",
- url_is_local(
- link) && global_link_prefix
- ? (const char*)
- global_link_prefix
- : "",
- url_is_local(link) && link_prefix
- ? (const char*)link_prefix
- : "",
- link, formatted_date);
- output_firstcol = TRUE;
- }
- }
+ ptimestamp_format++;
}
+ if (title)
+ print_output(output, "=> %s%s%s.gmi\t%s %s\n",
+ url_is_local(link) && global_link_prefix
+ ? (const char*)global_link_prefix
+ : "",
+ url_is_local(link) && link_prefix
+ ? (const char*)link_prefix
+ : "",
+ link, formatted_date, title);
+ else
+ print_output(output, "=> %s%s%s.gmi\t%s\n",
+ url_is_local(link) && global_link_prefix
+ ? (const char*)global_link_prefix
+ : "",
+ url_is_local(link) && link_prefix
+ ? (const char*)link_prefix
+ : "",
+ link, formatted_date);
+ output_firstcol = TRUE;
+process_timestamp_cleanup:
free(formatted_date);
free(in_line);
@@ -1562,10 +1533,10 @@ process_tag(FILE* output, const u8* token, const u8* link_prefix,
process_include(output, token, read_yaml_macros_and_links);
*skip_eol = TRUE;
}
- else if (startswith((char*)token, "incdir")) /* {incdir} */
+ else if (startswith((char*)token, "incdir")
+ && !read_yaml_macros_and_links) /* {incdir} */
{
- process_incdir(output, token, link_prefix,
- read_yaml_macros_and_links);
+ process_incdir(output, token, link_prefix);
*skip_eol = TRUE;
}
else if (*token == '=') /* {=macro} */
@@ -1932,14 +1903,14 @@ process_footnote(FILE* output, const u8* token, const BOOL footnote_definition,
}
int
-process_horizontal_rule(const u8* link_prefix, BOOL previous_line_blank,
- FILE* output)
+process_horizontal_rule(FILE* output, const u8* link_prefix,
+ BOOL previous_line_blank)
{
/* Temporarily break paragraph as hr is para-level */
- if (state & ST_PARA_OPEN)
+ if (IN(state, ST_PARA_OPEN))
process_para_end(output, link_prefix, previous_line_blank);
print_output(output, "————————————————————\n");
- if (state & ST_PARA_OPEN)
+ if (IN(state, ST_PARA_OPEN))
print_output(output, "\n");
return 0;
}
@@ -1990,8 +1961,8 @@ begin_article(FILE* output, const BOOL add_article_header, const u8* author,
}
int
-end_footnotes(FILE* output, const u8* link_prefix, BOOL add_footnote_div,
- BOOL previous_line_blank)
+end_footnotes(FILE* output, const u8* link_prefix, const BOOL add_footnote_div,
+ const BOOL previous_line_blank)
{
size_t footnote = 0;
@@ -2003,7 +1974,7 @@ end_footnotes(FILE* output, const u8* link_prefix, BOOL add_footnote_div,
process_paralinks(output, link_prefix);
}
- process_horizontal_rule(link_prefix, previous_line_blank, output);
+ process_horizontal_rule(output, link_prefix, previous_line_blank);
output_firstcol = TRUE;
for (footnote = 0; footnote < inline_footnote_count; footnote++)
@@ -2150,11 +2121,11 @@ do_line:
{
skip_eol = TRUE;
- if (!(IN(state, ST_YAML)) && lineno > 1
+ if (!(IN(state, ST_YAML)) && (lineno > 1)
&& !read_yaml_macros_and_links)
{
- process_horizontal_rule(link_prefix,
- previous_line_blank, output);
+ process_horizontal_rule(output, link_prefix,
+ previous_line_blank);
output_firstcol = TRUE;
}
else
@@ -2632,8 +2603,8 @@ do_line:
skip_eol = TRUE;
if (!read_yaml_macros_and_links)
{
- process_horizontal_rule(link_prefix,
- previous_line_blank, output);
+ process_horizontal_rule(output, link_prefix,
+ previous_line_blank);
output_firstcol = TRUE;
}
pline = NULL;
@@ -2995,7 +2966,8 @@ do_line:
case '/':
state &= ~ST_TABLE;
- process_table_end(output);
+ if (!read_yaml_macros_and_links)
+ process_table_end(output);
pline = NULL;
break;
@@ -3902,8 +3874,7 @@ done_line:
}
pvars->value_size = strlen((char*)token) + 1;
CALLOC(pvars->value, u8, pvars->value_size);
- strncpy((char*)pvars->value, (char*)token,
- pvars->value_size);
+ strncpy((char*)pvars->value, (char*)token, pvars->value_size);
}
else if (keep_token)
{
@@ -4172,7 +4143,8 @@ done_line:
if (IN(state, ST_BLOCKQUOTE) && (!*pbuffer || *pbuffer != '>'))
{
state &= ~ST_BLOCKQUOTE;
- process_blockquote(output, TRUE);
+ if (!read_yaml_macros_and_links)
+ process_blockquote(output, TRUE);
output_firstcol = TRUE;
}
@@ -4247,10 +4219,11 @@ done_buffer:
end_footnotes(output, link_prefix, add_footnote_div,
previous_line_blank);
- if (paralinks_count > 0)
+ if (!read_yaml_macros_and_links && (paralinks_count > 0))
process_paralinks(output, link_prefix);
- print_output(output, "\n");
+ if (!read_yaml_macros_and_links)
+ print_output(output, "\n");
output_firstcol = TRUE;
if (link_text)