From: Adam Dickmeiss Date: Tue, 4 Jun 1996 10:20:02 +0000 (+0000) Subject: Added support for character mapping. X-Git-Tag: ZEBRA.1.0~432 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=7ed12b6cc4a492d6062dd56bb1ebc49c9bc75b4a Added support for character mapping. --- diff --git a/dfa/dfa.c b/dfa/dfa.c index 4c7c864..ffe11f3 100644 --- a/dfa/dfa.c +++ b/dfa/dfa.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1996, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: dfa.c,v $ - * Revision 1.11 1996-01-08 19:15:24 adam + * Revision 1.12 1996-06-04 10:20:02 adam + * Added support for character mapping. + * + * Revision 1.11 1996/01/08 19:15:24 adam * Allow single $ in expressions. * * Revision 1.10 1996/01/08 09:09:17 adam @@ -428,6 +431,30 @@ static int read_charset (void) return L_CHARS; } +static int map_l_char (void) +{ + char **mapto; + const char *cp0 = expr_ptr-1; + int i = 0, len = strlen(cp0); + + if (cp0[0] == 1 && cp0[1]) + { + expr_ptr++; + look_ch = cp0[1]; + return L_CHAR; + } + if (!parse_info->cmap) + return L_CHAR; + + mapto = (*parse_info->cmap) (&cp0, len); + assert (mapto); + + expr_ptr = cp0; + look_ch = mapto[i][0]; + logf (LOG_DEBUG, "map from %c to %d", expr_ptr[-1], look_ch); + return L_CHAR; +} + static int lex_sub(void) { int esc; @@ -435,11 +462,11 @@ static int lex_sub(void) if (look_ch == '\"') { if (esc) - return L_CHAR; + return map_l_char (); inside_string = !inside_string; } else if (esc || inside_string) - return L_CHAR; + return map_l_char (); else if (look_ch == '[') return read_charset(); else @@ -452,7 +479,7 @@ static int lex_sub(void) --expr_ptr; return cc[1]; } - return L_CHAR; + return map_l_char (); } return 0; } @@ -978,6 +1005,7 @@ static struct DFA_parse *dfa_parse_init (void) parse_info->use_Tnode = parse_info->max_Tnode = 0; parse_info->charMap = NULL; parse_info->charMapSize = 0; + parse_info->cmap = NULL; return parse_info; } @@ -1032,6 +1060,11 @@ struct DFA *dfa_init (void) return dfa; } +void dfa_set_cmap (struct DFA *dfa, char **(*cmap)(const char **from, int len)) +{ + dfa->parse_info->cmap = cmap; +} + int dfa_parse (struct DFA *dfa, const char **pattern) { struct Tnode *top; diff --git a/dfa/dfap.h b/dfa/dfap.h index 2b7dbda..6265962 100644 --- a/dfa/dfap.h +++ b/dfa/dfap.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dfap.h,v $ - * Revision 1.3 1996-01-08 09:09:19 adam + * Revision 1.4 1996-06-04 10:20:03 adam + * Added support for character mapping. + * + * Revision 1.3 1996/01/08 09:09:19 adam * Function dfa_parse got 'const' string argument. * New functions to define char mappings made public. * @@ -35,6 +38,7 @@ struct DFA_parse { struct Tblock *end; /* end block of Tnodes */ int *charMap; int charMapSize; + char **(*cmap)(const char **from, int len); }; typedef struct DFA_stateb_ { diff --git a/dict/lookgrep.c b/dict/lookgrep.c index 5d8fe87..733be36 100644 --- a/dict/lookgrep.c +++ b/dict/lookgrep.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1996, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: lookgrep.c,v $ - * Revision 1.16 1996-05-24 14:46:04 adam + * Revision 1.17 1996-06-04 10:20:06 adam + * Added support for character mapping. + * + * Revision 1.16 1996/05/24 14:46:04 adam * Added dict_grep_cmap function to define user-mapping in grep lookups. * * Revision 1.15 1996/03/20 09:35:18 adam @@ -404,6 +407,9 @@ int dict_lookup_grep (Dict dict, const char *pattern, int range, void *client, int i, d; logf (LOG_DEBUG, "dict_lookup_grep '%s' range=%d", pattern, range); + + dfa_set_cmap (dfa, dict->grep_cmap); + i = dfa_parse (dfa, &this_pattern); if (i || *this_pattern) { @@ -445,7 +451,7 @@ int dict_lookup_grep (Dict dict, const char *pattern, int range, void *client, return i; } -void dict_grep_cmap (Dict dict, char **(*cmap)(const char **from)) +void dict_grep_cmap (Dict dict, char **(*cmap)(const char **from, int len)) { dict->grep_cmap = cmap; } diff --git a/include/dfa.h b/include/dfa.h index b609433..d4a4a44 100644 --- a/include/dfa.h +++ b/include/dfa.h @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1996, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: dfa.h,v $ - * Revision 1.5 1996-01-08 09:09:48 adam + * Revision 1.6 1996-06-04 10:20:10 adam + * Added support for character mapping. + * + * Revision 1.5 1996/01/08 09:09:48 adam * Function dfa_parse got 'const' string argument. * * Revision 1.4 1995/01/25 11:31:04 adam @@ -59,6 +62,8 @@ struct DFA { }; struct DFA *dfa_init (void); +void dfa_set_cmap (struct DFA *dfa, + char **(*cmap)(const char **from, int len)); int dfa_parse (struct DFA *, const char **); void dfa_mkstate (struct DFA *); void dfa_delete (struct DFA **); diff --git a/include/dict.h b/include/dict.h index 84b6e48..4cd048c 100644 --- a/include/dict.h +++ b/include/dict.h @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994, Index Data I/S + * Copyright (C) 1994-1996, Index Data I/S * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: dict.h,v $ - * Revision 1.21 1996-05-24 14:46:07 adam + * Revision 1.22 1996-06-04 10:20:10 adam + * Added support for character mapping. + * + * Revision 1.21 1996/05/24 14:46:07 adam * Added dict_grep_cmap function to define user-mapping in grep lookups. * * Revision 1.20 1996/03/20 09:35:23 adam @@ -121,7 +124,7 @@ typedef struct Dict_file_struct typedef struct Dict_struct { int rw; Dict_BFile dbf; - char **(*grep_cmap)(const char **from); + char **(*grep_cmap)(const char **from, int len); struct Dict_head head; } *Dict; @@ -154,7 +157,8 @@ int dict_scan (Dict dict, char *str, int (*f)(char *name, const char *info, int pos, void *client)); -void dict_grep_cmap (Dict dict, char **(*cmap)(const char **from)); +void dict_grep_cmap (Dict dict, + char **(*cmap)(const char **from, int len)); #define DICT_EOS 0