X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=marc.c;h=8bbb69c265f7e5a74f29397de2d056cbaa255d1b;hb=f4dfdf10de44985020d90581aa426d106dddc542;hp=5b546ab9eca937564bb0e99ee694a3a9662e5815;hpb=4ca298d78bdacb8a44057b66fcda06a2c012def4;p=ir-tcl-moved-to-github.git diff --git a/marc.c b/marc.c index 5b546ab..8bbb69c 100644 --- a/marc.c +++ b/marc.c @@ -5,7 +5,14 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: marc.c,v $ - * Revision 1.8 1995-11-14 16:48:00 adam + * Revision 1.10 1999-02-08 09:22:31 franck + * Added a grs mode for ir_tcl_get_marc which returns MARC records in a TCL + * structure similar to that of ir_tcl_get_grs. + * + * Revision 1.9 1996/07/03 13:31:13 adam + * The xmalloc/xfree functions from YAZ are used to manage memory. + * + * Revision 1.8 1995/11/14 16:48:00 adam * Bug fix: record extraction in line mode merged lines with same tag. * * Revision 1.7 1995/11/09 15:24:02 adam @@ -111,11 +118,11 @@ char *ir_tcl_fread_marc (FILE *inf, size_t *size) *size = atoi_n (length, 5); if (*size <= 6) return NULL; - if (!(buf = malloc (*size+1))) + if (!(buf = xmalloc (*size+1))) return NULL; if (fread (buf+5, 1, *size-5, inf) != (*size-5)) { - free (buf); + xfree (buf); return NULL; } memcpy (buf, length, 5); @@ -141,6 +148,8 @@ int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf, mode = 'f'; else if (!strcmp (argv[3], "line")) mode = 'l'; + else if (!strcmp (argv[3], "grs")) + mode = 'g'; else { Tcl_AppendResult (interp, "Unknown MARC extract mode", NULL); @@ -223,7 +232,7 @@ int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf, } if (marc_compare (identifier, argv[6])==0) { - char *data = malloc (i-i0+1); + char *data = xmalloc (i-i0+1); memcpy (data, buf+i0, i-i0); data[i-i0] = '\0'; @@ -247,12 +256,35 @@ int ir_tcl_get_marc (Tcl_Interp *interp, const char *buf, Tcl_AppendElement (interp, data); Tcl_AppendResult (interp, "} ", NULL); } + else if (mode == 'g') + { + if (strcmp (tag, ptag)) + { + if (*ptag) + Tcl_AppendResult (interp, "}} ", NULL); + if (*indicator) + Tcl_AppendResult (interp, "{ 0 numeric {", tag, + indicator, "} subtree {", NULL); + else + Tcl_AppendResult (interp, "{ 0 numeric ", tag, + " subtree {", NULL); + strcpy (ptag, tag); + } + if (*identifier) + Tcl_AppendResult (interp, "{3 string ", identifier, + " string ", NULL); + else + Tcl_AppendResult (interp, "{1 numeric 19 string ", + NULL); + Tcl_AppendElement (interp, data); + Tcl_AppendResult (interp, "} ", NULL); + } else Tcl_AppendElement (interp, data); - free (data); + xfree (data); } } - if (mode == 'l' && *ptag) + if (((mode == 'l') || (mode == 'g')) && *ptag) Tcl_AppendResult (interp, "}} ", NULL); if (i < end_offset) logf (LOG_WARN, "MARC: separator but not at end of field");