dbf文件C、C++的操作库程序.doc_第1页
dbf文件C、C++的操作库程序.doc_第2页
dbf文件C、C++的操作库程序.doc_第3页
dbf文件C、C++的操作库程序.doc_第4页
dbf文件C、C++的操作库程序.doc_第5页
已阅读5页,还剩43页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

求:dbf文件c/c+的操作库程序。/*dbfop for c+ v1.00 ,1995.1.10develop by john,liaomodified by zhanghao. 1998.05.18this module include the c+ headfile dbfop.hpp,and c+ resource file dbfop.cpp.this module is develop for use dbf(dbaseiii,dbaseii,mfoxbase,foxpro 2.x)and idx(mfoxbase).but use idx only allow read or change the field thatisnt key word.support netware share .flielock,fileunlock,recordlock,recordunlock.*/* -the class dbf is interface to custom,all function that givencan be invoked by use the class dbf.-1995.7.29 change file option fxxx to xxx like _fsopen replace with sopen1995.7.31 change dowith option when type=n1995.7.31 add option dbf:append(),dbf:clear();1998.5.18 add foxpro 2.x dbf process.-*/#include stdafx.h#ifdef debug#define debugm afxmessagebox#define new debug_new#endifstatic int2 ccc(char *,int2,int2);int2 ccc(char * ptsr,int2 len,int2 bit) char temp130,temp1130,i1; char temp230,temp2230,i2; int2tempi,i; char * ps,*ps1; for(ps1=ptsr;(*ps1= )&(*ps1!=x0);ps1+); ps=strchr(ps1,.); if(ps=null)/ not have . strcpy(temp1,ps1); temp20=x0; else *ps=x0; strcpy(temp1,ps1); ps+; strcpy(temp2,ps); i1=len-(bit?(bit+1):0); if(int)strlen(temp1);(int)i1) strncpy(temp11,temp1,i1); temp11i1=x0; else tempi=i1-strlen(temp1); for(i=0;i;0) if(int)strlen(temp2);(int)bit) strncpy(temp22,temp2,bit); temp22bit=x0; else i2=strlen(temp2); tempi=bit-strlen(temp2); strcpy(temp22,temp2); for(i=0;i;=(int2)items-1) return -2; curp+; / double return 0;int2 idx_block:find(char * key) int2 compi=keylen; char *p=buff+12; int2 retcode,i; if(int)strlen(key)(int)keylen) compi=strlen(key); for(i=0,p=buff+12;i;=2) / .and. this is a leaf or leaf&root node curp=i; return 0; / founded ,ok return to master else / .and. this is a frame or root node curp=i; return -10; / this is a root,maybe in gaven block if(retcode0) /if the key curent key in idx file if(flag;handle!=-1) close(handle); handle=-1; / open function open the idx fileint2 idx:pen(char * filename) char buff30; / fp=_fsopen(filename,rb,sh_denynone); / change by liaoj int 1999.3.22 handle=sopen(filename,_o_rdonly|_o_binary,_sh_denyno,_s_iread); /* handle=sopen(filename,o_rdwr|o_binary|o_denynone, sh_denynone,s_iread|s_i_write); */ / if(fp=null) return -1; if(handle=-1) return -1; if(_lseek(handle,0,seek_set)!=0) return -1; if(read(handle,buff,30)!=30) return -1; rootpos=*(uint4 *)buff; blocks=*(uint4 *)(buff+; key_len=*(int2 *)(buff+12); block.setkeylen(key_len); block.readblock(this-;handle,rootpos); while(block.getflag();handle,block.getresult(); gohome(); return 0;int2 idx:rev() uint4 prevblock; if(block.prev()!=0) prevblock=block.getprev(); if(prevblock=0xffffffffl) return -1; block.readblock(this-;handle,(int4)prevblock); block.end(); return 0;int2 idx:next() uint4 nextblock; if(block.next()!=0)/ is already in the last node in this block nextblock=block.getnext(); if(nextblock=0xffffffffl) return -2; block.readblock(this-;handle,(int4)nextblock); block.home(); return 0;int2 idx:find(char * key) int2 retcode; block.readblock(this-;handle,rootpos); for(; retcode=block.find(key); switch(retcode) case 0: return 0; case -1: return -1; case -2: if(block.getprev()=(uint4)0xffffffffl) return -1; else block.readblock(this-;handle,block.getprev(); break; case -3: if(block.getnext()=(uint4)0xffffffffl) return -1; else block.readblock(this-;handle,block.getnext(); break; case -10: block.readblock(this-;handle,block.getresult(); break; default: / - / fatal error : return code is not allow / in class idx_block:find(char * ); / - break; int2 idx:skip() return next();int2idx:gohome() while(block.getprev()!=(uint4)0xffffffffl) block.readblock(this-;handle,block.getprev(); ; block.home(); return 0;int2 idx:goend() while(block.getnext()!=(uint4)0xffffffffl) block.readblock(this-;handle,block.getnext(); ; block.end(); return 0;uint4 idx_block:getresult() char tf5; char * p=buff+12+curp*(keylen+4); p+=keylen; tf3=p0;tf2=p1;tf1=p2;tf0=p3; return *(uint4 * )tf;/int2 idx_block:readblock(file * fp,uint4 pos)int2 idx_block:readblock(int2 handle,uint4 pos) / fseek(fp,pos,seek_set); _lseek(handle,pos,seek_set); / fread(buff,512l,1,fp); read(handle,buff,512); flag=buff0; count=buff1; items=buff2; prev=*(uint4 *)(buff+4); next=*(uint4 *)(buff+; curp=0; return 0;/-next is dbf -dbf:bf() installed=0; first=null; pidx=null; handle=-1; buff=null; / - swapbuffer=null; maxrecnum=0; currecnum=0; / - current_recno=record_no=0l; record_len=0; name0=x0; changeflag=0; dbferrno=0; fieldvalue=null;dbf:dbf() if(first!=null) delete first; first=null; if(swapbuffer!=null) delete swapbuffer; swapbuffer=null; maxrecnum=0; currecnum=0; if(pidx!=null) delete first; pidx=null; if(handle!=-1) / this :close(handle); handle=-1; if(buff!=null) delete buff; buff=null; if(fieldvalue!=null) delete fieldvalue; fieldvalue=null; return;int2 dbf:clear() memset(buff, ,record_len); return 0;int2 dbf:appendblank() char tempbuf100; uint4temp_recno; int2 i; int4 offset; /- if(!installed)/ not open this file dbferrno=classnotinit; sprintf(this-;dbferrmsg,classnotinit!; return classnotinit; if(_lseek(handle,0l,seek_set)!=0) dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!; return this-;dbferrno; if(read(handle,tempbuf,!= this-;dbferrno=readfileerror; sprintf(this-;dbferrmsg,readfileerror!; return this-;dbferrno; temp_recno=+(*(uint4*)(tempbuf+4); if(_lseek(handle,0l,seek_set)!=0) this-;dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!; return dbferrno; if(_write(handle,tempbuf,!= this-;dbferrno=writefileerror; sprintf(this-;dbferrmsg,writefileerror!; return dbferrno; offset=(int4)head_len+(temp_recno-1l)*record_len; _lseek(handle,offset,seek_set); for(i=0;i;reopen(); this-;goto(temp_recno); return 0;int2 dbf:append() char tempbuf100; uint4temp_recno; int4 offset; if(!installed)/ not open this file dbferrno=classnotinit; sprintf(this-;dbferrmsg,classnotinit!; return classnotinit; if(_lseek(handle,0l,seek_set)!=0) dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!; return seekfileerror; if(read(handle,tempbuf,!= this-;dbferrno=readfileerror; sprintf(this-;dbferrmsg,readfileerror!; return dbferrno; temp_recno=+(*(uint4*)(tempbuf+4);/ recordnum+1; if(_lseek(handle,0l,seek_set)!=0) this-;dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!); return dbferrno; if(_write(handle,tempbuf,!= this-;dbferrno=writefileerror; sprintf(this-;dbferrmsg,writefileerror!); return dbferrno; offset=(int4)head_len+(temp_recno-1l)*record_len; if(_lseek(handle,offset,seek_set)!=offset) this-;dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!); return dbferrno; _write(handle,buff,(uint2)record_len); _write(handle,x1a,1); this-;reopen(); this-;goto(temp_recno); return 0;int2 dbf:dbf_wbuff() /char tempbuf100; int4 offset; offset=(int4)head_len+(current_recno-1l)*record_len; if(current_recno;dbferrmsg,recordoutofrange!); return dbferrno; if(changeflag=0) dbferrno=dbfok; sprintf(this-;dbferrmsg,dbfok!); return dbfok; if(_lseek(handle,offset,seek_set)!=offset) dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!); return dbferrno; if(_write(handle,buff,(uint2)record_len)!=(uint2)record_len) dbferrno=writefileerror; sprintf(this-;dbferrmsg,writefileerror!); return dbferrno; dbferrno=dbfok; sprintf(this-;dbferrmsg,dbfok!); return dbfok;int2 dbf:dbf_buff() int4 offset=(int4)head_len+(current_recno-1l)*record_len; if(current_recno;dbferrmsg,recordoutofrange!); return dbferrno; if(_lseek(handle,offset,seek_set)!=offset) dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!); return dbferrno; if(:eof(handle) dbferrno=seekfileerror; sprintf(this-;dbferrmsg,seekfileerror!); return dbferrno; if(read(handle,buff,(uint2)record_len)!=(uint2)record_len) dbferrno=readfileerror; sprintf(this-;dbferrmsg,readfileerror!); return dbferrno; changeflag=0; dbferrno=0; sprintf(this-;dbferrmsg,dbfok!); return 0;int2 dbf:zap() char tempbuf100; if(!installed)/ not open this file dbferrno=classnotinit; sprintf(this-;dbferrmsg,classnotinit!); return dbferrno; _lseek(handle,0l,seek_set); /if(fread(tempbuf,32l,1l,fp)!=1) if(read(handle,tempbuf,32)!=32) this-;close(); dbferrno=notdbffile; sprintf(this-;dbferrmsg,notdbffile!); return dbferrno; *(uint4 *)(tempbuf+4)=0l; / record_no if(chsize(handle,head_len)!=0) / - this-;dbferrno=chsizefileerror; sprintf(this-;dbferrmsg,chsizefileerror!); return dbferrno; _lseek(handle,0l,seek_set); if(_write(handle,tempbuf,32)!=32) /this-;close(); this-;dbferrno=writefileerror; sprintf(this-;dbferrmsg,writefileerror!); return writefileerror; _lseek(handle,0l,seek_end); _write(handle,x1ax0,2); maxrecnum=0; currecnum=0; lock_flag=0; reopen(); dbferrno=dbfok; sprintf(this-;dbferrmsg,dbfok!); return this-;dbferrno;int2 dbf:open(char * filename,int2 openmode_par,int2 dbftype_par) char tempbuf100; int2i,j,fieldoffset; struct field * tpf; if(installed) this-;close(); strcpy(name,filename); openmode=openmode_par; dbftype=dbftype_par; if(openmode=readwrite) handle=_sopen(name,_o_rdwr|_o_binary,_sh_denyno,_s_iread|_s_iwrite); else handle=_sopen(name,_o_rdonly|_o_binary,_sh_denyno,_s_iread); if(handle=-1) dbferrno=fileopenfailure; sprintf(this-;dbferrmsg,fileopenfailure!); return dbferrno; _lseek(handle,0l,seek_set); if(read(handle,tempbuf,32)!=32) this-;close(); dbferrno=readfileerror; sprintf(this-;dbferrmsg,readfileerror!); return dbferrno; record_no=*(uint4 *)(tempbuf+4); head_len=*(uint2 *)(tempbuf+8); record_len=*(uint2*)(tempbuf+10); fieldnum=(head_len)/32-1; / need automatic detect the dbf file type is foxbase or clipper if(dbftype=autodetect) if(head_len-1)%32=0) dbftype=foxbase; else dbftype=clipper; if(buff!=null) delete buff; buff=null; buff=(char *) new charrecord_len+20; if(buff=null)#ifdef

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论