Better ODR diagnostics for missing elements which includes additional
[yaz-moved-to-github.git] / util / yaz-comp
index 644b187..247b607 100755 (executable)
@@ -3,59 +3,10 @@
 exec tclsh "$0" "$@"
 #
 # yaz-comp: ASN.1 Compiler for YAZ
-# (c) Index Data 1996-2000
+# (c) Index Data 1996-2003
 # See the file LICENSE for details.
 #
-# $Log: yaz-comp,v $
-# Revision 1.2  2001-02-21 13:46:54  adam
-# C++ fixes.
-#
-# Revision 1.1  2000/03/02 08:48:20  adam
-# Renamed ASN.1 compiler to yaz-comp (used to be yc.tcl).
-#
-# Revision 1.6  2000/02/10 13:44:02  adam
-# Tcl command clock not used if unavailable (Tcl7.4 and earlier).
-#
-# Revision 1.5  2000/01/15 09:18:42  adam
-# Bug fix: some elements where treated as OPTIONAL when they shouldn't.
-#
-# Revision 1.4  1999/12/16 23:36:19  adam
-# Implemented ILL protocol. Minor updates ASN.1 compiler.
-#
-# Revision 1.3  1999/11/30 13:47:12  adam
-# Improved installation. Moved header files to include/yaz.
-#
-# Revision 1.2  1999/06/09 09:43:11  adam
-# Added option -I and variable h-path to specify path for header files.
-#
-# Revision 1.1  1999/06/08 10:10:16  adam
-# New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
-#
-# Revision 1.8  1999/04/20 10:37:04  adam
-# Updated for ODR - added name parameter.
-#
-# Revision 1.7  1998/04/03 14:44:20  adam
-# Small fix.
-#
-# Revision 1.6  1998/04/03 13:21:17  adam
-# Yet another fix.
-#
-# Revision 1.5  1998/04/03 12:48:17  adam
-# Fixed bug: missed handling of constructed tags for CHOICE.
-#
-# Revision 1.4  1998/03/31 15:47:45  adam
-# First compiled ASN.1 code for YAZ.
-#
-# Revision 1.3  1998/03/23 17:13:20  adam
-# Implemented SET OF and ENUM. The Compiler now eats ILL (ISO10161) and
-# LDAP (RFC1777).
-#
-# Revision 1.2  1997/10/07 10:31:01  adam
-# Added facility to specify tag type (CONTEXT, APPLICATION, ...).
-#
-# Revision 1.1.1.1  1996/10/31 14:04:40  adam
-# First version of the compiler for YAZ.
-#
+# $Id: yaz-comp,v 1.6 2003-05-20 19:55:30 adam Exp $
 #
 
 set yc_version 0.3
@@ -559,14 +510,14 @@ proc asnSequence {name tag implicit tagtype} {
     set nchoice 0
     if {![string length $tag]} {
         lappend l "\tif (!odr_sequence_begin (o, p, sizeof(**p), name))"
-        lappend l "\t\treturn opt && odr_ok (o);"
+        lappend l "\t\treturn odr_missing(o, opt, name) && odr_ok (o);"
     } elseif {$implicit} {
         lappend l "\tif (!odr_implicit_settag (o, $tagtype, $tag) ||"
         lappend l "\t\t!odr_sequence_begin (o, p, sizeof(**p), name))"
-        lappend l "\t\treturn opt && odr_ok(o);"
+        lappend l "\t\treturn odr_missing(o, opt, name);"
     } else {
         lappend l "\tif (!odr_constructed_begin (o, p, $tagtype, $tag, name))"
-        lappend l "\t\treturn opt && odr_ok(o);"
+        lappend l "\t\treturn odr_missing(o, opt, name);"
         lappend l "\tif (o->direction == ODR_DECODE)"
         lappend l "\t\t*p = ($inf(vprefix)$name *) odr_malloc (o, sizeof(**p));"
 
@@ -758,7 +709,7 @@ proc asnOf {name tag implicit tagtype isset} {
     lappend j "\tint [lindex $numName 0];"
 
     lappend l "\tif (!odr_initmember (o, p, sizeof(**p)))"
-    lappend l "\t\treturn opt && odr_ok(o);"
+    lappend l "\t\treturn odr_missing(o, opt, name);"
     if {[string length $tag]} {
         if {$implicit} {
             lappend l "\todr_implicit_settag (o, $tagtype, $tag);"
@@ -785,7 +736,7 @@ proc asnOf {name tag implicit tagtype isset} {
     lappend j "\}"
     lappend l "\t\treturn 1;"
     lappend l "\t*p = 0;"
-    lappend l "\treturn opt && odr_ok(o);"
+    lappend l "\treturn odr_missing(o, opt, name);"
     return [list [join $l \n] [join $j \n]]
 }
 
@@ -881,26 +832,26 @@ proc asnChoice {name tag implicit tagtype} {
     lappend l "\t\};"
     if {![string length $tag]} {
        lappend l "\tif (!odr_initmember(o, p, sizeof(**p)))"
-       lappend l "\t\treturn opt && odr_ok(o);"
+       lappend l "\t\treturn odr_missing(o, opt, name);"
        lappend l "\tif (odr_choice(o, arm, &(*p)->[lindex $uName 1], &(*p)->[lindex $uName 0], name))"
     } elseif {$implicit} {
        lappend l "\tif (!odr_initmember(o, p, sizeof(**p)))"
-       lappend l "\t\treturn opt && odr_ok(o);"
+       lappend l "\t\treturn odr_missing(o, opt, name);"
        lappend l "\todr_implicit_settag(o, $tagtype, $tag);"
        lappend l "\tif (odr_choice(o, arm, &(*p)->[lindex $uName 1], &(*p)->[lindex $uName 0], name))"
     } else {
        lappend l "\tif (!*p && o->direction != ODR_DECODE)"
        lappend l "\t\treturn opt;"
        lappend l "\tif (!odr_constructed_begin(o, p, $tagtype, $tag, 0))"
-       lappend l "\t\treturn opt && odr_ok(o);"
+       lappend l "\t\treturn odr_missing(o, opt, name);"
        lappend l "\tif (!odr_initmember(o, p, sizeof(**p)))"
-       lappend l "\t\treturn opt && odr_ok(o);"
+       lappend l "\t\treturn odr_missing(o, opt, name);"
        lappend l "\tif (odr_choice(o, arm, &(*p)->[lindex $uName 1], &(*p)->[lindex $uName 0], name) &&"
        lappend l "\t\todr_constructed_end(o))"
     }
     lappend l "\t\treturn 1;"
     lappend l "\t*p = 0;"
-    lappend l "\treturn opt && odr_ok(o);"
+    lappend l "\treturn odr_missing(o, opt, name);"
     return [list [join $l \n] [join $j \n]]
 }
 
@@ -1159,7 +1110,7 @@ proc asnModules {} {
            puts $file(outh) "\#ifndef ${ppname}_H"
            puts $file(outh) "\#define ${ppname}_H"
            puts $file(outh) {}
-           puts $file(outh) "\#include <$inf(h-dir)odr.h>"
+           puts $file(outh) "\#include <yaz/odr.h>"
           
             if {[info exists file(outp)]} { 
                puts $file(outp) "\#ifndef ${ppname}_P_H"