чување 821d81353155e115c87401b051abae6a91a8471c
родитељ 513313fae285a4e8d9c76c9ae38b2a4f7381186b
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 13 Jan 2022 19:48:14 +0100
Optimize, remove comments
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 8, додавања: 19(+), брисања: 155(-)
diff --git a/TODO b/TODO
@@ -1,7 +1,7 @@
TODO
====
- [ ] Find a way to process {inline-,}stylesheet in includes (no <header>
+ [x] Find a way to process {inline-,}stylesheet in includes (no <header>
for <style> and <link> to go to)
[ ] Investigate: if footnote text is at the end of file, it gets
diff --git a/css01.css b/css01.css
@@ -1,4 +0,0 @@
-h1
-{
- color: blue;
-}
diff --git a/css02.css b/css02.css
@@ -1,9 +0,0 @@
-h1
-{
- color: red;
-}
-
-h2
-{
- color: green;
-}
diff --git a/examples/includes/bugs.slw b/examples/includes/bugs.slw
@@ -1,4 +1,4 @@
## BUGS
Bugs can be reported using the ticket tracker at:
-[https://sr.ht/~strahinja/slweb/trackers](https://sr.ht/~strahinja/slweb/trackers)
+[https://sr.ht/\~strahinja/slweb/trackers](https://sr.ht/~strahinja/slweb/trackers)
diff --git a/slweb.c b/slweb.c
@@ -37,7 +37,6 @@ static size_t tsv_template_size = 0;
static char* tsv_filename = NULL;
static long tsv_iter = 0;
static ULLONG state = ST_NONE;
-static BOOL in_included_file = FALSE;
#define CHECKEXITNOMEM(ptr) \
do \
@@ -569,22 +568,26 @@ process_stylesheet(FILE* output, const u8* css_filename, BOOL output_yaml)
int
process_inline_stylesheet(FILE* output, const u8* css_filename, BOOL output_yaml)
{
- FILE* css = NULL;
- u8* bufline = NULL;
+ FILE* css = NULL;
+ u8* bufline = NULL;
+ char* css_pathname = NULL;
+ size_t css_filename_len = 0;
+ size_t css_pathname_size = 0;
if (!css_filename)
exit(error(EINVAL,
(u8*)"process_inline_stylesheet: Invalid argument"));
- if (!(css = fopen((const char*)css_filename, "rt")))
+ css_filename_len = strlen((char*)css_filename);
+ css_pathname_size = basedir_size + css_filename_len + 1;
+
+ CALLOC(css_pathname, char, css_pathname_size);
+ sprintf(css_pathname, "%s/%s", basedir, css_filename);
+ if (!(css = fopen((const char*)css_pathname, "rt")))
exit(error(ENOENT,
(u8*)"process_inline_stylesheet: No such file: %s",
- css_filename));
+ css_pathname));
- /*
- *print_output(output, "process_inline_stylesheet:read_yml: %s\n",
- * read_yaml_macros_and_links ? "TRUE" : "FALSE");
- */
if (output_yaml)
{
print_output(output, "inline-stylesheet: %s\n", css_filename);
@@ -605,6 +608,7 @@ process_inline_stylesheet(FILE* output, const u8* css_filename, BOOL output_yaml
output_firstcol = TRUE;
process_inline_stylesheet_cleanup:
+ free(css_pathname);
fclose(css);
free(bufline);
@@ -1280,13 +1284,6 @@ int
process_include(FILE* output, const u8* token,
const BOOL read_yaml_macros_and_links)
{
- // TODO: if (read_yaml_macros_and_links), process only stylesheets:
- // collect stylesheet names and add them to stylesheet list
- /*
- *if (read_yaml_macros_and_links)
- * return 0;
- */
-
u8* ptoken = (u8*)strchr((char*)token, ' ');
char* include_filename = NULL;
char* pinclude_filename = NULL;
@@ -1303,10 +1300,6 @@ process_include(FILE* output, const u8* token,
(u8*)"Directive 'include' requires"
" an argument"));
- /*
- *print_output(output, "== Before include %s==\n",
- * read_yaml_macros_and_links ? "(read yaml) " : "");
- */
fflush(output);
pipe(arg_pipe_fds);
pipe(output_pipe_fds);
@@ -1337,10 +1330,6 @@ process_include(FILE* output, const u8* token,
eol = strchr((char*)child_output_line, '\n');
if (eol)
*eol = 0;
- /*
- *print_output(output, "parent: got line [%s]\n",
- * child_output_line);
- */
simple_parse_yaml_line(child_output_line, &vars,
&vars_count, &pvars);
}
@@ -1348,11 +1337,6 @@ process_include(FILE* output, const u8* token,
fclose(child_output);
wait(&pstatus);
-
- /*
- *print_output(output, "== After include %s==\n",
- * read_yaml_macros_and_links ? "(read yaml) " : "");
- */
}
else if (pid == 0) /* child */
{
@@ -1363,9 +1347,6 @@ process_include(FILE* output, const u8* token,
size_t buffer_size = 0;
int result = 0;
FILE* child_output = NULL;
- /*
- *ULLONG saved_state = ST_NONE;
- */
prctl(PR_SET_PDEATHSIG, SIGTERM);
close(arg_pipe_fds[PIPE_WRITE_INDEX]);
@@ -1411,27 +1392,14 @@ process_include(FILE* output, const u8* token,
inline_footnotes = NULL;
inline_footnote_count = 0;
current_inline_footnote = 0;
-
- /*
- *saved_state = state;
- */
- state = ST_NONE;
- in_included_file = TRUE;
- /*
- *print_output(output,
- *"process_include:child(%s):read_yml==%s\n", filename,
- * read_yaml_macros_and_links ? "TRUE" : "FALSE");
- */
+ state = ST_NONE;
/* First pass: read YAML, macros and links */
result = slweb_parse(output, filename, buffer, TRUE,
read_yaml_macros_and_links, TRUE);
add_css(child_output, TRUE);
- if (result)
- goto process_include_child_cleanup;
-
- if (read_yaml_macros_and_links)
+ if (result || read_yaml_macros_and_links)
goto process_include_child_cleanup;
state = ST_NONE;
@@ -1442,10 +1410,6 @@ process_include(FILE* output, const u8* token,
result = slweb_parse(output, filename, buffer, TRUE,
read_yaml_macros_and_links, FALSE);
- /*
- *state = saved_state;
- */
-
process_include_child_cleanup:
slweb_cleanup();
free(filename);
@@ -2529,9 +2493,6 @@ add_css(FILE* output, BOOL output_yaml)
if (!vars)
return -1;
KeyValue* pvars = vars;
- /*
- *print_output(output, "=== add_css ===\n");
- */
while (pvars < vars + vars_count)
{
if (!strcmp((char*)pvars->key, "stylesheet"))
@@ -2541,9 +2502,6 @@ add_css(FILE* output, BOOL output_yaml)
output_yaml);
pvars++;
}
- /*
- *print_output(output, "=== /add_css ===\n");
- */
return 0;
}
@@ -2833,38 +2791,12 @@ slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
pfootnotes = footnotes;
lineno = 0;
- /*
- *print_output(output,
- * "slweb_parse: "
- * "read_yaml_macros_and_links=%s\n",
- * read_yaml_macros_and_links ? "TRUE" : "FALSE");
- */
- /*
- *if (in_included_file)
- *{
- * if (parent_read_yaml && read_yaml_macros_and_links)
- * {
- * print_output(output,
- *"slweb_parse(%s):add_css[1]\n", source_filename);
- *add_css(output, parent_read_yaml);
- * }
- *}
- *else
- *{
- */
if (!read_yaml_macros_and_links && !body_only)
{
begin_html_and_head(output);
- /*
- *print_output(output, "slweb_parse(%s):add_css[2]\n",
- * source_filename);
- */
add_css(output, FALSE);
end_head_start_body(output);
}
- /*
- *}
- */
if (!read_yaml_macros_and_links)
begin_article(output, source_filename, link_prefix,
@@ -4241,7 +4173,6 @@ do_line:
ptoken += tag_len;
}
state &= ~ST_LINK_SPAN;
- /*pline += 2;*/
pline++;
colno++;
}
@@ -4460,7 +4391,8 @@ do_line:
*ptoken = 0;
if (ANY(state,
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++;
diff --git a/test01.html b/test01.html
@@ -1,38 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-<title></title>
-<meta charset="utf-8" />
-<meta name="viewport" content="width=device-width, initial-scale=1" />
-<meta name="generator" content="slweb" />
-<style>
-h1
-{
- color: blue;
-}
-</style>
-<style>
-h1
-{
- color: red;
-}
-
-h2
-{
- color: green;
-}
-</style>
-</head>
-<body>
-<h1 id="heading-1">Include test</h1>
-
-<p>Including test02.</p>
-
-
-<h2 id="heading-1">Included file</h2>
-
-<p>This is the file test02.slw.</p>
-
-
-</body>
-</html>
diff --git a/test01.slw b/test01.slw
@@ -1,9 +0,0 @@
----
-inline-stylesheet: css01.css
----
-# Include test
-
-Including test02.
-
-{include "test02"}
-
diff --git a/test02.slw b/test02.slw
@@ -1,8 +0,0 @@
----
-inline-stylesheet: css02.css
----
-
-## Included file
-
-This is the file test02.slw.
-