1 # This file is part of the YAZ toolkit
2 # Copyright (c) Index Data 2006-2007
3 # See the file LICENSE for details.
5 # $Id: oidtoc.tcl,v 1.2 2007-04-18 08:08:02 adam Exp $
7 # Converts a CSV file with Object identifiers to C
9 proc readoids {input} {
10 set csv [open $input r]
15 set cnt [gets $csv line]
19 if {![string compare [string index $line 0] \"]} {
22 set tokens [string map {, { }} $line]
23 if {[llength $tokens] != 3} {
24 puts "$input:$lineno: Bad line '$line'"
30 if {![info exists oids]} {
31 puts "$input:0 No OIDS"
37 proc oid_to_c {srcdir input cname hname} {
38 set oids [readoids "${srcdir}/${input}"]
40 set cfile [open "${srcdir}/${cname}" w]
41 set hfile [open "${srcdir}/../include/yaz/${hname}" w]
43 puts $cfile "/** \\file $cname"
44 puts $hfile "/** \\file $hname"
45 set preamble " \\brief Standard Object Identifiers: Generated from $input */"
50 puts $cfile "\#include <yaz/oid_db.h>"
53 set lname [string tolower [lindex $oid 2]]
54 set lname [string map {- _ . _ { } _ ( {} ) {}} $lname]
55 set prefix [string tolower [lindex $oid 0]]
57 puts -nonewline $cfile "const int yaz_oid_${prefix}_${lname}\[\] = \{"
58 puts -nonewline $cfile [string map {. ,} [lindex $oid 1]]
61 puts $hfile "extern const int yaz_oid_${prefix}_${lname}\[\];"
64 puts $cfile "struct yaz_oid_entry yaz_oid_standard_entries\[\] ="
67 set lname [string tolower [lindex $oid 2]]
68 set lname [string map {- _ . _ { } _ ( {} ) {}} $lname]
69 set prefix [string tolower [lindex $oid 0]]
71 puts -nonewline $cfile "\t\{CLASS_[lindex $oid 0], "
72 puts -nonewline $cfile "yaz_oid_${prefix}_${lname}, "
73 puts -nonewline $cfile \"[lindex $oid 2]\"
77 puts $cfile "\t\{CLASS_NOP, 0, 0\}"
80 puts $hfile "extern struct yaz_oid_entry yaz_oid_standard_entries\[\];"
85 if {[llength $argv] != 4} {
86 puts "oidtoc.tcl srcdir csv cfile hfile"
89 oid_to_c [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3]