X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fpquery.c;h=69f4a6c043275852d5cf97410cbaa226cf2ec2fb;hb=80fee38926477efd73c739731c5670d59c5d1bf7;hp=a9dbcc3bada58bab874e1f648e9db33c4fd865ca;hpb=7a4064cd15f6c6b34c1180e1bc51f0d0e90da320;p=yaz-moved-to-github.git diff --git a/src/pquery.c b/src/pquery.c index a9dbcc3..69f4a6c 100644 --- a/src/pquery.c +++ b/src/pquery.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2010 Index Data * See the file LICENSE for details. - * - * $Id: pquery.c,v 1.10 2007-04-12 13:52:57 adam Exp $ */ /** * \file pquery.c @@ -33,14 +31,14 @@ struct yaz_pqf_parser { static Z_RPNStructure *rpn_structure(struct yaz_pqf_parser *li, ODR o, int num_attr, int max_attr, - int *attr_list, char **attr_clist, - int **attr_set); + Odr_int *attr_list, char **attr_clist, + Odr_oid **attr_set); -static int *query_oid_getvalbyname(struct yaz_pqf_parser *li, ODR o) +static Odr_oid *query_oid_getvalbyname(struct yaz_pqf_parser *li, ODR o) { char buf[32]; - if (li->lex_len > 31) + if (li->lex_len >= sizeof(buf)-1) return 0; memcpy (buf, li->lex_buf, li->lex_len); buf[li->lex_len] = '\0'; @@ -185,8 +183,8 @@ static int escape_string(char *out_buf, const char *in, int len) } static int p_query_parse_attr(struct yaz_pqf_parser *li, ODR o, - int num_attr, int *attr_list, - char **attr_clist, int **attr_set) + int num_attr, Odr_int *attr_list, + char **attr_clist, Odr_oid **attr_set) { const char *cp; @@ -241,8 +239,8 @@ static int p_query_parse_attr(struct yaz_pqf_parser *li, ODR o, } static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o, - int num_attr, int *attr_list, - char **attr_clist, int **attr_set) + int num_attr, Odr_int *attr_list, + char **attr_clist, Odr_oid **attr_set) { Z_AttributesPlusTerm *zapt; Odr_oct *term_octet; @@ -258,13 +256,13 @@ static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o, else { int i, k = 0; - int *attr_tmp; + Odr_int *attr_tmp; elements = (Z_AttributeElement**) odr_malloc (o, num_attr * sizeof(*elements)); - attr_tmp = (int *)odr_malloc (o, num_attr * 2 * sizeof(int)); - memcpy (attr_tmp, attr_list, num_attr * 2 * sizeof(int)); + attr_tmp = (Odr_int *)odr_malloc(o, num_attr * 2 * sizeof(*attr_tmp)); + memcpy(attr_tmp, attr_list, num_attr * 2 * sizeof(*attr_tmp)); for (i = num_attr; --i >= 0; ) { int j; @@ -294,8 +292,7 @@ static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o, Z_StringOrNumeric_string; elements[k]->value.complex->list[0]->u.string = attr_clist[i]; - elements[k]->value.complex->semanticAction = (int **) - odr_nullval(); + elements[k]->value.complex->semanticAction = 0; elements[k]->value.complex->num_semanticAction = 0; } else @@ -351,8 +348,9 @@ static Z_AttributesPlusTerm *rpn_term(struct yaz_pqf_parser *li, ODR o, } static Z_Operand *rpn_simple(struct yaz_pqf_parser *li, ODR o, - int num_attr, int *attr_list, char **attr_clist, - int **attr_set) + int num_attr, Odr_int *attr_list, + char **attr_clist, + Odr_oid **attr_set) { Z_Operand *zo; @@ -362,7 +360,7 @@ static Z_Operand *rpn_simple(struct yaz_pqf_parser *li, ODR o, case 't': zo->which = Z_Operand_APT; if (!(zo->u.attributesPlusTerm = - rpn_term (li, o, num_attr, attr_list, attr_clist, attr_set))) + rpn_term(li, o, num_attr, attr_list, attr_clist, attr_set))) return 0; lex (li); break; @@ -398,9 +396,9 @@ static Z_ProximityOperator *rpn_proximity (struct yaz_pqf_parser *li, ODR o) return NULL; } if (*li->lex_buf == '1') - p->exclusion = odr_intdup (o, 1); + p->exclusion = odr_booldup(o, 1); else if (*li->lex_buf == '0') - p->exclusion = odr_intdup (o, 0); + p->exclusion = odr_booldup(o, 0); else if (*li->lex_buf == 'v' || *li->lex_buf == 'n') p->exclusion = NULL; else @@ -428,9 +426,9 @@ static Z_ProximityOperator *rpn_proximity (struct yaz_pqf_parser *li, ODR o) return NULL; } if (*li->lex_buf == '1') - p->ordered = odr_intdup (o, 1); + p->ordered = odr_booldup(o, 1); else if (*li->lex_buf == '0') - p->ordered = odr_intdup (o, 0); + p->ordered = odr_booldup(o, 0); else { li->error = YAZ_PQF_ERROR_PROXIMITY; @@ -486,8 +484,8 @@ static Z_ProximityOperator *rpn_proximity (struct yaz_pqf_parser *li, ODR o) static Z_Complex *rpn_complex(struct yaz_pqf_parser *li, ODR o, int num_attr, int max_attr, - int *attr_list, char **attr_clist, - int **attr_set) + Odr_int *attr_list, char **attr_clist, + Odr_oid **attr_set) { Z_Complex *zc; Z_Operator *zo; @@ -533,7 +531,7 @@ static Z_Complex *rpn_complex(struct yaz_pqf_parser *li, ODR o, return zc; } -static void rpn_term_type(struct yaz_pqf_parser *li, ODR o) +static void rpn_term_type(struct yaz_pqf_parser *li) { if (!li->query_look) return ; @@ -562,9 +560,9 @@ static void rpn_term_type(struct yaz_pqf_parser *li, ODR o) static Z_RPNStructure *rpn_structure(struct yaz_pqf_parser *li, ODR o, int num_attr, int max_attr, - int *attr_list, + Odr_int *attr_list, char **attr_clist, - int **attr_set) + Odr_oid **attr_set) { Z_RPNStructure *sz; @@ -611,7 +609,7 @@ static Z_RPNStructure *rpn_structure(struct yaz_pqf_parser *li, ODR o, attr_clist, attr_set); case 'y': lex (li); - rpn_term_type (li, o); + rpn_term_type(li); return rpn_structure (li, o, num_attr, max_attr, attr_list, attr_clist, attr_set); @@ -622,13 +620,13 @@ static Z_RPNStructure *rpn_structure(struct yaz_pqf_parser *li, ODR o, return sz; } -Z_RPNQuery *p_query_rpn_mk(ODR o, struct yaz_pqf_parser *li, const char *qbuf) +static Z_RPNQuery *p_query_rpn_mk(ODR o, struct yaz_pqf_parser *li) { Z_RPNQuery *zq; - int attr_array[1024]; + Odr_int attr_array[1024]; char *attr_clist[512]; - int *attr_set[512]; - int *top_set = 0; + Odr_oid *attr_set[512]; + Odr_oid *top_set = 0; zq = (Z_RPNQuery *)odr_malloc (o, sizeof(*zq)); lex (li); @@ -645,8 +643,7 @@ Z_RPNQuery *p_query_rpn_mk(ODR o, struct yaz_pqf_parser *li, const char *qbuf) } if (!top_set) { - top_set = yaz_string_to_oid_odr(yaz_oid_std(), - CLASS_ATTSET, OID_STR_BIB1, o); + top_set = odr_oiddup(o, yaz_oid_attset_bib_1); } zq->attributeSetId = top_set; @@ -679,21 +676,20 @@ Z_RPNQuery *p_query_rpn(ODR o, const char *qbuf) li.term_type = Z_Term_general; li.query_buf = li.query_ptr = qbuf; li.lex_buf = 0; - return p_query_rpn_mk(o, &li, qbuf); + return p_query_rpn_mk(o, &li); } -Z_AttributesPlusTerm *p_query_scan_mk(struct yaz_pqf_parser *li, - ODR o, oid_proto proto, - Odr_oid **attributeSetP, - const char *qbuf) +static Z_AttributesPlusTerm *p_query_scan_mk(struct yaz_pqf_parser *li, + ODR o, + Odr_oid **attributeSetP) { - int attr_list[1024]; + Odr_int attr_list[1024]; char *attr_clist[512]; - int *attr_set[512]; + Odr_oid *attr_set[512]; int num_attr = 0; int max_attr = 512; - int *top_set = 0; + Odr_oid *top_set = 0; Z_AttributesPlusTerm *apt; lex (li); @@ -710,8 +706,7 @@ Z_AttributesPlusTerm *p_query_scan_mk(struct yaz_pqf_parser *li, } if (!top_set) { - top_set = yaz_string_to_oid_odr(yaz_oid_std(), - CLASS_ATTSET, OID_STR_BIB1, o); + top_set = odr_oiddup(o, yaz_oid_attset_bib_1); } *attributeSetP = top_set; @@ -739,7 +734,7 @@ Z_AttributesPlusTerm *p_query_scan_mk(struct yaz_pqf_parser *li, else if (li->query_look == 'y') { lex (li); - rpn_term_type (li, o); + rpn_term_type(li); } else break; @@ -775,7 +770,7 @@ Z_AttributesPlusTerm *p_query_scan (ODR o, oid_proto proto, li.query_buf = li.query_ptr = qbuf; li.lex_buf = 0; - return p_query_scan_mk (&li, o, proto, attributeSetP, qbuf); + return p_query_scan_mk(&li, o, attributeSetP); } YAZ_PQF_Parser yaz_pqf_create (void) @@ -802,7 +797,7 @@ Z_RPNQuery *yaz_pqf_parse(YAZ_PQF_Parser p, ODR o, const char *qbuf) return 0; p->query_buf = p->query_ptr = qbuf; p->lex_buf = 0; - return p_query_rpn_mk (o, p, qbuf); + return p_query_rpn_mk(o, p); } Z_AttributesPlusTerm *yaz_pqf_scan(YAZ_PQF_Parser p, ODR o, @@ -813,7 +808,7 @@ Z_AttributesPlusTerm *yaz_pqf_scan(YAZ_PQF_Parser p, ODR o, return 0; p->query_buf = p->query_ptr = qbuf; p->lex_buf = 0; - return p_query_scan_mk (p, o, PROTO_Z3950, attributeSetP, qbuf); + return p_query_scan_mk(p, o, attributeSetP); } int yaz_pqf_error (YAZ_PQF_Parser p, const char **msg, size_t *off) @@ -847,6 +842,7 @@ int yaz_pqf_error (YAZ_PQF_Parser p, const char **msg, size_t *off) /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab