Index: work/alien_formats/altium/pcbdoc_ascii.h =================================================================== --- work/alien_formats/altium/pcbdoc_ascii.h (revision 35462) +++ work/alien_formats/altium/pcbdoc_ascii.h (revision 35463) @@ -6,9 +6,13 @@ static inline long ucdf_fread(ucdf_file_t *fp, char *dst, long len) { + long res; if (feof(fp)) return 0; - return fread(dst, 1, len, fp); + res = fread(dst, 1, len, fp); + if ((res <= 0) && (feof(fp))) + return 0; + return res; } Index: work/alien_formats/altium/pcbdoc_bin.c =================================================================== --- work/alien_formats/altium/pcbdoc_bin.c (revision 35462) +++ work/alien_formats/altium/pcbdoc_bin.c (revision 35463) @@ -75,12 +75,15 @@ static long read_len(ucdf_file_t *fp, int field_width) { unsigned char lens[4]; - long len; + long len, res; assert(field_width <= 4); - if (ucdf_fread(fp, (void *)lens, field_width) != field_width) - return -1; + if ((res = ucdf_fread(fp, (void *)lens, field_width)) != field_width) { + if (res <= 0) + return res; + return -1; /* short read means broken field */ + } len = load_int(lens, field_width); if ((len < 0) || (len >= MAX_REC_LEN)) @@ -114,9 +117,11 @@ static long read_rec_tlb(ucdf_file_t *fp, altium_buf_t *tmp, int *type) { char typec; + long res; - if (ucdf_fread(fp, (void *)&typec, 1) != 1) - return -1; + if ((res = ucdf_fread(fp, (void *)&typec, 1)) != 1) + return res; + *type = typec; return read_rec_l4b(fp, tmp); @@ -180,11 +185,11 @@ if (len <= 0) return len; if (rectype != 1) { - rnd_message(RND_MSG_ERROR, "Arcs6 record with wrong type; expected 4, got %d\n", rectype); + rnd_message(RND_MSG_ERROR, "Arcs6 record with wrong type; expected 1, got %d\n", rectype); continue; } if (len < 56) { - rnd_message(RND_MSG_ERROR, "Arcs6 record too short; expected 45, got %ld\n", len); + rnd_message(RND_MSG_ERROR, "Arcs6 record too short; expected 56, got %ld\n", len); continue; } @@ -195,3 +200,34 @@ } } + +int pcbdoc_bin_parse_texts6(rnd_hidlib_t *hidlib, altium_tree_t *tree, ucdf_file_t *fp, altium_buf_t *tmp) +{ + for(;;) { + unsigned char *d; + int rectype; + long len; + + len = read_rec_tlb(fp, tmp, &rectype); + if (len <= 0) + return len; + if (rectype != 5) { + rnd_message(RND_MSG_ERROR, "Texts6 record with wrong type; expected 5, got %d\n", rectype); + continue; + } + if (len < 230) { + rnd_message(RND_MSG_ERROR, "Texts6 record too short; expected 230, got %ld\n", len); + continue; + } + + d = tmp->data; + + printf("text: layer=%d comp=%ld height=%.2f comment=%d designator=%d\n", d[0], load_int(d+7, 2), bmil(d+21), d[40], d[41]); + printf(" x=%.2f y=%.2f h=%.2f rot=%.3f mirr=%d\n", bmil(d+13), bmil(d+17), bmil(d+21), load_dbl(d+27), d[35]); + + len = read_rec_l4b(fp, tmp); + printf(" string='%s'\n", tmp->data+1); + + } +} + Index: work/alien_formats/altium/test.c =================================================================== --- work/alien_formats/altium/test.c (revision 35462) +++ work/alien_formats/altium/test.c (revision 35463) @@ -3,7 +3,7 @@ #include "pcbdoc_ascii.h" #include "pcbdoc_bin.h" -int pcbdoc_bin_parse_arcs6(rnd_hidlib_t *hidlib, altium_tree_t *tree, ucdf_file_t *fp, altium_buf_t *tmp); +int pcbdoc_bin_parse_texts6(rnd_hidlib_t *hidlib, altium_tree_t *tree, ucdf_file_t *fp, altium_buf_t *tmp); int main(int argc, char *argv[]) { @@ -20,8 +20,10 @@ exit(1); } - res = pcbdoc_bin_parse_arcs6(&hidlib, &tree, f, &tmp); + res = pcbdoc_bin_parse_texts6(&hidlib, &tree, f, &tmp); + printf("res=%d @ %ld\n", res, ftell(f)); + fclose(f); return res;