[ previous ] [ contents ] [ next ]

Programs called

m4

m4 is called by arfg with the -P flag, so that the names of any m4 builtins are prefixed with the string m4_. Basic operation proceeds by defining macros to expand to whatever replacement text. As an example, feeding the text (without leading line numbers, of course):


 1: m4_define(`my_macro', `Macro `$0' called with $# arguments,
 2: the first of which is ``$1''.')
 3: my_macro(`a b, c', d, e, f)
 4: m4_esyscmd(date)

to the command m4 -P, the result will be similar to:


 1:
 2: Macro my_macro called with 4 arguments,
 3: the first of which is `a b, c'.
 4: Sat Aug  6 23:08:56 CEST 2005

m4 offers numerous more advanced features like, e. g., changing the underlying syntax of m4 itself; for details, see your local documentation (info m4) or the current GNU man pages.

divert

divert is a tool for flexible accumulation and relocation of text blocks. It allows you to define any number of named locations, or «diversions», the flow of text can be diverted to and that can be dumped anywhere, working recursively. A simple example of this might be (again, the line numbers have only been added for clarity):


 1: <<LOTS_OF_VOWELS>>
 2: ..CONSONANTS>>
 3: ..VOWELS>>This is a.
 4: <<VOWELS..
 5: This is b.
 6: This is c.
 7: This is d.
 8: ..VOWELS>>This is e.
 9: <<VOWELS..
10: This is f.
11: This is g.
12: This is h.
13: ..VOWELS>>This is i.
14: <<VOWELS..
15: This is j.
16: <<CONSONANTS..
17: ..NUMBERS>>
18: This is 1.
19: This is 2.
20: <<NUMBERS..
21: ..LOTS_OF_VOWELS>><<VOWELS>><<VOWELS>><<LOTS_OF_VOWELS..
22: <<CONSONANTS>>

Calling divert on the above file will produce:


 1: This is a.
 2: This is e.
 3: This is i.
 4: This is a.
 5: This is e.
 6: This is i.
 7:
 8:
 9:
10:
11:
12:
13: This is b.
14: This is c.
15: This is d.
16:
17: This is f.
18: This is g.
19: This is h.
20:
21: This is j.
22:

Note the recursive nature of the expansion. More information can, of course, be found at the wml project's home page; the documentation resides at http://www.engelschall.com/sw/wml/docs/backend/wml_p5_divert.html.

eperl

eperl is a means of embedding Perl statements into a text file by enclosing them in special delimiters. The principle should be clear from (line numbers added):


 1: <:sub all {
 2: :>allocate(<:print (join(", &\n    ", @_)):>, &
 3:     STAT=AllocateStat)
 4: if (AllocateStat /= 0) call ErrorMessage("<:="allocation of ".join(", &
 5:     &",@_)." failed.":>")
 6: <: }
 7:
 8: &all(qw[a(1:5) b%c]):>
 9:
10: The time is <:$a=`date`;chomp($a);print $a:>.

Applying eperl - to the above yields something akin to:


 1: allocate(a(1:5), &
 2:     b%c, &
 3:     STAT=AllocateStat)
 4: if (AllocateStat /= 0) call ErrorMessage("allocation of a(1:5), &
 5:     &b%c failed.")
 6:
 7:
 8: The time is Sat Aug  6 23:08:56 CEST 2005.

Note, however, that at least some versions of eperl are not re-entrant, i. e. they cannot call themselves from a sub-shell as in the hypothetical <:=`eperl file`:>, presumably due to an incorrect handling of temporary files. Further documentation of eperl can be found at http://www.engelschall.com/sw/eperl/docs/.

Security notice

From the above examples, rudimentary as they are, it should be clear that both m4 and eperl have the ability to access the underlying operating system. Apart from the portability problems this brings about, it may also pose severe security problems when executing command strings that can be influenced by malicious users. In arfg, the flexibility and simplicity brought about by not explicitly inhibiting execution of potentially hazardous commands is deemed more important than security concerns; it is the programmer's responsibility to write safe scripts, and the user's responsibility to inspect the scripts before use.

[ previous ] [ contents ] [ next ]


Copyright © 2001-2005 by Albert REINER. All rights reserved.

URL: http://purl.oclc.org/NET/arfg/current/backends.html

URL: http://purl.oclc.org/NET/arfg/2.13c/backends.html

2001-12-13 17:19:43