Index: alien_formats/altium/pcbdoc_ascii.h =================================================================== --- alien_formats/altium/pcbdoc_ascii.h (revision 35456) +++ alien_formats/altium/pcbdoc_ascii.h (revision 35457) @@ -28,7 +28,11 @@ int dummy; } altium_tree_t; + +/* librnd */ typedef struct rnd_hidlib_s { int dummy; } rnd_hidlib_t; +#define RND_MSG_ERROR 0 +#define rnd_message(level, fmt, ...) fprintf(stderr, fmt, __VA_ARGS__) Index: alien_formats/altium/pcbdoc_bin.c =================================================================== --- alien_formats/altium/pcbdoc_bin.c (revision 35456) +++ alien_formats/altium/pcbdoc_bin.c (revision 35457) @@ -1,4 +1,5 @@ #include +#include #include "pcbdoc_ascii.h" #include "pcbdoc_bin.h" @@ -26,6 +27,12 @@ return res; } +static double bmil(unsigned const char *src) +{ + long raw = load_int(src, 4); + return (double)raw / 10000.0; +} + #define buf_grow(tmp, len) \ do { \ if (tmp->alloced < len) { \ @@ -39,18 +46,31 @@ } \ } while(0) -static long read_rec_l4b(ucdf_file_t *fp, altium_buf_t *tmp) +static long read_len(ucdf_file_t *fp, int field_width) { unsigned char lens[4]; - long len, res; + long len; - if (ucdf_fread(fp, (void *)lens, 4) != 4) + assert(field_width <= 4); + + if (ucdf_fread(fp, (void *)lens, field_width) != field_width) return -1; - len = load_int(lens, 4); + len = load_int(lens, field_width); if ((len < 0) || (len >= MAX_REC_LEN)) return -1; + return len; +} + +static long read_rec_l4b(ucdf_file_t *fp, altium_buf_t *tmp) +{ + long len, res; + + len = read_len(fp, 4); + if (len < 0) + return len; + buf_grow(tmp, len+1); res = ucdf_fread(fp, (void *)tmp->data, len); if (res == 0) @@ -65,6 +85,17 @@ return len; } +static long read_rec_tlb(ucdf_file_t *fp, altium_buf_t *tmp, int *type) +{ + char typec; + + if (ucdf_fread(fp, (void *)&typec, 1) != 1) + return -1; + *type = typec; + + return read_rec_l4b(fp, tmp); +} + static int pcbdoc_bin_parse_ascii(rnd_hidlib_t *hidlib, altium_tree_t *tree, const char *record, altium_buf_t *tmp) { #warning TODO: take over tmps buff and make it a block @@ -83,3 +114,26 @@ } +int pcbdoc_bin_parse_tracks6(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 (len < 45) { + rnd_message(RND_MSG_ERROR, "Tracks6 record too short; expected 45, got %ld\n", len); + continue; + } + + d = tmp->data; + + printf("line: 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+29), d[36], d[40]); + printf(" x1=%.2f y1=%.2f x2=%.2f y2=%.2f\n", bmil(d+13), bmil(d+17), bmil(d+21), bmil(d+25)); + } +} + Index: alien_formats/altium/test.c =================================================================== --- alien_formats/altium/test.c (revision 35456) +++ alien_formats/altium/test.c (revision 35457) @@ -3,7 +3,7 @@ #include "pcbdoc_ascii.h" #include "pcbdoc_bin.h" -int pcbdoc_bin_parse_board6(rnd_hidlib_t *hidlib, altium_tree_t *tree, ucdf_file_t *fp, altium_buf_t *tmp); +int pcbdoc_bin_parse_tracks6(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_board6(&hidlib, &tree, f, &tmp); + res = pcbdoc_bin_parse_tracks6(&hidlib, &tree, f, &tmp); fclose(f);