1 # This file is part of the YAZ toolkit
2 # Copyright (c) Index Data 1996-2006
3 # See the file LICENSE for details.
5 # $Id: csvtodiag.tcl,v 1.3 2006-04-20 20:50:51 adam Exp $
7 # Converts a CSV file with diagnostics to C+H file for easy
10 proc csvtodiag {ifiles name alias} {
11 set uname [string toupper $name]
12 set funcproto "const char *yaz_diag_${name}_str(int code)"
13 if {[string length $alias]} {
14 set funcalias "const char *${alias}(int code)"
16 set csv [open [lindex $ifiles 0] r]
17 set cfile [open [lindex $ifiles 1] w]
18 set hfile [open [lindex $ifiles 2] w]
20 puts $cfile "/** \\file [lindex $ifiles 1]"
21 puts $hfile "/** \\file [lindex $ifiles 2]"
22 set preamble " \\brief Diagnostics: Generated by csvtodiag.tcl from [lindex $ifiles 0] */"
25 #include \"diag-entry.h\"
26 \#include \"[lindex $ifiles 2]\"
27 struct yaz_diag_entry yaz_diag_${name}_tab\[\] = \{
31 \#include <yaz/yconfig.h>
33 \#ifndef YAZ_DIAG_${name}_H
34 \#define YAZ_DIAG_${name}_H
36 YAZ_EXPORT $funcproto;"
38 if {[info exists funcalias]} {
39 puts $hfile "YAZ_EXPORT $funcalias;"
43 set cnt [gets $csv line]
47 if {[regexp {([0-9]+)[^\"]*"([^\"]*)"} $line s code msg]} {
48 puts $cfile "\{$code, \"$msg\"\},"
50 set m [string toupper $msg]
51 regsub -all {DUPLICATE} $m {DUP} m
52 regsub -all {SECURITY CHALLENGE} $m {SEC_CHAL} m
53 regsub -all {COULD NOT} $m {COULDNT} m
54 regsub -all {COULD NOT} $m {COULDNT} m
55 regsub -all {NOT SUPPORTED} $m {UNSUPP} m
56 regsub -all {UNSUPPORTED} $m {UNSUPP} m
57 regsub -all {COMBINATION} $m {COMBI} m
58 regsub -all {PROXIMITY} $m {PROX} m
59 regsub -all {CHARACTERS} $m {CHARS} m
60 regsub -all {CHARACTER} $m {CHAR} m
61 regsub -all {[-/,:;."' \{\}()]} $m _ m
62 set m [string map {___ _ __ _} $m]
63 if {[string length $m] > 55} {
64 set m [string range $m 0 55]
65 set p [string last _ $m]
67 set m [string range $m 0 $p]
70 puts $hfile "\#define YAZ_${uname}_${m} $code"
73 puts $cfile "\{0, 0\}\}\;"
74 puts $cfile $funcproto
76 puts $cfile " return yaz_diag_to_str(yaz_diag_${name}_tab, code);"
79 if {[info exists funcalias]} {
80 puts $cfile $funcalias
82 puts $cfile " return yaz_diag_to_str(yaz_diag_${name}_tab, code);"