X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fcsvtodiag.tcl;h=12e263c45ede740f2bf5d93754aaf4ced5885aa7;hp=0066a3f9e4e267738f323046f0c8424d9875ab02;hb=5ef9ca5de57e415b34c21fe0d17a79f7b8e6b636;hpb=3b703e575c88bd31b38f5af81c29aeed757ff11b diff --git a/src/csvtodiag.tcl b/src/csvtodiag.tcl index 0066a3f..12e263c 100644 --- a/src/csvtodiag.tcl +++ b/src/csvtodiag.tcl @@ -1,8 +1,7 @@ # This file is part of the YAZ toolkit -# Copyright (c) Index Data 1996-2005 +# Copyright (C) Index Data # See the file LICENSE for details. # -# $Id: csvtodiag.tcl,v 1.2 2005-04-22 14:51:11 adam Exp $ # # Converts a CSV file with diagnostics to C+H file for easy # maintenance @@ -17,8 +16,14 @@ proc csvtodiag {ifiles name alias} { 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 "/** \\file [lindex $ifiles 1]" + puts $hfile "/** \\file [lindex $ifiles 2]" + set preamble " \\brief Diagnostics: Generated by csvtodiag.tcl from [lindex $ifiles 0] */" puts $cfile $preamble + puts $cfile "\#ifdef HAVE_CONFIG_H" + puts $cfile "\#include " + puts $cfile "\#endif" + puts $cfile " #include \"diag-entry.h\" \#include \"[lindex $ifiles 2]\" @@ -89,3 +94,55 @@ YAZ_END_CDECL close $hfile } +proc csvto_xml {csvfname xmlfname id} { + set xfile [open $xmlfname w] + set csv [open $csvfname r] + + puts $xfile "" + puts $xfile "" + puts $xfile {} + puts $xfile {} + puts $xfile {} + puts $xfile {} + puts $xfile {} + puts $xfile {Code} + puts $xfile {Text} + puts $xfile {} + puts $xfile {} + puts $xfile {} + + set lineno 0 + while {1} { + incr lineno + set cnt [gets $csv line] + if {$cnt < 0} { + break + } + if {[regexp {([0-9]+)[^\"]*"([^\"]*)"} $line s code msg]} { + puts $xfile {} + puts $xfile {} + puts $xfile $code + puts $xfile {} + puts $xfile $msg + puts $xfile {} + puts $xfile {} + } + } + puts $xfile {} + puts $xfile {} + puts $xfile {} + + close $xfile + close $csv +} + +if {[llength $argv] >= 4} { + set alias {} + if {[llength $argv] >= 5} { + set alias [lindex $argv 4] + } + csvtodiag [list [lindex $argv 0] [lindex $argv 1] [lindex $argv 2]] \ + [lindex $argv 3] $alias +} elseif {[llength $argv] == 3} { + csvto_xml [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] +} \ No newline at end of file