OSDN Git Service

* Append: Count max-length in all-lines for DrCC_FileType_VerityText()
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Thu, 16 Apr 2015 20:10:36 +0000 (05:10 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Thu, 16 Apr 2015 20:10:36 +0000 (05:10 +0900)
drcc/drcc_edittext_file.c
drcc/drcc_edittext_file.h
drcc/drcc_filetype.c
drcc/drcc_filetype.h
drcc/test_drcc_filetype.c

index 104dc46..8864a5b 100644 (file)
@@ -69,7 +69,8 @@ int
        DrCC_EditText_File_ReadTextFile(
                        Drd64_DrCC_TextInfo             *p_tinfo,
                        char    *pstr_filepath,
-                       DWord   dw_fsize )
+                       DWord   dw_fsize,
+                       DWord   dw_maxlength )
 {
        int             i_result        = 0x00;
        int             i_fd;
@@ -191,7 +192,7 @@ int
        if( NULL == p_tinfo )   { return -0x04; }
 
        /* Alloc File-Buffer */
-       dw_maxline      = (DWord)t_ftype.i_lines;
+       dw_maxline      = (DWord)t_ftype.dw_lines;
        dw_bufline      = (DWord)((double)dw_maxline
                                                * (double)DRD64_DRCC_DEFAULT_LINES_SAFETY_FACTOR);
        dw_bufsize      = t_ftype.dw_filesize
@@ -205,7 +206,8 @@ int
        strncpy( p_tinfo->str_filename, pstr_filename, DRD64_MAX_PATH );
 
        /* Read Textfile & Generate LineInfo */
-       i_result        = DrCC_EditText_File_ReadTextFile( p_tinfo, str_filepath, t_ftype.dw_filesize );
+       i_result        = DrCC_EditText_File_ReadTextFile(
+                                       p_tinfo, str_filepath, t_ftype.dw_filesize, t_ftype.dw_maxlength );
        if( 0x00 != i_result )  { return -0x05; }
 
        return p_tinfo->i_id;
index 4554dee..c1d1cee 100644 (file)
@@ -63,7 +63,8 @@ DRCC_EDITTEXT_FILE_EXTERN
 int            DrCC_EditText_File_CatPathFilename(
                        char *pstr_fullpath, char *pstr_path, char *pstr_filename );
 int            DrCC_EditText_File_ReadTextFile(
-                       Drd64_DrCC_TextInfo *p_tinfo, char *pstr_filepath, DWord dw_fsize );
+                       Drd64_DrCC_TextInfo *p_tinfo, char *pstr_filepath,
+                       DWord dw_fsize, DWord dw_maxlength );
 #endif
 
 #endif /* DRD64_HEADER_DRCC_EDITTEXT */
index eefbac7..b0e5a3a 100644 (file)
@@ -91,12 +91,15 @@ char *
 ----------------------------------------------------------------------*/
 int
        DrCC_FileType_VerifyTextFile(
-               int             *pi_lines,
+               DWord   *pdw_lines, 
+               DWord   *pdw_length,
                int             i_fd )
 {
        int             i_bytes;
        int             i_cnt;
-       int             i_lines         = 0;
+       DWord   dw_lines                = 0;
+       DWord   dw_length               = 0;
+       DWord   dw_maxlength    = 0;
        char    str_buf[1025];
        char    *pstr_buf;
 
@@ -105,12 +108,21 @@ int
        do {
                i_bytes = read( i_fd, &str_buf, 1024 );
                for( pstr_buf = str_buf, i_cnt = i_bytes; i_cnt > 0; i_cnt-- )  {
-                       if( '\n' == *pstr_buf++ )       { i_lines++; }
+                       dw_length++;
+
+                       if( '\n' == *pstr_buf ) {
+                               if( dw_length > dw_maxlength )  { dw_maxlength = dw_length; }
+                               dw_length       = 0;
+                               dw_lines++;
+                       }
+                       
+                       pstr_buf++;
                }
        } while( 0 < i_bytes );
        if( 0 > i_bytes )       { return -0x01; }
 
-       *pi_lines       = i_lines;
+       *pdw_lines      = dw_lines;
+       *pdw_length     = dw_maxlength;
        
        return 0x00;
 }
@@ -172,7 +184,8 @@ DRCC_FILETYPE_EXTERN
        int             i_result        = 0x00;
        int             i_fd;
        int             i_err;
-       int             i_lines;
+       DWord   dw_lines;
+       DWord   dw_length;
 
        i_result = DrCC_FileType_GetFileType_fromFileName( p_filetype, pstr_filename );
 
@@ -189,12 +202,13 @@ DRCC_FILETYPE_EXTERN
 
        /* XXX : Verify Data-File (Text or Binray) */
        if( DRD64_DRCC_FILETYPE_TEXT == p_filetype->b_type )    {
-               i_err   = DrCC_FileType_VerifyTextFile( &i_lines, i_fd );
+               i_err   = DrCC_FileType_VerifyTextFile( &dw_lines, &dw_length, i_fd );
                if( 0 > i_err )         {
                        i_result        = -0x02;
                        goto goto_DrCC_FileType_CheckFileType_post;
                }
-               p_filetype->i_lines     = i_lines;
+               p_filetype->dw_lines            = dw_lines;
+               p_filetype->dw_maxlength        = dw_length;
        }
 
 goto_DrCC_FileType_CheckFileType_post:
