chiark / gitweb /
initial import and build-faff, wip
[chiark-tcl.git] / base / tcmdifgen
index 22da4aea8e6ead31e12bb3f36c95bcea712be8eb..f14249ca4dd2441e3b9745d1fa625f76fc9cf1aa 100755 (executable)
 #     functions.
 #
 #     `Type' causes declarations in the .h file of these functions:
-#        int pat_TYPENAME(Tcl_Interp*, Tcl_Obj *obj, C-TYPE *val, ARGS);
-#        Tcl_Obj *ret_TYPENAME(Tcl_Interp*, C-TYPE val, ARGS);
+#        int cht_pat_TYPENAME(Tcl_Interp*, Tcl_Obj *obj, C-TYPE *val, ARGS);
+#        Tcl_Obj *cht_ret_TYPENAME(Tcl_Interp*, C-TYPE val, ARGS);
 #
-#     pat_... must attempt to parse obj into the appropriate type.
+#     cht_pat_... must attempt to parse obj into the appropriate type.
 #     val will already have been initialised with `Init' statements if
-#     relevant.  Whether pat_... fails or succeeds it may allocate
+#     relevant.  Whether cht_pat_... fails or succeeds it may allocate
 #     memory into the object and must leave the object valid (for
 #     `Fini').
 #
-#     ret_... must convert the value back to a new Tcl_Obj.  It may
+#     cht_ret_... must convert the value back to a new Tcl_Obj.  It may
 #     not fail.
 #
 #  Init TYPENAME    C-STATEMENTS
 #            ...
 #          [ =>  RESULT-TYPE ]
 #     This will cause the declaration of
-#        int do_TABLENAME_ENTRYNAME(ClientData cd, Tcl_Interp *ip,
+#        int cht_do_TABLENAME_ENTRYNAME(ClientData cd, Tcl_Interp *ip,
 #                                   FORMAL-ARGUMENTS, RESULT-C-TYPE*);
 #     which is the procedure which the application must supply to
 #     implement the function.  If the `=> RESULT-TYPE' is omitted, so
 #     is the result argument to the function.  Each argument to the
 #     function is of the C type corresponding to the specified type.
-#     The do_... function should not eat any memory associated with
+#     The cht_do_... function should not eat any memory associated with
 #     the arguments.  The result buffer (if any) will be initialised
 #     using the `Init' and should on success contain the relevant
 #     result.  On failure it should leave the result unmodified (or at
 #     EXTRA-VALUES; the EXTRA-VALUES are used as initialisers for the
 #     additional structure elements.
 #
-#  Also declared are these functions:
-#    void setstringresult(Tcl_Interp*, const char*);
+#  NoEntryDefine C-ENTRY-TYPE
+#     Prevents the definition of C-ENTRY-TYPE by Table.
+#     The C type must be defined elsewhere.
+#
+#  Also expected are these functions:
+#    void cht_setstringresult(Tcl_Interp*, const char*);
 #        sets the Tcl result from the supplied string
-#    int pat_enum(Tcl_Interp*, Tcl_Obj*, const void **c_e_t_array,
+#    int cht_pat_enum(Tcl_Interp*, Tcl_Obj*, const void **c_e_t_array,
 #                 const void *c_e_t_return, size_t c_e_t_sz, const char *what);
 #        scans a table of C-ENTRY-TYPEs looking for the
 #        string matching the string supplied by the script
 #        are in the same places no matter what the rest of
 #        the struct contains.
 #  and the two predefined types `int' (C `int') and `obj' (Tcl_Obj*,
-#  unmodified.)  The corresponding definitions are in tcmdiflib.c
-#  which #includes "tcmdiflib.h" (not supplied).
+#  unmodified.)  The corresponding definitions are in tcmdiflib.c.
 
 use IO;
 use Data::Dumper;
