Bib-1 and SRU diagnostics in manual (appendix) YAZ-748
[yaz-moved-to-github.git] / src / csvtodiag.tcl
index 6dcd1be..12e263c 100644 (file)
@@ -94,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 "<!-- Generated by csvtodiag.tcl from $csvfname -->"
+    puts $xfile "<informaltable id=\"${id}\">"
+    puts $xfile {<tgroup cols="2">}
+    puts $xfile {<colspec colwidth="1*" colname="code"></colspec>}
+    puts $xfile {<colspec colwidth="4*" colname="text"></colspec>}
+    puts $xfile {<thead>}
+    puts $xfile {<row>}
+    puts $xfile {<entry>Code</entry>}
+    puts $xfile {<entry>Text</entry>}
+    puts $xfile {</row>}
+    puts $xfile {</thead>}
+    puts $xfile {<tbody>}
+
+    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 {<row>}
+           puts $xfile {<entry>}
+           puts $xfile $code
+           puts $xfile {</entry><entry>}
+           puts $xfile $msg
+           puts $xfile {</entry>}
+           puts $xfile {</row>}
+       }
+    }
+    puts $xfile {</tbody>}
+    puts $xfile {</tgroup>}
+    puts $xfile {</informaltable>}
+
+    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