#include "numarithmodule.h" #include //#include //#include //#include #include "dllutils.h" #include "numarithmodule.xpm" static log2T s_log_function = 0; static void logger(int level, const char* msg) { if (s_log_function) s_log_function(level, "mod_numarithmodule", msg); } const char* getSpec(void) { return "mod_spec { name=[mod_numarithmodule] number_of_inputs=[3] number_of_outputs=[1] deterministic=[true] }"; } const char* getInputSpec(int index) { switch(index) { case 0: return "input_spec { type=typ_NumberType id=lhs const=true strong_dependency=true default=[0] } "; break; case 1: return "input_spec { type=typ_NumberType id=rhs const=true strong_dependency=true default=[0] } "; break; case 2: return "input_spec { type=typ_StringType id=op const=true strong_dependency=true default=[x+y] } "; break; } return 0; } const char* getOutputSpec(int index) { switch(index) { case 0: return "output_spec { type=typ_NumberType id=r } "; break; } return 0; } void* newInstance() { Instance* inst = (Instance*) malloc(sizeof(Instance)); if (inst == 0) { logger(0, "Could not allocate memory for instance struct!\n"); return 0; } inst->my = construct(); if (inst->my == 0) { free(inst); return 0; } return inst; } void deleteInstance(void* instance) { Instance* inst = (Instance*) instance; destruct(inst->my); free(inst); } int setInput(void* instance,int index,void* typePointer) { InstancePtr inst = (InstancePtr) instance; switch(index) { case 0: inst->in_lhs = (NumberType *) typePointer; break; case 1: inst->in_rhs = (NumberType *) typePointer; break; case 2: inst->in_op = (StringType *) typePointer; break; } //switch(index) return 1; } int setOutput(void* instance,int index, void* typePointer) { InstancePtr inst = (InstancePtr) instance; switch(index) { case 0: inst->out_r = (NumberType* ) typePointer; break; } //switch(index) return 0; } int getInfo(char* buf,int bufLen) { static const char* INFO = "info { name=[Calculon] group=[Number] inputs=[3 x{widget_type=[unboundednumber_selector] } y{widget_type=[unboundednumber_selector] } Operation{widget_type=[combo_box] values=[x+y,x-y,x*y,x/y,x%y,x^y,max(x;y),min(x;y),exp(x),ln(x),sin(x),|x|,x,y,floor(x),ceil(x),round(x)] hidden=[true] } ] outputs=[1 Result ] type=xpm } "; char* tmpBuf; int reqLen = 1 + strlen(INFO) + getSizeOfXPM(numarithmodule_xpm); if (buf != 0 && reqLen <= bufLen) { char* offset; int i; int lines = getNumberOfStringsXPM(numarithmodule_xpm); tmpBuf = (char*) malloc(reqLen); if (tmpBuf == 0) { printf("Could not allocate memory in getInfo\n"); return 0; } memcpy(tmpBuf,INFO,strlen(INFO)+1); offset = tmpBuf + strlen(INFO) + 1; for (i = 0; i < lines; ++i) { char* source = numarithmodule_xpm[i]; memcpy(offset,source,strlen(source)+1); offset += strlen(source) + 1; } memcpy(buf,tmpBuf,reqLen); free(tmpBuf); } return reqLen; } int initSO(log2T log_function) { s_log_function = log_function; return init(logger); }