Scripting Dynamics
/* * Copyright (c) 2013 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
#define DLL_EXPORT __declspec(dllexport) static int months[14]; char xbuf[40]; char *argx[100]; //************************************************************* //char *getDatefromJulian(int julian) { void getDatefromJulian(int julian) { //************************************************************* int d, m, y; int j, l, i, n; l = julian + 68569; n = (int) (4*l)/146097; l = (int) l-((146097*n+3)/4); i = (int) (4000*(l+1))/1461001; l = (int) l-((1461*i)/4)+31; j = (int) (80*l)/2447; d = (int) l-((2447*j)/80); l = (int) j/11; m = j+2-(12*l); y = 100*(n-49)+i+l; sprintf(xbuf, "%02d/%02d/%4d", m, d, y); } //************************************************************* int getJulianDate(char *xdate) { //************************************************************* int d, m, y, bc, ad, x, b, n; char z[3]; if (strlen(xdate)!=10) return -1; if (months[2] != 31) { months[1]=0; months[2]=31; months[3]=59; months[4]=90; months[5]=120; months[6]=151; months[7]=181; months[8]=212; months[9]=243; months[10]=273; months[11]=304; months[12]=334; months[13]=334+31; } y=atoi(xdate+6); strncpy(z, xdate, 2); z[2]='\0'; m=atoi(z); strncpy(z, xdate+3, 2); z[2]='\0'; d=atoi(z); b=0; if ( (y % 4)==0 ) { if ( (y % 100)!=0 || (y % 400)!=0 ) { if (m < 3) b=-1; } } n=months[m+1]-months[m]+b; if ( y<1 || m<1 || m>12 || d<1 || d>n ) return -1; bc = 4714; ad = y; x = (bc + ad - 2)*365; x = x + (bc + ad - 2)/4; x = x - (y/100); x = x + (y/400); x = x + months[m]; x = x + 2; x+=b; x += d; return x; } //************************************************************* DLL_EXPORT char * _run(char *proc, int *e, int argn, char **argz) { //************************************************************* int i, n; void *(__cdecl *vt[1])(int argc, char **argv); int f=atoi(argz[argn]); //CallBack vt[0]=f; *e=0; if (strcmp(proc, "getJulianDate")==0) { n=getJulianDate(argz[0]); if (n==-1) { sprintf(xbuf, "Error processing Julian Date %s", argz[0]); *e=1; } else { sprintf(xbuf, "%d", n); } return xbuf; } if (strcmp(proc, "getDatefromJulian")==0) { getDatefromJulian(atoi(argz[0])); return xbuf; } *e=1; sprintf(xbuf, "%s", "Proc Not Found "); strcat(xbuf, proc); return xbuf; } //************************************************************* DLL_EXPORT char * run(int argc, char **argv, char **argname, int *e) { //************************************************************* int ee; char *s; //(char *proc, int *e, int argn, char **argz) ee=0; s = _run(argv[0], &ee, argc, &argv[1]); *e = ee; return s; }