/* ************************************************************************* // * uPHP - micro php edition for embedded systems * Copyright (C) 2006-2007, SPiDCOM Technologies Inc. * Author(s): Nebojsa SUMRAK, nebojsa.sumrak@elsys-eastern.com * * This program 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 * of the License, or (at your option) any later version. * * This program 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 this program; if not, write to the Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ************************************************************************* */ #ifndef UPHP_H_ #define UPHP_H_ //#define DEBUG 1 #define DEBUG_MSGS 1 #define BUILD_INTERPRETER 1 //#define CONFIG_UPHP_CUSTOM_EREG //#define BUILD_COMPILER 1 //#define BUILD_EXECUTER 1 //#define TMPFILE_TEMPLATE "c:\\temp\\tcpXXXXXX" #define TMPFILE_TEMPLATE "/root/tcpXXXXXX" #define EXECUTER_EOL 10 #define DIRECTORY_SEPARATOR '/' #define CRLF "\n" #ifndef __FILENAME_MAX__ #define __FILENAME_MAX__ 256 #endif #include #include #include #include #include #include #include #include #ifdef BUILD_INTERPRETER #define BUILD_COMPILER 1 #define BUILD_EXECUTER 1 #endif #define MAX_ID_LEN 32 #define MAX_STACK_SIZE 256 #ifdef DEBUG #define trace printf #else #define trace(...) #endif // operator enum is based on priority, lower priority ops first enum { POP=0, PARAM, LABEL, STORE, RET, SCAT, SSHR, SSHL, SMOD, SADD, SSUB, SMUL, SDIV, SXOR, SAND, SOR, IIF, LAND, LOR, GT, LT, EQ, LE, GE, NE, BZ, BNZ, BRA, CALL, PUSH, DUP, CAT, SHR, SHL, ADD, TARABA='#', SUB, DIV, MOD, MUL, AND, OR, XOR, INC, DEC, ARRAY, NEG, NOT, LNOT }; enum { ERR_OK=0, ERR_ALREADY_SUSPENDED, ERR_POP_FROM_EMPTY_STACK, ERR_STACK_OVERFLOW, ERR_OUT_OF_MEMORY, ERR_STORE_NEEDS_VAR, ERR_PARAM_LIST_EXPECTED, ERR_VARIABLE_EXPECTED, ERR_DIVISION_BY_ZERO, ERR_SYNTAX, ERR_SYNTAX_IF, ERR_SYNTAX_FOR, ERR_SYNTAX_BREAK, ERR_SYNTAX_CASE, ERR_SYNTAX_DEFAULT, ERR_SYNTAX_DO, ERR_SYNTAX_CONTINUE, ERR_SYNTAX_RESERVED_WORD, ERR_SYNTAX_OPERATOR, ERR_INTERNAL, ERR_SYNTAX_RETURN, ERR_FUNCTION_PARAM_NUM, ERR_FUNCTION_NOT_FOUND, ERR_FUNCTION_API_ONLY, ERR_SYNTAX_ARRAY_BRACKET, ERR_FILE_NOT_FOUND }; struct FuncDef { struct FuncDef *next; char funcname[MAX_ID_LEN]; int numparams; int jumplabel; // if 0, api call void (*api)(void); }; struct VarDef { struct VarDef *next; char vtype; // 0-string, !0-array char varname[MAX_ID_LEN]; union { char *value; struct VarDef *arr; }; }; inline int char2hex(char c) { if(c>='0' && c<='9') return (c-'0'); if(c>='a' && c<='f') return (c-'a')+10; if(c>='A' && c<='F') return (c-'A')+10; return 0; } int isnum(char *str); extern struct FuncDef *funcs; // list of functions struct FuncDef *getfunc(char *fname); void clearfuncs(); void emiterror(int errno); void addstdfuncs(); #ifdef BUILD_EXECUTER void addapifunc(char *name, int paramnum, void (*apifunc)(void)); typedef void (*FREEPOOLFUNC)(void *); void ClearFromPool(void *data); void AddToFreePool(void *data,FREEPOOLFUNC freef); #else void addapifunc(char *name, int paramnum); #endif void print_headers(); #ifdef BUILD_EXECUTER double getfloatvalue(char *val); int getintvalue(char *val); char *getstrvalue(char *var); void execute(char *prg); void destroy(char *val); void push(char *val); void pusha(char *val); void pushi(int val); void pushf(double val); char *pop(); char *peek(int i=1); void stop_execution(); struct VarDef *getvar(char *var,struct VarDef *arr=0); struct VarDef *setvarvalue(char *v2, char *val, int copy=1); void OutputGif(unsigned char *image, int width, int height, long *colormap, int numcolors); #ifdef CONFIG_UPHP_CUSTOM_EREG typedef struct { int rm_so, rm_eo; } regmatch_t; int regex (char *regex, char *string, regmatch_t *m); #endif inline int isvariable(char *var) { if(*var>0 && *var<8) return 1; else return 0; } #endif #ifdef BUILD_COMPILER void compile(char *prg,FILE *of); #endif #define emitwarning(war) puts(war) void print(void); #endif /*UPHP_H_*/