/* $Id: parsecsv.c $
This file is part of the HandBrake source code.
- Homepage: <http://handbrake.m0k.org/>.
+ Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#include <fcntl.h>
#define is_newline(_x) ( (_x) == 13 || \
(_x) == 11 || \
(_x) == 10 )
-
+
#define is_white(_x) ( (_x) == '\t' || \
(_x) == ' ' || \
- is_newline(_x) )
-
+ is_newline(_x) )
+
#define is_sep(_x) ( (_x) == ',' )
#define is_esc(_x) ( (_x) == '\\' )
{
hb_csv_file_t *file = NULL;
FILE * fileref;
-
+
if( filepath == NULL )
{
return file;
}
-
+
fileref = fopen( filepath, "r" );
if( fileref == NULL )
{
return file;
}
-
+
file = malloc( sizeof( hb_csv_file_t ) );
file->fileref = fileref;
file->eof = 0;
return file;
}
-void hb_close_csv_file( hb_csv_file_t *file )
+void hb_close_csv_file( hb_csv_file_t *file )
{
if( file == NULL )
{
return;
}
-
+
fclose( file->fileref );
free( file );
}
{
return cell;
}
-
+
if( file->eof )
{
return cell;
}
-
+
cell = malloc( sizeof( hb_csv_cell_t ) );
cell->cell_row = file->curr_row;
cell->cell_col = file->curr_col;
}
}
}
-
+
if( c == CSV_CHAR_EOF )
{
file->eof = 1;
}
-
+
/* Terminate the cell text */
cell->cell_text[index] = '\0';
hb_trim_end( cell->cell_text );
{
return;
}
-
+
free( cell );
}
static uint16_t hb_parse_character( hb_csv_file_t * file )
{
int byte;
- uint16_t c;
- int read_result;
+ uint16_t c = 0;
int need_char = 1;
-
+
if( file == NULL )
{
return CSV_CHAR_ERROR;
}
-
+
while( need_char )
{
byte = fgetc( file->fileref );
{
return CSV_CHAR_ERROR;
}
-
+
if( file->parse_state == CSV_PARSE_SEEK && is_white(byte) )
{
continue;
c = (uint16_t)byte;
}
}
-
+
return c;
}
}
int i = strlen(text) - 1;
-
+
for( i = strlen(text) - 1; i >= 0 && is_white(text[i]) ; i-- )
{
text[i] = '\0';
}
-}
\ No newline at end of file
+}