index abaabe1..f69ed76 100644 (file)
@@ -72,7 +72,8 @@ typedef       struct  {
        Byte    b_type;
        Word    w_subtype;
        DWord   dw_filesize;
-       int             i_lines;
+       DWord   dw_lines;
+       DWord   dw_maxlength;
 } Drd64_DrCC_FileType;
 
 typedef        struct  {
@@ -124,7 +125,7 @@ int DrCC_FileType_CheckFileType(
 #ifdef DRCC_FILETYPE_INTERNALFUNC
 char *DrCC_FileType_GetFileNamePosition( char *pstr_filepath );
 char *DrCC_FileType_GetFileExtPosition( char *pstr_filepath );
-int DrCC_FileType_VerifyTextFile( int *pi_lines, int i_fd );
+int DrCC_FileType_VerifyTextFile( DWord *pdw_lines, DWord *pdw_length, int i_fd );
 #endif
 
 #endif /* DRD64_HEADER_XXX */
index 0e1abc1..9564d3e 100644 (file)
@@ -42,20 +42,22 @@ Comment:
 /*--------------------------------------------------------------------*/
 void Test_DrCC_FileType_VerifyTextFile_test00_001(void)
 {
-       int     i_fd;
-       int     i_lines = 0;
-       int     i_err;
+       int             i_fd;
+       int             i_err;
+       DWord   dw_lines        = 0;
+       DWord   dw_length       = 0;
        
        i_fd    = open( "./testdata/drcc_testfile.c", O_RDONLY );
        if( 0 > i_fd )  {
                CU_FAIL( " Not Exist TestFile: testdata/drcc_testfile.c" );
                return;
        }
-       i_err   = DrCC_FileType_VerifyTextFile( &i_lines, i_fd );       
+       i_err   = DrCC_FileType_VerifyTextFile( &dw_lines, &dw_length, i_fd );  
        close( i_fd );
        
        CU_ASSERT( 0x00 == i_err );
-       CU_ASSERT( 43 == i_lines );
+       CU_ASSERT( 43 == dw_lines );
+       CU_ASSERT( 76 == dw_length );
        return;
 }
 
@@ -63,19 +65,21 @@ void Test_DrCC_FileType_VerifyTextFile_test00_001(void)
 void Test_DrCC_FileType_VerifyTextFile_test00_002(void)
 {
        int     i_fd;
-       int     i_lines = 0;
        int     i_err;
+       DWord   dw_lines        = 0;
+       DWord   dw_length       = 0;
        
        i_fd    = open( "./testdata/drcc_testfile.h", O_RDONLY );
        if( 0 > i_fd )  {
                CU_FAIL( " Not Exist TestFile: testdata/drcc_testfile.h" );
                return;
        }
-       i_err   = DrCC_FileType_VerifyTextFile( &i_lines, i_fd );       
+       i_err   = DrCC_FileType_VerifyTextFile( &dw_lines, &dw_length, i_fd );  
        close( i_fd );
        
        CU_ASSERT( 0x00 == i_err );
-       CU_ASSERT( 49 == i_lines );
+       CU_ASSERT( 49 == dw_lines );
+       CU_ASSERT( 76 == dw_length );
        return;
 }
 
@@ -83,19 +87,21 @@ void Test_DrCC_FileType_VerifyTextFile_test00_002(void)
 void Test_DrCC_FileType_VerifyTextFile_test00_003(void)
 {
        int     i_fd;
-       int     i_lines = 0;
        int     i_err;
+       DWord   dw_lines        = 0;
+       DWord   dw_length       = 0;
        
        i_fd    = open( "./testdata/Makefile", O_RDONLY );
        if( 0 > i_fd )  {
                CU_FAIL( " Not Exist TestFile: testdata/Makefile" );
                return;
        }
-       i_err   = DrCC_FileType_VerifyTextFile( &i_lines, i_fd );       
+       i_err   = DrCC_FileType_VerifyTextFile( &dw_lines, &dw_length, i_fd );  
        close( i_fd );
        
        CU_ASSERT( 0x00 == i_err );
-       CU_ASSERT( 145 == i_lines );
+       CU_ASSERT( 145 == dw_lines );
+       CU_ASSERT( 78 == dw_length );
        return;
 }
 
@@ -103,19 +109,21 @@ void Test_DrCC_FileType_VerifyTextFile_test00_003(void)
 void Test_DrCC_FileType_VerifyTextFile_test00_004(void)
 {
        int     i_fd;
-       int     i_lines = 0;
        int     i_err;
+       DWord   dw_lines        = 0;
+       DWord   dw_length       = 0;
        
        i_fd    = open( "./testdata/x8664db.csv", O_RDONLY );
        if( 0 > i_fd )  {
                CU_FAIL( " Not Exist TestFile: testdata/x8664db.csv" );
                return;
        }
-       i_err   = DrCC_FileType_VerifyTextFile( &i_lines, i_fd );       
+       i_err   = DrCC_FileType_VerifyTextFile( &dw_lines, &dw_length, i_fd );  
        close( i_fd );
        
        CU_ASSERT( 0x00 == i_err );
-       CU_ASSERT( 1434 == i_lines );
+       CU_ASSERT( 1434 == dw_lines );
+       CU_ASSERT( 156 == dw_length );
        return;
 }