/***************************************************************************** * * $Id$ * Purpose ...............: TURBODIESEL Macro language * ***************************************************************************** * Copyright (C) 1997-2002 * * Michiel Broek FIDO: 2:280/2802 * Beekmansbos 10 * 1971 BV IJmuiden * the Netherlands * * This file is part of MBSE BBS. * * This BBS is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * MBSE BBS is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MBSE BBS; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ /* T U R B O D I E S E L Template-based Uncomplicated Report-Building Oriented Dumb Interpretively Evaluated String Expression Language This is a modified version of diesel language. Diesel is a interpreted macro language, used in AutoCAD and released to public domain by AutoDesk. Modified version by Redy Rodriguez, for use in mbsebbs. Original diesel language can be found at http://www.fournilab.ch/diesel. This "Dumb 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, "@" 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. TURBODIESEL facilities ---------------------- If a line begin with # then will be not evaluated, and any output is done. If a line begin with @! any output is done, but evaluation is performed. If a line begin with @{} produces output only if expression is TRUE (Any non-zero numeric value). To easily format output, you can use one-char variable names as follow: @A will be replaced by result of evaluate @(GETVAR,A). @A_____ will be replaced by result of evaluate @(GETVAR,A) truncated or padded with spaces to complete same lenght of '@A_____' (7 in that case). You can use > or < to especify alignement rigth or left: @A_____> @A_____< TURBODIESEL String Functions ---------------------------- @(+,,,...) The sum of the numbers , , ... is returned. @(-,,,...) The result of subtracting the numbers through from is returned. @(*,,,...) The result of multiplying the numbers ,,... is returned. @(/,,,...) The result of dividing the number by ,... is returned. @(=,,) If the numbers and are equal 1 is returned, otherwise 0 is returned. @(<,,) If the number is less than 1 is returned, otherwise 0 is returned. @(>,,) If the number is greater than 1 is returned, otherwise 0 is returned. @(!=,,) If the numbers and are not equal 1 is returned, otherwise 0 is returned. @(<=,,) If the number is less than or equal to 1 is returned, otherwise 0 is returned. @(>=,,) If the number is greater than or equal to 1 is returned, otherwise 0 is returned. @(AND,,,...) The bitwise logical AND of the integers through is returned. @(EQ,,) If the strings and are identical 1 is returned, otherwise 0. @(EVAL,) The string is passed to the DIESEL evaluator and the result of evaluating it is returned. @(FIX,) The real number is truncated to an integer by discarding any fractional part. @(IF,,,) If is nonzero, is evaluated and returned. Otherwise, is evaluated and returned. Note that the branch not chosen by is not evaluated. @(INDEX,,) is assumed to contain one or more values delimited by the macro argument separator character, comma. selects one of these values to be extracted, with the first item numbered zero. * @(LOWER,) The is returned converted to lower case according to the rules of the current locale. @(NTH,,,,) Evaluates and returns the argument selected by . If is 0, is returned, and so on. Note the difference between @(NTH) and @(INDEX); @(NTH) returns one of a series of arguments to the function while @(INDEX) extracts a value from a comma-delimited string passed as a single argument. Arguments not selected by are not evaluated. @(OR,,,...) The bitwise logical OR of the integers through is returned. * @(STRCMP,,) Compare strings and returns -1 if is less than , 0 if both are equals, or 1 if is greater than . @(STRFILL,,) Returns the result of concatenating of . @(STRLEN,) Returns the length of in characters. * @(STRSTR,,) Find first apparition of in , and return the position or 0 if not found. @(SUBSTR,,,) Returns the substring of starting at character and extending for characters. Characters in the string are numbered from 1. If is omitted, the entire remaining length of the string is returned. @(UPPER,) The is returned converted to upper case according to the rules of the current locale. @(XOR,,,...) The bitwise logical XOR of the integers through is returned. 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. Variable names are case sensitive. If you want easily format output you must use one-char variable names then you can format output as @V_____, @X_____< or @k___>. See above. @(GETVAR,varname) Returns the value stored in . If no variable with the name exists, a bad argument error is reported. @(SETVAR,varname,value) Stores the string into . If no variable called exists, a new variable is created. * @(CLEAR) Clear all variables. Unix Extensions --------------- If you compile DIESEL with the tag UNIXTENSIONS defined, the following additional functions will be available: @(GETENV,varname) Returns the variable from the environment. If no such variable is defined, returns the null string. @(TIME) Returns the current time in Unix fashion, as the number of seconds elapsed since 00:00:00 GMT January 1, 1970. @(EDTIME,