dbf文件C、C的操作库程序

上传人:缘*** 文档编号:333287843 上传时间:2022-09-01 格式:PDF 页数:48 大小:3.22MB
返回 下载 相关 举报
dbf文件C、C的操作库程序_第1页
第1页 / 共48页
dbf文件C、C的操作库程序_第2页
第2页 / 共48页
dbf文件C、C的操作库程序_第3页
第3页 / 共48页
dbf文件C、C的操作库程序_第4页
第4页 / 共48页
dbf文件C、C的操作库程序_第5页
第5页 / 共48页
点击查看更多>>
资源描述

《dbf文件C、C的操作库程序》由会员分享,可在线阅读,更多相关《dbf文件C、C的操作库程序(48页珍藏版)》请在金锄头文库上搜索。

1、求: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 FOXBA

2、SE).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

3、 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

4、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*p

5、s=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-s

6、trJ 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;retur

7、n 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 e

8、namef: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(ha

9、ndle,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.G

10、e 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-;handl

11、e,(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.GetP

12、revO);)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 Nex

13、t();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;CHA

14、R*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=b

15、uffl;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 DB

16、F()/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

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号