59 #define STR vstring_str
60 #define LEN VSTRING_LEN
80 #define DICT_THASH_OPEN_RETURN(d) do { \
84 if (line_buffer != 0) \
85 vstring_free(line_buffer); \
92 if (open_flags != O_RDONLY)
94 open_flags, dict_flags,
95 "%s:%s map requires O_RDONLY access mode",
102 for (before = time((time_t *) 0); ; before = after) {
105 open_flags, dict_flags,
106 "open database %s: %m", path));
118 if (line_buffer == 0)
121 while (
readllines(line_buffer, fp, &last_line, &lineno)) {
130 msg_warn(
"%s, line %d: non-UTF-8 input \"%s\""
131 " -- ignoring this line",
140 for (value =
STR(line_buffer); *value; value++) {
141 if (*value ==
'\\') {
147 }
else if (*value ==
'"') {
148 in_quotes = !in_quotes;
152 msg_warn(
"%s, line %d: unbalanced '\"' in '%s'"
153 " -- ignoring this line",
167 key =
STR(line_buffer);
173 if (*key == 0 || *value == 0) {
174 msg_warn(
"%s, line %d: expected format: key whitespace value"
175 " -- ignoring this line", path, lineno);
178 if (key[strlen(key) - 1] ==
':')
179 msg_warn(
"%s, line %d: record is in \"key: value\" format;"
180 " is this an alias file?", path, lineno);
191 if (dict->
lookup(dict, key) != 0) {
195 dict->
update(dict, key, value);
197 msg_warn(
"%s, line %d: duplicate entry: \"%s\"",
202 open_flags, dict_flags,
203 "%s, line %d: duplicate entry: \"%s\"",
207 dict->
update(dict, key, value);
219 after = time((time_t *) 0);
220 if (st.st_mtime < before - 1 || st.st_mtime > after)
228 msg_info(
"pausing to let file %s cool down", path);
#define DICT_FLAG_DUP_IGNORE
void(* close)(struct DICT *)
int valid_utf8_string(const char *, ssize_t)
VSTREAM * vstream_fopen(const char *path, int flags, mode_t mode)
#define DICT_THASH_OPEN_RETURN(d)
DICT * dict_open3(const char *, const char *, int, int)
int(* update)(struct DICT *, const char *, const char *)
#define DICT_FLAG_DUP_REPLACE
int vstream_fclose(VSTREAM *stream)
void dict_type_override(DICT *, const char *)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
DICT * dict_thash_open(const char *path, int open_flags, int dict_flags)
void doze(unsigned delay)
const char *(* lookup)(struct DICT *, const char *)
#define DICT_FLAG_DUP_WARN
char * trimblanks(char *, ssize_t)
NORETURN msg_fatal(const char *fmt,...)
VSTRING * readllines(VSTRING *buf, VSTREAM *fp, int *lineno, int *first_line)
#define vstream_fileno(vp)
DICT * dict_surrogate(const char *dict_type, const char *dict_name, int open_flags, int dict_flags, const char *fmt,...)
#define DICT_FLAG_UTF8_ACTIVE
void msg_info(const char *fmt,...)