bugGNU recutils - Bugs: bug #64546, rec_parse_rset: Comments on...

 
 

bug #64546: rec_parse_rset: Comments on Records Are Separate Records

Submitter:  None
Submitted:  Fri 11 Aug 2023 07:32:50 PM UTC
   
 
Category:  librec Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 12 Aug 2023 07:22:17 AM UTC, comment #3: 

Either way, the comment is a part of the record unless there is a new line character between it and the record. So it shouldn't be added as its own element in rset. Instead rset should consist of only records and comments which are singular and buffered above and below by new line characters.

Anonymous
Fri 11 Aug 2023 07:49:37 PM UTC, comment #2: 

Incorrect, rec_rset_num_records(rset) gave the correct value. Please disregard that.

However, iteration over rset by type MSET_ANY results in segmentation fault. I found through source I can use MSET_RECORD. This was buried and difficult to figure out.

Anonymous
Fri 11 Aug 2023 07:44:02 PM UTC, comment #1: 

Identical behavior when using rec_rset_num_records(rset).

Anonymous
Fri 11 Aug 2023 07:32:50 PM UTC, original submission:  

I could be ignorant of some details, it appears if the comment for a record is placed above the first field, and there is more than one record in a record set, the comment is added as a separate record.

Below (and attached) will output:
Record Set: Test
Record Count: 3

This is unvaried if instead a comment is prepended to the second record, or it will count 4 if prepended to both.

Potentially caused by rec-parser.c#920.

test.rec:

%rec: Test

#If first line is a comment, and there are 2+ records... This is its own record.
Line: This should be record 1, but it's 2.

Line: This should be record 2, but it's 3.


main.c:

#include <rec.h>
#include <stdio.h>

int main(void) {
    FILE *file;
    rec_parser_t parser;
    rec_rset_t rset;

    file = fopen("test.rec", "r");
    parser = rec_parser_new(file, "test.rec");

    while (rec_parse_rset(parser, &rset)) {
        printf("Record Set: %s\n", rec_rset_type(rset));
        printf("Record Count: %d\n", rec_rset_num_elems(rset));
    }

    rec_rset_destroy(rset);
    rec_parser_destroy(parser);
    fclose(file);
    return 0;
}

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #55026:  main.c added by None (466B - text/x-csrc - Attached test files for convenience.)
file #55027:  test.rec added by None (180B - application/octet-stream - Attached test files for convenience.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

Only logged-in users can vote.

 

Follow 2 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2023-08-11 None Attached File- Added main.c, #55026
    Attached File- Added test.rec, #55027

Back to the top

Powered by Savane 3.13-caa5.
Corresponding source code