From 77e8402dd68079c0e245fc8826daf2c6ad334766 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 26 Sep 2006 16:58:27 +0000 Subject: r18925: Add current snapshot of the ejs-2.0 code. Tridge, will you be incorporating this? (This used to be commit 917af234a8d517f82bd42256a940608a16b988f4) --- source4/lib/appweb/ejs-2.0/exml/Makefile | 42 ++ source4/lib/appweb/ejs-2.0/exml/exml.h | 94 ++++ source4/lib/appweb/ejs-2.0/exml/exmlParser.c | 752 +++++++++++++++++++++++++++ source4/lib/appweb/ejs-2.0/exml/files | 1 + 4 files changed, 889 insertions(+) create mode 100644 source4/lib/appweb/ejs-2.0/exml/Makefile create mode 100644 source4/lib/appweb/ejs-2.0/exml/exml.h create mode 100644 source4/lib/appweb/ejs-2.0/exml/exmlParser.c create mode 100644 source4/lib/appweb/ejs-2.0/exml/files (limited to 'source4/lib/appweb/ejs-2.0/exml') diff --git a/source4/lib/appweb/ejs-2.0/exml/Makefile b/source4/lib/appweb/ejs-2.0/exml/Makefile new file mode 100644 index 0000000000..663e65ed53 --- /dev/null +++ b/source4/lib/appweb/ejs-2.0/exml/Makefile @@ -0,0 +1,42 @@ +# +# Makefile for Embedded XML (EXML) +# +# Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved. +# + +# +# EXML may be linked into shared handlers so we must build the objects both +# shared and static. +# +COMPILE := *.c +EXPORT_OBJECTS := yes +MAKE_IFLAGS := -I../mpr + +include make.dep + +ifeq ($(BLD_FEATURE_TEST),1) +POST_DIRS := test +endif + +TARGETS += $(BLD_BIN_DIR)/libexml$(BLD_LIB) + +ifeq ($(BLD_FEATURE_XML),1) +compileExtra: $(TARGETS) +endif + +# MOB -- remove when FEATURE_XML is defined +compileExtra: $(TARGETS) + +$(BLD_BIN_DIR)/libexml$(BLD_LIB): $(FILES) + @bld --library $(BLD_BIN_DIR)/libexml \ + --objectsDir $(BLD_OBJ_DIR) --objectList files --libs mpr + +cleanExtra: + @echo "rm -f $(TARGETS)" | $(BLDOUT) + @rm -f $(TARGETS) + @rm -f $(BLD_BIN_DIR)/libexml.* + +## Local variables: +## tab-width: 4 +## End: +## vim: tw=78 sw=4 ts=4 diff --git a/source4/lib/appweb/ejs-2.0/exml/exml.h b/source4/lib/appweb/ejs-2.0/exml/exml.h new file mode 100644 index 0000000000..44c50a56b9 --- /dev/null +++ b/source4/lib/appweb/ejs-2.0/exml/exml.h @@ -0,0 +1,94 @@ +/* + * exml.h -- Embedded Xml Parser header + * + * Copyright (c) Mbedthis Software, LLC, 2003-2003. All Rights Reserved. -- MOB + */ + +#ifndef _h_EXML +#define _h_EXML 1 + +/******************************** Description *********************************/ + +#include "mpr.h" + +/********************************** Defines ***********************************/ + +#if BLD_FEATURE_SQUEEZE + #define EXML_BUFSIZE 512 /* Read buffer size */ +#else + #define EXML_BUFSIZE 1024 /* Read buffer size */ +#endif + +/* + * XML parser states. The states that are passed to the user handler have + * "U" appended to the comment. The error states (ERR and EOF) must be + * negative. + */ +#define EXML_ERR -1 /* Error */ +#define EXML_EOF -2 /* End of input */ +#define EXML_BEGIN 1 /* Before next tag */ +#define EXML_AFTER_LS 2 /* Seen "<" */ +#define EXML_COMMENT 3 /* Seen ""); + if (rc < 0) { + return TOKEN_TOO_BIG; + } else if (rc == 0) { + return TOKEN_ERR; + } + return TOKEN_COMMENT; + } + } + } + trimToken(xp); + return TOKEN_TEXT; + } + if ((c = getNextChar(xp)) < 0) { + return TOKEN_EOF; + } + } + + /* Should never get here */ + mprAssert(0); + return TOKEN_ERR; +} + +/******************************************************************************/ +/* + * Scan for a pattern. Eat and discard input up to the pattern. Return 1 if + * the pattern was found, return 0 if not found. Return < 0 on errors. + */ + +static int scanFor(Exml *xp, char *str) +{ + MprBuf *tokBuf; + char *cp; + int c; + + mprAssert(str); + + tokBuf = xp->tokBuf; + + while (1) { + for (cp = str; *cp; cp++) { + if ((c = getNextChar(xp)) < 0) { + return 0; + } + if (tokBuf) { + if (mprPutCharToBuf(tokBuf, c) < 0) { + return -1; + } + } + if (c != *cp) { + break; + } + } + if (*cp == '\0') { + /* + * Remove the pattern from the tokBuf + */ + if (tokBuf) { + mprAdjustBufEnd(tokBuf, -(int) strlen(str)); + trimToken(xp); + } + return 1; + } + } +} + +/******************************************************************************/ +/* + * Get another character. We read and buffer blocks of data if we need more + * data to parse. + */ + +static int getNextChar(Exml *xp) +{ + MprBuf *inBuf; + char c; + int l; + + inBuf = xp->inBuf; + if (mprGetBufLength(inBuf) <= 0) { + /* + * Flush to reset the servp/endp pointers to the start of the buffer + * so we can do a maximal read + */ + mprFlushBuf(inBuf); + l = (xp->readFn)(xp, xp->inputArg, mprGetBufStart(inBuf), + mprGetBufLinearSpace(inBuf)); + if (l <= 0) { + return -1; + } + mprAdjustBufEnd(inBuf, l); + } + c = mprGetCharFromBuf(inBuf); + + if (c == '\n') { + xp->lineNumber++; + } + return c; +} + +/******************************************************************************/ +/* + * Put back a character in the input buffer + */ + +static int putLastChar(Exml *xp, int c) +{ + if (mprInsertCharToBuf(xp->inBuf, (char) c) < 0) { + mprAssert(0); + return -1; + } + if (c == '\n') { + xp->lineNumber--; + } + return 0; +} + +/******************************************************************************/ +/* + * Output a parse message + */ + +static void error(Exml *xp, char *fmt, ...) +{ + va_list args; + char *buf; + + mprAssert(fmt); + + va_start(args, fmt); + mprAllocVsprintf(MPR_LOC_ARGS(xp), &buf, MPR_MAX_STRING, fmt, args); + va_end(args); + + /* + * MOB need to add the failing line text and a pointer to which column + */ + mprFree(xp->errMsg); + mprAllocSprintf(MPR_LOC_ARGS(xp), &xp->errMsg, MPR_MAX_STRING, + "XML error: %s\nAt line %d\n", buf, xp->lineNumber); + + mprFree(buf); +} + +/******************************************************************************/ +/* + * Remove trailing whitespace in a token and ensure it is terminated with + * a NULL for easy parsing + */ + +static void trimToken(Exml *xp) +{ + while (isspace(mprLookAtLastCharInBuf(xp->tokBuf))) { + mprAdjustBufEnd(xp->tokBuf, -1); + } + mprAddNullToBuf(xp->tokBuf); +} + +/******************************************************************************/ + +const char *exmlGetErrorMsg(Exml *xp) +{ + if (xp->errMsg == 0) { + return ""; + } + return xp->errMsg; +} + +/******************************************************************************/ + +int exmlGetLineNumber(Exml *xp) +{ + return xp->lineNumber; +} + +/******************************************************************************/ +#else + +void exmlParserDummy() {} +#endif /* BLD_FEATURE_EXML */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim:tw=78 + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/source4/lib/appweb/ejs-2.0/exml/files b/source4/lib/appweb/ejs-2.0/exml/files new file mode 100644 index 0000000000..0f10ea44dd --- /dev/null +++ b/source4/lib/appweb/ejs-2.0/exml/files @@ -0,0 +1 @@ +${BLD_OBJ_DIR}/exmlParser${BLD_OBJ} -- cgit