чување 8a41944b6b4c80e2175cdfc40f595c9e1aaf2ff2
родитељ 93e250ad01de944958c3a40b4fc816aefd5e4f97
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sat, 10 Jun 2023 20:29:21 +0200
Update to match slweb 0.6.1
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | .gitignore | | | 2 | ++ |
| M | TODO | | | 3 | ++- |
| M | defs.h | | | 11 | ++++++----- |
| M | slw2gmi.c | | | 753 | +++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- |
измењених датотека: 4, додавања: 456(+), брисања: 313(-)
diff --git a/.gitignore b/.gitignore
@@ -15,8 +15,10 @@
nohup.out
*.gz
*.xz
+config.redo
slw2gmi
slw2gmi.1
+slw2gmi.html
compile_commands.json
date
version
diff --git a/TODO b/TODO
@@ -1,7 +1,8 @@
TODO
====
-[ ] Update to match current slweb
+[~] Update to match current slweb
+ [ ] Test various cases
< > Convert tables to formatted text?
diff --git a/defs.h b/defs.h
@@ -24,8 +24,8 @@
#include "version.h"
#include "utf8.h"
-#define COPYRIGHTYEAR "2021, 2022"
-#define MADEBY_URL "https://strahinja.srht.site/slw2gmi/"
+#define COPYRIGHTYEAR "2021-2023"
+#define MADEBY_URL "gemini://gemini.strahinja.org/slw2gmi/"
#define BUFSIZE 1024
#define KEYSIZE 256
@@ -33,7 +33,7 @@
#define DATEBUFSIZE 12
static const char timestamp_format[] = "y-m-d";
-static const char timestamp_output_ext[] = ".html";
+static const char timestamp_output_ext[] = ".gmi";
static const char CMD_GIT_LOG[] = "xargs";
static const char* CMD_GIT_LOG_ARGS[] = {"xargs", "-I{}", "git", "log", "-1",
@@ -62,7 +62,6 @@ typedef struct {
u8* key;
u8* value;
size_t value_size;
- int seen; /* for use with macros */
} KeyValue;
typedef int (*csv_callback_t)(FILE* output, u8** csv_header, u8** csv_register);
@@ -111,7 +110,9 @@ typedef int (*tsv_callback_t)(FILE* output, u8** tsv_header, u8** tsv_register);
#define ST_TABLE_LINE ((ULLONG)1 << 31)
#define ST_TABLE ((ULLONG)1 << 32)
#define ST_STRIKE ((ULLONG)1 << 33)
-#define ST_ENT ((ULLONG)1 << 33)
+#define ST_SUMMARY ((ULLONG)1 << 34)
+#define ST_INCDIR ((ULLONG)1 << 35)
+#define ST_ENT ((ULLONG)1 << 36)
#define ST_CS_NONE 0
#define ST_CS_HEADER 1
diff --git a/slw2gmi.c b/slw2gmi.c
@@ -41,6 +41,7 @@ static size_t tsv_template_size = 0;
static char* tsv_filename = NULL;
static long tsv_iter = 0;
static ULLONG state = ST_NONE;
+static int incdir_only_summary = 0;
#define CHECKEXITNOMEM(ptr) \
do \
@@ -215,8 +216,21 @@ endswith(const char* s, const char* what)
return *ps == *pwhat && pwhat == what;
}
+int
+all_numeric(const u8* start, const u8* end)
+{
+ const u8* ps = start;
+ while (ps != end)
+ {
+ if (*ps && !isdigit((const int)*ps))
+ return 0;
+ ps++;
+ }
+ return 1;
+}
+
u8*
-get_value(KeyValue* list, const size_t list_count, const u8* key, int* seen)
+get_value(KeyValue* list, const size_t list_count, const u8* key)
{
if (!list)
return NULL;
@@ -224,14 +238,7 @@ get_value(KeyValue* list, const size_t list_count, const u8* key, int* seen)
while (plist < list + list_count)
{
if (!strcmp((char*)plist->key, (char*)key))
- {
- if (seen)
- {
- *seen = plist->seen;
- plist->seen = 1;
- }
return plist->value;
- }
plist++;
}
return NULL;
@@ -308,12 +315,23 @@ print_output(FILE* output, const char* fmt, ...)
{
char buf[BUFSIZE];
va_list args;
+ u8* var_incdir_only_summary = NULL;
+ int incdir_only_summary = 0;
if (!output || !fmt)
exit(error(EINVAL, (u8*)"print_output: Invalid argument"));
va_start(args, fmt);
- if (IN(state, ST_CSV_BODY))
+
+ var_incdir_only_summary
+ = get_value(vars, vars_count, (u8*)"incdir-only-summary");
+ incdir_only_summary
+ = var_incdir_only_summary && *var_incdir_only_summary == '1';
+
+ if (IN(state, ST_INCDIR) && !IN(state, ST_SUMMARY)
+ && incdir_only_summary)
+ return 0;
+ else if (IN(state, ST_CSV_BODY))
{
size_t buf_len = 0;
vsnprintf((char*)buf, BUFSIZE, fmt, args);
@@ -513,7 +531,7 @@ process_heading(FILE* output, const u8* token)
if (!token || strlen((char*)token) < 1)
warning(1, (u8*)"Empty heading");
- print_output(output, "%s\n\n", token ? (char*)token : "");
+ print_output(output, "%s\n", token ? (char*)token : "");
output_firstcol = 1;
return 0;
@@ -1038,8 +1056,7 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
UBYTE current_header = 0;
u8* csv_register[MAX_CSV_REGISTERS];
UBYTE current_register = 0;
- u8* csv_delimiter
- = get_value(vars, vars_count, (u8*)"csv-delimiter", NULL);
+ u8* csv_delimiter = get_value(vars, vars_count, (u8*)"csv-delimiter");
if (!(csv = fopen(filename, "rt")))
exit(error(ENOENT, (u8*)"csv: No such file: %s", filename));
@@ -1218,7 +1235,7 @@ int
process_include(FILE* output, const u8* token,
const int read_yaml_macros_and_links)
{
- u8* ptoken = (u8*)strchr((char*)token, ' ');
+ u8* ptoken;
char* include_filename = NULL;
char* pinclude_filename = NULL;
pid_t pid = 0;
@@ -1226,6 +1243,8 @@ process_include(FILE* output, const u8* token,
int arg_pipe_fds[2];
int output_pipe_fds[2];
+ ptoken = (u8*)strchr((char*)token, ' ');
+
if (!input_filename)
return warning(1, (u8*)"Cannot use 'include' in stdin");
@@ -1347,6 +1366,7 @@ process_include(FILE* output, const u8* token,
result = slweb_parse(output, filename, buffer, 0);
process_include_child_cleanup:
+ fflush(output);
slweb_cleanup();
free(filename);
free(buffer);
@@ -1368,7 +1388,7 @@ process_list_start(FILE* output)
int
process_list_item_start(FILE* output)
{
- fprintf(output, "%s* ", output_firstcol ? "" : "\n");
+ print_output(output, "%s* ", output_firstcol ? "" : "\n");
state |= ST_PARA_OPEN;
return 0;
}
@@ -1465,7 +1485,9 @@ int process_timestamp(FILE* output, const u8* link_prefix, const char* link,
int
process_incdir_subdir(FILE* output, const char* subdirname,
- const u8* link_prefix, const int details_open, const u8* macro_body)
+ const u8* link_prefix, const int details_open, const u8* macro_body,
+ const u8* footer_permalink_text, const char* permalink_url,
+ int ext_in_permalink)
{
struct dirent** namelist;
struct dirent** pnamelist;
@@ -1544,7 +1566,7 @@ process_incdir_subdir(FILE* output, const char* subdirname,
current_inline_footnote = 0;
saved_state = state;
- state = ST_NONE;
+ state = ST_INCDIR;
output_firstcol = 1;
skip_para_end = 0;
@@ -1565,16 +1587,28 @@ process_incdir_subdir(FILE* output, const char* subdirname,
return result;
}
- u8* date = get_value(vars, vars_count, (u8*)"date",
- NULL);
- u8* title = get_value(vars, vars_count, (u8*)"title",
- NULL);
+ u8* date = get_value(vars, vars_count, (u8*)"date");
+ u8* title = get_value(vars, vars_count, (u8*)"title");
if (title && date)
process_timestamp(output, link_prefix, link,
NULL, date, title);
state = saved_state;
+ if (footer_permalink_text && incdir_only_summary)
+ {
+ char* link = strip_ext(filename);
+
+ if (ext_in_permalink)
+ strcat(link, timestamp_output_ext);
+
+ print_output(output, "=> %s %s\n",
+ permalink_url ? permalink_url : link,
+ footer_permalink_text);
+
+ free(link);
+ }
+
fflush(output);
slweb_cleanup();
free(filename);
@@ -1606,7 +1640,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
int
process_incdir(FILE* output, const u8* token, const u8* link_prefix,
- const int read_yaml_macros_and_links)
+ const u8* footer_permalink_text, const char* permalink_url,
+ const int ext_in_permalink, const int read_yaml_macros_and_links)
{
u8* saveptr = NULL;
/* skipping the first token (incdir) */
@@ -1641,7 +1676,7 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
exit(error(1, (u8*)"incdir: Second argument required"));
if (*arg == '=')
- macro_body = get_value(macros, macros_count, arg + 1, NULL);
+ macro_body = get_value(macros, macros_count, arg + 1);
else
{
u8* parg = arg;
@@ -1667,8 +1702,7 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
(u8*)"incdir: Third argument not "
"macro"));
}
- macro_body = get_value(macros, macros_count, arg + 1,
- NULL);
+ macro_body = get_value(macros, macros_count, arg + 1);
}
}
@@ -1685,7 +1719,8 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
while (names_output < MIN(names_total, num))
{
process_incdir_subdir(output, (*pnamelist)->d_name, link_prefix,
- details_open, macro_body);
+ details_open, macro_body, footer_permalink_text,
+ permalink_url, ext_in_permalink);
details_open = 0;
pnamelist++;
names_output++;
@@ -1771,81 +1806,79 @@ process_timestamp_cleanup:
}
int
-process_macro(FILE* output, const u8* token,
+process_macro_def(FILE* output, const u8* token,
const int read_yaml_macros_and_links, const int end_tag)
{
- if (!end_tag)
+ if (end_tag)
{
- if (IN(state, ST_MACRO_BODY))
- exit(error(1, (u8*)"Macro undefined or nested"));
+ fflush(output);
+ state &= ~ST_MACRO_BODY;
+ return 0;
+ }
- int seen = 0;
- u8* macro_body = get_value(macros, macros_count, token + 1,
- read_yaml_macros_and_links ? NULL : &seen);
+ if (IN(state, ST_MACRO_BODY))
+ exit(error(1, (u8*)"Cannot nest definitions"));
- if (macro_body && !read_yaml_macros_and_links)
+ if (read_yaml_macros_and_links)
+ {
+ macros_count++;
+
+ if (!macros)
{
- if (seen)
- {
- u8* eol = (u8*)strrchr((char*)macro_body, '\n');
- size_t macro_body_len
- = strlen((char*)macro_body);
- if (eol)
- output_firstcol = macro_body
- + macro_body_len
- - (u8*)strrchr(
- (char*)macro_body,
- '\n')
- > 0;
- else
- output_firstcol = !*macro_body
- || *(macro_body + macro_body_len
- - 1)
- == '\n';
- print_output(output, "%s", macro_body);
- }
- else
- state |= ST_MACRO_BODY;
+ CALLOC(macros, KeyValue, macros_count);
+ pmacros = macros;
}
- else if (!macro_body)
+ else
{
- if (read_yaml_macros_and_links)
- {
- macros_count++;
-
- if (!macros)
- {
- CALLOC(macros, KeyValue, macros_count);
- pmacros = macros;
- }
- else
- {
- REALLOC(macros, KeyValue,
- macros_count * sizeof(KeyValue));
- pmacros = macros + macros_count - 1;
- }
- CALLOC(pmacros->key, u8, KEYSIZE);
- pmacros->seen = 0;
- strcpy((char*)pmacros->key, (char*)token + 1);
- pmacros->value = NULL;
- pmacros->value_size = 0;
- }
- state |= ST_MACRO_BODY;
+ REALLOC(macros, KeyValue,
+ macros_count * sizeof(KeyValue));
+ pmacros = macros + macros_count - 1;
}
+ CALLOC(pmacros->key, u8, KEYSIZE);
+ strcpy((char*)pmacros->key, (char*)token + 2);
+ pmacros->value = NULL;
+ pmacros->value_size = 0;
}
+ fflush(output);
+ state |= ST_MACRO_BODY;
+
+ return 0;
+}
+
+int
+process_macro(FILE* output, const u8* token, const int end_tag)
+{
+ u8* macro_body;
+ u8* eol;
+ size_t macro_body_len;
+
+ macro_body = get_value(macros, macros_count, token + 1);
+ if (!macro_body)
+ exit(error(1, (u8*)"Macro '%s' undefined", token + 1));
+
+ eol = (u8*)strrchr((char*)macro_body, '\n');
+ macro_body_len = strlen((char*)macro_body);
+ if (eol)
+ output_firstcol = macro_body + macro_body_len
+ - (u8*)strrchr((char*)macro_body, '\n')
+ > 0;
else
- state &= ~ST_MACRO_BODY;
+ output_firstcol = !*macro_body
+ || *(macro_body + macro_body_len - 1) == '\n';
+ print_output(output, "%s", macro_body);
return 0;
}
int process_para_end(FILE* output, const u8* link_prefix,
- const int previous_line_blank);
+ const int previous_line_blank, const int read_yaml_macros_and_links);
int
-process_tag(FILE* output, const u8* token, const u8* link_prefix,
- const int previous_line_blank, const int read_yaml_macros_and_links,
- int* skip_eol, const int end_tag)
+process_tag(FILE* output, const u8* token, const char* source_filename,
+ const u8* link_prefix, const int previous_line_blank,
+ const int first_line_in_doc, const u8* footer_permalink_text,
+ const char* permalink_url, const int ext_in_permalink,
+ const int read_yaml_macros_and_links, int* skip_eol, const int end_tag)
{
if (!token || strlen((char*)token) < 1)
return warning(1, (u8*)"%s:%ld:%ld: Empty tag name",
@@ -1856,14 +1889,6 @@ process_tag(FILE* output, const u8* token, const u8* link_prefix,
{
process_git_log(output);
}
- else if (!strcmp((char*)token, "made-by")
- && !read_yaml_macros_and_links) /* {made-by} */
- {
- print_output(output,
- "Generated by slw2gmi © %s Strahinya Radich.\n",
- COPYRIGHTYEAR);
- output_firstcol = 1;
- }
else if (startswith((char*)token, "csv")) /* {csv} */
process_csv(output, token, read_yaml_macros_and_links, end_tag);
else if (startswith((char*)token, "tsv")) /* {csv} */
@@ -1873,17 +1898,20 @@ process_tag(FILE* output, const u8* token, const u8* link_prefix,
process_include(output, token, read_yaml_macros_and_links);
*skip_eol = 1;
}
- else if (startswith((char*)token, "incdir")
- && !read_yaml_macros_and_links) /* {incdir} */
+ else if (startswith((char*)token, "incdir")) /* {incdir} */
{
process_incdir(output, token, link_prefix,
+ footer_permalink_text, permalink_url, ext_in_permalink,
read_yaml_macros_and_links);
*skip_eol = 1;
}
else if (*token == '=') /* {=macro} */
{
- process_macro(output, token, read_yaml_macros_and_links,
- end_tag);
+ if (*(token + 1) == '!')
+ process_macro_def(output, token,
+ read_yaml_macros_and_links, end_tag);
+ else if ((*(token + 1) != '!') && !read_yaml_macros_and_links)
+ process_macro(output, token, end_tag);
*skip_eol = 1;
}
else if (startswith((char*)token, "p") && !read_yaml_macros_and_links)
@@ -1893,7 +1921,8 @@ process_tag(FILE* output, const u8* token, const u8* link_prefix,
if (end_tag)
{
process_para_end(output, link_prefix,
- previous_line_blank);
+ previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
}
}
@@ -1936,6 +1965,18 @@ process_kbd(FILE* output, int end_tag)
}
int
+process_madeby(FILE* output)
+{
+ print_output(output,
+ "Generated by slw2gmi © %s Strahinya Radich.\n"
+ "=> %s slw2gmi\n",
+ COPYRIGHTYEAR, MADEBY_URL);
+
+ output_firstcol = 1;
+ return 0;
+}
+
+int
process_strike(FILE* output, int end_tag)
{
print_output(output, "~");
@@ -1957,6 +1998,7 @@ process_table_header_cell(FILE* output)
int
process_table_header_end(FILE* output)
{
+ print_output(output, "\n");
return 0;
}
@@ -1981,6 +2023,7 @@ process_table_body_cell(FILE* output)
int
process_table_body_row_end(FILE* output)
{
+ print_output(output, "\n");
return 0;
}
@@ -2037,10 +2080,13 @@ process_paralinks(FILE* output, const u8* link_prefix)
/*print_output(output, "\n");*/
}
+ // fprintf(stderr, "PL_count=%ld\n", paralinks_count);
while (pparalink < paralinks + paralinks_count)
{
if (pparalink->key)
{
+ /*fprintf(stderr, "PL{%s=%s}\n", pparalink->key,
+ pparalink->value);*/
if (!output_firstcol)
print_output(output, "\n");
print_output(output, "=> %s%s%s\t%s\n",
@@ -2071,9 +2117,10 @@ process_paralinks(FILE* output, const u8* link_prefix)
int
process_para_end(FILE* output, const u8* link_prefix,
- const int previous_line_blank)
+ const int previous_line_blank, const int read_yaml_macros_and_links)
{
- if (!skip_para_end)
+ if (!read_yaml_macros_and_links && !skip_para_end
+ && !previous_line_blank)
print_output(output, "\n");
process_paralinks(output, link_prefix);
@@ -2083,10 +2130,10 @@ process_para_end(FILE* output, const u8* link_prefix,
int
process_line_start(FILE* output, const u8* line, const u8* link_prefix,
const int first_line_in_doc, const int previous_line_blank,
- const int read_yaml_macros_and_links, const int list_para, u8** token,
- u8** ptoken)
+ int* previous_line_block, const int read_yaml_macros_and_links,
+ const int list_para, const int new_para_ok)
{
- if ((first_line_in_doc || previous_line_blank)
+ if ((first_line_in_doc || previous_line_blank || *previous_line_block)
&& !(ANY(state, ST_BLOCKQUOTE | ST_PRE)))
{
if (!list_para)
@@ -2119,19 +2166,25 @@ process_line_start(FILE* output, const u8* line, const u8* link_prefix,
&& (IN(state, ST_PARA_OPEN)))
{
process_para_end(output, link_prefix,
- previous_line_blank);
+ previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
}
state &= ~(ST_FOOTNOTE_TEXT | ST_PARA_OPEN);
}
}
- if (!ANY(state, ST_TABLE | ST_TABLE_HEADER | ST_TABLE_LINE))
+ if (new_para_ok
+ && !ANY(state,
+ ST_TABLE | ST_TABLE_HEADER | ST_TABLE_LINE))
{
if (!read_yaml_macros_and_links)
+ {
print_output(output, "%s",
output_firstcol && previous_line_blank
? ""
: "\n");
+ *previous_line_block = 0;
+ }
output_firstcol = 1;
skip_para_end = 0;
state |= ST_PARA_OPEN;
@@ -2143,20 +2196,21 @@ process_line_start(FILE* output, const u8* line, const u8* link_prefix,
int
process_text_token(FILE* output, const u8* line, const u8* link_prefix,
const int first_line_in_doc, const int previous_line_blank,
- const int processed_start_of_line, const int read_yaml_macros_and_links,
- const int list_para, u8** token, u8** ptoken, size_t* token_size,
- const int add_enclosing_paragraph)
+ int* previous_line_block, const int processed_start_of_line,
+ const int read_yaml_macros_and_links, const int list_para, u8** token,
+ u8** ptoken, size_t* token_size, const int add_enclosing_paragraph,
+ const int new_para_ok)
{
- if (!IN(state, ST_YAML))
+ if (!(IN(state, ST_YAML)))
{
if (add_enclosing_paragraph && !processed_start_of_line)
process_line_start(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
- read_yaml_macros_and_links, list_para, token,
- ptoken);
+ previous_line_block, read_yaml_macros_and_links,
+ list_para, new_para_ok);
**ptoken = 0;
if (**token && !read_yaml_macros_and_links
- && !IN(state, ST_MACRO_BODY))
+ && !(IN(state, ST_MACRO_BODY)))
{
print_output(output, "%s", *token);
u8* eol = (u8*)strrchr((char*)*token, '\n');
@@ -2173,8 +2227,8 @@ process_text_token(FILE* output, const u8* line, const u8* link_prefix,
}
int
-process_inline_footnote(FILE* output, const u8* token,
- const int read_yaml_macros_and_links)
+process_inline_footnote(const u8* token, const int read_yaml_macros_and_links,
+ FILE* output)
{
current_inline_footnote++;
@@ -2184,7 +2238,9 @@ process_inline_footnote(FILE* output, const u8* token,
inline_footnote_count++;
if (inline_footnote_count == 1 && footnote_count > 0)
- warning(1, (u8*)"Both inline and regular footnotes present");
+ warning(1,
+ (u8*)"Both inline and regular footnotes "
+ "present");
else if (!inline_footnotes)
{
inline_footnote_count = 1;
@@ -2196,8 +2252,8 @@ process_inline_footnote(FILE* output, const u8* token,
CALLOC(inline_footnotes[inline_footnote_count - 1], u8,
token_len + 1);
- strncpy((char*)inline_footnotes[inline_footnote_count - 1],
- (char*)token, token_len + 1);
+ strcpy((char*)inline_footnotes[inline_footnote_count - 1],
+ (char*)token);
*(inline_footnotes[inline_footnote_count - 1] + token_len) = 0;
}
else
@@ -2219,7 +2275,9 @@ process_footnote(FILE* output, const u8* token, const int footnote_definition,
{
footnote_count++;
if (footnote_count == 1 && inline_footnote_count > 0)
- warning(1, (u8*)"Both inline and regular footnotes present");
+ warning(1,
+ (u8*)"Both inline and regular footnotes "
+ "present");
else if (!footnotes)
{
CALLOC(footnotes, KeyValue, footnote_count);
@@ -2231,7 +2289,7 @@ process_footnote(FILE* output, const u8* token, const int footnote_definition,
pfootnotes = footnotes + footnote_count - 1;
}
CALLOC(pfootnotes->key, u8, KEYSIZE);
- strncpy((char*)pfootnotes->key, (char*)token, KEYSIZE - 1);
+ strcpy((char*)pfootnotes->key, (char*)token);
pfootnotes->value = NULL;
pfootnotes->value_size = 0;
}
@@ -2247,11 +2305,12 @@ process_footnote(FILE* output, const u8* token, const int footnote_definition,
int
process_horizontal_rule(FILE* output, const u8* link_prefix,
- int previous_line_blank)
+ const int previous_line_blank, const int read_yaml_macros_and_links)
{
/* Temporarily break paragraph as hr is para-level */
if (IN(state, ST_PARA_OPEN))
- process_para_end(output, link_prefix, previous_line_blank);
+ process_para_end(output, link_prefix, previous_line_blank,
+ read_yaml_macros_and_links);
print_output(output, "————————————————————\n");
if (IN(state, ST_PARA_OPEN))
print_output(output, "\n");
@@ -2265,9 +2324,10 @@ process_formula(FILE* output, const u8* token, int display_formula)
}
int
-begin_article(FILE* output, const int add_article_header, const u8* author,
- const u8* title, const u8* header_text, const char* title_heading_level,
- u8* date, const int ext_in_permalink, int first_line_in_doc,
+begin_article(FILE* output, const char* source_filename, const u8* link_prefix,
+ const int add_article_header, const u8* author, const u8* title,
+ const u8* header_text, const char* title_heading_level, u8* date,
+ const int ext_in_permalink, int first_line_in_doc,
int* previous_line_blank, const char* permalink_url)
{
if (title)
@@ -2275,6 +2335,8 @@ begin_article(FILE* output, const int add_article_header, const u8* author,
process_heading_start(output, 1);
process_heading(output, title);
}
+ int save_incdir = IN(state, ST_INCDIR);
+ state &= ~ST_INCDIR;
if (header_text)
print_output(output, "%s\n\n", (char*)header_text);
@@ -2282,29 +2344,31 @@ begin_article(FILE* output, const int add_article_header, const u8* author,
if (author)
print_output(output, "%s\n\n", author);
- if (date && input_filename)
+ if (date && source_filename)
{
- char* link = strip_ext(input_filename);
- char* real_link = NULL;
- CALLOC(real_link, char, BUFSIZE);
+ char* link = strip_ext((const char*)source_filename);
if (ext_in_permalink)
- strncat(link, timestamp_output_ext,
- BUFSIZE - strlen(link) - 1);
+ strcat(link, timestamp_output_ext);
- free(real_link);
free(link);
}
+ /*if (author || date || header_text || title)
+ print_output(output, "\n");*/
+
output_firstcol = author || date || header_text || title;
*previous_line_blank = author || header_text || title;
+ if (save_incdir)
+ state |= ST_INCDIR;
+
return 0;
}
int
end_footnotes(FILE* output, const u8* link_prefix, const int add_footnote_div,
- const int previous_line_blank)
+ const int previous_line_blank, const int read_yaml_macros_and_links)
{
size_t footnote = 0;
@@ -2316,7 +2380,8 @@ end_footnotes(FILE* output, const u8* link_prefix, const int add_footnote_div,
process_paralinks(output, link_prefix);
}
- process_horizontal_rule(output, link_prefix, previous_line_blank);
+ process_horizontal_rule(output, link_prefix, previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
for (footnote = 0; footnote < inline_footnote_count; footnote++)
@@ -2432,6 +2497,8 @@ slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
u8* ext_in_permalink = NULL;
u8* var_add_article_header = NULL;
u8* var_add_footnote_div = NULL;
+ u8* footer_permalink_text = NULL;
+ u8* var_incdir_only_summary = NULL;
u8* link_prefix = NULL;
const u8* pbuffer = NULL;
u8* line = NULL;
@@ -2450,30 +2517,37 @@ slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
int skip_eol = 0;
int keep_token = 0;
int previous_line_blank = 0;
+ int previous_line_block = 0;
int processed_start_of_line = 0;
int add_footnote_div = 0;
int list_para = 0;
int footnote_at_line_start = 0;
size_t pline_len = 0;
+ int madeby_present = 0;
if (!buffer)
exit(error(1, (u8*)"Empty buffer"));
- title = get_value(vars, vars_count, (u8*)"title", NULL);
+ title = get_value(vars, vars_count, (u8*)"title");
title_heading_level
- = get_value(vars, vars_count, (u8*)"title-heading-level", NULL);
- header_text = get_value(vars, vars_count, (u8*)"header-text", NULL);
- author = get_value(vars, vars_count, (u8*)"author", NULL);
- date = get_value(vars, vars_count, (u8*)"date", NULL);
- permalink_url = get_value(vars, vars_count, (u8*)"permalink-url", NULL);
- ext_in_permalink
- = get_value(vars, vars_count, (u8*)"ext-in-permalink", NULL);
+ = get_value(vars, vars_count, (u8*)"title-heading-level");
+ header_text = get_value(vars, vars_count, (u8*)"header-text");
+ author = get_value(vars, vars_count, (u8*)"author");
+ date = get_value(vars, vars_count, (u8*)"date");
+ permalink_url = get_value(vars, vars_count, (u8*)"permalink-url");
+ ext_in_permalink = get_value(vars, vars_count, (u8*)"ext-in-permalink");
var_add_article_header
- = get_value(vars, vars_count, (u8*)"add-article-header", NULL);
+ = get_value(vars, vars_count, (u8*)"add-article-header");
var_add_footnote_div
- = get_value(vars, vars_count, (u8*)"add-footnote-div", NULL);
+ = get_value(vars, vars_count, (u8*)"add-footnote-div");
add_footnote_div = var_add_footnote_div && *var_add_footnote_div == '1';
- link_prefix = get_value(vars, vars_count, (u8*)"link-prefix", NULL);
+ link_prefix = get_value(vars, vars_count, (u8*)"link-prefix");
+ footer_permalink_text = get_value(vars, vars_count,
+ (u8*)"incdir-footer-permalink-text");
+ var_incdir_only_summary
+ = get_value(vars, vars_count, (u8*)"incdir-only-summary");
+ incdir_only_summary
+ = var_incdir_only_summary && *var_incdir_only_summary == '1';
CALLOC(line, u8, BUFSIZE);
token_size = BUFSIZE;
@@ -2489,7 +2563,7 @@ slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
lineno = 0;
if (!read_yaml_macros_and_links)
- begin_article(output,
+ begin_article(output, source_filename, link_prefix,
var_add_article_header && *var_add_article_header == '1',
author, title, header_text, (char*)title_heading_level,
date, ext_in_permalink && *ext_in_permalink != '0',
@@ -2546,7 +2620,8 @@ do_line:
&& !read_yaml_macros_and_links)
{
process_horizontal_rule(output, link_prefix,
- previous_line_blank);
+ previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
}
else
@@ -2560,8 +2635,7 @@ do_line:
}
pline = NULL;
}
- else if (colno == 1 && strlen((char*)pline) > 1
- && *(pline + 1) == ' ')
+ else if (colno == 1 && *(pline + 1) == ' ')
{
if (IN(state, ST_NUMLIST))
{
@@ -2591,6 +2665,21 @@ do_line:
pline += 2;
colno += 2;
}
+ else if (IN(state, ST_SUMMARY) && *(pline + 1) == '/')
+ {
+ /* Output existing text up to -/ */
+ process_text_token(output, line, link_prefix,
+ first_line_in_doc, previous_line_blank,
+ &previous_line_block, processed_start_of_line,
+ read_yaml_macros_and_links, list_para, &token,
+ &ptoken, &token_size, 1, 1);
+ processed_start_of_line = 1;
+
+ state &= ~ST_SUMMARY;
+
+ pline += 2;
+ colno += 2;
+ }
else
{
CHECKCOPY(token, ptoken, token_size, pline);
@@ -2621,7 +2710,7 @@ do_line:
pvars = vars + vars_count - 1;
}
CALLOC(pvars->key, u8, KEYSIZE);
- strncpy((char*)pvars->key, (char*)token, KEYSIZE - 1);
+ strcpy((char*)pvars->key, (char*)token);
pvars->value = NULL;
pvars->value_size = 0;
@@ -2679,8 +2768,7 @@ do_line:
if (token_len + entity_len < BUFSIZE)
{
- strncat((char*)token, (char*)entity,
- BUFSIZE - token_len - 1);
+ strcat((char*)token, (char*)entity);
ptoken += entity_len;
}
}
@@ -2689,9 +2777,10 @@ do_line:
/* Output existing text up to ~~ */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
if (!read_yaml_macros_and_links
@@ -2720,8 +2809,7 @@ do_line:
if (token_len + entity_len < BUFSIZE)
{
- strncat((char*)token, (char*)entity,
- BUFSIZE - token_len - 1);
+ strcat((char*)token, (char*)entity);
ptoken += entity_len;
}
}
@@ -2730,9 +2818,10 @@ do_line:
/* Output existing text up to ~- */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
if (!read_yaml_macros_and_links
@@ -2762,8 +2851,7 @@ do_line:
if (token_len + tag_len < BUFSIZE)
{
- strncat((char*)token, (char*)tag,
- BUFSIZE - token_len - 1);
+ strcat((char*)token, (char*)tag);
ptoken += tag_len;
}
}
@@ -2772,9 +2860,10 @@ do_line:
/* Output existing text up to ~ */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
if (!read_yaml_macros_and_links
@@ -2833,9 +2922,10 @@ do_line:
/* Output existing text up to ` */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
}
@@ -3019,9 +3109,10 @@ do_line:
/* Output existing text up to __ */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
if (!read_yaml_macros_and_links
@@ -3045,9 +3136,10 @@ do_line:
/* Output existing text up to _ */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
if (!read_yaml_macros_and_links
@@ -3142,8 +3234,8 @@ do_line:
{
process_line_start(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
- read_yaml_macros_and_links, list_para, &token,
- &ptoken);
+ &previous_line_block,
+ read_yaml_macros_and_links, list_para, 1);
/* Ignore abbreviations (for now) */
pline = NULL;
@@ -3155,7 +3247,8 @@ do_line:
if (!read_yaml_macros_and_links)
{
process_horizontal_rule(output, link_prefix,
- previous_line_blank);
+ previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
}
pline = NULL;
@@ -3202,9 +3295,10 @@ do_line:
/* Output existing text up to * */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
if (!read_yaml_macros_and_links
@@ -3229,9 +3323,10 @@ do_line:
/* Output existing text up to * */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
if (!read_yaml_macros_and_links
@@ -3273,9 +3368,9 @@ do_line:
list_para = 1;
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
- processed_start_of_line,
+ &previous_line_block, processed_start_of_line,
read_yaml_macros_and_links, list_para, &token,
- &ptoken, &token_size, 1);
+ &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
while (*pline == ' ' || *pline == '\t')
{
@@ -3288,11 +3383,10 @@ do_line:
if (strlen((char*)pline) == 2 && *(pline + 1) == ' ')
{
*ptoken = 0;
- strncat((char*)ptoken, "\n",
- BUFSIZE - strlen((char*)token) - 1);
- ptoken += strlen("\n");
+ strcat((char*)ptoken, "\n");
+ ptoken++;
output_firstcol = 1;
- pline++;
+ pline += 2;
colno++;
}
else if (IN(state, ST_LINK_MACRO))
@@ -3373,9 +3467,9 @@ do_line:
/* Output existing text up to { */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
- processed_start_of_line,
+ &previous_line_block, processed_start_of_line,
read_yaml_macros_and_links, list_para, &token,
- &ptoken, &token_size, 1);
+ &ptoken, &token_size, 0, 1);
processed_start_of_line = 1;
}
@@ -3397,16 +3491,31 @@ do_line:
}
else if (IN(state, ST_HTML_TAG))
{
+ if (pline != line && *(pline - 1) == '<')
+ end_tag = 1;
pline++;
- colno++;
- break;
}
-
- if ((IN(state, ST_TAG)) && *(pline - 1) == '{')
+ else if ((IN(state, ST_TAG)) && pline != line
+ && *(pline - 1) == '{')
{
end_tag = 1;
pline++;
}
+ else if (*(pline + 1) == '-')
+ {
+ /* Output existing text up to /- */
+ process_text_token(output, line, link_prefix,
+ first_line_in_doc, previous_line_blank,
+ &previous_line_block, processed_start_of_line,
+ read_yaml_macros_and_links, list_para, &token,
+ &ptoken, &token_size, 1, 1);
+ processed_start_of_line = 1;
+
+ state |= ST_SUMMARY;
+
+ pline += 2;
+ colno++;
+ }
else
CHECKCOPY(token, ptoken, token_size, pline);
@@ -3428,9 +3537,18 @@ do_line:
state &= ~ST_TAG;
*ptoken = 0;
- process_tag(output, token, link_prefix,
- previous_line_blank, read_yaml_macros_and_links,
- &skip_eol, end_tag);
+ if (!strcmp((char*)token, "made-by"))
+ madeby_present = 1;
+ else
+ process_tag(output, token, source_filename,
+ link_prefix, previous_line_blank,
+ first_line_in_doc,
+ footer_permalink_text,
+ (const char*)permalink_url,
+ ext_in_permalink
+ && *ext_in_permalink != '0',
+ read_yaml_macros_and_links, &skip_eol,
+ end_tag);
RESET_TOKEN(token, ptoken, token_size);
end_tag = 0;
@@ -3460,6 +3578,8 @@ do_line:
if (strlen((char*)pline) > 1 && *(pline + 1) == '|')
{
+ /* Handle || within footnotes, headings and link
+ * text specially */
if (!ANY(state,
ST_INLINE_FOOTNOTE | ST_HEADING
| ST_FOOTNOTE_TEXT | ST_LINK))
@@ -3467,9 +3587,10 @@ do_line:
/* Output existing text up to || */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
}
@@ -3517,7 +3638,10 @@ do_line:
case '/':
state &= ~ST_TABLE;
if (!read_yaml_macros_and_links)
+ {
process_table_end(output);
+ output_firstcol = 1;
+ }
pline = NULL;
break;
@@ -3606,7 +3730,7 @@ do_line:
if (read_yaml_macros_and_links
|| ANY(state,
ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA
- | ST_IMAGE | ST_PRE))
+ | ST_KBD | ST_IMAGE | ST_PRE))
{
CHECKCOPY(token, ptoken, token_size, pline);
colno++;
@@ -3643,6 +3767,11 @@ do_line:
if (!read_yaml_macros_and_links
&& !(IN(state, ST_BLOCKQUOTE)))
{
+ if (IN(state, ST_PARA_OPEN))
+ {
+ print_output(output, "\n");
+ state &= ~ST_PARA_OPEN;
+ }
process_blockquote(output, 0);
output_firstcol = 0;
}
@@ -3683,9 +3812,9 @@ do_line:
*ptoken = 0;
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
- processed_start_of_line,
+ &previous_line_block, processed_start_of_line,
read_yaml_macros_and_links, list_para, &token,
- &ptoken, &token_size, 1);
+ &ptoken, &token_size, 0, 1);
processed_start_of_line = 1;
RESET_TOKEN(token, ptoken, token_size);
@@ -3757,7 +3886,8 @@ do_line:
&& (IN(state, ST_PARA_OPEN)))
{
process_para_end(output, link_prefix,
- previous_line_blank);
+ previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
}
state &= ~(ST_FOOTNOTE_TEXT | ST_PARA_OPEN);
@@ -3772,9 +3902,10 @@ do_line:
*ptoken = 0;
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
}
processed_start_of_line = 1;
@@ -3791,9 +3922,9 @@ do_line:
*ptoken = 0;
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
- processed_start_of_line,
+ &previous_line_block, processed_start_of_line,
read_yaml_macros_and_links, list_para, &token,
- &ptoken, &token_size, 1);
+ &ptoken, &token_size, 1, 1);
}
processed_start_of_line = 1;
@@ -3947,8 +4078,8 @@ do_line:
*ptoken = 0;
if (IN(state, ST_INLINE_FOOTNOTE))
{
- process_inline_footnote(output, token,
- read_yaml_macros_and_links);
+ process_inline_footnote(token,
+ read_yaml_macros_and_links, output);
keep_token = 0;
RESET_TOKEN(token, ptoken, token_size);
@@ -3989,8 +4120,7 @@ do_line:
{
if (!read_yaml_macros_and_links)
{
- u8* url = get_value(links, links_count, token,
- NULL);
+ u8* url = get_value(links, links_count, token);
if (!url)
exit(error(EINVAL,
(u8*)"get_"
@@ -4044,8 +4174,7 @@ do_line:
{
if (!read_yaml_macros_and_links)
{
- u8* url = get_value(links, links_count, token,
- NULL);
+ u8* url = get_value(links, links_count, token);
if (!url)
exit(error(EINVAL,
(u8*)"get_"
@@ -4115,8 +4244,7 @@ do_line:
plinks = links + links_count - 1;
}
CALLOC(plinks->key, u8, KEYSIZE);
- strncpy((char*)plinks->key, (char*)token,
- KEYSIZE - 1);
+ strcpy((char*)plinks->key, (char*)token);
plinks->value = NULL;
plinks->value_size = 0;
pline += 2;
@@ -4145,8 +4273,7 @@ do_line:
link_size = token_len + 1;
CALLOC(link_text, u8, link_size);
}
- strncpy((char*)link_text, (char*)token,
- link_size - 1);
+ strcpy((char*)link_text, (char*)token);
*(link_text + token_len) = 0;
pline += 2;
colno += 2;
@@ -4194,9 +4321,9 @@ do_line:
*ptoken = 0;
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
- processed_start_of_line,
+ &previous_line_block, processed_start_of_line,
read_yaml_macros_and_links, list_para, &token,
- &ptoken, &token_size, 1);
+ &ptoken, &token_size, 1, 1);
processed_start_of_line = 1;
RESET_TOKEN(token, ptoken, token_size);
@@ -4217,7 +4344,8 @@ do_line:
ST_DISPLAY_FORMULA
| ST_FORMULA
/*| ST_HTML_TAG*/
- | ST_IMAGE | ST_LINK | ST_MACRO_BODY))
+ | ST_IMAGE | ST_LINK_SECOND_ARG
+ | ST_LINK_SECOND_ARG_END | ST_MACRO_BODY))
{
CHECKCOPY(token, ptoken, token_size, pline);
colno++;
@@ -4248,7 +4376,8 @@ do_line:
case '$':
if (ANY(state,
- ST_CODE | ST_CSV_BODY | ST_IMAGE | ST_PRE | ST_YAML))
+ ST_CODE | ST_CSV_BODY | ST_IMAGE | ST_PRE
+ | ST_TSV_BODY | ST_YAML))
{
CHECKCOPY(token, ptoken, token_size, pline);
colno++;
@@ -4273,9 +4402,10 @@ do_line:
/* Output existing text up to $$ */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
}
processed_start_of_line = 1;
@@ -4309,9 +4439,10 @@ do_line:
/* Output existing text up to $ */
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
}
processed_start_of_line = 1;
@@ -4358,9 +4489,13 @@ do_line:
colno++;
break;
}
- else if (colno == 1 && strlen((char*)pline) > 1
+ else if ((colno == 1 || all_numeric(line, pline))
+ && strlen((char*)pline) > 1
&& (*(pline + 1) == '.' || *(pline + 1) == ')'))
{
+ ptoken = token;
+ *ptoken = 0;
+
if (IN(state, ST_LIST))
{
state &= ~ST_LIST;
@@ -4424,12 +4559,10 @@ 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);
+ strcpy((char*)pvars->value, (char*)token);
}
else if (keep_token)
{
- size_t token_len = strlen((char*)token);
-
if (ptoken + 2 > token + token_size)
{
size_t old_size = token_size;
@@ -4437,7 +4570,8 @@ done_line:
REALLOC(token, u8, token_size);
ptoken = token + old_size - 1;
}
- strncat((char*)token, " ", token_size - token_len - 1);
+ strcat((char*)token,
+ ANY(state, ST_IMAGE | ST_LINK) ? " " : "\n");
ptoken++;
*ptoken = 0;
}
@@ -4470,29 +4604,18 @@ done_line:
REALLOC(pmacros->value, u8,
pmacros->value_size);
}
- strncat((char*)pmacros->value,
- (char*)token,
- pmacros->value_size - value_len
- - 1);
- strncat((char*)pmacros->value, " ",
- pmacros->value_size
- - strlen((char*)pmacros
- ->value)
- - 1);
+ strcat((char*)pmacros->value,
+ (char*)token);
+ strcat((char*)pmacros->value, " ");
}
else
{
pmacros->value_size = BUFSIZE;
CALLOC(pmacros->value, u8,
pmacros->value_size);
- strncpy((char*)pmacros->value,
- (char*)token,
- pmacros->value_size - 1);
- strncat((char*)pmacros->value, " ",
- pmacros->value_size
- - strlen((char*)pmacros
- ->value)
- - 1);
+ strcpy((char*)pmacros->value,
+ (char*)token);
+ strcat((char*)pmacros->value, " ");
}
skip_macro_read:;
}
@@ -4521,32 +4644,21 @@ done_line:
REALLOC(pfootnotes->value, u8,
pfootnotes->value_size);
}
- strncat((char*)pfootnotes->value,
- (char*)token,
- pfootnotes->value_size
- - value_len - 1);
- strncat((char*)pfootnotes->value, " ",
- pfootnotes->value_size
- - strlen(
- (char*)pfootnotes
- ->value)
- - 1);
+ strcat((char*)pfootnotes->value,
+ (char*)token);
+ strcat((char*)pfootnotes->value, " ");
}
else
{
pfootnotes->value_size = BUFSIZE;
CALLOC(pfootnotes->value, u8,
pfootnotes->value_size);
- strncpy((char*)pfootnotes->value,
- (char*)token,
- pfootnotes->value_size - 1);
- strncat((char*)pfootnotes->value, " ",
- pfootnotes->value_size
- - strlen(
- (char*)pfootnotes
- ->value)
- - 1);
+ strcpy((char*)pfootnotes->value,
+ (char*)token);
+ strcat((char*)pfootnotes->value, " ");
}
+ *token = 0;
+ ptoken = token;
skip_footnote_read:;
}
else if (ANY(state,
@@ -4566,9 +4678,8 @@ done_line:
= strlen((char*)token) + 1;
CALLOC(plinks->value, u8,
plinks->value_size);
- strncpy((char*)plinks->value,
- (char*)token,
- plinks->value_size - 1);
+ strcpy((char*)plinks->value,
+ (char*)token);
}
}
else if (IN(state, ST_HEADING))
@@ -4585,20 +4696,33 @@ done_line:
| ST_IMAGE | ST_LINK))
process_text_token(output, line, link_prefix,
first_line_in_doc, previous_line_blank,
+ &previous_line_block,
processed_start_of_line,
read_yaml_macros_and_links, list_para,
- &token, &ptoken, &token_size, 1);
+ &token, &ptoken, &token_size, 1, 1);
}
if (!ANY(state,
ST_PRE | ST_IMAGE_SECOND_ARG | ST_LINK_SECOND_ARG
| ST_LINK_SECOND_ARG_END)
- && (!*pbuffer || (*pbuffer == '\n')))
+ && (!*pbuffer || *pbuffer == '\n'))
{
if (IN(state, ST_PARA_OPEN))
{
if (!read_yaml_macros_and_links)
{
+ /*print_output(output, "\n;");
+ output_firstcol = 1;*/
+ }
+ if (IN(state, ST_LIST))
+ skip_eol = 1;
+ state &= ~ST_PARA_OPEN;
+ }
+
+ if (!*pbuffer && (IN(state, ST_LIST)))
+ {
+ if (!read_yaml_macros_and_links)
+ {
process_list_item_end(output,
link_prefix);
process_list_end(output);
@@ -4619,15 +4743,11 @@ done_line:
if (IN(state, ST_PARA_OPEN))
{
- /*
- *if (skip_para_end)
- *print_output(output, "SPE"); else
- *print_output(output, "!SPE!");
- */
if (!read_yaml_macros_and_links)
{
process_para_end(output, link_prefix,
- previous_line_blank);
+ previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
}
@@ -4645,48 +4765,43 @@ done_line:
size_t token_len = strlen((char*)token);
skip_eol = 1;
- if (read_yaml_macros_and_links)
+ if (!read_yaml_macros_and_links)
+ goto skip_footnote_text_read;
+ if (!footnotes)
{
- if (!footnotes)
- {
- footnote_count = 1;
- CALLOC(footnotes, KeyValue,
- footnote_count);
- pfootnotes = footnotes;
- }
- if (pfootnotes->value)
- {
- size_t value_len = strlen((
- char*)pfootnotes->value);
-
- if (pfootnotes->value_size
- < value_len + token_len
- + 1)
- {
- pfootnotes->value_size
- = value_len
- + token_len + 1;
- REALLOC(pfootnotes->value,
- u8,
- pfootnotes
- ->value_size);
- }
- strncat((char*)pfootnotes->value,
- (char*)token,
- pfootnotes->value_size
- - 1);
- }
- else
+ footnote_count = 1;
+ CALLOC(footnotes, KeyValue,
+ footnote_count);
+ pfootnotes = footnotes;
+ }
+ if (pfootnotes->value)
+ {
+ size_t value_len = strlen(
+ (char*)pfootnotes->value);
+
+ if (pfootnotes->value_size
+ < value_len + token_len + 1)
{
pfootnotes->value_size
- = token_len + 1;
- CALLOC(pfootnotes->value, u8,
- pfootnotes->value_size);
- strncpy((char*)pfootnotes->value,
- (char*)token,
+ = value_len + token_len
+ + 1;
+ REALLOC(pfootnotes->value, u8,
pfootnotes->value_size);
}
+ strcat((char*)pfootnotes->value,
+ (char*)token);
+ }
+ else
+ {
+ pfootnotes->value_size = token_len + 1;
+ CALLOC(pfootnotes->value, u8,
+ pfootnotes->value_size);
+ strcpy((char*)pfootnotes->value,
+ (char*)token);
}
+ *token = 0;
+ ptoken = token;
+ skip_footnote_text_read:;
}
}
@@ -4696,7 +4811,8 @@ done_line:
if (!read_yaml_macros_and_links)
{
process_blockquote(output, 1);
- output_firstcol = 1;
+ previous_line_block = 1;
+ output_firstcol = 1;
}
}
@@ -4707,14 +4823,18 @@ done_line:
{
warning(1, (u8*)"Malformed table");
process_table_end(output);
+ output_firstcol = 1;
}
state &= ~(ST_TABLE_HEADER | ST_TABLE_LINE);
}
- if (IN(state, ST_TABLE) && (!line_len || !*pbuffer))
+ if ((IN(state, ST_TABLE)) && (!line_len || !*pbuffer))
{
if (!read_yaml_macros_and_links)
+ {
process_table_end(output);
+ output_firstcol = 1;
+ }
state &= ~ST_TABLE;
}
}
@@ -4732,7 +4852,7 @@ done_line:
if (!keep_token)
RESET_TOKEN(token, ptoken, token_size);
- if (!skip_change_first_line_in_doc && !IN(state, ST_YAML))
+ if (!skip_change_first_line_in_doc && !(IN(state, ST_YAML)))
first_line_in_doc = 0;
skip_change_first_line_in_doc = 0;
@@ -4749,12 +4869,27 @@ done_line:
else
{
process_para_end(output, link_prefix,
- previous_line_blank);
+ previous_line_blank,
+ read_yaml_macros_and_links);
output_firstcol = 1;
}
}
- previous_line_blank = 1;
+ else
+ {
+ process_para_end(output, link_prefix,
+ previous_line_blank,
+ read_yaml_macros_and_links);
+ output_firstcol = 1;
+ }
}
+ else
+ {
+ process_para_end(output, link_prefix,
+ previous_line_blank,
+ read_yaml_macros_and_links);
+ output_firstcol = 1;
+ }
+ previous_line_blank = 1;
}
else
previous_line_blank = 0;
@@ -4769,18 +4904,21 @@ done_buffer:
if (!read_yaml_macros_and_links
&& (footnote_count > 0 || inline_footnote_count > 0))
end_footnotes(output, link_prefix, add_footnote_div,
- previous_line_blank);
+ previous_line_blank, read_yaml_macros_and_links);
if (!read_yaml_macros_and_links && (paralinks_count > 0))
process_paralinks(output, link_prefix);
if (!read_yaml_macros_and_links)
- print_output(output, "\n");
- output_firstcol = 1;
-
- if (link_text)
- free(link_text);
+ {
+ if (madeby_present)
+ {
+ process_madeby(output);
+ output_firstcol = 1;
+ }
+ }
+ free(link_text);
free(link_macro);
free(token);
free(line);
@@ -4789,9 +4927,9 @@ done_buffer:
}
int
-main(int argc, char** argv)
+main(const int argc, const char** argv)
{
- char* arg;
+ const char* arg;
Command cmd = CMD_NONE;
int result = 0;
@@ -4833,7 +4971,8 @@ main(int argc, char** argv)
else
{
error(EINVAL,
- (u8*)"Invalid argument: --%s",
+ (u8*)"Invalid "
+ "argument: --%s",
arg);
return usage();
}
@@ -4856,7 +4995,8 @@ main(int argc, char** argv)
break;
default:
error(EINVAL,
- (u8*)"Invalid argument: -%c",
+ (u8*)"Invalid "
+ "argument: -%c",
c);
return usage();
}
@@ -4927,8 +5067,7 @@ main(int argc, char** argv)
buffer_size += BUFSIZE;
REALLOC(buffer, u8, buffer_size);
}
- strncat((char*)buffer, (char*)bufline,
- buffer_size - buffer_len - 1);
+ strcat((char*)buffer, (char*)bufline);
buffer_len += bufline_len;
}
free(bufline);