@@ -148,6 +148,7 @@ void parser_set_default_options(parser_t *self) {
148
148
self -> allow_embedded_newline = 1 ;
149
149
self -> strict = 0 ;
150
150
151
+ self -> expected_fields = -1 ;
151
152
self -> error_bad_lines = 0 ;
152
153
self -> warn_bad_lines = 0 ;
153
154
@@ -428,16 +429,19 @@ static void append_warning(parser_t *self, const char *msg) {
428
429
static int end_line (parser_t * self ) {
429
430
int fields ;
430
431
khiter_t k ; /* for hash set detection */
431
- int ex_fields = -1 ;
432
+ int ex_fields = self -> expected_fields ;
432
433
char * msg ;
433
434
434
435
fields = self -> line_fields [self -> lines ];
435
436
436
437
TRACE (("Line end, nfields: %d\n" , fields ));
437
438
438
-
439
439
if (self -> lines > 0 ) {
440
- ex_fields = self -> line_fields [self -> lines - 1 ];
440
+ if (self -> expected_fields >= 0 ) {
441
+ ex_fields = self -> expected_fields ;
442
+ } else {
443
+ ex_fields = self -> line_fields [self -> lines - 1 ];
444
+ }
441
445
}
442
446
443
447
if (self -> skipset != NULL ) {
@@ -457,7 +461,10 @@ static int end_line(parser_t *self) {
457
461
}
458
462
}
459
463
460
- if (!(self -> lines <= self -> header + 1 ) && fields > ex_fields ) {
464
+ /* printf("Line: %d, Fields: %d, Ex-fields: %d\n", self->lines, fields, ex_fields); */
465
+
466
+ if (!(self -> lines <= self -> header + 1 )
467
+ && (self -> expected_fields < 0 && fields > ex_fields )) {
461
468
// increment file line count
462
469
self -> file_lines ++ ;
463
470
@@ -491,7 +498,7 @@ static int end_line(parser_t *self) {
491
498
}
492
499
else {
493
500
/* missing trailing delimiters */
494
- if (self -> lines >= self -> header + 1 && self -> lines > 0 ) {
501
+ if (self -> lines >= self -> header + 1 ) {
495
502
while (fields < ex_fields ){
496
503
end_field (self );
497
504
/* printf("Prior word: %s\n", self->words[self->words_len - 2]); */
0 commit comments