чување 1f493fee5867919e0bd69653f811597743618523
родитељ f131823c8208a4cba7db189e61bb5288f0fa1bea
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Sun, 14 Jul 2024 21:23:06 +0200
slweb.c: Reorganize function error; remove CHECKEXITNOMEM; add MEMCCPY;
begin transition from strlc{py,at} to memccpy
Diffstat:
| M | slweb.c | | | 378 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
измењених датотека: 1, додавања: 192(+), брисања: 186(-)
diff --git a/slweb.c b/slweb.c
@@ -48,34 +48,42 @@ static int incdir_only_summary = 0;
" See the file LICENSE for exact copyright and license " \
"details.")
-#define CHECKEXITNOMEM(ptr, func) \
- do \
- { \
- if (!ptr) \
- exit(error(ENOMEM, \
- (u8*)"" #func ":%d: Memory allocation" \
- " failed (out of memory?)", \
- __LINE__)); \
+#define CALLOC(ptr, ptrtype, nmemb) \
+ do \
+ { \
+ ptr = calloc(nmemb, sizeof(ptrtype)); \
+ if (!ptr) \
+ { \
+ perror(PROGRAMNAME ": calloc"); \
+ exit(error(ENOMEM, __FILE__, __func__, __LINE__, \
+ "Allocation error")); \
+ } \
} while (0)
-#define CALLOC(ptr, ptrtype, nmemb) \
- do \
- { \
- ptr = calloc(nmemb, sizeof(ptrtype)); \
- CHECKEXITNOMEM(ptr, calloc); \
- } while (0)
-
-#define REALLOC(ptr, ptrtype, newsize) \
- do \
- { \
- ptrtype* newptr = realloc(ptr, newsize); \
- CHECKEXITNOMEM(newptr, realloc); \
- ptr = newptr; \
+#define REALLOC(ptr, ptrtype, newsize) \
+ do \
+ { \
+ ptrtype* newptr = realloc(ptr, newsize); \
+ if (!newptr) \
+ { \
+ perror(PROGRAMNAME ": realloc"); \
+ exit(error(ENOMEM, __FILE__, __func__, __LINE__, \
+ "Allocation error")); \
+ } \
+ ptr = newptr; \
} while (0)
#define REALLOCARRAY(ptr, membtype, newcount) \
REALLOC(ptr, membtype, sizeof(membtype) * newcount);
+#define MEMCCPY(to, from, tolen, temp) \
+ do \
+ { \
+ temp = memccpy(to, from, 0, tolen); \
+ if (!temp) \
+ to[tolen > 0 ? tolen - 1 : 0] = 0; \
+ } while (0)
+
#define CHECKCOPY(token, ptoken, token_size, pline) \
do \
{ \
@@ -122,16 +130,17 @@ usage(void)
}
int
-error(const int code, const u8* fmt, ...)
+error(const int code, const char* file, const char* func, const int line,
+ const char* fmt, ...)
{
char buf[BUFSIZE];
va_list args;
va_start(args, fmt);
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)", lineno, colno,
- buf);
+ fprintf(stderr, "%s:%s:%lu:%lu:%s:%s:%d: %s\n", PROGRAMNAME,
+ input_filename ? input_filename : "(init/stdin)", lineno, colno,
+ func, file, line, buf);
return code;
}
@@ -271,23 +280,24 @@ get_value(KeyValue* list, const size_t list_count, const u8* key,
int
set_basedir(char** basedir, size_t* basedir_size, const char* arg)
{
- size_t basedir_len = 0;
- size_t arg_len = strlen(arg);
+ size_t arg_len;
+ char* temp = NULL;
- if (arg_len < 1)
- exit(error(1, (u8*)"set_basedir: Argument required"));
+ if (!arg)
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "NULL argument supplied to set_basedir"));
+ if (!*arg)
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Argument required"));
+ arg_len = strlen(arg);
if (arg_len + 1 > *basedir_size)
{
*basedir_size = arg_len + 1;
REALLOC(*basedir, char, *basedir_size);
}
- if (strlcpy(*basedir, arg, *basedir_size) >= *basedir_size)
- warning(1, (u8*)"strlcpy:%d: Overflow", __LINE__);
- basedir_len = strlen(*basedir);
- if (*(*basedir + basedir_len - 1) == '/')
- *(*basedir + basedir_len - 1) = 0;
+ MEMCCPY(*basedir, arg, *basedir_size, temp);
return 0;
}
@@ -296,20 +306,23 @@ int
set_global_link_prefix(char** global_link_prefix,
size_t* global_link_prefix_size, const char* arg)
{
- size_t arg_len = strlen(arg);
+ char* temp = NULL;
+ size_t arg_len;
- if (arg_len < 1)
- exit(error(1, (u8*)"set_global_link_prefix: Argument required"));
+ if (!arg)
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "NULL argument supplied to set_basedir"));
+ if (!*arg)
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Argument required"));
+ arg_len = strlen(arg);
if (arg_len + 1 > *global_link_prefix_size)
{
*global_link_prefix_size = arg_len + 1;
REALLOC(*global_link_prefix, char, *global_link_prefix_size);
}
- if (strlcpy(*global_link_prefix, arg, *global_link_prefix_size)
- >= *global_link_prefix_size)
- warning(1, (u8*)"strlcpy:%d: Overflow", __LINE__);
- *(*global_link_prefix + arg_len) = 0;
+ MEMCCPY(*global_link_prefix, arg, *global_link_prefix_size, temp);
return 0;
}
@@ -340,13 +353,15 @@ strip_ext(const char* fn)
int
print_output(FILE* output, const char* fmt, ...)
{
+ char* temp = NULL;
char buf[BUFSIZE];
va_list args;
u8* var_incdir_only_summary = NULL;
int incdir_only_summary = 0;
if (!output || !fmt)
- exit(error(EINVAL, (u8*)"print_output: Invalid argument"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Invalid argument"));
va_start(args, fmt);
@@ -367,10 +382,7 @@ print_output(FILE* output, const char* fmt, ...)
{
csv_template_size = BUFSIZE;
CALLOC(csv_template, u8, csv_template_size);
- if (strlcpy((char*)csv_template, buf, csv_template_size)
- >= csv_template_size)
- warning(1, (u8*)"strlcpy:%d: Overflow",
- __LINE__);
+ MEMCCPY(csv_template, buf, csv_template_size, temp);
}
else
{
@@ -395,10 +407,7 @@ print_output(FILE* output, const char* fmt, ...)
{
tsv_template_size = BUFSIZE;
CALLOC(tsv_template, u8, tsv_template_size);
- if (strlcpy((char*)tsv_template, buf, tsv_template_size)
- >= tsv_template_size)
- warning(1, (u8*)"strlcpy:%d: Overflow",
- __LINE__);
+ MEMCCPY(tsv_template, buf, tsv_template_size, temp);
}
else
{
@@ -428,7 +437,8 @@ print_command(FILE* output, const char* command, const u8* pass_arguments[],
const u8* pipe_arguments[], const int strip_newlines)
{
if (!command || !pass_arguments)
- exit(error(EINVAL, (u8*)"print_command: Invalid argument"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Invalid argument"));
pid_t pid = 0;
int pstatus = 0;
@@ -451,7 +461,7 @@ print_command(FILE* output, const char* command, const u8* pass_arguments[],
exit(1);
}
else if (pid < 0)
- exit(error(errno, (u8*)"print_command: fork failed"));
+ exit(error(errno, __FILE__, __func__, __LINE__, "fork failed"));
/* Parent */
close(arg_pipe_fds[PIPE_READ_INDEX]);
@@ -462,7 +472,7 @@ print_command(FILE* output, const char* command, const u8* pass_arguments[],
if (!cmd_input || !cmd_output)
{
perror("fdopen");
- exit(error(1, (u8*)"print_command: fdopen failed"));
+ exit(error(1, __FILE__, __func__, __LINE__, "fdopen failed"));
}
if (pipe_arguments)
@@ -521,16 +531,14 @@ read_file_into_buffer(FILE** input, u8** buffer, size_t* buffer_size,
if (!*input)
{
perror("fopen");
- return error(ENOENT,
- (u8*)"read_file_into_buffer: fopen failed: %s",
- input_filename);
+ return error(ENOENT, __FILE__, __func__, __LINE__,
+ "fopen failed: %s", input_filename);
}
fstat(fileno(*input), &fs);
if (S_ISDIR(fs.st_mode))
- return error(EISDIR,
- (u8*)"read_file_into_buffer: Is a directory: %s",
- input_filename);
+ return error(EISDIR, __FILE__, __func__, __LINE__,
+ "Is a directory: %s", input_filename);
free(*buffer);
*buffer_size = fs.st_size + 1;
@@ -566,6 +574,7 @@ int read_tsv(FILE* output, const char* filename, tsv_callback_t callback);
int
print_meta_var(FILE* output, u8** tsv_header, u8** tsv_register)
{
+ UNUSED(tsv_header);
if (!*tsv_register || !*(tsv_register + 1))
return 0;
u8* pvalue = *(tsv_register + 1);
@@ -671,23 +680,22 @@ process_inline_stylesheet(FILE* output, const u8* css_filename, int output_yaml)
size_t css_pathname_size = 0;
if (!css_filename)
- exit(error(EINVAL,
- (u8*)"process_inline_stylesheet: Invalid argument"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Invalid argument"));
css_filename_len = strlen((char*)css_filename);
css_pathname_size = basedir_size + css_filename_len + 1;
CALLOC(css_pathname, char, css_pathname_size);
- if (snprintf(css_pathname, css_pathname_size, "%s/%s", basedir,
+ if ((size_t)snprintf(css_pathname, css_pathname_size, "%s/%s", basedir,
css_filename)
> css_pathname_size)
warning(1, (u8*)"snprintf:%d: Overflow", __LINE__);
if (!(css = fopen((const char*)css_pathname, "rt")))
{
perror("fopen");
- exit(error(ENOENT,
- (u8*)"process_inline_stylesheet: fopen failed: %s",
- css_pathname));
+ exit(error(ENOENT, __FILE__, __func__, __LINE__,
+ "fopen failed: %s", css_pathname));
}
if (output_yaml)
@@ -769,9 +777,8 @@ tsv_template_start:
case '#':
if (IN(tsv_state, ST_CS_HEADER))
{
- error(1,
- (u8*)"print_tsv_row: Invalid header register"
- " mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid header register mark");
tsv_state &= ~(ST_CS_REGISTER | ST_CS_HEADER);
}
else if (IN(tsv_state, ST_CS_REGISTER))
@@ -786,9 +793,8 @@ tsv_template_start:
case '?':
if (IN(tsv_state, ST_CS_COND))
{
- error(1,
- (u8*)"print_tsv_row: Invalid conditional"
- " mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid conditional mark");
tsv_state &= ~ST_CS_COND;
}
else if (IN(tsv_state, ST_CS_REGISTER))
@@ -808,9 +814,9 @@ tsv_template_start:
}
else if (IN(tsv_state, ST_CS_COND))
{
- error(1,
- (u8*)"print_tsv_row: Empty conditional"
- " before/without nonempty conditional");
+ error(1, __FILE__, __func__, __LINE__,
+ "Empty conditional before/without nonempty "
+ "conditional");
tsv_state &= ~(ST_CS_COND | ST_CS_COND_EMPTY);
}
else
@@ -860,14 +866,14 @@ tsv_template_start:
default:
if (IN(tsv_state, ST_CS_HEADER))
{
- error(1,
- (u8*)"print_tsv_row: Invalid header register"
- " mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid header register mark");
tsv_state &= ~ST_CS_HEADER;
}
else if (IN(tsv_state, ST_CS_REGISTER))
{
- error(1, (u8*)"print_tsv_row: Invalid register mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid register mark");
tsv_state &= ~ST_CS_REGISTER;
}
else
@@ -882,25 +888,27 @@ tsv_template_done:
int
read_tsv(FILE* output, const char* filename, tsv_callback_t callback)
{
- if (!callback)
- exit(error(EINVAL, (u8*)"read_tsv: Invalid callback argument"));
-
FILE* tsv = NULL;
- size_t tsv_lineno = 0;
u8* bufline = NULL;
u8* pbufline = NULL;
u8* token = NULL;
u8* ptoken = NULL;
- size_t token_size = 0;
u8* tsv_header[MAX_TSV_REGISTERS];
- UBYTE current_header = 0;
u8* tsv_register[MAX_TSV_REGISTERS];
+ size_t tsv_lineno = 0;
+ size_t token_size = 0;
+ UBYTE current_header = 0;
UBYTE current_register = 0;
+ if (!callback)
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Invalid callback argument"));
+
if (!(tsv = fopen(filename, "rt")))
{
perror("fopen");
- exit(error(ENOENT, (u8*)"read_tsv: fopen failed: %s", filename));
+ exit(error(ENOENT, __FILE__, __func__, __LINE__,
+ "fopen failed: %s", filename));
}
CALLOC(bufline, u8, BUFSIZE);
@@ -911,7 +919,7 @@ read_tsv(FILE* output, const char* filename, tsv_callback_t callback)
for (UBYTE i = 0; i < MAX_TSV_REGISTERS; i++)
CALLOC(tsv_register[i], u8, BUFSIZE);
- while (!feof(tsv) && (!tsv_iter || tsv_lineno <= tsv_iter))
+ while (!feof(tsv) && (!tsv_iter || tsv_lineno <= (size_t)tsv_iter))
{
u8* eol = NULL;
if (!fgets((char*)bufline, BUFSIZE, tsv))
@@ -1030,9 +1038,8 @@ process_tsv(FILE* output, const u8* arg_token,
else
{
if (ANY(state, ST_CSV_BODY | ST_TSV_BODY))
- exit(error(1,
- (u8*)"process_tsv: Can't nest csv/tsv"
- " directives"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Can't nest csv/tsv directives"));
state |= ST_TSV_BODY;
@@ -1043,14 +1050,12 @@ process_tsv(FILE* output, const u8* arg_token,
(void)strtok_r((char*)arg_token, " ", (char**)&saveptr);
args = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (!args)
- exit(error(EINVAL,
- (u8*)"process_tsv: Arguments"
- " required"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Arguments required"));
args_len = strlen((char*)args);
if (*args != '"' || *(args + args_len - 1) != '"')
- exit(error(EINVAL,
- (u8*)"process_tsv: First argument must be a"
- " string"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "First argument must be a string"));
if (!tsv_filename)
CALLOC(tsv_filename, char, BUFSIZE);
args_base = (u8*)strdup((char*)args + 1);
@@ -1064,10 +1069,8 @@ process_tsv(FILE* output, const u8* arg_token,
errno = 0;
tsv_iter = strtol((char*)args, NULL, 10);
if (errno)
- exit(error(errno,
- (u8*)"process_tsv: Invalid argument"
- " '%s'",
- args));
+ exit(error(errno, __FILE__, __func__, __LINE__,
+ "Invalid argument '%s'", args));
}
}
@@ -1094,13 +1097,12 @@ process_tsv_count(FILE* output, const u8* arg_token,
(void)strtok_r((char*)arg_token, " ", (char**)&saveptr);
args = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (!args)
- exit(error(EINVAL, (u8*)"%csv-count: Arguments required",
- is_tsv ? 't' : 'c'));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Arguments required"));
args_len = strlen((char*)args);
if (*args != '"' || *(args + args_len - 1) != '"')
- exit(error(EINVAL,
- (u8*)"%csv-count: First argument must be a string",
- is_tsv ? 't' : 'c'));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "First argument must be a string"));
if (!tsv_filename)
CALLOC(tsv_filename, char, BUFSIZE);
args_base = (u8*)strdup((char*)args + 1);
@@ -1113,8 +1115,8 @@ process_tsv_count(FILE* output, const u8* arg_token,
if (!(tsv = fopen(tsv_filename, "rt")))
{
perror("fopen");
- exit(error(ENOENT, (u8*)"%csv-count: fopen failed: %s",
- is_tsv ? 't' : 'c', tsv_filename));
+ exit(error(ENOENT, __FILE__, __func__, __LINE__,
+ "fopen failed: %s", tsv_filename));
}
CALLOC(bufline, char, BUFSIZE);
@@ -1195,9 +1197,8 @@ csv_template_start:
case '#':
if (IN(csv_state, ST_CS_HEADER))
{
- error(1,
- (u8*)"print_csv_row: Invalid header register"
- " mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid header register mark");
csv_state &= ~(ST_CS_REGISTER | ST_CS_HEADER);
}
else if (IN(csv_state, ST_CS_REGISTER))
@@ -1212,9 +1213,8 @@ csv_template_start:
case '?':
if (IN(csv_state, ST_CS_COND))
{
- error(1,
- (u8*)"print_csv_row: Invalid conditional"
- " mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid conditional mark");
csv_state &= ~ST_CS_COND;
}
else if (IN(csv_state, ST_CS_REGISTER))
@@ -1234,9 +1234,9 @@ csv_template_start:
}
else if (IN(csv_state, ST_CS_COND))
{
- error(1,
- (u8*)"print_csv_row: Empty conditional"
- " before/without nonempty conditional");
+ error(1, __FILE__, __func__, __LINE__,
+ "Empty conditional before/without nonempty "
+ "conditional");
csv_state &= ~(ST_CS_COND | ST_CS_COND_EMPTY);
}
else
@@ -1286,14 +1286,14 @@ csv_template_start:
default:
if (IN(csv_state, ST_CS_HEADER))
{
- error(1,
- (u8*)"print_csv_row: Invalid header register"
- " mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid header register mark");
csv_state &= ~ST_CS_HEADER;
}
else if (IN(csv_state, ST_CS_REGISTER))
{
- error(1, (u8*)"print_csv_row: Invalid register mark");
+ error(1, __FILE__, __func__, __LINE__,
+ "Invalid register mark");
csv_state &= ~ST_CS_REGISTER;
}
else
@@ -1309,7 +1309,8 @@ int
read_csv(FILE* output, const char* filename, csv_callback_t callback)
{
if (!callback)
- exit(error(EINVAL, (u8*)"read_csv: Invalid callback argument"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Invalid callback argument"));
FILE* csv = NULL;
size_t csv_lineno = 0;
@@ -1329,7 +1330,8 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
if (!(csv = fopen(filename, "rt")))
{
perror("fopen");
- exit(error(ENOENT, (u8*)"read_csv: fopen failed: %s", filename));
+ exit(error(ENOENT, __FILE__, __func__, __LINE__,
+ "fopen failed: %s", filename));
}
CALLOC(bufline, u8, BUFSIZE);
@@ -1340,7 +1342,7 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback)
for (UBYTE i = 0; i < MAX_CSV_REGISTERS; i++)
CALLOC(csv_register[i], u8, BUFSIZE);
- while (!feof(csv) && (!csv_iter || csv_lineno <= csv_iter))
+ while (!feof(csv) && (!csv_iter || csv_lineno <= (size_t)csv_iter))
{
u8* eol = NULL;
if (!fgets((char*)bufline, BUFSIZE, csv))
@@ -1500,9 +1502,8 @@ process_csv(FILE* output, const u8* arg_token,
else
{
if (ANY(state, ST_CSV_BODY | ST_TSV_BODY))
- exit(error(1,
- (u8*)"process_csv: Can't nest csv/tsv"
- " directives"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Can't nest csv/tsv directives"));
state |= ST_CSV_BODY;
@@ -1516,13 +1517,12 @@ process_csv(FILE* output, const u8* arg_token,
(void)strtok_r((char*)arg_token, " ", (char**)&saveptr);
args = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (!args)
- exit(error(EINVAL,
- (u8*)"process_csv: Arguments required"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Arguments required"));
size_t args_len = strlen((char*)args);
if (*args != '"' || *(args + args_len - 1) != '"')
- exit(error(EINVAL,
- (u8*)"process_csv: First argument must be a "
- "string"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "First argument must be a string"));
if (!csv_filename)
CALLOC(csv_filename, char, BUFSIZE);
u8* args_base = (u8*)strdup((char*)args + 1);
@@ -1536,10 +1536,8 @@ process_csv(FILE* output, const u8* arg_token,
errno = 0;
csv_iter = strtol((char*)args, NULL, 10);
if (errno)
- exit(error(errno,
- (u8*)"process_csv: Invalid argument "
- "'%s'",
- args));
+ exit(error(errno, __FILE__, __func__, __LINE__,
+ "Invalid argument '%s'", args));
}
}
@@ -1565,9 +1563,8 @@ process_include(FILE* output, const u8* token,
(u8*)"process_include: Cannot use 'include' in stdin");
if (!ptoken)
- exit(error(1,
- (u8*)"process_include: Directive 'include' requires"
- " an argument"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Directive 'include' requires an argument"));
fflush(output);
pipe(arg_pipe_fds);
@@ -1585,7 +1582,8 @@ process_include(FILE* output, const u8* token,
{
wait(&pstatus);
perror("fdopen");
- exit(error(1, (u8*)"process_include: fdopen failed"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "fdopen failed"));
}
CALLOC(child_output_line, u8, BUFSIZE);
@@ -1624,7 +1622,8 @@ process_include(FILE* output, const u8* token,
= fdopen(output_pipe_fds[PIPE_WRITE_INDEX], "w")))
{
perror("fdopen");
- exit(error(1, (u8*)"process_include: fdopen failed"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "fdopen failed"));
}
CALLOC(include_filename, char, BUFSIZE);
@@ -1689,7 +1688,7 @@ process_include(FILE* output, const u8* token,
exit(result);
}
else
- exit(error(1, (u8*)"process_include: fork failed"));
+ exit(error(1, __FILE__, __func__, __LINE__, "fork failed"));
return 0;
}
@@ -1811,6 +1810,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
long names_output;
char* abs_subdirname = NULL;
+ UNUSED(link_prefix);
+
if (list_only)
; /*print_output(output, "<ul>\n");*/
else
@@ -1831,9 +1832,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
< 0)
{
perror("scandir");
- exit(error(errno,
- (u8*)"process_incdir_subdir: scandir '%s' failed",
- abs_subdirname));
+ exit(error(errno, __FILE__, __func__, __LINE__,
+ "scandir '%s' failed", abs_subdirname));
}
pnamelist = namelist;
@@ -1913,9 +1913,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
formatted_date
= format_date(date, list_timestamp_format);
if (!formatted_date)
- exit(error(1,
- (u8*)"process_incdir_subdir: "
- "format_date error"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "format_date error"));
/* Have to temporarily reset this because of potential
* interaction with print_output */
@@ -2000,8 +1999,8 @@ process_incdir_subdir(FILE* output, const char* subdirname,
exit(result);
}
else
- exit(error(1,
- (u8*)"process_incdir_subdir: fork failed"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "fork failed"));
if (!list_only)
print_output(output, "</article>\n");
@@ -2050,12 +2049,14 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix,
(void)strtok_r((char*)token, " ", (char**)&saveptr);
arg = (u8*)strtok_r(NULL, " ", (char**)&saveptr);
if (!arg)
- exit(error(1, (u8*)"process_incdir: Arguments required"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Arguments required"));
arg_len = strlen((char*)arg);
if (*arg != '"' || *(arg + arg_len - 1) != '"')
- exit(error(1, (u8*)"process_incdir: First argument not string"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "First argument not string"));
incdir = strdup((char*)(arg + 1));
*(incdir + strlen(incdir) - 1) = 0; /* trim ending " */
@@ -2077,17 +2078,15 @@ incdir_next_arg:
while (parg && *parg)
{
if (*parg < '0' || *parg > '9')
- exit(error(1,
- (u8*)"process_incdir: Invalid "
- "argument"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Invalid argument"));
parg++;
}
errno = 0;
num = strtol((char*)arg, NULL, 10);
if (errno)
- exit(error(errno,
- (u8*)"process_incdir: Invalid parameter "
- "'num'"));
+ exit(error(errno, __FILE__, __func__, __LINE__,
+ "Invalid parameter 'num'"));
}
pass++;
if (pass < 3)
@@ -2101,8 +2100,8 @@ incdir_done_args:
< 0)
{
perror("scandir");
- exit(error(errno, (u8*)"process_incdir: scandir '%s' failed",
- incdir));
+ exit(error(errno, __FILE__, __func__, __LINE__,
+ "scandir '%s' failed", incdir));
}
pnamelist = namelist;
@@ -2246,8 +2245,8 @@ process_macro_def(FILE* output, const u8* token,
}
if (IN(state, ST_MACRO_BODY))
- exit(error(1,
- (u8*)"process_macro_def: Cannot nest definitions"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Cannot nest definitions"));
if (read_yaml_macros_and_links)
{
@@ -2284,10 +2283,12 @@ process_macro(FILE* output, const u8* token, const int end_tag)
u8* eol;
size_t macro_body_len;
+ UNUSED(end_tag);
+
macro_body = get_value(macros, macros_count, token + 1, NULL);
if (!macro_body)
- exit(error(1, (u8*)"process_macro: Macro '%s' undefined",
- token + 1));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Macro '%s' undefined", token + 1));
eol = (u8*)strrchr((char*)macro_body, '\n');
macro_body_len = strlen((char*)macro_body);
@@ -2309,6 +2310,7 @@ process_tag(FILE* output, const u8* token, const char* source_filename,
const char* permalink_url, const int ext_in_permalink,
const int read_yaml_macros_and_links, int* skip_eol, const int end_tag)
{
+ UNUSED(source_filename);
if (!token || strlen((char*)token) < 1)
return warning(1, (u8*)"%s:%ld:%ld: Empty tag name",
input_filename, lineno, colno);
@@ -2573,7 +2575,8 @@ print_image_dimensions(FILE* output, const u8* image_file_prefix, const u8* path
snprintf(command, BUFSIZE - 1, CMD_IDENTIFY, image_path);
cmd_output = popen(command, "r");
if (!cmd_output)
- return error(errno, (u8*)"print_image_dimensions: popen failed");
+ return error(errno, __FILE__, __func__, __LINE__,
+ "popen failed");
if (!fgets(cmd_output_line, BUFSIZE, cmd_output))
goto print_dimensions_cleanup;
@@ -2646,6 +2649,8 @@ process_line_start(FILE* output, const u8* line, const u8* link_prefix,
int* previous_line_block, const int read_yaml_macros_and_links,
const int list_para, const int new_para_ok)
{
+ UNUSED(line);
+ UNUSED(link_prefix);
if ((first_line_in_doc || previous_line_blank || *previous_line_block)
&& !(ANY(state, ST_BLOCKQUOTE | ST_PRE)))
{
@@ -2960,6 +2965,8 @@ begin_article(FILE* output, const char* source_filename, const u8* link_prefix,
const int ext_in_permalink, const char* permalink_url)
{
int save_incdir = IN(state, ST_INCDIR);
+
+ UNUSED(add_article_header);
state &= ~ST_INCDIR;
if (author || date || header_text || title)
@@ -3078,8 +3085,8 @@ simple_parse_yaml_line(const u8* line, KeyValue** vars, size_t* vars_count,
int in_arg = 0;
if (!line || !vars || !vars_count || !pvars)
- exit(error(EINVAL,
- (u8*)"simple_parse_yaml_line: Invalid argument"));
+ exit(error(EINVAL, __FILE__, __func__, __LINE__,
+ "Invalid argument"));
CALLOC(token, u8, BUFSIZE);
ptoken = token;
@@ -3092,10 +3099,9 @@ simple_parse_yaml_line(const u8* line, KeyValue** vars, size_t* vars_count,
*ptoken = 0;
var_key = (u8*)strdup((char*)token);
if (!var_key)
- exit(error(ENOMEM,
- (u8*)"simple_parse_yaml_line: strdup "
- "failed (out of "
- "memory?)"));
+ exit(error(ENOMEM, __FILE__, __func__, __LINE__,
+ "strdup failed (out of "
+ "memory?)"));
ptoken = token;
*ptoken = 0;
pline++;
@@ -3206,7 +3212,7 @@ slweb_parse(FILE* output, const char* source_filename, const u8* buffer,
u8* eol = NULL;
if (!buffer)
- exit(error(1, (u8*)"slweb_parse: Empty buffer"));
+ exit(error(1, __FILE__, __func__, __LINE__, "Empty buffer"));
title = get_value(vars, vars_count, (u8*)"title", NULL);
title_heading_level
@@ -4249,7 +4255,7 @@ do_line:
REALLOC(pmacros->value, u8,
pmacros->value_size);
}
- if (snprintf((char*)pmacros->value,
+ if ((size_t)snprintf((char*)pmacros->value,
pmacros->value_size, "{%s%s}",
end_tag ? "/" : "", (char*)token)
> pmacros->value_size)
@@ -5097,9 +5103,9 @@ do_line:
if (strlen((char*)pline) > 1 && *(pline + 1) == '$')
{
if (IN(state, ST_FORMULA))
- exit(error(1,
- (u8*)"slweb_parse: Display formula "
- "within an open formula"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Display formula within an open "
+ "formula"));
if (!(IN(state, ST_DISPLAY_FORMULA)))
{
@@ -5134,9 +5140,9 @@ do_line:
else
{
if (IN(state, ST_DISPLAY_FORMULA))
- exit(error(1,
- (u8*)"slweb_parse: Formula within an "
- "open display formula"));
+ exit(error(1, __FILE__, __func__, __LINE__,
+ "Formula within an open display "
+ "formula"));
if (!(IN(state, ST_FORMULA)))
{
@@ -5658,6 +5664,7 @@ main(const int argc, const char** argv)
u8* buffer = NULL;
size_t buffer_size = 0;
+ UNUSED(argc);
basedir_size = 2;
CALLOC(basedir, char, basedir_size);
*basedir = '.';
@@ -5699,10 +5706,9 @@ main(const int argc, const char** argv)
return usage();
else
{
- error(EINVAL,
- (u8*)"main: Invalid "
- "argument: --%s",
- arg);
+ error(EINVAL, __FILE__, __func__,
+ __LINE__,
+ "Invalid argument: --%s", arg);
return usage();
}
}
@@ -5729,10 +5735,9 @@ main(const int argc, const char** argv)
cmd = CMD_VERSION;
break;
default:
- error(EINVAL,
- (u8*)"main: Invalid "
- "argument: -%c",
- c);
+ error(EINVAL, __FILE__, __func__,
+ __LINE__,
+ "Invalid argument: -%c", c);
return usage();
}
}
@@ -5762,7 +5767,8 @@ main(const int argc, const char** argv)
}
if (cmd == CMD_BASEDIR)
- return error(1, (u8*)"main: set_basedir: Argument required");
+ return error(1, __FILE__, __func__, __LINE__,
+ "Argument required");
if (cmd == CMD_FULL_VERSION)
return version(1);