1 # This file is part of the YAZ toolkit
2 # Copyright (c) Index Data 1996-2013
3 # See the file LICENSE for details.
6 # Converts a CSV file with diagnostics to C+H file for easy
9 proc csvtodiag {ifiles name alias} {
10 set uname [string toupper $name]
11 set funcproto "const char *yaz_diag_${name}_str(int code)"
12 if {[string length $alias]} {
13 set funcalias "const char *${alias}(int code)"
15 set csv [open [lindex $ifiles 0] r]
16 set cfile [open [lindex $ifiles 1] w]
17 set hfile [open [lindex $ifiles 2] w]
19 puts $cfile "/** \\file [lindex $ifiles 1]"
20 puts $hfile "/** \\file [lindex $ifiles 2]"
21 set preamble " \\brief Diagnostics: Generated by csvtodiag.tcl from [lindex $ifiles 0] */"
23 puts $cfile "\#ifdef HAVE_CONFIG_H"
24 puts $cfile "\#include <config.h>"
28 #include \"diag-entry.h\"
29 \#include \"[lindex $ifiles 2]\"
30 struct yaz_diag_entry yaz_diag_${name}_tab\[\] = \{
34 \#include <yaz/yconfig.h>
36 \#ifndef YAZ_DIAG_${name}_H
37 \#define YAZ_DIAG_${name}_H
39 YAZ_EXPORT $funcproto;"
41 if {[info exists funcalias]} {
42 puts $hfile "YAZ_EXPORT $funcalias;"
46 set cnt [gets $csv line]
50 if {[regexp {([0-9]+)[^\"]*"([^\"]*)"} $line s code msg]} {
51 puts $cfile "\{$code, \"$msg\"\},"
53 set m [string toupper $msg]
54 regsub -all {DUPLICATE} $m {DUP} m
55 regsub -all {SECURITY CHALLENGE} $m {SEC_CHAL} m
56 regsub -all {COULD NOT} $m {COULDNT} m
57 regsub -all {COULD NOT} $m {COULDNT} m
58 regsub -all {NOT SUPPORTED} $m {UNSUPP} m
59 regsub -all {UNSUPPORTED} $m {UNSUPP} m
60 regsub -all {COMBINATION} $m {COMBI} m
61 regsub -all {PROXIMITY} $m {PROX} m
62 regsub -all {CHARACTERS} $m {CHARS} m
63 regsub -all {CHARACTER} $m {CHAR} m
64 regsub -all {[-/,:;."' \{\}()]} $m _ m
65 set m [string map {___ _ __ _} $m]
66 if {[string length $m] > 55} {
67 set m [string range $m 0 55]
68 set p [string last _ $m]
70 set m [string range $m 0 $p]
73 puts $hfile "\#define YAZ_${uname}_${m} $code"
76 puts $cfile "\{0, 0\}\}\;"
77 puts $cfile $funcproto
79 puts $cfile " return yaz_diag_to_str(yaz_diag_${name}_tab, code);"
82 if {[info exists funcalias]} {
83 puts $cfile $funcalias
85 puts $cfile " return yaz_diag_to_str(yaz_diag_${name}_tab, code);"