tape/main.cpp

00001 // main.cpp : Defines the entry point for the DLL application.
00002 //
00003 
00004 #define DLMAIN
00005 #define MAJOR 1
00006 #define MINOR 0
00007 
00008 #include <stdlib.h>
00009 #include "gridlabd.h"
00010 
00011 EXPORT int do_kill(void*);
00012 
00013 EXPORT int major=MAJOR, minor=MINOR;
00014 
00015 #ifdef WIN32
00016 
00017 #define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
00018 #include <windows.h>
00019 BOOL APIENTRY DllMain( HANDLE hModule, 
00020                        DWORD  ul_reason_for_call, 
00021                        LPVOID
00022                      )
00023 {
00024     switch (ul_reason_for_call)
00025     {
00026         case DLL_PROCESS_ATTACH:
00027         case DLL_THREAD_ATTACH:
00028             break;
00029         case DLL_THREAD_DETACH:
00030         case DLL_PROCESS_DETACH:
00031             do_kill(hModule);
00032             break;
00033     }
00034     return TRUE;
00035 }
00036 
00037 #else // !WIN32
00038 
00039 CDECL int dllinit() __attribute__((constructor));
00040 CDECL int dllkill() __attribute__((destructor));
00041 
00042 CDECL int dllinit()
00043 {
00044     return 0;
00045 }
00046 
00047 CDECL int dllkill() {
00048     do_kill(NULL);
00049 }
00050 
00051 #endif // !WIN32
00052 
00053 #include "tape.h"
00054 
00055 extern "C" VARMAP varmap[];
00056 
00057 CDECL EXPORT int setvar(char *varname, char *value)
00058 {
00059     VARMAP *p;
00060 
00061     for (p=varmap; p->name!=NULL; p++)
00062     {
00063         if (strcmp(p->name,varname)==0)
00064         {
00065             if (p->type==VT_INTEGER)
00066             {
00067                 int64 v = atoi64(value);
00068                 if (v>=(int64)p->min && v<=(int64)p->max)
00069                 {   *(int64*)(p->addr) = v; return 1;}
00070                 else return 0;
00071             }
00072             else if (p->type==VT_DOUBLE)
00073             {
00074                 double v = atof(value);
00075                 if (v>=p->min && v<=p->max)
00076                 {   *(double*)(p->addr) = v; return 1;}
00077                 else return 0;
00078             }
00079             else if (p->type==VT_STRING)
00080             {
00081                 strncpy((char*)(p->addr),value,(unsigned)p->min-1);
00082                 return 1;
00083             }
00084         }
00085     }
00086     return 0;
00087 }
00088 

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy