#include #include #include #include "dlx.h" class CDLXImports { protected: char** names; long* numlocs; long** relocs; long numimports; public: CDLXImports(FILE* infile, long nums); ~CDLXImports(); void Replace(char* data, char* name, char* placement); void CheckEmpty(); }; class CDLXSymbolList { protected: char*** tosymbols; char** names; long numdlx; public: CDLXSymbolList(); void AddExports(char *name, char** tosymbol); void Resolve(CDLXImports& ims, char* data); void RemoveExports(char*name); }; static CDLXSymbolList GlobalSymbols; class CDLX { protected: char* data; void (*LibMain)(int); char* name; long instance; long libloadpos; public: CDLX(char* iname, FILE* infile); ~CDLX(); int operator==(char*); int operator!(); int operator++(); int operator--(); }; static FILE* _DefaultOpen(char* name){return(fopen(name,"rb"));} static void _DefaultError(char *i){cout << "DLX Error!" << endl << i << endl;} FILE* (*DLXOpenFile)(char*)=_DefaultOpen; void (*DLXError)(char*)=_DefaultError; static CDLX** _dlxlist=(CDLX**)malloc(0); static long _numdlx=0; static void _NGucase(char *c) { for (unsigned long x=0; x96)&&(c[x]<123)) c[x]-=32; } void DLXLoad(char* name) { _NGucase(name); for(long l=0; l<_numdlx; l++) { if(*_dlxlist[l]==name) { ++*_dlxlist[l]; return; } } _numdlx++; _dlxlist=(CDLX**)realloc(_dlxlist, sizeof(CDLX**)*_numdlx); FILE* me=DLXOpenFile(name); _dlxlist[_numdlx-1]=new CDLX(name,me); fclose(me); } void DLXUnload(char* name) { _NGucase(name); for(long l=0; l<_numdlx; l++) { if(*_dlxlist[l]==name) { --*_dlxlist[l]; if(!_dlxlist[l]) { delete(_dlxlist[l]); _dlxlist[l]=_dlxlist[_numdlx-1]; _numdlx--; _dlxlist=(CDLX**)realloc(_dlxlist, sizeof(CDLX**)*_numdlx); } return; } } DLXError("DLX is not loaded!"); } void DLXImport(char* name, char** symbols) { GlobalSymbols.AddExports(name,symbols); } CDLXImports::CDLXImports(FILE* infile, long nums) { numimports=nums; names=(char**)malloc(sizeof(char *)*nums); numlocs=(long*)malloc(sizeof(long)*nums); relocs=(long**)malloc(sizeof(long*)*nums); long stlen; for(long l=0; l