>> Read No. 1944 article  
유닉스용 RZJOIN 소스

등록 2001-12-03 15:55:00     조회 8
이름 벌레잡이    

		전에 하이텔에 올렸던 소스입니다. 인터넷에 올라온 동영상 파일들을 보면
xxx.001, xxx.002 이렇게 이름 붙은 것들이 있죠? rzsplit라는 유틸리티로
분할한 것으로 rzjoin 유틸리티로 합칠 수 있습니다.
리눅스에서 어떻게 이런 파일을 합쳐볼려구 제가 어찌어찌 만들어 봤습니
다. 소스는 허접하지만, 지금까지 문제없이 잘 동작하네요. 어쩌다 윈도우즈
에서는 잘 join이 안되는 파일도 이걸로는 잘 합쳐집니다.
-- 신기하다 --;;
 아래는 소스입니다. 유닉스에서 cc -o rzjoin rzjoin.c 하면 컴팔됩니다.
사용법은 rzjoin xxx.001 입니다.
 /*
 * Made by Jung, Doyou(벌레잡이) <doyou89 at kornet.net>
 * 2001.06.17
 *
 * Join the split files by rzsplit.
 */
 #include <stdio.h>
 /* The return value of functions */
#define SUCCESS         1
#define FAIL            0
 /* The maximum header size to be read by RZjoin */
#define MAX_HEADER_SIZE 100
#define MAX_BUFFER_SIZE 102400
 /* tag */
