1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
t_3Dc *csv_format( t_csv *p )
{
t_3Dc *p_out = NULL;
if ( p ) ///T0
{
if ( p->raw->da ) ///T1
{
if ( (p_out = create_3D_c(p->line, p->row, 1000)) ) ///T2
{
t_uint64 i, i_tmp, line, row;
i_tmp = 0;
line = 0;
row = 0;
for( i=0 ; i < p->raw->x ; i++ )
{
if ( p->raw->da[i] == ';' )
i_tmp = 0, row++;
else if ( (p->raw->da[i] == '\n') )
i_tmp = 0, line++, row = 0;
else
{
if ( line >= p->line || row >= p->row || i_tmp >= 1000 )
printf("\n Possible SIGSEV signal while translating data to the 3D array\n max_line = %I64u ; current is %I64u\n max_row = %I64u ; current is %I64u\n i_tmp_max = %I64u ; current is %I64u", p->line , line+1, p->row, row+1, (t_uint64)1000 , i_tmp );
else
{
if (p->raw->da[i] != '\r')
p_out->da[line][row][i_tmp] = p->raw->da[i], i_tmp++;
}
}
}
}
else fprintf(logger, "csv.h::csv_format.T2 -> The memory allocation of the csv array's pointer is NULL\n");
}
else fprintf(logger, "csv.h::csv_format.T1 -> The raw csv file's pointer is NULL\n");
}
else fprintf(logger, "csv.h::csv_format.T0 -> The t_csv structure's pointer is NULL\n");
return p_out;
}
t_uint64 csv_get_line( t_csv *p )
{
t_uint64 line = 0;
if( p ) ///T1
{
if ( p->raw->da ) ///T2
line = str_count_occurrence( p->raw->da, '\n' );
else fprintf(logger, "csv.h::csv_get_line.T2 -> The char's pointer is NULL\n");
}
else fprintf(logger, "csv.h::csv_get_line.T1 -> The t_csv structure's pointer is NULL\n");
return line;
}
t_uint64 csv_get_row( t_csv *p )
{
t_uint64 max = 0;
t_uint64 row = 0;
if( p )
{
if ( p->raw )
{
t_uint64 i;
for ( i=0 ; i<p->raw->x ; i++ )
{
if ( p->raw->da[i] == '\n' )
{
if (row>max)
max=row;
row = 0;
}
if ( p->raw->da[i] == ';' )
row+=1;
}
}
else fprintf(logger, "csv.h::csv_get_row -> da t_2Dc structure's member is NULL\n");
}
else fprintf(logger, "csv.h::csv_get_row -> t_csv structure is NULL\n");
return max+1;
}
void csv_display(t_csv *p)
{
if(p)
{
t_uint64 i,j;
for(i=0;i<p->line;i++)
{
for(j=0;j<p->row;j++)
printf("%s ",p->array->da[i][j]);
printf("\n");
}
}
}
void csv_to_file( t_csv *p )
{
if (p)
{
FILE *f = NULL;
if ( f=file_open(p->path,"w") )
{
t_uint64 i,j;
for(i=0; i<p->line ; i++)
{
for(j=0 ; j<p->row ;j++ )
{
fprintf(f,"%s;",p->array->da[i][j]);
}
fprintf(f,"\n");
}
file_close(f);
}
}
} |
Partager