DIESEL is a rudimentary macro expansion. It is an acronym for Direct Interactively Evaluated String Expression Language. DIESEL is used in menu macros and toolbar macros. It also allows to customize the status bar.
The basic idea behind DIESEL is very simple: "There's nothing but strings". The DIESEL interpreter takes a string, processes it, and returns a string. Within this original string submitted for evaluation some character sequences are interpreted as DIESEL functions. Each of these functions in term, get evaluated by the DIESEL interpreter: the interpreter replaces the DIESEL function in the original string by it's return value. The result of processing and evaluating all these functions is a string.
The format is as follows: every function begins with a dollar sign and a parenthesis and a function name, like this:
$(fn1
it is then followed by one or more parameters and closed by a closing parenthesis.
,param1 [ ,param2 .. paramN])
The opening and closing parentheses signal the beginning and end of Diesel function.
Diesel functions can be nested, where the result of an inner function is passed as a parameter to the outer function:
$(fOuter$,$(fInner,param2,param3),param1)
Unlike Lisp, Diesel delimits parameters with a , colon - not a space as in Lisp. In fact Diesel does not allow spaces in most cases.
Using DIESEL in Menus and Toolbars
You can customize menus using DIESEL expressions in customization (CUI) files The DIESEL code is always preceded by $M= when working with menus, for example:
$M=$(getvar,cmdnames)
Using DIESEL in the Status Bar
You can use the MODEMACRO system variable to display information on the left most portion of the status bar. Use the MODEMACRO system variable directly on the command line or access it via the Settings dialog. For example, the following text entered on the command line, will prompt Hello world on the status bar :
:modemacro
:New value for MODEMACRO, or . for none/<"">: Hello world
You can use DIESEL to customize text that displays in the user area of the status bar.
:modemacro Dwg=$(getvar,dwgname)
To return the status bar to be blank, enter the following:
:modemacro ""
Note that since value of the MODEMACRO system variable does not get saved in between sessions, it will be cleared when you start a new session.
Using DIESEL within LISP
You can use the following functions in LISP in conjunction with DIESEL:
1) using Modemacro
SetVar – Use SetVar with the MODEMACRO system variable, for example:
(setvar "modemacro" "Tilemode= $(getvar,tilemode)")
2) using MenuCmd
Use MenuCmd with the M= menu macro to customize menus, for example:
(menucmd "M=Tilemode= $(getvar,tilemode)")
3) create a command line Diesel evaluator. Although you cannot evaluate DIESEL directly on the command line, following Lisp routine emulates such evalution on the command line. As above the function uses (menucmd m=) to perform the evaluation:
;command line DIESEL evaluator ;found @ http://www.crlf.de/Dokumente/Diesel/Diesel.html (defun c:DIESEL (/ s) (while (/= "" (setq s (getstring T "nDIESEL: "))) (princ (menucmd (strcat "m=" s))) ) (princ) )
This ”r;Direct Interpretively Executed String Expression Language” is the kernel of a macro language you can customise by adding C code and embedding it into your program.
It is short, written in portable C, and is readily integrated into any program. It is useful primarily to programs which need a very rudimentary macro expansion facility without the complexity of a full language such as Lisp or FORTH.
DIESEL copies its input directly to the output until a macro character, ”r;$” or quoted string is encountered. Quoted strings may be used to suppress evaluation of sequences of characters which would otherwise be interpreted as macros. Quote marks may be included in quoted strings by two adjacent quote marks. For example:
"$(if,1,True,False)="""$(if,1,True,False)""""
Status retrieval, computation, and display are performed by DIESEL functions. The available functions are as follows. User-defined functions are not implemented; what you see is all you've got. Naturally, if you embed DIESEL in your application, you'll add functions that provide access to information and actions within your own program. DIESEL's arithmetic functions accept either floating point or integer arguments, and perform all calculations in floating point.
DIESEL String Functions
Starting DIESEL
You invoke DIESEL within your program by calling:
int status; char instring[whatever], outstring[MAXSTR + 1]; status = diesel(instring, outstring);
The output from the evaluation will be stored in
outstring when control is returned to your program. If no errors
were detected during evaluation, status
will be zero.
Otherwise status
gives the character position within
instring at which the error was detected. If an error occurs,
DIESEL will include an error diagnostic, documented below, in
outstring
.
DIESEL Mechanics
Generally, if you mess something up in a DIESEL expression it's pretty obvious what went wrong. DIESEL embeds an error indication in the output stream depending on the nature of the error:
Variable Extensions
The base-line DIESEL includes no user-defined variables. This allows DIESEL to avoid allocating any local memory and renders it totally reentrant. If you compile DIESEL with the tag VARIABLES defined, the following additional functions are included which provide variable definition and access. Note that these functions call malloc() and strdup() and thus consume heap storage.
Unix Extensions
If you compile DIESEL with the tag UNIXTENSIONS defined, the following additional functions will be available:
Assume the date is: Thursday, 2 September 1993 4:53:17
Format phrases:
D | 2 |
DD | 02 |
DDD | Thu |
DDDD | Thursday |
M | 9 |
MO | 09 |
MON | Sep |
MONTH | September |
YY | 93 |
YYYY | 1993 |
H | 4 |
HH | 04 |
MM | 53 |
SS | 17 |
AM/PM | AM |
am/pm | am |
A/P | A |
a/p | a |
DIESEL is in the public domain; you can do anything you like with it.
DIESEL is supplied as a GZIPped TAR archive, diesel.tar.gz.
The following files will be present in the directory after the extraction is complete:
BCMAKE.BAT Batch file to build with Borland C on MS-DOS. DIESEL.C Complete source code, including a built-in test program. MAKEFILE Make file for Unix. MANIFEST List of files in the distribution. MSCMAKE.BAT Batch file to build with Microsoft C 7.0. REGRESS.DSL Diesel regression test script. REGRESS.MAS Regression test master output file. UTEST.DSL Test for the Unix extensions to DIESEL.
All files are distributed in MS-DOS end of line convention (CR/LF). You may have to convert them to the native end of line convention of your system before compiling. DIESEL has been built and regression tested without errors on the following systems:
Sun SPARCStation 2, SunOS 4.1.1 MS-DOS, Borland C 2.0 MS-DOS, Microsoft C 7.0
If DIESEL looks intriguing, but too small and simple for the application you have in mind, please check out ATLAST, my FORTH-based open application toolkit. ATLAST, although much larger and more complicated than DIESEL, is a full-fledged programming language which provides the speed of compiled code, multiple data types, user-defined functions and data types, and just about everything you'll need to make a closed application user programmable.
© Bricsys NV. All rights reserved. |