home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
m4-1.2-src.lha
/
GNU
/
src
/
amiga
/
m4-1.2
/
m4.info-2
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-07-19
|
51KB
|
1,109 lines
This is Info file m4.info, produced by Makeinfo-1.55 from the input
file m4.texinfo.
This file documents the GNU `m4' utility.
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994 Free Software
Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by the Foundation.
File: m4.info, Node: Input Control, Next: File Inclusion, Prev: Debugging, Up: Top
Input control
*************
This chapter describes various builtin macros for controlling the
input to `m4'.
* Menu:
* Dnl:: Deleting whitespace in input
* Changequote:: Changing the quote characters
* Changecom:: Changing the comment delimiters
* Changeword:: Changing the lexical structure of words
* M4wrap:: Saving input until end of input
File: m4.info, Node: Dnl, Next: Changequote, Prev: Input Control, Up: Input Control
Deleting whitespace in input
============================
The builtin `dnl' reads and discards all characters, up to and
including the first newline:
dnl
and it is often used in connection with `define', to remove the newline
that follow the call to `define'. Thus
define(`foo', `Macro `foo'.')dnl A very simple macro, indeed.
foo
=>Macro foo.
The input up to and including the next newline is discarded, as
opposed to the way comments are treated (*note Comments::.).
Usually, `dnl' is immediately followed by an end of line or some
other whitespace. GNU `m4' will produce a warning diagnostic if `dnl'
is followed by an open parenthesis. In this case, `dnl' will collect
and process all arguments, looking for a matching close parenthesis.
All predictable side effects resulting from this collection will take
place. `dnl' will return no output. The input following the matching
close parenthesis up to and including the next newline, on whatever
line containing it, will still be discarded.
File: m4.info, Node: Changequote, Next: Changecom, Prev: Dnl, Up: Input Control
Changing the quote characters
=============================
The default quote delimiters can be changed with the builtin
`changequote':
changequote(opt START, opt END)
where START is the new start-quote delimiter and END is the new
end-quote delimiter. If any of the arguments are missing, the default
quotes (``' and `'') are used instead of the void arguments.
The expansion of `changequote' is void.
changequote([,])
=>
define([foo], [Macro [foo].])
=>
foo
=>Macro foo.
If no single character is appropriate, START and END can be of any
length.
changequote([[,]])
=>
define([[foo]], [[Macro [[[foo]]].]])
=>
foo
=>Macro [foo].
Changing the quotes to the empty strings will effectively disable the
quoting mechanism, leaving no way to quote text.
define(`foo', `Macro `FOO'.')
=>
changequote(,)
=>
foo
=>Macro `FOO'.
`foo'
=>`Macro `FOO'.'
There is no way in `m4' to quote a string containing an unmatched
left quote, except using `changequote' to change the current quotes.
Neither quote string should start with a letter or `_' (underscore),
as they will be confused with names in the input. Doing so disables
the quoting mechanism.
File: m4.info, Node: Changecom, Next: Changeword, Prev: Changequote, Up: Input Control
Changing comment delimiters
===========================
The default comment delimiters can be changed with the builtin macro
`changecom':
changecom(opt START, opt END)
where START is the new start-comment delimiter and END is the new
end-comment delimiter. If any of the arguments are void, the default
comment delimiters (`#' and newline) are used instead of the void
arguments. The comment delimiters can be of any length.
The expansion of `changecom' is void.
define(`comment', `COMMENT')
=>
# A normal comment
=># A normal comment
changecom(`/*', `*/')
=>
# Not a comment anymore
=># Not a COMMENT anymore
But: /* this is a comment now */ while this is not a comment
=>But: /* this is a comment now */ while this is not a COMMENT
Note how comments are copied to the output, much as if they were
quoted strings. If you want the text inside a comment expanded, quote
the start comment delimiter.
Calling `changecom' without any arguments disables the commenting
mechanism completely.
define(`comment', `COMMENT')
=>
changecom
=>
# Not a comment anymore
=># Not a COMMENT anymore
File: m4.info, Node: Changeword, Next: M4wrap, Prev: Changecom, Up: Input Control
Changing the lexical structure of words
=======================================
The macro `changeword' and all associated functionnality is
experimental. It is only available if the `--enable-changeword'
option was given to `configure', at GNU `m4' installation time.
The functionnality might change or even go away in the future.
*Do not rely on it*. Please direct your comments about it the
same way you would do for bugs.
A file being processed by `m4' is split into quoted strings, words
(potential macro names) and simple tokens (any other single character).
Initially a word is defined by the following regular expression:
[_a-zA-Z][_a-zA-Z0-9]*
Using `changeword', you can change this regular expression. Relaxing
`m4''s lexical rules might be useful (for example) if you wanted to
apply translations to a file of numbers:
changeword(`[_a-zA-Z0-9]+')
define(1, 0)
=>1
Tightening the lexical rules is less useful, because it will
generally make some of the builtins unavailable. You could use it to
prevent accidental call of builtins, for example:
define(`_indir', defn(`indir'))
changeword(`_[_a-zA-Z0-9]*')
esyscmd(foo)
_indir(`esyscmd',`ls')
Because `m4' constructs its words a character at a time, there is a
restriction on the regular expressions that may be passed to
`changeword'. This is that if your regular expression accepts `foo',
it must also accept `f' and `fo'.
`changeword' has another function. If the regular expression
supplied contains any bracketed subexpressions, then text outside the
first of these is discarded before symbol lookup. So:
changecom(`/*',`*/')
changeword(`#\([_a-zA-Z0-9]*\)')
#esyscmd(ls)
`m4' now requires a `#' mark at the beginning of every macro
invocation, so one can use `m4' to preprocess shell scripts without
getting `shift' commands swallowed, and plain text without losing
various common words.
`m4''s macro substitution is based on text, while TeX's is based on
tokens. `changeword' can throw this difference into relief. For
example, here is the same idea represented in TeX and `m4'. First, the
TeX version:
\def\a{\message{Hello}}
\catcode`\@=0
\catcode`\\=12
=>@a
=>@bye
Then, the `m4' version:
define(a,`errprint(`Hello')')
changeword(`@\([_a-zA-Z0-9]*\)')
=>@a
In the TeX example, the first line defines a macro `a' to print the
message `Hello'. The second line defines @ to be usable instead of \
as an escape character. The third line defines \ to be a normal
printing character, not an escape. The fourth line invokes the macro
`a'. So, when TeX is run on this file, it displays the message `Hello'.
When the `m4' example is passed through `m4', it outputs
`errprint(Hello)'. The reason for this is that TeX does lexical
analysis of macro definition when the macro is *defined*. `m4' just
stores the text, postponing the lexical analysi