C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[38909] Re:비주얼 씨 -> c builder 변환 가능한가요?
멀더 [mulder] 1397 읽음    2005-01-25 17:23
안녕하세요. 멀더입니다.
고수는 아니지만, VC Class를 아래와 같이 대충(초간단, 아주대충)만들어 보았습니다.
테스트는 거의 안하였습니다. 완료되시면 함 올려 주세요.
그리고 NONE-THREAD-SAFTY 합니다.

그리고 문제의 함수는 상당히 이상하더군요... TEXT 라인의 집합을 Binary로 오픈하는
이유는 몬가요 ???



#include <stdio.h>
#include <string>

namespace NONE_TESTED {

    class CFile {
    public:
        static UINT modeRead;
        static UINT modeWrite;
        static UINT typeText;
        static UINT typeBinary;

    };

    UINT CFile::modeRead   = 0x01;
    UINT CFile::modeWrite  = 0x02;
    UINT CFile::typeText   = 0x04;
    UINT CFile::typeBinary = 0x08;


    class CString {
    public:
        std::string s;

        CString() {
        }

        CString(char* AStr) {
            Set(AStr);
        }
        CString(const char* AStr) {
            Set(AStr);
        }

        CString& operator= (char* AStr) {
            Set(AStr);
            return *this;
        }

        bool operator!= (CString AStr) {
            return (AStr.s != this->s);
        }

        CString& Left (int nCount) {
            static CString ss ( s.substr(0, nCount).c_str() );
            return ss;
        }

        void Set(char* AStr) {
            s = AStr;
        }
        void Set(const char* AStr) {
            s = AStr;
        }
        UINT GetLength () {
            return s.length();
        }
        CString& TrimLeft() {
            AnsiString ss = s.c_str();
            s = ss.TrimLeft().c_str();
            return *this;
        }

        UINT Find(char c, UINT pos) {
            return s.find(c, pos);
        }

        UINT Find(const char* c, UINT pos) {
            return s.find(c, pos);
        }

        int Delete(int iIndex, int nCount = 1 ) {
            s.erase(iIndex, nCount);
            return nCount;
        }

    };

    class CStdioFile : public CFile {
    public:
        FILE* f;

        CStdioFile() {
            f = 0;
        }

        virtual FILE* Open(
            LPCTSTR lpszFileName,
            UINT nOpenFlags, void* x) {
                char AMode[3];

                memset(AMode, 0, 3);
                if (nOpenFlags & CFile::modeRead) {
                    AMode[0] = 'r';
                }
                if (nOpenFlags & CFile::modeWrite) {
                    AMode[0] = 'w';
                }
                if (nOpenFlags & CFile::typeText) {
                    AMode[1] = 't';
                }
                if (nOpenFlags & CFile::typeBinary) {
                    AMode[1] = 'b';
                }

                f = fopen(lpszFileName, AMode );
                return f;
        }

        virtual FILE* Close() {
            fclose(f); f = 0;
        }


        virtual UINT GetLength() {
            UINT fileSize = 0;
            if(f) {
                fseek (f, 0, SEEK_END);
                fileSize = ftell (f);
                fseek (f, 0, SEEK_SET);
            }
            return fileSize;
        }

        virtual void SeekToBegin() {
            fseek (f, 0, SEEK_SET);
        }

        virtual void SeekToEnd() {
            fseek (f, 0, SEEK_END);
        }

        virtual UINT GetPosition() {
            return ftell(f);
        }

        virtual BOOL ReadString(CString& rString) {
            char s[2048+1];

            memset(s, 0, 1024);
            if( fgets (s, 2048, f) ) {
               rString = s;
               return TRUE;
            }
            return FALSE;
        }


    };

    // 제가 만데로 만든 데이터형...!!!
    struct ParamT {
        char Name[100];
        long Address;
        long Size;
    };
    struct  t_struct {
        int Count;
        ParamT Param[100];
    };



    //------------------------------------
    ReadData( char* pFileName , t_struct* pParamList )
    {
        char *cTempNoUse;
        int i;
        bool bParamFound;
        CStdioFile pFile;
        unsigned long iFileSize;

        if(NULL == pFile.Open(pFileName, CFile::modeRead | CFile::typeBinary, 0))return 1;

        iFileSize = pFile.GetLength();

        for( int iI = 0  ; iI < pParamList->Count ; iI++ )
        {
            bParamFound = false;
            pFile .SeekToBegin();

            while ( pFile.GetPosition()  < iFileSize  )
            {
                CString clStr;
                pFile.ReadString ( clStr );
                if( !clStr.GetLength() )
                    continue;

                clStr.TrimLeft();

                i = clStr.Find( " " , 0 ) ;
                //String clName = clStr.Left( i ) ;
                CString clName = clStr.Left( i ) ;
                clStr.Delete( 0 , i );
                clStr.TrimLeft();


                if( clName != CString(pParamList->Param[iI].Name) )
                    continue;

                i = clStr.Find( " " , 0 ) ;
                clStr.Delete( 0 , i );
                clStr.TrimLeft();

                i = clStr.Find( " " , 0 ) ;
                //pParamList->Param[iI].Address = strtol( (LPCTSTR)clStr, &cTempNoUse, 0x10 );
                pParamList->Param[iI].Address = strtol( clStr.s.c_str(), &cTempNoUse, 0x10 );
                clStr.Delete( 0 , i );

                clStr.TrimLeft();
                i = clStr.Find( " " , 0 ) ;
                //pParamList->Param[iI].Address += atoi( clStr.Left( i ) );
                pParamList->Param[iI].Address += atoi( clStr.Left( i ).s.c_str() );
                clStr.Delete( 0 , i );


                clStr.TrimLeft();
                i = clStr.Find( " " , 0 ) ;
                //pParamList->Param[iI].Size = atoi( clStr.Left( i ) );
                pParamList->Param[iI].Size = atoi( clStr.Left( i ).s.c_str() );

                bParamFound = true;
                break;
            }

            if( !bParamFound )
            {
                pFile.Close();
                return 1;
            }
        }

        pFile.Close();
        return 0;
    }


};

