Waitrud Weber’s blog

things and reminders for memories

windows-make: csv: CSV frame ... 002

Setting a file name and which seek is well for the analyzation.
And, csv analyzation is commented out of function "put the word".

 

*

-   - - -
 

read_csv_002.h  File modified time Mon Aug 07 16:48:43 2023

0001 #ifndef _SETTLE_GRID_002_H_
0002 #define _SETTLE_GRID_002_H_
0003 
0004 extern int csv_once_002 (int *index, int *end_index ) ;
0005 extern char* m_concat_c_002 ( char* word_002 , int c ) ;
0006 extern int Set_Logging_read_csv_002 ( Logging* log ) ;
0007 extern int Set_Filename_002 ( char* filename ) ;
0008 
0009 #endif
0010 

     
 

read_csv_002.cpp  File modified time Mon Aug 07 16:48:49 2023

0001 #include <tchar.h>
0002 #include <windows.h>
0003 #include <windowsx.h>
0004 
0005 #include <ctime>
0006 
0007 #include <stdio.h>
0008 #include <stdlib.h>
0009 
0010 #include "Print.h"
0011 #include "array_counter.h"
0012 #include "parse.h"
0013 
0014 #include "log_001.h"
0015 
0016 #include "read_csv_002.h"
0017 #include "read_csv_003.h"
0018 #include "read_csv_004.h"
0019 
0020 static Logging* log_001;
0021 static LOG_001* dlog_001 = NULL;
0022 
0023 static char* filename_002 = NULL;
0024 static FILE* rfp = NULL;
0025 
0026 int csv_once (int *index, int *end_index ) ;
0027 char get_char_002 (int *index) ;
0028 int endline_002 ( char bc, char c) ;
0029 int puttheword_002 ( int ii, int jj, char* word_002 ) ;
0030 char* m_concat_c_002 ( char* word_002 , int c ) ;
0031 int Set_Logging_read_csv_002 ( Logging* log ) ;
0032 
0033 
0034 char* word_002  = NULL;
0035 char* word_002_c = NULL;
0036 
0037 // Add; mode and quotes
0038 // example
0039 int csv_once_002 (int *index, int *end_index ) {
0040     int i;
0041     int ii, jj;
0042     int mode;
0043     int count = 0;
0044     char c, bc;
0045     int word_002_cnt;
0046     int continued_flg = 0;
0047     char msg[255];
0048 
0049     dlog_001 = log_001->update_log ( (char*)"int csv_once_002 (int *index, int *end_index ) starts." );
0050 
0051     mode = 0;
0052     ii=0; jj=0;
0053 
0054     for ( i = *index; i< 10 + *index && i < *end_index; i++ ) {
0055         count++;
0056         c = get_char_002 (&i);
0057 
0058         if ( mode == 0 && c == '\,' ) {
0059             ii++;
0060 //            continued_flg = 1;
0061             continued_flg = 0;
0062         } if ( mode == 0 && endline_003 ( bc, c) ) {
0063             word_002_cnt = array_count (word_002);
0064             word_002[ word_002_cnt - 1 ] = '\0';
0065             ii++;
0066             jj++;
0067 //            continued_flg = 1;
0068             continued_flg = 0;
0069         }
0070 
0071         bc = c;
0072 
0073         if ( continued_flg == 1 ) {
0074             puttheword_004 ( ii, jj, (char*) word_002 );
0075             word_002 = NULL;
0076             continued_flg = 0;
0077             continue;
0078         }
0079 
0080 
0081         word_002_c = (char*) m_concat_c_002 ( (char*) word_002 , (int) c );
0082         aFree(word_002);
0083         word_002 = word_002_c;
0084 
0085         sprintf( msg, "count %d word_002 |%s| word_002_c |%s| c|%d|", count, word_002, word_002_c, c );
0086         dlog_001 = log_001->update_log ( (char*)msg );
0087     }
0088 
0089     *index += count;
0090     dlog_001 = log_001->update_log ( (char*)"int csv_once_002 (int *index, int *end_index ) ends." );
0091 }
0092 
0093 //
0094 char get_char_002 (int *index_r ) {
0095     char dummy[255];
0096     char rc;
0097     char msg[255];
0098 
0099     rfp = (FILE*) fopen( filename_002, "rb" );
0100     if (rfp == NULL) {
0101         exit(-1);
0102     }
0103 
0104     sprintf( msg, "SEEK index_r |%d|", *index_r );
0105     dlog_001 = log_001->update_log ( (char*)msg );
0106 
0107     fseek( rfp, *index_r, SEEK_SET);
0108     fread ( dummy, 1, 1, rfp );
0109 
0110     fclose(rfp);
0111     rc = dummy[0];
0112     return rc;
0113 }
0114 
0115 int endline_002 ( char bc, char c) {
0116     return 0;
0117 }
0118 
0119 
0120 int puttheword_002 ( int ii, int jj, char* word_002 ) {
0121     return 0;
0122 }
0123 
0124 
0125 char* m_concat_c_002 ( char* word_002 , int c ) {
0126     static char* dummy = NULL;
0127     char cc;
0128     char msg[255];
0129 
0130     cc = (char)c;
0131 
0132     if ( dummy == NULL ) {
0133         dummy = (char*) malloc ( sizeof(char) * 4 );
0134         if ( dummy == NULL ) return NULL;
0135     }
0136     dummy[0] = c;
0137     dummy[1] = '\0';
0138 
0139     sprintf( msg, "msg dummy |%s| c|%d|", dummy, c );
0140     dlog_001 = log_001->update_log ( (char*)msg );
0141 
0142     return m_concat( word_002, dummy );
0143 }
0144 
0145 //
0146 int Set_Logging_read_csv_002 ( Logging* log ) {
0147     log_001 = (Logging*)log;
0148     return 0;
0149 }
0150 
0151 int Set_Filename_002 ( char* filename ) {
0152     filename_002 = (char*)filename;
0153     return 0;
0154 }
0155