tool.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:3k
- // loadmylib.cpp: implementation of the loadmylib class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "tool.h"
- #include "stdio.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- LinkStr:: LinkStr()
- {
- str[0]=0;
- Next=NULL;
- }
- LinkStr:: ~LinkStr()
- {
- ;
- }
- ///////////////////////////////////////////////
- // 插入扩展识别码
- // 去掉大于4后面的编码后插入
- int tool:: InsertStr(char *ss)
- {
- unsigned char cc;
- char temss[200];
- LinkStr *p,*np;
- strcpy(temss,ss);
- cc=temss[0];
- temss[4]=0;
- p=&linkstrHead[cc];
- while(p->Next)
- {
- if(strcmp(p->Next->str,temss)>=0)
- break;
- p=p->Next;
- }
- if(p->Next!=NULL)
- {
- if(strcmp(temss,p->Next->str)==0)
- return -1;
- }
- np=new LinkStr;
- strcpy(np->str,temss);
- np->Next=p->Next;
- p->Next=np;
- NodeNum++;
- return 0;
- }
- tool::tool()
- {
- int i;
- for(i=0;i<256;i++)
- linkstrHead[i].Next=NULL;
- NodeNum=0;
- }
- int tool::OutExCode(HANDLE outfp)
- {
- LinkStr *p;
- long i,end=0;
- char tem[5];
- DWORD retbyteNum;
- //WriteFile(outfp,&NodeNum,4,&retbyteNum,0); //输出个数
- for(i=1;i<256;i++)
- {
- p=linkstrHead[i].Next;
- while(p!=NULL)
- {
- sprintf(tem,"%-4s",p->str);
- WriteFile(outfp,tem,5,&retbyteNum,0);
- p=p->Next;
- }
- }
- return 0;
- }
- tool::~tool()
- {
- }
- //
- long tool::TranChar(char *fileName,long num,char *cc,char *tranCh)
- {
- HANDLE infp;
- HANDLE outfp;
- char buf[5000];
- char nf[1000];
- unsigned long tt=0, i,ret=0,lon=1000;
- sprintf(nf,"%st",fileName);
- infp = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
- if(infp==INVALID_HANDLE_VALUE)
- {
- MessageBox(0,"TranChar函数装载文件失败","tt.txt文件不存在于当前目录",0);
- return -1;
- }
- outfp= CreateFile(nf, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0);
- if(infp==INVALID_HANDLE_VALUE)
- {
- MessageBox(0,"建立输出文件失败","tt.txtt文件不能建立",0);
- return -1;
- }
- ReadFile(infp, buf, lon+2,&ret, NULL);
- if(ret==lon+2)
- {
- ret=lon;
- while(ret>0)
- {
- for(i=0;i<ret+2;i++)
- {
- if(buf[i]<num && buf[i+2]==cc[0])
- buf[i+2]=tranCh[0];
- }
- WriteFile(outfp, buf, ret, &ret, NULL);
- buf[0]=buf[ret];
- buf[1]=buf[ret+1];
- ReadFile(infp, &buf[2], lon, &ret, NULL);
- }
- WriteFile(outfp, buf, 2, &ret, NULL);
- }
- else
- {
- for(i=0;i<ret-2;i++)
- {
- if(buf[i]<num && buf[i+2]==cc[0])
- buf[i+2]=tranCh[0];
- }
- WriteFile(outfp, buf, ret, &ret, NULL);
- }
- CloseHandle( infp);
- CloseHandle( outfp);
- MessageBox(0,"Over","转换结束",0);
- return 0;
- }