aboutsummaryrefslogtreecommitdiffstats
path: root/service/src/stlfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'service/src/stlfile.c')
-rw-r--r--service/src/stlfile.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/service/src/stlfile.c b/service/src/stlfile.c
index 7c067f3..04e6727 100644
--- a/service/src/stlfile.c
+++ b/service/src/stlfile.c
@@ -62,6 +62,13 @@ stack_ind(struct stack *stack, int search)
}
int
+stack_top_eq(struct stack *stack, int cmp)
+{
+ if (!stack->count) return 0;
+ return stack->data[stack->count-1] == cmp;
+}
+
+int
isws(char c)
{
return c && strchr(wsset, c);
@@ -131,11 +138,11 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
while ((kw = consume_keyword(&bp))) {
switch (kw) {
case KW_SOLID_BEGIN:
- stack_push(&states, STATE_SOLID);
- if (stack_ind(&states, KW_SOLID_BEGIN) != -1) {
- FMT_ERR("Multiple nested solids!\n");
+ if (states.count) {
+ FMT_ERR("Improper nesting, solid not top-level in STL\n");
goto fail;
}
+ stack_push(&states, STATE_SOLID);
tmp = bp;
if (!consume_keyword(&bp)
&& (arg = consume_arg(&bp, &end))) {
@@ -162,11 +169,11 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
}
break;
case KW_LOOP_BEGIN:
- stack_push(&states, STATE_LOOP);
- if (stack_ind(&states, KW_LOOP_BEGIN) != -1) {
- FMT_ERR("Multiple nested loops!\n");
+ if (!stack_top_eq(&states, STATE_FACET)) {
+ FMT_ERR("Loop parent is not a facet!\n");
goto fail;
}
+ stack_push(&states, STATE_LOOP);
break;
case KW_LOOP_END:
if ((kw = stack_pop(&states)) != STATE_LOOP) {
@@ -177,11 +184,11 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
info->loopcount++;
break;
case KW_FACET_BEGIN:
- stack_push(&states, STATE_FACET);
- if (stack_ind(&states, KW_LOOP_BEGIN) != -1) {
- FMT_ERR("Multiple nested facets!\n");
+ if (!stack_top_eq(&states, STATE_SOLID)) {
+ FMT_ERR("Facet parent is not a solid!\n");
goto fail;
}
+ stack_push(&states, STATE_FACET);
for (i = 0; i < 3; i++) {
if (!(arg = consume_arg(&bp, &end))) {
FMT_ERR("Facet with < 3 args!\n");
@@ -202,6 +209,10 @@ parse_file_ascii(struct parseinfo *info, char *buf, size_t len)
}
break;
case KW_VERTEX:
+ if (!stack_top_eq(&states, STATE_LOOP)) {
+ FMT_ERR("Vertex parent is not a loop!\n");
+ goto fail;
+ }
for (i = 0; i < 3; i++) {
if (!(arg = consume_arg(&bp, &end))) {
FMT_ERR("Vertex with < 3 args\n");