summaryrefslogtreecommitdiff
path: root/mktext.c
diff options
context:
space:
mode:
Diffstat (limited to 'mktext.c')
-rw-r--r--mktext.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/mktext.c b/mktext.c
index 55af074..1cfcf4b 100644
--- a/mktext.c
+++ b/mktext.c
@@ -94,8 +94,29 @@ int main(int argc, char **argv) {
else { missing++; /* keep a placeholder so indices stay aligned */ }
size_t need = strlen(cv) + strlen(text) + 3;
while (olen + need > obuf) { obuf *= 2; out = realloc(out, obuf); }
- olen += (size_t)snprintf(out + olen, need, "%s %s", cv, text);
- out[olen++] = '\n';
+ /* "chap:verse " then the text with runs of whitespace collapsed to one
+ * space and the ends trimmed -- matching lectio's Fields-based render, so
+ * the source's stray double spaces don't leak through. */
+ {
+ size_t cl = strlen(cv);
+ int sp = 0, started = 0;
+ const char *p;
+ memcpy(out + olen, cv, cl);
+ olen += cl;
+ out[olen++] = ' ';
+ for (p = text; *p; p++) {
+ if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') {
+ sp = 1;
+ } else {
+ if (sp && started)
+ out[olen++] = ' ';
+ sp = 0;
+ started = 1;
+ out[olen++] = *p;
+ }
+ }
+ out[olen++] = '\n';
+ }
}
if (missing)
fprintf(stderr, "mktext: warning: %zu of %zu verses not in corpus (blank)\n", missing, nkeys);