PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: #Debug[Next]: #DefineRexx[+]
\ -> Commands -> #define[+|?]

#define[+|?]

A #define can be used to define a value (constant) once and then refer to it elsewhere. It allows you to update one place and have all necessary change flow though to all the statements that refer to it.

If ppwizard discovers that you are about to redefine an existing variable then:

  1. If the command was "#define" a warning is generated. The reason for this is because it is assumed you did not expect this. You could be reusing a macro that belongs to someone else (hidden in a header you use) or you may have made some kind if mistake.

  2. If the command was "#define+" then you are expecting to override a variable and so no warning is generated. I recommend you don't use this command for general use.

  3. If the command was "#define?" then the definition is aborted. This is useful in your header files where the user is allowed to override default values.

For more information on macros and their use please see the macros section.

There are some situations where you may wish to use the #AutoTag facility instead. The main difference is with a #define'd variable you indicate where the replacement will occur - if it can't do it the build fails, when using #AutoTags the replacement occurs automatically but it may not always come out the way you wish and of course no error if it "fails" (use of #defines is also very much faster). I mainly use #AutoTag when I'm including real working code from a file and I want to created hypertext links or highlight sections. I can then quickly change the example without having to worry about having to retag it.

You should also have a look at the #evaluate command which can do things that a #define can't.

Note that there are some extreme situations which you will not be able to wrap up in a #define (or at least easily). As an example of a situation which will be very difficult (if not impossible) would be to include a reference to a macro which then uses the #AsIs command, also be careful with #AutoTag. commands. In these situations you can use a #Include command to perform the textual replacement.

The DefineMacroReplace option affects how this command works.

Syntax

The syntax of this command is different from most others as it does not accept quoted strings, the reason for this is to ensure that you can include 'C' header files with a bit of care (allowing sharing of the common header).

[WhiteSpace]#define[+] Variable  Contents

The "Variable" is the name of the macro and when seen in following lines will be replaced by the contents. If the macro you are creating contains ppwizard commands then you must use the line continuation characters and place each ppwizard command on a line of its own.

The "Contents" is basically the rest of the line and is what is placed into the output. This may contain any number of mandatory or optional parameters.

The line containing a #define does not itself have variables substituted. What this means is that if the "Contents" contains other definitions, the values of these at the time of use will be used. If this is not what you wish then use the "#evaluate" to create the definition.

Note that for ppwizard commands (within a #define) to be executed when the macro is expanded the commands must be on their own line. Please see the multi line macros section.

I highly recommend that you read the whole section on macros. I get a reasonable amount of emails from people who haven't....

You can redefine a variable if you wish.

Example 1 - No Parameters Used

;--- #define some standard stuff --------------------------------------------
#define Img100%PureJava         <IMG SRC="graphics/java100.gif" ALT="{100% pure Java}" HSPACE=5 VSPACE=10 ALIGN=middle BORDER=0 WIDTH=100 HEIGHT=100>
#define ImgFreeIbmVisualAgeJava <IMG                                 \
                                        SRC="graphics/vaj_free.gif"  \
                                        ALT="{Free Visual Age Java}" \
                                        HSPACE=5                     \
                                        ALIGN=middle                 \
                                        BORDER=0                     \
                                        WIDTH=88 HEIGHT=31           \
                                >
#define ImgBarbedWire           <P><CENTER><IMG SRC="graphics/barbwire.gif"></CENTER>

;--- Now use some #defines -------------------------------------------------
<P>Paragraph before barbed wire.

<$ImgBarbedWire>

<P>Paragraph after barbed wire.

Example 2 - Parameters Used

;--- Define an image -------------------------------------------------------
#define AnImage <IMG SRC="graphics/AnImage.gif" WIDTH={$WIDTH} HEIGHT={$HEIGHT}>

;--- Refer to image twice, each with different size ------------------------
<P>Image at Size 1 = <$AnImage WIDTH="100" HEIGHT="33">
<P>Image at Size 2 = <$AnImage WIDTH='200' HEIGHT=|66|>


;--- Define an image -------------------------------------------------------
#define AnImage2 <IMG SRC="graphics/AnImage.gif" {$All}>>

;--- Refer to the image supplying any and all parameters -------------------
<P>Image = <$AnImage2 All=/ALT="{An Image}" WIDTH="100" HEIGHT="33"/>

;--- Refer to the image supplying NO parameters ----------------------------
<P>Image = <$AnImage2 All="">

Example 3 - Contains Logic

;--- Define a macro that can be used to include my example files -----------
#define    IncludeExampleFile                    \
           <BR><TABLE BORDER=5 CELLSPACING=5>    \
           <TR>                                  \
           <TH ALIGN=LEFT>{$TEXT}                \
           </TR>                                 \
           <TR><TH ALIGN=LEFT>                   \
           <PRE>                                 \
           <FONT size=-1>                        \
           #AsIs    ON                           \
           #include "{$FILE}"                    \
           #AsIs    OFF                          \
           </FONT>                               \
           </PRE>                                \
           </TR>                                 \
           </TABLE>

<$IncludeExampleFile FILE="Example.TXT" TEXT='Example file "EXAMPLE.TXT"'>

Example 4 - Default Parameters

;--- Define a stupid macro which defaults some parameters ------------------
#define    AMacro /{Parm1}/{Parm2="Default2"}/{Parm3=+Default3+}/

;--- Use the macro ---------------------------------------------------------
<$AMacro Parm1='Text1'>
<$AMacro Parm1='Text1' Parm2=*Text2*>


email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: #Debug[Next]: #DefineRexx[+]


PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday February 28 2016 at 2:05pm