1# Generate tbl_funcs.h 2# 3# Copyright (c) 2010-2011 Free Software Foundation, Inc. 4# 5# This file is part of GNU Zile. 6# 7# GNU Zile is free software; you can redistribute it and/or modify it 8# under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 3, or (at your option) 10# any later version. 11# 12# GNU Zile is distributed in the hope that it will be useful, but 13# WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15# General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with GNU Zile; see the file COPYING. If not, write to the 19# Free Software Foundation, Fifth Floor, 51 Franklin Street, Boston, 20# MA 02111-1301, USA. 21 22use File::Copy; 23 24use Zile; 25 26my $dir = shift; 27 28my $output = "src/tbl_funcs.h"; 29open OUT, ">$output.new" or die; 30 31print OUT <<END; 32/* 33 * Automatically generated file: DO NOT EDIT! 34 * $ENV{PACKAGE_NAME} command to C function bindings and docstrings. 35 * Generated from C sources. 36 */ 37 38END 39 40foreach my $file (@ARGV) { 41 open IN, "<$dir/$file" or die; 42 while (<IN>) { 43 if (/^DEFUN/) { 44 /"(.+?)"/; 45 my $name = $1; 46 die "invalid DEFUN syntax `$_'\n" unless $name; 47 48 my $interactive = !/^DEFUN_NONINTERACTIVE/; 49 my $doc = ""; 50 my $state = 0; 51 while (<IN>) { 52 if ($state == 1) { 53 if (m|^\+\*/|) { 54 $state = 0; 55 last; 56 } 57 $doc .= $_; 58 } elsif (m|^/\*\+|) { 59 $state = 1; 60 } 61 } 62 63 die "no docstring for $name\n" if $doc eq ""; 64 die "unterminated docstring for $name\n" if $state == 1; 65 66 my $cname = $name; 67 $cname =~ s/-/_/g; 68 $doc = texi($doc); 69 $doc =~ s/\n/\\n\\\n/g; 70 print OUT "X(\"$name\", $cname, " . ($interactive ? "true" : "false") . ", \"\\\n$doc\")\n"; 71 } 72 } 73} 74 75# Only replace the output file if it changed, to avoid pointless rebuilds 76open STDERR, ">", "/dev/null"; 77if ((system "diff", $output, "$output.new") != 0) { 78 move("$output.new", $output); 79} else { 80 unlink "$output.new"; 81} 82