@@ -123,8 +126,9 @@ parse('builtins','DATA');
 
 while (@ARGV) {
     $_= shift @ARGV;
-    if (m/^\-p(\w+)/) {
+    if (m/^\-p([-_0-9a-z]+)$/) {
        $prefix= $1;
+       $prefix =~ y/-/_/;
     } elsif (m/^\-w(c|h)$/) {
        $write= $1;
     } elsif (m/^\-o(.+)$/) {
@@ -163,11 +167,11 @@ sub parse ($$) {
            unshift @i, $this_indent;
        }
 
-       if (@i==0 && m/^Table\s+(\w+)\s+(\w+)$/) {
+       if (@i==0 && m/^Table\s+(\*toplevel\*|\w+)\s+(\w+)$/) {
            zilch();
            $c_table= $1;
            $table_x{$c_table}{C}= $2;
-           $entrytype_x{$2}= '';
+           $entrytype_x{$2}= '' unless exists $entrytype_x{$2};
        } elsif (@i==0 && m/^Untabled$/) {
            zilch();
            $c_table= '';
@@ -176,6 +180,9 @@ sub parse ($$) {
        } elsif (@i==0 && m/^EntryExtra\s+(\w+)$/) {
            zilch();
            $c_entryextra= $1;
+       } elsif (@i==0 && m/^NoEntryDefine\s+(\w+)$/) {
+           zilch();
+           $entrytype_x{$1}= " ";
        } elsif (@i>=1 && defined $c_entryextra) {
            $entrytype_x{$c_entryextra} .= "  $_\n";
        } elsif (@i==1 && m/^[a-z].*$/ && defined $c_table) {
@@ -225,19 +232,20 @@ foreach $t (sort keys %types) {
     $type= $types{$t};
     $c= $type->{C};
     $xta= $type->{X};
-    $decl= "int pat_$t(Tcl_Interp *ip, Tcl_Obj *obj, ";
+    $decl= "int cht_pat_$t(Tcl_Interp *ip, Tcl_Obj *obj, ";
     $decl .= subst_in_decl('*val', $c, "type $t");
     $decl .= ", $xta",  if length $xta;
     $decl .= ");\n";
     o('h',160, $decl);
 
-    $decl= "Tcl_Obj *ret_$t(Tcl_Interp *ip, ".subst_in_decl('val',$c);
+    $decl= "Tcl_Obj *cht_ret_$t(Tcl_Interp *ip, ".subst_in_decl('val',$c);
     $decl .= ", $xta" if length $xta;
     $decl .= ");\n";
     o('h',170, $decl);
 }
 
 foreach $c_entrytype (sort keys %entrytype_x) {
+    next if $entrytype_x{$c_entrytype} =~ m/^\s$/;
     o('h', 20, "typedef struct $c_entrytype $c_entrytype;\n");
     o('h', 100,
       "struct $c_entrytype {\n".
@@ -257,7 +265,7 @@ foreach $c_table (sort keys %tables) {
        $r_entry= $r_table->{$c_entry};
        $pa_decl= "int pa_${c_table}_${c_entry_c}(ClientData cd,".
            " Tcl_Interp *ip, int objc, Tcl_Obj *const *objv)";
-       $do_decl= "int do_${c_table}_${c_entry_c}(";
+       $do_decl= "int cht_do_${c_table}_${c_entry_c}(";
        @do_al= ('ClientData cd', 'Tcl_Interp *ip');
        @do_aa= qw(cd ip);
        $pa_init= '';
@@ -310,7 +318,7 @@ foreach $c_table (sort keys %tables) {
            if (exists $type_fini{$t}) {
                $pa_fini .= '  '.subst_in("a_$n", $type_fini{$t})."\n";
            }
-           $pa_body .= "  rc= pat_$t(ip, *objv++, $paarg";
+           $pa_body .= "  rc= cht_pat_$t(ip, *objv++, $paarg";
            $pa_body .= ", ".$a if length $a;
            $pa_body .= ");$pafin if (rc) goto rc_err;\n";
            push @do_aa, "a_$n";
@@ -333,16 +341,16 @@ foreach $c_table (sort keys %tables) {
        if (exists $r_entry->{R}) {
            $t= $r_entry->{R};
            $xta= $r_entry->{X};
-           push @do_al, make_decl("*result", $t, "do_al result");
+           push @do_al, make_decl("*result", $t, "cht_do_al result");
            $pa_vars .= make_decl_init("result", $t, $xta, \$pa_init,
                                       "pa_vars result");
            push @do_aa, "&result";
-           $pa_rslt .= "  Tcl_SetObjResult(ip, ret_$t(ip, result";
+           $pa_rslt .= "  Tcl_SetObjResult(ip, cht_ret_$t(ip, result";
            $pa_rslt .= ", $xta" if length $xta;
            $pa_rslt .= "));\n";
        }
        $pa_body .= "\n";
-       $pa_body .= "  rc= do_${c_table}_${c_entry_c}(";
+       $pa_body .= "  rc= cht_do_${c_table}_${c_entry_c}(";
        $pa_body .= join ', ', @do_aa;
        $pa_body .= ");\n";
        $pa_body .= "  if (rc) goto rc_err;\n";
@@ -411,11 +419,6 @@ o(h, 0,
   "#define INCLUDED_\U${prefix}_H\n\n".
   "#include <tcl8.3/tcl.h>\n");
 
-o(h, 400,
-  "void setstringresult(Tcl_Interp*, const char*);\n".
-  "int pat_enum(Tcl_Interp*, Tcl_Obj*, const void**,".
-  "             const void*, size_t, const char *what);\n");
-
 o(h, 999,
   "#endif /*INCLUDED_\U${prefix}_H*/\n");