📄 pquery.c
字号:
p->exclusion = NULL; if (!lex (li)) { li->error = YAZ_PQF_ERROR_MISSING; return NULL; } p->distance = (int *)odr_malloc (o, sizeof(*p->distance)); *p->distance = atoi (li->lex_buf); if (!lex (li)) { li->error = YAZ_PQF_ERROR_MISSING; return NULL; } p->ordered = (int *)odr_malloc (o, sizeof(*p->ordered)); *p->ordered = atoi (li->lex_buf); if (!lex (li)) { li->error = YAZ_PQF_ERROR_MISSING; return NULL; } p->relationType = (int *)odr_malloc (o, sizeof(*p->relationType)); *p->relationType = atoi (li->lex_buf); if (!lex (li)) { li->error = YAZ_PQF_ERROR_MISSING; return NULL; } if (*li->lex_buf == 'k') p->which = 0; else if (*li->lex_buf == 'p') p->which = 1; else p->which = atoi (li->lex_buf); if (!lex (li)) { li->error = YAZ_PQF_ERROR_MISSING; return NULL; } p->which = Z_ProximityOperator_known; p->u.known = (int *)odr_malloc (o, sizeof(*p->u.known)); *p->u.known = atoi (li->lex_buf); return p;}static Z_Complex *rpn_complex (struct yaz_pqf_parser *li, ODR o, oid_proto proto, int num_attr, int max_attr, int *attr_list, char **attr_clist, oid_value *attr_set){ Z_Complex *zc; Z_Operator *zo; zc = (Z_Complex *)odr_malloc (o, sizeof(*zc)); zo = (Z_Operator *)odr_malloc (o, sizeof(*zo)); zc->roperator = zo; switch (li->query_look) { case 'a': zo->which = Z_Operator_and; zo->u.and_not = odr_nullval(); break; case 'o': zo->which = Z_Operator_or; zo->u.and_not = odr_nullval(); break; case 'n': zo->which = Z_Operator_and_not; zo->u.and_not = odr_nullval(); break; case 'p': zo->which = Z_Operator_prox; zo->u.prox = rpn_proximity (li, o); if (!zo->u.prox) return NULL; break; default: /* we're only called if one of the above types are seens so this shouldn't happen */ li->error = YAZ_PQF_ERROR_INTERNAL; return NULL; } lex (li); if (!(zc->s1 = rpn_structure (li, o, proto, num_attr, max_attr, attr_list, attr_clist, attr_set))) return NULL; if (!(zc->s2 = rpn_structure (li, o, proto, num_attr, max_attr, attr_list, attr_clist, attr_set))) return NULL; return zc;}static void rpn_term_type (struct yaz_pqf_parser *li, ODR o){ if (!li->query_look) return ; if (compare_term (li, "general", 0)) li->term_type = Z_Term_general; else if (compare_term (li, "numeric", 0)) li->term_type = Z_Term_numeric; else if (compare_term (li, "string", 0)) li->term_type = Z_Term_characterString; else if (compare_term (li, "oid", 0)) li->term_type = Z_Term_oid; else if (compare_term (li, "datetime", 0)) li->term_type = Z_Term_dateTime; else if (compare_term (li, "null", 0)) li->term_type = Z_Term_null; else if (compare_term(li, "range", 0)) { /* prepare for external: range search .. */ li->term_type = Z_Term_external; li->external_type = VAL_MULTISRCH2; } lex (li);} static Z_RPNStructure *rpn_structure (struct yaz_pqf_parser *li, ODR o, oid_proto proto, int num_attr, int max_attr, int *attr_list, char **attr_clist, oid_value *attr_set){ Z_RPNStructure *sz; sz = (Z_RPNStructure *)odr_malloc (o, sizeof(*sz)); switch (li->query_look) { case 'a': case 'o': case 'n': case 'p': sz->which = Z_RPNStructure_complex; if (!(sz->u.complex = rpn_complex (li, o, proto, num_attr, max_attr, attr_list, attr_clist, attr_set))) return NULL; break; case 't': case 's': sz->which = Z_RPNStructure_simple; if (!(sz->u.simple = rpn_simple (li, o, proto, num_attr, attr_list, attr_clist, attr_set))) return NULL; break; case 'l': lex (li); if (!li->query_look) { li->error = YAZ_PQF_ERROR_MISSING; return 0; } if (num_attr >= max_attr) { li->error = YAZ_PQF_ERROR_TOOMANY; return 0; } if (!p_query_parse_attr(li, o, num_attr, attr_list, attr_clist, attr_set)) return 0; num_attr++; lex (li); return rpn_structure (li, o, proto, num_attr, max_attr, attr_list, attr_clist, attr_set); case 'y': lex (li); rpn_term_type (li, o); return rpn_structure (li, o, proto, num_attr, max_attr, attr_list, attr_clist, attr_set); case 0: /* operator/operand expected! */ li->error = YAZ_PQF_ERROR_MISSING; return 0; } return sz;}Z_RPNQuery *p_query_rpn_mk (ODR o, struct yaz_pqf_parser *li, oid_proto proto, const char *qbuf){ Z_RPNQuery *zq; int attr_array[1024]; char *attr_clist[512]; oid_value attr_set[512]; oid_value topSet = VAL_NONE; zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq)); lex (li); if (li->query_look == 'r') { lex (li); topSet = query_oid_getvalbyname (li); if (topSet == VAL_NONE) { li->error = YAZ_PQF_ERROR_ATTSET; return NULL; } lex (li); } if (topSet == VAL_NONE) topSet = p_query_dfset; if (topSet == VAL_NONE) topSet = VAL_BIB1; zq->attributeSetId = yaz_oidval_to_z3950oid(o, CLASS_ATTSET, topSet); if (!zq->attributeSetId) { li->error = YAZ_PQF_ERROR_ATTSET; return 0; } if (!(zq->RPNStructure = rpn_structure (li, o, proto, 0, 512, attr_array, attr_clist, attr_set))) return 0; if (li->query_look) { li->error = YAZ_PQF_ERROR_EXTRA; return 0; } return zq;}Z_RPNQuery *p_query_rpn (ODR o, oid_proto proto, const char *qbuf){ struct yaz_pqf_parser li; li.error = 0; li.left_sep = "{\""; li.right_sep = "}\""; li.escape_char = '@'; li.term_type = Z_Term_general; li.query_buf = li.query_ptr = qbuf; li.lex_buf = 0; return p_query_rpn_mk (o, &li, proto, qbuf);}Z_AttributesPlusTerm *p_query_scan_mk (struct yaz_pqf_parser *li, ODR o, oid_proto proto, Odr_oid **attributeSetP, const char *qbuf){ int attr_list[1024]; char *attr_clist[512]; oid_value attr_set[512]; int num_attr = 0; int max_attr = 512; oid_value topSet = VAL_NONE; Z_AttributesPlusTerm *apt; lex (li); if (li->query_look == 'r') { lex (li); topSet = query_oid_getvalbyname (li); lex (li); } if (topSet == VAL_NONE) topSet = p_query_dfset; if (topSet == VAL_NONE) topSet = VAL_BIB1; *attributeSetP = yaz_oidval_to_z3950oid (o, CLASS_ATTSET, topSet); while (1) { if (li->query_look == 'l') { lex (li); if (!li->query_look) { li->error = YAZ_PQF_ERROR_MISSING; return 0; } if (num_attr >= max_attr) { li->error = YAZ_PQF_ERROR_TOOMANY; return 0; } if (!p_query_parse_attr(li, o, num_attr, attr_list, attr_clist, attr_set)) return 0; num_attr++; lex (li); } else if (li->query_look == 'y') { lex (li); rpn_term_type (li, o); } else break; } if (!li->query_look) { li->error = YAZ_PQF_ERROR_MISSING; return 0; } apt = rpn_term (li, o, proto, num_attr, attr_list, attr_clist, attr_set); lex (li); if (li->query_look != 0) { li->error = YAZ_PQF_ERROR_EXTRA; return 0; } return apt;}Z_AttributesPlusTerm *p_query_scan (ODR o, oid_proto proto, Odr_oid **attributeSetP, const char *qbuf){ struct yaz_pqf_parser li; li.error = 0; li.left_sep = "{\""; li.right_sep = "}\""; li.escape_char = '@'; li.term_type = Z_Term_general; li.query_buf = li.query_ptr = qbuf; li.lex_buf = 0; return p_query_scan_mk (&li, o, proto, attributeSetP, qbuf);}int p_query_attset (const char *arg){ p_query_dfset = oid_getvalbyname (arg); return (p_query_dfset == VAL_NONE) ? -1 : 0;}YAZ_PQF_Parser yaz_pqf_create (void){ YAZ_PQF_Parser p = (YAZ_PQF_Parser) xmalloc (sizeof(*p)); p->error = 0; p->left_sep = "{\""; p->right_sep = "}\""; p->escape_char = '@'; p->term_type = Z_Term_general; return p;}void yaz_pqf_destroy (YAZ_PQF_Parser p){ xfree (p);}Z_RPNQuery *yaz_pqf_parse (YAZ_PQF_Parser p, ODR o, const char *qbuf){ if (!p) return 0; p->query_buf = p->query_ptr = qbuf; p->lex_buf = 0; return p_query_rpn_mk (o, p, PROTO_Z3950, qbuf);}Z_AttributesPlusTerm *yaz_pqf_scan (YAZ_PQF_Parser p, ODR o, Odr_oid **attributeSetP, const char *qbuf){ if (!p) return 0; p->query_buf = p->query_ptr = qbuf; p->lex_buf = 0; return p_query_scan_mk (p, o, PROTO_Z3950, attributeSetP, qbuf);}int yaz_pqf_error (YAZ_PQF_Parser p, const char **msg, size_t *off){ switch (p->error) { case YAZ_PQF_ERROR_NONE: *msg = "no error"; break; case YAZ_PQF_ERROR_EXTRA: *msg = "extra token"; break; case YAZ_PQF_ERROR_MISSING: *msg = "missing token"; break; case YAZ_PQF_ERROR_ATTSET: *msg = "unknown attribute set"; break; case YAZ_PQF_ERROR_TOOMANY: *msg = "too many attributes"; break; case YAZ_PQF_ERROR_BADATTR: *msg = "bad attribute specification"; break; case YAZ_PQF_ERROR_INTERNAL: *msg = "internal error"; break; default: *msg = "unknown error"; break; } *off = p->query_ptr - p->query_buf; return p->error;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -