Now we need a lookup table to be able to find sections by name.
Something that provides an `n*log(N)` search time is probably
justified, but for now I want a minimal stand-alone program so a
-linked list managed by insertion-sort will do. As a comparison
-function it is easiest to sort based on length before content. So
-sections won't be in standard lexical order, but that isn't important.
+linked list managed by insertion-sort will do.
+
+The text compare function will likely be useful for any clients of our
+library, so we may as well export it.
If we cannot find a section, we simply want to create it. This allows
sections and references to be created in any order. Sections with
no references or no content will cause a warning eventually.
+#### exported functions
+
+ int text_cmp(struct text a, struct text b);
+
#### internal functions
- static int text_cmp(struct text a, struct text b)
+ int text_cmp(struct text a, struct text b)
{
- if (a.len != b.len)
+ int len = a.len;
+ if (len > b.len)
+ len = b.len;
+ int cmp = strncmp(a.txt, b.txt, len);
+ if (cmp)
+ return cmp;
+ else
return a.len - b.len;
- return strncmp(a.txt, b.txt, a.len);
}
static struct psection *section_find(struct psection **list, struct text name)