/[m4]/m4/doc/m4.texinfo
ViewVC logotype

Diff of /m4/doc/m4.texinfo

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.20 by gary, Mon May 2 21:21:43 2005 UTC revision 1.21 by gary, Sun May 8 00:37:44 2005 UTC
# Line 22  Line 22 
22  @ifinfo  @ifinfo
23  This file documents GNU @code{m4} @value{VERSION}  This file documents GNU @code{m4} @value{VERSION}
24    
25  Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2000,  Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2000, 2001, 2004, 2005
 2001, 2004  
26  Free Software Foundation, Inc.  Free Software Foundation, Inc.
27    
28  Permission is granted to copy, distribute and/or modify this document  Permission is granted to copy, distribute and/or modify this document
# Line 50  identical to this one except for the rem Line 49  identical to this one except for the rem
49    
50  @page  @page
51  @vskip 0pt plus 1filll  @vskip 0pt plus 1filll
52  Copyright @copyright{} 1989, 1990, 1991, 1992, 1993, 1994, 1998, 1999,  Copyright @copyright{} 1989, 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
 2000, 2001 Free Software Foundation, Inc.  
53    
54  Permission is granted to copy, distribute and/or modify this document  Permission is granted to copy, distribute and/or modify this document
55  under the terms of the GNU Free Documentation License, Version 1.1  under the terms of the GNU Free Documentation License, Version 1.1
# Line 158  How to define new macros Line 156  How to define new macros
156  * Undefine::                    Deleting a macro  * Undefine::                    Deleting a macro
157  * Defn::                        Renaming macros  * Defn::                        Renaming macros
158  * Pushdef::                     Temporarily redefining macros  * Pushdef::                     Temporarily redefining macros
159    * Erenamesyms and Renamesyms::  Renaming macros with regular expressions
160    
161  * Indir::                       Indirect call of macros  * Indir::                       Indirect call of macros
162  * Builtin::                     Indirect call of builtins  * Builtin::                     Indirect call of builtins
# Line 996  value, which can be brought back at a la Line 995  value, which can be brought back at a la
995  * Undefine::                    Deleting a macro  * Undefine::                    Deleting a macro
996  * Defn::                        Renaming macros  * Defn::                        Renaming macros
997  * Pushdef::                     Temporarily redefining macros  * Pushdef::                     Temporarily redefining macros
998    * Erenamesyms and Renamesyms::  Renaming macros with regular expressions
999    
1000  * Indir::                       Indirect call of macros  * Indir::                       Indirect call of macros
1001  * Builtin::                     Indirect call of builtins  * Builtin::                     Indirect call of builtins
# Line 1379  revealing the former definition. Line 1379  revealing the former definition.
1379  It is possible to temporarily redefine a builtin with @code{pushdef}  It is possible to temporarily redefine a builtin with @code{pushdef}
1380  and @code{defn}.  and @code{defn}.
1381    
1382    @node Erenamesyms and Renamesyms
1383    @section Renaming macros with regular expressions
1384    
1385    @cindex regular expressions
1386    @cindex macros, how to rename
1387    @cindex renaming macros
1388    @cindex GNU extensions
1389    @deffn {Builtin (gnu)} erenamesyms (@var{regexp}, @var{replacement})
1390    Global renaming of macros is done by @code{erenamesyms}, which selects
1391    all macros with names that match @var{regexp}, and renames each match
1392    according to @var{replacement}.
1393    
1394    A macro that does not have a name that matches @var{regexp} is left
1395    with its original name.  If only part of the name matches, any part of
1396    the name that is not covered by @var{regexp} is copied to the
1397    replacement name.  Whenever a match is found in the name, the search
1398    proceeds from the end of the match, so no character in the original
1399    name can be substituted twice.  If @var{regexp} matches a string of
1400    zero length, the start position for the continued search is
1401    incremented to avoid infinite loops.
1402    
1403    Where a replacement is to be made, @var{replacement} replaces the
1404    matched text in the original name, with @samp{\@var{n}} substituted by
1405    the text matched by the @var{n}th parenthesized sub-expression of
1406    @var{regexp}, and @samp{\&} being the text matched by the entire
1407    regular expression.
1408    
1409    The builtin macro @code{erenamesyms} is recognized only when given
1410    arguments.
1411    @end deffn
1412    
1413    Here is an example that performs the same renaming as the
1414    @option{--prefix-builtins} option.  Where @option{--prefix-builtins}
1415    only renames M4 builtin macros, @code{erenamesyms} will rename any
1416    macros that match when it runs, including text macros.
1417    
1418    @example
1419    erenamesyms(`^.*$', `m4_\&')
1420    @result{}
1421    @end example
1422    
1423    Here is a more realistic example that performs a similar renaming on
1424    macros with lowercase names, except that it ignores macros with names
1425    that begin with @samp{_}, and avoids creating macros with names that
1426    begin with @samp{m4_m4}.
1427    
1428    @example
1429    erenamesyms(`^[^_]\w*$', `m4_\&')
1430    @result{}
1431    m4_erenamesyms(`^m4_m4(\w*)$', `m4_\1')
1432    @result{}
1433    @end example
1434    
1435    @deffn {Builtin (gnu)} renamesyms (@var{regexp}, @var{replacement})
1436    Same as @code{erenamesyms}, but using Basic Regular Expression syntax,
1437    see @xref{Eregexp and Regexp}, for more details.
1438    @end deffn
1439    
1440    
1441  @node Indir  @node Indir
1442  @section Indirect call of macros  @section Indirect call of macros
1443    
# Line 3034  most common. Line 3093  most common.
3093  @cindex substitution by regular expression  @cindex substitution by regular expression
3094  @cindex GNU extensions  @cindex GNU extensions
3095  @deffn {Builtin (gnu)} epatsubst (@var{string}, @var{regexp}, @w{opt @var{replacement})}  @deffn {Builtin (gnu)} epatsubst (@var{string}, @var{regexp}, @w{opt @var{replacement})}
3096  Global substitution in a string is done by @code{patsubst}, which  Global substitution in a string is done by @code{epatsubst}, which
3097  searches @var{string} for matches of @var{regexp}, and substitutes  searches @var{string} for matches of @var{regexp}, and substitutes
3098  @var{replacement} for each match.  It uses Extended Regular Expressions  @var{replacement} for each match.  It uses Extended Regular Expressions
3099  syntax.  syntax.
# Line 3054  being the text the entire regular expres Line 3113  being the text the entire regular expres
3113  The @var{replacement} argument can be omitted, in which case the text  The @var{replacement} argument can be omitted, in which case the text
3114  matched by @var{regexp} is deleted.  matched by @var{regexp} is deleted.
3115    
3116  The builtin macro @code{patsubst} is recognized only when given  The builtin macro @code{epatsubst} is recognized only when given
3117  arguments.  arguments.
3118  @end deffn  @end deffn
3119    

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26