wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
#define BLD_PRODUCT "Samba4"
|
||||
#define BLD_NAME "Samba4 SWAT"
|
||||
#define BLD_VERSION "4"
|
||||
#define BLD_NUMBER "1"
|
||||
#define BLD_TYPE "DEBUG"
|
||||
#define BLD_DEFAULTS "normal"
|
||||
#define BLD_PACKAGES ""
|
||||
#define BLD_APPWEB_CONFIG "normal.conf"
|
||||
#define BLD_APPWEB 0
|
||||
#define BLD_COMPANY "Mbedthis"
|
||||
#define BLD_DEBUG 0
|
||||
#define BLD_DIRS "bootstrap include obj bin mpr ejs esp http doc appWeb appWebSamples images"
|
||||
#define BLD_HTTP_PORT 7777
|
||||
#define BLD_LIB_VERSION "1.0.0"
|
||||
#define BLD_SSL_PORT 4443
|
||||
#define BLD_CLEAN_INSTALL "0"
|
||||
#define BLD_LICENSE "gpl"
|
||||
#define BLD_HOST_SYSTEM "i686-pc-linux-gnu"
|
||||
#define BLD_BUILD_SYSTEM "i686-pc-linux-gnu"
|
||||
#define BLD_HOST_OS "LINUX"
|
||||
#define BLD_HOST_CPU_ARCH MPR_CPU_IX86
|
||||
#define BLD_HOST_CPU "i686"
|
||||
#define BLD_HOST_UNIX 1
|
||||
#define BLD_BUILD_OS "LINUX"
|
||||
#define BLD_BUILD_CPU_ARCH MPR_CPU_IX86
|
||||
#define BLD_BUILD_CPU i686
|
||||
#define BLD_BUILD_UNIX 1
|
||||
#define BLD_ROOT_PREFIX "/"
|
||||
#define BLD_FEATURE_ACCESS_LOG 0
|
||||
#define BLD_FEATURE_ADMIN_MODULE 0
|
||||
#define BLD_FEATURE_ASPNET_MODULE 0
|
||||
#define BLD_FEATURE_ASSERT 1
|
||||
#define BLD_FEATURE_AUTH_MODULE 0
|
||||
#define BLD_FEATURE_C_API_MODULE 1
|
||||
#define BLD_FEATURE_C_API_CLIENT 0
|
||||
#define BLD_FEATURE_CGI_MODULE 0
|
||||
#define BLD_FEATURE_COMPAT_MODULE 0
|
||||
#define BLD_FEATURE_CONFIG_PARSE 0
|
||||
#define BLD_FEATURE_CONFIG_SAVE 0
|
||||
#define BLD_FEATURE_COOKIE 0
|
||||
#define BLD_FEATURE_COPY_MODULE 0
|
||||
#define BLD_FEATURE_DIGEST 0
|
||||
#define BLD_FEATURE_DLL 0
|
||||
#define BLD_FEATURE_EGI_MODULE 0
|
||||
#define BLD_FEATURE_EJS 1
|
||||
#define BLD_FEATURE_ESP_MODULE 1
|
||||
#define BLD_FEATURE_EVAL_PERIOD 30
|
||||
#define BLD_FEATURE_FLOATING_POINT 1
|
||||
#define BLD_FEATURE_IF_MODIFIED 0
|
||||
#define BLD_FEATURE_INT64 1
|
||||
#define BLD_FEATURE_KEEP_ALIVE 0
|
||||
#define BLD_FEATURE_LEGACY_API 0
|
||||
#define BLD_FEATURE_LIB_STDCPP 0
|
||||
#define BLD_FEATURE_LICENSE 0
|
||||
#define BLD_FEATURE_LOG 0
|
||||
#define BLD_FEATURE_MULTITHREAD 0
|
||||
#define BLD_FEATURE_MALLOC 0
|
||||
#define BLD_FEATURE_MALLOC_STATS 0
|
||||
#define BLD_FEATURE_MALLOC_LEAK 0
|
||||
#define BLD_FEATURE_MALLOC_HOOK 0
|
||||
#define BLD_FEATURE_NUM_TYPE int64_t
|
||||
#define BLD_FEATURE_NUM_TYPE_ID MPR_TYPE_INT64
|
||||
#define BLD_FEATURE_ROMFS 0
|
||||
#define BLD_FEATURE_RUN_AS_SERVICE 0
|
||||
#define BLD_FEATURE_SAFE_STRINGS 0
|
||||
#define BLD_FEATURE_SAMPLES 0
|
||||
#define BLD_FEATURE_SESSION 1
|
||||
#define BLD_FEATURE_SHARED 0
|
||||
#define BLD_FEATURE_SQUEEZE 0
|
||||
#define BLD_FEATURE_SSL_MODULE 0
|
||||
#define BLD_FEATURE_STATIC 1
|
||||
#define BLD_FEATURE_STATIC_LINK_LIBC 0
|
||||
#define BLD_FEATURE_TEST 0
|
||||
#define BLD_FEATURE_UPLOAD_MODULE 0
|
||||
#define BLD_FEATURE_XDB_MODULE 0
|
||||
#define BLD_FEATURE_ADMIN_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_ASPNET_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_AUTH_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_C_API_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_CGI_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_COMPAT_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_COPY_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_EGI_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_ESP_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_SSL_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_UPLOAD_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_XDB_MODULE_BUILTIN 0
|
||||
#define BLD_FEATURE_ADMIN_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_ASPNET_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_AUTH_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_C_API_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_CGI_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_COMPAT_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_COPY_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_EGI_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_ESP_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_SSL_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_UPLOAD_MODULE_LOADABLE 0
|
||||
#define BLD_FEATURE_XDB_MODULE_LOADABLE 0
|
||||
#define BLD_AR_FOR_BUILD "ar"
|
||||
#define BLD_CC_FOR_BUILD "cc"
|
||||
#define BLD_CSC_FOR_BUILD ""
|
||||
#define BLD_JAVAC_FOR_BUILD ""
|
||||
#define BLD_LD_FOR_BUILD "ld"
|
||||
#define BLD_RANLIB_FOR_BUILD ""
|
||||
#define BLD_NM_FOR_BUILD "nm"
|
||||
#define BLD_CFLAGS_FOR_BUILD ""
|
||||
#define BLD_IFLAGS_FOR_BUILD ""
|
||||
#define BLD_LDFLAGS_FOR_BUILD ""
|
||||
#define BLD_ARCHIVE_FOR_BUILD ".a"
|
||||
#define BLD_EXE_FOR_BUILD ""
|
||||
#define BLD_OBJ_FOR_BUILD ".o"
|
||||
#define BLD_PIOBJ_FOR_BUILD ".lo"
|
||||
#define BLD_CLASS_FOR_BUILD ".class"
|
||||
#define BLD_SHLIB_FOR_BUILD ""
|
||||
#define BLD_SHOBJ_FOR_BUILD ".so"
|
||||
#define BLD_AR_FOR_HOST "ar"
|
||||
#define BLD_CC_FOR_HOST "cc"
|
||||
#define BLD_CSC_FOR_HOST "csc"
|
||||
#define BLD_JAVAC_FOR_HOST "javac"
|
||||
#define BLD_LD_FOR_HOST "ld"
|
||||
#define BLD_RANLIB_FOR_HOST "true"
|
||||
#define BLD_NM_FOR_HOST "nm"
|
||||
#define BLD_CFLAGS_FOR_HOST ""
|
||||
#define BLD_IFLAGS_FOR_HOST ""
|
||||
#define BLD_LDFLAGS_FOR_HOST ""
|
||||
#define BLD_ARCHIVE_FOR_HOST ".a"
|
||||
#define BLD_EXE_FOR_HOST ""
|
||||
#define BLD_OBJ_FOR_HOST ".o"
|
||||
#define BLD_PIOBJ_FOR_HOST ".lo"
|
||||
#define BLD_CLASS_FOR_HOST ".class"
|
||||
#define BLD_SHLIB_FOR_HOST ""
|
||||
#define BLD_SHOBJ_FOR_HOST ".so"
|
||||
#define BLD_TOOLS_DIR "${BLD_TOP}/bin"
|
||||
#define BLD_BIN_DIR "${BLD_TOP}/bin"
|
||||
#define BLD_INC_DIR "/usr/include/${BLD_PRODUCT}"
|
||||
#define BLD_EXP_OBJ_DIR "${BLD_TOP}/obj"
|
||||
|
||||
#ifndef MAX_FLOAT
|
||||
#define MAX_FLOAT 3.40282347e+38F
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* @file ejs.h
|
||||
* @brief Primary Embedded Javascript (ECMAScript) header.
|
||||
* @overview This Embedded Javascript (EJS) header defines the
|
||||
* public API. This API should only be used by those directly
|
||||
* using EJS without using Embedded Server Pages (ESP). ESP
|
||||
* wraps all relevant APIs to expose a single consistent API.
|
||||
* \n\n
|
||||
* This API requires the mpr/var.h facilities to create and
|
||||
* manage objects and properties.
|
||||
*/
|
||||
/********************************* Copyright **********************************/
|
||||
/*
|
||||
* @copy default.g
|
||||
*
|
||||
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
|
||||
* Portions Copyright (c) GoAhead Software, 1995-2000. All Rights Reserved.
|
||||
*
|
||||
* This software is distributed under commercial and open source licenses.
|
||||
* You may use the GPL open source license described below or you may acquire
|
||||
* a commercial license from Mbedthis Software. You agree to be fully bound
|
||||
* by the terms of either license. Consult the LICENSE.TXT distributed with
|
||||
* this software for full details.
|
||||
*
|
||||
* This software is open source; 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 of the License, or (at your
|
||||
* option) any later version. See the GNU General Public License for more
|
||||
* details at: http://www.mbedthis.com/downloads/gplLicense.html
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* This GPL license does NOT permit incorporating this software into
|
||||
* proprietary programs. If you are unable to comply with the GPL, you must
|
||||
* acquire a commercial license to use this software. Commercial licenses
|
||||
* for this software and support services are available from Mbedthis
|
||||
* Software at http://www.mbedthis.com
|
||||
*
|
||||
* @end
|
||||
*/
|
||||
/********************************** Includes **********************************/
|
||||
|
||||
#ifndef _h_EJS
|
||||
#define _h_EJS 1
|
||||
|
||||
#include "lib/appweb/mpr/miniMpr.h"
|
||||
#include "lib/appweb/mpr/var.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/********************************* Prototypes *********************************/
|
||||
|
||||
typedef MprVarHandle EjsId;
|
||||
typedef MprVarHandle EjsHandle;
|
||||
|
||||
/*
|
||||
* Multithreaded lock routines
|
||||
*/
|
||||
typedef void (*EjsLock)(void *lockData);
|
||||
typedef void (*EjsUnlock)(void *lockData);
|
||||
|
||||
/********************************* Prototypes *********************************/
|
||||
/*
|
||||
* Module management
|
||||
*/
|
||||
extern int ejsOpen(EjsLock lock, EjsUnlock unlock, void *lockData);
|
||||
extern void ejsClose(void);
|
||||
extern EjsId ejsOpenEngine(EjsHandle primaryHandle, EjsHandle altHandle);
|
||||
extern void ejsCloseEngine(EjsId eid);
|
||||
|
||||
void *ejs_save_state(void);
|
||||
void ejs_restore_state(void *ptr);
|
||||
|
||||
/*
|
||||
* Evaluation functions
|
||||
*/
|
||||
extern int ejsEvalFile(EjsId eid, char *path, MprVar *result, char **emsg);
|
||||
extern int ejsEvalScript(EjsId eid, char *script, MprVar *result,
|
||||
char **emsg);
|
||||
extern int ejsRunFunction(int eid, MprVar *obj, const char *functionName,
|
||||
MprArray *args);
|
||||
|
||||
/*
|
||||
* Composite variable get / set routines. Can also use the MPR property
|
||||
* routines on an object variable.
|
||||
*/
|
||||
extern MprVar ejsCreateObj(const char *name, int hashSize);
|
||||
extern MprVar ejsCreateArray(const char *name, int hashSize);
|
||||
extern bool ejsDestroyVar(MprVar *obj);
|
||||
extern int ejsCopyVar(EjsId eid, const char *var, MprVar *value,
|
||||
bool copyRef);
|
||||
extern int ejsReadVar(EjsId eid, const char *var, MprVar *value);
|
||||
extern int ejsWriteVar(EjsId eid, const char *var, MprVar *value);
|
||||
extern int ejsWriteVarValue(EjsId eid, const char *var, MprVar value);
|
||||
extern int ejsDeleteVar(EjsId eid, const char *var);
|
||||
|
||||
extern MprVar *ejsGetLocalObject(EjsId eid);
|
||||
extern MprVar *ejsGetGlobalObject(EjsId eid);
|
||||
|
||||
/*
|
||||
* Function routines
|
||||
*/
|
||||
extern void ejsDefineFunction(EjsId eid, const char *functionName,
|
||||
char *args, char *body);
|
||||
extern void ejsDefineCFunction(EjsId eid, const char *functionName,
|
||||
MprCFunction fn, void *thisPtr, int flags);
|
||||
extern void ejsDefineStringCFunction(EjsId eid, const char *functionName,
|
||||
MprStringCFunction fn, void *thisPtr, int flags);
|
||||
extern void *ejsGetThisPtr(EjsId eid);
|
||||
extern MprVar *ejsGetReturnValue(EjsId eid);
|
||||
extern int ejsGetLineNumber(EjsId eid);
|
||||
extern int ejsParseArgs(int argc, char **argv, char *fmt, ...);
|
||||
extern void ejsSetErrorMsg(EjsId eid, const char* fmt, ...)
|
||||
PRINTF_ATTRIBUTE(2,3);
|
||||
extern void ejsSetReturnValue(EjsId eid, MprVar value);
|
||||
extern void ejsSetReturnString(EjsId eid, const char *str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _h_EJS */
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* @file ejsInternal.h
|
||||
* @brief Private header for Embedded Javascript (ECMAScript)
|
||||
* @overview This Embedded Javascript header defines the private Embedded
|
||||
* Javascript internal structures.
|
||||
*/
|
||||
/********************************* Copyright **********************************/
|
||||
/*
|
||||
* @copy default.g
|
||||
*
|
||||
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
|
||||
* Portions Copyright (c) GoAhead Software, 1995-2000. All Rights Reserved.
|
||||
*
|
||||
* This software is distributed under commercial and open source licenses.
|
||||
* You may use the GPL open source license described below or you may acquire
|
||||
* a commercial license from Mbedthis Software. You agree to be fully bound
|
||||
* by the terms of either license. Consult the LICENSE.TXT distributed with
|
||||
* this software for full details.
|
||||
*
|
||||
* This software is open source; 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 of the License, or (at your
|
||||
* option) any later version. See the GNU General Public License for more
|
||||
* details at: http://www.mbedthis.com/downloads/gplLicense.html
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* This GPL license does NOT permit incorporating this software into
|
||||
* proprietary programs. If you are unable to comply with the GPL, you must
|
||||
* acquire a commercial license to use this software. Commercial licenses
|
||||
* for this software and support services are available from Mbedthis
|
||||
* Software at http://www.mbedthis.com
|
||||
*
|
||||
* @end
|
||||
*/
|
||||
/********************************* Includes ***********************************/
|
||||
|
||||
#ifndef _h_EJS_INTERNAL
|
||||
#define _h_EJS_INTERNAL 1
|
||||
|
||||
#include "ejs.h"
|
||||
|
||||
/********************************** Defines ***********************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
#if BLD_FEATURE_SQUEEZE
|
||||
#define EJS_PARSE_INCR 256 /* Growth factor */
|
||||
#define EJS_MAX_RECURSE 25 /* Sanity for maximum recursion */
|
||||
#define EJS_MAX_ID 128 /* Maximum ID length */
|
||||
#define EJS_OBJ_HASH_SIZE 13 /* Object hash table size */
|
||||
#define EJS_SMALL_OBJ_HASH_SIZE 11 /* Small object hash size */
|
||||
#define EJS_LIST_INCR 8 /* Growth increment for lists */
|
||||
#else
|
||||
#define EJS_PARSE_INCR 1024 /* Growth factor */
|
||||
#define EJS_MAX_RECURSE 100 /* Sanity for maximum recursion */
|
||||
#define EJS_MAX_ID 256 /* Maximum ID length */
|
||||
#define EJS_OBJ_HASH_SIZE 29 /* Object hash table size */
|
||||
#define EJS_SMALL_OBJ_HASH_SIZE 11 /* Small object hash size */
|
||||
#define EJS_LIST_INCR 16 /* Growth increment for lists */
|
||||
#endif
|
||||
#define EJS_TOKEN_STACK 4 /* Put back token stack */
|
||||
|
||||
/*
|
||||
* Lexical analyser tokens
|
||||
*/
|
||||
#define EJS_TOK_ERR -1 /* Any error */
|
||||
#define EJS_TOK_LPAREN 1 /* ( */
|
||||
#define EJS_TOK_RPAREN 2 /* ) */
|
||||
#define EJS_TOK_IF 3 /* if */
|
||||
#define EJS_TOK_ELSE 4 /* else */
|
||||
#define EJS_TOK_LBRACE 5 /* { */
|
||||
#define EJS_TOK_RBRACE 6 /* } */
|
||||
#define EJS_TOK_LOGICAL 7 /* ||, &&, ! */
|
||||
#define EJS_TOK_EXPR 8 /* +, -, /, % */
|
||||
#define EJS_TOK_SEMI 9 /* ; */
|
||||
#define EJS_TOK_LITERAL 10 /* literal string */
|
||||
#define EJS_TOK_FUNCTION_NAME 11 /* functionName */
|
||||
#define EJS_TOK_NEWLINE 12 /* newline white space */
|
||||
#define EJS_TOK_ID 13 /* Identifier */
|
||||
#define EJS_TOK_EOF 14 /* End of script */
|
||||
#define EJS_TOK_COMMA 15 /* Comma */
|
||||
#define EJS_TOK_VAR 16 /* var */
|
||||
#define EJS_TOK_ASSIGNMENT 17 /* = */
|
||||
#define EJS_TOK_FOR 18 /* for */
|
||||
#define EJS_TOK_INC_DEC 19 /* ++, -- */
|
||||
#define EJS_TOK_RETURN 20 /* return */
|
||||
#define EJS_TOK_PERIOD 21 /* . */
|
||||
#define EJS_TOK_LBRACKET 22 /* [ */
|
||||
#define EJS_TOK_RBRACKET 23 /* ] */
|
||||
#define EJS_TOK_NEW 24 /* new */
|
||||
#define EJS_TOK_DELETE 25 /* delete */
|
||||
#define EJS_TOK_IN 26 /* in */
|
||||
#define EJS_TOK_FUNCTION 27 /* function */
|
||||
#define EJS_TOK_NUMBER 28 /* Number */
|
||||
|
||||
/*
|
||||
* Expression operators
|
||||
*/
|
||||
#define EJS_EXPR_LESS 1 /* < */
|
||||
#define EJS_EXPR_LESSEQ 2 /* <= */
|
||||
#define EJS_EXPR_GREATER 3 /* > */
|
||||
#define EJS_EXPR_GREATEREQ 4 /* >= */
|
||||
#define EJS_EXPR_EQ 5 /* == */
|
||||
#define EJS_EXPR_NOTEQ 6 /* != */
|
||||
#define EJS_EXPR_PLUS 7 /* + */
|
||||
#define EJS_EXPR_MINUS 8 /* - */
|
||||
#define EJS_EXPR_DIV 9 /* / */
|
||||
#define EJS_EXPR_MOD 10 /* % */
|
||||
#define EJS_EXPR_LSHIFT 11 /* << */
|
||||
#define EJS_EXPR_RSHIFT 12 /* >> */
|
||||
#define EJS_EXPR_MUL 13 /* * */
|
||||
#define EJS_EXPR_ASSIGNMENT 14 /* = */
|
||||
#define EJS_EXPR_INC 15 /* ++ */
|
||||
#define EJS_EXPR_DEC 16 /* -- */
|
||||
#define EJS_EXPR_BOOL_COMP 17 /* ! */
|
||||
|
||||
/*
|
||||
* Conditional operators
|
||||
*/
|
||||
#define EJS_COND_AND 1 /* && */
|
||||
#define EJS_COND_OR 2 /* || */
|
||||
#define EJS_COND_NOT 3 /* ! */
|
||||
|
||||
/*
|
||||
* States
|
||||
*/
|
||||
#define EJS_STATE_ERR -1 /* Error state */
|
||||
#define EJS_STATE_EOF 1 /* End of file */
|
||||
#define EJS_STATE_COND 2 /* Parsing a "(conditional)" stmt */
|
||||
#define EJS_STATE_COND_DONE 3
|
||||
#define EJS_STATE_RELEXP 4 /* Parsing a relational expr */
|
||||
#define EJS_STATE_RELEXP_DONE 5
|
||||
#define EJS_STATE_EXPR 6 /* Parsing an expression */
|
||||
#define EJS_STATE_EXPR_DONE 7
|
||||
#define EJS_STATE_STMT 8 /* Parsing General statement */
|
||||
#define EJS_STATE_STMT_DONE 9
|
||||
#define EJS_STATE_STMT_BLOCK_DONE 10 /* End of block "}" */
|
||||
#define EJS_STATE_ARG_LIST 11 /* Function arg list */
|
||||
#define EJS_STATE_ARG_LIST_DONE 12
|
||||
#define EJS_STATE_DEC_LIST 16 /* Declaration list */
|
||||
#define EJS_STATE_DEC_LIST_DONE 17
|
||||
#define EJS_STATE_DEC 18 /* Declaration statement */
|
||||
#define EJS_STATE_DEC_DONE 19
|
||||
#define EJS_STATE_RET 20 /* Return statement */
|
||||
|
||||
#define EJS_STATE_BEGIN EJS_STATE_STMT
|
||||
|
||||
/*
|
||||
* General parsing flags.
|
||||
*/
|
||||
#define EJS_FLAGS_EXE 0x1 /* Execute statements */
|
||||
#define EJS_FLAGS_LOCAL 0x2 /* Get local vars only */
|
||||
#define EJS_FLAGS_GLOBAL 0x4 /* Get global vars only */
|
||||
#define EJS_FLAGS_CREATE 0x8 /* Create var */
|
||||
#define EJS_FLAGS_ASSIGNMENT 0x10 /* In assignment stmt */
|
||||
#define EJS_FLAGS_DELETE 0x20 /* Deleting a variable */
|
||||
#define EJS_FLAGS_FOREACH 0x40 /* In foreach */
|
||||
#define EJS_FLAGS_NEW 0x80 /* In a new stmt() */
|
||||
#define EJS_FLAGS_EXIT 0x100 /* Must exit */
|
||||
|
||||
/*
|
||||
* Putback token
|
||||
*/
|
||||
|
||||
typedef struct EjsToken {
|
||||
char *token; /* Token string */
|
||||
int id; /* Token ID */
|
||||
} EjsToken;
|
||||
|
||||
/*
|
||||
* EJ evaluation block structure
|
||||
*/
|
||||
typedef struct ejEval {
|
||||
EjsToken putBack[EJS_TOKEN_STACK]; /* Put back token stack */
|
||||
int putBackIndex; /* Top of stack index */
|
||||
MprStr line; /* Current line */
|
||||
int lineLength; /* Current line length */
|
||||
int lineNumber; /* Parse line number */
|
||||
int lineColumn; /* Column in line */
|
||||
MprStr script; /* Input script for parsing */
|
||||
char *scriptServp; /* Next token in the script */
|
||||
int scriptSize; /* Length of script */
|
||||
MprStr tokbuf; /* Current token */
|
||||
char *tokEndp; /* Pointer past end of token */
|
||||
char *tokServp; /* Pointer to next token char */
|
||||
int tokSize; /* Size of token buffer */
|
||||
struct ejEval *next; /* used for backtraces */
|
||||
const char *procName; /* gives name in backtrace */
|
||||
} EjsInput;
|
||||
|
||||
/*
|
||||
* Function call structure
|
||||
*/
|
||||
typedef struct {
|
||||
MprArray *args; /* Args for function */
|
||||
MprVar *fn; /* Function definition */
|
||||
char *procName; /* Function name */
|
||||
} EjsProc;
|
||||
|
||||
/*
|
||||
* Per EJS structure
|
||||
*/
|
||||
typedef struct ej {
|
||||
EjsHandle altHandle; /* alternate callback handle */
|
||||
MprVar *currentObj; /* Ptr to current object */
|
||||
MprVar *currentProperty; /* Ptr to current property */
|
||||
EjsId eid; /* Halloc handle */
|
||||
char *error; /* Error message */
|
||||
int exitStatus; /* Status to exit() */
|
||||
int flags; /* Flags */
|
||||
MprArray *frames; /* List of variable frames */
|
||||
MprVar *global; /* Global object */
|
||||
EjsInput *input; /* Input evaluation block */
|
||||
MprVar *local; /* Local object */
|
||||
EjsHandle primaryHandle; /* primary callback handle */
|
||||
EjsProc *proc; /* Current function */
|
||||
MprVar result; /* Variable result */
|
||||
void *thisPtr; /* C++ ptr for functions */
|
||||
int tid; /* Current token id */
|
||||
char *token; /* Pointer to token string */
|
||||
MprVar tokenNumber; /* Parsed number */
|
||||
} Ejs;
|
||||
|
||||
typedef int EjsBlock; /* Scope block id */
|
||||
|
||||
/*
|
||||
* Function callback when using Alternate handles.
|
||||
*/
|
||||
typedef int (*EjsAltStringCFunction)(EjsHandle userHandle, EjsHandle altHandle,
|
||||
int argc, char **argv);
|
||||
typedef int (*EjsAltCFunction)(EjsHandle userHandle, EjsHandle altHandle,
|
||||
int argc, MprVar **argv);
|
||||
|
||||
/******************************** Prototypes **********************************/
|
||||
/*
|
||||
* Ejs Lex
|
||||
*/
|
||||
extern int ejsLexOpenScript(Ejs* ep, char *script);
|
||||
extern void ejsLexCloseScript(Ejs* ep);
|
||||
extern int ejsInitInputState(EjsInput *ip);
|
||||
extern void ejsLexSaveInputState(Ejs* ep, EjsInput* state);
|
||||
extern void ejsLexFreeInputState(Ejs* ep, EjsInput* state);
|
||||
extern void ejsLexRestoreInputState(Ejs* ep, EjsInput* state);
|
||||
extern int ejsLexGetToken(Ejs* ep, int state);
|
||||
extern void ejsLexPutbackToken(Ejs* ep, int tid, char *string);
|
||||
|
||||
/*
|
||||
* Parsing
|
||||
*/
|
||||
extern MprVar *ejsFindObj(Ejs *ep, int state, const char *property,
|
||||
int flags);
|
||||
extern MprVar *ejsFindProperty(Ejs *ep, int state, MprVar *obj,
|
||||
char *property, int flags);
|
||||
extern int ejsGetVarCore(Ejs *ep, const char *var, MprVar **obj,
|
||||
MprVar **varValue, int flags);
|
||||
extern int ejsParse(Ejs *ep, int state, int flags);
|
||||
extern Ejs *ejsPtr(EjsId eid);
|
||||
extern void ejsSetExitStatus(int eid, int status);
|
||||
extern void ejsSetFlags(int orFlags, int andFlags);
|
||||
|
||||
/*
|
||||
* Create variable scope blocks
|
||||
*/
|
||||
extern EjsBlock ejsOpenBlock(EjsId eid);
|
||||
extern int ejsCloseBlock(EjsId eid, EjsBlock vid);
|
||||
extern int ejsEvalBlock(EjsId eid, char *script, MprVar *v, char **err);
|
||||
extern int ejsDefineStandardProperties(MprVar *objVar);
|
||||
|
||||
/*
|
||||
* Error handling
|
||||
*/
|
||||
extern void ejsError(Ejs *ep, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _h_EJS_INTERNAL */
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
@@ -0,0 +1,923 @@
|
||||
/*
|
||||
* @file ejsLex.c
|
||||
* @brief EJS Lexical Analyser
|
||||
* @overview EJS lexical analyser. This implementes a lexical analyser
|
||||
* for a subset of the JavaScript language.
|
||||
*/
|
||||
/********************************* Copyright **********************************/
|
||||
/*
|
||||
* @copy default.g
|
||||
*
|
||||
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
|
||||
* Portions Copyright (c) GoAhead Software, 1995-2000. All Rights Reserved.
|
||||
*
|
||||
* This software is distributed under commercial and open source licenses.
|
||||
* You may use the GPL open source license described below or you may acquire
|
||||
* a commercial license from Mbedthis Software. You agree to be fully bound
|
||||
* by the terms of either license. Consult the LICENSE.TXT distributed with
|
||||
* this software for full details.
|
||||
*
|
||||
* This software is open source; 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 of the License, or (at your
|
||||
* option) any later version. See the GNU General Public License for more
|
||||
* details at: http://www.mbedthis.com/downloads/gplLicense.html
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* This GPL license does NOT permit incorporating this software into
|
||||
* proprietary programs. If you are unable to comply with the GPL, you must
|
||||
* acquire a commercial license to use this software. Commercial licenses
|
||||
* for this software and support services are available from Mbedthis
|
||||
* Software at http://www.mbedthis.com
|
||||
*
|
||||
* @end
|
||||
*/
|
||||
/********************************** Includes **********************************/
|
||||
|
||||
#include "ejsInternal.h"
|
||||
|
||||
#if BLD_FEATURE_EJS
|
||||
|
||||
/****************************** Forward Declarations **************************/
|
||||
|
||||
static int getLexicalToken(Ejs *ep, int state);
|
||||
static int tokenAddChar(Ejs *ep, int c);
|
||||
static int inputGetc(Ejs *ep);
|
||||
static void inputPutback(Ejs *ep, int c);
|
||||
static int charConvert(Ejs *ep, int base, int maxDig);
|
||||
|
||||
/************************************* Code ***********************************/
|
||||
/*
|
||||
* Open a new input script
|
||||
*/
|
||||
|
||||
int ejsLexOpenScript(Ejs *ep, char *script)
|
||||
{
|
||||
EjsInput *ip;
|
||||
|
||||
mprAssert(ep);
|
||||
mprAssert(script);
|
||||
|
||||
if ((ip = mprMalloc(sizeof(EjsInput))) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memset(ip, 0, sizeof(*ip));
|
||||
ip->next = ep->input;
|
||||
ep->input = ip;
|
||||
ip->procName = ep->proc?ep->proc->procName:NULL;
|
||||
|
||||
/*
|
||||
* Create the parse token buffer and script buffer
|
||||
*/
|
||||
ip->tokbuf = mprMalloc(EJS_PARSE_INCR);
|
||||
ip->tokSize = EJS_PARSE_INCR;
|
||||
ip->tokServp = ip->tokbuf;
|
||||
ip->tokEndp = ip->tokbuf;
|
||||
|
||||
ip->script = mprStrdup(script);
|
||||
ip->scriptSize = strlen(script);
|
||||
ip->scriptServp = ip->script;
|
||||
|
||||
ip->lineNumber = 1;
|
||||
ip->lineLength = 0;
|
||||
ip->lineColumn = 0;
|
||||
ip->line = NULL;
|
||||
|
||||
ip->putBackIndex = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Close the input script
|
||||
*/
|
||||
|
||||
void ejsLexCloseScript(Ejs *ep)
|
||||
{
|
||||
EjsInput *ip;
|
||||
int i;
|
||||
|
||||
mprAssert(ep);
|
||||
|
||||
ip = ep->input;
|
||||
mprAssert(ip);
|
||||
ep->input = ip->next;
|
||||
|
||||
for (i = 0; i < EJS_TOKEN_STACK; i++) {
|
||||
mprFree(ip->putBack[i].token);
|
||||
ip->putBack[i].token = 0;
|
||||
}
|
||||
|
||||
mprFree(ip->line);
|
||||
mprFree(ip->tokbuf);
|
||||
mprFree(ip->script);
|
||||
|
||||
mprFree(ip);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Initialize an input state structure
|
||||
*/
|
||||
|
||||
int ejsInitInputState(EjsInput *ip)
|
||||
{
|
||||
mprAssert(ip);
|
||||
|
||||
memset(ip, 0, sizeof(*ip));
|
||||
ip->putBackIndex = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Save the input state
|
||||
*/
|
||||
|
||||
void ejsLexSaveInputState(Ejs *ep, EjsInput *state)
|
||||
{
|
||||
EjsInput *ip;
|
||||
int i;
|
||||
|
||||
mprAssert(ep);
|
||||
|
||||
ip = ep->input;
|
||||
mprAssert(ip);
|
||||
|
||||
*state = *ip;
|
||||
|
||||
for (i = 0; i < ip->putBackIndex; i++) {
|
||||
state->putBack[i].token = mprStrdup(ip->putBack[i].token);
|
||||
state->putBack[i].id = ip->putBack[i].id;
|
||||
}
|
||||
for (; i < EJS_TOKEN_STACK; i++) {
|
||||
state->putBack[i].token = 0;
|
||||
}
|
||||
|
||||
state->line = mprMalloc(ip->lineLength);
|
||||
mprStrcpy(state->line, ip->lineLength, ip->line);
|
||||
|
||||
state->lineColumn = ip->lineColumn;
|
||||
state->lineNumber = ip->lineNumber;
|
||||
state->lineLength = ip->lineLength;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Restore the input state
|
||||
*/
|
||||
|
||||
void ejsLexRestoreInputState(Ejs *ep, EjsInput *state)
|
||||
{
|
||||
EjsInput *ip;
|
||||
int i;
|
||||
|
||||
mprAssert(ep);
|
||||
mprAssert(state);
|
||||
|
||||
ip = ep->input;
|
||||
mprAssert(ip);
|
||||
|
||||
ip->tokbuf = state->tokbuf;
|
||||
ip->tokServp = state->tokServp;
|
||||
ip->tokEndp = state->tokEndp;
|
||||
ip->tokSize = state->tokSize;
|
||||
|
||||
ip->script = state->script;
|
||||
ip->scriptServp = state->scriptServp;
|
||||
ip->scriptSize = state->scriptSize;
|
||||
|
||||
ip->putBackIndex = state->putBackIndex;
|
||||
for (i = 0; i < ip->putBackIndex; i++) {
|
||||
mprFree(ip->putBack[i].token);
|
||||
ip->putBack[i].id = state->putBack[i].id;
|
||||
ip->putBack[i].token = mprStrdup(state->putBack[i].token);
|
||||
}
|
||||
|
||||
mprFree(ip->line);
|
||||
ip->line = mprMalloc(state->lineLength);
|
||||
mprStrcpy(ip->line, state->lineLength, state->line);
|
||||
|
||||
ip->lineColumn = state->lineColumn;
|
||||
ip->lineNumber = state->lineNumber;
|
||||
ip->lineLength = state->lineLength;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Free a saved input state
|
||||
*/
|
||||
|
||||
void ejsLexFreeInputState(Ejs *ep, EjsInput *state)
|
||||
{
|
||||
int i;
|
||||
|
||||
mprAssert(ep);
|
||||
mprAssert(state);
|
||||
|
||||
for (i = 0; i < EJS_TOKEN_STACK; i++) {
|
||||
mprFree(state->putBack[i].token);
|
||||
}
|
||||
state->putBackIndex = -1;
|
||||
mprFree(state->line);
|
||||
state->lineLength = 0;
|
||||
state->lineColumn = 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Get the next EJS token
|
||||
*/
|
||||
|
||||
int ejsLexGetToken(Ejs *ep, int state)
|
||||
{
|
||||
mprAssert(ep);
|
||||
|
||||
ep->tid = getLexicalToken(ep, state);
|
||||
return ep->tid;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/*
|
||||
* Check for reserved words "if", "else", "var", "for", "foreach",
|
||||
* "delete", "function", and "return". "new", "in" and "function"
|
||||
* done below. "true", "false", "null", "undefined" are handled
|
||||
* as global objects.
|
||||
*
|
||||
* Other reserved words not supported:
|
||||
* "break", "case", "catch", "continue", "default", "do",
|
||||
* "finally", "instanceof", "switch", "this", "throw", "try",
|
||||
* "typeof", "while", "with"
|
||||
*
|
||||
* ECMA extensions reserved words (not supported):
|
||||
* "abstract", "boolean", "byte", "char", "class", "const",
|
||||
* "debugger", "double", "enum", "export", "extends",
|
||||
* "final", "float", "goto", "implements", "import", "int",
|
||||
* "interface", "long", "native", "package", "private",
|
||||
* "protected", "public", "short", "static", "super",
|
||||
* "synchronized", "throws", "transient", "volatile"
|
||||
*/
|
||||
|
||||
static int checkReservedWord(Ejs *ep, int state, int c, int tid)
|
||||
{
|
||||
if (state == EJS_STATE_STMT) {
|
||||
if (strcmp(ep->token, "if") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_IF;
|
||||
} else if (strcmp(ep->token, "else") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_ELSE;
|
||||
} else if (strcmp(ep->token, "var") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_VAR;
|
||||
} else if (strcmp(ep->token, "for") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_FOR;
|
||||
} else if (strcmp(ep->token, "delete") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_DELETE;
|
||||
} else if (strcmp(ep->token, "function") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_FUNCTION;
|
||||
} else if (strcmp(ep->token, "return") == 0) {
|
||||
if ((c == ';') || (c == '(')) {
|
||||
inputPutback(ep, c);
|
||||
}
|
||||
return EJS_TOK_RETURN;
|
||||
}
|
||||
} else if (state == EJS_STATE_EXPR) {
|
||||
if (strcmp(ep->token, "new") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_NEW;
|
||||
} else if (strcmp(ep->token, "in") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_IN;
|
||||
} else if (strcmp(ep->token, "function") == 0) {
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_FUNCTION;
|
||||
}
|
||||
}
|
||||
return tid;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Get the next EJS token
|
||||
*/
|
||||
|
||||
static int getLexicalToken(Ejs *ep, int state)
|
||||
{
|
||||
MprType type;
|
||||
EjsInput *ip;
|
||||
int done, tid, c, quote, style, idx;
|
||||
|
||||
mprAssert(ep);
|
||||
ip = ep->input;
|
||||
mprAssert(ip);
|
||||
|
||||
ep->tid = -1;
|
||||
tid = -1;
|
||||
type = BLD_FEATURE_NUM_TYPE_ID;
|
||||
|
||||
/*
|
||||
* Use a putback tokens first. Don't free strings as caller needs access.
|
||||
*/
|
||||
if (ip->putBackIndex >= 0) {
|
||||
idx = ip->putBackIndex;
|
||||
tid = ip->putBack[idx].id;
|
||||
ep->token = (char*) ip->putBack[idx].token;
|
||||
tid = checkReservedWord(ep, state, 0, tid);
|
||||
ip->putBackIndex--;
|
||||
return tid;
|
||||
}
|
||||
ep->token = ip->tokServp = ip->tokEndp = ip->tokbuf;
|
||||
*ip->tokServp = '\0';
|
||||
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
return EJS_TOK_EOF;
|
||||
}
|
||||
|
||||
/*
|
||||
* Main lexical analyser
|
||||
*/
|
||||
for (done = 0; !done; ) {
|
||||
switch (c) {
|
||||
case -1:
|
||||
return EJS_TOK_EOF;
|
||||
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\r':
|
||||
do {
|
||||
if ((c = inputGetc(ep)) < 0)
|
||||
break;
|
||||
} while (c == ' ' || c == '\t' || c == '\r');
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
return EJS_TOK_NEWLINE;
|
||||
|
||||
case '(':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_LPAREN;
|
||||
|
||||
case ')':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_RPAREN;
|
||||
|
||||
case '[':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_LBRACKET;
|
||||
|
||||
case ']':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_RBRACKET;
|
||||
|
||||
case '.':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_PERIOD;
|
||||
|
||||
case '{':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_LBRACE;
|
||||
|
||||
case '}':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_RBRACE;
|
||||
|
||||
case '+':
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c != '+' ) {
|
||||
inputPutback(ep, c);
|
||||
tokenAddChar(ep, EJS_EXPR_PLUS);
|
||||
return EJS_TOK_EXPR;
|
||||
}
|
||||
tokenAddChar(ep, EJS_EXPR_INC);
|
||||
return EJS_TOK_INC_DEC;
|
||||
|
||||
case '-':
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c != '-' ) {
|
||||
inputPutback(ep, c);
|
||||
tokenAddChar(ep, EJS_EXPR_MINUS);
|
||||
return EJS_TOK_EXPR;
|
||||
}
|
||||
tokenAddChar(ep, EJS_EXPR_DEC);
|
||||
return EJS_TOK_INC_DEC;
|
||||
|
||||
case '*':
|
||||
tokenAddChar(ep, EJS_EXPR_MUL);
|
||||
return EJS_TOK_EXPR;
|
||||
|
||||
case '%':
|
||||
tokenAddChar(ep, EJS_EXPR_MOD);
|
||||
return EJS_TOK_EXPR;
|
||||
|
||||
case '/':
|
||||
/*
|
||||
* Handle the division operator and comments
|
||||
*/
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c != '*' && c != '/') {
|
||||
inputPutback(ep, c);
|
||||
tokenAddChar(ep, EJS_EXPR_DIV);
|
||||
return EJS_TOK_EXPR;
|
||||
}
|
||||
style = c;
|
||||
/*
|
||||
* Eat comments. Both C and C++ comment styles are supported.
|
||||
*/
|
||||
while (1) {
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
if (style == '/') {
|
||||
return EJS_TOK_EOF;
|
||||
}
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c == '\n' && style == '/') {
|
||||
break;
|
||||
} else if (c == '*') {
|
||||
c = inputGetc(ep);
|
||||
if (style == '/') {
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (c == '/') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Continue looking for a token, so get the next character
|
||||
*/
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
return EJS_TOK_EOF;
|
||||
}
|
||||
break;
|
||||
|
||||
case '<': /* < and <= */
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c == '<') {
|
||||
tokenAddChar(ep, EJS_EXPR_LSHIFT);
|
||||
return EJS_TOK_EXPR;
|
||||
} else if (c == '=') {
|
||||
tokenAddChar(ep, EJS_EXPR_LESSEQ);
|
||||
return EJS_TOK_EXPR;
|
||||
}
|
||||
tokenAddChar(ep, EJS_EXPR_LESS);
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_EXPR;
|
||||
|
||||
case '>': /* > and >= */
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c == '>') {
|
||||
tokenAddChar(ep, EJS_EXPR_RSHIFT);
|
||||
return EJS_TOK_EXPR;
|
||||
} else if (c == '=') {
|
||||
tokenAddChar(ep, EJS_EXPR_GREATEREQ);
|
||||
return EJS_TOK_EXPR;
|
||||
}
|
||||
tokenAddChar(ep, EJS_EXPR_GREATER);
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_EXPR;
|
||||
|
||||
case '=': /* "==" */
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c == '=') {
|
||||
tokenAddChar(ep, EJS_EXPR_EQ);
|
||||
return EJS_TOK_EXPR;
|
||||
}
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_ASSIGNMENT;
|
||||
|
||||
case '!': /* "!=" or "!"*/
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if (c == '=') {
|
||||
tokenAddChar(ep, EJS_EXPR_NOTEQ);
|
||||
return EJS_TOK_EXPR;
|
||||
}
|
||||
inputPutback(ep, c);
|
||||
tokenAddChar(ep, EJS_EXPR_BOOL_COMP);
|
||||
return EJS_TOK_EXPR;
|
||||
|
||||
case ';':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_SEMI;
|
||||
|
||||
case ',':
|
||||
tokenAddChar(ep, c);
|
||||
return EJS_TOK_COMMA;
|
||||
|
||||
case '|': /* "||" */
|
||||
if ((c = inputGetc(ep)) < 0 || c != '|') {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
tokenAddChar(ep, EJS_COND_OR);
|
||||
return EJS_TOK_LOGICAL;
|
||||
|
||||
case '&': /* "&&" */
|
||||
if ((c = inputGetc(ep)) < 0 || c != '&') {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
tokenAddChar(ep, EJS_COND_AND);
|
||||
return EJS_TOK_LOGICAL;
|
||||
|
||||
case '\"': /* String quote */
|
||||
case '\'':
|
||||
quote = c;
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Syntax Error");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
|
||||
while (c != quote) {
|
||||
/*
|
||||
* Check for escape sequence characters
|
||||
*/
|
||||
if (c == '\\') {
|
||||
c = inputGetc(ep);
|
||||
|
||||
if (isdigit(c)) {
|
||||
/*
|
||||
* Octal support, \101 maps to 65 = 'A'. Put first
|
||||
* char back so converter will work properly.
|
||||
*/
|
||||
inputPutback(ep, c);
|
||||
c = charConvert(ep, 8, 3);
|
||||
|
||||
} else {
|
||||
switch (c) {
|
||||
case 'n':
|
||||
c = '\n'; break;
|
||||
case 'b':
|
||||
c = '\b'; break;
|
||||
case 'f':
|
||||
c = '\f'; break;
|
||||
case 'r':
|
||||
c = '\r'; break;
|
||||
case 't':
|
||||
c = '\t'; break;
|
||||
case 'x':
|
||||
/*
|
||||
* Hex support, \x41 maps to 65 = 'A'
|
||||
*/
|
||||
c = charConvert(ep, 16, 2);
|
||||
break;
|
||||
case 'u':
|
||||
/*
|
||||
* Unicode support, \x0401 maps to 65 = 'A'
|
||||
*/
|
||||
c = charConvert(ep, 16, 2);
|
||||
c = c*16 + charConvert(ep, 16, 2);
|
||||
|
||||
break;
|
||||
case '\'':
|
||||
case '\"':
|
||||
case '\\':
|
||||
break;
|
||||
default:
|
||||
ejsError(ep, "Invalid Escape Sequence");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
}
|
||||
if (tokenAddChar(ep, c) < 0) {
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
} else {
|
||||
if (tokenAddChar(ep, c) < 0) {
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
}
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
ejsError(ep, "Unmatched Quote");
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
}
|
||||
return EJS_TOK_LITERAL;
|
||||
|
||||
case '0':
|
||||
if (tokenAddChar(ep, c) < 0) {
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
break;
|
||||
}
|
||||
if (tolower(c) == 'x') {
|
||||
do {
|
||||
if (tokenAddChar(ep, c) < 0) {
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
break;
|
||||
}
|
||||
} while (isdigit(c) || (tolower(c) >= 'a' && tolower(c) <= 'f'));
|
||||
|
||||
mprDestroyVar(&ep->tokenNumber);
|
||||
ep->tokenNumber = mprParseVar(ep->token, type);
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_NUMBER;
|
||||
}
|
||||
if (! isdigit(c)) {
|
||||
#if BLD_FEATURE_FLOATING_POINT
|
||||
if (c == '.' || tolower(c) == 'e' || c == '+' || c == '-') {
|
||||
/* Fall through */
|
||||
type = MPR_TYPE_FLOAT;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
mprDestroyVar(&ep->tokenNumber);
|
||||
ep->tokenNumber = mprParseVar(ep->token, type);
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_NUMBER;
|
||||
}
|
||||
}
|
||||
/* Fall through to get more digits */
|
||||
|
||||
case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
do {
|
||||
if (tokenAddChar(ep, c) < 0) {
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
break;
|
||||
}
|
||||
#if BLD_FEATURE_FLOATING_POINT
|
||||
if (c == '.' || tolower(c) == 'e' || tolower(c) == 'f') {
|
||||
type = MPR_TYPE_FLOAT;
|
||||
}
|
||||
} while (isdigit(c) || c == '.' || tolower(c) == 'e' || tolower(c) == 'f' ||
|
||||
((type == MPR_TYPE_FLOAT) && (c == '+' || c == '-')));
|
||||
#else
|
||||
} while (isdigit(c));
|
||||
#endif
|
||||
|
||||
mprDestroyVar(&ep->tokenNumber);
|
||||
ep->tokenNumber = mprParseVar(ep->token, type);
|
||||
inputPutback(ep, c);
|
||||
return EJS_TOK_NUMBER;
|
||||
|
||||
default:
|
||||
/*
|
||||
* Identifiers or a function names
|
||||
*/
|
||||
while (1) {
|
||||
if (c == '\\') {
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
break;
|
||||
}
|
||||
if (c == '\n' || c == '\r') {
|
||||
break;
|
||||
}
|
||||
} else if (tokenAddChar(ep, c) < 0) {
|
||||
break;
|
||||
}
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
break;
|
||||
}
|
||||
if (!isalnum(c) && c != '$' && c != '_' && c != '\\') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*ep->token == '\0') {
|
||||
c = inputGetc(ep);
|
||||
break;
|
||||
}
|
||||
if (! isalpha((int) *ep->token) && *ep->token != '$' &&
|
||||
*ep->token != '_') {
|
||||
ejsError(ep, "Invalid identifier %s", ep->token);
|
||||
return EJS_TOK_ERR;
|
||||
}
|
||||
|
||||
tid = checkReservedWord(ep, state, c, EJS_TOK_ID);
|
||||
if (tid != EJS_TOK_ID) {
|
||||
return tid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip white space after token to find out whether this is
|
||||
* a function or not.
|
||||
*/
|
||||
while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
|
||||
if ((c = inputGetc(ep)) < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
tid = EJS_TOK_ID;
|
||||
done++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Putback the last extra character for next time
|
||||
*/
|
||||
inputPutback(ep, c);
|
||||
return tid;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Convert a hex or octal character back to binary, return original char if
|
||||
* not a hex digit
|
||||
*/
|
||||
|
||||
static int charConvert(Ejs *ep, int base, int maxDig)
|
||||
{
|
||||
int i, c, lval, convChar;
|
||||
|
||||
lval = 0;
|
||||
for (i = 0; i < maxDig; i++) {
|
||||
if ((c = inputGetc(ep)) < 0) {
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Initialize to out of range value
|
||||
*/
|
||||
convChar = base;
|
||||
if (isdigit(c)) {
|
||||
convChar = c - '0';
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
convChar = c - 'a' + 10;
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
convChar = c - 'A' + 10;
|
||||
}
|
||||
/*
|
||||
* If unexpected character then return it to buffer.
|
||||
*/
|
||||
if (convChar >= base) {
|
||||
inputPutback(ep, c);
|
||||
break;
|
||||
}
|
||||
lval = (lval * base) + convChar;
|
||||
}
|
||||
return lval;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Putback the last token read. Accept at most one push back token.
|
||||
*/
|
||||
|
||||
void ejsLexPutbackToken(Ejs *ep, int tid, char *string)
|
||||
{
|
||||
EjsInput *ip;
|
||||
int idx;
|
||||
|
||||
mprAssert(ep);
|
||||
ip = ep->input;
|
||||
mprAssert(ip);
|
||||
|
||||
ip->putBackIndex += 1;
|
||||
idx = ip->putBackIndex;
|
||||
ip->putBack[idx].id = tid;
|
||||
|
||||
if (ip->putBack[idx].token) {
|
||||
if (ip->putBack[idx].token == string) {
|
||||
return;
|
||||
}
|
||||
mprFree(ip->putBack[idx].token);
|
||||
}
|
||||
ip->putBack[idx].token = mprStrdup(string);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Add a character to the token buffer
|
||||
*/
|
||||
|
||||
static int tokenAddChar(Ejs *ep, int c)
|
||||
{
|
||||
EjsInput *ip;
|
||||
uchar *oldbuf;
|
||||
|
||||
mprAssert(ep);
|
||||
ip = ep->input;
|
||||
mprAssert(ip);
|
||||
|
||||
if (ip->tokEndp >= &ip->tokbuf[ip->tokSize - 1]) {
|
||||
ip->tokSize += EJS_PARSE_INCR;
|
||||
oldbuf = ip->tokbuf;
|
||||
ip->tokbuf = mprRealloc(ip->tokbuf, ip->tokSize);
|
||||
if (ip->tokbuf == 0) {
|
||||
ejsError(ep, "Token too big");
|
||||
return -1;
|
||||
}
|
||||
ip->tokEndp += (int) ((uchar*) ip->tokbuf - oldbuf);
|
||||
ip->tokServp += (int) ((uchar*) ip->tokbuf - oldbuf);
|
||||
ep->token += (int) ((uchar*) ip->tokbuf - oldbuf);
|
||||
}
|
||||
*ip->tokEndp++ = c;
|
||||
*ip->tokEndp = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Get another input character
|
||||
*/
|
||||
|
||||
static int inputGetc(Ejs *ep)
|
||||
{
|
||||
EjsInput *ip;
|
||||
int c;
|
||||
|
||||
mprAssert(ep);
|
||||
ip = ep->input;
|
||||
|
||||
if (ip->scriptSize <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
c = (uchar) (*ip->scriptServp++);
|
||||
ip->scriptSize--;
|
||||
|
||||
/*
|
||||
* For debugging, accumulate the line number and the currenly parsed line
|
||||
*/
|
||||
if (c == '\n') {
|
||||
#if BLD_DEBUG && 0
|
||||
if (ip->lineColumn > 0) {
|
||||
printf("PARSED: %s\n", ip->line);
|
||||
}
|
||||
#endif
|
||||
ip->lineNumber++;
|
||||
ip->lineColumn = 0;
|
||||
} else {
|
||||
if ((ip->lineColumn + 2) >= ip->lineLength) {
|
||||
ip->lineLength += 80;
|
||||
ip->line = mprRealloc(ip->line, ip->lineLength * sizeof(char));
|
||||
}
|
||||
ip->line[ip->lineColumn++] = c;
|
||||
ip->line[ip->lineColumn] = '\0';
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Putback a character onto the input queue
|
||||
*/
|
||||
|
||||
static void inputPutback(Ejs *ep, int c)
|
||||
{
|
||||
EjsInput *ip;
|
||||
|
||||
mprAssert(ep);
|
||||
|
||||
if (c != 0) {
|
||||
ip = ep->input;
|
||||
*--ip->scriptServp = c;
|
||||
ip->scriptSize++;
|
||||
ip->lineColumn--;
|
||||
ip->line[ip->lineColumn] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#else
|
||||
void ejsLexDummy() {}
|
||||
|
||||
/******************************************************************************/
|
||||
#endif /* BLD_FEATURE_EJS */
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,704 @@
|
||||
/*
|
||||
* @file ejsProc.c
|
||||
* @brief EJS support functions
|
||||
*/
|
||||
/********************************* Copyright **********************************/
|
||||
/*
|
||||
* @copy default.g
|
||||
*
|
||||
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
|
||||
* Portions Copyright (c) GoAhead Software, 1995-2000. All Rights Reserved.
|
||||
*
|
||||
* This software is distributed under commercial and open source licenses.
|
||||
* You may use the GPL open source license described below or you may acquire
|
||||
* a commercial license from Mbedthis Software. You agree to be fully bound
|
||||
* by the terms of either license. Consult the LICENSE.TXT distributed with
|
||||
* this software for full details.
|
||||
*
|
||||
* This software is open source; 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 of the License, or (at your
|
||||
* option) any later version. See the GNU General Public License for more
|
||||
* details at: http://www.mbedthis.com/downloads/gplLicense.html
|
||||
*
|
||||
* This program is distributed WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* This GPL license does NOT permit incorporating this software into
|
||||
* proprietary programs. If you are unable to comply with the GPL, you must
|
||||
* acquire a commercial license to use this software. Commercial licenses
|
||||
* for this software and support services are available from Mbedthis
|
||||
* Software at http://www.mbedthis.com
|
||||
*
|
||||
* @end
|
||||
*/
|
||||
/********************************** Includes **********************************/
|
||||
|
||||
#include "ejsInternal.h"
|
||||
|
||||
#if BLD_FEATURE_EJS
|
||||
|
||||
/****************************** Forward Declarations **************************/
|
||||
/*
|
||||
* Object constructors
|
||||
*/
|
||||
static int objectConsProc(EjsHandle eid, int argc, MprVar **argv);
|
||||
static int arrayConsProc(EjsHandle eid, int argc, MprVar **argv);
|
||||
static int booleanConsProc(EjsHandle eid, int argc, MprVar **agv);
|
||||
static int numberConsProc(EjsHandle eid, int argc, MprVar **argv);
|
||||
static int stringConsProc(EjsHandle eid, int argc, MprVar **argv);
|
||||
|
||||
/*
|
||||
* Core functions
|
||||
*/
|
||||
static int toStringProc(EjsHandle eid, int argc, MprVar **argv);
|
||||
static int valueOfProc(EjsHandle eid, int argc, MprVar **argv);
|
||||
|
||||
/*
|
||||
* Triggers
|
||||
*/
|
||||
static MprVarTriggerStatus lengthTrigger(MprVarTriggerOp op,
|
||||
MprProperties *parentProperties, MprVar *prop, MprVar *newValue,
|
||||
int copyRef);
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Routine to create the base common to all object types
|
||||
*/
|
||||
|
||||
MprVar ejsCreateObj(const char *name, int hashSize)
|
||||
{
|
||||
MprVar o;
|
||||
|
||||
o = mprCreateObjVar(name, hashSize);
|
||||
if (o.type == MPR_TYPE_UNDEFINED) {
|
||||
mprAssert(0);
|
||||
return o;
|
||||
}
|
||||
|
||||
mprCreatePropertyValue(&o, "toString",
|
||||
mprCreateCFunctionVar(toStringProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(&o, "valueOf",
|
||||
mprCreateCFunctionVar(valueOfProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
return o;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Routine to destroy a variable
|
||||
*/
|
||||
|
||||
bool ejsDestroyVar(MprVar *obj)
|
||||
{
|
||||
return mprDestroyVar(obj);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Routine to create the base array type
|
||||
*/
|
||||
|
||||
MprVar ejsCreateArray(const char *name, int size)
|
||||
{
|
||||
MprVar obj, *lp, undef;
|
||||
char idx[16];
|
||||
int i;
|
||||
|
||||
/* Sanity limit for size of hash table */
|
||||
|
||||
obj = ejsCreateObj(name, max(size, 503));
|
||||
if (obj.type == MPR_TYPE_UNDEFINED) {
|
||||
mprAssert(0);
|
||||
return obj;
|
||||
}
|
||||
|
||||
undef = mprCreateUndefinedVar();
|
||||
for (i = 0; i < size; i++) {
|
||||
mprItoa(i, idx, sizeof(idx));
|
||||
mprCreateProperty(&obj, idx, &undef);
|
||||
}
|
||||
|
||||
lp = mprCreatePropertyValue(&obj, "length", mprCreateIntegerVar(size));
|
||||
mprAssert(lp);
|
||||
|
||||
mprSetVarReadonly(lp, 1);
|
||||
mprAddVarTrigger(lp, lengthTrigger);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************** Constructors ********************************/
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Object constructor. Nothing really done here. For future expansion.
|
||||
*/
|
||||
|
||||
static int objectConsProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
#if XX_UNUSED_XX
|
||||
MprVar *obj;
|
||||
Ejs *ep;
|
||||
|
||||
if((ep = ejsPtr(eid)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
obj = mprGetProperty(ep->local, "this", 0);
|
||||
mprAssert(obj);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Array constructor
|
||||
*/
|
||||
|
||||
static int arrayConsProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
MprVar *obj, *lp, undef;
|
||||
Ejs *ep;
|
||||
char idx[16];
|
||||
int i, max;
|
||||
|
||||
objectConsProc(eid, argc, argv);
|
||||
|
||||
if((ep = ejsPtr(eid)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
obj = mprGetProperty(ep->local, "this", 0);
|
||||
mprAssert(obj);
|
||||
|
||||
|
||||
if (argc == 1 && mprVarIsNumber(argv[0]->type)) {
|
||||
/*
|
||||
* x = new Array(size);
|
||||
*/
|
||||
undef = mprCreateUndefinedVar();
|
||||
max = (int) mprVarToInteger(argv[0]);
|
||||
for (i = 0; i < max; i++) {
|
||||
mprItoa(i, idx, sizeof(idx));
|
||||
mprCreateProperty(obj, idx, &undef);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* x = new Array(element0, element1, ..., elementN):
|
||||
*/
|
||||
max = argc;
|
||||
for (i = 0; i < max; i++) {
|
||||
mprItoa(i, idx, sizeof(idx));
|
||||
mprCreateProperty(obj, idx, argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
lp = mprCreatePropertyValue(obj, "length", mprCreateIntegerVar(max));
|
||||
mprAssert(lp);
|
||||
|
||||
mprSetVarReadonly(lp, 1);
|
||||
mprAddVarTrigger(lp, lengthTrigger);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Boolean constructor
|
||||
*/
|
||||
|
||||
static int booleanConsProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
objectConsProc(eid, argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
#if FUTURE
|
||||
/*
|
||||
* Date constructor
|
||||
*/
|
||||
|
||||
static int dateConsProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
objectConsProc(eid, argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Number constructor
|
||||
*/
|
||||
|
||||
static int numberConsProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
objectConsProc(eid, argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* String constructor
|
||||
*/
|
||||
|
||||
static int stringConsProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
objectConsProc(eid, argc, argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/********************************** Functions *********************************/
|
||||
/******************************************************************************/
|
||||
|
||||
static int toStringProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
MprVar *obj;
|
||||
Ejs *ep;
|
||||
char *buf;
|
||||
int radix;
|
||||
|
||||
if (argc == 0) {
|
||||
radix = 10;
|
||||
|
||||
} else if (argc == 1) {
|
||||
radix = (int) mprVarToInteger(argv[0]);
|
||||
|
||||
} else {
|
||||
mprAssert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((ep = ejsPtr(eid)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
obj = mprGetProperty(ep->local, "this", 0);
|
||||
mprAssert(obj);
|
||||
|
||||
mprVarToString(&buf, MPR_MAX_STRING, 0, obj);
|
||||
mprCopyVarValue(&ep->result, mprCreateStringVar(buf, 0), MPR_SHALLOW_COPY);
|
||||
mprFree(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static int valueOfProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
MprVar *obj;
|
||||
Ejs *ep;
|
||||
|
||||
if (argc != 0) {
|
||||
mprAssert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((ep = ejsPtr(eid)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
obj = mprGetProperty(ep->local, "this", 0);
|
||||
mprAssert(obj);
|
||||
|
||||
switch (obj->type) {
|
||||
default:
|
||||
case MPR_TYPE_UNDEFINED:
|
||||
case MPR_TYPE_NULL:
|
||||
case MPR_TYPE_CFUNCTION:
|
||||
case MPR_TYPE_OBJECT:
|
||||
case MPR_TYPE_FUNCTION:
|
||||
case MPR_TYPE_STRING_CFUNCTION:
|
||||
case MPR_TYPE_PTR:
|
||||
mprCopyVar(&ep->result, obj, MPR_SHALLOW_COPY);
|
||||
break;
|
||||
|
||||
case MPR_TYPE_STRING:
|
||||
mprCopyVarValue(&ep->result, mprCreateIntegerVar(atoi(obj->string)), 0);
|
||||
break;
|
||||
|
||||
case MPR_TYPE_BOOL:
|
||||
case MPR_TYPE_INT:
|
||||
#if BLD_FEATURE_INT64
|
||||
case MPR_TYPE_INT64:
|
||||
#endif
|
||||
#if BLD_FEATURE_FLOATING_POINT
|
||||
case MPR_TYPE_FLOAT:
|
||||
#endif
|
||||
mprCopyVar(&ep->result, obj, 0);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Var access trigger on the Array.length property. Return the count of
|
||||
* enumerable properties (don't count functions).
|
||||
*/
|
||||
|
||||
static MprVarTriggerStatus lengthTrigger(MprVarTriggerOp op,
|
||||
MprProperties *parentProperties, MprVar *prop, MprVar *newValue,
|
||||
int copyRef)
|
||||
{
|
||||
switch (op) {
|
||||
case MPR_VAR_READ:
|
||||
/*
|
||||
* Subtract one for the length property
|
||||
* FUTURE -- need an API to access parentProperties
|
||||
* FUTURE -- contradiction to be read-only yet allow USE_NEW_VALUE.
|
||||
* API needs finer control.
|
||||
*/
|
||||
*newValue = mprCreateIntegerVar(parentProperties->numDataItems - 1);
|
||||
return MPR_TRIGGER_USE_NEW_VALUE;
|
||||
|
||||
case MPR_VAR_WRITE:
|
||||
return MPR_TRIGGER_ABORT;
|
||||
|
||||
case MPR_VAR_CREATE_PROPERTY:
|
||||
case MPR_VAR_DELETE_PROPERTY:
|
||||
case MPR_VAR_DELETE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return MPR_TRIGGER_PROCEED;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/**************************** Extension Functions *****************************/
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Assert
|
||||
*/
|
||||
|
||||
static int assertProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
bool b;
|
||||
|
||||
if (argc < 1) {
|
||||
ejsSetErrorMsg(eid, "usage: assert(condition)\n");
|
||||
return -1;
|
||||
}
|
||||
b = mprVarToBool(argv[0]);
|
||||
if (b == 0) {
|
||||
ejsSetErrorMsg(eid, "Assertion failure\n");
|
||||
return -1;
|
||||
}
|
||||
ejsSetReturnValue(eid, mprCreateBoolVar(b));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Exit
|
||||
*/
|
||||
|
||||
static int exitProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
int status;
|
||||
|
||||
if (argc < 1) {
|
||||
ejsSetErrorMsg(eid, "usage: exit(status)\n");
|
||||
return -1;
|
||||
}
|
||||
status = (int) mprVarToInteger(argv[0]);
|
||||
ejsSetExitStatus(eid, status);
|
||||
|
||||
ejsSetReturnValue(eid, mprCreateStringVar("", 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static void printVar(MprVar *vp, int recurseCount, int indent)
|
||||
{
|
||||
MprVar *np;
|
||||
char *buf;
|
||||
int i;
|
||||
|
||||
if (recurseCount > 5) {
|
||||
write(1, "Skipping - recursion too deep\n", 29);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < indent; i++) {
|
||||
write(1, " ", 2);
|
||||
}
|
||||
|
||||
if (vp->type == MPR_TYPE_OBJECT) {
|
||||
if (vp->name) {
|
||||
write(1, vp->name, strlen(vp->name));
|
||||
} else {
|
||||
write(1, "unknown", 7);
|
||||
}
|
||||
write(1, ": {\n", 4);
|
||||
np = mprGetFirstProperty(vp, MPR_ENUM_DATA);
|
||||
while (np) {
|
||||
if (strcmp(np->name, "local") == 0 ||
|
||||
strcmp(np->name, "global") == 0 ||
|
||||
strcmp(np->name, "this") == 0) {
|
||||
np = mprGetNextProperty(vp, np, MPR_ENUM_DATA);
|
||||
continue;
|
||||
}
|
||||
printVar(np, recurseCount + 1, indent + 1);
|
||||
np = mprGetNextProperty(vp, np, MPR_ENUM_DATA);
|
||||
if (np) {
|
||||
write(1, ",\n", 2);
|
||||
}
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
for (i = 0; i < indent; i++) {
|
||||
write(1, " ", 2);
|
||||
}
|
||||
write(1, "}", 1);
|
||||
|
||||
} else {
|
||||
if (vp->name) {
|
||||
write(1, vp->name, strlen(vp->name));
|
||||
} else {
|
||||
write(1, "unknown", 7);
|
||||
}
|
||||
write(1, ": ", 2);
|
||||
|
||||
/* FUTURE -- other types ? */
|
||||
mprVarToString(&buf, MPR_MAX_STRING, 0, vp);
|
||||
if (vp->type == MPR_TYPE_STRING) {
|
||||
write(1, "\"", 1);
|
||||
}
|
||||
write(1, buf, strlen(buf));
|
||||
if (vp->type == MPR_TYPE_STRING) {
|
||||
write(1, "\"", 1);
|
||||
}
|
||||
mprFree(buf);
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Print the args to stdout
|
||||
*/
|
||||
|
||||
static int printVarsProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
MprVar *vp;
|
||||
char *buf;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
vp = argv[i];
|
||||
switch (vp->type) {
|
||||
case MPR_TYPE_OBJECT:
|
||||
printVar(vp, 0, 0);
|
||||
break;
|
||||
default:
|
||||
mprVarToString(&buf, MPR_MAX_STRING, 0, vp);
|
||||
write(1, buf, strlen(buf));
|
||||
mprFree(buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
write(1, "\n", 1);
|
||||
|
||||
ejsSetReturnValue(eid, mprCreateStringVar("", 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Print the args to stdout
|
||||
*/
|
||||
|
||||
static int printProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
char *buf;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
mprVarToString(&buf, MPR_MAX_STRING, 0, argv[i]);
|
||||
write(1, buf, strlen(buf));
|
||||
mprFree(buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* println
|
||||
*/
|
||||
|
||||
static int printlnProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
printProc(eid, argc, argv);
|
||||
write(1, "\n", 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Trace
|
||||
*/
|
||||
|
||||
static int traceProc(EjsHandle eid, int argc, char **argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
mprLog(0, "%s", argv[0]);
|
||||
|
||||
} else if (argc == 2) {
|
||||
mprLog(atoi(argv[0]), "%s", argv[1]);
|
||||
|
||||
} else {
|
||||
ejsSetErrorMsg(eid, "Usage: trace([level], message)");
|
||||
return -1;
|
||||
}
|
||||
ejsSetReturnString(eid, "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Return the object reference count
|
||||
*/
|
||||
|
||||
static int refCountProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
MprVar *vp;
|
||||
int count;
|
||||
|
||||
vp = argv[0];
|
||||
if (vp->type == MPR_TYPE_OBJECT) {
|
||||
count = mprGetVarRefCount(vp);
|
||||
ejsSetReturnValue(eid, mprCreateIntegerVar(count));
|
||||
} else {
|
||||
ejsSetReturnValue(eid, mprCreateIntegerVar(0));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Evaluate a sub-script. It is evaluated in the same variable scope as
|
||||
* the calling script / function.
|
||||
*/
|
||||
|
||||
static int evalScriptProc(EjsHandle eid, int argc, MprVar **argv)
|
||||
{
|
||||
MprVar *arg;
|
||||
char *emsg;
|
||||
int i;
|
||||
|
||||
ejsSetReturnValue(eid, mprCreateUndefinedVar());
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
arg = argv[i];
|
||||
if (arg->type != MPR_TYPE_STRING) {
|
||||
continue;
|
||||
}
|
||||
if (ejsEvalScript(eid, arg->string, 0, &emsg) < 0) {
|
||||
ejsSetErrorMsg(eid, "%s", emsg);
|
||||
mprFree(emsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Return with the value of the last expression
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
/******************************************************************************/
|
||||
/*
|
||||
* Define the standard properties and functions inherited by all script engines.
|
||||
*/
|
||||
|
||||
int ejsDefineStandardProperties(MprVar *obj)
|
||||
{
|
||||
#if BLD_FEATURE_FLOATING_POINT
|
||||
double d = 0.0;
|
||||
|
||||
/* FUTURE - this generates warnings on some systems. This is okay. */
|
||||
|
||||
mprCreatePropertyValue(obj, "NaN", mprCreateFloatVar(0.0 / d));
|
||||
d = MAX_FLOAT;
|
||||
mprCreatePropertyValue(obj, "Infinity", mprCreateFloatVar(d * d));
|
||||
#endif
|
||||
mprCreatePropertyValue(obj, "null", mprCreateNullVar());
|
||||
mprCreatePropertyValue(obj, "undefined", mprCreateUndefinedVar());
|
||||
mprCreatePropertyValue(obj, "true", mprCreateBoolVar(1));
|
||||
mprCreatePropertyValue(obj, "false", mprCreateBoolVar(0));
|
||||
mprCreatePropertyValue(obj, "NULL", mprCreatePtrVar(NULL));
|
||||
|
||||
#if BLD_FEATURE_LEGACY_API
|
||||
/*
|
||||
* DEPRECATED: 2.0.
|
||||
* So that ESP/ASP can ignore "language=javascript" statements
|
||||
*/
|
||||
mprCreatePropertyValue(obj, "javascript", mprCreateIntegerVar(0));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Extension functions
|
||||
*/
|
||||
mprCreatePropertyValue(obj, "assert",
|
||||
mprCreateCFunctionVar(assertProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "eval",
|
||||
mprCreateCFunctionVar(evalScriptProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "exit",
|
||||
mprCreateCFunctionVar(exitProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "refCount",
|
||||
mprCreateCFunctionVar(refCountProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "print",
|
||||
mprCreateCFunctionVar(printProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "println",
|
||||
mprCreateCFunctionVar(printlnProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "printVars",
|
||||
mprCreateCFunctionVar(printVarsProc,0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "trace",
|
||||
mprCreateStringCFunctionVar(traceProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
mprCreatePropertyValue(obj, "Array",
|
||||
mprCreateCFunctionVar(arrayConsProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "Boolean",
|
||||
mprCreateCFunctionVar(booleanConsProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "Object",
|
||||
mprCreateCFunctionVar(objectConsProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "Number",
|
||||
mprCreateCFunctionVar(numberConsProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
mprCreatePropertyValue(obj, "String",
|
||||
mprCreateCFunctionVar(stringConsProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
|
||||
/* mprCreatePropertyValue(obj, "Date",
|
||||
* mprCreateCFunctionVar(dateConsProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
* mprCreatePropertyValue(obj, "Regexp",
|
||||
* mprCreateCFunctionVar(regexpConsProc, 0, MPR_VAR_SCRIPT_HANDLE));
|
||||
*/
|
||||
|
||||
/*
|
||||
* Can we use on var x = "string text";
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
#else
|
||||
void ejsProcsDummy() {}
|
||||
|
||||
/******************************************************************************/
|
||||
#endif /* BLD_FEATURE_EJS */
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
Reference in New Issue
Block a user