on master help sign in
Get rid of unused pieces
6e52955Neil Mitchell
gen/test.c+4−15
@@ -3,11 +3,8 @@
3#include <stdlib.h>
3#include <stdlib.h>
4#include <string.h>
4#include <string.h>
5#include <assert.h>
5#include <assert.h>
6−#include <ctype.h>
7#include <stdio.h>
6#include <stdio.h>
8
7
9−typedef int bool;
10−
11/////////////////////////////////////////////////////////////////////
8/////////////////////////////////////////////////////////////////////
12// TYPES
9// TYPES
13
10
@@ -53,20 +50,13 @@ typedef struct
53struct document
50struct document
54{
51{
55 const char* body; // pointer to initial argument, not owned by us
52 const char* body; // pointer to initial argument, not owned by us
56−
53+ int body_len; // length of the body
57− // things only used while parsing
58− const char* cursor; // pointer to where we are in body
59− const char* end; // pointer to one past the last char
60− // if cursor is > end we have gone past the end
61
54
62 char* error_message;
55 char* error_message;
63 node_buffer nodes;
56 node_buffer nodes;
64 attr_buffer attrs;
57 attr_buffer attrs;
65};
58};
66
59
67−static inline int doc_length(const document* d) { return (int) (d->end - d->body); }
68−static inline int doc_position(const document* d) { return (int) (d->cursor - d->body); }
69−
70
60
71/////////////////////////////////////////////////////////////////////
61/////////////////////////////////////////////////////////////////////
72// RENDER CODE
62// RENDER CODE
@@ -100,7 +90,7 @@ static inline void bound_str(str s, int mn, int mx)
100
90
101static void render_str(render* r, str s)
91static void render_str(render* r, str s)
102{
92{
103− bound_str(s, 0, doc_length(r->d));
93+ bound_str(s, 0, r->d->body_len);
104 for (int i = 0; i < s.length; i++)
94 for (int i = 0; i < s.length; i++)
105 render_char(r, r->d->body[s.start + i]);
95 render_char(r, r->d->body[s.start + i]);
106}
96}
@@ -109,7 +99,7 @@ static void render_tag(render* r, const node* n);
109
99
110static void render_content(render* r, const node* n)
100static void render_content(render* r, const node* n)
111{
101{
112− bound_str(n->inner, 0, doc_length(r->d));
102+ bound_str(n->inner, 0, r->d->body_len);
113 bound_str(n->nodes, 0, r->d->nodes.used_front);
103 bound_str(n->nodes, 0, r->d->nodes.used_front);
114 bound_str(n->attrs, 0, r->d->attrs.used);
104 bound_str(n->attrs, 0, r->d->attrs.used);
115
105
@@ -308,8 +298,7 @@ document* hexml_document_parse(const char* s, int slen)
308 assert(buf);
298 assert(buf);
309 document* d = &buf->document;
299 document* d = &buf->document;
310 d->body = s;
300 d->body = s;
311− d->cursor = s;
301+ d->body_len = slen;
312− d->end = &s[slen];
313 d->error_message = NULL;
302 d->error_message = NULL;
314 d->attrs.size = 1000;
303 d->attrs.size = 1000;
315 d->attrs.used = 0;
304 d->attrs.used = 0;