static int parse_line(struct parse_arg *pa, struct _region *r) { char buf[20]; struct zone z1, z2; size_t len; len = _region_size(r); z1.begin = _bcs_skip_ws_len(_region_head(r), &len); if (len == 0) return EFTYPE; z1.end = _bcs_skip_nonws_len(z1.begin, &len); if (len == 0) return EFTYPE; z2.begin = _bcs_skip_ws_len(z1.end, &len); if (len == 0) return EFTYPE; z2.end = _bcs_skip_nonws_len(z2.begin, &len); /* z1 : dst name, z2 : norm */ snprintf(pa->dst, sizeof(pa->dst), "%.*s", (int)(z1.end-z1.begin), z1.begin); snprintf(buf, sizeof(buf), "%.*s", (int)(z2.end-z2.begin), z2.begin); pa->norm = _bcs_strtoul(buf, NULL, 0); return 0; }
static int convert_line(struct _citrus_db_factory *df, const char *line, size_t len) { const char *p; char data[LINE_MAX], key[LINE_MAX]; /* cut off trailing comment */ p = memchr(line, T_COMM, len); if (p) len = p - line; /* key */ line = _bcs_skip_ws_len(line, &len); if (len == 0) return (0); p = _bcs_skip_nonws_len(line, &len); if (p == line) return (0); snprintf(key, sizeof(key), "%.*s", (int)(p-line), line); _bcs_convert_to_lower(key); /* data */ line = _bcs_skip_ws_len(p, &len); _bcs_trunc_rws_len(line, &len); snprintf(data, sizeof(data), "%.*s", (int)len, line); return (_db_factory_addstr_by_s(df, key, data)); }
static int convert_line(struct src_head *sh, const char *line, size_t len) { struct src_entry *se; const char *p; char key1[LINE_MAX], key2[LINE_MAX], data[LINE_MAX]; char *ep; uint32_t val; int ret; se = NULL; /* cut off trailing comment */ p = memchr(line, T_COMM, len); if (p) len = p - line; /* key1 */ line = _bcs_skip_ws_len(line, &len); if (len == 0) return (0); p = _bcs_skip_nonws_len(line, &len); if (p == line) return (0); snprintf(key1, sizeof(key1), "%.*s", (int)(p - line), line); /* key2 */ line = _bcs_skip_ws_len(p, &len); if (len == 0) return (0); p = _bcs_skip_nonws_len(line, &len); if (p == line) return (0); snprintf(key2, sizeof(key2), "%.*s", (int)(p - line), line); /* data */ line = _bcs_skip_ws_len(p, &len); _bcs_trunc_rws_len(line, &len); snprintf(data, sizeof(data), "%.*s", (int)len, line); val = strtoul(data, &ep, 0); if (*ep != '\0') return (EFTYPE); /* insert to DB */ ret = find_src(sh, &se, key1); if (ret) return (ret); return (_db_factory_add32_by_s(se->se_df, key2, val)); }
static int seq_next_plain(struct _citrus_lookup *cl, struct _region *key, struct _region *data) { const char *p, *q; size_t len; if (cl->cl_rewind) _memstream_bind(&cl->cl_plainms, &cl->cl_plainr); cl->cl_rewind = 0; retry: p = _memstream_getln(&cl->cl_plainms, &len); if (p == NULL) return ENOENT; /* ignore comment */ q = memchr(p, T_COMM, len); if (q) { len = q-p; } /* ignore trailing spaces */ _bcs_trunc_rws_len(p, &len); p = _bcs_skip_ws_len(p, &len); q = _bcs_skip_nonws_len(p, &len); if (p==q) goto retry; if (cl->cl_key && ((size_t)(q-p) != cl->cl_keylen || memcmp(p, cl->cl_key, (size_t)(q-p)) != 0)) goto retry; /* found a entry */ if (key) _region_init(key, __UNCONST(p), (size_t)(q-p)); p = _bcs_skip_ws_len(q, &len); if (data) _region_init(data, len ? __UNCONST(p) : NULL, len); return 0; }
static int parse_file(struct _citrus_mapper_646 *m6, const char *path) { struct _memstream ms; struct _region r; const char *p; char *pp; size_t len; char buf[PATH_MAX]; int i, ret; ret = _map_file(&r, path); if (ret) return (ret); _memstream_bind(&ms, &r); for (i = 0; i < NUM_OF_SPECIALS; i++) { retry: p = _memstream_getln(&ms, &len); if (p == NULL) { ret = EINVAL; break; } p = _bcs_skip_ws_len(p, &len); if (*p == T_COMM || len==0) goto retry; if (!_bcs_isdigit(*p)) { ret = EINVAL; break; } snprintf(buf, sizeof(buf), "%.*s", (int)len, p); pp = __DECONST(void *, p); m6->m6_map[i] = strtoul(buf, (char **)&pp, 0); p = _bcs_skip_ws(buf); if (*p != T_COMM && !*p) { ret = EINVAL; break; } } _unmap_file(&r); return (ret); };