slw2gmi

Конвертор из slweb-а у Џемини
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 2d92894a36850f6e07d2ec1cc532d322ce8e0ce4
родитељ 2dc1091e26feee76afd075e7162817682a09d592
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Thu, 12 Aug 2021 21:08:11 +0200

Removed libunistring as a dependency

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MREADME | 12+++++-------
MTODO | 10+++++++++-
Mdefs.h | 28+++++-----------------------
Mslw2gmi.c | 965+++++++++++++++++++++++++++++++++++++++----------------------------------------
Mslw2gmi.do | 2+-
Autf8.c | 161+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Autf8.h | 40++++++++++++++++++++++++++++++++++++++++
измењених датотека: 7, додавања: 703(+), брисања: 515(-)

diff --git a/README b/README @@ -5,18 +5,16 @@ slw2gmi is a converter from slweb[1] to Gemini[2] format. Although both are similar to Markdown, the two formats differ enough to warrant a full converter. -[1]: https://strahinja.srht.site/slweb/index.html +[1]: https://strahinja.srht.site/slweb/ [2]: https://gemini.circumlunar.space Prerequisites ------------- -Aside from the obvious (a C compiler, by default GNU C), slw2gmi requires GNU -libunistring[3], 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}. - -[3]: https://www.gnu.org/software/libunistring/ +Aside from the obvious (a C compiler, by default GNU C), slw2gmi 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}. Install diff --git a/TODO b/TODO @@ -1,7 +1,15 @@ TODO ==== - [ ] Remove libunistring as a dependency + [x] Add ~text~ -> <s>text</s> + + [x] Add ~~ -> &nbsp; + + [x] Distinguish between [(Some text)][somelink] and + [Some (text)][somelink] - the latter should not output + <span></span>, just retain the parentheses instead + + [x] Remove libunistring as a dependency < > Remove realpath as a dependency? diff --git a/defs.h b/defs.h @@ -1,21 +1,4 @@ -/* - * slw2gmi - slweb to Gemini converter - * Copyright (C) 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,14 +17,13 @@ #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> -#include <unistr.h> -#include <unistdio.h> -#include <uniwidth.h> + +#include "utf8.h" #define PROGRAMNAME "slw2gmi" -#define VERSION "0.1.1" +#define VERSION "0.1.2" #define COPYRIGHTYEAR "2021" -#define MADEBY_URL "https://strahinja.srht.site/slw2gmi/index.html" +#define MADEBY_URL "https://strahinja.srht.site/slw2gmi/" #define BUFSIZE 1024 #define KEYSIZE 256 diff --git a/slw2gmi.c b/slw2gmi.c @@ -1,21 +1,4 @@ -/* - * slw2gmi - slweb to Gemini converter - * Copyright (C) 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" @@ -46,42 +29,42 @@ 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 ULONG state = ST_NONE; +static ULLONG state = ST_NONE; -#define CHECKEXITNOMEM(ptr) { if (!ptr) exit(error(ENOMEM, \ - (uint8_t*)"Memory allocation failed (out of memory?)")); } +#define CHECKEXITNOMEM(ptr) do { if (!ptr) exit(error(ENOMEM, \ + (u8*)"Memory allocation failed (out of memory?)")); } while (0) -#define CALLOC(ptr, ptrtype, nmemb) { ptr = calloc(nmemb, sizeof(ptrtype)); \ - CHECKEXITNOMEM(ptr) } +#define CALLOC(ptr, ptrtype, nmemb) do { ptr = calloc(nmemb, sizeof(ptrtype)); \ + CHECKEXITNOMEM(ptr); } while (0) -#define REALLOC(ptr, ptrtype, newsize) { ptrtype* newptr = realloc(ptr, newsize); \ - CHECKEXITNOMEM(newptr) \ - ptr = newptr; } +#define REALLOC(ptr, ptrtype, newsize) do { ptrtype* newptr = realloc(ptr, newsize); \ + CHECKEXITNOMEM(newptr); \ + ptr = newptr; } while (0) #define REALLOCARRAY(ptr, membtype, newcount) \ - REALLOC(ptr, membtype, sizeof(membtype) * newcount) + REALLOC(ptr, membtype, sizeof(membtype) * newcount); -#define CHECKCOPY(token, ptoken, token_size, pline) { \ +#define CHECKCOPY(token, ptoken, token_size, pline) do { \ 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; \ } \ - *ptoken++ = *pline++; } + *ptoken++ = *pline++; } while (0) -#define RESET_TOKEN(token, ptoken, token_size) { \ +#define RESET_TOKEN(token, ptoken, token_size) do { \ token_size = BUFSIZE; \ - REALLOC(token, uint8_t, token_size) \ - *token = 0; ptoken = token; } + REALLOC(token, u8, token_size); \ + *token = 0; ptoken = token; } while (0) #define ALL(var, mask) ( ((var) & (mask)) == (mask) ) #define ANY(var, mask) ( (var) & (mask) ) @@ -103,12 +86,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)", @@ -117,12 +100,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; @@ -149,7 +132,7 @@ int slweb_cleanup(); int -slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links); +slweb_parse(u8* buffer, FILE* output, BOOL read_yaml_macros_and_links); BOOL startswith(const char* s, const char* what) @@ -167,15 +150,15 @@ 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) { if (!list) return NULL; KeyValue* plist = list; while (plist < list + list_count) { - if (!u8_strcmp(plist->key, key)) + if (!strcmp((char*)plist->key, (char*)key)) { if (seen) { @@ -196,12 +179,12 @@ 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) { *basedir_size = arg_len+1; - REALLOC(*basedir, char, *basedir_size) + REALLOC(*basedir, char, *basedir_size); } strncpy(*basedir, arg, *basedir_size-1); *(*basedir + arg_len) = 0; @@ -219,12 +202,12 @@ 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) { *global_link_prefix_size = arg_len+1; - REALLOC(*global_link_prefix, char, *global_link_prefix_size) + REALLOC(*global_link_prefix, char, *global_link_prefix_size); } strncpy(*global_link_prefix, arg, *global_link_prefix_size-1); *(*global_link_prefix + arg_len) = 0; @@ -245,7 +228,7 @@ strip_ext(const char* fn) if (!dot) return NULL; - CALLOC(newname, char, strlen(fn)+1) + CALLOC(newname, char, strlen(fn)+1); pnewname = newname; pfn = fn; @@ -258,34 +241,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 @@ -299,11 +282,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]; @@ -327,7 +310,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]); @@ -336,11 +319,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); @@ -349,8 +332,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)) @@ -372,7 +355,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); @@ -381,7 +364,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; @@ -389,13 +372,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) @@ -404,7 +387,7 @@ read_file_into_buffer(uint8_t** buffer, size_t* buffer_size, char* input_filenam slash = strrchr(input_filename, '/'); if (slash) { - CALLOC(*input_dirname, char, strlen(input_filename)+1) + CALLOC(*input_dirname, char, strlen(input_filename)+1); char* pinput_dirname = *input_dirname; char* pinput_filename = input_filename; while (pinput_filename && *pinput_filename @@ -413,7 +396,7 @@ read_file_into_buffer(uint8_t** buffer, size_t* buffer_size, char* input_filenam } else { - CALLOC(*input_dirname, char, 2) + CALLOC(*input_dirname, char, 2); **input_dirname = '.'; } @@ -441,10 +424,10 @@ process_heading_start(FILE* output, UBYTE heading_level, } int -process_heading(const uint8_t* token, FILE* output) +process_heading(const u8* token, FILE* output) { - 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\n\n", token ? (char*)token : ""); output_firstcol = TRUE; @@ -456,11 +439,11 @@ 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; - CALLOC(basename, char, basename_size) + CALLOC(basename, char, basename_size); char* slash = strrchr(input_filename, '/'); pid_t result = 0; @@ -469,18 +452,18 @@ 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, "Previous commit: "); 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, "\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) { \ @@ -492,9 +475,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; @@ -528,7 +511,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) @@ -543,7 +526,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) @@ -563,7 +546,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); } @@ -607,12 +590,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 @@ -627,45 +610,45 @@ int read_csv(FILE* output, const char* filename, csv_callback_t callback) { if (!callback) - exit(error(EINVAL, (uint8_t*)"read_csv: Invalid callback argument")); + exit(error(EINVAL, (u8*)"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; + u8* bufline = NULL; + u8* pbufline = NULL; + u8* token = NULL; + u8* ptoken = NULL; size_t token_size = 0; UBYTE csv_state = ST_CS_NONE; - uint8_t* csv_header[MAX_CSV_REGISTERS]; + u8* csv_header[MAX_CSV_REGISTERS]; UBYTE current_header = 0; - uint8_t* csv_register[MAX_CSV_REGISTERS]; + u8* csv_register[MAX_CSV_REGISTERS]; UBYTE current_register = 0; - uint8_t* csv_delimiter = get_value(vars, vars_count, - (uint8_t*)"csv-delimiter", NULL); + 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; pbufline = bufline; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); current_register = 0; while (*pbufline) { @@ -681,29 +664,29 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback) case ';': case ',': if (csv_state & ST_CS_QUOTE) - CHECKCOPY(token, ptoken, token_size, pbufline) + CHECKCOPY(token, ptoken, token_size, pbufline); else { *ptoken = 0; 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) + RESET_TOKEN(token, ptoken, token_size); pbufline++; } break; default: if (csv_state & ST_CS_QUOTE) - CHECKCOPY(token, ptoken, token_size, pbufline) + CHECKCOPY(token, ptoken, token_size, pbufline); else { if (csv_delimiter && *pbufline == *csv_delimiter) @@ -712,20 +695,20 @@ 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) + RESET_TOKEN(token, ptoken, token_size); pbufline++; } else - CHECKCOPY(token, ptoken, token_size, pbufline) + CHECKCOPY(token, ptoken, token_size, pbufline); } } } @@ -733,15 +716,16 @@ 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) + RESET_TOKEN(token, ptoken, token_size); if (csv_lineno > 0 && pbufline != bufline) (*callback)(output, csv_header, csv_register); @@ -762,7 +746,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) @@ -783,7 +767,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; @@ -791,27 +775,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((char*)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((char*)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)); } } @@ -819,20 +803,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); @@ -845,7 +829,7 @@ process_include(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links) { prctl(PR_SET_PDEATHSIG, SIGTERM); - CALLOC(include_filename, char, BUFSIZE) + CALLOC(include_filename, char, BUFSIZE); pinclude_filename = include_filename; ptoken++; while (ptoken && *ptoken) @@ -857,13 +841,13 @@ process_include(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links) if (!strcmp(basedir, ".")) set_basedir(input_dirname, &basedir, &basedir_size); - CALLOC(input_filename, char, BUFSIZE) + CALLOC(input_filename, char, BUFSIZE); snprintf(input_filename, BUFSIZE, "%s/%s.slw", basedir, include_filename); free(include_filename); FILE* input = NULL; FILE* output = stdout; - uint8_t* buffer = NULL; + u8* buffer = NULL; size_t buffer_size = 0; int result = 0; ULONG saved_state = ST_NONE; @@ -931,7 +915,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; } @@ -951,10 +935,10 @@ process_list_item_start(FILE* output) } int -process_paralinks(const uint8_t* link_prefix, FILE* output); +process_paralinks(const u8* link_prefix, FILE* output); int -process_list_item_end(const uint8_t* link_prefix, FILE* output) +process_list_item_end(const u8* link_prefix, FILE* output) { if (state & ST_PARA_OPEN) { @@ -996,7 +980,7 @@ filter_subdirs(const struct dirent* node) struct stat st; char* nodename = NULL; - CALLOC(nodename, char, BUFSIZE) + CALLOC(nodename, char, BUFSIZE); snprintf(nodename, BUFSIZE, "%s/%s", incdir, node->d_name); if (lstat(nodename, &st) < 0 || !S_ISDIR(st.st_mode)) @@ -1037,12 +1021,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, uint8_t* title); +process_timestamp(FILE* output, const u8* link_prefix, const char* link, + u8* permalink_macro, u8* date, u8* title); 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) { struct dirent** namelist; struct dirent** pnamelist; @@ -1050,14 +1034,14 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix, long names_output; char* abs_subdirname = NULL; - CALLOC(abs_subdirname, char, BUFSIZE) + CALLOC(abs_subdirname, char, BUFSIZE); snprintf(abs_subdirname, BUFSIZE, "%s/%s", basedir, subdirname); if ((names_total = scandir(abs_subdirname, &namelist, &filter_slw, &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)); } @@ -1068,7 +1052,7 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix, int pstatus = 0; char* basename = strip_ext((*pnamelist)->d_name); char* link = NULL; - CALLOC(link, char, BUFSIZE) + CALLOC(link, char, BUFSIZE); snprintf(link, BUFSIZE, "%s/%s", subdirname, basename); @@ -1085,7 +1069,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; ULONG saved_state = ST_NONE; @@ -1142,8 +1126,8 @@ process_incdir_subdir(const char* subdirname, const uint8_t* link_prefix, return result; } - uint8_t* date = get_value(vars, vars_count, (uint8_t*)"date", NULL); - uint8_t* title = get_value(vars, vars_count, (uint8_t*)"title", + u8* date = get_value(vars, vars_count, (u8*)"date", NULL); + u8* title = get_value(vars, vars_count, (u8*)"title", NULL); if (title && date) process_timestamp(output, link_prefix, link, NULL, date, title); @@ -1164,7 +1148,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")); free(link); free(basename); @@ -1181,61 +1165,61 @@ 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; int current_name = 0; struct dirent** namelist; BOOL details_open = TRUE; - arg = u8_strtok(NULL, (uint8_t*)" ", &saveptr); + arg = (u8*)strtok_r((char*)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((char*)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++; } 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((char*)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); } @@ -1245,7 +1229,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)); } current_name = 0; @@ -1274,27 +1258,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, uint8_t* title) +process_timestamp(FILE* output, const u8* link_prefix, const char* link, + u8* permalink_macro, u8* date, u8* title) { - 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((char*)NULL, "-", (char**)&ptr); if (month) { - day = u8_strtok(NULL, (uint8_t*)"T", &ptr); + day = (u8*)strtok_r((char*)NULL, "T", (char**)&ptr); if (day) { ptimestamp_format = timestamp_format; @@ -1302,18 +1286,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++; @@ -1345,16 +1329,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) @@ -1363,11 +1347,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'; @@ -1385,17 +1369,17 @@ process_macro(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links, if (!macros) { - CALLOC(macros, KeyValue, macros_count) + CALLOC(macros, KeyValue, macros_count); pmacros = macros; } else { - REALLOC(macros, KeyValue, macros_count * sizeof(KeyValue)) + 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; } @@ -1409,15 +1393,15 @@ process_macro(uint8_t* token, FILE* output, BOOL read_yaml_macros_and_links, } int -process_para_end(const uint8_t* link_prefix, BOOL previous_line_blank, FILE* output); +process_para_end(const u8* link_prefix, BOOL previous_line_blank, FILE* output); int -process_tag(uint8_t* token, const uint8_t* link_prefix, FILE* output, +process_tag(u8* token, const u8* link_prefix, FILE* output, BOOL previous_line_blank, 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") @@ -1568,19 +1552,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)) @@ -1596,7 +1580,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); @@ -1604,24 +1588,24 @@ get_realpath(char** realpath, char* relativeto, char* path) } int -process_inline_link(uint8_t* link_text, uint8_t* link_macro_body, - uint8_t* link_url, FILE* output) +process_inline_link(u8* link_text, u8* link_macro_body, + u8* link_url, FILE* output) { print_output(output, "%s", link_text); return 0; } int -process_link(uint8_t* link_text, uint8_t* link_macro_body, uint8_t* link_id, +process_link(u8* link_text, 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_macro_body, url, output); } int -process_inline_image(uint8_t* image_text, uint8_t* image_url, FILE* output, +process_inline_image(u8* image_text, u8* image_url, FILE* output, BOOL add_link, BOOL add_figcaption) { print_output(output, "%s ", image_text); @@ -1629,16 +1613,16 @@ process_inline_image(uint8_t* image_text, uint8_t* image_url, FILE* output, } int -process_image(uint8_t* image_text, uint8_t* image_id, FILE* output, +process_image(u8* image_text, 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, url, output, add_link, add_figcaption); } int -process_paralinks(const uint8_t* link_prefix, FILE* output) +process_paralinks(const u8* link_prefix, FILE* output) { KeyValue* pparalink = paralinks; if (!skip_para_end) @@ -1676,7 +1660,7 @@ process_paralinks(const uint8_t* link_prefix, FILE* output) } int -process_para_end(const uint8_t* link_prefix, BOOL previous_line_blank, FILE* output) +process_para_end(const u8* link_prefix, BOOL previous_line_blank, FILE* output) { if (!skip_para_end) print_output(output, "\n"); @@ -1686,10 +1670,10 @@ process_para_end(const uint8_t* link_prefix, BOOL previous_line_blank, FILE* out } 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 skip_eol, BOOL list_para, - FILE* output, uint8_t** token, uint8_t** ptoken) + FILE* output, u8** token, u8** ptoken) { if ((first_line_in_doc || previous_line_blank) && !(ANY(state, ST_BLOCKQUOTE | ST_PRE))) @@ -1740,11 +1724,11 @@ 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 skip_eol, BOOL read_yaml_macros_and_links, BOOL list_para, FILE* output, - uint8_t** token, uint8_t** ptoken, size_t* token_size, + u8** token, u8** ptoken, size_t* token_size, BOOL add_enclosing_paragraph) { if (!(state & ST_YAML)) @@ -1758,40 +1742,41 @@ 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; } } - RESET_TOKEN(*token, *ptoken, *token_size) + RESET_TOKEN(*token, *ptoken, *token_size); return 0; } 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 @@ -1804,7 +1789,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++; @@ -1813,19 +1798,19 @@ 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) + CALLOC(footnotes, KeyValue, footnote_count); pfootnotes = footnotes; } else { - REALLOCARRAY(footnotes, KeyValue, footnote_count) + 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; } @@ -1840,7 +1825,7 @@ process_footnote(uint8_t* token, BOOL footnote_definition, BOOL footnote_output, } int -process_horizontal_rule(const uint8_t* link_prefix, BOOL previous_line_blank, +process_horizontal_rule(const u8* link_prefix, BOOL previous_line_blank, FILE* output) { /* Temporarily break paragraph as hr is para-level */ @@ -1853,16 +1838,16 @@ process_horizontal_rule(const uint8_t* link_prefix, BOOL previous_line_blank, } int -process_formula(FILE* output, const uint8_t* token, BOOL display_formula) +process_formula(FILE* output, const u8* token, BOOL display_formula) { return 0; } int begin_article(FILE* output, 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, const BOOL ext_in_permalink, BOOL first_line_in_doc, + const u8* author, const u8* title, + const u8* header_text, const char* title_heading_level, + u8* date, const BOOL ext_in_permalink, BOOL first_line_in_doc, BOOL* previous_line_blank, const char* permalink_url) { if (title) @@ -1882,7 +1867,7 @@ begin_article(FILE* output, const BOOL add_article_header, { char* link = strip_ext(input_filename); char* real_link = NULL; - CALLOC(real_link, char, BUFSIZE) + CALLOC(real_link, char, BUFSIZE); if (ext_in_permalink) strncat(link, timestamp_output_ext, BUFSIZE-strlen(link)-1); @@ -1898,7 +1883,7 @@ begin_article(FILE* output, const BOOL add_article_header, } int -end_footnotes(FILE* output, const uint8_t* link_prefix, BOOL add_footnote_div, +end_footnotes(FILE* output, const u8* link_prefix, BOOL add_footnote_div, BOOL previous_line_blank) { size_t footnote = 0; @@ -1935,30 +1920,30 @@ end_footnotes(FILE* output, const uint8_t* link_prefix, BOOL add_footnote_div, } int -slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) +slweb_parse(u8* buffer, FILE* output, 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; BOOL end_tag = FALSE; BOOL first_line_in_doc = TRUE; @@ -1975,29 +1960,29 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) size_t pline_len = 0; if (!buffer) - exit(error(1, (uint8_t*)"Empty buffer")); + exit(error(1, (u8*)"Empty buffer")); - title = get_value(vars, vars_count, (uint8_t*)"title", NULL); + title = get_value(vars, vars_count, (u8*)"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); + (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; @@ -2014,11 +1999,11 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) ext_in_permalink && *ext_in_permalink != '0', first_line_in_doc, &previous_line_blank, (char*)permalink_url); - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); do { - uint8_t* eol = u8_strchr(pbuffer, (ucs4_t)'\n'); + u8* eol = (u8*)strchr((char*)pbuffer, '\n'); if (!eol) break; @@ -2028,7 +2013,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) pbuffer++; *pline = 0; pline = line; - line_len = u8_strlen(line); + line_len = strlen((char*)line); lineno++; colno = 1; @@ -2046,7 +2031,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_MACRO_BODY | ST_PRE | ST_YAML_VAL)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } else if (state & ST_HTML_TAG) @@ -2056,7 +2041,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } else if (colno == 1 - && u8_strlen(pline) > 2 + && strlen((char*)pline) > 2 && startswith((char*)pline, "---")) { skip_eol = TRUE; @@ -2080,7 +2065,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) pline = NULL; } else if (colno == 1 - && u8_strlen(pline) > 1 + && strlen((char*)pline) > 1 && *(pline+1) == ' ') { if (state & ST_NUMLIST) @@ -2111,7 +2096,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -2129,21 +2114,21 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!vars) { - CALLOC(vars, KeyValue, vars_count) + CALLOC(vars, KeyValue, vars_count); pvars = vars; } else { - REALLOCARRAY(vars, KeyValue, vars_count) + 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; state |= ST_YAML_VAL; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); pline++; colno++; @@ -2160,7 +2145,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -2171,27 +2156,28 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) | ST_LINK_SECOND_ARG_END | ST_MACRO_BODY | ST_PRE | ST_TAG | ST_YAML)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; 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; } } @@ -2218,18 +2204,19 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_INLINE_FOOTNOTE | ST_HEADING | ST_FOOTNOTE_TEXT | ST_LINK)) { - uint8_t* tag = state & ST_STRIKE - ? (uint8_t*)"~" - : (uint8_t*)"~"; - size_t tag_len = u8_strlen(tag); + u8* tag = state & ST_STRIKE + ? (u8*)"~" + : (u8*)"~"; + 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; } } @@ -2257,7 +2244,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_DISPLAY_FORMULA | ST_FORMULA | ST_IMAGE | ST_MACRO_BODY)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2269,7 +2256,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } if (colno == 1 - && u8_strlen(pline) > 2 + && strlen((char*)pline) > 2 && startswith((char*)pline, "```")) { state ^= ST_PRE; @@ -2305,7 +2292,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -2355,7 +2342,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -2366,7 +2353,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) | ST_LINK_SECOND_ARG_END | ST_MACRO_BODY | ST_PRE | ST_TAG | ST_YAML)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2377,7 +2364,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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 @@ -2430,7 +2417,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) /*| ST_HTML_TAG */| ST_IMAGE | ST_MACRO_BODY | ST_PRE | ST_YAML)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2442,7 +2429,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } if (colno == 1 - && u8_strlen(pline) > 1 + && strlen((char*)pline) > 1 && *(pline+1) == ' ') { if (state & ST_NUMLIST) @@ -2483,7 +2470,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) /*| ST_HTML_TAG */| ST_IMAGE | ST_MACRO_BODY | ST_PRE | ST_YAML)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2494,7 +2481,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } - pline_len = u8_strlen(pline); + pline_len = strlen((char*)pline); if (colno == 1 && pline_len > 1 && *(pline+1) == '[') { @@ -2518,7 +2505,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) pline = NULL; } else if (colno == 1 - && u8_strlen(pline) > 1 + && strlen((char*)pline) > 1 && *(pline+1) == ' ') { if (state & ST_NUMLIST) @@ -2600,7 +2587,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_IMAGE | ST_MACRO_BODY | ST_PRE | ST_YAML_VAL)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2617,7 +2604,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } if (colno == 1 - && u8_strlen(pline) > 1 + && strlen((char*)pline) > 1 && startswith((char*)pline, " ")) { list_para = TRUE; @@ -2635,12 +2622,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } - if (u8_strlen(pline) == 2 + if (strlen((char*)pline) == 2 && *(pline+1) == ' ') { *ptoken = 0; - u8_strncat(ptoken, (uint8_t*)"\n", - BUFSIZE-u8_strlen(token)-1); + strncat((char*)ptoken, "\n", + BUFSIZE-strlen((char*)token)-1); ptoken += strlen("\n"); output_firstcol = TRUE; pline++; @@ -2649,14 +2636,14 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) else if (state & ST_LINK_MACRO) { *ptoken = 0; - u8_strncpy(link_macro, token, BUFSIZE-1); - *(link_macro + u8_strlen(token)) = 0; - RESET_TOKEN(token, ptoken, token_size) + strncpy((char*)link_macro, (char*)token, BUFSIZE-1); + *(link_macro + strlen((char*)token)) = 0; + RESET_TOKEN(token, ptoken, token_size); state &= ~ST_LINK_MACRO; } else if (!(state & ST_HEADING && *(pline-1) == '#')) - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; @@ -2664,7 +2651,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA /*| ST_HTML_TAG*/ | ST_PRE | ST_YAML | ST_YAML_VAL)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2678,7 +2665,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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) @@ -2686,25 +2673,27 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!macros) { macros_count = 1; - CALLOC(macros, KeyValue, macros_count) + CALLOC(macros, KeyValue, macros_count); pmacros = macros; } 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); } } } @@ -2720,7 +2709,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } state |= ST_TAG; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); pline++; colno++; @@ -2730,7 +2719,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_IMAGE | ST_PRE | ST_HEADING | ST_YAML_VAL)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2747,7 +2736,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) pline++; } else - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; @@ -2756,7 +2745,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_IMAGE | ST_PRE | ST_YAML | ST_YAML_VAL)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2769,7 +2758,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) process_tag(token, link_prefix, output, previous_line_blank, read_yaml_macros_and_links, &skip_eol, end_tag); - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); end_tag = FALSE; } @@ -2782,7 +2771,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) /*| ST_HTML_TAG*/ | ST_IMAGE | ST_PRE | ST_TAG | ST_YAML)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2793,7 +2782,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } - if (u8_strlen(pline) > 1 && *(pline+1) == '|') + if (strlen((char*)pline) > 1 && *(pline+1) == '|') { if (!ANY(state, ST_INLINE_FOOTNOTE | ST_HEADING | ST_FOOTNOTE_TEXT | ST_LINK)) @@ -2813,7 +2802,8 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) colno += 2; } /* Partial tables (for templating) */ - else if (!(state & ST_PRE) && colno == 1 && u8_strlen(pline) > 1 + else if (!(state & ST_PRE) && colno == 1 + && strlen((char*)pline) > 1 && *(pline+1) == '@') { skip_eol = TRUE; @@ -2855,8 +2845,8 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; default: - warning(1, (uint8_t*)"Invalid partial table line"); - CHECKCOPY(token, ptoken, token_size, pline) + warning(1, (u8*)"Invalid partial table line"); + CHECKCOPY(token, ptoken, token_size, pline); colno++; } } @@ -2902,12 +2892,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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); else process_table_header_end(output); } - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); pline++; colno++; } @@ -2919,18 +2909,18 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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); else process_table_body_row_end(output); } - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); pline++; colno++; } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -2940,7 +2930,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) || ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_IMAGE | ST_PRE)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2962,7 +2952,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_DISPLAY_FORMULA | ST_FORMULA | ST_IMAGE | ST_MACRO_BODY)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -2985,7 +2975,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -2996,7 +2986,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) | ST_INLINE_FOOTNOTE | ST_LINK | ST_MACRO_BODY | ST_PRE)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3007,7 +2997,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } - if (u8_strlen(pline) > 1 && *(pline+1) == '[') + if (strlen((char*)pline) > 1 && *(pline+1) == '[') { /* Output existing text up to ! */ *ptoken = 0; @@ -3018,7 +3008,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) &token_size, TRUE); processed_start_of_line = TRUE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state |= ST_IMAGE; keep_token = TRUE; @@ -3027,7 +3017,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } @@ -3037,7 +3027,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_MACRO_BODY | ST_PRE | ST_TAG)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3056,18 +3046,18 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } 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)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3103,7 +3093,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } processed_start_of_line = TRUE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state |= ST_FOOTNOTE; pline += 2; colno += 2; @@ -3122,7 +3112,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } processed_start_of_line = TRUE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state |= ST_LINK; keep_token = TRUE; *link_macro = 0; @@ -3144,20 +3134,20 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) | ST_FOOTNOTE_TEXT | ST_HEADING | ST_INLINE_FOOTNOTE | ST_LINK_SECOND_ARG_END | ST_MACRO_BODY | ST_PRE)) - CHECKCOPY(token, ptoken, token_size, pline) + 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(tag); * size_t token_len = 0; * * *ptoken = 0; - * token_len = u8_strlen(token); + * token_len = strlen(token); * * if (token_len + tag_len < BUFSIZE) * { - * u8_strncat(token, tag, BUFSIZE-token_len-1); + * strncat((char*)token, tag, BUFSIZE-token_len-1); * ptoken += tag_len; * } */ @@ -3166,7 +3156,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) pline++; } else - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; @@ -3174,7 +3164,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_DISPLAY_FORMULA | ST_FORMULA | ST_LINK_SECOND_ARG_END)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3198,17 +3188,17 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) paralinks_count++; if (!paralinks) { - CALLOC(paralinks, KeyValue, paralinks_count) + CALLOC(paralinks, KeyValue, paralinks_count); pparalinks = paralinks; } else { - REALLOCARRAY(paralinks, KeyValue, paralinks_count) + REALLOCARRAY(paralinks, KeyValue, paralinks_count); pparalinks = paralinks + paralinks_count - 1; } - pparalinks->key = u8_strdup(token); - pparalinks->value_size = u8_strlen(link_text)+1; - pparalinks->value = u8_strdup(link_text); + pparalinks->key = (u8*)strdup((char*)token); + pparalinks->value_size = strlen((char*)link_text)+1; + pparalinks->value = (u8*)strdup((char*)link_text); if (output_firstcol && ((*(line+line_len-1) == ']') @@ -3231,14 +3221,14 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) output_firstcol = !*link_text; } } - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state &= ~(ST_LINK | ST_LINK_SECOND_ARG | ST_IMAGE | ST_IMAGE_SECOND_ARG); if (pline) pline++; } else - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; @@ -3246,7 +3236,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_HEADING | ST_MACRO_BODY | ST_PRE)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3264,14 +3254,14 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) output); keep_token = FALSE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state &= ~ST_INLINE_FOOTNOTE; pline++; colno++; } 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, @@ -3279,7 +3269,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) !footnote_definition && !read_yaml_macros_and_links, output); - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state &= ~ST_FOOTNOTE; footnote_at_line_start = FALSE; pline++; @@ -3300,23 +3290,23 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) { if (!read_yaml_macros_and_links) { - uint8_t* url = get_value(links, links_count, token, NULL); + u8* url = get_value(links, links_count, token, NULL); if (!url) - exit(error(EINVAL, (uint8_t*)"get_value: Invalid argument")); + exit(error(EINVAL, (u8*)"get_value: Invalid argument")); paralinks_count++; if (!paralinks) { - CALLOC(paralinks, KeyValue, paralinks_count) + CALLOC(paralinks, KeyValue, paralinks_count); pparalinks = paralinks; } else { - REALLOCARRAY(paralinks, KeyValue, paralinks_count) + REALLOCARRAY(paralinks, KeyValue, paralinks_count); pparalinks = paralinks + paralinks_count - 1; } - pparalinks->key = u8_strdup(url); - pparalinks->value_size = u8_strlen(link_text)+1; - pparalinks->value = u8_strdup(link_text); + pparalinks->key = (u8*)strdup((char*)url); + pparalinks->value_size = strlen((char*)link_text)+1; + pparalinks->value = (u8*)strdup((char*)link_text); if (output_firstcol && ((*(line+line_len-1) == ']') @@ -3334,7 +3324,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) output_firstcol = !*link_text; } } - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state &= ~(ST_LINK | ST_LINK_SECOND_ARG); if (pline) { @@ -3346,23 +3336,23 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) { if (!read_yaml_macros_and_links) { - uint8_t* url = get_value(links, links_count, token, NULL); + u8* url = get_value(links, links_count, token, NULL); if (!url) - exit(error(EINVAL, (uint8_t*)"get_value: Invalid argument")); + exit(error(EINVAL, (u8*)"get_value: Invalid argument")); paralinks_count++; if (!paralinks) { - CALLOC(paralinks, KeyValue, paralinks_count) + CALLOC(paralinks, KeyValue, paralinks_count); pparalinks = paralinks; } else { - REALLOCARRAY(paralinks, KeyValue, paralinks_count) + REALLOCARRAY(paralinks, KeyValue, paralinks_count); pparalinks = paralinks + paralinks_count - 1; } - pparalinks->key = u8_strdup(url); - pparalinks->value_size = u8_strlen(link_text)+1; - pparalinks->value = u8_strdup(link_text); + pparalinks->key = (u8*)strdup((char*)url); + pparalinks->value_size = strlen((char*)link_text)+1; + pparalinks->value = (u8*)strdup((char*)link_text); if (output_firstcol && ((*(line+line_len-1) == ']') @@ -3378,7 +3368,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) output_firstcol = !*link_text; } } - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state &= ~(ST_IMAGE | ST_IMAGE_SECOND_ARG); if (pline) { @@ -3386,7 +3376,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) colno++; } } - else if (u8_strlen(pline) > 1) + else if (strlen((char*)pline) > 1) { size_t token_len = 0; switch (*(pline+1)) @@ -3396,16 +3386,16 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!links) { - CALLOC(links, KeyValue, links_count) + CALLOC(links, KeyValue, links_count); plinks = links; } else { - REALLOCARRAY(links, KeyValue, links_count) + 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; @@ -3415,32 +3405,32 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) pline++; colno++; } - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); keep_token = FALSE; state |= ST_LINK_SECOND_ARG_END; break; 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; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); keep_token = FALSE; if (state & ST_LINK) state |= ST_LINK_SECOND_ARG; @@ -3448,7 +3438,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) state |= ST_IMAGE_SECOND_ARG; break; default: - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; state &= ~(ST_LINK | ST_IMAGE); break; @@ -3456,7 +3446,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -3466,7 +3456,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) | ST_FOOTNOTE_TEXT | ST_IMAGE | ST_INLINE_FOOTNOTE | ST_PRE | ST_YAML)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3477,7 +3467,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } - if (u8_strlen(pline) > 1 && *(pline+1) == '[') + if (strlen((char*)pline) > 1 && *(pline+1) == '[') { /* Output existing text up to ^[ */ *ptoken = 0; @@ -3488,7 +3478,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) &token_size, TRUE); processed_start_of_line = TRUE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); state |= ST_INLINE_FOOTNOTE; keep_token = TRUE; pline += 2; @@ -3496,7 +3486,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; @@ -3506,7 +3496,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) /*| ST_HTML_TAG*/ | ST_IMAGE | ST_LINK | ST_MACRO_BODY)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3517,12 +3507,12 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } - if (u8_strlen(pline) > 1) + if (strlen((char*)pline) > 1) { pline++; colno++; - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); } else { @@ -3537,7 +3527,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_CSV_BODY | ST_IMAGE | ST_PRE | ST_YAML)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; break; } @@ -3548,11 +3538,11 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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)) @@ -3578,7 +3568,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) process_formula(output, token, TRUE); keep_token = FALSE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); } pline += 2; @@ -3587,7 +3577,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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)) @@ -3613,7 +3603,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) process_formula(output, token, FALSE); keep_token = FALSE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); } pline++; @@ -3626,7 +3616,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (ANY(state, ST_CODE | ST_DISPLAY_FORMULA | ST_FORMULA | ST_MACRO_BODY | ST_PRE | ST_YAML_VAL)) { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } else if (state & ST_HTML_TAG) @@ -3636,7 +3626,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) break; } else if (colno == 1 - && u8_strlen(pline) > 1 + && strlen((char*)pline) > 1 && (*(pline+1) == '.' || *(pline+1) == ')')) { if (state & ST_LIST) @@ -3667,7 +3657,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } break; @@ -3680,7 +3670,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } else { - CHECKCOPY(token, ptoken, token_size, pline) + CHECKCOPY(token, ptoken, token_size, pline); colno++; } } @@ -3695,25 +3685,25 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!vars) { vars_count = 1; - CALLOC(vars, KeyValue, vars_count) + 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, (uint8_t*)" ", + strncat((char*)token, " ", token_size - token_len - 1); ptoken++; *ptoken = 0; @@ -3723,7 +3713,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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; @@ -3732,30 +3722,33 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!macros) { macros_count = 1; - CALLOC(macros, KeyValue, macros_count) + CALLOC(macros, KeyValue, macros_count); pmacros = macros; } 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*)" ", - pmacros->value_size-u8_strlen(pmacros->value)-1); + strncat((char*)pmacros->value, " ", + 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*)" ", - 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, " ", + pmacros->value_size + -strlen((char*)pmacros->value)-1); } } } @@ -3767,30 +3760,33 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!footnotes) { footnote_count = 1; - CALLOC(footnotes, KeyValue, footnote_count) + CALLOC(footnotes, KeyValue, footnote_count); pfootnotes = footnotes; } 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*)" ", - pfootnotes->value_size-u8_strlen(pfootnotes->value)-1); + strncat((char*)pfootnotes->value, " ", + 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*)" ", - 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, " ", + pfootnotes->value_size + -strlen((char*)pfootnotes->value)-1); } } } @@ -3801,12 +3797,13 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!links) { links_count = 1; - CALLOC(links, KeyValue, links_count) + 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) @@ -3815,7 +3812,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!read_yaml_macros_and_links) process_heading(token, output); first_line_in_doc = FALSE; - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); heading_level = 0; } else if (!ANY(state, ST_DISPLAY_FORMULA | ST_FORMULA @@ -3874,7 +3871,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) 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) @@ -3882,26 +3879,28 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) if (!footnotes) { footnote_count = 1; - CALLOC(footnotes, KeyValue, footnote_count) + CALLOC(footnotes, KeyValue, footnote_count); pfootnotes = footnotes; } 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); } } } @@ -3920,7 +3919,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) { if (!read_yaml_macros_and_links) { - warning(1, (uint8_t*)"Malformed table"); + warning(1, (u8*)"Malformed table"); process_table_end(output); } state &= ~(ST_TABLE_HEADER | ST_TABLE_LINE); @@ -3944,7 +3943,7 @@ slweb_parse(uint8_t* buffer, FILE* output, BOOL read_yaml_macros_and_links) } if (!keep_token) - RESET_TOKEN(token, ptoken, token_size) + RESET_TOKEN(token, ptoken, token_size); if (!skip_change_first_line_in_doc && !(state & ST_YAML)) @@ -4036,7 +4035,7 @@ main(int argc, char** argv) int result = 0; basedir_size = 2; - CALLOC(basedir, char, basedir_size) + CALLOC(basedir, char, basedir_size); *basedir = '.'; while ((arg = *++argv)) @@ -4070,7 +4069,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(); } } @@ -4091,7 +4090,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(); } } @@ -4120,46 +4119,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/slw2gmi.do b/slw2gmi.do @@ -1,3 +1,3 @@ redo-ifchange slw2gmi.o slw2gmi.c defs.h -${SLW2GMI_CC:-gcc} -g -Wall -std=c99 -o $3 slw2gmi.o -lunistring +${SLW2GMI_CC:-gcc} -g -Wall -std=c99 -o $3 slw2gmi.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); +