?? ararxout.c
字號(hào):
/*
Copyright (c) 2003, Dan Kranz and Arnold Rom
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* The names of its contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <roots.h>
static DataBaseInternalValue rep;
DataBaseInternalValue* arxout(DataBase* db, short bfi, char* Istring)
// -----------------------------------------------------------------------
{ // arxcout START
// -----------------------------------------------------------------------
// local data
long fld[2],i,cpl,n1=1,kt,nblank,need;
long v[2];
char* string;
char blank = '\0';
BYTE park[256];
static long maxval[4]={255,65535,16777215,2147483647};
// handle NULL input case
if(Istring==NULL) string=␣ else string=Istring;
// derive a roots field definition for string
cpl=fld[1]=strlen(string);
fld[0]=1;
// eliminate leading blanks from other than t-types
if(db->type[bfi-1]!=T_TYPE)
{
for(i=0; i<cpl; i++)
{
if(string[i]!=' ') break;
fld[0]++;
fld[1]--;
}
}
rep.type=db->type[bfi-1];
switch(db->type[bfi-1])
// -------------------------------
{ // switch start
// -------------------------------
// ---------
case B_TYPE:
// ---------
// convert date field
if(db->ARMRtype[bfi-1] == D_TYPE)
{
if(cdatec(string,fld,&rep.binary))
{
RootsError("Invalid date\n");
return NULL;;
}
}
else // convert regular binary
{
if(chcdbf(string,fld,&rep.binary,&n1))
{
RootsError("Invalid numerics**\n");
return NULL;
}
}
// Audit
cpl = db->blkfld[bfi-1][1];
if (rep.binary > maxval[cpl-1])
{
RootsError("The number input is too large");
return NULL;
}
break;
// ---------
case R_TYPE:
// ---------
if(clcdbr(string,fld,&rep.real,&n1))
{
RootsError("Invalid numerics**\n");
return NULL;
}
break;
// ---------
case T_TYPE:
// ---------
if(!(kt=db->tabinx[bfi-1])) {RootsSOS("** sos exit from arxout **/n");
abort();}
// set blanks to zero
for(i=0, nblank=0; i<fld[1]; i++)
{
if(string[fld[0]+i-1] != ' ') break;
nblank++;
}
if(nblank==fld[1]) {rep.binary=0; break;}
// make room for new entry
need=db->arx[kt-1].nline+1;
if(need>db->arx[kt-1].nAlloc) need+=100;
ExpandBlock(db->arx[kt-1],need);
// derive tabular index & set update flags
v[0]=1; v[1]=db->arx[kt-1].cpl;
chmove(string,fld,park,v,&n1);
chtab(BLOCK(db->arx[kt-1]),park,v,&rep.binary);
// audit for table overflow
if(db->blkfld[bfi-1][1]==1 && rep.binary>255 ||
db->blkfld[bfi-1][1]==2 && rep.binary>MAXLIN)
{
RootsSOS("New Binary table index exceeds data base field width");
abort();
}
break;
// ---------
case E_TYPE:
// ---------
memcpy(rep.Estring,&string[fld[0]-1],fld[1]);
rep.Estring[fld[1]]='\0';
break;
// ----------------
default: return NULL;
// ----------------
// -------------------------------
} // switch end
// -------------------------------
return &rep;
// -----------------------------------------------------------------------
} // arxcout END
// -----------------------------------------------------------------------
BYTE cdatec(BYTE* reply, long* repfld, long* ymd)
// -----------------------------------------------------------------------
{ // cdatec START
// -----------------------------------------------------------------------
// local data
long i,nf,flds[3][2],mdy[3],n3=3,n1=1;
long mo,dy,yr,remain;
static BYTE daymon[12]={31,29,31,30,31,30,31,31,30,31,30,31};
BYTE* tokens[20];
short tokcpl[20];
static long cyear, ccntry;
static int first=1;
// Determine current century and year
if (first)
{
date(&dy,&mo,&yr);
cyear = yr%100;
ccntry = yr-cyear;
first=0;
}
*ymd=0;
// get rid of front and/or back blanks
if(!(nf=Parse(&reply[repfld[0]-1],repfld[1],tokens,tokcpl)))
return FALSE;
if(nf!=1) return TRUE;
// identify / or - separaters and build fields
for(i=nf=0,flds[nf][0]=1,flds[nf][1]=0; i<tokcpl[0]; i++)
if(tokens[0][i]=='/' || tokens[0][i]=='-')
{
nf++; if(nf>2) return TRUE;
flds[nf][0]=flds[nf-1][0]+flds[nf-1][1]+1;
flds[nf][1]=0;
}
else flds[nf][1]++;
nf++;
if(nf!=1 && nf!=3) return TRUE;
// build month day year from mm/dd/yy type input or yymmdd
if(nf==3)
{
if(chcdbf(tokens[0],flds[0],mdy,&n3)) return TRUE;
// 2 digit year input
if (flds[2][1]<=2)
{
if(cyear<50)
{
if(mdy[2]<50)
mdy[2] += ccntry;
else
mdy[2] += (ccntry-100);
}
else
{
if(mdy[2]<50)
mdy[2] += (ccntry+100);
else
mdy[2] += ccntry;
}
}
// Full year input
else mdy[2] -= 1900;
*ymd=mdy[2]*10000+mdy[0]*100+mdy[1];
if(mdy[2]<0) return TRUE;
}
// Convert yymmdd directly
else if(chcdbf(tokens[0],flds[0],ymd,&n1)) return TRUE;
// audit date
if(!*ymd) return FALSE;
yr=*ymd/10000;
remain=*ymd%10000;
mo=remain/100;
dy=remain%100;
if(mo<1 || mo > 12) return TRUE;
if(dy<1 || dy > daymon[mo-1]) return TRUE;
// 2/29 audit
if (dy==29 && mo==2)
{
if (yr<1900) yr+=1900;
if (!(yr%4==0 && (yr%100!=0 || yr%400==0))) return TRUE;
}
// Full year entered?
if (yr>=1900)
{
yr-=1900;
*ymd=yr*10000+mo*100+dy;
}
return FALSE;
// -----------------------------------------------------------------------
} // cdatec END
// -----------------------------------------------------------------------
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -