From: Adam Dickmeiss Date: Tue, 14 Feb 1995 16:20:53 +0000 (+0000) Subject: Qualifiers are read from a file now. X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=8fd2a3304338723cbcbaf8f90f3312762de34ed9;p=egate.git Qualifiers are read from a file now. --- diff --git a/ccl/bib1 b/ccl/bib1 new file mode 100644 index 0000000..cfea312 --- /dev/null +++ b/ccl/bib1 @@ -0,0 +1,17 @@ +# $Id: bib1,v 1.1 1995/02/14 16:20:53 adam Exp $ +# CCL qualifiers and their mapping to a bib-1 subset +# +term s=pw t=l,r +au u=1 s=pw +ti u=4 s=pw +isbn u=7 +issn u=8 +cc u=20 +su u=21 s=pw +date u=30 r=o +dp u=31 r=o +da u=32 r=o +la u=54 s=pw +ab u=62 s=pw +note u=63 s=pw +af u=1006 s=pw diff --git a/ccl/ccl.h b/ccl/ccl.h index b89c498..da94d92 100644 --- a/ccl/ccl.h +++ b/ccl/ccl.h @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: ccl.h,v $ - * Revision 1.3 1995/02/14 10:25:55 adam + * Revision 1.4 1995/02/14 16:20:53 adam + * Qualifiers are read from a file now. + * + * Revision 1.3 1995/02/14 10:25:55 adam * The constructions 'qualifier rel term ...' implemented. * * Revision 1.2 1995/02/13 15:15:06 adam @@ -23,6 +26,9 @@ #define CCL_ERR_DOBBLE_QUAL 7 #define CCL_ERR_EQ_EXPECTED 8 #define CCL_ERR_BAD_RELATION 9 +#define CCL_ERR_TRUNC_NOT_LEFT 10 +#define CCL_ERR_TRUNC_NOT_BOTH 11 +#define CCL_ERR_TRUNC_NOT_RIGHT 12 struct ccl_rpn_attr { struct ccl_rpn_attr *next; @@ -52,6 +58,7 @@ void ccl_rpn_delete (struct ccl_rpn_node *rpn); void ccl_pr_tree (struct ccl_rpn_node *rpn); void ccl_qual_add (CCL_bibset b, const char *name, int no, int *attr); +void ccl_qual_file (CCL_bibset bibset, FILE *inf); CCL_bibset ccl_qual_mk (void); void ccl_qual_rm (CCL_bibset *b); struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len); @@ -96,9 +103,7 @@ struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len); #define CCL_BIB1_STR_WP (-1) #define CCL_BIB1_REL_ORDER (-1) -#define CCL_TRUNC_L 1 -#define CCL_TRUNC_R 2 -#define CCL_TRUNC_LR 4 -#define CCL_TRUNC_NONE 8 -#define CCL_TRUNC_HASH 16 -#define CCL_TRUNC_REG 32 +#define CCL_BIB1_TRU_CAN_LEFT (-1) +#define CCL_BIB1_TRU_CAN_RIGHT (-2) +#define CCL_BIB1_TRU_CAN_BOTH (-3) +#define CCL_BIB1_TRU_CAN_NONE (-4) diff --git a/ccl/cclerrms.c b/ccl/cclerrms.c index c05e6bd..be736cc 100644 --- a/ccl/cclerrms.c +++ b/ccl/cclerrms.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: cclerrms.c,v $ - * Revision 1.3 1995/02/14 10:25:56 adam + * Revision 1.4 1995/02/14 16:20:54 adam + * Qualifiers are read from a file now. + * + * Revision 1.3 1995/02/14 10:25:56 adam * The constructions 'qualifier rel term ...' implemented. * * Revision 1.2 1995/02/13 15:15:06 adam @@ -23,7 +26,10 @@ char *err_msg_array[] = { "Unknown qualifier", "Qualifiers applied twice", "'=' expected", - "Bad relation" + "Bad relation", + "Left truncation not supported", + "Both left - and right truncation not supported", + "Right truncation not supported" }; const char *ccl_err_msg (int ccl_errno) diff --git a/ccl/cclfind.c b/ccl/cclfind.c index 76556a1..3288f87 100644 --- a/ccl/cclfind.c +++ b/ccl/cclfind.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: cclfind.c,v $ - * Revision 1.5 1995/02/14 14:12:41 adam + * Revision 1.6 1995/02/14 16:20:55 adam + * Qualifiers are read from a file now. + * + * Revision 1.5 1995/02/14 14:12:41 adam * Ranges for ordered qualfiers implemented (e.g. pd=1980-1990). * * Revision 1.4 1995/02/14 13:16:29 adam @@ -45,6 +48,17 @@ static struct ccl_rpn_attr *qual_val (struct ccl_rpn_attr *list, int type) return NULL; } +static int qual_val_type (struct ccl_rpn_attr *list, int type, int value) +{ + while (list) + { + if (list->type == type && list->value == value) + return 1; + list = list->next; + } + return 0; +} + static void strxcat (char *n, const char *src, int len) { while (*n) @@ -122,6 +136,7 @@ static void add_attr (struct ccl_rpn_node *p, int type, int value) static struct ccl_rpn_node *search_term (struct ccl_rpn_attr **qa) { struct ccl_rpn_node *p; + struct ccl_rpn_attr *attr; struct ccl_token *lookahead = look_token; int len = 0; int no, i; @@ -170,12 +185,11 @@ static struct ccl_rpn_node *search_term (struct ccl_rpn_attr **qa) if (i) strcat (p->u.t.term, " "); strxcat (p->u.t.term, src_str, src_len); - ADVANCE; + ADVANCE; } if (qa) { int i; - struct ccl_rpn_attr *attr; for (i=0; qa[i]; i++) { struct ccl_rpn_attr *attr; @@ -184,21 +198,58 @@ static struct ccl_rpn_node *search_term (struct ccl_rpn_attr **qa) if (attr->value > 0) add_attr (p, attr->type, attr->value); } - if ((attr = qual_val (qa[0], CCL_BIB1_STR)) && - attr->value == CCL_BIB1_STR_WP) - { - if (no == 1) - add_attr (p, CCL_BIB1_STR, 2); - else - add_attr (p, CCL_BIB1_STR, 1); - } + attr = qa[0]; + } + else + attr = ccl_qual_search (bibset, "term", 4); + if (attr && qual_val_type (attr, CCL_BIB1_STR, CCL_BIB1_STR_WP)) + { + if (no == 1) + add_attr (p, CCL_BIB1_STR, 2); + else + add_attr (p, CCL_BIB1_STR, 1); } if (left_trunc && right_trunc) + { + if (attr && !qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH)) + { + ccl_error = CCL_ERR_TRUNC_NOT_BOTH; + if (qa) + free (qa); + ccl_rpn_delete (p); + return NULL; + } add_attr (p, CCL_BIB1_TRU, 3); + } else if (right_trunc) + { + if (attr && !qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT)) + { + ccl_error = CCL_ERR_TRUNC_NOT_RIGHT; + if (qa) + free (qa); + ccl_rpn_delete (p); + return NULL; + } add_attr (p, CCL_BIB1_TRU, 1); + } else if (left_trunc) + { + if (attr && !qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT)) + { + ccl_error = CCL_ERR_TRUNC_NOT_LEFT; + if (qa) + free (qa); + ccl_rpn_delete (p); + return NULL; + } add_attr (p, CCL_BIB1_TRU, 2); + } + else + { + if (attr && qual_val_type (attr, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE)) + add_attr (p, CCL_BIB1_TRU, 100); + } return p; } @@ -234,7 +285,8 @@ static struct ccl_rpn_node *qualifiers (struct ccl_token *la, ADVANCE; } ap[i] = NULL; - if (! (attr = qual_val (ap[0], CCL_BIB1_REL)) || attr->value == 3) + if (! (attr = qual_val (ap[0], CCL_BIB1_REL)) || + attr->value != CCL_BIB1_REL_ORDER) { /* unordered relation */ struct ccl_rpn_node *p; diff --git a/ccl/cclqual.c b/ccl/cclqual.c index 263b6ce..cb8e0a2 100644 --- a/ccl/cclqual.c +++ b/ccl/cclqual.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: cclqual.c,v $ - * Revision 1.2 1995/02/14 10:25:56 adam + * Revision 1.3 1995/02/14 16:20:56 adam + * Qualifiers are read from a file now. + * + * Revision 1.2 1995/02/14 10:25:56 adam * The constructions 'qualifier rel term ...' implemented. * * Revision 1.1 1995/02/13 15:15:07 adam @@ -23,21 +26,32 @@ struct ccl_qualifiers { void ccl_qual_add (CCL_bibset b, const char *name, int no, int *pairs) { - struct ccl_qualifier *new_qual; + struct ccl_qualifier *q; struct ccl_rpn_attr **attrp; - - assert (b); - new_qual = malloc (sizeof(*new_qual)); - assert (new_qual); - - new_qual->next = b->list; - b->list = new_qual; - - new_qual->name = malloc (strlen(name)+1); - assert (new_qual->name); - strcpy (new_qual->name, name); - attrp = &new_qual->attr_list; + assert (b); + for (q = b->list; q; q = q->next) + if (!strcmp (name, q->name)) + break; + if (!q) + { + struct ccl_qualifier *new_qual = malloc (sizeof(*new_qual)); + assert (new_qual); + + new_qual->next = b->list; + b->list = new_qual; + + new_qual->name = malloc (strlen(name)+1); + assert (new_qual->name); + strcpy (new_qual->name, name); + attrp = &new_qual->attr_list; + } + else + { + attrp = &q->attr_list; + while (*attrp) + attrp = &(*attrp)->next; + } while (--no >= 0) { struct ccl_rpn_attr *attr; @@ -76,3 +90,86 @@ struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len) return q->attr_list; return NULL; } + +void ccl_qual_file (CCL_bibset bibset, FILE *inf) +{ + char line[256]; + char *cp; + char qual_name[128]; + char qual_des[128]; + int no_scan; + + while (fgets (line, 255, inf)) + { + cp = line; + if (*cp == '#') + continue; + if (sscanf (cp, "%s%n", qual_name, &no_scan) != 1) + continue; + cp += no_scan; + while (1) + { + int pair[2]; + char *qual_type; + char *qual_value; + char *split; + + if (sscanf (cp, "%s%n", qual_des, &no_scan) != 1) + break; + + if (!(split = strchr (qual_des, '='))) + break; + cp += no_scan; + + *split++ = '\0'; + qual_type = qual_des; + qual_value = split; + while (1) + { + if ((split = strchr (qual_value, ','))) + *split++ = '\0'; + pair[1] = atoi (qual_value); + switch (qual_type[0]) + { + case 'u': + pair[0] = CCL_BIB1_USE; + break; + case 'r': + pair[0] = CCL_BIB1_REL; + if (!strcmp (qual_value, "o")) + pair[1] = CCL_BIB1_REL_ORDER; + break; + case 'p': + pair[0] = CCL_BIB1_POS; + break; + case 's': + pair[0] = CCL_BIB1_STR; + if (!strcmp (qual_value, "pw")) + pair[1] = CCL_BIB1_STR_WP; + break; + case 't': + pair[0] = CCL_BIB1_TRU; + if (!strcmp (qual_value, "l")) + pair[1] = CCL_BIB1_TRU_CAN_LEFT; + else if (!strcmp (qual_value, "r")) + pair[1] = CCL_BIB1_TRU_CAN_RIGHT; + else if (!strcmp (qual_value, "b")) + pair[1] = CCL_BIB1_TRU_CAN_BOTH; + else if (!strcmp (qual_value, "n")) + pair[1] = CCL_BIB1_TRU_CAN_NONE; + break; + case 'c': + pair[0] = CCL_BIB1_COM; + break; + default: + pair[0] = atoi (qual_type); + } + printf ("adding %s t=%d, v=%d\n", qual_name, pair[0], pair[1]); + ccl_qual_add (bibset, qual_name, 1, pair); + if (!split) + break; + qual_value = split; + } + } + } +} diff --git a/ccl/cclsh.c b/ccl/cclsh.c index 51754ec..7f5d6b0 100644 --- a/ccl/cclsh.c +++ b/ccl/cclsh.c @@ -2,7 +2,10 @@ * Europagate 1995 * * $Log: cclsh.c,v $ - * Revision 1.4 1995/02/14 14:12:42 adam + * Revision 1.5 1995/02/14 16:20:57 adam + * Qualifiers are read from a file now. + * + * Revision 1.4 1995/02/14 14:12:42 adam * Ranges for ordered qualfiers implemented (e.g. pd=1980-1990). * * Revision 1.3 1995/02/14 10:25:57 adam @@ -43,12 +46,13 @@ static int pd_attr[] = { int main (int argc, char **argv) { CCL_bibset bibset; + FILE *bib_inf; + char *bib_fname; prog = *argv; bibset = ccl_qual_mk (); while (--argc > 0) { - ++argv; if (**++argv == '-') { switch (argv[0][1]) @@ -56,6 +60,29 @@ int main (int argc, char **argv) case 'd': debug = 1; break; + case 'b': + if (argv[0][2]) + bib_fname = argv[0]+2; + else if (argc > 0) + { + --argc; + bib_fname = *++argv; + } + else + { + fprintf (stderr, "%s: missing bib filename\n", prog); + exit (1); + } + bib_inf = fopen (bib_fname, "r"); + if (!bib_inf) + { + fprintf (stderr, "%s: cannot open %s\n", prog, + bib_fname); + exit (1); + } + ccl_qual_file (bibset, bib_inf); + fclose (bib_inf); + break; default: fprintf (stderr, "%s: unknown option '%s'\n", prog, *argv); @@ -68,9 +95,6 @@ int main (int argc, char **argv) exit (1); } } - ccl_qual_add (bibset, "ti", sizeof(ti_attr)/(2*sizeof(int)), ti_attr); - ccl_qual_add (bibset, "au", sizeof(au_attr)/(2*sizeof(int)), au_attr); - ccl_qual_add (bibset, "pd", sizeof(pd_attr)/(2*sizeof(int)), pd_attr); while (1) { char buf[80]; @@ -96,5 +120,3 @@ int main (int argc, char **argv) putchar ('\n'); return 0; } - -