/* This file is part of the Zebra server.
- Copyright (C) 1994-2009 Index Data
+ Copyright (C) Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
/**
* \file charmap.c
* \brief character conversions (.chr)
- *
+ *
* Support module to handle character-conversions into and out of the
* Zebra dictionary.
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
/*
* General argument structure for callback functions (internal use only)
*/
-typedef struct chrwork
+typedef struct chrwork
{
chrmaptab map;
char string[CHR_MAXSTR+1];
}
if (!len)
{
- if (!root->target || !root->target[0] ||
+ if (!root->target || !root->target[0] ||
strcmp((const char *) root->target[0], to))
{
- if (from_0 &&
+ if (from_0 &&
root->target && root->target[0] && root->target[0][0] &&
strcmp((const char *) root->target[0], CHR_UNKNOWN))
{
else
res = 0;
/* otherwhise there was no match on beginning of field, move on */
- }
-
+ }
+
if (!res && t->children[(unsigned char) **from])
{
(*len)--;
chr_t_entry *t = maptab->q_input;
chr_t_entry *res;
int len_tmp[2];
-
+
len_tmp[0] = len;
len_tmp[1] = -1;
if (!(res = find_entry_x(t, from, len_tmp, first)))
ucs4_t i = 0;
char fmtstr[8];
- yaz_log(YLOG_DEBUG, "prim_w %.3s", (char *) *s);
if (**s == '\\' && 1[*s])
{
(*s)++;
case 'n': c = '\n'; (*s)++; break;
case 't': c = '\t'; (*s)++; break;
case 's': c = ' '; (*s)++; break;
- case 'x':
+ case 'x':
if (zebra_ucs4_strlen(*s) >= 3)
{
fmtstr[0] = (*s)[1];
{
chrmaptab tab = (chrmaptab) data;
char tmp[2];
-
+
tmp[0] = num; tmp[1] = '\0';
tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s), tmp, 0);
tab->output[num + tab->base_uppercase] =
(unsigned char *) nmem_strdup(tab->nmem, s);
}
-/*
+/*
* Callback function.
* Add a space-entry to the value space.
*/
(char*) CHR_SPACE, 0);
}
-/*
+/*
* Callback function.
* Add a space-entry to the value space.
*/
static void fun_add_equivalent_string(const char *s, void *data, int num)
{
chr_equiv_work *arg = (chr_equiv_work *) data;
-
+
if (arg->no_eq == CHR_MAXEQUIV)
return;
arg->eq[arg->no_eq++] = nmem_strdup(arg->nmem, s);
size_t inbytesleft = inlen * sizeof(ucs4_t);
char *inbuf = (char*) from;
size_t ret;
-
+
if (t == 0)
*outbuf++ = *from; /* ISO-8859-1 is OK here */
else
ret = yaz_iconv(t, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
if (ret != (size_t) (-1))
ret = yaz_iconv(t, 0, 0, &outbuf, &outbytesleft);
-
-
+
+
if (ret == (size_t) (-1))
{
yaz_log(YLOG_LOG, "from: %2X %2X %2X %2X",
ucs4_t arg[512];
ucs4_t arg_prim[512];
- ucs4_t *s0, *s = arg;
+ ucs4_t *s = arg;
ucs4_t c, begin, end;
size_t i;
char *inbuf = s_native;
size_t outbytesleft = sizeof(arg)-4;
size_t inbytesleft = strlen(s_native);
- size_t ret;
+ size_t ret;
ret = yaz_iconv(t_unicode, &inbuf, &inbytesleft,
&outbuf, &outbytesleft);
if (ret != (size_t)(-1))
ret = yaz_iconv(t_unicode, 0, 0, &outbuf, &outbytesleft);
-
+
if (ret == (size_t)(-1))
return -1;
i = (outbuf - (char*) arg)/sizeof(ucs4_t);
}
else
- {
+ {
for (i = 0; s_native[i]; i++)
arg[i] = s_native[i] & 255; /* ISO-8859-1 conversion */
}
break;
case '(':
++s;
- s0 = s; i = 0;
+ i = 0;
while (*s != ')' || s[-1] == '\\')
+ {
+ if (*s == '\0')
+ {
+ yaz_log(YLOG_FATAL, "Missing ) in charmap");
+ return -1;
+ }
arg_prim[i++] = zebra_prim_w(&s);
+ }
arg_prim[i] = 0;
if (scan_to_utf8(t_utf8, arg_prim, zebra_ucs4_strlen(arg_prim), str, sizeof(str)-1))
return -1;
}
w.nmem = res->nmem;
w.no_eq = 0;
- if (scan_string(argv[1], t_unicode, t_utf8,
+ if (scan_string(argv[1], t_unicode, t_utf8,
fun_add_equivalent_string, &w, 0) < 0)
{
yaz_log(YLOG_FATAL, "equivalent: invalid string");
yaz_log(YLOG_WARN, "Syntax error at '%s' in %s", line, name);
errors++;
}
- }
+ }
yaz_fclose(f);
if (no_directives == 0)
{
chrmaptab_destroy(res);
res = 0;
}
- yaz_log(YLOG_DEBUG, "maptab %s close %d errors", name, errors);
+ yaz_log(YLOG_DEBUG, "maptab %s num=%d close %d errors", name, num, errors);
if (t_utf8 != 0)
yaz_iconv_close(t_utf8);
if (t_unicode != 0)
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab