From d30e034fc508f9d901f0fa60113eb160e2d7406f Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 17 Mar 2004 11:00:04 +0000 Subject: [PATCH] Use more compact way to store MARC-8 conversion tables --- CHANGELOG | 2 ++ src/Makefile.am | 4 ++-- src/charconv.tcl | 31 +++++++++++++++++++------------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7d05f8c..128cf0f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ Possible compatibility problems with earlier versions marked with '*'. +Use a more compact way to store MARC-8 conversion tables. + --- 2.0.16 2004/03/16 Debian only Oleg Kolobov Fixed a bug in yaz_iconv regarding conversion to diff --git a/src/Makefile.am b/src/Makefile.am index de8916d..9f8962e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ ## Copyright (C) 1994-2004, Index Data ## All rights reserved. -## $Id: Makefile.am,v 1.10 2004-03-16 13:12:42 adam Exp $ +## $Id: Makefile.am,v 1.11 2004-03-17 11:00:04 adam Exp $ if ISTHR thrlib=libyazthread.la @@ -35,7 +35,7 @@ THREADED_FLAGS = @CFLAGSTHREADS@ # MARC8 conversion is generated from charconv.sgm + codetables.xml marc8.c: charconv.tcl charconv.sgm codetables.xml - cd $(srcdir); ./charconv.tcl -O 1 -p marc8 -s 50 charconv.sgm codetables.xml -o marc8.c + cd $(srcdir); ./charconv.tcl -O 1 -p marc8 charconv.sgm codetables.xml -o marc8.c libyaz_la_SOURCES=version.c options.c log.c marcdisp.c oid.c wrbuf.c \ nmemsdup.c xmalloc.c readconf.c tpath.c nmem.c matchstr.c atoin.c \ diff --git a/src/charconv.tcl b/src/charconv.tcl index 5ad4be1..7d1fd07 100755 --- a/src/charconv.tcl +++ b/src/charconv.tcl @@ -2,7 +2,7 @@ # the next line restats using tclsh \ exec tclsh "$0" "$@" # -# $Id: charconv.tcl,v 1.4 2004-03-16 13:13:34 adam Exp $ +# $Id: charconv.tcl,v 1.5 2004-03-17 11:00:04 adam Exp $ proc usage {} { puts {charconv.tcl: [-p prefix] [-s split] [-o ofile] file ... } @@ -17,11 +17,11 @@ proc preamble_trie {ofilehandle} { puts $f "\#include " puts $f " struct yaz_iconv_trie_flat { - char *from; + char from\[6\]; $totype to; }; struct yaz_iconv_trie_dir { - struct yaz_iconv_trie *ptr; + short ptr; $totype to; }; @@ -31,16 +31,17 @@ proc preamble_trie {ofilehandle} { }; " puts $f { - static unsigned long lookup(struct yaz_iconv_trie *t, unsigned char *inp, + static unsigned long lookup(struct yaz_iconv_trie **ptrs, int ptr, unsigned char *inp, size_t inbytesleft, size_t *no_read) { + struct yaz_iconv_trie *t = (ptr >= 0) ? ptrs[ptr] : 0; if (!t || inbytesleft < 1) - return 0; + return 0; if (t->dir) { size_t ch = inp[0] & 0xff; unsigned long code = - lookup(t->dir[ch].ptr, inp+1, inbytesleft-1, no_read); + lookup(ptrs, t->dir[ch].ptr, inp+1, inbytesleft-1, no_read); if (code) { (*no_read)++; @@ -72,7 +73,6 @@ proc preamble_trie {ofilehandle} { } return 0; } - } } @@ -86,7 +86,7 @@ proc reset_trie {} { set trie(no) 1 set trie(size) 0 set trie(max) 0 - set trie(split) 40 + set trie(split) 50 set trie(prefix) {} } @@ -189,10 +189,10 @@ proc dump_trie {ofilehandle} { set ch [format %02X $i] set null 1 if {[info exist trie($this,ptr,$ch)]} { - puts -nonewline $f "&$trie(prefix)page$trie($this,ptr,$ch), " + puts -nonewline $f "$trie($this,ptr,$ch), " set null 0 } else { - puts -nonewline $f "0, " + puts -nonewline $f "-1, " } if {[info exist trie($this,to,$ch)]} { puts -nonewline $f "0x$trie($this,to,$ch)\}" @@ -215,12 +215,20 @@ proc dump_trie {ofilehandle} { puts $f "\};" } } + + puts $f "struct yaz_iconv_trie *$trie(prefix)ptrs \[\] = {" + for {set this 0} {$this < $trie(no)} {incr this} { + puts $f " &$trie(prefix)page$this," + } + puts $f "0, };" + puts $f "" + puts $f "unsigned long yaz_$trie(prefix)_conv (unsigned char *inp, size_t inbytesleft, size_t *no_read) { unsigned long code; - code = lookup(&$trie(prefix)page0, inp, inbytesleft, no_read); + code = lookup($trie(prefix)ptrs, 0, inp, inbytesleft, no_read); if (!code) { *no_read = 1; @@ -283,7 +291,6 @@ proc readfile {fname ofilehandle prefix omits} { set verbose 0 set ifile {} set ofile out.c -set trie(split) 40 set prefix {c} # Parse command line set l [llength $argv] -- 1.7.10.4