Scripting Dynamics
/* * Copyright (c) 2017 Miguel Pando * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include
#include
#include
#include
#include
#define DLL_EXPORT __declspec(dllexport) #define grade=0.0174533 //Radians static char xbuf[16]; //************************************************************* DLL_EXPORT char * _run(char *proc, int *e, int argn, char **argz) { //************************************************************* double dbl; int r, n; static rflag=0; int x=0; if (strcmp(proc, "lshift")==0 || strcmp(proc, "rshift")==0) { if (argn < 1) {*e=1; return "Arguments Error";} r=atoi(argz[0]); if (proc[0]=='r') r>>=atoi(argz[1]); else r<<=atoi(argz[1]); sprintf(xbuf, "%d", r); return xbuf; } if (strcmp(proc, "or")==0 || strcmp(proc, "and")==0 || strcmp(proc, "xor")==0) { if (argn < 1) {*e=1; return "Arguments Error";} r=atoi(argz[0]); if (proc[0]=='o') { r|=atoi(argz[1]); } else { if (proc[0]=='x') { r^=atoi(argz[1]); } else { r&=atoi(argz[1]); } } sprintf(xbuf, "%d", r); return xbuf; } dbl=atof(argz[0]); if (strcmp(proc, "sin")==0) { dbl=sin(dbl); x=1; } if (strcmp(proc, "cos")==0) { dbl=cos(dbl); x=1; } if (strcmp(proc, "tan")==0) { dbl=tan(dbl); x=1; } if (x) { sprintf(xbuf, "%f", dbl); return xbuf; } if (strcmp(proc, "random")==0) { if (!rflag) {rflag=1; srand((unsigned int) time(NULL));} n=atoi(argz[0]); r=rand()/(RAND_MAX/n); r=rand()/(RAND_MAX/n); sprintf(xbuf, "%d", r); return xbuf; } *e=1; sprintf(xbuf, "%s", "Proc Not Found "); strcat(xbuf, proc); return xbuf; }