From ddccceb2d9e85c93eca315233f73adf6743bc2bf Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 11 May 1995 14:03:56 +0000 Subject: [PATCH] Changes in the reading of qualifier(s). New function: ccl_qual_fitem. New variable ccl_case_sensitive, which controls whether reserved words and field names are case sensitive or not. --- ccl/Makefile | 11 +++-- ccl/bib1 | 3 +- ccl/cclqfile.c | 151 ++++++++++++++++++++++++++++++++------------------------ ccl/cclqual.c | 20 ++++++-- ccl/cclsh.c | 10 +++- ccl/cclstr.c | 57 +++++++++++++++++++++ ccl/ccltoken.c | 29 ++++++++--- include/ccl.h | 12 ++++- 8 files changed, 213 insertions(+), 80 deletions(-) create mode 100644 ccl/cclstr.c diff --git a/ccl/Makefile b/ccl/Makefile index 841ec93..109daa8 100644 --- a/ccl/Makefile +++ b/ccl/Makefile @@ -2,7 +2,12 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.9 1995/04/17 09:31:34 adam +# Revision 1.10 1995/05/11 14:03:56 adam +# Changes in the reading of qualifier(s). New function: ccl_qual_fitem. +# New variable ccl_case_sensitive, which controls whether reserved +# words and field names are case sensitive or not. +# +# Revision 1.9 1995/04/17 09:31:34 adam # Improved handling of qualifiers. Aliases or reserved words. # # Revision 1.8 1995/04/10 10:22:35 quinn @@ -31,11 +36,11 @@ INCLUDE=-I../include #CFLAGS=-g -Wall -pedantic -ansi TPROG1=cclsh LIB=../lib/ccl.a -PO=cclfind.o ccltoken.o cclerrms.o cclqual.o cclptree.o cclqfile.o +PO=cclfind.o ccltoken.o cclerrms.o cclqual.o cclptree.o cclqfile.o cclstr.o CPP=$(CC) -E DEFS=$(INCLUDE) -all: $(LIB) +all: $(LIB) $(TPROG1) $(TPROG1): $(TPROG1).o $(LIB) $(CC) $(CFLAGS) -o $(TPROG1) $(TPROG1).o $(LIB) diff --git a/ccl/bib1 b/ccl/bib1 index 173e4e5..973174a 100644 --- a/ccl/bib1 +++ b/ccl/bib1 @@ -1,4 +1,4 @@ -# $Id: bib1,v 1.4 1995/04/17 09:31:38 adam Exp $ +# $Id: bib1,v 1.5 1995/05/11 14:03:56 adam Exp $ # CCL qualifiers and their mapping to a bib-1 subset # term s=pw t=l,r @@ -16,6 +16,7 @@ ab u=62 s=pw note u=63 s=pw af u=1006 s=pw rel s=9 +cln # Relation Attributes rel:lt r=1 diff --git a/ccl/cclqfile.c b/ccl/cclqfile.c index dd6f63c..888707d 100644 --- a/ccl/cclqfile.c +++ b/ccl/cclqfile.c @@ -2,7 +2,12 @@ * Europagate, 1995 * * $Log: cclqfile.c,v $ - * Revision 1.1 1995/04/17 09:31:45 adam + * Revision 1.2 1995/05/11 14:03:56 adam + * Changes in the reading of qualifier(s). New function: ccl_qual_fitem. + * New variable ccl_case_sensitive, which controls whether reserved + * words and field names are case sensitive or not. + * + * Revision 1.1 1995/04/17 09:31:45 adam * Improved handling of qualifiers. Aliases or reserved words. * */ @@ -14,6 +19,85 @@ #include +void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name) +{ + char qual_type[128]; + int no_scan; + int pair[128]; + int pair_no = 0; + + while (1) + { + char *qual_value; + char *split; + + if (sscanf (cp, "%s%n", qual_type, &no_scan) != 1) + break; + + if (!(split = strchr (qual_type, '='))) + break; + cp += no_scan; + + *split++ = '\0'; + while (1) + { + int type, value; + + qual_value = split; + if ((split = strchr (qual_value, ','))) + *split++ = '\0'; + value = atoi (qual_value); + switch (qual_type[0]) + { + case 'u': + case 'U': + type = CCL_BIB1_USE; + break; + case 'r': + case 'R': + type = CCL_BIB1_REL; + if (!ccl_stricmp (qual_value, "o")) + value = CCL_BIB1_REL_ORDER; + break; + case 'p': + case 'P': + type = CCL_BIB1_POS; + break; + case 's': + case 'S': + type = CCL_BIB1_STR; + if (!ccl_stricmp (qual_value, "pw")) + value = CCL_BIB1_STR_WP; + break; + case 't': + case 'T': + type = CCL_BIB1_TRU; + if (!ccl_stricmp (qual_value, "l")) + value = CCL_BIB1_TRU_CAN_LEFT; + else if (!ccl_stricmp (qual_value, "r")) + value = CCL_BIB1_TRU_CAN_RIGHT; + else if (!ccl_stricmp (qual_value, "b")) + value = CCL_BIB1_TRU_CAN_BOTH; + else if (!ccl_stricmp (qual_value, "n")) + value = CCL_BIB1_TRU_CAN_NONE; + break; + case 'c': + case 'C': + type = CCL_BIB1_COM; + break; + default: + type = atoi (qual_type); + } + pair[pair_no*2] = type; + pair[pair_no*2+1] = value; + pair_no++; + if (!split) + break; + } + } + ccl_qual_add (bibset, qual_name, pair_no, pair); +} + /* * ccl_qual_file: Read bibset definition from file. * bibset: Bibset @@ -32,7 +116,6 @@ 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)) @@ -43,68 +126,6 @@ void ccl_qual_file (CCL_bibset bibset, FILE *inf) if (sscanf (cp, "%s%n", qual_name, &no_scan) != 1) continue; /* also ignore empty lines */ 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); - } - ccl_qual_add (bibset, qual_name, 1, pair); - if (!split) - break; - qual_value = split; - } - } + ccl_qual_fitem (bibset, cp, qual_name); } } diff --git a/ccl/cclqual.c b/ccl/cclqual.c index 117702d..857a17c 100644 --- a/ccl/cclqual.c +++ b/ccl/cclqual.c @@ -2,7 +2,12 @@ * Europagate, 1995 * * $Log: cclqual.c,v $ - * Revision 1.7 1995/04/17 09:31:46 adam + * Revision 1.8 1995/05/11 14:03:57 adam + * Changes in the reading of qualifier(s). New function: ccl_qual_fitem. + * New variable ccl_case_sensitive, which controls whether reserved + * words and field names are case sensitive or not. + * + * Revision 1.7 1995/04/17 09:31:46 adam * Improved handling of qualifiers. Aliases or reserved words. * * Revision 1.6 1995/02/23 08:32:00 adam @@ -138,8 +143,17 @@ struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len) assert (b); for (q = b->list; q; q = q->next) - if (strlen(q->name) == len && !memcmp (name, q->name, len)) - return q->attr_list; + if (strlen(q->name) == len) + if (ccl_case_sensitive) + { + if (!memcmp (name, q->name, len)) + return q->attr_list; + } + else + { + if (!ccl_memicmp (name, q->name, len)) + return q->attr_list; + } return NULL; } diff --git a/ccl/cclsh.c b/ccl/cclsh.c index e1500e7..f7f3a0e 100644 --- a/ccl/cclsh.c +++ b/ccl/cclsh.c @@ -2,7 +2,12 @@ * Europagate 1995 * * $Log: cclsh.c,v $ - * Revision 1.9 1995/02/23 08:32:00 adam + * Revision 1.10 1995/05/11 14:03:57 adam + * Changes in the reading of qualifier(s). New function: ccl_qual_fitem. + * New variable ccl_case_sensitive, which controls whether reserved + * words and field names are case sensitive or not. + * + * Revision 1.9 1995/02/23 08:32:00 adam * Changed header. * * Revision 1.7 1995/02/15 17:42:16 adam @@ -54,6 +59,9 @@ int main (int argc, char **argv) { switch (argv[0][1]) { + case 'c': + ccl_case_sensitive = 0; + break; case 'd': debug = 1; break; diff --git a/ccl/cclstr.c b/ccl/cclstr.c new file mode 100644 index 0000000..434182a --- /dev/null +++ b/ccl/cclstr.c @@ -0,0 +1,57 @@ +/* CCL string compare utilities + * Europagate, 1995 + * + * $Log: cclstr.c,v $ + * Revision 1.1 1995/05/11 14:03:57 adam + * Changes in the reading of qualifier(s). New function: ccl_qual_fitem. + * New variable ccl_case_sensitive, which controls whether reserved + * words and field names are case sensitive or not. + * + */ +#include +#include + +#include + +static int ccli_toupper (int c) +{ + return toupper (c); +} + +int (*ccl_toupper)(int c) = NULL; + +int ccl_stricmp (const char *s1, const char *s2) +{ + if (!ccl_toupper) + ccl_toupper = ccli_toupper; + while (*s1 && *s2) + { + int c1, c2; + c1 = (*ccl_toupper)(*s1); + c2 = (*ccl_toupper)(*s2); + if (c1 != c2) + return c1 - c2; + s1++; + s2++; + } + return (*ccl_toupper)(*s1) - (*ccl_toupper)(*s2); +} + +int ccl_memicmp (const char *s1, const char *s2, size_t n) +{ + if (!ccl_toupper) + ccl_toupper = ccli_toupper; + while (1) + { + int c1, c2; + + c1 = (*ccl_toupper)(*s1); + c2 = (*ccl_toupper)(*s2); + if (n <= 1 || c1 != c2) + return c1 - c2; + s1++; + s2++; + --n; + } +} + diff --git a/ccl/ccltoken.c b/ccl/ccltoken.c index 26a45f6..51cdf0e 100644 --- a/ccl/ccltoken.c +++ b/ccl/ccltoken.c @@ -2,7 +2,12 @@ * Europagate, 1995 * * $Log: ccltoken.c,v $ - * Revision 1.7 1995/04/19 12:11:24 adam + * Revision 1.8 1995/05/11 14:03:57 adam + * Changes in the reading of qualifier(s). New function: ccl_qual_fitem. + * New variable ccl_case_sensitive, which controls whether reserved + * words and field names are case sensitive or not. + * + * Revision 1.7 1995/04/19 12:11:24 adam * Minor change. * * Revision 1.6 1995/04/17 09:31:48 adam @@ -36,6 +41,7 @@ const char *ccl_token_and = "and"; const char *ccl_token_or = "or"; const char *ccl_token_not = "not andnot"; const char *ccl_token_set = "set"; +int ccl_case_sensitive = 1; /* * token_cmp: Compare token with keyword(s) @@ -52,13 +58,24 @@ static int token_cmp (const char *kw, struct ccl_token *token) return 0; while ((cp2 = strchr (cp1, ' '))) { - if (token->len == cp2-cp1 && - !memcmp (cp1, token->name, token->len)) - return 1; + if (token->len == cp2-cp1) + if (ccl_case_sensitive) + { + if (!memcmp (cp1, token->name, token->len)) + return 1; + } + else + { + if (!ccl_memicmp (cp1, token->name, token->len)) + return 1; + } cp1 = cp2+1; } - return token->len == strlen(cp1) - && !memcmp (cp1, token->name, token->len); + if (ccl_case_sensitive) + return token->len == strlen(cp1) + && !memcmp (cp1, token->name, token->len); + return token->len == strlen(cp1) && + !ccl_memicmp (cp1, token->name, token->len); } /* diff --git a/include/ccl.h b/include/ccl.h index 84ce87a..6980755 100644 --- a/include/ccl.h +++ b/include/ccl.h @@ -2,7 +2,12 @@ * Europagate, 1995 * * $Log: ccl.h,v $ - * Revision 1.5 1995/02/23 08:32:11 adam + * Revision 1.6 1995/05/11 14:04:03 adam + * Changes in the reading of qualifier(s). New function: ccl_qual_fitem. + * New variable ccl_case_sensitive, which controls whether reserved + * words and field names are case sensitive or not. + * + * Revision 1.5 1995/02/23 08:32:11 adam * Changed header. * * Revision 1.3 1995/02/16 13:20:10 adam @@ -146,6 +151,7 @@ void ccl_pr_tree (struct ccl_rpn_node *rpn, FILE *fd_out); void ccl_qual_add (CCL_bibset b, const char *name, int no, int *attr); void ccl_qual_file (CCL_bibset bibset, FILE *inf); +void ccl_qual_fitem (CCL_bibset bibset, const char *cp, const char *qual_name); CCL_bibset ccl_qual_mk (void); void ccl_qual_rm (CCL_bibset *b); @@ -153,7 +159,11 @@ extern const char *ccl_token_and; extern const char *ccl_token_or; extern const char *ccl_token_not; extern const char *ccl_token_set; +extern int ccl_case_sensitive; +extern int (*ccl_toupper)(int c); +int ccl_stricmp (const char *s1, const char *s2); +int ccl_memicmp (const char *s1, const char *s2, size_t n); struct ccl_rpn_attr *ccl_qual_search (CCL_bibset b, const char *name, int len); #endif -- 1.7.10.4