# HG changeset patch # User Rik # Date 1337363323 25200 # Node ID 5fa6a41d4fbe73d69f4290631f26f3371ca57215 # Parent 7c463e49006209079f9ca83bb6f5d0169ff9c089 build: Use Perl to create DOCSTRINGS in src/ directory. * gendoc.pl: New script generates DOCSTRINGS from *.df files * mkgendoc: Delete file which created gendoc.cc. * src/Makefile.am: Incorporate gendoc.pl into build system. Remove references to gendoc executable. diff -r 7c463e490062 -r 5fa6a41d4fbe src/Makefile.am --- a/src/Makefile.am Thu May 17 23:19:33 2012 -0400 +++ b/src/Makefile.am Fri May 18 10:48:43 2012 -0700 @@ -100,6 +100,7 @@ defaults.in.h \ DOCSTRINGS \ find-defun-files.sh \ + gendoc.pl \ genprops.awk \ gl2ps.c \ graphics.in.h \ @@ -107,7 +108,6 @@ mk-pkg-add \ mkbuiltins \ mkdefs \ - mkgendoc \ mkoctfile.in.cc \ mkoctfile.in.sh \ mkops \ @@ -662,27 +662,16 @@ AM_CXXFLAGS := $(filter-out $(DLL_CXXDEFS), $(AM_CXXFLAGS) $(GRAPHICS_CFLAGS)) if AMCOND_BUILD_DOCS -.DOCSTRINGS: gendoc$(BUILD_EXEEXT) +.DOCSTRINGS: $(ALL_DEF_FILES) gendoc.pl if [ "x$(srcdir)" != "x." ] && [ -f $(srcdir)/DOCSTRINGS ] && [ ! -f DOCSTRINGS ]; then \ cp $(srcdir)/DOCSTRINGS DOCSTRINGS; \ touch -r $(srcdir)/DOCSTRINGS DOCSTRINGS; \ fi @echo "creating .DOCSTRINGS from .cc source files" - @./gendoc > $@ + @$(PERL) $(srcdir)/gendoc.pl $(ALL_DEF_FILES) > $@ $(top_srcdir)/build-aux/move-if-change $@ DOCSTRINGS touch $@ -doc-files: $(ALL_DEF_FILES) - echo $(ALL_DEF_FILES) > $@-t - mv $@-t $@ - -gendoc.cc: doc-files mkgendoc - $(srcdir)/mkgendoc doc-files > $@-t - mv $@-t $@ - -gendoc$(BUILD_EXEEXT): gendoc.cc - $(BUILD_CXX) $(BUILD_CXXFLAGS) -o $@ $^ $(BUILD_LDFLAGS) - all-local: $(OCT_STAMP_FILES) $(DLD_FUNCTIONS_PKG_ADD_FILE) .DOCSTRINGS else all-local: $(OCT_STAMP_FILES) $(DLD_FUNCTIONS_PKG_ADD_FILE) @@ -769,9 +758,6 @@ CLEANFILES = \ $(bin_SCRIPTS) \ $(DLD_FUNCTIONS_PKG_ADD_FILE) \ - doc-files \ - gendoc.cc \ - gendoc$(BUILD_EXEEXT) \ graphics-props.cc \ oct-parse.output diff -r 7c463e490062 -r 5fa6a41d4fbe src/gendoc.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gendoc.pl Fri May 18 10:48:43 2012 -0700 @@ -0,0 +1,73 @@ +#! /usr/bin/perl -w +# +# Copyright (C) 2012 Rik Wehbring +# +# This file is part of Octave. +# +# Octave 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 3 of the License, or (at +# your option) any later version. +# +# Octave 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 Octave; see the file COPYING. If not, see +# . + +unless (@ARGV > 1) { die "Usage: $0 df-file1 ..." } + +print <<__END_OF_MSG__; +### DO NOT EDIT! +### +### This file is generated automatically from Octave source files. +### Edit source files directly and run make to update this file. + +__END_OF_MSG__ + +DFFILE: foreach $df_fname (@ARGV) +{ + open (DF_FH, $df_fname) or die "Unable to open $df_fname"; + + $src_fname = ""; + @func_list = (); + @docstr = (); + + LINE: while () + { + if (/XDEFUN_FILE_NAME \("([^"]+)"/) + { + $src_fname = $1; + next LINE; + } + if (/XDEF/ and ! /XDEFALIAS/) + { + ## Decode 4 or 5 part macro definition. + ($func, $str) = /\("?(\w+)"?,[^,]+,[^,]+,(?:[^,]+,)?\s*"(.*)"\)\s*$/ ; + + unless ($func) { die "Unable to parse $df_fname at line $.\n" } + + push (@func_list, $func); + ## Do escape sequence expansion + $str =~ s/(?. - -SED=${SED:-'sed'} - -if test $# -ne 1; then - echo "usage: mkgendoc f1" 1>&2 - exit 1 -fi - -DOC_FILES=`cat $1` - -if test -z "$DOC_FILES"; then - echo "mkgendoc: DOC_FILES is empty!" 1>&2 - exit 1 -fi - -cat << \EOF -// DO NOT EDIT! Generated automatically by mkgendoc - -#if defined (__DECCXX) -#define __USE_STD_IOSTREAM -#endif - -#include -#include - -#define XDEFUN_FILE_NAME(name) \ - std::string file_name = name; - -#define XDEFUN_DLD_INTERNAL(name, args_name, nargout_name, doc) \ - print_doc_string (#name, file_name, doc); - -#define XDEFUNX_DLD_INTERNAL(name, fname, args_name, nargout_name, doc) \ - print_doc_string (name, file_name, doc); - -#define XDEFUN_INTERNAL(name, args_name, nargout_name, doc) \ - print_doc_string (#name, file_name, doc); - -#define XDEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \ - print_doc_string (#name, file_name, doc); - -#define XDEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \ - print_doc_string (name, file_name, doc); - -#define XDEFALIAS_INTERNAL(alias, name) - -#define XDEFVAR_INTERNAL(name, sname, defn, protect, chg_fcn, doc) \ - print_doc_string (#name, file_name, doc); - -#define XDEFCONST_INTERNAL(name, defn, doc) \ - print_doc_string (#name, file_name, doc); - -static void -print_doc_string (const std::string& name, const std::string& file_name, - const std::string& doc) -{ - std::cout << ""; - - size_t len = name.length (); - - if (name[0] == '"' && name[len-1] == '"') - std::cout << name.substr (1, len-2) << "\n"; - else - std::cout << name << "\n"; - - std::cout << "@c " << name << " " << file_name << "\n" << doc << "\n"; -} - -EOF - -for file in $DOC_FILES; do - fcn=`echo $file | $SED 's,.*/,,; s/\.df//; s/-/_/g;'` - echo "static void" - echo "print_${fcn}_doc_strings (void)" - echo "{" - cat $file - echo "}" - echo "" -done - -cat << \EOF - -int -main (void) -{ - std::cout - << "### DO NOT EDIT!\n" - << "###\n" - << "### This file is generated automatically from the Octave sources.\n" - << "### Edit those files instead and run make to update this file.\n" - << std::endl; - -EOF - -for file in $DOC_FILES; do - fcn=`echo $file | $SED 's,.*/,,; s/\.df//; s/-/_/g;'` - echo " print_${fcn}_doc_strings ();" -done - -cat << \EOF - - return 0; -} -EOF - -exit 0