summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-03 23:01:31 -0600
committersanine <sanine.not@pm.me>2023-02-03 23:01:31 -0600
commit1b4564c02380d10f7f8630d73441e7f9aa83c812 (patch)
treeda0f9294e1fc7c637547629faab4b45ed3e3494c
parentea512c3b1d2d85ff76aa7d4979c73dd7f1217757 (diff)
begin implementing kai_read_float_array()
-rw-r--r--include/kalmia.h61
-rw-r--r--src/geometry/geometry.c12
-rw-r--r--src/geometry/geometry.h3
-rw-r--r--src/geometry/geometry.test.c15
-rw-r--r--src/xml/kalmia.tab.c164
-rw-r--r--yy/kalmia.y4
6 files changed, 121 insertions, 138 deletions
diff --git a/include/kalmia.h b/include/kalmia.h
index 524072b..bab1b34 100644
--- a/include/kalmia.h
+++ b/include/kalmia.h
@@ -66,66 +66,11 @@ typedef float ka_real_t;
/**************** geometry types ****************/
struct ka_float_array_t {
+ unsigned int count; /* required */
char *id;
- size_t count;
- ka_real_t *data;
+ unsigned int digits; /* default 6 */
+ int magnitude; /* default 38 */
};
-struct ka_param_t {
- char *name;
- char *type;
-};
-
-
-struct ka_accessor_t {
- size_t count;
- size_t offset;
- char *source;
- size_t stride;
-
- struct ka_param_t *param;
- size_t param_count;
-};
-
-
-struct ka_technique_common_t {
- struct ka_accessor_t accessor;
-};
-
-
-struct ka_source_t {
- char *id;
- struct ka_float_array_t float_array;
- struct ka_technique_common_t technique_common;
-};
-
-
-struct ka_vertices_t {
-};
-
-
-struct ka_triangles_t {
-};
-
-
-struct ka_mesh_t {
- struct ka_source_t *source;
- size_t source_count;
-
- struct ka_vertices_t vertices;
-
- struct ka_triangles_t *triangles;
- size_t triangles_count;
-};
-
-
-struct ka_geometry_t {
- struct ka_mesh_t mesh;
-};
-
-
-typedef ka_real_t ka_matrix_t[16];
-
-
#endif
diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c
index ba1ca58..5e93c55 100644
--- a/src/geometry/geometry.c
+++ b/src/geometry/geometry.c
@@ -2,4 +2,16 @@
#include <kalmia.h>
#include "util/util.h"
+#include "xml/xml.h"
#include "geometry.h"
+
+
+int kai_read_float_array(struct ka_float_array_t *dest, struct kai_tag_t *src)
+{
+ if (strcmp(src->type, "float_array") != 0) {
+ /* incorrect tag type */
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/geometry/geometry.h b/src/geometry/geometry.h
index da089c1..1672ffa 100644
--- a/src/geometry/geometry.h
+++ b/src/geometry/geometry.h
@@ -2,5 +2,8 @@
#define KALMIA_GEOMETRY_H
#include <kalmia.h>
+#include "xml/xml.h"
+
+int kai_read_float_array(struct ka_float_array_t *dest, struct kai_tag_t *src);
#endif
diff --git a/src/geometry/geometry.test.c b/src/geometry/geometry.test.c
index fe4421e..b724ee7 100644
--- a/src/geometry/geometry.test.c
+++ b/src/geometry/geometry.test.c
@@ -8,5 +8,20 @@
LILY_FILE_BEGIN(geometry_suite)
+LILY_TEST("fail to read non-float_array")
+{
+ struct kai_tag_t *t = kai_parse_string(
+ "<non_float_array></non_float_array>"
+ );
+
+ struct ka_float_array_t arr;
+ int result = kai_read_float_array(&arr, t);
+ CHECK_EQF(result, -1, "%d");
+
+ kai_tag_destroy(t);
+}
+#include LILY_PUSH_TEST()
+
+
#define LILY_FILE_END
#include LILY_REGISTER_TESTS()
diff --git a/src/xml/kalmia.tab.c b/src/xml/kalmia.tab.c
index 6f6f547..95492f0 100644
--- a/src/xml/kalmia.tab.c
+++ b/src/xml/kalmia.tab.c
@@ -491,18 +491,18 @@ union yyalloc
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
-#define YYFINAL 7
+#define YYFINAL 9
/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 31
+#define YYLAST 32
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 14
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 9
/* YYNRULES -- Number of rules. */
-#define YYNRULES 16
+#define YYNRULES 17
/* YYNSTATES -- Number of states. */
-#define YYNSTATES 31
+#define YYNSTATES 32
/* YYMAXUTOK -- Last valid token kind. */
#define YYMAXUTOK 266
@@ -552,8 +552,8 @@ static const yytype_int8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 94, 94, 98, 99, 104, 110, 117, 124, 128,
- 133, 142, 147, 156, 161, 162, 166
+ 0, 95, 95, 96, 100, 101, 106, 112, 119, 126,
+ 130, 135, 144, 149, 158, 163, 164, 168
};
#endif
@@ -596,10 +596,10 @@ yysymbol_name (yysymbol_kind_t yysymbol)
STATE-NUM. */
static const yytype_int8 yypact[] =
{
- 8, 11, 17, 10, -6, -4, -6, -6, 3, 12,
- 14, -1, -6, -6, -6, -6, 9, 7, -6, 16,
- -6, -6, -6, 13, -6, -6, -6, -6, 15, 18,
- -6
+ 13, 1, -5, 10, -6, -3, -6, -6, 0, -6,
+ 15, 17, 14, -6, -6, -6, -6, 2, 6, -6,
+ 18, -6, -6, -6, 12, -6, -6, -6, -6, 16,
+ 19, -6
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@@ -607,22 +607,22 @@ static const yytype_int8 yypact[] =
means the default is an error. */
static const yytype_int8 yydefact[] =
{
- 0, 0, 0, 0, 2, 0, 8, 1, 0, 0,
- 0, 0, 3, 5, 9, 11, 0, 0, 14, 0,
- 6, 4, 7, 0, 10, 12, 15, 13, 0, 0,
- 16
+ 0, 0, 0, 0, 2, 0, 9, 3, 0, 1,
+ 0, 0, 0, 4, 6, 10, 12, 0, 0, 15,
+ 0, 7, 5, 8, 0, 11, 13, 16, 14, 0,
+ 0, 17
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
- -6, -6, -6, -3, -6, -6, -5, -6, 6
+ -6, -6, -6, -1, -6, -6, 9, -6, 11
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
- 0, 2, 11, 4, 5, 6, 13, 17, 18
+ 0, 3, 12, 4, 5, 6, 14, 18, 19
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
@@ -630,42 +630,42 @@ static const yytype_int8 yydefgoto[] =
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_int8 yytable[] =
{
- 3, 9, 12, 3, 9, 20, 22, 10, 21, 14,
- 15, 1, 16, 24, 25, 3, 16, 7, 8, 9,
- 19, 23, 27, 26, 0, 29, 28, 0, 0, 0,
- 0, 30
+ 7, 2, 10, 8, 13, 2, 15, 16, 11, 17,
+ 9, 22, 25, 26, 24, 17, 1, 2, 2, 10,
+ 21, 23, 10, 20, 28, 29, 30, 0, 0, 27,
+ 0, 0, 31
};
static const yytype_int8 yycheck[] =
{
- 4, 5, 5, 4, 5, 10, 11, 11, 11, 6,
- 7, 3, 9, 6, 7, 4, 9, 0, 8, 5,
- 8, 12, 6, 17, -1, 10, 13, -1, -1, -1,
- -1, 13
+ 1, 4, 5, 8, 5, 4, 6, 7, 11, 9,
+ 0, 12, 6, 7, 12, 9, 3, 4, 4, 5,
+ 11, 12, 5, 8, 6, 13, 10, -1, -1, 18,
+ -1, -1, 13
};
/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
state STATE-NUM. */
static const yytype_int8 yystos[] =
{
- 0, 3, 15, 4, 17, 18, 19, 0, 8, 5,
- 11, 16, 17, 20, 6, 7, 9, 21, 22, 8,
- 20, 17, 20, 12, 6, 7, 22, 6, 13, 10,
- 13
+ 0, 3, 4, 15, 17, 18, 19, 17, 8, 0,
+ 5, 11, 16, 17, 20, 6, 7, 9, 21, 22,
+ 8, 20, 17, 20, 12, 6, 7, 22, 6, 13,
+ 10, 13
};
/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
static const yytype_int8 yyr1[] =
{
- 0, 14, 15, 16, 16, 17, 17, 17, 17, 18,
- 18, 19, 19, 20, 21, 21, 22
+ 0, 14, 15, 15, 16, 16, 17, 17, 17, 17,
+ 18, 18, 19, 19, 20, 21, 21, 22
};
/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
static const yytype_int8 yyr2[] =
{
- 0, 2, 2, 1, 2, 2, 3, 3, 1, 3,
- 4, 3, 4, 3, 1, 2, 5
+ 0, 2, 1, 2, 1, 2, 2, 3, 3, 1,
+ 3, 4, 3, 4, 3, 1, 2, 5
};
@@ -1524,127 +1524,133 @@ yyreduce:
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
- case 2: /* document: PROLOG tag */
-#line 94 "kalmia.y"
- { *document = (yyvsp[0].tag); }
+ case 2: /* document: tag */
+#line 95 "kalmia.y"
+ { *document = (yyvsp[0].tag); }
#line 1531 "kalmia.tab.c"
break;
- case 3: /* tags: tag */
-#line 98 "kalmia.y"
- { (yyval.tag) = (yyvsp[0].tag); }
+ case 3: /* document: PROLOG tag */
+#line 96 "kalmia.y"
+ { *document = (yyvsp[0].tag); }
#line 1537 "kalmia.tab.c"
break;
- case 4: /* tags: tags tag */
-#line 99 "kalmia.y"
- { (yyval.tag) = (yyvsp[-1].tag); kai_tag_last((yyval.tag))->next = (yyvsp[0].tag); }
+ case 4: /* tags: tag */
+#line 100 "kalmia.y"
+ { (yyval.tag) = (yyvsp[0].tag); }
#line 1543 "kalmia.tab.c"
break;
- case 5: /* tag: start_tag end_tag */
-#line 105 "kalmia.y"
+ case 5: /* tags: tags tag */
+#line 101 "kalmia.y"
+ { (yyval.tag) = (yyvsp[-1].tag); kai_tag_last((yyval.tag))->next = (yyvsp[0].tag); }
+#line 1549 "kalmia.tab.c"
+ break;
+
+ case 6: /* tag: start_tag end_tag */
+#line 107 "kalmia.y"
{
(yyval.tag) = (yyvsp[-1].tag);
if (strcmp((yyval.tag)->type, (yyvsp[0].string)) != 0) TAG_MISMATCH((yyval.tag)->type, (yyvsp[0].string));
free((yyvsp[0].string));
}
-#line 1553 "kalmia.tab.c"
+#line 1559 "kalmia.tab.c"
break;
- case 6: /* tag: start_tag CONTENT end_tag */
-#line 111 "kalmia.y"
+ case 7: /* tag: start_tag CONTENT end_tag */
+#line 113 "kalmia.y"
{
(yyval.tag) = (yyvsp[-2].tag);
(yyval.tag)->content = (yyvsp[-1].string);
if (strcmp((yyval.tag)->type, (yyvsp[0].string)) != 0) TAG_MISMATCH((yyval.tag)->type, (yyvsp[0].string));
free((yyvsp[0].string));
}
-#line 1564 "kalmia.tab.c"
+#line 1570 "kalmia.tab.c"
break;
- case 7: /* tag: start_tag tags end_tag */
-#line 118 "kalmia.y"
+ case 8: /* tag: start_tag tags end_tag */
+#line 120 "kalmia.y"
{
(yyval.tag) = (yyvsp[-2].tag);
(yyval.tag)->children = (yyvsp[-1].tag);
if (strcmp((yyval.tag)->type, (yyvsp[0].string)) != 0) TAG_MISMATCH((yyval.tag)->type, (yyvsp[0].string));
free((yyvsp[0].string));
}
-#line 1575 "kalmia.tab.c"
+#line 1581 "kalmia.tab.c"
break;
- case 8: /* tag: empty_tag */
-#line 124 "kalmia.y"
+ case 9: /* tag: empty_tag */
+#line 126 "kalmia.y"
{ (yyval.tag) = (yyvsp[0].tag); }
-#line 1581 "kalmia.tab.c"
+#line 1587 "kalmia.tab.c"
break;
- case 9: /* start_tag: S_TAG_OPEN NAME TAG_CLOSE */
-#line 129 "kalmia.y"
+ case 10: /* start_tag: S_TAG_OPEN NAME TAG_CLOSE */
+#line 131 "kalmia.y"
{
(yyval.tag) = kai_tag_new((yyvsp[-1].string), NULL);
if ((yyval.tag) == NULL) YYNOMEM;
}
-#line 1590 "kalmia.tab.c"
+#line 1596 "kalmia.tab.c"
break;
- case 10: /* start_tag: S_TAG_OPEN NAME attributes TAG_CLOSE */
-#line 134 "kalmia.y"
+ case 11: /* start_tag: S_TAG_OPEN NAME attributes TAG_CLOSE */
+#line 136 "kalmia.y"
{
(yyval.tag) = kai_tag_new((yyvsp[-2].string), (yyvsp[-1].attr));
if ((yyval.tag) == NULL) YYNOMEM;
}
-#line 1599 "kalmia.tab.c"
+#line 1605 "kalmia.tab.c"
break;
- case 11: /* empty_tag: S_TAG_OPEN NAME EMPTY_TAG_CLOSE */
-#line 143 "kalmia.y"
+ case 12: /* empty_tag: S_TAG_OPEN NAME EMPTY_TAG_CLOSE */
+#line 145 "kalmia.y"
{
(yyval.tag) = kai_tag_new((yyvsp[-1].string), NULL);
if ((yyval.tag) == NULL) YYNOMEM;
}
-#line 1608 "kalmia.tab.c"
+#line 1614 "kalmia.tab.c"
break;
- case 12: /* empty_tag: S_TAG_OPEN NAME attributes EMPTY_TAG_CLOSE */
-#line 148 "kalmia.y"
+ case 13: /* empty_tag: S_TAG_OPEN NAME attributes EMPTY_TAG_CLOSE */
+#line 150 "kalmia.y"
{
(yyval.tag) = kai_tag_new((yyvsp[-2].string), (yyvsp[-1].attr));
if ((yyval.tag) == NULL) YYNOMEM;
}
-#line 1617 "kalmia.tab.c"
+#line 1623 "kalmia.tab.c"
break;
- case 13: /* end_tag: E_TAG_OPEN NAME TAG_CLOSE */
-#line 156 "kalmia.y"
+ case 14: /* end_tag: E_TAG_OPEN NAME TAG_CLOSE */
+#line 158 "kalmia.y"
{ (yyval.string) = (yyvsp[-1].string); }
-#line 1623 "kalmia.tab.c"
+#line 1629 "kalmia.tab.c"
break;
- case 14: /* attributes: attribute */
-#line 161 "kalmia.y"
+ case 15: /* attributes: attribute */
+#line 163 "kalmia.y"
{ (yyval.attr) = (yyvsp[0].attr); }
-#line 1629 "kalmia.tab.c"
+#line 1635 "kalmia.tab.c"
break;
- case 15: /* attributes: attributes attribute */
-#line 162 "kalmia.y"
+ case 16: /* attributes: attributes attribute */
+#line 164 "kalmia.y"
{ (yyval.attr) = (yyvsp[-1].attr); kai_attr_last((yyval.attr))->next = (yyvsp[0].attr); }
-#line 1635 "kalmia.tab.c"
+#line 1641 "kalmia.tab.c"
break;
- case 16: /* attribute: ATTR '=' '"' TEXT '"' */
-#line 167 "kalmia.y"
+ case 17: /* attribute: ATTR '=' '"' TEXT '"' */
+#line 169 "kalmia.y"
{
(yyval.attr) = kai_attr_new((yyvsp[-4].string), (yyvsp[-1].string));
if ((yyval.attr) == NULL) YYNOMEM;
}
-#line 1644 "kalmia.tab.c"
+#line 1650 "kalmia.tab.c"
break;
-#line 1648 "kalmia.tab.c"
+#line 1654 "kalmia.tab.c"
default: break;
}
@@ -1873,7 +1879,7 @@ yyreturnlab:
return yyresult;
}
-#line 174 "kalmia.y"
+#line 176 "kalmia.y"
diff --git a/yy/kalmia.y b/yy/kalmia.y
index 3d28248..9b2574c 100644
--- a/yy/kalmia.y
+++ b/yy/kalmia.y
@@ -91,7 +91,9 @@
%%
-document: PROLOG tag { *document = $2; }
+document:
+ tag { *document = $1; }
+ | PROLOG tag { *document = $2; }
tags: