Index: eagle_bin/test_parser/eagle_bin.c =================================================================== --- eagle_bin/test_parser/eagle_bin.c (revision 9410) +++ eagle_bin/test_parser/eagle_bin.c (revision 9411) @@ -918,87 +918,92 @@ return d; } -int read_drc(void *ctx, FILE *f, const char *fn) +int read_notes(void *ctx, FILE *f, const char *fn) { - unsigned char sub_block[8]; unsigned char block[8]; - int DRC_length_used = 244; - unsigned char DRC_block[244]; - unsigned char DRC_sub_block[244]; - long sentinel_found = 0; - long magic_found = 0; - int extra_bytes = 0; - long offset = 0; - int index = 0; + unsigned char free_text[400]; + int notes_length = 0; + int text_remaining = 0; if (fread(block, 1, 8, f) != 8) { - printf("E: short attempted DRC sentinel read. DRC start sentinel not found.\n"); + printf("E: short attempted free text section read. Text section, DRC, not found.\n"); return -1; } - /* look for DRC start sentinel */ - while (!sentinel_found) /* \x10\x04\x00\x20 */ - { - for (offset = 0; offset < 5; offset++) { - if (load_long(block, offset, 1) == 0x10 - && load_long(block, offset+1, 1) == 0x04 - && load_long(block, offset+2, 1) == 0x00 - && load_long(block, offset+3, 1) == 0x20) { - sentinel_found = 1; - } - } - if (fread(sub_block, 1, 4, f) != 4) { - printf("E: short attempted DRC sentinel read. DRC start sentinel not found.\n"); + if (load_long(block, 0, 1) == 0x13 + && load_long(block, 1, 1) == 0x12) { + printf("Start of pre-DRC free text section found.\n"); + } else { + printf("Failed to find 0x1312 start of pre-DRC free text section.\n"); + return -1; + } + + text_remaining = notes_length = (int)load_long(block, 4, 2); + text_remaining += 4; /* there seems to be a 4 byte checksum or something at the end */ + printf("Pre-DRC free text section length remaining: %d\n", notes_length); + + while (text_remaining > 400) { + if (fread(free_text, 1, 400, f) != 400) { + printf("E: short attempted free text block read. Truncated file?\n"); return -1; } - for (index = 7; index > 3; index--) { - block[index-4] = block[index]; - block[index] = sub_block[index-4]; - } + text_remaining -= 400; + } + if (fread(free_text, 1, text_remaining, f) != text_remaining) { + printf("E: short attempted free text block read. Truncated file?\n"); + return -1; + } else { + printf("Pre-DRC free text block has been read.\n"); } - printf("found DRC start sentinel x10x04x00x20.\n"); + return 0; +} - while (!magic_found) /* \x78\x56\x34\x12 */ - { - for (offset = 0; offset < 5; offset++) { - if (load_long(block, offset, 1) == 0x78 - && load_long(block, offset+1, 1) == 0x56 - && load_long(block, offset+2, 1) == 0x34 - && load_long(block, offset+3, 1) == 0x12) { - magic_found = 1; - extra_bytes = 4 - offset; - } +int read_drc(void *ctx, FILE *f, const char *fn) +{ + unsigned char block[4]; + int DRC_length_used = 244; + unsigned char DRC_block[244]; + int DRC_preamble_end_found = 0; + + if (fread(block, 1, 4, f) != 4) { + printf("E: short attempted DRC preamble read; preamble not found. Truncated file?\n"); + return -1; + } + + /* look for DRC start sentinel */ + if (!(load_long(block, 0, 1) == 0x10 + && load_long(block, 1, 1) == 0x04 + && load_long(block, 2, 1) == 0x00 + && load_long(block, 3, 1) == 0x20)) { + printf("E: start of DRC preamble not found where it was expected.\n"); + printf("E: drc byte 0 : %d\n", (int)load_long(block, 0, 1) ); + printf("E: drc byte 1 : %d\n", (int)load_long(block, 1, 1) ); + printf("E: drc byte 2 : %d\n", (int)load_long(block, 2, 1) ); + printf("E: drc byte 3 : %d\n", (int)load_long(block, 3, 1) ); + return -1; + } else { + printf("start of DRC preamble section 0x10 0x04 0x00 0x20 found.\n"); + } + + while (!DRC_preamble_end_found) { + if (fread(block, 1, 4, f) != 4) { /* the text preamble seems to n * 24 bytes */ + printf("E: short attempted DRC preamble read. Truncated file?\n"); + return -1; } - if (!magic_found) { - if (fread(sub_block, 1, 4, f) != 4) { - printf("E: short attempted DRC magic read. DRC magic not found.\n"); - return -1; - } - for (index = 7; index > 3; index--) { /*shuffle things over */ - block[index-4] = block[index]; - block[index] = sub_block[index-4]; - /* printf("parse read block at index: %d : %d\n", index, block[index]); */ - } + if (load_long(block, 0, 1) == 0x78 + && load_long(block, 1, 1) == 0x56 + && load_long(block, 2, 1) == 0x34 + && load_long(block, 3, 1) == 0x12) { + DRC_preamble_end_found = 1; } } - printf("found DRC magic x78x56x34x12.\n"); - printf("readbuffer still contains %d DRC bytes\n", extra_bytes); - if (fread(DRC_sub_block, 1, (DRC_length_used - extra_bytes), f) != (DRC_length_used-extra_bytes)) { - printf("E: short DRC value block read. DRC section incomplete.\n"); + printf("found end of DRC preamble text x78x56x34x12. About to load DRC rules.\n"); + + if (fread(DRC_block, 1, DRC_length_used, f) != DRC_length_used) { + printf("E: short DRC value block read. DRC section incomplete. Truncated file?\n"); return -1; } - for (index = 0; index < extra_bytes; index++) { - printf("placing residual bytes in parse read block at index %d: %d\n", 8-extra_bytes+index, block[8-extra_bytes+index]); - /* printf("into DRC_block index: %d\n", index);*/ - DRC_block[index] = block[8-extra_bytes+index]; - } - for (index = extra_bytes; index < (DRC_length_used-extra_bytes); index++) { - DRC_block[index] = DRC_sub_block[index-extra_bytes]; - } - /*for (index = 0; index < DRC_length_used; index++) { - printf("DRC_block index: %d and value %d\n", index, DRC_block[index]); - } */ /* first ~134 bytes contain the most useful DRC stuff, such as # wire2wire wire2pad wire2via pad2pad pad2via via2via pad2smd via2smd smd2smd @@ -1191,6 +1196,7 @@ printf("Section blocks have been parsed. Next job is finding DRC.\n\n"); + read_notes(ctx, f, fn); read_drc(ctx, f, fn); return 0;