00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "conf_explorer.h"
00048 #include LIB_MEM
00049 #include "file.h"
00050 #include "navigation.h"
00051 #include "reader_txt.h"
00052 #include "unicode.h"
00053
00054
00055
00056
00057
00065 Bool reader_txt_open( Bool b_readonly )
00066 {
00067 if( !file_open( (b_readonly)? FOPEN_MODE_R : FOPEN_MODE_R_PLUS ) )
00068 return FALSE;
00069 reader_txt_beg();
00070 return TRUE;
00071 }
00072
00073
00082 Bool reader_txt_new( const FS_STRING sz_name , U8 u8_txt_format )
00083 {
00084
00085 U8 string_header[UNI_MAX_HEADER_SIZE];
00086 U8 u8_header_size;
00087
00088
00089 if ( !nav_file_create( sz_name ))
00090 return FALSE;
00091
00092 fs_g_nav_entry.u8_txt_format = u8_txt_format;
00093
00094
00095 u8_header_size = unicode_header_get( string_header, fs_g_nav_entry.u8_txt_format );
00096 file_write_buf( string_header , u8_header_size );
00097 return TRUE;
00098 }
00099
00100
00103 void reader_txt_beg( void )
00104 {
00105
00106 U8 string_header[UNI_MAX_HEADER_SIZE];
00107
00108 file_seek( 0, FS_SEEK_SET );
00109
00110
00111 memset( string_header, 0, UNI_MAX_HEADER_SIZE );
00112 file_read_buf( string_header , UNI_MAX_HEADER_SIZE );
00113 fs_g_nav_entry.u8_txt_format = unicode_header_scan( string_header );
00114
00115 file_seek( unicode_header_get( string_header, fs_g_nav_entry.u8_txt_format ), FS_SEEK_SET );
00116 }
00117
00118
00123 void reader_txt_select_format( U8 u8_txt_format )
00124 {
00125 fs_g_nav_entry.u8_txt_format = u8_txt_format;
00126 }
00127
00128
00142 U16 reader_txt_get_line( Bool b_unicode, FS_STRING string , U16 u16_str_size )
00143 {
00144 U8 utf8[UNI_MAX_UTF8_SIZE];
00145 U8 size_utf8_buf=0;
00146 U8 size_utf8_dec=0;
00147 U16 u16_size_line = 1;
00148 U16 u16_unicode;
00149 Bool b_error = FALSE;
00150
00151 nav_checkdisk_disable();
00152
00153 while( 0 == file_eof() && !b_error )
00154 {
00155
00156 switch( fs_g_nav_entry.u8_txt_format )
00157 {
00158 case UNI_TYPE_UTF8:
00159
00160 if( 0 != size_utf8_dec )
00161 {
00162 U8 u8_i;
00163 for( u8_i=0; u8_i<(UNI_MAX_UTF8_SIZE-size_utf8_dec); u8_i++ )
00164 {
00165 utf8[u8_i]=utf8[u8_i+size_utf8_dec];
00166 }
00167 size_utf8_buf -= size_utf8_dec;
00168 size_utf8_dec =0;
00169 }
00170
00171 size_utf8_buf += file_read_buf( &utf8[size_utf8_buf], (UNI_MAX_UTF8_SIZE-size_utf8_buf) );
00172
00173 size_utf8_dec = utf8_to_unicode( &utf8[0], &u16_unicode );
00174 break;
00175
00176 case UNI_TYPE_UTF16BE:
00177 MSB(u16_unicode) = file_getc();
00178 LSB(u16_unicode) = file_getc();
00179 if (LSB(u16_unicode) == (FS_EOF & 0xFF) && fs_g_status != FS_ERR_EOF)
00180 b_error = TRUE;
00181 break;
00182
00183 case UNI_TYPE_UTF16LE:
00184 LSB(u16_unicode) = file_getc();
00185 MSB(u16_unicode) = file_getc();
00186 if (MSB(u16_unicode) == (FS_EOF & 0xFF) && fs_g_status != FS_ERR_EOF)
00187 b_error = TRUE;
00188 break;
00189
00190 default:
00191 u16_unicode = file_getc();
00192 if (u16_unicode == FS_EOF && fs_g_status != FS_ERR_EOF)
00193 b_error = TRUE;
00194 break;
00195 }
00196
00197
00198 if( '\r' == u16_unicode )
00199 continue;
00200
00201
00202 if(( 0 == u16_unicode )
00203 || ('\n' == u16_unicode ) )
00204 break;
00205
00206 u16_size_line++;
00207
00208 if( 1 < u16_str_size )
00209 {
00210 if( b_unicode )
00211 {
00212 ((FS_STR_UNICODE)string)[0] = u16_unicode;
00213 }else{
00214 string[0] = u16_unicode;
00215 }
00216 string += (b_unicode? 2 : 1 );
00217 u16_str_size--;
00218 }
00219 }
00220
00221
00222 if( UNI_TYPE_UTF8 == fs_g_nav_entry.u8_txt_format )
00223 {
00224
00225 file_seek( (size_utf8_buf-size_utf8_dec) , FS_SEEK_CUR_RE );
00226 }
00227
00228
00229 if (b_error)
00230 {
00231 nav_checkdisk_enable();
00232 return 0;
00233 }
00234
00235
00236 if( 0 != u16_str_size )
00237 {
00238 if( b_unicode )
00239 {
00240 ((FS_STR_UNICODE)string)[0] = 0;
00241 }else{
00242 string[0] = 0;
00243 }
00244 }
00245 nav_checkdisk_enable();
00246 return u16_size_line;
00247 }
00248
00249
00256 Bool reader_txt_jump_line( U16 nb_line )
00257 {
00258 while( 0 != nb_line )
00259 {
00260 if( 0 != file_eof() )
00261 return FALSE;
00262 reader_txt_get_line( FALSE, NULL, 0 );
00263 nb_line--;
00264 }
00265 return TRUE;
00266 }
00267
00268
00271 void reader_txt_close( void )
00272 {
00273 file_close();
00274 }
00275