-/* $Id: d1_espec.c,v 1.5 2004-11-19 10:26:53 heikki Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
- Index Data Aps
-
-This file is part of the Zebra server.
+/* This file is part of the Zebra server.
+ Copyright (C) Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdlib.h>
#include <assert.h>
#include <string.h>
+#include <ctype.h>
+#include <yaz/log.h>
#include <yaz/odr.h>
#include <yaz/proto.h>
-#include <yaz/ylog.h>
#include <idzebra/data1.h>
+#include <yaz/oid_db.h>
static Z_Variant *read_variant(int argc, char **argv, NMEM nmem,
const char *file, int lineno)
{
Z_Variant *r = (Z_Variant *)nmem_malloc(nmem, sizeof(*r));
- oident var1;
int i;
- int oid[OID_SIZE];
-
- var1.proto = PROTO_Z3950;
- var1.oclass = CLASS_VARSET;
- var1.value = VAL_VAR1;
- r->globalVariantSetId = odr_oiddup_nmem(nmem, oid_ent_to_oid(&var1, oid));
+ r->globalVariantSetId = odr_oiddup_nmem(nmem, yaz_oid_varset_variant_1);
if (argc)
r->triples = (Z_Triple **)nmem_malloc(nmem, sizeof(Z_Triple*) * argc);
else
}
t = r->triples[i] = (Z_Triple *)nmem_malloc(nmem, sizeof(Z_Triple));
t->variantSetId = 0;
- t->zclass = (int *)nmem_malloc(nmem, sizeof(int));
- *t->zclass = zclass;
- t->type = (int *)nmem_malloc(nmem, sizeof(int));
- *t->type = type;
+ t->zclass = nmem_intdup(nmem, zclass);
+ t->type = nmem_intdup(nmem, type);
/*
* This is wrong.. we gotta look up the correct type for the
* variant, I guess... damn this stuff.
else if (d1_isdigit(*value))
{
t->which = Z_Triple_integer;
- t->value.integer = (int *)
- nmem_malloc(nmem, sizeof(*t->value.integer));
- *t->value.integer = atoi(value);
+ t->value.integer = nmem_intdup(nmem, atoi(value));
}
else
{
t->which = Z_Triple_internationalString;
- t->value.internationalString = (char *)
- nmem_malloc(nmem, strlen(value)+1);
- strcpy(t->value.internationalString, value);
+ t->value.internationalString = nmem_strdup(nmem, value);
}
}
return r;
{
Z_Occurrences *op = (Z_Occurrences *)nmem_malloc(nmem, sizeof(*op));
char *p;
-
+
if (!occ)
{
op->which = Z_Occurrences_values;
op->u.values = (Z_OccurValues *)
nmem_malloc(nmem, sizeof(Z_OccurValues));
- op->u.values->start = (int *)nmem_malloc(nmem, sizeof(int));
- *op->u.values->start = 1;
+ op->u.values->start = nmem_intdup(nmem, 1);
op->u.values->howMany = 0;
}
else if (!strcmp(occ, "all"))
else
{
Z_OccurValues *ov = (Z_OccurValues *)nmem_malloc(nmem, sizeof(*ov));
-
+
if (!d1_isdigit(*occ))
{
yaz_log(YLOG_WARN, "%s:%d: Bad occurrences-spec %s",
}
op->which = Z_Occurrences_values;
op->u.values = ov;
- ov->start = (int *)nmem_malloc(nmem, sizeof(*ov->start));
- *ov->start = atoi(occ);
+ ov->start = nmem_intdup(nmem, atoi(occ));
if ((p = strchr(occ, '+')))
- {
- ov->howMany = (int *)nmem_malloc(nmem, sizeof(*ov->howMany));
- *ov->howMany = atoi(p + 1);
- }
+ ov->howMany = nmem_intdup(nmem, atoi(p + 1));
else
ov->howMany = 0;
}
int terms;
int type;
char value[512], occ[512];
-
+
if (*buf == '*')
{
u->which = Z_ETagUnit_wildPath;
Z_SpecificTag *t;
char *valp = value;
int force_string = 0;
-
+
if (*valp == '\'')
{
valp++;
force_string = 1;
+ if (*valp && valp[strlen(valp)-1] == '\'')
+ *valp = '\0';
}
u->which = Z_ETagUnit_specificTag;
u->u.specificTag = t = (Z_SpecificTag *)nmem_malloc(nmem, sizeof(*t));
- t->tagType = (int *)nmem_malloc(nmem, sizeof(*t->tagType));
- *t->tagType = type;
+ t->tagType = nmem_intdup(nmem, type);
t->tagValue = (Z_StringOrNumeric *)
nmem_malloc(nmem, sizeof(*t->tagValue));
- if (!force_string && (numval = atoi(valp)))
+ if (!force_string && isdigit(*(unsigned char *)valp))
{
+ numval = atoi(valp);
t->tagValue->which = Z_StringOrNumeric_numeric;
- t->tagValue->u.numeric = (int *)nmem_malloc(nmem, sizeof(int));
- *t->tagValue->u.numeric = numval;
+ t->tagValue->u.numeric = nmem_intdup(nmem, numval);
}
else
{
t->tagValue->which = Z_StringOrNumeric_string;
- t->tagValue->u.string = (char *)nmem_malloc(nmem, strlen(valp)+1);
- strcpy(t->tagValue->u.string, valp);
+ t->tagValue->u.string = nmem_strdup(nmem, valp);
}
if (terms > 2) /* an occurrences-spec exists */
t->occurrences = read_occurrences(occ, nmem, file, lineno);
else
t->occurrences = 0;
}
+ else if ((terms = sscanf(buf, "%511[^)]", value)) >= 1)
+ {
+ Z_SpecificTag *t;
+ char *valp = value;
+
+ u->which = Z_ETagUnit_specificTag;
+ u->u.specificTag = t = (Z_SpecificTag *)nmem_malloc(nmem, sizeof(*t));
+ t->tagType = nmem_intdup(nmem, 3);
+ t->tagValue = (Z_StringOrNumeric *)
+ nmem_malloc(nmem, sizeof(*t->tagValue));
+ t->tagValue->which = Z_StringOrNumeric_string;
+ t->tagValue->u.string = nmem_strdup(nmem, valp);
+ t->occurrences = read_occurrences("all", nmem, file, lineno);
+ }
else
{
return 0;
int argc, size_esn = 0;
char *argv[50], line[512];
Z_Espec1 *res = (Z_Espec1 *)nmem_malloc(nmem, sizeof(*res));
-
+
if (!(f = data1_path_fopen(dh, file, "r")))
- {
- yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", file);
return 0;
- }
-
+
res->num_elementSetNames = 0;
res->elementSetNames = 0;
res->defaultVariantSetId = 0;
res->defaultTagType = 0;
res->num_elements = 0;
res->elements = 0;
-
+
while ((argc = readconf_line(f, &lineno, line, 512, argv, 50)))
if (!strcmp(argv[0], "elementsetnames"))
{
int nnames = argc-1, i;
-
+
if (!nnames)
{
yaz_log(YLOG_WARN, "%s:%d: Empty elementsetnames directive",
file, lineno);
continue;
}
-
+
res->elementSetNames =
(char **)nmem_malloc(nmem, sizeof(char**)*nnames);
for (i = 0; i < nnames; i++)
{
- res->elementSetNames[i] = (char *)
- nmem_malloc(nmem, strlen(argv[i+1])+1);
- strcpy(res->elementSetNames[i], argv[i+1]);
+ res->elementSetNames[i] = nmem_strdup(nmem, argv[i+1]);
}
res->num_elementSetNames = nnames;
}
file, lineno, argv[0]);
continue;
}
- res->defaultTagType = (int *)nmem_malloc(nmem, sizeof(int));
- *res->defaultTagType = atoi(argv[1]);
+ res->defaultTagType = nmem_intdup(nmem, atoi(argv[1]));
}
else if (!strcmp(argv[0], "defaultvariantrequest"))
{
char *path = argv[1];
char *ep;
int num, i = 0;
-
+
if (!res->elements)
res->elements = (Z_ElementRequest **)
nmem_malloc(nmem, size_esn = 24*sizeof(er));
file, lineno, argv[0]);
continue;
}
-
+
res->elements[res->num_elements++] = er =
(Z_ElementRequest *)nmem_malloc(nmem, sizeof(*er));
er->which = Z_ERequest_simpleElement;
;
tp->tags = (Z_ETagUnit **)
nmem_malloc(nmem, sizeof(Z_ETagUnit*)*num);
-
+
for ((ep = strchr(path, '/')) ; path ;
(void)((path = ep) && (ep = strchr(path, '/'))))
{
Z_ETagUnit *tagunit;
if (ep)
ep++;
-
+
assert(i<num);
tagunit = read_tagunit(path, nmem, file, lineno);
if (!tagunit)
}
tp->tags[tp->num_tags++] = tagunit;
}
-
+
if (argc > 2 && !strcmp(argv[2], "variant"))
se->variantRequest=
read_variant(argc-3, argv+3, nmem, file, lineno);
fclose (f);
return res;
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+