version 1.20, 2012/12/06 13:06:05 |
version 1.21, 2012/12/13 15:36:16 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
|
#include <ctype.h> |
#include <errno.h> |
#include <errno.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
|
{ |
{ |
FILE *f; |
FILE *f; |
u_int n; |
u_int n; |
char *buf, *line, *cause; |
char *buf, *copy, *line, *cause; |
size_t len, newlen; |
size_t len, oldlen; |
struct cmd_list *cmdlist; |
struct cmd_list *cmdlist; |
struct cmd_ctx ctx; |
struct cmd_ctx ctx; |
enum cmd_retval retval; |
enum cmd_retval retval; |
|
|
line = NULL; |
line = NULL; |
retval = CMD_RETURN_NORMAL; |
retval = CMD_RETURN_NORMAL; |
while ((buf = fgetln(f, &len))) { |
while ((buf = fgetln(f, &len))) { |
|
/* Trim \n. */ |
if (buf[len - 1] == '\n') |
if (buf[len - 1] == '\n') |
len--; |
len--; |
|
log_debug ("%s: %s", path, buf); |
|
|
/* Current line is the continuation of the previous one. */ |
/* Current line is the continuation of the previous one. */ |
if (line != NULL) { |
if (line != NULL) { |
newlen = strlen(line) + len + 1; |
oldlen = strlen(line); |
line = xrealloc(line, 1, newlen); |
line = xrealloc(line, 1, oldlen + len + 1); |
} else { |
} else { |
newlen = len + 1; |
oldlen = 0; |
line = xmalloc(newlen); |
line = xmalloc(len + 1); |
*line = '\0'; |
|
} |
} |
|
|
/* Append current line to the previous. */ |
/* Append current line to the previous. */ |
strlcat(line, buf, newlen); |
memcpy(line + oldlen, buf, len); |
|
line[oldlen + len] = '\0'; |
n++; |
n++; |
|
|
/* Continuation: get next line? */ |
/* Continuation: get next line? */ |
|
|
if (len > 1 && line[len - 2] != '\\') |
if (len > 1 && line[len - 2] != '\\') |
continue; |
continue; |
} |
} |
buf = line; |
copy = line; |
line = NULL; |
line = NULL; |
|
|
|
/* Skip empty lines. */ |
|
buf = copy; |
|
while (isspace((u_char)*buf)) |
|
buf++; |
|
if (*buf == '\0') |
|
continue; |
|
|
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) { |
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) { |
free(buf); |
free(copy); |
if (cause == NULL) |
if (cause == NULL) |
continue; |
continue; |
cfg_add_cause(causes, "%s: %u: %s", path, n, cause); |
cfg_add_cause(causes, "%s: %u: %s", path, n, cause); |
free(cause); |
free(cause); |
continue; |
continue; |
} |
} |
free(buf); |
free(copy); |
if (cmdlist == NULL) |
if (cmdlist == NULL) |
continue; |
continue; |
|
|