чување e0dbba53c09c98df77dc1411a255f01657fb3dce
родитељ acef9605cc98d6f673220e990586029d00917308
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Wed, 11 Aug 2021 17:31:02 +0200
Removed libunistring as a dependency
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | README | | | 15 | +++++++-------- |
| M | TODO | | | 2 | +- |
| M | defs.h | | | 36 | ++++++++++++------------------------ |
| M | index.html | | | 13 | ++++++------- |
| M | index.slw | | | 12 | +++++------- |
| M | slweb.c | | | 872 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
| M | slweb.do | | | 2 | +- |
| A | utf8.c | | | 161 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | utf8.h | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
измењених датотека: 9, додавања: 674(+), брисања: 479(-)
diff --git a/README b/README
@@ -9,14 +9,13 @@ transforms custom Markdown-like syntax into HTML.
Prerequisites
-------------
-Aside from the obvious (a C compiler, by default GNU C), slweb requires GNU
-libunistring[1], 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[2] is optionally used
-for math mode.
-
-[1]: https://www.gnu.org/software/libunistring/
-[2]: https://katex.org
+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.
+
+[1]: https://katex.org
Install
-------
diff --git a/TODO b/TODO
@@ -9,7 +9,7 @@
[Some (text)][somelink] - the latter should not output
<span></span>, just retain the parentheses instead
- [ ] Remove libunistring as a dependency
+ [x] Remove libunistring as a dependency
< > Remove realpath as a dependency?
diff --git a/defs.h b/defs.h
@@ -1,21 +1,4 @@
-/*
- * slweb - Simple static webpage generator
- * Copyright (C) 2020, 2021 Страхиња Радић
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- */
+/* See the file LICENSE for copyright and license details. */
#ifndef __DEFS_H
#define __DEFS_H
@@ -34,9 +17,14 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
-#include <unistr.h>
-#include <unistdio.h>
-#include <uniwidth.h>
+/*
+ *#include <unistd.h>
+ *#include <unistr.h>
+ *#include <unistdio.h>
+ *#include <uniwidth.h>
+ */
+
+#include "utf8.h"
#define PROGRAMNAME "slweb"
#define VERSION "0.3.10"
@@ -82,13 +70,13 @@ typedef enum
typedef struct
{
- uint8_t* key;
- uint8_t* value;
+ u8* key;
+ u8* value;
size_t value_size;
BOOL seen; /* for use with macros */
} KeyValue;
-typedef int (*csv_callback_t)(FILE* output, uint8_t** csv_header, uint8_t** csv_register);
+typedef int (*csv_callback_t)(FILE* output, u8** csv_header, u8** csv_register);
#ifdef __GNUC__
#pragma GCC diagnostic push
diff --git a/index.html b/index.html
@@ -35,12 +35,11 @@ transforms custom Markdown-like syntax into HTML.</p>
<h2 id="heading-2">Prerequisites</h2>
-<p>Aside from the obvious (a C compiler, by default <strong>GNU C</strong>), slweb requires GNU
-<a href="https://www.gnu.org/software/libunistring/">libunistring</a>, <strong>realpath</strong>(1) to determine paths in local links
-and <strong>groff</strong>(1) and <strong>gzip</strong>(1) to create and compress documentation.
-<strong>git</strong>(1) is, aside from cloning the repository, required to use the directive
-<code>{git-log}</code>. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span> (<a href="https://katex.org">https://katex.org</a>) is optionally used for math
-mode.</p>
+<p>Aside from the obvious (a C compiler, by default <strong>GNU C</strong>), slweb requires
+<strong>realpath</strong>(1) to determine paths in local links and <strong>groff</strong>(1) and
+<strong>gzip</strong>(1) to create and compress documentation. <strong>git</strong>(1) is, aside from
+cloning the repository, required to use the directive <code>{git-log}</code>. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>KaTeX</mtext></mrow><annotation encoding="application/x-tex">\KaTeX</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.89883em;vertical-align:-0.2155em;"></span><span class="mord text"><span class="mord textrm">K</span><span class="mspace" style="margin-right:-0.17em;"></span><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.68333em;"><span style="top:-2.904999em;"><span class="pstrut" style="height:2.7em;"></span><span class="mord"><span class="mord textrm mtight sizing reset-size6 size3">A</span></span></span></span></span></span><span class="mspace" style="margin-right:-0.15em;"></span><span class="mord text"><span class="mord textrm">T</span><span class="mspace" style="margin-right:-0.1667em;"></span><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.46782999999999997em;"><span style="top:-2.7845em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord textrm">E</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2155em;"><span></span></span></span></span><span class="mspace" style="margin-right:-0.125em;"></span><span class="mord textrm">X</span></span></span></span></span></span>
+(<a href="https://katex.org">https://katex.org</a>) is optionally used for math mode.</p>
<h2 id="heading-3">Install</h2>
@@ -153,7 +152,7 @@ this program. If not, see <<a href="https://www.gnu.org/licenses">https://www
<div id="git-log">
Previous commit:
-index.slw badbf9c 2021-08-10 14:20:51 +0200 (Страхиња Радић) (HEAD -> master, tag: v0.3.10, origin/master, origin/HEAD)
+index.slw acef960 2021-08-11 16:09:33 +0200 (Страхиња Радић) (HEAD -> master, origin/master, origin/HEAD)
</div><!--git-log-->
diff --git a/index.slw b/index.slw
@@ -16,12 +16,11 @@ transforms custom Markdown-like syntax into HTML.
## Prerequisites
-Aside from the obvious (a C compiler, by default **GNU C**), slweb requires GNU
-[libunistring][unist], **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.
+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.
## Install
@@ -143,5 +142,4 @@ this program. If not, see <[https://www.gnu.org/licenses/][licen]>.
[mtodo]: https://git.sr.ht/~strahinja/slweb/tree/master/item/TODO
[katex]: https://katex.org
[licen]: https://www.gnu.org/licenses
-[unist]: https://www.gnu.org/software/libunistring/
diff --git a/slweb.c b/slweb.c
@@ -1,21 +1,4 @@
-/*
- * slweb - Simple static webpage generator
- * Copyright (C) 2020, 2021 Страхиња Радић
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- */
+/* See the file LICENSE for copyright and license details. */
#include "defs.h"
@@ -42,17 +25,17 @@ static KeyValue* footnotes = NULL;
static KeyValue* pfootnotes = NULL;
static size_t footnote_count = 0;
static size_t current_footnote = 0;
-static uint8_t** inline_footnotes = NULL;
+static u8** inline_footnotes = NULL;
static size_t inline_footnote_count = 0;
static size_t current_inline_footnote = 0;
-static uint8_t* csv_template = NULL;
+static u8* csv_template = NULL;
static size_t csv_template_size = 0;
static char* csv_filename = NULL;
static long csv_iter = 0;
static ULLONG state = ST_NONE;
#define CHECKEXITNOMEM(ptr) { if (!ptr) exit(error(ENOMEM, \
- (uint8_t*)"Memory allocation failed (out of memory?)")); }
+ (u8*)"Memory allocation failed (out of memory?)")); }
#define CALLOC(ptr, ptrtype, nmemb) { ptr = calloc(nmemb, sizeof(ptrtype)); \
CHECKEXITNOMEM(ptr) }
@@ -69,14 +52,14 @@ static ULLONG state = ST_NONE;
{ \
size_t old_size = token_size; \
token_size += BUFSIZE; \
- REALLOC(token, uint8_t, token_size) \
+ REALLOC(token, u8, token_size) \
ptoken = token + old_size - 1; \
} \
*ptoken++ = *pline++; }
#define RESET_TOKEN(token, ptoken, token_size) { \
token_size = BUFSIZE; \
- REALLOC(token, uint8_t, token_size) \
+ REALLOC(token, u8, token_size) \
*token = 0; ptoken = token; }
#define ALL(var, mask) ( ((var) & (mask)) == (mask) )
@@ -98,12 +81,12 @@ usage()
}
int
-error(int code, uint8_t* fmt, ...)
+error(int code, u8* fmt, ...)
{
- uint8_t buf[BUFSIZE];
+ char buf[BUFSIZE];
va_list args;
va_start(args, fmt);
- u8_vsnprintf(buf, sizeof(buf), (const char*)fmt, args);
+ vsnprintf(buf, sizeof(buf), (const char*)fmt, args);
va_end(args);
fprintf(stderr, "%s:%s:%lu:%lu: %s\n", PROGRAMNAME,
input_filename ? input_filename : "(stdin)",
@@ -112,12 +95,12 @@ error(int code, uint8_t* fmt, ...)
}
int
-warning(int code, uint8_t* fmt, ...)
+warning(int code, u8* fmt, ...)
{
- uint8_t buf[BUFSIZE];
+ char buf[BUFSIZE];
va_list args;
va_start(args, fmt);
- u8_vsnprintf(buf, sizeof(buf), (const char*)fmt, args);
+ vsnprintf(buf, sizeof(buf), (const char*)fmt, args);
va_end(args);
fprintf(stderr, "Warning: %s\n", buf);
return code;
@@ -167,7 +150,7 @@ slweb_cleanup()
}
int
-slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
+slweb_parse(u8* buffer, FILE* output, BOOL body_only,
BOOL read_yaml_macros_and_links);
BOOL
@@ -186,13 +169,13 @@ startswith(const char* s, const char* what)
return !*what;
}
-uint8_t*
-get_value(KeyValue* list, size_t list_count, uint8_t* key, BOOL* seen)
+u8*
+get_value(KeyValue* list, size_t list_count, u8* key, BOOL* seen)
{
KeyValue* plist = list;
while (plist < list + list_count)
{
- if (!u8_strcmp(plist->key, key))
+ if (!strcmp((char*)plist->key, (char*)key))
{
if (seen)
{
@@ -213,7 +196,7 @@ set_basedir(char* arg, char** basedir, size_t* basedir_size)
size_t arg_len = strlen(arg);
if (arg_len < 1)
- exit(error(1, (uint8_t*)"--basedir: Argument required"));
+ exit(error(1, (u8*)"--basedir: Argument required"));
if (arg_len + 1 > *basedir_size)
{
@@ -236,7 +219,7 @@ set_global_link_prefix(char* arg, char** global_link_prefix,
size_t arg_len = strlen(arg);
if (arg_len < 1)
- exit(error(1, (uint8_t*)"--global-link-prefix: Argument required"));
+ exit(error(1, (u8*)"--global-link-prefix: Argument required"));
if (arg_len + 1 > *global_link_prefix_size)
{
@@ -275,34 +258,34 @@ strip_ext(const char* fn)
int
print_output(FILE* output, char* fmt, ...)
{
- uint8_t buf[BUFSIZE];
+ char buf[BUFSIZE];
va_list args;
if (!output || !fmt)
- exit(error(EINVAL, (uint8_t*)"print_output: Invalid argument"));
+ exit(error(EINVAL, (u8*)"print_output: Invalid argument"));
va_start(args, fmt);
if (state & ST_CSV_BODY)
{
size_t buf_len = 0;
vsnprintf((char*)buf, BUFSIZE, fmt, args);
- buf_len = u8_strlen(buf);
+ buf_len = strlen(buf);
if (!csv_template)
{
csv_template_size = BUFSIZE;
- CALLOC(csv_template, uint8_t, csv_template_size)
- u8_strncpy(csv_template, buf, BUFSIZE-1);
+ CALLOC(csv_template, u8, csv_template_size)
+ strncpy((char*)csv_template, buf, BUFSIZE-1);
*(csv_template + buf_len) = 0;
}
else
{
- if (u8_strlen(csv_template) + buf_len > csv_template_size)
+ if (strlen((char*)csv_template) + buf_len > csv_template_size)
{
csv_template_size += BUFSIZE;
- REALLOC(csv_template, uint8_t, csv_template_size)
+ REALLOC(csv_template, u8, csv_template_size)
}
- u8_strncat(csv_template, buf, csv_template_size
- - u8_strlen(csv_template) - 1);
+ strncat((char*)csv_template, buf, csv_template_size
+ - strlen((char*)csv_template) - 1);
}
}
else
@@ -316,11 +299,11 @@ print_output(FILE* output, char* fmt, ...)
int
print_command(const char* command,
- const uint8_t* pass_arguments[], const uint8_t* pipe_arguments[],
+ const u8* pass_arguments[], const u8* pipe_arguments[],
FILE* output, BOOL strip_newlines)
{
if (!command || !pass_arguments)
- exit(error(EINVAL, (uint8_t*)"print_command: Invalid argument"));
+ exit(error(EINVAL, (u8*)"print_command: Invalid argument"));
pid_t pid = 0;
int arg_pipe_fds[2];
@@ -344,7 +327,7 @@ print_command(const char* command,
exit(1);
}
else if (pid < 0)
- exit(error(errno, (uint8_t*)"Fork failed"));
+ exit(error(errno, (u8*)"Fork failed"));
/* Parent */
close(arg_pipe_fds[PIPE_READ_INDEX]);
@@ -353,11 +336,11 @@ print_command(const char* command,
FILE* cmd_output = fdopen(output_pipe_fds[PIPE_READ_INDEX], "r");
if (!cmd_input || !cmd_output)
- exit(error(1, (uint8_t*)"Cannot fdopen"));
+ exit(error(1, (u8*)"Cannot fdopen"));
if (pipe_arguments)
{
- const uint8_t** ppipe_argument = pipe_arguments;
+ const u8** ppipe_argument = pipe_arguments;
while (ppipe_argument && *ppipe_argument)
{
fprintf(cmd_input, "%s\n", *ppipe_argument);
@@ -366,8 +349,8 @@ print_command(const char* command,
}
fclose(cmd_input);
- uint8_t* cmd_output_line = NULL;
- CALLOC(cmd_output_line, uint8_t, BUFSIZE)
+ u8* cmd_output_line = NULL;
+ CALLOC(cmd_output_line, u8, BUFSIZE)
while (!feof(cmd_output))
{
if (!fgets((char*)cmd_output_line, BUFSIZE, cmd_output))
@@ -389,7 +372,7 @@ print_command(const char* command,
kill(pid, SIGKILL);
pid_t wpid = waitpid(pid, &pstatus, 0);
if (wpid < 0)
- warning(pstatus, (uint8_t*)"Child returned nonzero status, errno = %d",
+ warning(pstatus, (u8*)"Child returned nonzero status, errno = %d",
errno);
if (WIFEXITED(pstatus))
return WEXITSTATUS(pstatus);
@@ -398,7 +381,7 @@ print_command(const char* command,
}
int
-read_file_into_buffer(uint8_t** buffer, size_t* buffer_size, char* input_filename,
+read_file_into_buffer(u8** buffer, size_t* buffer_size, char* input_filename,
char** input_dirname, FILE** input)
{
struct stat fs;
@@ -406,13 +389,13 @@ read_file_into_buffer(uint8_t** buffer, size_t* buffer_size, char* input_filenam
*input = fopen(input_filename, "r");
if (!*input)
- return error(ENOENT, (uint8_t*)"No such file: %s", input_filename);
+ return error(ENOENT, (u8*)"No such file: %s", input_filename);
fstat(fileno(*input), &fs);
if (*buffer)
free(*buffer);
*buffer_size = fs.st_size+1;
- CALLOC(*buffer, uint8_t, *buffer_size)
+ CALLOC(*buffer, u8, *buffer_size)
fread((void*)*buffer, 1, *buffer_size, *input);
if (*input_dirname)
@@ -443,18 +426,18 @@ int
read_csv(FILE* output, const char* filename, csv_callback_t callback);
int
-print_meta_var(FILE* output, uint8_t** csv_header, uint8_t** csv_register)
+print_meta_var(FILE* output, u8** csv_header, u8** csv_register)
{
if (*csv_register && *(csv_register+1))
{
- uint8_t* pvalue = *(csv_register+1);
- size_t value_len = u8_strlen(pvalue);
+ u8* pvalue = *(csv_register+1);
+ size_t value_len = strlen((char*)pvalue);
if (*pvalue == '%' && *(pvalue+value_len-1) == '%')
{
- uint8_t* var_name = NULL;
- var_name = u8_strdup(pvalue+1);
+ u8* var_name = NULL;
+ var_name = (u8*)strdup((char*)pvalue+1);
*(var_name+value_len-2) = 0;
- uint8_t* value = get_value(vars, vars_count, var_name, NULL);
+ u8* value = get_value(vars, vars_count, var_name, NULL);
if (value)
print_output(output, "<meta name=\"%s\" content=\"%s\" />\n",
@@ -477,10 +460,10 @@ process_heading_start(FILE* output, UBYTE heading_level, ULONG heading_count)
}
int
-process_heading(uint8_t* token, FILE* output, UBYTE heading_level)
+process_heading(u8* token, FILE* output, UBYTE heading_level)
{
- if (!token || u8_strlen(token) < 1)
- warning(1, (uint8_t*)"Empty heading");
+ if (!token || strlen((char*)token) < 1)
+ warning(1, (u8*)"Empty heading");
print_output(output, "%s</h%d>",
token ? (char*)token : "", heading_level);
@@ -492,7 +475,7 @@ int
process_git_log(FILE* output)
{
if (!input_filename)
- return warning(1, (uint8_t*)"Cannot use 'git-log' in stdin");
+ return warning(1, (u8*)"Cannot use 'git-log' in stdin");
char* basename = NULL;
size_t basename_size = strlen(input_filename)+1;
@@ -505,19 +488,19 @@ process_git_log(FILE* output)
else
strncpy(basename, input_filename, basename_size-1);
- uint8_t* pipe_args[] = { (uint8_t*)basename, NULL };
+ u8* pipe_args[] = { (u8*)basename, NULL };
print_output(output, "<div id=\"git-log\">\nPrevious commit:\n");
result = print_command(CMD_GIT_LOG,
- (const uint8_t**)CMD_GIT_LOG_ARGS,
- (const uint8_t**)pipe_args, output, FALSE);
+ (const u8**)CMD_GIT_LOG_ARGS,
+ (const u8**)pipe_args, output, FALSE);
print_output(output, "</div><!--git-log-->\n");
output_firstcol = TRUE;
free(basename);
- return result ? warning(result, (uint8_t*)"git-log: Cannot run git") : 0;
+ return result ? warning(result, (u8*)"git-log: Cannot run git") : 0;
}
#define PRINTIF(format, arg) { \
@@ -529,9 +512,9 @@ process_git_log(FILE* output)
{ fprintf(output, format, arg); } }
int
-print_csv_row(FILE* output, uint8_t** csv_header, uint8_t** csv_register)
+print_csv_row(FILE* output, u8** csv_header, u8** csv_register)
{
- uint8_t* pcsv_template = csv_template;
+ u8* pcsv_template = csv_template;
UBYTE csv_state = ST_CS_NONE;
UBYTE num = 0;
UBYTE conditional_index = 0;
@@ -565,7 +548,7 @@ print_csv_row(FILE* output, uint8_t** csv_header, uint8_t** csv_register)
case '#':
if (csv_state & ST_CS_HEADER)
{
- error(1, (uint8_t*)"csv: Invalid header register mark");
+ error(1, (u8*)"csv: Invalid header register mark");
csv_state &= ~(ST_CS_REGISTER | ST_CS_HEADER);
}
else if (csv_state & ST_CS_REGISTER)
@@ -580,7 +563,7 @@ print_csv_row(FILE* output, uint8_t** csv_header, uint8_t** csv_register)
case '?':
if (csv_state & ST_CS_COND)
{
- error(1, (uint8_t*)"csv: Invalid conditional mark");
+ error(1, (u8*)"csv: Invalid conditional mark");
csv_state &= ~ST_CS_COND;
}
else if (csv_state & ST_CS_REGISTER)
@@ -600,7 +583,7 @@ print_csv_row(FILE* output, uint8_t** csv_header, uint8_t** csv_register)
}
else if (csv_state & ST_CS_COND)
{
- error(1, (uint8_t*)"Empty conditional before/without nonempty"
+ error(1, (u8*)"Empty conditional before/without nonempty"
" conditional");
csv_state &= ~(ST_CS_COND | ST_CS_COND_EMPTY);
}
@@ -644,12 +627,12 @@ print_csv_row(FILE* output, uint8_t** csv_header, uint8_t** csv_register)
default:
if (csv_state & ST_CS_HEADER)
{
- error(1, (uint8_t*)"csv: Invalid header register mark");
+ error(1, (u8*)"csv: Invalid header register mark");
csv_state &= ~ST_CS_HEADER;
}
else if (csv_state & ST_CS_REGISTER)
{
- error(1, (uint8_t*)"csv: Invalid register mark");
+ error(1, (u8*)"csv: Invalid register mark");
csv_state &= ~ST_CS_REGISTER;
}
else
@@ -664,40 +647,40 @@ int
read_csv(FILE* output, const char* filename, csv_callback_t callback)
{
if (!callback)
- exit(error(EINVAL, (uint8_t*)"read_csv: Invalid callback argument"));
-
- FILE* csv = NULL;
- size_t csv_lineno = 0;
- uint8_t* bufline = NULL;
- uint8_t* pbufline = NULL;
- uint8_t* token = NULL;
- uint8_t* ptoken = NULL;
- size_t token_size = 0;
- UBYTE csv_state = ST_CS_NONE;
- uint8_t* csv_header[MAX_CSV_REGISTERS];
- UBYTE current_header = 0;
- uint8_t* csv_register[MAX_CSV_REGISTERS];
- UBYTE current_register = 0;
- uint8_t* csv_delimiter = get_value(vars, vars_count,
- (uint8_t*)"csv-delimiter", NULL);
+ exit(error(EINVAL, (u8*)"read_csv: Invalid callback argument"));
+
+ FILE* csv = NULL;
+ size_t csv_lineno = 0;
+ u8* bufline = NULL;
+ u8* pbufline = NULL;
+ u8* token = NULL;
+ u8* ptoken = NULL;
+ size_t token_size = 0;
+ UBYTE csv_state = ST_CS_NONE;
+ u8* csv_header[MAX_CSV_REGISTERS];
+ 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);
if (!(csv = fopen(filename, "rt")))
- exit(error(ENOENT, (uint8_t*)"csv: No such file: %s", filename));
+ exit(error(ENOENT, (u8*)"csv: No such file: %s", filename));
- CALLOC(bufline, uint8_t, BUFSIZE)
+ CALLOC(bufline, u8, BUFSIZE)
token_size = BUFSIZE;
- CALLOC(token, uint8_t, token_size)
+ CALLOC(token, u8, token_size)
for (UBYTE i = 0; i < MAX_CSV_REGISTERS; i++)
- CALLOC(csv_header[i], uint8_t, BUFSIZE)
+ CALLOC(csv_header[i], u8, BUFSIZE)
for (UBYTE i = 0; i < MAX_CSV_REGISTERS; i++)
- CALLOC(csv_register[i], uint8_t, BUFSIZE)
+ CALLOC(csv_register[i], u8, BUFSIZE)
while (!feof(csv) && (!csv_iter || csv_lineno <= csv_iter))
{
- uint8_t* eol = NULL;
+ u8* eol = NULL;
if (!fgets((char*)bufline, BUFSIZE, csv))
break;
- eol = u8_strchr(bufline, (ucs4_t)'\n');
+ eol = (u8*)strchr((char*)bufline, '\n');
if (eol)
*eol = 0;
@@ -725,14 +708,14 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
if (csv_lineno > 0)
{
if (current_register < MAX_CSV_REGISTERS)
- u8_strncpy(csv_register[current_register++], token,
- BUFSIZE-1);
+ strncpy((char*)csv_register[current_register++],
+ (char*)token, BUFSIZE-1);
}
else
{
if (current_header < MAX_CSV_REGISTERS)
- u8_strncpy(csv_header[current_header++], token,
- BUFSIZE-1);
+ strncpy((char*)csv_header[current_header++],
+ (char*)token, BUFSIZE-1);
}
RESET_TOKEN(token, ptoken, token_size)
pbufline++;
@@ -749,14 +732,14 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
if (csv_lineno > 0)
{
if (current_register < MAX_CSV_REGISTERS)
- u8_strncpy(csv_register[current_register++], token,
- BUFSIZE-1);
+ strncpy((char*)csv_register[current_register++],
+ (char*)token, BUFSIZE-1);
}
else
{
if (current_header < MAX_CSV_REGISTERS)
- u8_strncpy(csv_header[current_header++], token,
- BUFSIZE-1);
+ strncpy((char*)csv_header[current_header++],
+ (char*)token, BUFSIZE-1);
}
RESET_TOKEN(token, ptoken, token_size)
pbufline++;
@@ -770,13 +753,14 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
if (csv_lineno > 0)
{
if (current_register < MAX_CSV_REGISTERS)
- u8_strncpy(csv_register[current_register++], token,
- BUFSIZE-1);
+ strncpy((char*)csv_register[current_register++],
+ (char*)token, BUFSIZE-1);
}
else
{
if (current_header < MAX_CSV_REGISTERS)
- u8_strncpy(csv_header[current_header++], token, BUFSIZE-1);
+ strncpy((char*)csv_header[current_header++],
+ (char*)token, BUFSIZE-1);
}
RESET_TOKEN(token, ptoken, token_size)
@@ -799,7 +783,7 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
}
int
-process_csv(uint8_t* arg_token, FILE* output, BOOL read_yaml_macros_and_links,
+process_csv(u8* arg_token, FILE* output, BOOL read_yaml_macros_and_links,
BOOL end_tag)
{
if (end_tag)
@@ -820,7 +804,7 @@ process_csv(uint8_t* arg_token, FILE* output, BOOL read_yaml_macros_and_links,
else
{
if (state & ST_CSV_BODY)
- exit(error(1, (uint8_t*)"Can't nest csv directives"));
+ exit(error(1, (u8*)"Can't nest csv directives"));
state |= ST_CSV_BODY;
@@ -828,27 +812,27 @@ process_csv(uint8_t* arg_token, FILE* output, BOOL read_yaml_macros_and_links,
return 0;
csv_iter = 0;
- uint8_t* saveptr = NULL;
- uint8_t* args = u8_strtok(arg_token, (uint8_t*)" ", &saveptr);
- args = u8_strtok(NULL, (uint8_t*)" ", &saveptr);
+ u8* saveptr = NULL;
+ u8* args = (u8*)strtok_r((char*)arg_token, " ", (char**)&saveptr);
+ args = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (!args)
- exit(error(EINVAL, (uint8_t*)"csv: Arguments required"));
- size_t args_len = u8_strlen(args);
+ exit(error(EINVAL, (u8*)"csv: Arguments required"));
+ size_t args_len = strlen((char*)args);
if (*args != '"' || *(args + args_len - 1) != '"')
- exit(error(EINVAL, (uint8_t*)"csv: First argument must be a string"));
+ exit(error(EINVAL, (u8*)"csv: First argument must be a string"));
if (!csv_filename)
- CALLOC(csv_filename, uint8_t, BUFSIZE)
- uint8_t* args_base = u8_strdup(args+1);
- *(args_base + u8_strlen(args_base) - 1) = 0;
+ CALLOC(csv_filename, u8, BUFSIZE)
+ u8* args_base = (u8*)strdup((char*)args+1);
+ *(args_base + strlen((char*)args_base) - 1) = 0;
snprintf(csv_filename, BUFSIZE, "%s/%s.csv", input_dirname, (char*)args_base);
free(args_base);
- args = u8_strtok(NULL, (uint8_t*)" ", &saveptr);
+ args = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (args)
{
errno = 0;
csv_iter = strtol((char*)args, NULL, 10);
if (errno)
- exit(error(errno, (uint8_t*)"csv: Invalid argument '%s'", args));
+ exit(error(errno, (u8*)"csv: Invalid argument '%s'", args));
}
}
@@ -856,20 +840,20 @@ process_csv(uint8_t* arg_token, FILE* output, BOOL read_yaml_macros_and_links,
}
int
-process_include(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links)
+process_include(u8* token, FILE* output, BOOL read_yaml_macros_and_links)
{
if (read_yaml_macros_and_links)
return 0;
if (!input_filename)
- return warning(1, (uint8_t*)"Cannot use 'include' in stdin");
+ return warning(1, (u8*)"Cannot use 'include' in stdin");
- uint8_t* ptoken = u8_strchr(token, (ucs4_t)' ');
+ u8* ptoken = (u8*)strchr((char*)token, ' ');
char* include_filename = NULL;
char* pinclude_filename = NULL;
if (!ptoken)
- exit(error(1, (uint8_t*)"Directive 'include' requires"
+ exit(error(1, (u8*)"Directive 'include' requires"
" an argument"));
fflush(output);
@@ -900,7 +884,7 @@ process_include(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links)
FILE* input = NULL;
FILE* output = stdout;
- uint8_t* buffer = NULL;
+ u8* buffer = NULL;
size_t buffer_size = 0;
int result = 0;
ULLONG saved_state = ST_NONE;
@@ -953,7 +937,7 @@ process_include(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links)
exit(result);
}
else
- exit(error(1, (uint8_t*)"Fork failed"));
+ exit(error(1, (u8*)"Fork failed"));
return 0;
}
@@ -1063,12 +1047,12 @@ reverse_alphacompare(const struct dirent** a, const struct dirent** b)
}
int
-process_timestamp(FILE* output, const uint8_t* link_prefix, const char* link,
- uint8_t* permalink_macro, uint8_t* date);
+process_timestamp(FILE* output, const u8* link_prefix, const char* link,
+ u8* permalink_macro, u8* date);
int
-process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
- FILE* output, BOOL details_open, uint8_t* macro_body)
+process_incdir_subdir(const char* subdirname, const u8* link_prefix,
+ FILE* output, BOOL details_open, u8* macro_body)
{
print_output(output, "<li>\n<details%s>\n<summary>",
details_open ? " open" : "");
@@ -1089,7 +1073,7 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
&reverse_alphacompare)) < 0)
{
perror("scandir");
- exit(error(errno, (uint8_t*)"incdir_subdir: scandir '%s' error",
+ exit(error(errno, (u8*)"incdir_subdir: scandir '%s' error",
abs_subdirname));
}
@@ -1118,7 +1102,7 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
FILE* input = NULL;
FILE* output = stdout;
- uint8_t* buffer = NULL;
+ u8* buffer = NULL;
size_t buffer_size = 0;
int result = 0;
ULLONG saved_state = ST_NONE;
@@ -1181,7 +1165,7 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
exit(result);
}
else
- exit(error(1, (uint8_t*)"Fork failed"));
+ exit(error(1, (u8*)"Fork failed"));
pnamelist++;
names_output++;
@@ -1198,18 +1182,19 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix,
}
int
-process_incdir(uint8_t* token, const uint8_t* link_prefix, FILE* output,
+process_incdir(u8* token, const u8* link_prefix, FILE* output,
BOOL read_yaml_macros_and_links)
{
if (read_yaml_macros_and_links)
return 0;
- uint8_t* saveptr = NULL;
+ u8* saveptr = NULL;
/* skipping the first token (incdir) */
- uint8_t* arg = u8_strtok(token, (uint8_t*)" ", &saveptr);
+ u8* arg = (u8*)strtok_r((char*)token, " ",
+ (char**)&saveptr);
size_t arg_len = 0;
long num = 5;
- uint8_t* macro_body = NULL;
+ u8* macro_body = NULL;
int names_total = 0;
struct dirent** namelist;
struct dirent** pnamelist;
@@ -1217,44 +1202,44 @@ process_incdir(uint8_t* token, const uint8_t* link_prefix, FILE* output,
BOOL details_open = TRUE;
- arg = u8_strtok(NULL, (uint8_t*)" ", &saveptr);
+ arg = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (!arg)
- exit(error(1, (uint8_t*)"incdir: Arguments required"));
+ exit(error(1, (u8*)"incdir: Arguments required"));
- arg_len = u8_strlen(arg);
+ arg_len = strlen((char*)arg);
if (*arg != '"' || *(arg + arg_len - 1) != '"')
- exit(error(1, (uint8_t*)"incdir: First argument not string"));
+ exit(error(1, (u8*)"incdir: First argument not string"));
incdir = strdup((char*)(arg+1));
*(incdir + strlen(incdir) - 1) = 0;
- arg = u8_strtok(NULL, (uint8_t*)" ", &saveptr);
+ arg = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (!arg)
- exit(error(1, (uint8_t*)"incdir: Second argument required"));
+ exit(error(1, (u8*)"incdir: Second argument required"));
if (*arg == '=')
macro_body = get_value(macros, macros_count, arg+1, NULL);
else
{
- uint8_t* parg = arg;
+ u8* parg = arg;
while (parg && *parg)
{
if (*parg < '0' || *parg > '9')
- exit(error(1, (uint8_t*)"incdir: Non-numeric argument"));
+ exit(error(1, (u8*)"incdir: Non-numeric argument"));
parg++;
}
errno = 0;
num = strtol((char*)arg, NULL, 10);
if (errno)
- exit(error(errno, (uint8_t*)"incdir: Invalid parameter 'num'"));
- arg = u8_strtok(NULL, (uint8_t*)" ", &saveptr);
+ exit(error(errno, (u8*)"incdir: Invalid parameter 'num'"));
+ arg = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (arg)
{
if (*arg != '=')
{
free(incdir);
- exit(error(1, (uint8_t*)"incdir: Third argument not macro"));
+ exit(error(1, (u8*)"incdir: Third argument not macro"));
}
macro_body = get_value(macros, macros_count, arg+1, NULL);
}
@@ -1266,7 +1251,7 @@ process_incdir(uint8_t* token, const uint8_t* link_prefix, FILE* output,
&reverse_alphacompare)) < 0)
{
perror("scandir");
- exit(error(errno, (uint8_t*)"incdir: scandir '%s' error", incdir));
+ exit(error(errno, (u8*)"incdir: scandir '%s' error", incdir));
}
pnamelist = namelist;
@@ -1294,27 +1279,27 @@ BOOL
url_is_local(const char* url);
int
-process_timestamp(FILE* output, const uint8_t* link_prefix, const char* link,
- uint8_t* permalink_macro, uint8_t* date)
+process_timestamp(FILE* output, const u8* link_prefix, const char* link,
+ u8* permalink_macro, u8* date)
{
- uint8_t* day = NULL;
- uint8_t* month = NULL;
- uint8_t* year = NULL;
- uint8_t* formatted_date = NULL;
- uint8_t* ptr = NULL;
+ u8* day = NULL;
+ u8* month = NULL;
+ u8* year = NULL;
+ u8* formatted_date = NULL;
+ u8* ptr = NULL;
const char* ptimestamp_format = NULL;
char* in_filename = NULL;
char* in_line = NULL;
- CALLOC(formatted_date, uint8_t, DATEBUFSIZE)
+ CALLOC(formatted_date, u8, DATEBUFSIZE)
ptr = NULL;
- year = u8_strtok(date, (uint8_t*)"-", &ptr);
+ year = (u8*)strtok_r((char*)date, "-", (char**)&ptr);
if (year)
{
- month = u8_strtok(NULL, (uint8_t*)"-", &ptr);
+ month = (u8*)strtok_r(NULL, "-", (char**)&ptr);
if (month)
{
- day = u8_strtok(NULL, (uint8_t*)"T", &ptr);
+ day = (u8*)strtok_r(NULL, "T", (char**)&ptr);
if (day)
{
ptimestamp_format = timestamp_format;
@@ -1322,18 +1307,18 @@ process_timestamp(FILE* output, const uint8_t* link_prefix, const char* link,
{
if (*ptimestamp_format == 'd'
|| *ptimestamp_format == 'D')
- u8_strncat(formatted_date, day,
- DATEBUFSIZE-u8_strlen(formatted_date)-1);
+ strncat((char*)formatted_date, (char*)day,
+ DATEBUFSIZE-strlen((char*)formatted_date)-1);
else if (*ptimestamp_format == 'm'
|| *ptimestamp_format == 'M')
- u8_strncat(formatted_date, month,
- DATEBUFSIZE-u8_strlen(formatted_date)-1);
+ strncat((char*)formatted_date, (char*)month,
+ DATEBUFSIZE-strlen((char*)formatted_date)-1);
else if (*ptimestamp_format == 'y'
|| *ptimestamp_format == 'Y')
- u8_strncat(formatted_date, year,
- DATEBUFSIZE-u8_strlen(formatted_date)-1);
+ strncat((char*)formatted_date, (char*)year,
+ DATEBUFSIZE-strlen((char*)formatted_date)-1);
else
- *(formatted_date + u8_strlen(formatted_date))
+ *(formatted_date + strlen((char*)formatted_date))
= *ptimestamp_format;
ptimestamp_format++;
@@ -1360,16 +1345,16 @@ process_timestamp(FILE* output, const uint8_t* link_prefix, const char* link,
}
int
-process_macro(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links,
+process_macro(u8* token, FILE* output, BOOL read_yaml_macros_and_links,
BOOL end_tag)
{
if (!end_tag)
{
if (state & ST_MACRO_BODY)
- exit(error(1, (uint8_t*)"Macro undefined or nested"));
+ exit(error(1, (u8*)"Macro undefined or nested"));
BOOL seen = FALSE;
- uint8_t* macro_body = get_value(macros, macros_count, token+1,
+ u8* macro_body = get_value(macros, macros_count, token+1,
read_yaml_macros_and_links ? NULL : &seen);
if (macro_body)
@@ -1378,11 +1363,11 @@ process_macro(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links,
{
if (seen)
{
- uint8_t* eol = u8_strrchr(macro_body, '\n');
- size_t macro_body_len = u8_strlen(macro_body);
+ 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(macro_body, '\n') > 0;
+ (u8*)strrchr((char*)macro_body, '\n') > 0;
else
output_firstcol = !*macro_body
|| *(macro_body+macro_body_len-1) == '\n';
@@ -1408,9 +1393,9 @@ process_macro(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links,
REALLOC(macros, KeyValue, macros_count * sizeof(KeyValue))
pmacros = macros + macros_count - 1;
}
- CALLOC(pmacros->key, uint8_t, KEYSIZE)
+ CALLOC(pmacros->key, u8, KEYSIZE)
pmacros->seen = FALSE;
- u8_strncpy(pmacros->key, token+1, KEYSIZE-1);
+ strncpy((char*)pmacros->key, (char*)token+1, KEYSIZE-1);
pmacros->value = NULL;
pmacros->value_size = 0;
}
@@ -1424,11 +1409,11 @@ process_macro(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links,
}
int
-process_tag(uint8_t* token, const uint8_t* link_prefix, FILE* output,
+process_tag(u8* token, const u8* link_prefix, FILE* output,
BOOL read_yaml_macros_and_links, BOOL* skip_eol, BOOL end_tag)
{
- if (!token || u8_strlen(token) < 1)
- return warning(1, (uint8_t*)"%s:%ld:%ld: Empty tag name",
+ if (!token || strlen((char*)token) < 1)
+ return warning(1, (u8*)"%s:%ld:%ld: Empty tag name",
input_filename, lineno, colno);
if (!strcmp((char*)token, "git-log")
@@ -1638,19 +1623,19 @@ url_is_local(const char* url)
int
get_realpath(char** realpath, char* relativeto, char* path)
{
- uint8_t* command = NULL;
+ u8* command = NULL;
FILE* cmd_output = NULL;
- CALLOC(command, uint8_t, BUFSIZE)
+ CALLOC(command, u8, BUFSIZE)
strncpy(*realpath, ".", BUFSIZE-1);
- u8_snprintf(command, BUFSIZE-1, "realpath --relative-to=%s %s",
+ snprintf((char*)command, BUFSIZE-1, "realpath --relative-to=%s %s",
relativeto, path);
cmd_output = popen((char*)command, "r");
if (cmd_output)
{
- uint8_t* cmd_output_line = NULL;
- CALLOC(cmd_output_line, uint8_t, BUFSIZE)
+ u8* cmd_output_line = NULL;
+ CALLOC(cmd_output_line, u8, BUFSIZE)
while (!feof(cmd_output))
{
if (!fgets((char*)cmd_output_line, BUFSIZE, cmd_output))
@@ -1666,7 +1651,7 @@ get_realpath(char** realpath, char* relativeto, char* path)
free(cmd_output_line);
}
else
- warning(1, (uint8_t*)"get_realpath: Cannot popen");
+ warning(1, (u8*)"get_realpath: Cannot popen");
free(command);
@@ -1674,8 +1659,8 @@ get_realpath(char** realpath, char* relativeto, char* path)
}
int
-process_inline_link(uint8_t* link_text, const uint8_t* link_prefix,
- uint8_t* link_macro_body, uint8_t* link_url, FILE* output)
+process_inline_link(u8* link_text, const u8* link_prefix,
+ u8* link_macro_body, u8* link_url, FILE* output)
{
print_output(output, "<a href=\"%s%s%s\">%s%s</a>",
global_link_prefix ? (const char*)global_link_prefix : "",
@@ -1689,17 +1674,17 @@ process_inline_link(uint8_t* link_text, const uint8_t* link_prefix,
}
int
-process_link(uint8_t* link_text, const uint8_t* link_prefix,
- uint8_t* link_macro_body, uint8_t* link_id, FILE* output)
+process_link(u8* link_text, const u8* link_prefix,
+ u8* link_macro_body, u8* link_id, FILE* output)
{
- uint8_t* url = get_value(links, links_count, link_id, NULL);
+ u8* url = get_value(links, links_count, link_id, NULL);
return process_inline_link(link_text, link_prefix, link_macro_body, url,
output);
}
int
-process_inline_image(uint8_t* image_text, const uint8_t* link_prefix,
- uint8_t* image_url, FILE* output, BOOL add_link, BOOL add_figcaption)
+process_inline_image(u8* image_text, const u8* link_prefix,
+ u8* image_url, FILE* output, BOOL add_link, BOOL add_figcaption)
{
if (add_figcaption)
print_output(output, "<figure>\n");
@@ -1730,19 +1715,19 @@ process_inline_image(uint8_t* image_text, const uint8_t* link_prefix,
}
int
-process_image(uint8_t* image_text, const uint8_t* link_prefix,
- uint8_t* image_id, FILE* output, BOOL add_link, BOOL add_figcaption)
+process_image(u8* image_text, const u8* link_prefix,
+ u8* image_id, FILE* output, BOOL add_link, BOOL add_figcaption)
{
- uint8_t* url = get_value(links, links_count, image_id, NULL);
+ u8* url = get_value(links, links_count, image_id, NULL);
return process_inline_image(image_text, link_prefix, url, output, add_link,
add_figcaption);
}
int
-process_line_start(uint8_t* line, const uint8_t* link_prefix,
+process_line_start(u8* line, const u8* link_prefix,
BOOL first_line_in_doc, BOOL previous_line_blank,
BOOL read_yaml_macros_and_links, BOOL list_para, FILE* output,
- uint8_t** token, uint8_t** ptoken)
+ u8** token, u8** ptoken)
{
if ((first_line_in_doc || previous_line_blank)
&& !(ANY(state, ST_BLOCKQUOTE | ST_PRE)))
@@ -1793,10 +1778,10 @@ process_line_start(uint8_t* line, const uint8_t* link_prefix,
}
int
-process_text_token(uint8_t* line, const uint8_t* link_prefix,
+process_text_token(u8* line, const u8* link_prefix,
BOOL first_line_in_doc, BOOL previous_line_blank, BOOL
processed_start_of_line, BOOL read_yaml_macros_and_links,
- BOOL list_para, FILE* output, uint8_t** token, uint8_t** ptoken,
+ BOOL list_para, FILE* output, u8** token, u8** ptoken,
size_t* token_size, BOOL add_enclosing_paragraph)
{
if (!(state & ST_YAML))
@@ -1810,9 +1795,9 @@ process_text_token(uint8_t* line, const uint8_t* link_prefix,
&& !(state & ST_MACRO_BODY))
{
print_output(output, "%s", *token);
- uint8_t* eol = u8_strrchr(*token, '\n');
+ u8* eol = (u8*)strrchr((char*)*token, '\n');
if (eol)
- output_firstcol = *token + u8_strlen(*token) - eol > 0;
+ output_firstcol = *token + strlen((char*)*token) - eol > 0;
else
output_firstcol = FALSE;
}
@@ -1822,34 +1807,35 @@ process_text_token(uint8_t* line, const uint8_t* link_prefix,
}
int
-process_inline_footnote(uint8_t* token, BOOL read_yaml_macros_and_links,
+process_inline_footnote(u8* token, BOOL read_yaml_macros_and_links,
FILE* output)
{
current_inline_footnote++;
if (read_yaml_macros_and_links)
{
- size_t token_len = u8_strlen(token);
+ size_t token_len = strlen((char*)token);
inline_footnote_count++;
if (inline_footnote_count == 1 && footnote_count > 0)
- warning(1, (uint8_t*)"Both inline and regular footnotes present");
+ warning(1, (u8*)"Both inline and regular footnotes present");
else if (!inline_footnotes)
{
inline_footnote_count = 1;
- CALLOC(inline_footnotes, uint8_t*, inline_footnote_count)
+ CALLOC(inline_footnotes, u8*, inline_footnote_count)
}
else
- REALLOC(inline_footnotes, uint8_t*, sizeof(uint8_t*) * inline_footnote_count)
- CALLOC(inline_footnotes[inline_footnote_count-1], uint8_t, token_len+1)
+ REALLOC(inline_footnotes, u8*, sizeof(u8*) * inline_footnote_count)
+ CALLOC(inline_footnotes[inline_footnote_count-1], u8, token_len+1)
- u8_strncpy(inline_footnotes[inline_footnote_count-1], token, token_len);
+ strncpy((char*)inline_footnotes[inline_footnote_count-1], (char*)token,
+ token_len);
*(inline_footnotes[inline_footnote_count-1] + token_len) = 0;
}
else
{
- print_output(output, "<a href=\"#inline-footnote-%d\" id=\"inline-footnote-text-%d\">"
- "<sup>%d</sup></a>",
+ print_output(output, "<a href=\"#inline-footnote-%d\" "
+ "id=\"inline-footnote-text-%d\"><sup>%d</sup></a>",
current_inline_footnote, current_inline_footnote,
current_inline_footnote);
output_firstcol = FALSE;
@@ -1859,7 +1845,7 @@ process_inline_footnote(uint8_t* token, BOOL read_yaml_macros_and_links,
}
int
-process_footnote(uint8_t* token, BOOL footnote_definition, BOOL footnote_output,
+process_footnote(u8* token, BOOL footnote_definition, BOOL footnote_output,
FILE* output)
{
current_footnote++;
@@ -1868,7 +1854,7 @@ process_footnote(uint8_t* token, BOOL footnote_definition, BOOL footnote_output,
{
footnote_count++;
if (footnote_count == 1 && inline_footnote_count > 0)
- warning(1, (uint8_t*)"Both inline and regular footnotes present");
+ warning(1, (u8*)"Both inline and regular footnotes present");
else if (!footnotes)
{
CALLOC(footnotes, KeyValue, footnote_count)
@@ -1879,8 +1865,8 @@ process_footnote(uint8_t* token, BOOL footnote_definition, BOOL footnote_output,
REALLOCARRAY(footnotes, KeyValue, footnote_count)
pfootnotes = footnotes + footnote_count - 1;
}
- CALLOC(pfootnotes->key, uint8_t, KEYSIZE)
- u8_strncpy(pfootnotes->key, token, KEYSIZE-1);
+ CALLOC(pfootnotes->key, u8, KEYSIZE)
+ strncpy((char*)pfootnotes->key, (char*)token, KEYSIZE-1);
pfootnotes->value = NULL;
pfootnotes->value_size = 0;
}
@@ -1910,16 +1896,16 @@ process_horizontal_rule(FILE* output)
}
int
-process_formula(FILE* output, const uint8_t* token, BOOL display_formula)
+process_formula(FILE* output, const u8* token, BOOL display_formula)
{
int result = 0;
- const uint8_t* pipe_args[] = { token, NULL};
+ const u8* pipe_args[] = { token, NULL};
result = print_command(CMD_KATEX,
display_formula
- ? (const uint8_t**)CMD_KATEX_DISPLAY_ARGS
- : (const uint8_t**)CMD_KATEX_INLINE_ARGS,
- (const uint8_t**)pipe_args, output, TRUE);
+ ? (const u8**)CMD_KATEX_DISPLAY_ARGS
+ : (const u8**)CMD_KATEX_INLINE_ARGS,
+ (const u8**)pipe_args, output, TRUE);
if (result)
{
@@ -1936,14 +1922,14 @@ process_formula(FILE* output, const uint8_t* token, BOOL display_formula)
int
begin_html_and_head(FILE* output)
{
- uint8_t* lang = get_value(vars, vars_count, (uint8_t*)"lang", NULL);
- uint8_t* site_name = get_value(vars, vars_count, (uint8_t*)"site-name", NULL);
- uint8_t* site_desc = get_value(vars, vars_count, (uint8_t*)"site-desc", NULL);
- 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);
+ u8* lang = get_value(vars, vars_count, (u8*)"lang", NULL);
+ u8* site_name = get_value(vars, vars_count, (u8*)"site-name", NULL);
+ u8* site_desc = get_value(vars, vars_count, (u8*)"site-desc", NULL);
+ u8* canonical = get_value(vars, vars_count, (u8*)"canonical", NULL);
+ u8* favicon_url = get_value(vars, vars_count, (u8*)"favicon-url", NULL);
+ u8* meta = get_value(vars, vars_count, (u8*)"meta", NULL);
+ u8* feed = get_value(vars, vars_count, (u8*)"feed", NULL);
+ u8* feed_desc = get_value(vars, vars_count, (u8*)"feed-desc", NULL);
print_output(output, "<!DOCTYPE html>\n"
"<html lang=\"%s\">\n"
@@ -1998,7 +1984,7 @@ add_css(FILE* output)
KeyValue* pvars = vars;
while (pvars < vars + vars_count)
{
- if (!u8_strcmp(pvars->key, (uint8_t*)"stylesheet"))
+ if (!strcmp((char*)pvars->key, "stylesheet"))
{
print_output(output, "<link rel=\"stylesheet\" href=\"%s\" />\n",
pvars->value);
@@ -2019,10 +2005,10 @@ end_head_start_body(FILE* output)
}
int
-begin_article(FILE* output, const uint8_t* link_prefix,
- const BOOL add_article_header, const uint8_t* author,
- const uint8_t* title, const uint8_t* header_text,
- const char* title_heading_level, uint8_t* date,
+begin_article(FILE* output, 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)
{
if (author || date || header_text || title)
@@ -2044,11 +2030,11 @@ begin_article(FILE* output, const uint8_t* link_prefix,
if (date && input_filename)
{
char* link = strip_ext(input_filename);
- uint8_t* samedir_permalink = get_value(vars, vars_count,
- (uint8_t*)"samedir-permalink", NULL);
+ u8* samedir_permalink = get_value(vars, vars_count,
+ (u8*)"samedir-permalink", NULL);
char* real_link = NULL;
- uint8_t* permalink_macro = get_value(macros, macros_count,
- (uint8_t*)"permalink", NULL);
+ u8* permalink_macro = get_value(macros, macros_count,
+ (u8*)"permalink", NULL);
CALLOC(real_link, char, BUFSIZE)
if (ext_in_permalink)
@@ -2057,7 +2043,7 @@ begin_article(FILE* output, const uint8_t* link_prefix,
if (permalink_url)
process_timestamp(output, link_prefix, permalink_url,
permalink_macro, date);
- else if (samedir_permalink && !u8_strcmp(samedir_permalink, (uint8_t*)"1"))
+ else if (samedir_permalink && !strcmp((char*)samedir_permalink, "1"))
{
get_realpath(&real_link, input_dirname, link);
process_timestamp(output, link_prefix, real_link, permalink_macro,
@@ -2138,31 +2124,31 @@ end_body_and_html(FILE* output)
}
int
-slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
+slweb_parse(u8* buffer, FILE* output, BOOL body_only,
BOOL read_yaml_macros_and_links)
{
- uint8_t* title = NULL;
- uint8_t* title_heading_level = NULL;
- uint8_t* header_text = NULL;
- uint8_t* author = NULL;
- uint8_t* date = NULL;
- uint8_t* permalink_url = NULL;
- uint8_t* ext_in_permalink = NULL;
- uint8_t* var_add_article_header = NULL;
- uint8_t* var_add_image_links = NULL;
- uint8_t* var_add_figcaption = NULL;
- uint8_t* var_add_footnote_div = NULL;
- uint8_t* link_prefix = NULL;
- uint8_t* pbuffer = NULL;
- uint8_t* line = NULL;
- uint8_t* pline = NULL;
+ u8* title = NULL;
+ u8* title_heading_level = NULL;
+ u8* header_text = NULL;
+ u8* author = NULL;
+ u8* date = NULL;
+ u8* permalink_url = NULL;
+ u8* ext_in_permalink = NULL;
+ u8* var_add_article_header = NULL;
+ u8* var_add_image_links = NULL;
+ u8* var_add_figcaption = NULL;
+ u8* var_add_footnote_div = NULL;
+ u8* link_prefix = NULL;
+ u8* pbuffer = NULL;
+ u8* line = NULL;
+ u8* pline = NULL;
size_t line_len = 0;
- uint8_t* token = NULL;
- uint8_t* ptoken = NULL;
+ u8* token = NULL;
+ u8* ptoken = NULL;
size_t token_size = 0;
- uint8_t* link_text = NULL;
+ u8* link_text = NULL;
size_t link_size = 0;
- uint8_t* link_macro = NULL;
+ u8* link_macro = NULL;
UBYTE heading_level = 0;
ULONG heading_count = 0;
BOOL end_tag = FALSE;
@@ -2180,28 +2166,28 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
size_t pline_len = 0;
if (!buffer)
- 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);
- 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);
- permalink_url = get_value(vars, vars_count, (uint8_t*)"permalink-url", NULL);
- ext_in_permalink = get_value(vars, vars_count, (uint8_t*)"ext-in-permalink", NULL);
- var_add_article_header = get_value(vars, vars_count, (uint8_t*)"add-article-header", NULL);
- var_add_image_links = get_value(vars, vars_count, (uint8_t*)"add-image-links", NULL);
+ exit(error(1, (u8*)"Empty buffer"));
+
+ title = get_value(vars, vars_count, (u8*)"title", NULL);
+ 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);
+ var_add_article_header = get_value(vars, vars_count, (u8*)"add-article-header", NULL);
+ var_add_image_links = get_value(vars, vars_count, (u8*)"add-image-links", NULL);
add_image_links = !(var_add_image_links && *var_add_image_links == '0');
- var_add_figcaption = get_value(vars, vars_count, (uint8_t*)"add-figcaption", NULL);
+ var_add_figcaption = get_value(vars, vars_count, (u8*)"add-figcaption", NULL);
add_figcaption = !(var_add_figcaption && *var_add_figcaption == '0');
- var_add_footnote_div = get_value(vars, vars_count, (uint8_t*)"add-footnote-div", NULL);
+ var_add_footnote_div = get_value(vars, vars_count, (u8*)"add-footnote-div", NULL);
add_footnote_div = var_add_footnote_div && *var_add_footnote_div == '1';
- link_prefix = get_value(vars, vars_count, (uint8_t*)"link-prefix", NULL);
+ link_prefix = get_value(vars, vars_count, (u8*)"link-prefix", NULL);
- CALLOC(line, uint8_t, BUFSIZE)
+ CALLOC(line, u8, BUFSIZE)
token_size = BUFSIZE;
- CALLOC(token, uint8_t, BUFSIZE)
- CALLOC(link_macro, uint8_t, BUFSIZE)
+ CALLOC(token, u8, BUFSIZE)
+ CALLOC(link_macro, u8, BUFSIZE)
pbuffer = buffer;
pvars = vars;
@@ -2228,7 +2214,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
do
{
- uint8_t* eol = u8_strchr(pbuffer, (ucs4_t)'\n');
+ u8* eol = (u8*)strchr((char*)pbuffer, '\n');
if (!eol)
break;
@@ -2238,7 +2224,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
pbuffer++;
*pline = 0;
pline = line;
- line_len = u8_strlen(line);
+ line_len = strlen((char*)line);
lineno++;
colno = 1;
@@ -2260,7 +2246,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
colno++;
}
else if (colno == 1
- && u8_strlen(pline) > 2
+ && strlen((char*)pline) > 2
&& startswith((char*)pline, "---"))
{
skip_eol = TRUE;
@@ -2280,7 +2266,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
pline = NULL;
}
else if (colno == 1
- && u8_strlen(pline) > 1
+ && strlen((char*)pline) > 1
&& *(pline+1) == ' ')
{
if (state & ST_NUMLIST)
@@ -2338,8 +2324,8 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
REALLOCARRAY(vars, KeyValue, vars_count)
pvars = vars + vars_count - 1;
}
- CALLOC(pvars->key, uint8_t, KEYSIZE)
- u8_strncpy(pvars->key, token, KEYSIZE-1);
+ CALLOC(pvars->key, u8, KEYSIZE)
+ strncpy((char*)pvars->key, (char*)token, KEYSIZE-1);
pvars->value = NULL;
pvars->value_size = 0;
@@ -2371,22 +2357,23 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) > 1 && *(pline+1) == '~')
+ 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))
{
- uint8_t* entity = (uint8_t*)" ";
- size_t entity_len = u8_strlen(entity);
+ u8* entity = (u8*)" ";
+ size_t entity_len = strlen((char*)entity);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + entity_len < BUFSIZE)
{
- u8_strncat(token, entity, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)entity,
+ BUFSIZE-token_len-1);
ptoken += entity_len;
}
}
@@ -2413,18 +2400,19 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (ANY(state, ST_INLINE_FOOTNOTE | ST_HEADING
| ST_FOOTNOTE_TEXT | ST_LINK))
{
- uint8_t* tag = state & ST_STRIKE
- ? (uint8_t*)"</s>"
- : (uint8_t*)"<s>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = state & ST_STRIKE
+ ? (u8*)"</s>"
+ : (u8*)"<s>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
}
@@ -2459,7 +2447,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
if (colno == 1
- && u8_strlen(pline) > 2
+ && strlen((char*)pline) > 2
&& startswith((char*)pline, "```"))
{
state ^= ST_PRE;
@@ -2482,18 +2470,19 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (ANY(state, ST_INLINE_FOOTNOTE | ST_HEADING
| ST_FOOTNOTE_TEXT | ST_LINK))
{
- uint8_t* tag = state & ST_CODE
- ? (uint8_t*)"</code>"
- : (uint8_t*)"<code>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = state & ST_CODE
+ ? (u8*)"</code>"
+ : (u8*)"<code>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
}
@@ -2578,24 +2567,25 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) > 1 && *(pline+1) == '_')
+ 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))
{
- uint8_t* tag = state & ST_BOLD
- ? (uint8_t*)"</strong>"
- : (uint8_t*)"<strong>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = state & ST_BOLD
+ ? (u8*)"</strong>"
+ : (u8*)"<strong>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
}
@@ -2623,18 +2613,19 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (ANY(state, ST_INLINE_FOOTNOTE | ST_HEADING
| ST_FOOTNOTE_TEXT | ST_LINK))
{
- uint8_t* tag = state & ST_ITALIC
- ? (uint8_t*)"</em>"
- : (uint8_t*)"<em>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = state & ST_ITALIC
+ ? (u8*)"</em>"
+ : (u8*)"<em>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
}
@@ -2669,7 +2660,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
if (colno == 1
- && u8_strlen(pline) > 1
+ && strlen((char*)pline) > 1
&& *(pline+1) == ' ')
{
if (state & ST_NUMLIST)
@@ -2716,7 +2707,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- pline_len = u8_strlen(pline);
+ pline_len = strlen((char*)pline);
if (colno == 1
&& pline_len > 1 && *(pline+1) == '[')
{
@@ -2736,7 +2727,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
pline = NULL;
}
else if (colno == 1
- && u8_strlen(pline) > 1
+ && strlen((char*)pline) > 1
&& *(pline+1) == ' ')
{
if (state & ST_NUMLIST)
@@ -2772,18 +2763,19 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (ANY(state, ST_INLINE_FOOTNOTE | ST_HEADING
| ST_FOOTNOTE_TEXT | ST_LINK))
{
- uint8_t* tag = state & ST_BOLD
- ? (uint8_t*)"</strong>"
- : (uint8_t*)"<strong>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = state & ST_BOLD
+ ? (u8*)"</strong>"
+ : (u8*)"<strong>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
}
@@ -2812,18 +2804,19 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
| ST_FOOTNOTE_TEXT | ST_LINK))
{
- uint8_t* tag = state & ST_ITALIC
- ? (uint8_t*)"</em>"
- : (uint8_t*)"<em>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = state & ST_ITALIC
+ ? (u8*)"</em>"
+ : (u8*)"<em>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
}
@@ -2872,7 +2865,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
if (colno == 1
- && u8_strlen(pline) > 1
+ && strlen((char*)pline) > 1
&& startswith((char*)pline, " "))
{
list_para = TRUE;
@@ -2889,12 +2882,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) == 2
+ if (strlen((char*)pline) == 2
&& *(pline+1) == ' ')
{
*ptoken = 0;
- u8_strncat(ptoken, (uint8_t*)"<br />",
- BUFSIZE-u8_strlen(token)-1);
+ strncat((char*)ptoken, "<br />",
+ BUFSIZE-strlen((char*)token)-1);
ptoken += strlen("<br />");
output_firstcol = FALSE;
pline++;
@@ -2903,8 +2896,8 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
else if (state & ST_LINK_MACRO)
{
*ptoken = 0;
- u8_strncpy(link_macro, token, BUFSIZE-1);
- *(link_macro + u8_strlen(token)) = 0;
+ strncpy((char*)link_macro, (char*)token, BUFSIZE-1);
+ *(link_macro + strlen((char*)token)) = 0;
RESET_TOKEN(token, ptoken, token_size)
state &= ~ST_LINK_MACRO;
}
@@ -2926,7 +2919,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (state & ST_MACRO_BODY)
{
*ptoken = 0;
- size_t token_len = u8_strlen(token);
+ size_t token_len = strlen((char*)token);
skip_eol = TRUE;
if (read_yaml_macros_and_links)
@@ -2939,20 +2932,22 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
if (pmacros->value)
{
- size_t value_len = u8_strlen(pmacros->value);
+ size_t value_len = strlen((char*)pmacros->value);
if (pmacros->value_size < value_len + token_len + 1)
{
pmacros->value_size += token_len;
- REALLOC(pmacros->value, uint8_t, pmacros->value_size)
+ REALLOC(pmacros->value, u8, pmacros->value_size)
}
- u8_strncat(pmacros->value, token, pmacros->value_size-1);
+ strncat((char*)pmacros->value, (char*)token,
+ pmacros->value_size-1);
}
else
{
pmacros->value_size = token_len+1;
- CALLOC(pmacros->value, uint8_t, pmacros->value_size)
- u8_strncpy(pmacros->value, token, pmacros->value_size-1);
+ CALLOC(pmacros->value, u8, pmacros->value_size)
+ strncpy((char*)pmacros->value, (char*)token,
+ pmacros->value_size-1);
}
}
}
@@ -3028,24 +3023,25 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) > 1 && *(pline+1) == '|')
+ 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))
{
- uint8_t* tag = state & ST_KBD
- ? (uint8_t*)"</kbd>"
- : (uint8_t*)"<kbd>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = state & ST_KBD
+ ? (u8*)"</kbd>"
+ : (u8*)"<kbd>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
}
@@ -3071,8 +3067,9 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
colno += 2;
}
/* Partial tables (for templating) */
- else if (!(state & ST_PRE) && colno == 1 && u8_strlen(pline) > 1
- && *(pline+1) == '@')
+ else if (!(state & ST_PRE) && colno == 1
+ && strlen((char*)pline) > 1
+ && *(pline+1) == '@')
{
skip_eol = TRUE;
@@ -3123,7 +3120,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
default:
- warning(1, (uint8_t*)"Invalid partial table line");
+ warning(1, (u8*)"Invalid partial table line");
CHECKCOPY(token, ptoken, token_size, pline)
colno++;
}
@@ -3179,7 +3176,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
print_output(output, "%s", token);
if (*token)
output_firstcol = FALSE;
- if (u8_strlen(pline) > 1)
+ if (strlen((char*)pline) > 1)
{
process_table_header_cell(output);
output_firstcol = FALSE;
@@ -3202,7 +3199,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
print_output(output, "%s", token);
if (*token)
output_firstcol = FALSE;
- if (u8_strlen(pline) > 1)
+ if (strlen((char*)pline) > 1)
{
process_table_body_cell(output);
output_firstcol = FALSE;
@@ -3236,9 +3233,9 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (ANY(state, ST_CODE | ST_KBD | ST_PRE))
{
- size_t lt_len = u8_strlen((uint8_t*)"<");
+ size_t lt_len = strlen("<");
*ptoken = 0;
- u8_strncat(token, (uint8_t*)"<",
+ strncat((char*)token, "<",
BUFSIZE-(ptoken-token)-1);
ptoken += lt_len;
pline++;
@@ -3297,7 +3294,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) > 1 && *(pline+1) == '[')
+ if (strlen((char*)pline) > 1 && *(pline+1) == '[')
{
/* Output existing text up to ! */
*ptoken = 0;
@@ -3345,7 +3342,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
case '[':
- pline_len = u8_strlen(pline);
+ pline_len = strlen((char*)pline);
if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA
| ST_HEADING | ST_IMAGE | ST_MACRO_BODY | ST_PRE))
@@ -3405,16 +3402,16 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (*pline == '(')
{
- uint8_t* tag = (uint8_t*)"<span>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = (u8*)"<span>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag, BUFSIZE-token_len-1);
ptoken += tag_len;
}
@@ -3433,16 +3430,17 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
CHECKCOPY(token, ptoken, token_size, pline)
else if (*link_macro && (state & ST_LINK))
{
- uint8_t* tag = (uint8_t*)"<span>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = (u8*)"<span>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
@@ -3463,21 +3461,22 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- pline_len = u8_strlen(pline);
+ pline_len = strlen((char*)pline);
if (state & ST_LINK_SPAN && pline_len > 1
&& *(pline+1) == ']')
{
- uint8_t* tag = (uint8_t*)"</span>";
- size_t tag_len = u8_strlen(tag);
+ u8* tag = (u8*)"</span>";
+ size_t tag_len = strlen((char*)tag);
size_t token_len = 0;
*ptoken = 0;
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (token_len + tag_len + 1 < BUFSIZE)
{
- u8_strncat(token, tag, BUFSIZE-token_len-1);
+ strncat((char*)token, (char*)tag,
+ BUFSIZE-token_len-1);
ptoken += tag_len;
}
state &= ~ST_LINK_SPAN;
@@ -3532,7 +3531,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
else if (state & ST_FOOTNOTE)
{
- BOOL footnote_definition = (u8_strlen(pline) > 1)
+ BOOL footnote_definition = (strlen((char*)pline) > 1)
&& (*(pline+1) == ':') && footnote_at_line_start;
process_footnote(token,
@@ -3579,7 +3578,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
pline++;
colno++;
}
- else if (u8_strlen(pline) > 1)
+ else if (strlen((char*)pline) > 1)
{
size_t token_len = 0;
switch (*(pline+1))
@@ -3597,8 +3596,9 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
REALLOCARRAY(links, KeyValue, links_count)
plinks = links + links_count - 1;
}
- CALLOC(plinks->key, uint8_t, KEYSIZE)
- u8_strncpy(plinks->key, token, KEYSIZE-1);
+ CALLOC(plinks->key, u8, KEYSIZE)
+ strncpy((char*)plinks->key, (char*)token,
+ KEYSIZE-1);
plinks->value = NULL;
plinks->value_size = 0;
pline += 2;
@@ -3615,21 +3615,22 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
case '[':
case '(':
- token_len = u8_strlen(token);
+ token_len = strlen((char*)token);
if (link_text)
{
if (token_len + 1 > link_size)
{
link_size = token_len+1;
- REALLOC(link_text, uint8_t, link_size)
+ REALLOC(link_text, u8, link_size)
}
}
else
{
link_size = token_len+1;
- CALLOC(link_text, uint8_t, link_size)
+ CALLOC(link_text, u8, link_size)
}
- u8_strncpy(link_text, token, link_size-1);
+ strncpy((char*)link_text, (char*)token,
+ link_size-1);
*(link_text + token_len) = 0;
pline += 2;
colno += 2;
@@ -3664,7 +3665,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) > 1 && *(pline+1) == '[')
+ if (strlen((char*)pline) > 1 && *(pline+1) == '[')
{
/* Output existing text up to ^[ */
*ptoken = 0;
@@ -3697,7 +3698,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) > 1)
+ if (strlen((char*)pline) > 1)
{
pline++;
colno++;
@@ -3722,11 +3723,11 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
break;
}
- if (u8_strlen(pline) > 1
+ if (strlen((char*)pline) > 1
&& *(pline+1) == '$')
{
if (state & ST_FORMULA)
- exit(error(1, (uint8_t*)"Display formula within an"
+ exit(error(1, (u8*)"Display formula within an"
" open formula"));
if (!(state & ST_DISPLAY_FORMULA))
@@ -3760,7 +3761,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
else
{
if (state & ST_DISPLAY_FORMULA)
- exit(error(1, (uint8_t*)"Formula within an open"
+ exit(error(1, (u8*)"Formula within an open"
" display formula"));
if (!(state & ST_FORMULA))
@@ -3802,7 +3803,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
colno++;
}
else if (colno == 1
- && u8_strlen(pline) > 1
+ && strlen((char*)pline) > 1
&& (*(pline+1) == '.' || *(pline+1) == ')'))
{
if (state & ST_LIST)
@@ -3857,23 +3858,23 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
CALLOC(vars, KeyValue, vars_count)
pvars = vars;
}
- pvars->value_size = u8_strlen(token)+1;
- CALLOC(pvars->value, uint8_t, pvars->value_size)
- u8_strncpy(pvars->value, token, pvars->value_size-1);
+ pvars->value_size = strlen((char*)token)+1;
+ CALLOC(pvars->value, u8, pvars->value_size)
+ strncpy((char*)pvars->value, (char*)token, pvars->value_size-1);
}
else if (keep_token)
{
- size_t token_len = u8_strlen(token);
+ size_t token_len = strlen((char*)token);
if (ptoken + 2 > token + token_size)
{
size_t old_size = token_size;
token_size += BUFSIZE;
- REALLOC(token, uint8_t, token_size)
+ REALLOC(token, u8, token_size)
ptoken = token + old_size - 1;
}
- u8_strncat(token, ANY(state, ST_IMAGE | ST_LINK)
- ? (uint8_t*)" " : (uint8_t*)"\n",
+ strncat((char*)token, ANY(state, ST_IMAGE | ST_LINK)
+ ? " " : "\n",
token_size - token_len - 1);
ptoken++;
*ptoken = 0;
@@ -3883,7 +3884,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
if (*token)
{
*ptoken = 0;
- size_t token_len = u8_strlen(token);
+ size_t token_len = strlen((char*)token);
if (state & ST_MACRO_BODY)
{
skip_eol = TRUE;
@@ -3897,25 +3898,28 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
if (pmacros->value)
{
- size_t value_len = u8_strlen(pmacros->value);
+ size_t value_len = strlen((char*)pmacros->value);
if (pmacros->value_size < value_len + token_len + 1)
{
pmacros->value_size += BUFSIZE;
- REALLOC(pmacros->value, uint8_t, pmacros->value_size)
+ REALLOC(pmacros->value, u8, pmacros->value_size)
}
- u8_strncat(pmacros->value, token,
+ strncat((char*)pmacros->value, (char*)token,
pmacros->value_size-value_len-1);
- u8_strncat(pmacros->value, (uint8_t*)"\n",
- pmacros->value_size-u8_strlen(pmacros->value)-1);
+ strncat((char*)pmacros->value, "\n",
+ pmacros->value_size
+ -strlen((char*)pmacros->value)-1);
}
else
{
pmacros->value_size = BUFSIZE;
- CALLOC(pmacros->value, uint8_t, pmacros->value_size)
- u8_strncpy(pmacros->value, token, pmacros->value_size-1);
- u8_strncat(pmacros->value, (uint8_t*)"\n",
- pmacros->value_size-u8_strlen(pmacros->value)-1);
+ CALLOC(pmacros->value, u8, pmacros->value_size)
+ strncpy((char*)pmacros->value, (char*)token,
+ pmacros->value_size-1);
+ strncat((char*)pmacros->value, "\n",
+ pmacros->value_size
+ -strlen((char*)pmacros->value)-1);
}
}
}
@@ -3932,25 +3936,28 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
if (pfootnotes->value)
{
- size_t value_len = u8_strlen(pfootnotes->value);
+ size_t value_len = strlen((char*)pfootnotes->value);
if (pfootnotes->value_size < value_len + token_len + 1)
{
pfootnotes->value_size += BUFSIZE;
- REALLOC(pfootnotes->value, uint8_t, pfootnotes->value_size)
+ REALLOC(pfootnotes->value, u8, pfootnotes->value_size)
}
- u8_strncat(pfootnotes->value, token,
+ strncat((char*)pfootnotes->value, (char*)token,
pfootnotes->value_size-value_len-1);
- u8_strncat(pfootnotes->value, (uint8_t*)"\n",
- pfootnotes->value_size-u8_strlen(pfootnotes->value)-1);
+ strncat((char*)pfootnotes->value, "\n",
+ pfootnotes->value_size
+ -strlen((char*)pfootnotes->value)-1);
}
else
{
pfootnotes->value_size = BUFSIZE;
- CALLOC(pfootnotes->value, uint8_t, pfootnotes->value_size)
- u8_strncpy(pfootnotes->value, token, pfootnotes->value_size-1);
- u8_strncat(pfootnotes->value, (uint8_t*)"\n",
- pfootnotes->value_size-u8_strlen(pfootnotes->value)-1);
+ CALLOC(pfootnotes->value, u8, pfootnotes->value_size)
+ strncpy((char*)pfootnotes->value, (char*)token,
+ pfootnotes->value_size-1);
+ strncat((char*)pfootnotes->value, "\n",
+ pfootnotes->value_size
+ -strlen((char*)pfootnotes->value)-1);
}
}
}
@@ -3964,9 +3971,10 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
CALLOC(links, KeyValue, links_count)
plinks = links;
}
- plinks->value_size = u8_strlen(token)+1;
- CALLOC(plinks->value, uint8_t, plinks->value_size)
- u8_strncpy(plinks->value, token, plinks->value_size-1);
+ plinks->value_size = strlen((char*)token)+1;
+ CALLOC(plinks->value, u8, plinks->value_size)
+ strncpy((char*)plinks->value, (char*)token,
+ plinks->value_size-1);
}
}
else if (state & ST_HEADING)
@@ -4030,7 +4038,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
state &= ~ST_FOOTNOTE_TEXT;
*ptoken = 0;
- size_t token_len = u8_strlen(token);
+ size_t token_len = strlen((char*)token);
skip_eol = TRUE;
if (read_yaml_macros_and_links)
@@ -4043,21 +4051,23 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
}
if (pfootnotes->value)
{
- size_t value_len = u8_strlen(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, uint8_t, pfootnotes->value_size)
+ REALLOC(pfootnotes->value, u8, pfootnotes->value_size)
}
- u8_strncat(pfootnotes->value, token, pfootnotes->value_size-1);
+ strncat((char*)pfootnotes->value, (char*)token,
+ pfootnotes->value_size-1);
}
else
{
pfootnotes->value_size = token_len + 1;
- CALLOC(pfootnotes->value, uint8_t, pfootnotes->value_size)
- u8_strncpy(pfootnotes->value, token, pfootnotes->value_size-1);
+ CALLOC(pfootnotes->value, u8, pfootnotes->value_size)
+ strncpy((char*)pfootnotes->value, (char*)token,
+ pfootnotes->value_size-1);
}
}
}
@@ -4076,7 +4086,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL body_only,
{
if (!read_yaml_macros_and_links)
{
- warning(1, (uint8_t*)"Malformed table");
+ warning(1, (u8*)"Malformed table");
process_table_end(output);
output_firstcol = TRUE;
}
@@ -4186,7 +4196,7 @@ main(int argc, char** argv)
return usage();
else
{
- error(EINVAL, (uint8_t*)"Invalid argument: --%s", arg);
+ error(EINVAL, (u8*)"Invalid argument: --%s", arg);
return usage();
}
}
@@ -4210,7 +4220,7 @@ main(int argc, char** argv)
cmd = CMD_VERSION;
break;
default:
- error(EINVAL, (uint8_t*)"Invalid argument: -%c", c);
+ error(EINVAL, (u8*)"Invalid argument: -%c", c);
return usage();
}
}
@@ -4232,46 +4242,46 @@ main(int argc, char** argv)
}
if (cmd == CMD_BASEDIR)
- return error(1, (uint8_t*)"-d: Argument required");
+ return error(1, (u8*)"-d: Argument required");
if (cmd == CMD_VERSION)
return version();
FILE* input = NULL;
FILE* output = stdout;
- uint8_t* buffer = NULL;
+ u8* buffer = NULL;
size_t buffer_size = 0;
if (input_filename)
read_file_into_buffer(&buffer, &buffer_size, input_filename, &input_dirname, &input);
else
{
- uint8_t* bufline = NULL;
+ u8* bufline = NULL;
size_t buffer_len = 0;
size_t buffer_size = 0;
size_t bufline_len = 0;
input = stdin;
- CALLOC(bufline, uint8_t, BUFSIZE)
+ CALLOC(bufline, u8, BUFSIZE)
buffer_size = BUFSIZE;
- CALLOC(buffer, uint8_t, buffer_size)
+ CALLOC(buffer, u8, buffer_size)
while (!feof(input))
{
- uint8_t* eol = NULL;
+ u8* eol = NULL;
if (!fgets((char*)bufline, BUFSIZE-1, input))
break;
- eol = u8_strchr(bufline, (ucs4_t)'\n');
+ eol = (u8*)strchr((char*)bufline, '\n');
if (eol)
*(eol+1) = 0;
- bufline_len = u8_strlen(bufline);
+ bufline_len = strlen((char*)bufline);
if (buffer_len + bufline_len + 1 > buffer_size)
{
buffer_size += BUFSIZE;
- REALLOC(buffer, uint8_t, buffer_size)
+ REALLOC(buffer, u8, buffer_size)
}
- u8_strncat(buffer, bufline, buffer_size-buffer_len-1);
+ strncat((char*)buffer, (char*)bufline, buffer_size-buffer_len-1);
buffer_len += bufline_len;
}
free(bufline);
diff --git a/slweb.do b/slweb.do
@@ -1,3 +1,3 @@
redo-ifchange slweb.o slweb.c defs.h
-${SLWEB_CC:-gcc} -g -Wall -std=c99 -o $3 slweb.o -lunistring
+${SLWEB_CC:-gcc} -g -Wall -std=c99 -o $3 slweb.o
diff --git a/utf8.c b/utf8.c
@@ -0,0 +1,161 @@
+/* See the file LICENSE for copyright and license details. */
+
+#include "utf8.h"
+
+/*
+ * 00000000 -- 0000007F: 0xxxxxxx
+ * (2^7 = 128 chars)
+ * 00000080 -- 000007FF: 110xxxxx 10xxxxxx
+ * (2^5 = 32 chars)
+ * 00000800 -- 0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx
+ * (2^4 = 16 chars)
+ * 00010000 -- 001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
+ * (2^3 = 8 chars)
+ * 00200000 -- 007FFFFF: 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ * (2^2 = 4 chars)
+ * 00800000 -- 00FFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
+ * 10xxxxxx
+ * (2^1 = 2 chars)
+ */
+
+const int
+utf_length_table[256] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 32 */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 64 */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 96 */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 128 */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 160 */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 192 */
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 224 */
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 1, 1, /* 256 */
+};
+
+const int
+extract_masks[6] = {
+ XMASK1, XMASK2, XMASK3, XMASK4, XMASK5, XMASK6
+};
+
+int
+u8_char_to_u32(u32* to, const u8 *from, size_t* from_delta)
+{
+ const u8* pfrom = from;
+ if (!from)
+ return 1;
+ *from_delta = 0;
+ int len = utf_length_table[*from];
+ *to = *from & extract_masks[len-1];
+ for (int i = 1; i < len; i++)
+ {
+ pfrom = from + i;
+ if (!*pfrom)
+ return 1;
+ *to <<= 6;
+ *to |= *pfrom & XMASKR;
+ }
+ *from_delta = len;
+
+ return 0;
+}
+
+size_t
+u32_char_to_u8(u8 *to, const u32 from)
+{
+ size_t len = 0;
+ u8 start = 0;
+ u32 cfrom = from;
+ if (from >= BOUND6)
+ {
+ start = START6;
+ len = 6;
+ }
+ else if (from >= BOUND5)
+ {
+ start = START5;
+ len = 5;
+ }
+ else if (from >= BOUND4)
+ {
+ start = START4;
+ len = 4;
+ }
+ else if (from >= BOUND3)
+ {
+ start = START3;
+ len = 3;
+ }
+ else if (from >= BOUND2)
+ {
+ start = START2;
+ len = 2;
+ }
+ else
+ {
+ start = START1;
+ len = 1;
+ }
+ for (int i = len-1; i > 0; i--)
+ {
+ to[len-1] = STARTR | (cfrom & XMASKR);
+ cfrom >>= 6;
+ }
+ to[0] = start | cfrom;
+ return len;
+}
+
+int
+u8_to_u32(u32 *to, const u8 *from, size_t* from_delta)
+{
+ const u8* pfrom = from;
+ u32* pto = to;
+ if (!from)
+ return 1;
+ size_t delta = 0;
+ *from_delta = 0;
+ while (*pfrom)
+ {
+ int result = u8_char_to_u32(pto, pfrom, &delta);
+ if (result)
+ return result;
+ pto++;
+ pfrom += delta;
+ *from_delta += delta;
+ }
+ *pto = 0;
+ return 0;
+}
+
+size_t
+u32_to_u8(u8 *to, const u32* from)
+{
+ u8* pto = to;
+ const u32* pfrom = from;
+ size_t len = 0;
+ if (!from)
+ return 0;
+ while (*pfrom)
+ {
+ size_t delta = u32_char_to_u8(pto, *pfrom);
+ pto += delta;
+ len += delta;
+ pfrom++;
+ }
+ return len;
+}
+
+size_t
+u32_strlen(const u32* s)
+{
+ const u32* ps = s;
+ while (ps && *ps)
+ ps++;
+ return ps - s;
+}
+
diff --git a/utf8.h b/utf8.h
@@ -0,0 +1,40 @@
+/* See the file LICENSE for copyright and license details. */
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#define XMASK1 0x7F /* b01111111 */
+#define XMASK2 0x1F /* b00011111 */
+#define XMASK3 0x0F /* b00001111 */
+#define XMASK4 0x07 /* b00000111 */
+#define XMASK5 0x03 /* b00000011 */
+#define XMASK6 0x01 /* b00000001 */
+
+#define XMASKR 0x3F /* b00111111 */
+
+/*
+#define BOUND1 0x0*/
+#define BOUND2 0x80
+#define BOUND3 0x800
+#define BOUND4 0x10000
+#define BOUND5 0x200000
+#define BOUND6 0x800000
+
+#define START1 0x00 /* b0xxxxxxx */
+#define START2 0xC0 /* b110xxxxx */
+#define START3 0xE0 /* b1110xxxx */
+#define START4 0xF0 /* b11110xxx */
+#define START5 0xF8 /* b111110xx */
+#define START6 0xFC /* b1111110x */
+
+#define STARTR 0x80 /* b10xxxxxx */
+
+typedef uint8_t u8;
+typedef uint32_t u32;
+
+int u8_char_to_u32(u32* to, const u8* from, size_t* from_delta);
+size_t u32_char_to_u8(u8* to, const u32 from);
+int u8_to_u32(u32* to, const u8* from, size_t* from_delta);
+size_t u32_to_u8(u8* to, const u32* from);
+size_t u32_strlen(const u32* s);
+