From 699fc16c7654c5af9260407eb7ecdbb20fc501de Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 28 Jul 2016 18:05:23 +0300 Subject: Improve modinc * modinc: Provide explicit construct for multiline expansion. * modules/stub.am: Use the new construct for HEADING expansion. * stub.ac: Likewise. --- modinc | 38 +++++++++++++++++++++++++++----------- modules/stub.am | 4 ++-- stub.ac | 4 ++-- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/modinc b/modinc index 7c1c5e1..5b88051 100755 --- a/modinc +++ b/modinc @@ -96,12 +96,29 @@ output file. During macro expansion, each occurrence of B<< > >> is replaced with the contents of the macro variable I, if it is defined. Expansion -of undefined variables lefts the text as is. +of undefined variables leaves the text as is. -A B<< > >> appearing alone after a sequence of non-whitespace -characters (a I) at the beginning of the line is treated specially: -if I expands to multiple lines, I is prepended to each line -on output. +The construct B<< #I> >> is expanded if it appears on a line +alone, possibly preceded by any string of characters. It works similarly +to B<< > >>, except that if I expands to multiple lines, the +second and subsequent lines of expansion are prefixed with I on output. +If I is empty, the content of the source line immediately preceding the +construct is used instead. This makes it possible to use expansions after a +comment character. E.g. if the variable B contains: + + This file is generated automatically. + Please, do not edit. + See the docs for more info. + +and the input file contains: + + dnl + +Then, the resulting expansion will be: + + dnl This file is generated automatically. + dnl Please, do not edit. + dnl See the docs for more info. The macro variables are specific for each file, and are described below. @@ -281,8 +298,7 @@ use constant EX_NOINPUT => 66; # cannot open input file use constant EX_SOFTWARE => 70; # internal software error (not used yet) use constant EX_CANTCREAT => 73; # can't create (user) output file -my $progname; -($progname = $0) =~ s/.*\///; +my $progname = basename($0); my $progdescr = "Recreate Dico module autoconf structure"; my $addmod; my $dry_run; @@ -528,14 +544,14 @@ sub make_file { } while (<$ifd>) { next if (defined($ref->{ignorecomm}) and /^$ref->{ignorecomm}/); - if (/^(\S+)<([A-Z][A-Z0-9_]+)>\s*$/) { - my $pfx = "$1 "; - $_ = $pfx . replace_macro($2, $ref, @_); + if (/^(.*)<([A-Z][A-Z0-9_]+)#([^>]*)>\s*$/) { + my $pfx = $3 || $1; + $_ = $1 . replace_macro($2, $ref); chomp; s/\n/\n$pfx/g; $_ .= "\n"; } else { - s/<([A-Z][A-Z0-9_]+)>/replace_macro($1, $ref, @_)/gex; + s/<([A-Z][A-Z0-9_]+)>/replace_macro($1, $ref)/gex; } print $ofd $_; } diff --git a/modules/stub.am b/modules/stub.am index bd14b9d..56ecf6e 100644 --- a/modules/stub.am +++ b/modules/stub.am @@ -1,6 +1,6 @@ -# +# # This file is part of GNU Dico -# Copyright (C) 1998-2000, 2008, 2010, 2012, 2014 Sergey Poznyakoff +# Copyright (C) 1998-2000, 2008, 2010, 2012-2016 Sergey Poznyakoff # # GNU Dico is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/stub.ac b/stub.ac index 46b33c4..7e9b812 100644 --- a/stub.ac +++ b/stub.ac @@ -5,10 +5,10 @@ ## 1. Comments starting with ## are removed from the output. ## 2. A construct is replaced with the value of the variable NAME. ## 3. Everything else is reproduced verbatim. -dnl +dnl dnl Process this file with -*- autoconf -*- to produce a configure script. # This file is part of GNU Dico -# Copyright (C) 1998-2000, 2008-2010, 2012, 2013, 2014 Sergey Poznyakoff +# Copyright (C) 1998-2000, 2008-2010, 2012-2016 Sergey Poznyakoff # # GNU Dico is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -- cgit v1.2.1