X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/halibut/blobdiff_plain/f15300499bce37cd28ea2ace0f2bd1c364fc835e..0dfaac7284d7f1a54e957bba4a881d93328c1630:/bk_text.c diff --git a/bk_text.c b/bk_text.c index d7c539c..4f8cdd7 100644 --- a/bk_text.c +++ b/bk_text.c @@ -10,7 +10,7 @@ typedef enum { LEFT, LEFTPLUS, CENTRE } alignment; typedef struct { alignment align; - int just_numbers; + int number_at_all, just_numbers; wchar_t *underline; wchar_t *number_suffix; } alignstruct; @@ -67,6 +67,7 @@ static textconfig text_configure(paragraph *source) { ret.bullet.alt = NULL; ret.bullet.type = word_Normal; ret.atitle.just_numbers = FALSE; /* ignored */ + ret.atitle.number_at_all = TRUE; /* ignored */ /* * Defaults. @@ -80,12 +81,14 @@ static textconfig text_configure(paragraph *source) { ret.atitle.underline = L"\x2550\0=\0\0"; ret.achapter.align = LEFT; ret.achapter.just_numbers = FALSE; + ret.achapter.number_at_all = TRUE; ret.achapter.number_suffix = L": "; ret.achapter.underline = L"\x203E\0-\0\0"; ret.nasect = 1; ret.asect = snewn(ret.nasect, alignstruct); ret.asect[0].align = LEFTPLUS; ret.asect[0].just_numbers = TRUE; + ret.asect[0].number_at_all = TRUE; ret.asect[0].number_suffix = L" "; ret.asect[0].underline = L"\0"; ret.include_version_id = TRUE; @@ -126,9 +129,7 @@ static textconfig text_configure(paragraph *source) { if (!ustricmp(p->keyword, L"text-indent")) { ret.indent = utoi(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-charset")) { - char *csname = utoa_dup(uadv(p->keyword), CS_ASCII); - ret.charset = charset_from_localenc(csname); - sfree(csname); + ret.charset = charset_from_ustr(&p->fpos, uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-filename")) { sfree(ret.filename); ret.filename = dupstr(adv(p->origkeyword)); @@ -146,6 +147,8 @@ static textconfig text_configure(paragraph *source) { ret.achapter.underline = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-chapter-numeric")) { ret.achapter.just_numbers = utob(uadv(p->keyword)); + } else if (!ustricmp(p->keyword, L"text-chapter-shownumber")) { + ret.achapter.number_at_all = utob(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"text-chapter-suffix")) { ret.achapter.number_suffix = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"text-section-align")) { @@ -193,6 +196,21 @@ static textconfig text_configure(paragraph *source) { ret.nasect = n+1; } ret.asect[n].just_numbers = utob(q); + } else if (!ustricmp(p->keyword, L"text-section-shownumber")) { + wchar_t *q = uadv(p->keyword); + int n = 0; + if (uisdigit(*q)) { + n = utoi(q); + q = uadv(q); + } + if (n >= ret.nasect) { + int i; + ret.asect = sresize(ret.asect, n+1, alignstruct); + for (i = ret.nasect; i <= n; i++) + ret.asect[i] = ret.asect[ret.nasect-1]; + ret.nasect = n+1; + } + ret.asect[n].number_at_all = utob(q); } else if (!ustricmp(p->keyword, L"text-section-suffix")) { wchar_t *q = uadv(p->keyword); int n = 0; @@ -293,7 +311,7 @@ void text_backend(paragraph *sourceform, keywordlist *keywords, word spaceword; textfile tf; wchar_t *prefixextra; - int nesting, nestindent; + int nesting, nestbase, nestindent; int indentb, indenta; IGNORE(unused); @@ -305,7 +323,10 @@ void text_backend(paragraph *sourceform, keywordlist *keywords, /* * Open the output file. */ - tf.fp = fopen(conf.filename, "w"); + if (!strcmp(conf.filename, "-")) + tf.fp = stdout; + else + tf.fp = fopen(conf.filename, "w"); if (!tf.fp) { error(err_cantopenw, conf.filename); return; @@ -320,7 +341,8 @@ void text_backend(paragraph *sourceform, keywordlist *keywords, conf.atitle, conf.indent, conf.width, &conf); nestindent = conf.listindentbefore + conf.listindentafter; - nesting = (conf.indent_preambles ? 0 : -conf.indent); + nestbase = (conf.indent_preambles ? 0 : -conf.indent); + nesting = nestbase; /* Do the main document */ for (p = sourceform; p; p = p->next) switch (p->type) { @@ -338,7 +360,7 @@ void text_backend(paragraph *sourceform, keywordlist *keywords, break; case para_LcontPop: nesting -= nestindent; - assert(nesting >= 0); + assert(nesting >= nestbase); break; /* @@ -441,7 +463,8 @@ void text_backend(paragraph *sourceform, keywordlist *keywords, * Tidy up */ text_output(&tf, NULL); /* end charset conversion */ - fclose(tf.fp); + if (tf.fp != stdout) + fclose(tf.fp); sfree(conf.asect); sfree(conf.filename); } @@ -617,12 +640,14 @@ static void text_heading(textfile *tf, word *tprefix, word *nprefix, int firstlinewidth, wrapwidth; wrappedline *wrapping, *p; - if (align.just_numbers && nprefix) { - text_rdaddw(&t, nprefix, NULL, cfg); - rdadds(&t, align.number_suffix); - } else if (!align.just_numbers && tprefix) { - text_rdaddw(&t, tprefix, NULL, cfg); - rdadds(&t, align.number_suffix); + if (align.number_at_all) { + if (align.just_numbers && nprefix) { + text_rdaddw(&t, nprefix, NULL, cfg); + rdadds(&t, align.number_suffix); + } else if (!align.just_numbers && tprefix) { + text_rdaddw(&t, tprefix, NULL, cfg); + rdadds(&t, align.number_suffix); + } } margin = length = ustrwid(t.text ? t.text : L"", cfg->charset);