#define END_OF_HEADER   0x2F
#define SPACE           0x20
 /*#define DEBUG*/
 int RZ_openFile(char *p_sFileName, FILE **fp, char *p_sHeader)
{
    int iRet;
     *fp = fopen (p_sFileName, "r");
    if ( *fp == NULL)
        return FAIL;
     /* read header from the file */
    iRet = fread (p_sHeader, MAX_HEADER_SIZE, 1, *fp);
    if ( iRet == 0) {
        fclose (*fp);
        return FAIL;
    }
     return SUCCESS;
}
 int RZ_openResultFile(char *p_sFileName, FILE **fp)
{
    *fp = fopen (p_sFileName, "w");
    if ( *fp == NULL)
        return FAIL;
     return SUCCESS;
}
 int RZ_getResultFileName_Size(int *p_iByteRead, char
*p_sResultFileName, int *p_iResultFileSize, char *p_sHeader)
{
    int iByteRead, i;
    char sFileSize[21];
     iByteRead = 0;
 #ifdef DEBUG
    printf ("Get the output filename.");
#endif
    /* read the result file name */
    while ( *p_sHeader != END_OF_HEADER ) {
        /* 3 consecutive spaces means end of filename. */
        if ( *p_sHeader == SPACE &&
                *(p_sHeader+1) == SPACE &&
                *(p_sHeader+2) == SPACE )
            break;
         *p_sResultFileName++ = *p_sHeader++;
        iByteRead++;
    }
 #ifdef DEBUG
    printf ("put ending mark & skip the spaces.");
#endif
     /* if there is no filename, it's error. */
    if ( iByteRead == 0 || *p_sHeader == END_OF_HEADER )
        return FAIL;
     /* put ending mark */
    *p_sResultFileName = 0;
#ifdef DEBUG
    printf ("The output filename is %s.", p_sResultFileName);
#endif
     /* skip the spaces */
    while ( *p_sHeader == SPACE ) {
        p_sHeader++;
        iByteRead++;
    }
 #ifdef DEBUG
    printf ("Get the size of the output file.");
#endif
    i = 0;
    /* read the result file size */
#ifdef DEBUG
    printf ("header : %d.", *p_sHeader);
#endif
    while ( *p_sHeader != END_OF_HEADER ) {
#ifdef DEBUG
    printf ("header : %d.", *p_sHeader);
#endif
        sFileSize[i++] = *p_sHeader++;
        iByteRead++;
    }
    sFileSize[i] = 0; /* put ending mark */
 #ifdef DEBUG
    printf ("convert filesize string to integer.");
#endif
    /* convert filesize string to integer. */
    *p_iResultFileSize = atoi(sFileSize);
    if ( *p_iResultFileSize == 0 ) {
#ifdef DEBUG
    printf ("file size is %s.", sFileSize);
#endif
        return FAIL;
    }
 #ifdef DEBUG
    printf ("Get the start point of the result file.");
#endif
    /* set the start point of the result file */
    *p_iByteRead = iByteRead + 1;
     return SUCCESS;
}
 int RZ_getNextFile(char *p_sFileName, FILE **fp)
{
    int iLen;
    char *p_ptr;
     iLen = strlen (p_sFileName);
    p_ptr =  p_sFileName + iLen - 1;
     if ( *p_ptr < '9' )
        *p_ptr += 1;
    else {
        *p_ptr = '0';
        if ( *(p_ptr-1) < '9' )
            *(p_ptr-1) += 1;
        else {
            *(p_ptr-1) = '0';
            if ( *(p_ptr-2) < '9' )
                *(p_ptr-2) += 1;
            else
                return FAIL;
        }
    }
     *fp = fopen (p_sFileName, "r");
    if ( *fp == NULL) {
#ifdef DEBUG
    printf ("file, %s do not exists.", p_sFileName);
#endif
        return FAIL;
    }
     printf ("Read %s", p_sFileName);
     return SUCCESS;
}
 int RZ_joining(int iByteRead, int iResultFileSize, char *p_sFileName,
char *p_sResultFileName)
{
    char sBuffer[MAX_BUFFER_SIZE+1];
    int  iRet, iReadSize;
    int  iTotalWrite;
    FILE *fp, *fpOut;
     /* open result file to be joined. */
    if ( !RZ_openResultFile (p_sResultFileName, &fpOut) ) {
        printf ("Error in opening file, %s.", p_sResultFileName);
        return FAIL;
    }
     /* Initialize filename */
    p_sFileName[strlen(p_sFileName)-1] = '0';
    RZ_getNextFile (p_sFileName, &fp);
     /* read out the header scope. */
    fread (sBuffer, iByteRead, 1, fp);
     iTotalWrite = 0;
    do {
         /* do the file copy */
        while ( (iReadSize = fread (sBuffer, 1, MAX_BUFFER_SIZE, fp)) !
= 0 ) {
            iRet = fwrite (sBuffer, iReadSize, 1, fpOut);
            iTotalWrite += iReadSize;
             if ( iRet == 0 ) {
                printf ("Error in writing the result file.");
                return FAIL;
            }
        }
        fclose (fp);
         iRet = RZ_getNextFile (p_sFileName, &fp);
#ifdef DEBUG
    printf ("The result of RZ_getNextFile() is %d.", iRet);
#endif
     } while ( iRet ) ;
     if ( iTotalWrite != iResultFileSize ) {
        printf ("Differ in file size!!!");
        printf ("Expected file size : %d, real writing size : %d",
                iResultFileSize, iTotalWrite);
        return FAIL;
    }
     /*fclose (fp);*/
    fclose (fpOut);
     return SUCCESS;
}
  main(int argv, char *argc<>)
{
    char sFileName[256];
    int  iByteRead;
    char sResultFileName[256];
    int  iResultFileSize;
    char sHeader[MAX_HEADER_SIZE+1];
    FILE *fp;
     if ( argv < 2 ) {
        printf ("");
        printf ("Author : Jung, Doyou(벌레잡이)
<doyou89 at kornet.net>");
        printf ("         made at 19 Jun, 2001.");
        printf ("");
        printf ("USAGE : rzjoin <file-to-be-joined>");
        printf ("");
        exit (0);
    }
    strcpy (sFileName, argc[1]);
#ifdef DEBUG
    printf ("file, %s will be open.", sFileName);
#endif
     /* open the source file to be joined. */
    if ( !RZ_openFile (sFileName, &fp, sHeader) ) {
        printf ("Error in opening file, %s.", sFileName);
        exit (1);
    }
#ifdef DEBUG
    printf ("file, %s opened.", sFileName);
#endif
      /* get the result filename and size */
    if ( !RZ_getResultFileName_Size (&iByteRead, sResultFileName,
&iResultFileSize, sHeader) ) {
        printf ("Could not get the result filename and size.");
        exit (1);
    }
     fclose (fp);
     printf ("");
    printf ("result file name : %s",sResultFileName);
    printf ("result file size : %i",iResultFileSize);
    printf ("");
     /* start joining */
    if ( !RZ_joining (iByteRead, iResultFileSize, sFileName,
sResultFileName) ) {
        printf ("Error in joining file, %s.", sResultFileName);
        exit (1);
    }
     printf ("");
    printf ("rzjoin complete..");
 }--emoticon
 |____
이름
암호


>> 관련글
1944 유닉스용 RZJOIN 소스  벌레잡이  2001.12.03  ....
  답장 RE: 호오.. ^^;;  맨드라미  2001.12.03  ....
  목록보기 윗글 아랫글
글쓰기
답장쓰기 수정 삭제
정규표현식 [ 상세 검색 ]
페이지로딩: [ 0.92 초 ] 작업시간: [ 0.06 초 ]

Copyleft 1999-2026 by JSBoard Open Project
Theme Designed by IDOO All right reserved
[TOP]

적수네 동네
+
| 적수네 동네
| 공부방
| 리눅스 잡지 서고
| LSN 소스
| 링크 모음
+---+
게시판
+
| 떠들어보세!
| 질문과 답변
| 새소식과 정보
| 1원짜리 팁?
| 대화방
+---+
칼럼?
+
| 세하 훔쳐보기
| Welcome2nite
| 혜진의 염장판
+---+
리눅스 상표권
+
| 반대 서명란
| 토론 게시판
+---+
GNU
+
| GNU 선언문
| GNU GPL
| GNU 미러 목록
+---+
프로젝트?
+
| 리눅스카운터
| RC5DES
| 실질헌법 제작
+---+
커널 소식
+
| 안정 버젼: 2.4.14
+---+
테마 선택
+
LSN 방송국?
+
| OFF AIR
+---+
회원
+
| 로그인
+---+
[ 적수네 동네 ] [ 리눅스 상표권 독점 반대 ] [ 한글 리눅스 문서 프로젝트 ] [ KrLine ] [ 사랑넷 ] [ Valid HTML 4.0! ] [ SlashDot ] [ Freshmeat ]
Copyleft (C) 1998-2001 Byeong-Chan Kim . License
TIME: 1791048983
System by WYZsoft, HDD by I.O.Linux, Mizi Research, Embryo, WOWLINUX, Domain by SarangNet, Network by KrLine.