summaryrefslogtreecommitdiff
path: root/kicad
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-19 05:24:33 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-19 05:24:33 (GMT)
commit05eb800a657fd7b24ed796332c74fd550be86b14 (patch)
treef95a6ed4dcb0f7edde6884b460506721152cb314 /kicad
parentc93142e545d73b929ab6df42d991ea18cccf8fa4 (diff)
downloadeeshow-05eb800a657fd7b24ed796332c74fd550be86b14.zip
eeshow-05eb800a657fd7b24ed796332c74fd550be86b14.tar.gz
eeshow-05eb800a657fd7b24ed796332c74fd550be86b14.tar.bz2
kicad/sch-parse.c: record comments
Diffstat (limited to 'kicad')
-rw-r--r--kicad/sch-parse.c34
-rw-r--r--kicad/sch.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/kicad/sch-parse.c b/kicad/sch-parse.c
index 2707eda..86c8ed2 100644
--- a/kicad/sch-parse.c
+++ b/kicad/sch-parse.c
@@ -334,6 +334,29 @@ static bool parse_hsheet_field(struct sch_ctx *ctx, const char *line)
}
+/* ----- Comments ---------------------------------------------------------- */
+
+
+static void add_comment(struct sheet *sheet, unsigned n, char *s)
+{
+ unsigned i;
+
+ if (n >= sheet->n_comments) {
+ sheet->comments =
+ realloc_type_n(sheet->comments, const char *, n + 1);
+ for (i = sheet->n_comments; i <= n; i++)
+ sheet->comments[i] = NULL;
+ sheet->n_comments = n + 1;
+ }
+ if (sheet->comments[n]) {
+ warning("duplicate comment %d", n);
+ free(s);
+ return;
+ }
+ sheet->comments[n] = s;
+}
+
+
/* ----- Schematics parser ------------------------------------------------- */
@@ -367,6 +390,8 @@ static struct sheet *new_sheet(struct sch_ctx *ctx)
sheet->size = NULL;
sheet->w = sheet->h = 0;
+ sheet->comments = NULL;
+ sheet->n_comments = 0;
sheet->has_children = 0;
@@ -582,6 +607,15 @@ static bool parse_line(const struct file *file, void *user, const char *line)
ctx->curr_sheet->title = s;
return 1;
}
+ if (sscanf(line, "Comment%*d \"\"%n", &n) == 0 && n)
+ return 1;
+ if (sscanf(line, "Comment%d \"%m[^\"]\"", &n, &s) == 2) {
+ if (n < 0)
+ fatal("%s:%u: invalid comment index %d",
+ file->name, file->lineno, n);
+ add_comment(ctx->curr_sheet, n, s);
+ return 1;
+ }
if (sscanf(line, "$EndDescr%n", &n) || !n)
return 1;
ctx->state = sch_basic;
diff --git a/kicad/sch.h b/kicad/sch.h
index 97e730e..395b77a 100644
--- a/kicad/sch.h
+++ b/kicad/sch.h
@@ -111,6 +111,8 @@ struct sheet {
const char *size; /* paper size, from $Descr */
int w, h;
+ const char **comments;
+ unsigned n_comments;
bool has_children; /* aka sub-sheets */