чување 1e2eab9ead8233529d10d48026fec5816a9216f3
родитељ 7e1395d676b3571d20b80e04a943274c80ba252d
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Sun, 22 Aug 2021 15:49:44 +0200
Removed realpath as a dependency; removed get_realpath
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | README | | | 9 | ++++----- |
| M | TODO | | | 4 | ++-- |
| M | defs.h | | | 6 | ------ |
| M | index.slw | | | 8 | ++++---- |
| M | slweb.c | | | 116 | +++++++++++++++++++++++-------------------------------------------------------- |
измењених датотека: 5, додавања: 44(+), брисања: 99(-)
diff --git a/README b/README
@@ -9,11 +9,10 @@ transforms custom Markdown-like syntax into HTML.
Prerequisites
-------------
-Aside from the obvious (a C compiler, by default GNU C), slweb requires
-realpath(1) to determine paths in local links and groff(1) and gzip(1) to create
-and compress documentation. git(1) is, aside from cloning the repository,
-required to use the directive {git-log}. KaTeX[1] is optionally used for math
-mode.
+Aside from the obvious (a C compiler, by default GNU C), slweb requires groff(1)
+and gzip(1) to create and compress documentation. git(1) is, aside from cloning
+the repository, required to use the directive {git-log}. KaTeX[1] is optionally
+used for math mode.
[1]: https://katex.org
diff --git a/TODO b/TODO
@@ -11,11 +11,11 @@
[x] Remove libunistring as a dependency
- < > Remove realpath as a dependency?
+ <x> Remove realpath as a dependency?
< > Add <abbr>?
- [ ] Add width and height attributes to images (get through identify,
+ [x] Add width and height attributes to images (get through identify,
YAML variable toggle)
[ ] Investigate multiline links
diff --git a/defs.h b/defs.h
@@ -17,12 +17,6 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
-/*
- *#include <unistd.h>
- *#include <unistr.h>
- *#include <unistdio.h>
- *#include <uniwidth.h>
- */
#include "utf8.h"
diff --git a/index.slw b/index.slw
@@ -17,10 +17,10 @@ transforms custom Markdown-like syntax into HTML.
## Prerequisites
Aside from the obvious (a C compiler, by default **GNU C**), slweb requires
-**realpath**(1) to determine paths in local links and **groff**(1) and
-**gzip**(1) to create and compress documentation. **git**(1) is, aside from
-cloning the repository, required to use the directive `{git-log}`. $\KaTeX$
-([https://katex.org][katex]) is optionally used for math mode.
+**groff**(1) and **gzip**(1) to create and compress documentation. **git**(1)
+is, aside from cloning the repository, required to use the directive
+`{git-log}`. $\KaTeX$ ([https://katex.org][katex]) is optionally used for math
+mode.
## Install
diff --git a/slweb.c b/slweb.c
@@ -171,8 +171,8 @@ slweb_cleanup()
return 0;
}
-int slweb_parse(FILE* output, const u8* buffer, const BOOL body_only,
- const BOOL read_yaml_macros_and_links);
+int slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
+ const BOOL body_only, const BOOL read_yaml_macros_and_links);
BOOL
startswith(const char* s, const char* what)
@@ -932,7 +932,6 @@ process_include(FILE* output, const u8* token,
read_file_into_buffer(&input, &buffer, &buffer_size, filename,
&input_dirname);
- free(filename);
free_keyvalue(&links, links_count);
free(links);
links = NULL;
@@ -956,11 +955,12 @@ process_include(FILE* output, const u8* token,
state = ST_NONE;
/* First pass: read YAML, macros and links */
- result = slweb_parse(output, buffer, TRUE, TRUE);
+ result = slweb_parse(output, filename, buffer, TRUE, TRUE);
if (result)
{
slweb_cleanup();
+ free(filename);
free(buffer);
return result;
}
@@ -969,11 +969,12 @@ process_include(FILE* output, const u8* token,
current_inline_footnote = 0;
/* Second pass: parse and output */
- result = slweb_parse(output, buffer, TRUE, FALSE);
+ result = slweb_parse(output, filename, buffer, TRUE, FALSE);
state = saved_state;
slweb_cleanup();
+ free(filename);
free(buffer);
exit(result);
}
@@ -1089,8 +1090,9 @@ reverse_alphacompare(const struct dirent** a, const struct dirent** b)
return -1 * strcmp((*a)->d_name, (*b)->d_name);
}
-int process_timestamp(FILE* output, const u8* link_prefix, const char* link,
- const u8* permalink_macro, const u8* date);
+int process_timestamp(FILE* output, const char* source_filename,
+ const u8* link_prefix, const char* link, const u8* permalink_macro,
+ const u8* date);
int
process_incdir_subdir(FILE* output, const char* subdirname,
@@ -1126,12 +1128,6 @@ process_incdir_subdir(FILE* output, const char* subdirname,
while (names_output < names_total && pnamelist && *pnamelist)
{
int pstatus = 0;
- /*
- *char* basename = strip_ext((*pnamelist)->d_name);
- *char* link = NULL;
- *CALLOC(link, char, BUFSIZE);
- *snprintf(link, BUFSIZE, "%s/%s", subdirname, basename);
- */
fflush(output);
pid_t pid = fork();
@@ -1154,9 +1150,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
ULLONG saved_state = ST_NONE;
read_file_into_buffer(&input, &buffer, &buffer_size,
- input_filename, &input_dirname);
+ filename, &input_dirname);
- free(filename);
free_keyvalue(&links, links_count);
free(links);
links = NULL;
@@ -1180,11 +1175,13 @@ process_incdir_subdir(FILE* output, const char* subdirname,
state = ST_NONE;
/* First pass: read YAML, macros and links */
- result = slweb_parse(output, buffer, TRUE, TRUE);
+ result = slweb_parse(output, filename, buffer, TRUE,
+ TRUE);
if (result)
{
slweb_cleanup();
+ free(filename);
free(buffer);
free(abs_subdirname);
while (names_total--)
@@ -1198,12 +1195,14 @@ process_incdir_subdir(FILE* output, const char* subdirname,
current_inline_footnote = 0;
/* Second pass: parse and output */
- result = slweb_parse(output, buffer, TRUE, FALSE);
+ result = slweb_parse(output, filename, buffer, TRUE,
+ FALSE);
state = saved_state;
fflush(output);
slweb_cleanup();
+ free(filename);
free(buffer);
free(abs_subdirname);
while (names_total--)
@@ -1329,8 +1328,9 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
BOOL url_is_local(const char* url);
int
-process_timestamp(FILE* output, const u8* link_prefix, const char* link,
- const u8* permalink_macro, const u8* date)
+process_timestamp(FILE* output, const char* source_filename,
+ const u8* link_prefix, const char* link, const u8* permalink_macro,
+ const u8* date)
{
u8* day = NULL;
u8* month = NULL;
@@ -1676,44 +1676,6 @@ url_is_local(const char* url)
}
int
-get_realpath(char** realpath, const char* relativeto, const char* path)
-{
- u8* command = NULL;
- FILE* cmd_output = NULL;
-
- CALLOC(command, u8, BUFSIZE);
- strncpy(*realpath, ".", BUFSIZE - 1);
- snprintf((char*)command, BUFSIZE - 1, "realpath --relative-to=%s %s",
- relativeto, path);
-
- cmd_output = popen((char*)command, "r");
- if (cmd_output)
- {
- u8* cmd_output_line = NULL;
- CALLOC(cmd_output_line, u8, BUFSIZE);
- while (!feof(cmd_output))
- {
- if (!fgets((char*)cmd_output_line, BUFSIZE, cmd_output))
- continue;
-
- char* eol = strchr((char*)cmd_output_line, '\n');
- if (eol)
- *eol = 0;
-
- strncpy(*realpath, (char*)cmd_output_line, BUFSIZE - 1);
- }
- pclose(cmd_output);
- free(cmd_output_line);
- }
- else
- warning(1, (u8*)"get_realpath: Cannot popen");
-
- free(command);
-
- return 0;
-}
-
-int
process_inline_link(FILE* output, const u8* link_text, const u8* link_prefix,
const u8* link_macro_body, const u8* link_url)
{
@@ -1744,26 +1706,19 @@ print_image_dimensions(FILE* output, const u8* image_file_prefix, const u8* path
char command[BUFSIZE];
char cmd_output_line[BUFSIZE];
char* eol = NULL;
- char image_path[BUFSIZE];
+ char image_path[BUFSIZE - strlen(CMD_IDENTIFY)];
if (!path || !*path)
return 1;
- snprintf(image_path, BUFSIZE - 1, "%s%s%s",
+ snprintf(image_path, BUFSIZE - strlen(CMD_IDENTIFY) - 1, "%s%s%s",
image_file_prefix ? (char*)image_file_prefix : ".",
*path == '/' ? "" : "/", path);
- char cwd[BUFSIZE];
- getcwd(cwd, BUFSIZE - 1);
- fprintf(stderr, "image-file-prefix: %s\n",
- image_file_prefix ? (char*)image_file_prefix : "(NULL)");
- fprintf(stderr, "cwd: %s\n", cwd);
- fprintf(stderr, "basedir: %s\n", basedir);
- fprintf(stderr, "image_path: %s\n", image_path);
if (stat(image_path, &sb) < 0)
return 1;
- snprintf(command, BUFSIZE, CMD_IDENTIFY, image_path);
+ snprintf(command, BUFSIZE - 1, CMD_IDENTIFY, image_path);
cmd_output = popen(command, "r");
if (!cmd_output)
return error(errno, (u8*)"print_image_dimensions: Cannot popen");
@@ -1788,9 +1743,6 @@ process_inline_image(FILE* output, const u8* image_text,
const u8* image_file_prefix, const u8* link_prefix, const u8* image_url,
const BOOL add_link, const BOOL add_figcaption)
{
- int width = -1;
- int height = -1;
-
if (add_figcaption)
print_output(output, "<figure>\n");
@@ -2129,7 +2081,7 @@ end_head_start_body(FILE* output)
}
int
-begin_article(FILE* output, const u8* link_prefix,
+begin_article(FILE* output, const char* source_filename, const u8* link_prefix,
const BOOL add_article_header, const u8* author, const u8* title,
const u8* header_text, const char* title_heading_level, u8* date,
const BOOL ext_in_permalink, const char* permalink_url)
@@ -2149,9 +2101,9 @@ begin_article(FILE* output, const u8* link_prefix,
if (author)
print_output(output, "<address>%s</address>\n", author);
- if (date && input_filename)
+ if (date && source_filename)
{
- char* link = strip_ext(input_filename);
+ char* link = strip_ext((const char*)source_filename);
char* real_link = NULL;
u8* permalink_macro = get_value(macros, macros_count,
(u8*)"permalink", NULL);
@@ -2162,11 +2114,11 @@ begin_article(FILE* output, const u8* link_prefix,
BUFSIZE - strlen(link) - 1);
if (permalink_url)
- process_timestamp(output, link_prefix, permalink_url,
- permalink_macro, date);
+ process_timestamp(output, source_filename, link_prefix,
+ permalink_url, permalink_macro, date);
else
- process_timestamp(output, link_prefix, link,
- permalink_macro, date);
+ process_timestamp(output, source_filename, link_prefix,
+ link, permalink_macro, date);
free(real_link);
free(link);
@@ -2242,8 +2194,8 @@ end_body_and_html(FILE* output)
}
int
-slweb_parse(FILE* output, const u8* buffer, const BOOL body_only,
- const BOOL read_yaml_macros_and_links)
+slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
+ const BOOL body_only, const BOOL read_yaml_macros_and_links)
{
u8* title = NULL;
u8* title_heading_level = NULL;
@@ -2331,7 +2283,7 @@ slweb_parse(FILE* output, const u8* buffer, const BOOL body_only,
}
if (!read_yaml_macros_and_links)
- begin_article(output, link_prefix,
+ 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',
@@ -4553,7 +4505,7 @@ main(const int argc, const char** argv)
inline_footnote_count = 0;
/* First pass: read YAML, macros and links */
- result = slweb_parse(output, buffer, body_only, TRUE);
+ result = slweb_parse(output, input_filename, buffer, body_only, TRUE);
if (result)
{
@@ -4567,7 +4519,7 @@ main(const int argc, const char** argv)
current_inline_footnote = 0;
/* Second pass: parse and output */
- result = slweb_parse(output, buffer, body_only, FALSE);
+ result = slweb_parse(output, input_filename, buffer, body_only, FALSE);
slweb_cleanup();
free(buffer);