资源预览内容
第1页 / 共48页
第2页 / 共48页
第3页 / 共48页
第4页 / 共48页
第5页 / 共48页
第6页 / 共48页
第7页 / 共48页
第8页 / 共48页
第9页 / 共48页
第10页 / 共48页
亲,该文档总共48页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
求:d b f文件C/C+的操作库程序。DBFOP f or C+VI.00,1995.1.10De ve lop b y J ohn,Lia oM od if ie d b y Zha ng ha o.1998.05.18This M od ule inc lud e the C+he a d f ile d b f op.hpp,a nd C+re sourc e f ile d b f op.c pp.This mod ule is d e ve lop f or use DBF(DBASEIII,DBASEII,M FOXBASE,FOXPRO 2.x)a nd IDX(M FOXBASE).b ut use IDX only a llow re a d or c ha ng e the f ie ld tha tisnt ke y word.Support ne twa re sha re .f lie loc k,f ile unloc k,re c ord loc k,re c ord unloc k./*-The c la ss DBF is inte rf a c e to c ustom,a ll f unc tion tha t g ive nc a n b e invoke d b y use the c la ss DBF.1995.7.29 Cha ng e f ile option f xxx to xxx like _f sope n re pla c e with sope n1995.7.31 Cha ng e d owith option whe n type=N1995.7.31 Ad d option DBF:a ppe nd(),DBF:c le a r 0;1998.5.18 Ad d Foxpro 2.x DBF proc e ss.-*/#inc lud e std a f x.h#if d e f DEBUG#d e f ine d e b ug m Af xM e ssa g e Boxttd e f ine ne w DEBUG_NEW#e nd ifsta tic INT2 c c c(CHAR*,INT2,INT2);INT2 c c c(CIIAR*ptsr,INT2 le n,INT2 b it)ICHAR te mpi30,te mpi130,il;CHAR te mp230,te mp2230,i2;INT2 te mpi,i;CHAR*ps,*psl;f or(psl=ptsr;(*psl=,)&(*psl!=x0);psl+);ps二strc hr(psi,.);if (ps=NULL)/NOT HAVE.strc py(te mpi,psi);te mp20=,XxO1;e lse*ps=x0;strc py(te mpi,psi);ps+;strc py(te mp2,ps);)il=le n-(b it?(b it+l):O);if(int)strle n(te mpi);(int)i1)strnc py(te mpi 1,te mpi,il);te mpllil=,xOJ;e lse te mpi=i1-strle n(te mpi);f or(i=0;i;0)if(int)strlen(temp2);(int)bit)strncpy(temp22,temp2f bit);temp22bit=,xOf;else i2=strlen(temp2);tempi=bit-strJ en(temp2);s trcpy(temp22,temp2);for(i=0;i;=(INT2)i te/ns-J)return-2;c u r p+-f-;/doublereturn 0;)INT2 IDX_BLOCK:find(CHAR*key)(INT2 compi=keylen;CHAR*p=buff+12;INT2 Re tCode,i;if(int)strlen(key)(int)keylen)compi=strlen(key);for(1=0,p=buff+12;i;=2)/.and.this is a leaf orleaf&root nodecurp=i;return 0;/Founded,OKreturn to master else /.and.this is aframe or root nodecurp=i;return-10;/This is aROOT,Maybe in gaven BLOCKif(RetCode0)/if the key cur ent key in idx fileif(flag;handle!=-1)close(handle);handle-l;/open function open the idx fileINT2 IDX:0pen(CHAR*filename)CHAR buff30;/fp=fsopen(fi 1 enamef:rb,SH DENY NONE);/change by lia o j in t 1999.3.22handle=sopen(filename,0 RDONLYI_0 BINARY,_SH_DENYNO,_SREAD);/*handle=sopen(filename,0 RDWRjO_ BINARY IODENYNONE,SH DENYNONE,STREAD IS_I_write);*/i f (fp=NULL)return-J;if(handle=l)return-1;i f (_1 seek(handle,0,SEEK_SET)!=0)return-1;i f (read(handle,buff,30)!=30)return-1;roo tpos=*(UINT4*)buff;blocks=*(UINT4*)(buff;key_ Jen=*(INT2*)(buff+12);block.SetKeyLen(key_len);block.ReadBlock(this-;handlef rootpos);while(block.GetFlagO;handl e,block.Get Re suit();GoHome();return 0;)INT2 IDX:rev()UINT4 PrevBlock;i f (block.Prev()!=0)Pre vBlock=block.Ge tPre v();i f (Pre vBl ock=Oxffffffffl)return-1;block.ReadBlock(this-;handle,(INT4)PrevBlock);block.End();return 0;INT2 IDX:Next()(UINT4 NextBlock;i f (block.Next()!=0)/Is already in the last node in this blockNextBlock=block.GetNext();i f(Nex tBlock=Oxffffffffl)return-2;block.ReadBlock(this-;handle,(INT4)NextBlock);block.Home():return 0;INT2 IDX:Find(CHAR*key)(INT2 Ret Code;block.ReadBlock(this-;handlef rootpos);for(;Q)RetCode=block.find(key);switch(RetCode)case 0:return 0;case-1:return-J;case-2:i f (block.Ge tPre v()=(UINT4)O x ffffffffl)return-1:else(block.ReadBlock(this-;handle,block.GetPrevO);)break;case-3:i f (block.GetNext()=(UINT4)O x ffffffffl)return-1;/else block.ReadBlock(this-;handle,block.GetNext();break;case-10:block.ReadBlock(this-;handle,block.GetResult():break;default:/Fatal Error:returncode is not allow/in class IDX_BLOCK:fin d (CHAR*);/break;)INT2 IDX:Skip()return Next();INT2 IDX:GoHome()while(block.GetPrevO!=(U IN T4)0 xffffffffl)block.ReadBlock(this-;handle,block.GetPrev();;block.Home();return 0;INT2 IDX:GoEnd()while(block.GetNext()!=(UINT4)O x ffffffffl)block.ReadBlock(this-;handle,block.GetNext();:block.End();return 0;UINT4 IDX BLOCK:GetResult()CHAR tf5j;CHAR*p=buff-f-12-(-curp*(keylen+4);p-f-=keylen;tf3=p0;tf2=pl;tfl=p2;tf0=p3;return*(UINT4*)tf;/INT2 IDX_BLOCK:ReadBlock(FILE*f p,UINT4 pos)INT2 IDX_BLOCK:ReadBlock(INT2 handle,UINT4 pos)(/fseek(f p,pos,SEEK SET):_1 seek(handle,pos,SEEK SET);/fread(buff,5121,1,fp);read(handle,buff,512);flag=buffO;count=buffl;items=buff2;prev=*(UINT4*)(buff+4);next=*(UINT4*)(buff-i;curp=O;return 0;/-Next is DBF-DBF:BF()Installed=O;First=NULL;pIDX=NULL;handle=l;buff=NULL;/-SwapBuffer=NULL;MaxRecNum=O;CurRecNum=O;/-curren t_ recno=record_no=01;record_ len=O;NameO=f xOf;changeflag=O;dbferrno=0;fi eldvalue=NULL;DBF:r DBF()/i f (First!=NULL)delete First;Fir st=NULL;)if(SwapBuffer!=NULL)delete SwapBuffer;SwapBuffer=NULL;MaxRecNum=O;CurRecNum=O;if(pIDX!=NULL)delete First;pIDX=NULL;i f (handle!=-l)/this:close(handle);handle=-l;if(buff!=NULL)delete buff;buff=NULL;i f (fi eldvalue!=NULL)delete fieldvalue;fi eldvalue二NULL;return;INT2 DBF:Cl ear()memset(buff,record_len);return 0;INT2 DBF:AppendBlank()(CHAR tempbufl 00;UI NT4 temprecno;INT2 i;INT4 o ffset;/-i f (!Installed)/Not open this filedbferrno=CassNotInit:sp rin
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号