X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fcsvtodiag.tcl;fp=src%2Fcsvtodiag.tcl;h=e5d6a3f3f4ffd4a68c4ab6111e6cf1b0771ea528;hb=84d7b06c13daa609e93f353e655c4b02f936d65c;hp=0000000000000000000000000000000000000000;hpb=00757f0ff95a6e5557823e151a7ae9d6f48f0f8f;p=yaz-moved-to-github.git diff --git a/src/csvtodiag.tcl b/src/csvtodiag.tcl new file mode 100644 index 0000000..e5d6a3f --- /dev/null +++ b/src/csvtodiag.tcl @@ -0,0 +1,90 @@ +# This file is part of the YAZ toolkit +# Copyright (c) Index Data 1996-2005 +# See the file LICENSE for details. +# +# $Id: csvtodiag.tcl,v 1.1 2005-04-22 08:27:58 adam Exp $ +# +# Converts a CSV file with diagnostics to C+H file for easy +# maintenance + +proc csvtodiag {ifiles name alias} { + set uname [string toupper $name] + set funcproto "const char *yaz_diag_${name}_str(int code)" + if {[string length $alias]} { + set funcalias "const char *${alias}(int code)" + } + set csv [open [lindex $ifiles 0] r] + set cfile [open [lindex $ifiles 1] w] + set hfile [open [lindex $ifiles 2] w] + set lineno 0 + set preamble "/* Generated automatically by csvtodiag.tcl from [lindex $ifiles 0] */" + puts $cfile $preamble + puts $cfile " +#include \"diag-entry.h\" +struct yaz_diag_entry yaz_diag_${name}_tab\[\] = \{ +" + puts $hfile $preamble + puts $hfile " +\#include + +\#ifndef YAZ_DIAG_${name}_H +\#define YAZ_DIAG_${name}_H +YAZ_BEGIN_CDECL +YAZ_EXPORT $funcproto;" + + if {[info exists funcalias]} { + puts $hfile "YAZ_EXPORT $funcalias;" +} + while {1} { + incr lineno + set cnt [gets $csv line] + if {$cnt < 0} { + break + } + if {[regexp {([0-9]+)[^\"]*"([^\"]*)"} $line s code msg]} { + puts $cfile "\{$code, \"$msg\"\}," + + set m [string toupper $msg] + regsub -all {DUPLICATE} $m {DUP} m + regsub -all {SECURITY CHALLENGE} $m {SEC_CHAL} m + regsub -all {COULD NOT} $m {COULDNT} m + regsub -all {COULD NOT} $m {COULDNT} m + regsub -all {NOT SUPPORTED} $m {UNSUPP} m + regsub -all {UNSUPPORTED} $m {UNSUPP} m + regsub -all {COMBINATION} $m {COMBI} m + regsub -all {PROXIMITY} $m {PROX} m + regsub -all {CHARACTERS} $m {CHARS} m + regsub -all {CHARACTER} $m {CHAR} m + regsub -all {[-/,:;."' \{\}()]} $m _ m + set m [string map {___ _ __ _} $m] + if {[string length $m] > 55} { + set m [string range $m 0 55] + set p [string last _ $m] + if {$p > 30} { + set m [string range $m 0 $p] + } + } + puts $hfile "\#define YAZ_${uname}_${m} $code" + } + } + puts $cfile "\{0, 0\}\}\;" + puts $cfile $funcproto + puts $cfile "\{" + puts $cfile " return yaz_diag_to_str(yaz_diag_${name}_tab, code);" + puts $cfile "\}" + + if {[info exists funcalias]} { + puts $cfile $funcalias + puts $cfile "\{" + puts $cfile " return yaz_diag_to_str(yaz_diag_${name}_tab, code);" + puts $cfile "\}" + } + puts $hfile " +YAZ_END_CDECL +\#endif +" + close $csv + close $cfile + close $hfile +} +