-struct grs_handler {
- RecTypeGrs type;
- void *clientData;
- int initFlag;
- struct grs_handler *next;
-};
-
-struct grs_handlers {
- struct grs_handler *handlers;
-};
-
-static int read_grs_type (struct grs_handlers *h,
- struct grs_read_info *p, const char *type,
- data1_node **root)
-{
- struct grs_handler *gh = h->handlers;
- const char *cp = strchr (type, '.');
-
- if (cp == NULL || cp == type)
- {
- cp = strlen(type) + type;
- *p->type = 0;
- }
- else
- strcpy (p->type, cp+1);
- for (gh = h->handlers; gh; gh = gh->next)
- {
- if (!memcmp (type, gh->type->type, cp-type) &&
- gh->type->type[cp-type] == '\0')
- {
- if (!gh->initFlag)
- {
- gh->initFlag = 1;
- gh->clientData = (*gh->type->init)();
- }
- p->clientData = gh->clientData;
- *root = (gh->type->read)(p);
- gh->clientData = p->clientData;
- return 0;
- }
- }
- return 1;
-}
-
-static void grs_add_handler (struct grs_handlers *h, RecTypeGrs t)
-{
- struct grs_handler *gh = (struct grs_handler *) xmalloc (sizeof(*gh));
- gh->next = h->handlers;
- h->handlers = gh;
- gh->initFlag = 0;
- gh->clientData = 0;
- gh->type = t;
-}
-
-static void *grs_init(RecType recType)
-{
- struct grs_handlers *h = (struct grs_handlers *) xmalloc (sizeof(*h));
- h->handlers = 0;
-
- grs_add_handler (h, recTypeGrs_sgml);
- grs_add_handler (h, recTypeGrs_regx);
-#if HAVE_TCL_H
- grs_add_handler (h, recTypeGrs_tcl);
-#endif
- grs_add_handler (h, recTypeGrs_marc);
- grs_add_handler (h, recTypeGrs_marcxml);
-#if HAVE_EXPAT_H
- grs_add_handler (h, recTypeGrs_xml);
-#endif
-#if HAVE_PERL
- grs_add_handler (h, recTypeGrs_perl);
-#endif
- grs_add_handler (h, recTypeGrs_danbib);
- return h;
-}
-
-static void grs_destroy(void *clientData)
-{
- struct grs_handlers *h = (struct grs_handlers *) clientData;
- struct grs_handler *gh = h->handlers, *gh_next;
- while (gh)
- {
- gh_next = gh->next;
- if (gh->initFlag)
- (*gh->type->destroy)(gh->clientData);
- xfree (gh);
- gh = gh_next;
- }
- xfree (h);
-}
-