Index: altium/pcbdoc_bin.c =================================================================== --- altium/pcbdoc_bin.c (revision 35458) +++ altium/pcbdoc_bin.c (revision 35459) @@ -1,4 +1,5 @@ #include +#include #include #include "pcbdoc_ascii.h" #include "pcbdoc_bin.h" @@ -8,6 +9,13 @@ #define MAX_REC_LEN (1UL << 20) +static const union { + short int sh; + char c[2]; +} endianness = {0x0102}; + +#define is_host_litend (endianness.c[0] == 2) + /* convert a file integer (len bytes wide) into a native integer, assuming source is little-endian */ static long load_int(unsigned const char *src, int len) { @@ -27,6 +35,24 @@ return res; } +/* convert a double, assuming source is little-endian */ +static double load_dbl(unsigned const char *src) +{ + double d; + + if (is_host_litend) { /* le to le -> copy */ + memcpy(&d, src, 8); + return d; + } + else { /* le to be -> swap */ + unsigned char tmp[8]; + tmp[0] = src[7]; tmp[1] = src[6]; tmp[2] = src[5]; tmp[3] = src[4]; + tmp[4] = src[3]; tmp[5] = src[2]; tmp[6] = src[1]; tmp[7] = src[0]; + memcpy(&d, tmp, 8); + return d; + } +} + static double bmil(unsigned const char *src) { long raw = load_int(src, 4); @@ -141,3 +167,31 @@ } } + +int pcbdoc_bin_parse_arcs6(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 != 1) { + rnd_message(RND_MSG_ERROR, "Arcs6 record with wrong type; expected 4, got %d\n", rectype); + continue; + } + if (len < 45) { + rnd_message(RND_MSG_ERROR, "Arcs6 record too short; expected 45, got %ld\n", len); + continue; + } + + d = tmp->data; + + printf("arc: layer=%d ko=%d net=%ld poly=%ld comp=%ld width=%.2f uu=%d%d\n", d[0], d[1], load_int(d+3, 2), load_int(d+5, 2), load_int(d+7, 2), bmil(d+41), d[48], d[55]); + printf(" cx=%.2f cy=%.2f r=%.2f sa=%.3f ea=%.3f\n", bmil(d+13), bmil(d+17), bmil(d+21), load_dbl(d+25), load_dbl(d+33)); + } +} + Index: altium/test.c =================================================================== --- altium/test.c (revision 35458) +++ altium/test.c (revision 35459) @@ -3,7 +3,7 @@ #include "pcbdoc_ascii.h" #include "pcbdoc_bin.h" -int pcbdoc_bin_parse_tracks6(rnd_hidlib_t *hidlib, altium_tree_t *tree, ucdf_file_t *fp, altium_buf_t *tmp); +int pcbdoc_bin_parse_arcs6(rnd_hidlib_t *hidlib, altium_tree_t *tree, ucdf_file_t *fp, altium_buf_t *tmp); int main(int argc, char *argv[]) { @@ -20,7 +20,7 @@ exit(1); } - res = pcbdoc_bin_parse_tracks6(&hidlib, &tree, f, &tmp); + res = pcbdoc_bin_parse_arcs6(&hidlib, &tree, f, &tmp); fclose(f);