X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zutil%2Fpquery.c;h=46b221ad88f67f7fd2e68df6d4e2a14d888c8855;hb=ed00497d5186ebac1435b0f5e1ef2fe732cfa05c;hp=f507ac7c38796346062f1c92001e17b1cc2d8489;hpb=c1957f49e5f8c37c06ed839cde52d60108bc2e35;p=yaz-moved-to-github.git diff --git a/zutil/pquery.c b/zutil/pquery.c index f507ac7..46b221a 100644 --- a/zutil/pquery.c +++ b/zutil/pquery.c @@ -1,102 +1,8 @@ /* - * Copyright (c) 1995-2001, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * - * $Log: pquery.c,v $ - * Revision 1.7 2001-05-09 23:31:35 adam - * String attribute values for PQF. Proper C-backslash escaping for PQF. - * - * Revision 1.6 2001/03/07 13:24:40 adam - * Member and_not in Z_Operator is kept for backwards compatibility. - * Added support for definition of CCL operators in field spec file. - * - * Revision 1.5 2001/02/21 13:46:54 adam - * C++ fixes. - * - * Revision 1.4 1999/12/21 16:25:20 adam - * Fixed handling of default/inherited attributes. - * - * Revision 1.3 1999/12/20 15:20:13 adam - * Implemented ccl_pquery to convert from CCL tree to prefix query. - * - * Revision 1.2 1999/11/30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.1 1999/06/08 10:10:16 adam - * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree. - * - * Revision 1.22 1999/04/20 09:56:49 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.21 1998/10/13 16:03:37 adam - * Better checking for invalid OID's in p_query_rpn. - * - * Revision 1.20 1998/03/31 15:13:20 adam - * Development towards compiled ASN.1. - * - * Revision 1.19 1998/03/05 08:09:03 adam - * Minor change to make C++ happy. - * - * Revision 1.18 1998/02/11 11:53:36 adam - * Changed code so that it compiles as C++. - * - * Revision 1.17 1997/11/24 11:33:57 adam - * Using function odr_nullval() instead of global ODR_NULLVAL when - * appropriate. - * - * Revision 1.16 1997/09/29 13:19:00 adam - * Added function, oid_ent_to_oid, to replace the function - * oid_getoidbyent, which is not thread safe. - * - * Revision 1.15 1997/09/29 07:13:43 adam - * Changed type of a few variables to avoid warnings. - * - * Revision 1.14 1997/09/22 12:33:41 adam - * Fixed bug introduced by previous commit. - * - * Revision 1.13 1997/09/17 12:10:42 adam - * YAZ version 1.4. - * - * Revision 1.12 1997/09/01 08:54:13 adam - * New windows NT/95 port using MSV5.0. Made prefix query handling - * thread safe. The function options ignores empty arguments when met. - * - * Revision 1.11 1996/11/11 13:15:29 adam - * Added proximity operator. - * - * Revision 1.10 1996/08/12 14:10:35 adam - * New function p_query_attset to define default attribute set. - * - * Revision 1.9 1996/03/15 11:03:46 adam - * Attribute set can be set globally for a query with the @attrset - * operator. The @attr operator has an optional attribute-set specifier - * that sets the attribute set locally. - * - * Revision 1.8 1996/01/02 11:46:56 quinn - * Changed 'operator' to 'roperator' to avoid C++ conflict. - * - * Revision 1.7 1995/09/29 17:12:36 quinn - * Smallish - * - * Revision 1.6 1995/09/27 15:03:03 quinn - * Modified function heads & prototypes. - * - * Revision 1.5 1995/06/15 12:31:02 quinn - * *** empty log message *** - * - * Revision 1.4 1995/06/15 07:45:19 quinn - * Moving to v3. - * - * Revision 1.3 1995/06/14 11:06:35 adam - * Bug fix: Attributes wasn't interpreted correctly! - * - * Revision 1.2 1995/05/26 08:56:11 adam - * New function: p_query_scan. - * - * Revision 1.1 1995/05/22 15:31:49 adam - * New function, p_query_rpn, to convert from prefix (ascii) to rpn (asn). - * + * $Id: pquery.c,v 1.14 2002-05-01 10:22:52 adam Exp $ */ #include @@ -164,7 +70,13 @@ static int query_token (struct lex_info *li) ++(*qptr); } li->lex_buf = *qptr; - + + if (**qptr == li->escape_char && isdigit ((*qptr)[1])) + { + ++(li->lex_len); + ++(*qptr); + return 'l'; + } while (**qptr && **qptr != sep_char) { if (**qptr == '\\') @@ -177,7 +89,8 @@ static int query_token (struct lex_info *li) } if (**qptr) ++(*qptr); - if (li->lex_len >= 1 && li->lex_buf[0] == li->escape_char) + if (sep_char == ' ' && + li->lex_len >= 1 && li->lex_buf[0] == li->escape_char) { if (compare_term (li, "and", 1)) return 'a'; @@ -301,7 +214,7 @@ static int p_query_parse_attr(struct lex_info *li, ODR o, { int len = li->lex_len - (cp - li->lex_buf); attr_list[2*num_attr+1] = 0; - attr_clist[num_attr] = odr_malloc (o, len+1); + attr_clist[num_attr] = (char *) odr_malloc (o, len+1); len = escape_string(attr_clist[num_attr], cp, len); attr_clist[num_attr][len] = '\0'; } @@ -345,20 +258,9 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o, elements[k] = (Z_AttributeElement*)odr_malloc (o,sizeof(**elements)); elements[k]->attributeType = &attr_tmp[2*i]; - if (attr_set[i] == VAL_NONE) - elements[k]->attributeSet = 0; - else - { - oident attrid; - int oid[OID_SIZE]; - - attrid.proto = PROTO_Z3950; - attrid.oclass = CLASS_ATTSET; - attrid.value = attr_set[i]; - - elements[k]->attributeSet = - odr_oiddup (o, oid_ent_to_oid (&attrid, oid)); - } + elements[k]->attributeSet = + yaz_oidval_to_z3950oid(o, CLASS_ATTSET, attr_set[i]); + if (attr_clist[i]) { elements[k]->which = Z_AttributeValue_complex; @@ -388,22 +290,17 @@ static Z_AttributesPlusTerm *rpn_term (struct lex_info *li, ODR o, } num_attr = k; } -#ifdef ASN_COMPILED zapt->attributes = (Z_AttributeList *) odr_malloc (o, sizeof(*zapt->attributes)); zapt->attributes->num_attributes = num_attr; zapt->attributes->attributes = elements; -#else - zapt->num_attributes = num_attr; - zapt->attributeList = elements; -#endif zapt->term = term; term->which = Z_Term_general; term->u.general = term_octet; term_octet->buf = (unsigned char *)odr_malloc (o, li->lex_len); term_octet->size = term_octet->len = - escape_string (term_octet->buf, li->lex_buf, li->lex_len); + escape_string ((char *) (term_octet->buf), li->lex_buf, li->lex_len); return zapt; } @@ -421,13 +318,13 @@ static Z_Operand *rpn_simple (struct lex_info *li, ODR o, oid_proto proto, if (!(zo->u.attributesPlusTerm = rpn_term (li, o, proto, num_attr, attr_list, attr_clist, attr_set))) - return NULL; + return 0; lex (li); break; case 's': lex (li); if (!li->query_look) - return NULL; + return 0; zo->which = Z_Operand_resultSetId; zo->u.resultSetId = (char *)odr_malloc (o, li->lex_len+1); memcpy (zo->u.resultSetId, li->lex_buf, li->lex_len); @@ -435,7 +332,7 @@ static Z_Operand *rpn_simple (struct lex_info *li, ODR o, oid_proto proto, lex (li); break; default: - return NULL; + return 0; } return zo; } @@ -485,14 +382,9 @@ static Z_ProximityOperator *rpn_proximity (struct lex_info *li, ODR o) if (!lex (li)) return NULL; -#ifdef ASN_COMPILED p->which = Z_ProximityOperator_known; p->u.known = (int *)odr_malloc (o, sizeof(*p->u.known)); *p->u.known = atoi (li->lex_buf); -#else - p->proximityUnitCode = (int *)odr_malloc (o, sizeof(*p->proximityUnitCode)); - *p->proximityUnitCode = atoi (li->lex_buf); -#endif return p; } @@ -578,7 +470,9 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, return NULL; if (num_attr >= max_attr) return NULL; - p_query_parse_attr(li, o, num_attr, attr_list, attr_clist, attr_set); + if (!p_query_parse_attr(li, o, num_attr, attr_list, + attr_clist, attr_set)) + return 0; num_attr++; lex (li); return @@ -618,8 +512,6 @@ Z_RPNQuery *p_query_rpn_mk (ODR o, struct lex_info *li, oid_proto proto, char *attr_clist[512]; oid_value attr_set[512]; oid_value topSet = VAL_NONE; - oident oset; - int oid[OID_SIZE]; zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq)); lex (li); @@ -636,13 +528,11 @@ Z_RPNQuery *p_query_rpn_mk (ODR o, struct lex_info *li, oid_proto proto, topSet = p_query_dfset; if (topSet == VAL_NONE) topSet = VAL_BIB1; - oset.proto = proto; - oset.oclass = CLASS_ATTSET; - oset.value = topSet; - if (!oid_ent_to_oid (&oset, oid)) - return NULL; - zq->attributeSetId = odr_oiddup (o, oid); + zq->attributeSetId = yaz_oidval_to_z3950oid(o, CLASS_ATTSET, topSet); + + if (!zq->attributeSetId) + return 0; if (!(zq->RPNStructure = rpn_structure (li, o, proto, 0, 512, attr_array, attr_clist, attr_set))) @@ -675,8 +565,6 @@ Z_AttributesPlusTerm *p_query_scan_mk (struct lex_info *li, int num_attr = 0; int max_attr = 512; oid_value topSet = VAL_NONE; - oident oset; - int oid[OID_SIZE]; lex (li); if (li->query_look == 'r') @@ -690,20 +578,19 @@ Z_AttributesPlusTerm *p_query_scan_mk (struct lex_info *li, topSet = p_query_dfset; if (topSet == VAL_NONE) topSet = VAL_BIB1; - oset.proto = proto; - oset.oclass = CLASS_ATTSET; - oset.value = topSet; - *attributeSetP = odr_oiddup (o, oid_ent_to_oid (&oset, oid)); + *attributeSetP = yaz_oidval_to_z3950oid (o, CLASS_ATTSET, topSet); while (li->query_look == 'l') { lex (li); if (!li->query_look) - return NULL; + return 0; if (num_attr >= max_attr) - return NULL; - p_query_parse_attr(li, o, num_attr, attr_list, attr_clist, attr_set); + return 0; + if (!p_query_parse_attr(li, o, num_attr, attr_list, + attr_clist, attr_set)) + return 0; num_attr++; lex (li); }