@@ -148,6 +148,7 @@ void parser_set_default_options(parser_t *self) {
148148 self -> allow_embedded_newline = 1 ;
149149 self -> strict = 0 ;
150150
151+ self -> expected_fields = -1 ;
151152 self -> error_bad_lines = 0 ;
152153 self -> warn_bad_lines = 0 ;
153154
@@ -428,16 +429,19 @@ static void append_warning(parser_t *self, const char *msg) {
428429static int end_line (parser_t * self ) {
429430 int fields ;
430431 khiter_t k ; /* for hash set detection */
431- int ex_fields = -1 ;
432+ int ex_fields = self -> expected_fields ;
432433 char * msg ;
433434
434435 fields = self -> line_fields [self -> lines ];
435436
436437 TRACE (("Line end, nfields: %d\n" , fields ));
437438
438-
439439 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+ }
441445 }
442446
443447 if (self -> skipset != NULL ) {
@@ -457,7 +461,10 @@ static int end_line(parser_t *self) {
457461 }
458462 }
459463
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 )) {
461468 // increment file line count
462469 self -> file_lines ++ ;
463470
@@ -491,7 +498,7 @@ static int end_line(parser_t *self) {
491498 }
492499 else {
493500 /* missing trailing delimiters */
494- if (self -> lines >= self -> header + 1 && self -> lines > 0 ) {
501+ if (self -> lines >= self -> header + 1 ) {
495502 while (fields < ex_fields ){
496503 end_field (self );
497504 /* printf("Prior word: %s\n", self->words[self->words_len - 2]); */
0 commit comments