int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, void *cb_data, long lines, long *begin, long *end, const char *path) { *begin = *end = 0; if (*arg == ':') { arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, begin, end, path); if (!arg || *arg) return -1; return 0; } arg = parse_loc(arg, nth_line_cb, cb_data, lines, 1, begin); if (*arg == ',') arg = parse_loc(arg + 1, nth_line_cb, cb_data, lines, *begin + 1, end); if (*arg) return -1; if (*begin && *end && *end < *begin) { long tmp; tmp = *end; *end = *begin; *begin = tmp; } return 0; }
int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, void *cb_data, long lines, long anchor, long *begin, long *end, const char *path) { *begin = *end = 0; if (anchor < 1) anchor = 1; if (anchor > lines) anchor = lines + 1; if (*arg == ':' || (*arg == '^' && *(arg + 1) == ':')) { arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, anchor, begin, end, path); if (!arg || *arg) return -1; return 0; } arg = parse_loc(arg, nth_line_cb, cb_data, lines, -anchor, begin); if (*arg == ',') arg = parse_loc(arg + 1, nth_line_cb, cb_data, lines, *begin + 1, end); if (*arg) return -1; if (*begin && *end && *end < *begin) { SWAP(*end, *begin); } return 0; }
const char *skip_range_arg(const char *arg) { if (*arg == ':') return parse_range_funcname(arg, NULL, NULL, 0, NULL, NULL, NULL); arg = parse_loc(arg, NULL, NULL, 0, -1, NULL); if (*arg == ',') arg = parse_loc(arg+1, NULL, NULL, 0, 0, NULL); return arg; }
int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, void *cb_data, long lines, long *begin, long *end, const char *path) { if (*arg == ':') { arg = parse_range_funcname(arg, nth_line_cb, cb_data, lines, begin, end, path); if (!arg || *arg) return -1; return 0; } arg = parse_loc(arg, nth_line_cb, cb_data, lines, 1, begin); if (*arg == ',') arg = parse_loc(arg + 1, nth_line_cb, cb_data, lines, *begin + 1, end); if (*arg) return -1; return 0; }
xml_weather * parse_weather (xmlNode *cur_node) { xml_weather *ret; if (!NODE_IS_TYPE (cur_node, "weather")) { return NULL; } if ((ret = g_new0(xml_weather, 1)) == NULL) return NULL; for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next) { if (cur_node->type != XML_ELEMENT_NODE) continue; if (NODE_IS_TYPE (cur_node, "cc")) ret->cc = parse_cc(cur_node); else if (NODE_IS_TYPE (cur_node, "loc")) ret->loc = parse_loc(cur_node); else if (NODE_IS_TYPE (cur_node, "dayf")) { xmlNode *child_node; guint i = 0; for (child_node = cur_node->children; child_node; child_node = child_node->next) { if (NODE_IS_TYPE (child_node, "day")) { if (i >= XML_WEATHER_DAYF_N) break; ret->dayf[i] = parse_dayf(child_node); i++; } } } } return ret; }
dns_result ReadName(unsigned char *reader, size_t data_len, unsigned short type, unsigned char *dns, char *output_buf, size_t output_buf_size) { if (type < 1 || type > 256) { return DNS_RESULT_ERR; } switch (type) { case T_A: return parse_ip(reader, output_buf, output_buf_size); break; case T_NS: // printf("datalen: %d", data_len); parse_ns(reader, (unsigned short)data_len, dns, output_buf, output_buf_size); break; case T_CNAME: parse_cname(reader, dns, output_buf, output_buf_size, data_len); break; case T_SOA: parse_soa(reader, (unsigned short)data_len, dns, output_buf, output_buf_size); break; case T_PTR: parse_ptr(reader, (unsigned short)data_len, dns, output_buf, output_buf_size); break; case T_HINFO: parse_hinfo(reader, (unsigned short)data_len, output_buf, output_buf_size); break; case T_MX: parse_mx(reader, (unsigned short)data_len, dns, output_buf, output_buf_size); break; case T_TXT: return parse_txt(reader, data_len, output_buf, output_buf_size); break; case T_RP: parse_rp(reader, dns, output_buf, output_buf_size, data_len); break; case T_AFSDB: parse_afsdb(reader, dns, output_buf, output_buf_size, data_len); break; case T_AAAA: parse_aaaa(reader, output_buf, output_buf_size); break; case T_LOC: parse_loc(reader, output_buf, output_buf_size); break; case T_SRV: parse_srv(reader, dns, output_buf, output_buf_size, data_len); break; case T_NAPTR: return parse_naptr(reader, (unsigned short)data_len, output_buf, output_buf_size); break; case T_RRSIG: parse_rrsig(reader, dns, (unsigned short)data_len, output_buf, output_buf_size); break; case T_NSEC: parse_nsec(reader, dns, output_buf, output_buf_size, data_len); break; case T_DNSKEY: parse_dnskey(reader, (unsigned short)data_len, output_buf, output_buf_size); break; default: parse_default(reader, (unsigned short)data_len, output_buf, output_buf_size); break; } return DNS_RESULT_OK; }