* Sebastian Hammer, Adam Dickmeiss
*
* $Log: charmap.c,v $
- * Revision 1.16 1999-09-07 07:19:21 adam
+ * Revision 1.17 1999-09-08 12:13:21 adam
+ * Fixed minor bug "replace"-mappings. Removed some logging messages.
+ *
+ * Revision 1.16 1999/09/07 07:19:21 adam
* Work on character mapping. Implemented replace rules.
*
* Revision 1.15 1999/05/26 07:49:14 adam
case 't': c = '\t'; (*s)++; break;
case 's': c = ' '; (*s)++; break;
case 'x': sscanf(*s, "x%2x", &i); c = i; *s += 3; break;
- case '{': case '[': case '(': case '}': case ']': case ')': case '$':
- (*s)++;
- break;
- default:
- sscanf(*s, "%3o", &i); c = i; *s += 3; break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ sscanf(*s, "%3o", &i);
+ c = i;
+ *s += 3;
+ break;
+ default:
+ (*s)++;
}
return c;
}
chrwork *arg = (chrwork *) data;
assert(arg->map->input);
- logf (LOG_LOG, "set map %.*s", (int) strlen(s), s);
+ logf (LOG_DEBUG, "set map %.*s", (int) strlen(s), s);
set_map_string(arg->map->input, arg->map->nmem, s, strlen(s), arg->string);
for (s = arg->string; *s; s++)
- logf (LOG_LOG, " %3d", (unsigned char) *s);
+ logf (LOG_DEBUG, " %3d", (unsigned char) *s);
}
/*
chrwork *arg = (chrwork *) data;
assert(arg->map->q_input);
- logf (LOG_LOG, "set qmap %.*s", (int) strlen(s), s);
+ logf (LOG_DEBUG, "set qmap %.*s", (int) strlen(s), s);
set_map_string(arg->map->q_input, arg->map->nmem, s,
strlen(s), arg->string);
for (s = arg->string; *s; s++)
- logf (LOG_LOG, " %3d", (unsigned char) *s);
+ logf (LOG_DEBUG, " %3d", (unsigned char) *s);
}
int argc, num = (int) *CHR_BASE, i;
NMEM nmem;
- logf (LOG_LOG, "maptab %s open", name);
+ logf (LOG_DEBUG, "maptab %s open", name);
if (!(f = yaz_path_fopen(tabpath, name, "r")))
{
logf(LOG_WARN|LOG_ERRNO, "%s", name);
chrmaptab_destroy(res);
res = 0;
}
- logf (LOG_LOG, "maptab %s close %d errors", name, errors);
+ logf (LOG_DEBUG, "maptab %s close %d errors", name, errors);
return res;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zebramap.c,v $
- * Revision 1.16 1999-09-07 07:19:21 adam
+ * Revision 1.17 1999-09-08 12:13:21 adam
+ * Fixed minor bug "replace"-mappings. Removed some logging messages.
+ *
+ * Revision 1.16 1999/09/07 07:19:21 adam
* Work on character mapping. Implemented replace rules.
*
* Revision 1.15 1999/05/26 07:49:14 adam
#define ZEBRA_MAP_TYPE_SORT 1
#define ZEBRA_MAP_TYPE_INDEX 2
+#define ZEBRA_REPLACE_ANY 300
+
struct zm_token {
- char *token_from;
+ int *token_from;
char *token_to;
int token_min;
struct zm_token *next;
(*zm)->maptab = NULL;
(*zm)->completeness = 0;
(*zm)->positioned = 0;
+ (*zm)->replace_tokens = 0;
}
else if (zm && !yaz_matchstr (argv[0], "charmap") && argc == 2)
{
else if (zm && !yaz_matchstr (argv[0], "replace") && argc >= 2)
{
struct zm_token *token = nmem_malloc (zms->nmem, sizeof(*token));
- char *cp, *dp;
token->next = (*zm)->replace_tokens;
(*zm)->replace_tokens = token;
- dp = token->token_from = nmem_strdup (zms->nmem, cp = argv[1]);
- while (*cp)
- {
- if (*cp == '$')
- {
- *dp++ = ' ';
- cp++;
- }
- else
- *dp++ = zebra_prim(&cp);
+ token->token_from = 0;
+ if (argc >= 2)
+ {
+ char *cp = argv[1];
+ int *dp = token->token_from = (int *)
+ nmem_malloc (zms->nmem, (1+strlen(cp))*sizeof(int));
+ while (*cp)
+ if (*cp == '$')
+ {
+ *dp++ = ' ';
+ cp++;
+ }
+ else if (*cp == '.')
+ {
+ *dp++ = ZEBRA_REPLACE_ANY;
+ cp++;
+ }
+ else
+ *dp++ = zebra_prim(&cp);
+ *dp = '\0';
}
- *dp = '\0';
-
if (argc >= 3)
{
- dp = token->token_to = nmem_strdup (zms->nmem, cp = argv[2]);
+ char *cp = argv[2];
+ char *dp = token->token_to =
+ nmem_malloc (zms->nmem, strlen(cp)+1);
while (*cp)
- {
if (*cp == '$')
{
*dp++ = ' ';
}
else
*dp++ = zebra_prim(&cp);
- }
*dp = '\0';
}
else
wrbuf_write(zms->wrbuf_1, input_str, input_len);
if (!zm->replace_tokens)
return zms->wrbuf_1;
-
+
#if 0
- logf (LOG_LOG, "zebra_replace");
logf (LOG_LOG, "in:%.*s:", wrbuf_len(zms->wrbuf_1),
wrbuf_buf(zms->wrbuf_1));
#endif
c = ' ';
else
c = tolower(input_str[j+i]);
- if (token->token_from[j] == '.')
+ if (token->token_from[j] == ZEBRA_REPLACE_ANY)
{
if (c == ' ')
break;