#!/usr/bin/perl
+# code generator to help with writing Tcl extensions
+# Copyright 2006 Ian Jackson
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+
# Input format is line-based, ws-significant, offside rule (some kind
# of, anyway).
#
# Arranges for generated .h files to #include the specified
# file. C-INCLUDE-SPECIFIER should include the <..> or "..".
#
-# Table TABLENAME C-ENTRY-TYPE
+# Table [*]TABLENAME C-ENTRY-TYPE
# Starts a table of commands or subcommands. The generated .h
# will contain a definition of C-ENTRY-TYPE containing
# const char *name;
# where C-ARRAY-NAME is TABLENAME, with `_entries' appended
# and `cht_' prepended. The entries are indented one level (one
# or more spaces) and look like this:
-# ENTRYNAME
+# ENTRYNAME [ C-EXTRA-ENTRY-VALUES ]
# FORMALARGNAME TYPE
# ...
# [ => RESULT-TYPE ]
# arguments, processes the command, and sets any result, as
# applicable.
#
-# ExtraEntry C-ENTRY-TYPE
+# `*' should be used if the table name is not useful for error
+# messages. It suppresses `TABLENAME ' from the front of the
+# autogenerated argument parsing error strings.
+#
+# EntryExtra C-ENTRY-TYPE
# Introduces a section of additional C code which will be inserted
# into the definition of C-ENTRY-TYPE by `Table'. The C
# code, which follows on several indented lines, should be
# structure member definitions.
#
-# When ExtraEntry is used, in the corresponding Table, each
+# When EntryExtra is used, in the corresponding Table, each
# ENTRYNAME should be followed on the same line by whitespace and
# EXTRA-VALUES; the EXTRA-VALUES are used as initialisers for the
# additional structure elements.
unshift @i, $this_indent;
}
- if (@i==0 && m/^Table\s+(\w+)\s+(\w+)$/) {
+ if (@i==0 && m/^Table\s+(\*?)(\w+)\s+(\w+)$/) {
zilch();
- $c_table= $1;
- $table_x{$c_table}{C}= $2;
- $entrytype_x{$2}= '' unless exists $entrytype_x{$2};
+ $c_table= $2;
+ $table_x{$c_table}{T}= $1;
+ $table_x{$c_table}{C}= $3;
+ $entrytype_x{$3}= '' unless exists $entrytype_x{$3};
} elsif (@i==0 && m/^Untabled$/) {
zilch();
$c_table= '';
$any_eerr= 0;
$any_eargc= 0;
$pa_hint= '';
- $pa_hint .= "$c_table " if length $c_table;
+ $pa_hint .= "$c_table " if length $c_table &&
+ !length $table_x{$c_table}{T};
$pa_hint.= $c_entry;
foreach $arg (@{ $r_entry->{A} }) {
$n= $arg->{N};
o(h, 0,
"#ifndef INCLUDED_\U${prefix}_H\n".
- "#define INCLUDED_\U${prefix}_H\n\n".
- "#include <tcl8.3/tcl.h>\n");
+ "#define INCLUDED_\U${prefix}_H\n\n");
o(h, 999,
"#endif /*INCLUDED_\U${prefix}_H*/\n");