@@ -46,20 +46,21 @@ static void get_data_index_async(struct zsvsheet_ui_buffer *uibuffp, const char
46
46
47
47
static int read_data (struct zsvsheet_ui_buffer * * uibufferp , // a new zsvsheet_ui_buffer will be allocated
48
48
struct zsvsheet_ui_buffer_opts * uibopts , // if *uibufferp == NULL and uibopts != NULL
49
- size_t start_row , size_t start_col , size_t header_span , struct zsvsheet_opts * zsvsheet_opts ,
49
+ size_t start_row , size_t start_col , size_t header_span ,
50
50
struct zsv_prop_handler * custom_prop_handler ) {
51
- const char * filename = ( uibufferp && * uibufferp ) ? ( * uibufferp ) -> filename : uibopts ? uibopts -> filename : NULL ;
51
+ struct zsvsheet_opts * zsvsheet_opts = uibopts -> zsvsheet_opts ;
52
52
struct zsv_opts opts = {0 };
53
53
if (uibufferp && * uibufferp )
54
54
opts = (* uibufferp )-> zsv_opts ;
55
- else if ( uibopts )
55
+ else
56
56
opts = uibopts -> zsv_opts ;
57
57
58
58
struct zsvsheet_ui_buffer * uibuff = uibufferp ? * uibufferp : NULL ;
59
59
size_t remaining_rows_to_skip = start_row ;
60
60
size_t remaining_header_to_skip = header_span ;
61
61
size_t original_row_num = 0 ;
62
62
FILE * fp ;
63
+ const char * filename = NULL ;
63
64
64
65
if (uibuff ) {
65
66
if (uibuff -> data_filename )
@@ -68,7 +69,7 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_
68
69
filename = uibuff -> filename ;
69
70
}
70
71
71
- if (!filename && uibopts ) {
72
+ if (!filename ) {
72
73
if (uibopts -> data_filename )
73
74
filename = uibopts -> data_filename ;
74
75
else if (uibopts -> filename )
@@ -116,17 +117,17 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_
116
117
size_t find_len = zsvsheet_opts -> find ? strlen (zsvsheet_opts -> find ) : 0 ;
117
118
size_t rows_searched = 0 ;
118
119
zsvsheet_screen_buffer_t buffer = uibuff ? uibuff -> buffer : NULL ;
119
- if (uibuff && uibuff -> has_row_num )
120
+ if (uibuff && uibuff -> no_add_row_num )
120
121
zsvsheet_opts -> hide_row_nums = 1 ;
121
122
122
123
while (zsv_next_row (parser ) == zsv_status_row &&
123
124
(rows_read == 0 || rows_read < zsvsheet_screen_buffer_rows (buffer ))) { // for each row
124
125
125
126
size_t col_count = zsv_cell_count (parser );
126
- if (uibuff == NULL && uibufferp && uibopts && col_count > 0 ) {
127
+ if (uibuff == NULL && uibufferp && col_count > 0 ) {
127
128
enum zsvsheet_priv_status stat ;
128
129
struct zsvsheet_ui_buffer * tmp_uibuff = NULL ;
129
- if (!(buffer = zsvsheet_screen_buffer_new (col_count , uibopts -> buff_opts , & stat )) ||
130
+ if (!(buffer = zsvsheet_screen_buffer_new (col_count + 1 , uibopts -> buff_opts , & stat )) ||
130
131
stat != zsvsheet_priv_status_ok || !(tmp_uibuff = zsvsheet_ui_buffer_new (buffer , uibopts ))) {
131
132
if (tmp_uibuff )
132
133
zsvsheet_ui_buffer_delete (tmp_uibuff );
@@ -138,24 +139,24 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_
138
139
}
139
140
140
141
// row number
141
- size_t rownum_column_offset = 0 ;
142
142
if (rows_read == 0 && zsvsheet_opts -> hide_row_nums == 0 ) {
143
143
// Check if we already have Row #
144
144
struct zsv_cell c = zsv_get_cell (parser , 0 );
145
145
if (c .len == ZSVSHEET_ROWNUM_HEADER_LEN && !memcmp (c .str , ZSVSHEET_ROWNUM_HEADER , c .len )) {
146
146
zsvsheet_opts -> hide_row_nums = 1 ;
147
147
if (uibuff )
148
- uibuff -> has_row_num = 1 ;
148
+ uibuff -> no_add_row_num = 1 ;
149
149
}
150
150
}
151
+ size_t rownum_column_offset = !zsvsheet_opts -> hide_row_nums ;
151
152
152
153
original_row_num ++ ;
153
154
if (remaining_header_to_skip > 0 ) {
154
155
remaining_header_to_skip -- ;
155
156
continue ;
156
157
}
157
158
if (uibuff ) {
158
- if (col_count + ! buffer -> opts . no_rownum_column > buffer -> cols ) {
159
+ if (col_count > buffer -> cols ) {
159
160
if (zsvsheet_screen_buffer_grow (buffer , col_count ) != zsvsheet_priv_status_ok )
160
161
return -1 ;
161
162
}
@@ -187,7 +188,6 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_
187
188
sprintf (buff , "########" );
188
189
zsvsheet_screen_buffer_write_cell (buffer , rows_read , 0 , (unsigned char * )buff );
189
190
}
190
- rownum_column_offset = 1 ;
191
191
}
192
192
193
193
for (size_t i = start_col ; i < col_count && i + rownum_column_offset < zsvsheet_screen_buffer_cols (buffer ); i ++ ) {
@@ -261,14 +261,16 @@ static void *get_data_index(void *gdi) {
261
261
static size_t zsvsheet_find_next (struct zsvsheet_ui_buffer * uib , const char * needle ,
262
262
struct zsvsheet_opts * zsvsheet_opts , size_t header_span ,
263
263
struct zsv_prop_handler * custom_prop_handler ) {
264
+ struct zsvsheet_ui_buffer_opts uibopts = {0 };
264
265
struct zsvsheet_rowcol * input_offset = & uib -> input_offset ;
265
266
struct zsvsheet_rowcol * buff_offset = & uib -> buff_offset ;
266
267
size_t cursor_row = uib -> cursor_row ;
267
268
zsvsheet_opts -> find = needle ;
268
269
zsvsheet_opts -> found_rownum = 0 ;
270
+ uibopts .zsvsheet_opts = zsvsheet_opts ;
269
271
// TO DO: check if it exists in current row, later column (and change 'cursor_row - 1' below to 'cursor_row')
270
- read_data (& uib , NULL , input_offset -> row + buff_offset -> row + header_span + cursor_row - 1 , 0 , header_span ,
271
- zsvsheet_opts , custom_prop_handler );
272
+ read_data (& uib , & uibopts , input_offset -> row + buff_offset -> row + header_span + cursor_row - 1 , 0 , header_span ,
273
+ custom_prop_handler );
272
274
zsvsheet_opts -> find = NULL ;
273
275
return zsvsheet_opts -> found_rownum ;
274
276
}
0 commit comments