on master help sign in
Warning fixes and a few off-by-one fixes
commit5f4ef783805fe6209581556e7b857a3cded3db52 authorNeil Mitchell <ndmitchell@gmail.com> dateSun 27 Nov 2016, 14:54 (10 years ago) parentf5e23f6
1 file changed+16−9
hexml.c+16−9
hexml.c+16−9
@@ -10,7 +10,7 @@ typedef int bool;
1010/////////////////////////////////////////////////////////////////////
1111// TYPES
1212
13−int static inline end(str s){return s.start + s.length;}
13+int static inline end(str s) { return s.start + s.length; }
1414
1515str static inline start_length(int32_t start, int32_t length)
1616{
@@ -193,6 +193,7 @@ attr* node_attributes(document* d, node* n, int* res)
193193attr* node_attributeBy(document* d, node* n, char* s, int slen)
194194{
195195 assert(0);
196+ return NULL;
196197}
197198
198199// Search for given strings within a node
@@ -213,6 +214,7 @@ node* node_firstChildBy(document* d, node* n, char* s, int slen)
213214node* node_nextChildBy(document* d, node* parent, node* prev, char* s, int slen)
214215{
215216 assert(0);
217+ return NULL;
216218}
217219
218220
@@ -299,7 +301,6 @@ str parse_name(document* d)
299301str parse_attrval(document* d)
300302{
301303 trim(d);
302− str res;
303304 if (peek(d) != '=') return start_length(0,0);
304305 trim(d);
305306 return parse_name(d);
@@ -323,13 +324,14 @@ str parse_content(document* d);
323324// Add a new entry into tag, am at a '<'
324325void parse_tag(document* d)
325326{
326− char c = get(d);
327− assert(c == '<');
328−
329327 node_alloc(&d->nodes, 1);
330− int me = d->nodes.used_back;
331328 d->nodes.used_back++;
329+ int me = d->nodes.size - d->nodes.used_back;
330+
331+ char c = get(d);
332+ assert(c == '<');
332333
334+ d->nodes.nodes[me].outer.start = d->cursor;
333335 d->nodes.nodes[me].name = parse_name(d);
334336 d->nodes.nodes[me].attrs = parse_attributes(d);
335337
@@ -338,9 +340,13 @@ void parse_tag(document* d)
338340 {
339341 skip(d, 2);
340342 d->nodes.nodes[me].nodes = start_length(0, 0);
343+ d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, d->cursor).length;
344+ d->nodes.nodes[me].inner = start_length(d->cursor, 0);
341345 return;
342346 }
347+ d->nodes.nodes[me].inner.start = d->cursor;
343348 d->nodes.nodes[me].nodes = parse_content(d);
349+ d->nodes.nodes[me].inner.length = start_end(d->nodes.nodes[me].inner.start, d->cursor).length;
344350
345351 if (d->error_message != NULL) return;
346352 if (peek(d) == '<' && peekAt(d, 1) == '/')
@@ -350,13 +356,14 @@ void parse_tag(document* d)
350356 lexeme("openning tag", d, d->nodes.nodes[me].name);
351357 lexeme("closing tag", d, close);
352358 trim(d);
359+ d->nodes.nodes[me].outer.length = start_end(d->nodes.nodes[me].outer.start, d->cursor).length;
353360 if (close.length == d->nodes.nodes[me].name.length &&
354361 memcmp(&d->body[close.start], &d->body[d->nodes.nodes[me].name.start], close.length) == 0)
355362 return;
356− d->error_message = strdup("Mismatch in closing tags");
363+ d->error_message = _strdup("Mismatch in closing tags");
357364 return;
358365 }
359− d->error_message = strdup("Weirdness when trying to close tags");
366+ d->error_message = _strdup("Weirdness when trying to close tags");
360367}
361368
362369// Parser until </, return the index of your node children
@@ -427,7 +434,7 @@ document* document_parse(char* s, int slen)
427434 if (d->cursor < d->length && d->error_message == NULL)
428435 {
429436 printf("%i vs %i\n", d->cursor, d->length);
430− d->error_message = strdup("Trailing junk at the end of the document");
437+ d->error_message = _strdup("Trailing junk at the end of the document");
431438 }
432439 return d;
433440}