Added DIESEL macro language
This commit is contained in:
parent
cec920a69b
commit
1ccf40e57e
@ -4612,6 +4612,9 @@ v0.33.20 10-Feb-2002
|
||||
clcomm.a
|
||||
Added counter for mailer TCP/IP sessions.
|
||||
|
||||
diesel.a
|
||||
New library for parsing macro templates.
|
||||
|
||||
mbsetup:
|
||||
In message groups added default settings for auto area
|
||||
creation.
|
||||
|
294
lib/Diesel.doc
Normal file
294
lib/Diesel.doc
Normal file
@ -0,0 +1,294 @@
|
||||
|
||||
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 @{<expresion>} 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
|
||||
----------------------------
|
||||
|
||||
@(+,<val1>,<val2>,...<valn>)
|
||||
The sum of the numbers <val1>, <val2>, ...<valn> is returned.
|
||||
|
||||
@(-,<val1>,<val2>,...<valn>)
|
||||
The result of subtracting the numbers <val2> through <valn> from
|
||||
<val1> is returned.
|
||||
|
||||
@(*,<val1>,<val2>,...<valn>)
|
||||
The result of multiplying the numbers <val1>,<val2>,...<valn> is
|
||||
returned.
|
||||
|
||||
@(/,<val1>,<val2>,...<valn>)
|
||||
The result of dividing the number <val1> by <val2>,... <valn> is
|
||||
returned.
|
||||
|
||||
@(=,<val1>,<val2>)
|
||||
If the numbers <val1> and <val2> are equal 1 is returned,
|
||||
otherwise 0 is returned.
|
||||
|
||||
@(<,<val1>,<val2>)
|
||||
If the number <val1> is less than <val2> 1 is returned, otherwise
|
||||
0 is returned.
|
||||
|
||||
@(>,<val1>,<val2>)
|
||||
If the number <val1> is greater than <val2> 1 is returned,
|
||||
otherwise 0 is returned.
|
||||
|
||||
@(!=,<val1>,<val2>)
|
||||
If the numbers <val1> and <val2> are not equal 1 is returned,
|
||||
otherwise 0 is returned.
|
||||
|
||||
@(<=,<val1>,<val2>)
|
||||
If the number <val1> is less than or equal to <val2> 1 is
|
||||
returned, otherwise 0 is returned.
|
||||
|
||||
@(>=,<val1>,<val2>)
|
||||
If the number <val1> is greater than or equal to <val2> 1 is
|
||||
returned, otherwise 0 is returned.
|
||||
|
||||
@(AND,<val1>,<val2>,...<valn>)
|
||||
The bitwise logical AND of the integers <val1> through <valn> is
|
||||
returned.
|
||||
|
||||
@(EQ,<val1>,<val2>)
|
||||
If the strings <val1> and <val2> are identical 1 is returned,
|
||||
otherwise 0.
|
||||
|
||||
@(EVAL,<str>)
|
||||
The string <str> is passed to the DIESEL evaluator and the result
|
||||
of evaluating it is returned.
|
||||
|
||||
@(FIX,<value>)
|
||||
The real number <value> is truncated to an integer by discarding
|
||||
any fractional part.
|
||||
|
||||
@(IF,<expr>,<dotrue>,<dofalse>)
|
||||
If <expr> is nonzero, <dotrue> is evaluated and returned.
|
||||
Otherwise, <dofalse> is evaluated and returned. Note that the
|
||||
branch not chosen by <expr> is not evaluated.
|
||||
|
||||
@(INDEX,<which>,<string>)
|
||||
<string> is assumed to contain one or more values delimited by the
|
||||
macro argument separator character, comma. <which> selects one of
|
||||
these values to be extracted, with the first item numbered zero.
|
||||
|
||||
* @(LOWER,<string>)
|
||||
The <string> is returned converted to lower case according to the
|
||||
rules of the current locale.
|
||||
|
||||
@(NTH,<which>,<arg0>,<arg1>,<argN>)
|
||||
Evaluates and returns the argument selected by <which>. If
|
||||
<which> is 0, <arg0> 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 <which> are not evaluated.
|
||||
|
||||
@(OR,<val1>,<val2>,...<valn>)
|
||||
The bitwise logical OR of the integers <val1> through <valn> is
|
||||
returned.
|
||||
|
||||
* @(STRCMP,<str1>,<str2>)
|
||||
Compare strings and returns -1 if <str1> is less than <Str2>, 0 if
|
||||
both are equals, or 1 if <str1> is greater than <str2> .
|
||||
|
||||
@(STRFILL,<string>,<ncopies>)
|
||||
Returns the result of concatenating <ncopies> of <string>.
|
||||
|
||||
@(STRLEN,<string>)
|
||||
Returns the length of <string> in characters.
|
||||
|
||||
* @(STRSTR,<str1>,<str2>)
|
||||
Find first apparition of <str2> in <str1>, and return the position
|
||||
or 0 if not found.
|
||||
|
||||
@(SUBSTR,<string>,<start>,<length>)
|
||||
Returns the substring of <string> starting at character <start>
|
||||
and extending for <length> characters. Characters in the string
|
||||
are numbered from 1. If <length> is omitted, the entire remaining
|
||||
length of the string is returned.
|
||||
|
||||
@(UPPER,<string>)
|
||||
The <string> is returned converted to upper case according to the
|
||||
rules of the current locale.
|
||||
|
||||
@(XOR,<val1>,<val2>,...<valn>)
|
||||
The bitwise logical XOR of the integers <val1> through <valn> 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 <varname>. If no variable with
|
||||
the name <varname> exists, a bad argument error is reported.
|
||||
|
||||
@(SETVAR,varname,value)
|
||||
Stores the string <value> into <varname>. If no variable
|
||||
called <varname> 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 <varname> 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,<time>,<picture>)
|
||||
Edit the Unix time <time> to format <picture>. If <time> is 0,
|
||||
the current date and time is edited (this is just shorthand for
|
||||
the equivalent "@(EDTIME,@(TIME),<picture>)".).
|
||||
|
||||
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
|
||||
|
||||
If any of the "AM/PM" phrases appear in the picture, the "H" and
|
||||
"HH" phrases will edit the time according to the 12 hour civil
|
||||
clock (12:00-12:59-1:00-11:59) instead of the 24 hour clock
|
||||
(00:00-23:59).
|
||||
|
||||
TURBODIESEL 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:
|
||||
|
||||
@? Syntax error (usually a missing right parenthesis
|
||||
or runaway string).
|
||||
|
||||
@(<func>,??) Incorrect arguments to <func>.
|
||||
|
||||
@(<func>)?? Unknown function <func>.
|
||||
|
||||
@++ Output string too long--evaluation truncated.
|
||||
|
||||
|
||||
Using TURBODIESEL
|
||||
-----------------
|
||||
|
||||
You invoke TURBODIESEL within your program by calling:
|
||||
|
||||
int status;
|
||||
char instring[<whatever>], outstring[MAXSTR + 1];
|
||||
|
||||
outstring = ParseMacro(instring, &status);
|
||||
|
||||
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, TURBODIESEL will include an error diagnostic,
|
||||
documented above, in outstring.
|
||||
|
||||
To set single-char variables you can use:
|
||||
|
||||
MacroVars(<string-names>,<string-types>,<value1>,...,<valueN>);
|
||||
|
||||
string-names -> Variable names
|
||||
string-types -> Variable types
|
||||
(s: string, c: char, d: integer, f: float).
|
||||
Both strings must be same lenght, and the number of values must
|
||||
match with lenght and types.
|
||||
|
||||
Sample:
|
||||
|
||||
MacroVars("ABCDE","sscdf","A String","Another String",'C',5,4.67);
|
||||
|
||||
To clear all variables you can use:
|
||||
|
||||
MacroClear();
|
||||
|
21
lib/Makefile
21
lib/Makefile
@ -27,15 +27,22 @@ MSGBASE_HDRS = jam.h jammsg.h jamsys.h msg.h msgtext.h
|
||||
MBINET_SRCS = nntp.c pop3.c smtp.c
|
||||
MBINET_OBJS = nntp.o pop3.o smtp.o
|
||||
MBINET_HDRS = mbinet.h
|
||||
DIESEL_SRSC = diesel.c mbdiesel.c
|
||||
DIESEL_HDRS = diesel.h
|
||||
DIESEL_OBJS = diesel.o mbdiesel.o
|
||||
MEMWATCH_SRCS = memwatch.c
|
||||
MEMWATCH_OBJS = memwatch.o
|
||||
MEMWATCH_HDRS = memwatch.h
|
||||
OTHER_HDRS = ansi.h bluewave.h libs.h mbse.h records.h structs.h users.h
|
||||
SRCS = ${CLCOMM_SRCS} ${COMMON_SRCS} ${DBASE_SRCS} ${MSGBASE_SRCS} ${MBINET_SRCS} ${MEMWATCH_SRCS}
|
||||
OBJS = ${CLCOMM_OBJS} ${COMMON_OBJS} ${DBASE_OBJS} ${MSGBASE_OBJS} ${MBINET_OBJS} ${MEMWATCH_OBJS}
|
||||
HDRS = ${CLCOMM_HDRS} ${COMMON_HDRS} ${DBASE_HDRS} ${MSGBASE_HDRS} ${MBINET_HDRS} ${MEMWATCH_HDRS} ${OTHER_HDRS}
|
||||
OTHER = Makefile README ftscprod.006 mkprod.awk FAQ README.memwatch USING test.c memwatch.c.org
|
||||
TARGET = libclcomm.a libcommon.a libdbase.a libmsgbase.a libmbinet.a libmemwatch.a
|
||||
SRCS = ${CLCOMM_SRCS} ${COMMON_SRCS} ${DBASE_SRCS} ${MSGBASE_SRCS} ${MBINET_SRCS} \
|
||||
${DIESEL_SRCS} ${MEMWATCH_SRCS}
|
||||
OBJS = ${CLCOMM_OBJS} ${COMMON_OBJS} ${DBASE_OBJS} ${MSGBASE_OBJS} ${MBINET_OBJS} \
|
||||
${DIESEL_OBJS} ${MEMWATCH_OBJS}
|
||||
HDRS = ${CLCOMM_HDRS} ${COMMON_HDRS} ${DBASE_HDRS} ${MSGBASE_HDRS} ${MBINET_HDRS} \
|
||||
${DIESEL_HDRS} ${MEMWATCH_HDRS} ${OTHER_HDRS}
|
||||
OTHER = Makefile README ftscprod.006 mkprod.awk FAQ README.memwatch USING test.c \
|
||||
memwatch.c.org README.diesel README.macro Diesel.doc
|
||||
TARGET = libclcomm.a libcommon.a libdbase.a libmsgbase.a libmbinet.a libdiesel.a libmemwatch.a
|
||||
|
||||
#############################################################################
|
||||
|
||||
@ -67,6 +74,10 @@ libmbinet.a: ${MBINET_OBJS}
|
||||
ar r $@ $?
|
||||
${RANLIB} $@
|
||||
|
||||
libdiesel.a: ${DIESEL_OBJS}
|
||||
ar r $@ $?
|
||||
${RANLIB} $@
|
||||
|
||||
libmemwatch.a: ${MEMWATCH_OBJS}
|
||||
ar r $@ $?
|
||||
${RANLIB} $@
|
||||
|
20
lib/README.diesel
Normal file
20
lib/README.diesel
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
If you want compile a standalone diesel executable interpreter, you can
|
||||
do it writing at linux prompt:
|
||||
|
||||
# cc -DTESTPROG -g diesel.c -o diesel
|
||||
|
||||
Then you can interpret a diesel script and see output calling...
|
||||
|
||||
# diesel <script
|
||||
or...
|
||||
# cat script |diesel
|
||||
|
||||
If you want set some vars before interpret script you can do...
|
||||
|
||||
# echo '@! @(setvar,a,5) @(setvar,B,HELLO)'| cat - script |diesel
|
||||
|
||||
Or you can put all @(setvar...) sentences in a separated file an call...
|
||||
|
||||
# cat setvar.file script |diesel
|
||||
|
52
lib/README.macro
Normal file
52
lib/README.macro
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
Using turbodiesel macro files in mbse. Now you can personalize response
|
||||
reports from areamgr, filemgr an notify using diesel macro files.
|
||||
|
||||
See diesel.doc for turbodiesel syntax.
|
||||
|
||||
Mbfido look for macro files first in macro language phat acording defined
|
||||
language in nodes setup, and then in $MBSEROT/etc/. If no macro file found
|
||||
mbfido uses harcoded respose.
|
||||
|
||||
(Michiel check that, I prefer not change CFG struct. If you add a default
|
||||
macro path, you must change function OpenMacro in mgrutil.c at line 495)
|
||||
|
||||
Macro files used are:
|
||||
|
||||
areamgr.flow -> %FLOW
|
||||
areamgr.group -> group report (included in areamgr.list)
|
||||
areamgr.help -> %HELP
|
||||
areamgr.list -> %LIST
|
||||
areamgr.notify.flow -> Flow report sent by 'mbfido notify'
|
||||
areamgr.notify.list -> Area status report sent by 'mbfido notify'
|
||||
areamgr.query -> %QUERY
|
||||
areamgr.responses -> Multiple responses for results of areamgr.
|
||||
areamgr.status -> %STATUS
|
||||
areamgr.unlink -> %UNLINK
|
||||
|
||||
filemgr.group -> group report (included in filemgr.list)
|
||||
filemgr.help -> %HELP
|
||||
filemgr.list -> %LIST
|
||||
filemgr.notify.list -> Area status report sent by 'mbfido notify'
|
||||
filemgr.query -> %QUERY
|
||||
filemgr.responses -> Multiple responses for results of filemgr.
|
||||
filemgr.status -> %STATUS
|
||||
filemgr.unlink -> %UNLINK
|
||||
|
||||
Some files are very similar, and can be a symbolic link to other including a
|
||||
few conditional macros.
|
||||
|
||||
See coments in sample files to undestand how work.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
For every macro file multiple values are passed in diesel variables,
|
||||
see samples to know what variables can be used for each file.
|
||||
|
||||
If you assign a value to 'subject' variable in a macro file, then the
|
||||
message subject will be that value.
|
||||
|
||||
Some files have multiple sections. Sections delimiter is @| at begin of line,
|
||||
you can put a comentary after @| delimiter (see areamgr.list sample).
|
||||
|
1932
lib/diesel.c
Normal file
1932
lib/diesel.c
Normal file
File diff suppressed because it is too large
Load Diff
54
lib/diesel.h
Normal file
54
lib/diesel.h
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef _DIESEL_H
|
||||
#define _DIESEL_H
|
||||
|
||||
#define UNIXTENSIONS
|
||||
#define VARIABLES
|
||||
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#define DIAGNOSTIC 2
|
||||
|
||||
#define EOS '\0'
|
||||
|
||||
#define V (void)
|
||||
|
||||
/* Globals exported */
|
||||
|
||||
#ifdef TRACE
|
||||
int tracing = TRUE; /* Trace macro evalution */
|
||||
#endif
|
||||
|
||||
/* Local variables. */
|
||||
|
||||
#define MAXARGS 10 /* Maximum arguments to a macro */
|
||||
#define MAXSTR 256 /* Maximum string length */
|
||||
#define MAXDEPTH 32 /* Maximum recursion depth for eval */
|
||||
|
||||
#define MACROCHAR '@' /* Macro trigger character */
|
||||
#define ARGOPEN '(' /* Argument open bracket */
|
||||
#define ARGCLOSE ')' /* Argument close bracket */
|
||||
#define ARGSEP ',' /* Argument separator character */
|
||||
#define QUOTE '"' /* Literal string quote character */
|
||||
#define CASEINS /* Case-insensitive function names */
|
||||
|
||||
#define STRLIMIT (MAXSTR - 20) /* String output length limit */
|
||||
#define OverFlow " @(++)" /* Glyph indicating string overflow */
|
||||
|
||||
#define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
|
||||
#define FUZZEQ(a, b) ((((a) < (b)) ? ((b) - (a)) : ((a) - (b))) < 1E-10)
|
||||
|
||||
|
||||
int diesel(const char *, char *);
|
||||
char *ParseMacro( const char *, int * );
|
||||
void MacroVars( const char *, const char *, ... );
|
||||
void MacroClear(void);
|
||||
|
||||
|
||||
/*
|
||||
* MBSE BBS specific functions
|
||||
*/
|
||||
FILE *OpenMacro(const char *, int);
|
||||
|
||||
#endif
|
||||
|
91
lib/mbdiesel.c
Normal file
91
lib/mbdiesel.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $Id$
|
||||
* Purpose ...............: MBSE BBS functions for TURBODIESEL
|
||||
*
|
||||
*****************************************************************************
|
||||
* 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, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "libs.h"
|
||||
#include "structs.h"
|
||||
#include "users.h"
|
||||
#include "records.h"
|
||||
#include "clcomm.h"
|
||||
#include "diesel.h"
|
||||
|
||||
|
||||
|
||||
FILE *OpenMacro(const char *filename, int Language)
|
||||
{
|
||||
FILE *pLang, *fi = NULL;
|
||||
char *temp;
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
temp[0] = '\0';
|
||||
|
||||
if (Language != '\0') {
|
||||
/*
|
||||
* Maybe a valid language character, try to load the language
|
||||
*/
|
||||
sprintf(temp, "%s/etc/language.data", getenv("MBSE_ROOT"));
|
||||
if ((pLang = fopen(temp, "rb")) == NULL) {
|
||||
WriteError("mbdiesel: Can't open language file: %s", temp);
|
||||
} else {
|
||||
fread(&langhdr, sizeof(langhdr), 1, pLang);
|
||||
|
||||
while (fread(&lang, langhdr.recsize, 1, pLang) == 1) {
|
||||
if ((lang.LangKey[0] == Language) && (lang.Available)) {
|
||||
sprintf(temp,"%s/%s", lang.MacroPath, filename);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(pLang);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to open the selected language
|
||||
*/
|
||||
if (temp[0] != '\0')
|
||||
fi = fopen(temp, "r");
|
||||
|
||||
/*
|
||||
* If no selected language is loaded, try default language
|
||||
*/
|
||||
if (fi == NULL) {
|
||||
sprintf(temp, "%s/%s", CFG.bbs_macros, filename);
|
||||
fi = fopen(temp,"r");
|
||||
}
|
||||
|
||||
if (fi == NULL)
|
||||
Syslog('d', "OpenMacro(%s, %c): not found, using hardcoded", filename, Language);
|
||||
else
|
||||
Syslog('d', "OpenMacro(%s, %c): using %s", filename, Language, temp);
|
||||
|
||||
free(temp);
|
||||
return fi;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ MBFILE_OBJS = mbfile.o mbfkill.o mbfutil.o mbfindex.o mbfcheck.o mbfpack.o mbfli
|
||||
mbfimport.o virscan.o mbftoberep.o mbfmove.o mbfdel.o
|
||||
MBMSG_OBJS = post.o mbmsg.o
|
||||
MBFIDO_LIBS = ../lib/libmemwatch.a ../lib/libclcomm.a ../lib/libcommon.a ../lib/libmsgbase.a \
|
||||
../lib/libdbase.a ../lib/libmbinet.a
|
||||
../lib/libdbase.a ../lib/libdiesel.a ../lib/libmbinet.a
|
||||
MBSEQ_LIBS = ../lib/libmemwatch.a ../lib/libclcomm.a ../lib/libcommon.a ../lib/libdbase.a
|
||||
MBAFF_LIBS = ../lib/libmemwatch.a ../lib/libclcomm.a ../lib/libcommon.a ../lib/libmsgbase.a ../lib/libdbase.a
|
||||
MBINDEX_LIBS = ../lib/libmemwatch.a ../lib/libclcomm.a ../lib/libcommon.a ../lib/libdbase.a
|
||||
|
881
mbfido/areamgr.c
881
mbfido/areamgr.c
File diff suppressed because it is too large
Load Diff
745
mbfido/filemgr.c
745
mbfido/filemgr.c
File diff suppressed because it is too large
Load Diff
180
mbfido/mgrutil.c
180
mbfido/mgrutil.c
@ -35,13 +35,13 @@
|
||||
#include "../lib/common.h"
|
||||
#include "../lib/clcomm.h"
|
||||
#include "../lib/dbnode.h"
|
||||
#include "../lib/diesel.h"
|
||||
#include "sendmail.h"
|
||||
#include "rollover.h"
|
||||
#include "addpkt.h"
|
||||
#include "mgrutil.h"
|
||||
|
||||
|
||||
|
||||
extern int net_out;
|
||||
|
||||
|
||||
@ -51,27 +51,38 @@ extern int net_out;
|
||||
*/
|
||||
void WriteMailGroups(FILE *fp, faddr *f)
|
||||
{
|
||||
int Count = 0, First = TRUE;
|
||||
char *Group, *temp;
|
||||
FILE *gp;
|
||||
int Count = 0, First = TRUE, res;
|
||||
char *Group, *temp, *line;
|
||||
FILE *gp,*fi;
|
||||
faddr *g;
|
||||
fpos_t fileptr;
|
||||
|
||||
temp = calloc(128, sizeof(char));
|
||||
fprintf(fp, "Dear %s\r\r", nodes.Sysop);
|
||||
line = calloc(256, sizeof(char));
|
||||
sprintf(temp, "%s/etc/mgroups.data", getenv("MBSE_ROOT"));
|
||||
fprintf(fp, "The following is a list of mail groups at %s\r\r", ascfnode(f, 0x1f));
|
||||
|
||||
fi=NULL;
|
||||
fi=OpenMacro("areamgr.group", nodes.Language);
|
||||
if (fi != NULL){
|
||||
while ( (fgets(line, 254, fi) != NULL) && ((line[0]!='@') || (line[1]!='|'))){
|
||||
fprintf( fp, "%s", ParseMacro(line,&res));
|
||||
}
|
||||
fgetpos(fi,&fileptr);
|
||||
}else{
|
||||
fprintf(fp, "Dear %s\r\r", nodes.Sysop);
|
||||
fprintf(fp, "The following is a list of mail groups at %s\r\r", ascfnode(f, 0x1f));
|
||||
}
|
||||
if ((gp = fopen(temp, "r")) == NULL) {
|
||||
WriteError("$Can't open %s", temp);
|
||||
free(temp);
|
||||
free(line);
|
||||
return;
|
||||
}
|
||||
fread(&mgrouphdr, sizeof(mgrouphdr), 1, gp);
|
||||
|
||||
|
||||
// 123456789012 1234567890123456789012345678901234567890123456789012345
|
||||
fprintf(fp, "Group Description\r");
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
|
||||
if (fi == NULL){
|
||||
fprintf(fp, "Group Description\r");
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
}
|
||||
while (TRUE) {
|
||||
Group = GetNodeMailGrp(First);
|
||||
if (Group == NULL)
|
||||
@ -84,17 +95,32 @@ void WriteMailGroups(FILE *fp, faddr *f)
|
||||
if ((!strcmp(mgroup.Name, Group)) &&
|
||||
(g->zone == f->zone) && (g->net == f->net) &&
|
||||
(g->node == f->node) && (g->point == f->point)) {
|
||||
fprintf(fp, "%-12s %s\r", mgroup.Name, mgroup.Comment);
|
||||
if (fi !=NULL){
|
||||
MacroVars("gh", "ss", mgroup.Name, mgroup.Comment );
|
||||
fsetpos(fi,&fileptr);
|
||||
while ( (fgets(line, 254, fi) != NULL) && ((line[0]!='@') || (line[1]!='|'))){
|
||||
fprintf( fp, "%s", ParseMacro(line,&res));
|
||||
}
|
||||
}else{
|
||||
fprintf(fp, "%-12s %s\r", mgroup.Name, mgroup.Comment);
|
||||
}
|
||||
Count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
fprintf(fp, "%d group(s)\r\r\r", Count);
|
||||
|
||||
if (fi != NULL){
|
||||
MacroVars("b", "d", Count );
|
||||
while ( fgets(line, 254, fi) != NULL ){
|
||||
fprintf( fp, "%s", ParseMacro(line,&res));
|
||||
}
|
||||
fclose(fi);
|
||||
}else{
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
fprintf(fp, "%d group(s)\r\r\r", Count);
|
||||
}
|
||||
fclose(gp);
|
||||
free(line);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
@ -105,27 +131,38 @@ void WriteMailGroups(FILE *fp, faddr *f)
|
||||
*/
|
||||
void WriteFileGroups(FILE *fp, faddr *f)
|
||||
{
|
||||
int Count = 0, First = TRUE;
|
||||
char *Group, *temp;
|
||||
FILE *gp;
|
||||
int Count = 0, First = TRUE, res;
|
||||
char *Group, *temp, *line;
|
||||
FILE *gp, *fi;
|
||||
faddr *g;
|
||||
fpos_t fileptr;
|
||||
|
||||
temp = calloc(128, sizeof(char));
|
||||
fprintf(fp, "Dear %s\r\r", nodes.Sysop);
|
||||
line = calloc(256, sizeof(char));
|
||||
sprintf(temp, "%s/etc/fgroups.data", getenv("MBSE_ROOT"));
|
||||
fprintf(fp, "The following is a list of file groups at %s\r\r", ascfnode(f, 0x1f));
|
||||
|
||||
fi=NULL;
|
||||
fi=OpenMacro("filemgr.group", nodes.Language);
|
||||
if (fi != NULL){
|
||||
while ( (fgets(line, 254, fi) != NULL) && ((line[0]!='@') || (line[1]!='|'))){
|
||||
fprintf( fp, "%s", ParseMacro(line,&res));
|
||||
}
|
||||
fgetpos(fi,&fileptr);
|
||||
}else{
|
||||
fprintf(fp, "Dear %s\r\r", nodes.Sysop);
|
||||
fprintf(fp, "The following is a list of file groups at %s\r\r", ascfnode(f, 0x1f));
|
||||
}
|
||||
if ((gp = fopen(temp, "r")) == NULL) {
|
||||
WriteError("$Can't open %s", temp);
|
||||
free(temp);
|
||||
free(line);
|
||||
return;
|
||||
}
|
||||
fread(&fgrouphdr, sizeof(fgrouphdr), 1, gp);
|
||||
|
||||
|
||||
// 123456789012 1234567890123456789012345678901234567890123456789012345
|
||||
fprintf(fp, "Group Description\r");
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
|
||||
if (fi == NULL){
|
||||
fprintf(fp, "Group Description\r");
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
}
|
||||
while (TRUE) {
|
||||
Group = GetNodeFileGrp(First);
|
||||
if (Group == NULL)
|
||||
@ -138,17 +175,32 @@ void WriteFileGroups(FILE *fp, faddr *f)
|
||||
if ((!strcmp(fgroup.Name, Group)) &&
|
||||
(g->zone == f->zone) && (g->net == f->net) &&
|
||||
(g->node == f->node) && (g->point == f->point)) {
|
||||
fprintf(fp, "%-12s %s\r", fgroup.Name, fgroup.Comment);
|
||||
if (fi !=NULL){
|
||||
MacroVars("gh", "ss", fgroup.Name, fgroup.Comment );
|
||||
fsetpos(fi,&fileptr);
|
||||
while ( (fgets(line, 254, fi) != NULL) && ((line[0]!='@') || (line[1]!='|'))){
|
||||
fprintf( fp, "%s", ParseMacro(line,&res));
|
||||
}
|
||||
}else{
|
||||
fprintf(fp, "%-12s %s\r", fgroup.Name, fgroup.Comment);
|
||||
}
|
||||
Count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
fprintf(fp, "%d group(s)\r\r\r", Count);
|
||||
|
||||
if (fi != NULL){
|
||||
MacroVars("b", "d", Count );
|
||||
while ( fgets(line, 254, fi) != NULL ){
|
||||
fprintf( fp, "%s", ParseMacro(line,&res));
|
||||
}
|
||||
fclose(fi);
|
||||
}else{
|
||||
fprintf(fp, "--------------------------------------------------------------------\r");
|
||||
fprintf(fp, "%d group(s)\r\r\r", Count);
|
||||
}
|
||||
fclose(gp);
|
||||
free(line);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
@ -192,21 +244,26 @@ void CleanBuf(char *Buf)
|
||||
/*
|
||||
* Change AreaMgr and FileMgr password for a node
|
||||
*/
|
||||
void MgrPasswd(faddr *t, char *Buf, FILE *tmp, int Len)
|
||||
void MgrPasswd(faddr *t, char *Buf, FILE *tmp, int Len, int mgr)
|
||||
{
|
||||
ShiftBuf(Buf, Len);
|
||||
CleanBuf(Buf);
|
||||
|
||||
MacroVars("SsP", "sss", CFG.sysop_name, nodes.Sysop, mgr?(char *)"Filemgr":(char *)"Areamgr");
|
||||
if ((strlen(Buf) < 3) || (strlen(Buf) > 15)) {
|
||||
MacroVars("RABCDE", "ssssss",(char *)"ERR_PASS_LEN",(char *)"",(char *)"",(char *)"",(char *)"",(char *)"");
|
||||
if (!MsgResult(mgr?"filemgr.responses":"areamgr.responses",tmp))
|
||||
fprintf(tmp, "A new password must be between 3 and 15 characters in length\n");
|
||||
Syslog('+', "XxxxMgr: Password length %d, not changed", strlen(Buf));
|
||||
return;
|
||||
Syslog('+', "XxxxMgr: Password length %d, not changed", strlen(Buf));
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&nodes.Apasswd, 0, sizeof(nodes.Apasswd));
|
||||
strncpy(nodes.Apasswd, tu(Buf), 15);
|
||||
fprintf(tmp, "AreaMgr and FileMgr password is now \"%s\"\n", nodes.Apasswd);
|
||||
MacroVars("RABCDE", "ssssss",(char *)"OK_PASS",nodes.Apasswd,(char *)"",(char *)"",(char *)"",(char *)"");
|
||||
if (!MsgResult(mgr?"filemgr.responses":"areamgr.responses",tmp))
|
||||
fprintf(tmp, "AreaMgr and FileMgr password is now \"%s\"\n", nodes.Apasswd);
|
||||
Syslog('+', "XxxxMgr: Password \"%s\" for node %s", nodes.Apasswd, ascfnode(t, 0x1f));
|
||||
MacroClear();
|
||||
UpdateNode();
|
||||
SearchNodeFaddr(t);
|
||||
}
|
||||
@ -216,7 +273,7 @@ void MgrPasswd(faddr *t, char *Buf, FILE *tmp, int Len)
|
||||
/*
|
||||
* Change AreaMgr/FileMgr nodify flag for node
|
||||
*/
|
||||
void MgrNotify(faddr *t, char *Buf, FILE *tmp)
|
||||
void MgrNotify(faddr *t, char *Buf, FILE *tmp, int mgr)
|
||||
{
|
||||
/*
|
||||
* First strip leading garbage
|
||||
@ -234,7 +291,11 @@ void MgrNotify(faddr *t, char *Buf, FILE *tmp)
|
||||
UpdateNode();
|
||||
SearchNodeFaddr(t);
|
||||
Syslog('+', "XxxxMgr: Notify %s", GetBool(nodes.Notify));
|
||||
fprintf(tmp, "AreaMgr and FileMgr Notify is %s\n", GetBool(nodes.Notify));
|
||||
MacroVars("SsP", "sss", CFG.sysop_name, nodes.Sysop,mgr?(char *)"Filemgr":(char *)"Areamgr");
|
||||
MacroVars("RABCDE", "ssssss",(char *)"OK_PASS",nodes.Apasswd,(char *)"",(char *)"",(char *)"",(char *)"");
|
||||
if (!MsgResult(mgr?"filemgr.responses":"areamgr.responses",tmp))
|
||||
fprintf(tmp, "AreaMgr and FileMgr Notify is %s\n", GetBool(nodes.Notify));
|
||||
MacroClear();
|
||||
}
|
||||
|
||||
|
||||
@ -368,3 +429,42 @@ int UplinkRequest(faddr *t, int FileMgr, char *cmd)
|
||||
}
|
||||
|
||||
|
||||
void GetRpSubject(const char *report, char* subject)
|
||||
{
|
||||
FILE *fi;
|
||||
char *temp;
|
||||
int res;
|
||||
temp = calloc(256,sizeof(char));
|
||||
if ((fi=OpenMacro(report, nodes.Language))!=NULL){
|
||||
while ( fgets(temp, 254, fi) != NULL )
|
||||
ParseMacro(temp,&res);
|
||||
fclose(fi);
|
||||
}
|
||||
res=diesel("@(getvar,subject)",temp);
|
||||
Syslog('d', "diesel: %d %s", res, temp);
|
||||
if(res==0)
|
||||
sprintf(subject,"%s",temp);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
int MsgResult(const char * report, FILE *fo)
|
||||
{
|
||||
FILE *fi;
|
||||
char *temp;
|
||||
int res;
|
||||
temp = calloc(256,sizeof(char));
|
||||
if ((fi=OpenMacro(report, nodes.Language))!=NULL){
|
||||
while ( fgets(temp, 254, fi) != NULL ){
|
||||
fprintf(fo,"%s",ParseMacro(temp,&res));
|
||||
}
|
||||
fclose(fi);
|
||||
res=1;
|
||||
}else{
|
||||
res=0;
|
||||
}
|
||||
free(temp);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -4,13 +4,16 @@
|
||||
#define _MGRUTIL_H
|
||||
|
||||
|
||||
int MsgResult(const char *, FILE * );
|
||||
void GetRpSubject(const char *, char*);
|
||||
|
||||
void WriteMailGroups(FILE *, faddr *);
|
||||
void WriteFileGroups(FILE *, faddr *);
|
||||
char *GetBool(int);
|
||||
void CleanBuf(char *);
|
||||
void ShiftBuf(char *, int);
|
||||
void MgrPasswd(faddr *, char *, FILE *, int);
|
||||
void MgrNotify(faddr *, char *, FILE *);
|
||||
void MgrPasswd(faddr *, char *, FILE *, int, int);
|
||||
void MgrNotify(faddr *, char *, FILE *, int);
|
||||
int UplinkRequest(faddr *, int, char *);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user