From c2e1d60e2eb99f53affd18b4e77ce2fceadd2a17 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 26 Jul 2016 08:23:28 -0300 Subject: [PATCH] sch2fig/: add unit letter(s) to component reference of multi-unit components --- sch2fig/TODO | 1 - sch2fig/lib.c | 19 ++++--------------- sch2fig/lib.h | 16 +++++++++++++++- sch2fig/sch.c | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/sch2fig/TODO b/sch2fig/TODO index 117d053..ca3b2d2 100644 --- a/sch2fig/TODO +++ b/sch2fig/TODO @@ -4,7 +4,6 @@ - unify alignment, direction - support fonts attributes ? - support line thickness ? -- show unit in component reference - ~ as space (grep for ~ in out.fig) - ~ as overline (grep for ~ in out.fig) - support pin name not inside component diff --git a/sch2fig/lib.c b/sch2fig/lib.c index 58d0df7..42bd41f 100644 --- a/sch2fig/lib.c +++ b/sch2fig/lib.c @@ -92,19 +92,6 @@ struct obj { }; -struct comp { - const char *name; - - unsigned visible; /* visible fields, bit mask */ - bool show_pin_name; - bool show_pin_num; - unsigned name_offset; - - struct obj *objs; - struct comp *next; -}; - - /* ----- Drawing ----------------------------------------------------------- */ @@ -436,15 +423,17 @@ static bool parse_def(const char *line) char *s; char draw_num, draw_name; unsigned name_offset; + unsigned units; - if (sscanf(line, "DEF %ms %*s %*d %u %c %c", - &s, &name_offset, &draw_num, &draw_name) != 4) + if (sscanf(line, "DEF %ms %*s %*d %u %c %c %u", + &s, &name_offset, &draw_num, &draw_name, &units) != 5) return 0; curr_comp = alloc_type(struct comp); if (*s == '~') s++; curr_comp->name = s; + curr_comp->units = units; curr_comp->visible = 0; curr_comp->show_pin_name = draw_name == 'Y'; diff --git a/sch2fig/lib.h b/sch2fig/lib.h index 2a17213..7ba88db 100644 --- a/sch2fig/lib.h +++ b/sch2fig/lib.h @@ -28,7 +28,21 @@ struct lib_ctx { unsigned lineno; }; -struct comp; +struct obj; + +struct comp { + const char *name; + unsigned units; + + unsigned visible; /* visible fields, bit mask */ + bool show_pin_name; + bool show_pin_num; + unsigned name_offset; + + struct obj *objs; + struct comp *next; +}; + const struct comp *lib_find(const char *name); diff --git a/sch2fig/sch.c b/sch2fig/sch.c index 5699608..6b301cd 100644 --- a/sch2fig/sch.c +++ b/sch2fig/sch.c @@ -122,6 +122,24 @@ static bool parse_field(struct sch_ctx *ctx, const char *line) return 1; } + if (n == 0 && ctx->comp->units > 1) { + int len = strlen(txt->s); + char *s; + + s = realloc((void *) txt->s, len + 3); + if (!s) { + perror("realloc"); + exit(1); + } + if (ctx->unit <= 26) + sprintf(s + len, "%c", 'A' + ctx->unit - 1); + else + sprintf(s + len, "%c%c", + 'A' + (ctx->unit - 1) / 26 - 1, + 'A' + (ctx->unit - 1) % 26); + txt->s = s; + } + field->next = ctx->fields; ctx->fields = field;