8 proc readoids {input} {
9 set csv [open $input r]
14 set cnt [
gets $csv line]
18 if {![
string compare [
string index $line 0] \"]} {
21 set tokens [
string map {, { }} $line]
22 if {[
llength $tokens] != 3} {
23 puts "$input:$lineno: Bad line '$line'"
29 if {![
info exists oids]} {
30 puts "$input:0 No OIDS"
36 proc constant_var {oid} {
37 set lname [
string tolower [
lindex $oid 2]]
38 set lname [
string map {- _ . _ { } _ ( {} ) {}} $lname]
39 set prefix [
string tolower [
lindex $oid 0]]
41 return yaz_oid_${prefix}_${lname}
44 proc oid_to_xml {input xname} {
46 set xfile [open "${xname}" w]
48 puts $xfile "<!-- Generated by oidtoc.tcl from $input -->"
49 puts $xfile {<informaltable id="standard-oids">}
50 puts $xfile {<tgroup cols="3">}
51 puts $xfile {<colspec colwidth="3*" colname="name"></colspec>}
52 puts $xfile {<colspec colwidth="2*" colname="class"></colspec>}
53 puts $xfile {<colspec colwidth="4*" colname="oid"></colspec>}
56 puts $xfile {<entry>Name</entry>}
57 puts $xfile {<entry>Class</entry>}
58 puts $xfile {<entry>Constant / OID</entry>}
60 puts $xfile {</thead>}
66 puts $xfile {<entry morerows="1">}
67 puts $xfile [
lindex $oid 2]
68 puts $xfile {</entry>}
71 puts $xfile {<entry morerows="1">}
72 puts $xfile [
lindex $oid 0]
73 puts $xfile {</entry>}
75 puts $xfile {<entry><literal>}
78 puts $xfile {</literal></entry>}
84 puts $xfile {<entry namest="oid">}
85 puts $xfile [
lindex $oid 1]
86 puts $xfile {</entry>}
91 puts $xfile {</tbody>}
92 puts $xfile {</tgroup>}
94 puts $xfile {</informaltable>}
98 proc oid_to_c {input cname hname} {
101 set cfile [open ${cname} w]
102 set hfile [open ${hname} w]
104 puts $cfile "/** \\file [
file tail $cname]"
105 puts $hfile "/** \\file [
file tail $hname]"
106 set preamble " \\brief Standard Object Identifiers: Generated from $input */"
107 puts $cfile $preamble
108 puts $hfile $preamble
109 puts $hfile "\#ifndef OID_STD_H"
110 puts $hfile "\#define OID_STD_H"
112 puts $cfile "\#if HAVE_CONFIG_H"
113 puts $cfile "\#include <config.h>"
114 puts $cfile "\#endif"
116 puts $cfile "\#include <yaz/oid_db.h>"
119 puts $hfile "\#ifdef YAZ_DLL"
120 puts $hfile "\#define OID_EXPORT YAZ_EXPORT"
122 puts $hfile "\#define OID_EXPORT YAZ_IMPORT"
123 puts $hfile "\#endif"
125 puts $hfile "YAZ_BEGIN_CDECL"
130 puts -nonewline $cfile "YAZ_EXPORT const Odr_oid $v\[\] = \{"
131 puts -nonewline $cfile [
string map {. ,} [
lindex $oid 1]]
134 puts $hfile "OID_EXPORT extern const Odr_oid $v\[\];"
137 puts $cfile "YAZ_EXPORT struct yaz_oid_entry yaz_oid_standard_entries\[\] ="
142 puts -nonewline $cfile "\t\{CLASS_[
lindex $oid 0], "
143 puts -nonewline $cfile "$v, "
144 puts -nonewline $cfile \"[
lindex $oid 2]\"
148 puts $cfile "\t\{CLASS_NOP, 0, 0\}"
151 puts $hfile "OID_EXPORT extern struct yaz_oid_entry yaz_oid_standard_entries\[\];"
152 puts $hfile "YAZ_END_CDECL"
153 puts $hfile "\#endif"
158 if {[
llength $argv] == 3} {
159 oid_to_c [
lindex $argv 0] [
lindex $argv 1] [
lindex $argv 2]
160 }
elseif {[
llength $argv] == 2} {
163 puts "oidtoc.tcl csv cfile hfile"