Directives are special instructions which are considered when a Proteus program is initially pre-compiled in memory; all directives start with the character '!' and, just like remarks, can appear between two lines of a splitted instruction; directives are not case sensitive and can be used to: include source code from another file, conditionally execute one part or another of a program (by using labels).
A label is a case-sensistive sequence of alphanumeric characters, whose definition can be tested or specified. The directives working on labels are the following:
define LABEL; same as using command line parameter -n
remove definition for LABEL; same as using command line parameter -u
!ifdef LABEL ... !else ... !endif
this directive tests if LABEL is defined; if the test is positive, the interpreter compiles all the code between !ifdef and !else (if present, or !endif); if LABEL is undefined, Proteus compiles the code following !else (if present) and preceding !endif; this structure is very similar to IF..ELSE..ENDIF
!ifndef LABEL ... !else ... !endif
analogous to !ifdef, this structure reverses the logic; if LABEL is defined, the code following !else is compiled, otherwise the code preceding it.
Proteus has the following labels defined upon startup (unless they are explicitly removed by using -u or !undef):
|UNIX||is defined if the operating system being used is Unix|
|MS_DOS||is defined if the operating system being used is Ms-Dos|
|WINDOWS||is defined if the operating system being used is Windows (95, 98, ME, NT, 2000, XP)|
|INTERACTIVE||is defined if the version of the interpreter being used supports interactive (console) functions|
|SERVICE||is defined if the version of the interpreter being used is a service|
|ISAPI||is defined if the version of the interpreter being used is an ISAPI|
The labels allow to conditionally pseudo-compile in memory specific parts of the source, e.g. for creating multi-language or platform-independent programs.
A special directive is:
this directive includes the source code contained in the specified file; the parameter is a string (between double quotes) corresponding to an existing filename (including path).
The Proteus interpreter is shipped with a few standard header files, including useful constants and function definitions for writing programs using strings, which are easier to remember than obscure numbers:
In the following example:
!ifdef UNIX !include "unxspec.prt" !else !include "dosspec.prt" !endif
the resulting program will include "unxspec.prt" if UNIX is defined, "dosspec.prt" otherwise. The included files can, in turn, include other files, without limitations (except memory). The rule for searching the included files is the same used for opening a program file, with the following exception: before evaluating the directories in the environment variable PATH, the directory corresponding to the program specified on the command line is considered. The usage of !include allows to create a library of functions that can be re-used in many programs.
Two special directives are available to document the program, by adding formatted blocks of text directly inside the source code:
all the text that follows is ignored, except for the directives !bdoc and !edoc
continues the interpretation of the program, which was previously suspended by using !bdoc
The directives !bdoc and !edoc can be nested; take care that the number of directives of the first type matches the number of those of the second type; to understand how the interpretation works, think of a counter that is increased by !bdoc and decreased by !edoc: only when the counter is zero the program is interpreted (by the way, that counter should never become negative). Example:
!bdoc Here we can write anything we want; the only thing that we must avoid is beginning a line with !bdoc or !edoc. !edoc CONSOLELN "Hello, world!"
Another special directive is:
ends the program, independently from the position in the file where it appears (even if it is encountered within an include file)
By using !endprog, it is possibile to "cut out" all the code
that follows; this is useful to speed up loading time, for example if what follows
consists only of remarks and blocks of documentation.
It is even possible to eventually include data after the source code; when this directive appears, the variable PROG_DATA is defined and gets the value of the offset, within the script, of the next line following the directive !endprog. By using this simple code fragment, it is possible to access the data following the directive:
H = FOPEN(ARGV(2), 1) FSEEK(H, PROG_DATA, 0)
By default, if Proteus does not recognize a directive it prints out an error message and does not execute the program; this behaviour can be changed by using command line parameter '-g'.
Another very important directive, available in the Windows version of the interpreter, is !extern; this directive allows using functions compiled in external DLLs in Proteus programs, by following the scheme presented in the chapter "Linking external functions to Proteus programs".
|Start of page||Next topic||Previous topic||Contents||Index|