![]() |
WPP 2.13.1.35 - The Web Preprocessor
Author: Marco Lamberto |
![]() |
Index | < Previous Next > |
Macro expansion |
![]() |
@MACRO MNAME(arg1, arg2, ...)@ ... @ENDMACRO@Declare MNAME as a new macro. Notice that the valid charset for the name and the arguments is the same of the variables (A-Z,0-9,_).
@MNAME("arg1", "arg2", ...)@Calls MNAME. If you use the char '"' within a macro argument you should excape it by prepending a '\' char.
<!-- macro called with args containing string constants -->
@MY_MACRO("Test", "test.html")@
<!-- macro called with args containing variables -->
@MY_MACRO(@FILENAME@, "@FILENAME@.html")@
<!-- example of splitted macro call -->
@MY_MACRO("\"@FILENAME@\" is the source",\
"@FILENAME@.html")@
Notes & Restrictions |
![]() |
Macros can be called within other macros (but pay attention to recursive calls!), variables assignments or macro aguments.
Sometimes can be useful surrounding a macro declaration with an IF block. By testing the macro's name you can prevent multiple declarations of the same macro.
Overloading |
![]() |
<!-- macro #1 declaration -->
@MACRO HTML_LINK(NAME, HREF)@
<A HREF="@HREF@">@NAME@</A>
@ENDMACRO@
<!-- macro #2 declaration -->
@MACRO HTML_LINK(HREF)@
@HTML_LINK("unnamed link (@HREF@)", "@HREF@")@
@ENDMACRO@
@ENDIF@
Built-in macros |
![]() |
Macro | Expanded to (XHTML output) |
---|---|
@HTML_IMAGE(img)@ |
<img src="img" width="(image width)" height="(image height)" /> |
@HTML_IMAGE(img, alt)@ |
<img srg="img" width="(image width)" height="(image height)" alt="alt" /> |
@HTML_IMAGE(img, alt, extra)@ |
<img src="img" width="(image width)" height="(image height)" alt="alt" extra /> |
@HTML_IMAGE_SIZE(img)@ |
src="img" width="(image width)" height="(image height)" |
@HTML_IMAGE_SIZEO(img)@ |
width="(image width)" height="(image height)" |
@HTML_IMAGE_WIDTH(img)@ |
width="(image width)" |
@HTML_IMAGE_HEIGHT(img)@ |
height="(image height)" |
@IMAGE_WIDTH(img)@ |
Image width. |
@IMAGE_HEIGHT(img)@ |
Image height. |
@HTML_IMAGE("index.jpg", "my logo",\ "border=\"0\" hspace=\"10\"")@
<IMG SRC="index.jpg" WIDTH="100" HEIGHT="200" ALT="my logo" border="0" hspace="10" >
<img src="index.jpg" width="100" height="200" alt="my logo" border="0" hspace="10" />
Macro | Expanded to (XHTML output) |
---|---|
@CERN2HTML(mapfile)@ @NCSA2HTML(mapfile)@ |
<map name="mapfile" id="mapfile"> <area shape="..." href="..." coords="..." alt="..." /> </map> |
@CERN2HTML(mapfile, mapname)@ @NCSA2HTML(mapfile, mapname)@ |
<map name="mapname" id="mapname"> <area shape="..." href="..." coords="..." alt="..." /> </map> |
@CERN2HTML(mapfile, mapname, mapid)@ @NCSA2HTML(mapfile, mapname, mapid)@ |
<map name="mapname" id="mapid"> <area shape="..." href="..." coords="..." alt="..." /> </map> |
@NCSA2HTML("index.map", "myindex")@ <A HREF="index.map"><IMG SRC="menu.gif" WIDTH="600" HEIGHT="50" ISMAP USEMAP="#myindex"></A>
Macro | Expanded to |
---|---|
@FILE_SIZE(file)@ @FILE_SIZE(file, unit)@ |
File size in bytes. The unit can be 'b' (bytes, default), 'k' (kilobytes) , 'm' (megabytes) and 'g' (gigabytes). |
@FILE_DATE(file)@ |
File modification date, according to DATE_FORMAT. |
Extending WPP |
![]() |
Macro | Expanded to |
---|---|
@SYSTEM(CMD)@ |
The output of 'CMD' command. |
@SYSTEM(CMD, DOPP)@ @SYSTEM_PP(CMD)@ |
The command output postprocessed through WPP if 'DOPP' isn't an empty string. SYSTEM_PP is an alias for SYSTEM with postprocessed output. |
@MACRO RED(TEXT)@ <span style="color: red;">@TEXT@</span> @ENDMACRO@ @CMD=ls --color=no -1 / | sed 's|^| @AT@RED("|; s|/||g; s|$|")@AT@|g'@ <table> <tr> <td> System #1: <pre> @SYSTEM("@CMD@")@ </pre> </td> <td> System #2: <pre> @SYSTEM("@CMD@", "1")@ </pre> </td> </tr> </table>
System #1:
@RED("bin")@ @RED("boot")@ @RED("dev")@ @RED("etc")@ @RED("home")@ @RED("initrd")@ @RED("lib")@ @RED("lost+found")@ @RED("misc")@ @RED("mnt")@ @RED("movies")@ @RED("opt")@ @RED("proc")@ @RED("rar")@ @RED("root")@ @RED("sbin")@ @RED("tftpboot")@ @RED("tmp")@ @RED("usr")@ @RED("var")@ |
System #2:
bin boot dev etc home initrd lib lost+found misc mnt movies opt proc rar root sbin tftpboot tmp usr var |
@VAR=some value@ ... @INLINE@ my $v; my $f = ''; for ($v = 0; $v < 10; $v++) { $f .= ' ' . ($v * $v); } return "test code [$f @VAR@]"; @ENDINLINE@ ...
... test code [ 0 1 4 9 16 25 36 49 64 81 some value] ...
Macro | Expanded to |
---|---|
@EVAL(expr)@ |
The value returned by the Perl expression expr. |
@EVAL(" \ my $str = ''; \ for(my $i = 0; $i < 11; $i++) { \ $str .= $i . ' '; \ } \ return $str; \ ")@
@LIMIT=11@ @EVAL(" \ my $str = ''; \ for(my $i = 0; $i < @LIMIT@; $i++) { \ $str .= \"@RANDOM()@ \"; \ } \ return $str; \ ")@
@LIMIT=11@ @EVAL(" \ my $str = ''; \ for(my $i = 0; $i < @LIMIT@; $i++) { \ $str .= WPP::call('RANDOM') . ' '; \ } \ return $str; \ ")@
@MACRO TEST(TEXT)@ [@TEXT@] @ENDMACRO@ @F=/etc/group@ @EVAL(" \ $str = ''; \ open(FH, '@F@'); \ while (<FH>) { \ chomp; \ $str .= WPP::call('TEST', $_) . \"\n\"; \ }; \ close(FH); \ return $str; \ ")@
[root:x:0:root] [bin:x:1:root,bin,daemon] [daemon:x:2:root,bin,daemon] [sys:x:3:root,bin,adm] [adm:x:4:root,adm,daemon] [tty:x:5:] [disk:x:6:root]
@TVAL=@EVAL("1 != 1")@@ @IF !TVAL@ EVAL ok! @ENDIF@ @TVAL=@EVAL("1 == 1")@@ @IF TVAL@ EVAL ok! @ENDIF@
EVAL ok! EVAL ok!
@EVAL("print 'TEST ' . (1 == 1); return '';")@ @EVAL("return 'TEST ' . (1 == 1);")@
@HEAD@ @TAIL@ $Date$ @EVAL("1+1'A'")@
[ko]$ wpp - < test_eval_err.raw W2: EVAL error 'String found where operator expected at (eval 2) line 1, near "1'A'"' (EVAL(v1):-:4) W2: EVAL error **** 1+1'A' **** W2: EVAL error ' (Missing operator before 'A'?)' (EVAL(v1):-:4) W2: EVAL error **** 1+1'A' **** W2: EVAL error 'syntax error at (eval 2) line 1, near "1'A'"' (EVAL(v1):-:4) W2: EVAL error **** 1+1'A' ****
Method | Description |
---|---|
WPP::eval(string) |
Run wpp parser over a specified block of text, the parsed output is returned. |
WPP::call(macroname, ...) |
Calls the specified macro, the parsed output is returned.
This method is a cleaner way for calling a macro within inlined code without using WPP::eval and dealing with '@' chars escaping. |
WPP::set(varname, value) |
Sets the value value of a wpp variable varname. |
WPP::get(varname) |
Returns the value of the variable varname. |
WPP::canonpath(path) |
Return the canonicalized path. |
WPP::debug(msg) WPP::message(msg) WPP::warning(msg) WPP::error(msg) |
Those methods are used for outputing log messages at different severity level. |
WPP::current_file() |
Returns the complete current file name where the expression is evaluated. |
WPP::depend(file, ...) |
Add the specified files to the dependencies for make. |
^ Top | < Previous Next > | |
Marco (LM) Lamberto lm@sunnyspot.org
Revised: 2003/03/10 07:38:04 http://wpp.sf.net/manual_6.html |
![]() ![]() ![]() |