// 제가 테스트하였는데, text를 바이너리로 만든 파일이 없어서,
// 실제 테스트는 못하였습니다...
using namespace  NONE_TESTED;
void __fastcall TForm2::Button1Click(TObject *Sender)
{
    CStdioFile pFile;
    unsigned long iFileSize;
    LPCTSTR pFileName = "NBSVR.exe";

    if(NULL == pFile.Open(pFileName, CFile::modeRead | CFile::typeBinary, 0)) return;

    iFileSize = pFile.GetLength();

    pFile .SeekToBegin();
    while ( pFile.GetPosition()  < iFileSize  )
    {
        CString clStr;
        pFile.ReadString ( clStr );
        if( !clStr.GetLength() )
            break;
        clStr.TrimLeft();
        int i = clStr.Find( " " , 0 );
    }


    pFile.Close();

}
//---------------------------------------------------------------------------



빌더 초짜 님이 쓰신 글 :
: 안녕하세요...여러 고수님들
:
: 제가 프로그램을 하나 보다가 문제가 있어서 이렇게 글 올립니다..
:
: 다름이 아니라 제가 비주얼 씨로 구현된 함수를 하나 받아서 이걸 다시
:
: c builder로 변환 하려구 하는데 잘 안되네요..ㅜ.ㅜ
:
: 파일을 읽어들이는 부분인데요..
:
: 그래서 이렇게 염치불구하고 이렇게 글 올립니다..
:
: 고수님들 ..한심해 보일지 모르지만 한수 부탁드리겠읍니다...
:
: 받은 소스는 아래와 같습니다..
:
: //------------------------------------
: ReadData( char* pFileName , t_struct* pParamList )
: char *cTempNoUse;
:     int i;
:     bool bParamFound;
:         CStdioFile pFile;       
:     unsigned long iFileSize;
:
:         if(NULL == pFile.Open(pFileName, CFile::modeRead | CFile::typeBinary, NUL))return 1;
:            
:     iFileSize = pFile.GetLength();
:    
:     for( int iI = 0  ; iI < pParamList->Count ; iI++ )
:     {
:         bParamFound = false;
:         pFile .SeekToBegin();
:            
:         while ( pFile.GetPosition()  < iFileSize  )
:         {
:             CString clStr;
:             pFile.ReadString ( clStr ); 
:             if( !clStr.GetLength() )
:                 continue;
:            
:             clStr.TrimLeft();
:            
:             i = clStr.Find( " " , 0 ) ;
:             String clName = clStr.Left( i ) ;
:             clStr.Delete( 0 , i );
:             clStr.TrimLeft();
:            
:            
:             if( clName != CString(pParamList->Param[iI].Name) )
:                 continue;
:            
:             i = clStr.Find( " " , 0 ) ;
:             clStr.Delete( 0 , i );
:             clStr.TrimLeft();
:            
:             i = clStr.Find( " " , 0 ) ;
:             pParamList->Param[iI].Address = strtol( (LPCTSTR)clStr, &cTempNoUse, 0x10 );
:             clStr.Delete( 0 , i );
:            
:             clStr.TrimLeft();
:             i = clStr.Find( " " , 0 ) ;
:             pParamList->Param[iI].Address += atoi( clStr.Left( i ) );
:             clStr.Delete( 0 , i );
:            
:            
:             clStr.TrimLeft();
:             i = clStr.Find( " " , 0 ) ;
:             pParamList->Param[iI].Size = atoi( clStr.Left( i ) );
:            
:             bParamFound = true;
:             break;
:         }   
:
:         if( !bParamFound )
:         {
:             pFile.Close();
:             return 1;
:         }
:     }
:    
:     pFile.Close();
:     return 0;
: //------------------------------------------------------
:
: 원본 함수는 위와 같고요..이걸 똑같이 c builder로 변환 해야 하는데
: 자꾸 에러만 나고 해서 이렇게 도움을 구하고 있읍니다..
:
: 제발 고수님들 도와주세요....

+ -

관련 글 리스트
38906 비주얼 씨 -> c builder 변환 가능한가요? 빌더 초짜 821 2005/01/25
38909     Re:비주얼 씨 -> c builder 변환 가능한가요? 멀더 1397 2005/01/25
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.