Conditional Processing and Flow Control

Top  Previous  Next

Project file commands may be executed conditionally, using #if, #then, #elsif, #else, and #endif commands. In addition, processing may be stopped with #error and #abort when certain conditions occur.

 

#if

The syntax of the #if command is as follows :

 

#if <boolean-expression> #then

commands

#elsif <boolean-expression> #then

commands

#else

commands

#endif

The #elsif part may be omitted, or may be repeated any number of times. The #else part may be omitted.

The expressions are evaluated in order, until one of them yields true, then the following command sequence is executed. If none of the expressions yield true, and the #else part is present, then the commands following #else are executed. All other commands are ignored.

The syntax and semantics of boolean expressions are described under Boolean Expressions below.

 

#error

  #error <string>

This command terminates the current project. Under the Clarion environment, the Text Editor is opened at the position of the #error command, and displays the supplied string as the error message. For example:

 

#if "%name"="" #then

#error "name not set up"

#endif

 

#abort

  #abort [ on | off ]

This command is used to control whether a failed #compile or #run command will terminate a project. If abort mode is on, a project will be aborted as soon as a #compile fails, or a #run command produces a non-zero return-code. If abort mode is off, a project will only be aborted if an internal command fails, including a #link, #implib or #exemod command.

#abort on will set abort mode to on, while #abort off will turn it off. #abort without one of the above arguments will abort the current project immediately.

The default abort mode is on when running under the Clarion environment.

 

User Interface

The following commands allow you to collect information and provide feedback during the make process.

 

#message

  #message <string>

This command displays the specified string in the make display window. This can be used to indicate progress through the project file, or to display status messages. For example:

#message "finished making %prjname"

 

#prompt

  #prompt <promptstring> [ <defaultstring> ]

This command prompts you to enter a string, by displaying the <promptstring> and waiting for a keyboard entry. The string you enter is returned as the value of the macro %reply. If <defaultstring> is specified, and no keyboard entry is made, the <defaultstring> will be used as the value returned to %reply. For example:

#prompt "Command line: " %cline

#set cline = %reply

 

Boolean Expressions

Boolean expressions used in #if and #elsif commands are made up from the following boolean operators (listed in order of precedence):

 

#or

#and

#not

=

#exists

#older

( )

 

#or

