/*
* IR toolkit for tcl/tk
* (c) Index Data 1995
+ * See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: marc.c,v $
- * Revision 1.1 1995-05-26 08:54:19 adam
+ * Revision 1.4 1995-06-22 13:15:09 adam
+ * Feature: SUTRS. Setting getSutrs implemented.
+ * Work on display formats.
+ * Preferred record syntax can be set by the user.
+ *
+ * Revision 1.3 1995/05/29 08:44:26 adam
+ * Work on delete of objects.
+ *
+ * Revision 1.2 1995/05/26 11:44:11 adam
+ * Bugs fixed. More work on MARC utilities and queries. Test
+ * client is up-to-date again.
+ *
+ * Revision 1.1 1995/05/26 08:54:19 adam
* New MARC utilities. Uses prefix query.
*
*/
#define ISO2709_FS 036
#define ISO2709_IDFS 037
-int atoi_n (const char *buf, int len)
+static int atoi_n (const char *buf, int len)
{
int val = 0;
{
if (isdigit (*buf))
val = val*10 + (*buf - '0');
+ else if (*buf != ' ')
+ return 0;
buf++;
}
return val;
return *f - *p;
}
-FILE *outf = stderr;
-
char *ir_tcl_fread_marc (FILE *inf, size_t *size)
{
char length[5];
int length_data_entry;
int length_starting;
int length_implementation;
+ char ptag[4];
int mode = 0;
+ *ptag = '\0';
if (!strcmp (argv[3], "field"))
mode = 'f';
- else if (!strcmp (argv[3], "lines"))
+ else if (!strcmp (argv[3], "lines") || !strcmp (argv[3], "list"))
mode = 'l';
else
{
Tcl_AppendResult (interp, "Unknown MARC extract mode", NULL);
return TCL_ERROR;
}
+ if (!buf)
+ {
+ Tcl_AppendResult (interp, "Not a MARC record", NULL);
+ return TCL_ERROR;
+ }
record_length = atoi_n (buf, 5);
if (record_length < 25)
{
continue;
while (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS && i < end_offset)
{
+ int i0;
+
if (memcmp (tag, "00", 2) && identifier_length)
{
- int i0;
i++;
for (j = 1; j<identifier_length; j++)
identifier[j-1] = buf[i++];
buf[i] != ISO2709_FS && i < end_offset;
i++)
;
- if (marc_compare (identifier, argv[6])==0)
- {
- char *data = malloc (i-i0+1);
-
- memcpy (data, buf+i0, i-i0);
- data[i-i0] = '\0';
- Tcl_AppendElement (interp, data);
- free (data);
- }
}
else
{
- int i0;
-
for (i0 = i; buf[i] != ISO2709_RS &&
buf[i] != ISO2709_FS && i < end_offset;
i++)
;
- if (marc_compare (NULL, argv[6])==0)
- {
- char *data = malloc (i-i0+1);
-
- memcpy (data, buf+i0, i-i0);
- data[i-i0] = '\0';
- Tcl_AppendElement (interp, data);
- free (data);
- }
-
+ *identifier = '\0';
}
+ if (marc_compare (identifier, argv[6])==0)
+ {
+ char *data = malloc (i-i0+1);
+
+ memcpy (data, buf+i0, i-i0);
+ data[i-i0] = '\0';
+ if (mode == 'l')
+ {
+ if (strcmp (tag, ptag))
+ {
+ if (*ptag)
+ Tcl_AppendResult (interp, "}} ", NULL);
+ if (!*indicator)
+ Tcl_AppendResult (interp, "{", tag, " {} {", NULL);
+ else
+ Tcl_AppendResult (interp, "{", tag, " {",
+ indicator, "} {", NULL);
+ strcpy (ptag, tag);
+ }
+ if (!*identifier)
+ Tcl_AppendResult (interp, "{{}", NULL);
+ else
+ Tcl_AppendResult (interp, "{", identifier, NULL);
+ Tcl_AppendElement (interp, data);
+ Tcl_AppendResult (interp, "} ", NULL);
+ }
+ else
+ Tcl_AppendElement (interp, data);
+ free (data);
+ }
}
if (i < end_offset)
- fprintf (outf, "-- separator but not at end of field\n");
+ logf (LOG_WARN, "MARC: separator but not at end of field");
if (buf[i] != ISO2709_RS && buf[i] != ISO2709_FS)
- fprintf (outf, "-- no separator at end of field\n");
+ logf (LOG_WARN, "MARC: no separator at end of field");
}
+ if (mode == 'l' && *ptag)
+ Tcl_AppendResult (interp, "}} ", NULL);
return TCL_OK;
}
-#if 0
-int ir_tcl_get_marc_fields(Tcl_Interp *interp, const char *buf,
- size_t size, int argc, char **argv)
-{
- Iso2709Anchor a;
- char *data;
- if (!rec)
- return TCL_OK;
- a = iso2709_a_mk (rec);
- while (iso2709_a_search (a, argv[4], argv[5], argv[6]))
- {
- if (!(iso2709_a_info_field (a, NULL, NULL, NULL, &data)))
- break;
- Tcl_AppendElement (interp, data);
- iso2709_a_next (a);
- }
- iso2709_a_rm (a);
- return TCL_OK;
-}
-int ir_tcl_get_marc_lines(Tcl_Interp *interp, const char *buf,
- size_t size, int argc, char **argv)
-{
- Iso2709Anchor a;
- char *tag;
- char *indicator;
- char *identifier;
- char *data;
- char *ptag = "";
-
- if (!rec)
- return TCL_OK;
- a = iso2709_a_mk (rec);
- while (iso2709_a_search (a, argv[4], argv[5], argv[6]))
- {
- if (!(iso2709_a_info_field (a, &tag, &indicator, &identifier, &data)))
- break;
- if (strcmp (tag, ptag))
- {
- if (*ptag)
- Tcl_AppendResult (interp, "}} ", NULL);
- if (!indicator)
- Tcl_AppendResult (interp, "{", tag, " {} {", NULL);
- else
- Tcl_AppendResult (interp, "{", tag, " {", indicator,
- "} {", NULL);
- ptag = tag;
- }
- if (!identifier)
- Tcl_AppendResult (interp, "{{}", NULL);
- else
- Tcl_AppendResult (interp, "{", identifier, NULL);
- Tcl_AppendElement (interp, data);
- Tcl_AppendResult (interp, "} ", NULL);
- iso2709_a_next (a);
- }
- if (*ptag)
- Tcl_AppendResult (interp, "}} ", NULL);
- iso2709_a_rm (a);
- return TCL_OK;
-}
-#endif