FILECUT a linux console c source

#include
#include
#include
#include

/*
void version(void);
//print banner
void version(void)
    {
    printf("\n");
    printf("\t++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
    printf("\t+ \tFILECUT [VERSION1.1] by Alone             +\n");
    printf("\t+ \t(C) Copyright 2008-2010                  +\n");
    printf("\t+\tEmail:c4rp3nt3r@gmail.com                 +\n");
    printf("\t++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n");
    }

*/

void hzcount(char * hz);


FILE *fp1,*fp2;

int main(int argc,char ** argv)
    {
   
    int i;
    long n,s_max_f,j=0;        //single max content of file that will be created
    int fcoutn=0;            //number of files that created
    char data[257]={'\0'};        //databuffer for read then write
   
    char hz[20]={"_0001."};
    char name[30]={'\0'};
    char filehz[20]={'\0'};
    char tran[30]={'\0'};        //get the file name without .hz
    char curdir[256]={'\0'};    //the buffer to store the current dir
    char tmpdir[256]={'\0'};    //tempdir
   
    char *p;            //tmp pointer

    /*version(); //print banner*/

    if(argc != 3)
        {
        printf("[-]Please    Input the file name!\n");
        printf("[*]Usage: argv[0] \n");
        exit(0);
        }
    s_max_f=atoi(argv[2]);
    //printf("s_max_f).........%d",s_max_f);
   


    strcpy(tran,argv[1]);/*去掉路径得到文件名*/
    p=strrchr(tran,'/');
    if(p!=NULL)
        {
        strcpy(tran,p+1);
        }
    //printf("p ...%s\ntran...%s",p,tran);

    for(i=0;tran[i]!='\0';i++)
        {
        if(tran[i]=='.')
            {
            strcpy(filehz,&tran[i+1]);
            tran[i]='\0';
            //printf("now the filehz is ...%s",filehz);
            break;
            }
        }
    /*后缀处理*/

    strcpy(name,tran);

    //mkdir 需为绝对路径 后面是0777
    getcwd(curdir,256);
    strcat(curdir,"/");
    strcat(curdir,tran);

    //printf("tran should be ...%s\n",tran);
    //printf("curdir should be ...%s\n",curdir);
    mkdir(curdir,0777);
   
    strcat(curdir,"/");
    strcpy(tmpdir,curdir);
    //printf("the name should be ddd...%s\n",name);


    strcat(hz,filehz);
    //printf("the hz should be _0001.txt%s\n",hz);
    strcat(name,hz);
    //printf("the name should be ddd0001.txt%s\n",name);
    strcat(tmpdir,name);
    //printf("the tmpdir should be ......%s\n",tmpdir);
   
    /*文件操作*/
    /*打开源文件*/

    if((fp1=fopen(argv[1],"rb"))==NULL)
        {
        printf("\n cannot open %s \n",argv[1]);
        exit(0);
        }

    /*打开目标文件*/
    if((fp2=fopen(tmpdir,"wb"))==NULL)
        {
        printf("\n cannot open %s \n",tmpdir);
        exit(0);
        }
   
    n=0;   
    while(!feof(fp1))
        {
       
        fread(data,256,1,fp1);n++;
        if(n*256>s_max_f*1024)
            {
            fclose(fp2);
            fcoutn++;

            hzcount(hz);
            strcpy(name,tran);
            strcat(name,hz);
            strcpy(tmpdir,curdir);
            strcat(tmpdir,name);
           
            if((fp2=fopen(tmpdir,"wb"))==NULL)
                {
                printf("\ncannot open %s.",name);
                exit(0);
                }
            n=0;
            }


        fwrite(data,256,1,fp2);
       
        for(j=0;j<257;j++)>

0 评论: