/* ************************************************************************* // * 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. * ************************************************************************* */ #include "uphp.h" struct FuncDef *funcs=0; // list of functions struct FreePool { struct FreePool *next; void *data; FREEPOOLFUNC freefunc; } *freepool = 0; void AddToFreePool(void *data,FREEPOOLFUNC freef) { struct FreePool *p = (struct FreePool *)malloc(sizeof(struct FreePool)); if(!p) emiterror(ERR_OUT_OF_MEMORY); p->data=data; p->freefunc=freef; p->next=freepool; freepool=p; } void ClearFromPool(void *data) { struct FreePool *p=freepool; if(p->data==data) { freepool=p->next; p->freefunc(data); free(p); } else for(;p->next;p=p->next) { if(p->next->data==data) { struct FreePool *n=p->next; p->next=n->next; n->freefunc(data); free(n); return; } } } struct FuncDef *getfunc(char *fname) { struct FuncDef *f; for(f=funcs;f;f=f->next) { if(!strcasecmp(f->funcname,fname)) return f; } return 0; } void clearfuncs() { struct FuncDef *f; for(f=funcs;f;) { struct FuncDef *n=f->next; free(f); f=n; } funcs=0; struct FreePool *p; for(p=freepool;p;) { struct FreePool *n=p->next; p->freefunc(p->data); free(p); p=n; } } #ifdef BUILD_EXECUTER void addapifunc(char *name, int paramnum, void (*apifunc)(void)) { struct FuncDef *func=(struct FuncDef *)malloc(sizeof(struct FuncDef)); if(!func) emiterror(ERR_OUT_OF_MEMORY); func->jumplabel=0; func->api=apifunc; func->numparams=paramnum; func->next=funcs; strcpy(func->funcname,name); funcs=func; } #else void addapifunc(char *name, int paramnum) { struct FuncDef *func=(struct FuncDef *)malloc(sizeof(struct FuncDef)); if(!func) emiterror(ERR_OUT_OF_MEMORY); func->jumplabel=0; func->api=(void (*)())0xffffffff; func->numparams=paramnum; func->next=funcs; strcpy(func->funcname,name); funcs=func; } #endif