boolean-expression = <factor> { #or <factor> }

A boolean expression containing one or more #or operators yields true if the evaluation of any of the factors yields true.

 

#and

<factor> = <term> { #and <term> }

A factor containing one or more #and operators yields false if the evaluation of any of the terms yields false.

 

#not

<term> = #not <term>

A term proceeded by the #not operator yields true if the evaluation of the term yields false, and vice versa.

 

= (comparison)

<term> = string = string

A term containing a comparison operator yields true if the strings are identical, otherwise false. == may be used instead of =.

The = operator and second string may be omitted, in which case the first string is compared against the string "on". That is,

DemoSwitch =

is equivalent to

DemoSwitch = "on"

The first string may be replaced by an expression of the form name1(name2), where name2 names a #pragma of class name1. In this case, the expression is replaced by the current setting of the specified #pragma, before the comparison is made.

 

#exists

<term> = #exists <file-name>

A term containing the #exists operator yields true if the file exists (after applying redirection to the filename), otherwise false.

 

#older

<term> = <file-name> #older <file-name> { , <file-name> }

A term containing the #older operator yields true if the first file specified is older than at least one of the other files specified, otherwise false. Redirection is applied to all filenames (See The Redirection File below). This operator is often useful to determine whether a post/pre-processing action needs to be performed. For example:

 

#if mydll.lib #older mydll.exp #then

...

 

() Parenthesized Boolean expressions

<term> = ( <Boolean-expression> )

A term may consist of a parenthesized Boolean expression, in order to alter or clarify the binding of other Boolean operators. The term yields true if the enclosed Boolean expression yields true. Arbitrarily complex Boolean expressions may be formed.

 

 

Filenames and Redirection Analysis

Filenames may be fully qualified (i.e., C:\Clarion\Orders\Order.tps) in which case redirection analysis is not done. Alternatively, filenames may not be fully qualified, e.g. ORDERS.TPS, in which case redirection analysis is applied.

Redirection analysis means the project system compares the filename with the filepatterns in the current redirection file, until a match is found. Then, the project system searches only those directory paths associated with matching filepattern to locate the file.

When creating new files, the project system creates the file in the first directory associated with the matching filepattern.

 

#file Commands

The following file system commands are available:

 

#file adderrors

#file append

#file copy

#file delete

#file move

#file redirect

#file touch

 

#file copy <src-filename> <dst-filename>

This command causes a file to be copied from <src-filename> to <dst-filename>. Both <src-filename> and <dst-filename> must be filenames without wildcard characters. Redirection is applied to both filenames.

#file delete <filename>

This command causes the nominated file to be deleted. <filename> must be a filename without wildcard characters. Redirection is applied to the filename.

#file move <src-filename> <dst-filename>

This command moves (renames) a file from <src-filename> to <dst-filename>. Both filenames must specify files on the same drive. Redirection is applied to both filenames.

#file touch <filename>

This command sets the date and time of <filename> to be the current date and time.

#file append <filename> <string>

This command appends the specified string to <filename>, followed by a CR/LF pair. The file will be created if it does not exist. This command can be used to build log files, etc.

#file redirect [ <filename> ]

This command changes the current redirection file to <filename>. If no filename is specified, then the command changes the current redirection file to the redirection file that began the project.

At the end of the project file, the redirection file is restored to the redirection file that began the project.

#file adderrors <filename>

This command processes the error messages in the nominated file, and adds them to the errors that will be reported when the project terminates.

Each error message must be in one of the following formats:

 

(filename lineno,colno): error string

(filename lineno): error string

filename(lineno): error string

To capture errors from a program with a different error format, a filter program can be used to translate them. For example:

 

#run ‘masm %f; > %f.err’

#file adderrors %f.err

#run ‘myprog %f; | myfilter > %f.err’

#file adderrors %f.err

If any errors are detected, and abort mode is on, the project will terminate and the errors will be reported in the make status window.

The macros %errors and %warnings are set to the number of errors and warnings detected.

 

Other Commands

 

#run <commandstring>

This command executes the command specified by <commandstring>. A #run command is generated whenever you add a file to the Programs to execute folder in the Project Tree dialog.

For example:

 

#run "dir > dir.log"

#run "myprog"

 

 Filenames within the command string (with the exception of the executable filename itself) are not automatically subject to redirection - #expand may be used before using #run if this is required.

 

#include <file-name>

A copy of the contents of the nominated file is inserted in the input stream. <filename> should specify a fully qualified filename, or an unqualified filename, in which case redirection analysis is applied (see The Redirection File above).

The current values of the link list, #pragma settings, and macros are fully available to the #include statements. In other words, the #include statements are handled as though they resided within the including .prj file.

#call <file-name>

A copy of the contents of the nominated file is inserted in the input stream. <filename> should specify a fully qualified filename, or an unqualified filename, in which case redirection analysis is applied (see The Redirection File above).

The current values of the link list, #pragma settings, and macros are not available to the #call statements, and the #call statements cannot modify these values in the calling environment. In other words, #call statements are handled as a process that is completely separate from the calling process.

#declare_compiler <file_extension> = <executed_macro>

This defines a macro which is invoked when compiling source files with an extension matching the first parameter. The macros %src and %obj, are set to the names of the source and object files.

Generally, you will not have to use this command explicitly, as all SoftVelocity compilers are pre-declared in the Project System. For example the following is to invoke MASM

 

#declare_compiler asm=

‘#set make=%%remake

#if %%make #then

#edit save %%src

#expand %%src

#set _masmsrc=%%opath

#expand %%obj

#set _masmobj=%%cpath

#run "masm %%_masmsrc,%%_masmobj/MX/e; >masmtmp.$$$"

#file adderrors masmtmp.$$$

#file delete masmtmp.$$$

#endif

#pragma link(%%obj)’

 

#rundll <dll_name> <source_filename> <output_filename>

This command invokes an integrated SoftVelocity compiler/utility. The first string is the DLL name, the second is the source filename, and the third is the output filename.

You should never have to use this command explicitly, as all SoftVelocity compilers/utilities are pre-declared in the Project System.

#exemod

  #exemod <file-name> <file-name> <file-name>

This command is the equivalent of using the tsexemod utility that comes with SoftVelocity C, C++, and Modula-2. #exemod is required to make advanced overlay model programs, Windows programs and DOS DLLs. However, it is not necessary to use this command explicitly when making Windows programs.

TSEXEMOD is used to modify the header and segment information in a new format executable file (.EXE or .DLL), using the information in a module definition (.EXP) file. For example:

TSEXEMOD binfile.* expfile.exp mapfile.map