diff options
| -rw-r--r-- | biblio.c | 2 | ||||
| -rw-r--r-- | buttress.h | 2 | ||||
| -rw-r--r-- | contents.c | 30 | ||||
| -rw-r--r-- | index.c | 2 | ||||
| -rw-r--r-- | input.c | 7 | ||||
| -rw-r--r-- | keywords.c | 4 | ||||
| -rw-r--r-- | ustring.c | 4 |
7 files changed, 43 insertions, 8 deletions
@@ -67,7 +67,7 @@ void gen_citations(paragraph *source, keywordlist *kl) { wchar_t *wp = para->keyword; while (*wp) { cite_biblio(kl, wp, para->fpos); - wp += 1+ustrlen(wp); + wp = uadv(wp); } } @@ -97,6 +97,7 @@ enum { para_NoCite, para_Title, para_VersionID, + para_Config, /* configuration directive */ para_NotParaType /* placeholder value */ }; @@ -225,6 +226,7 @@ word *dup_word_list(word *w); wchar_t *ustrdup(wchar_t *s); char *ustrtoa(wchar_t *s, char *outbuf, int size); int ustrlen(wchar_t *s); +wchar_t *uadv(wchar_t *s); wchar_t *ustrcpy(wchar_t *dest, wchar_t *source); wchar_t utolower(wchar_t); int ustrcmp(wchar_t *lhs, wchar_t *rhs); @@ -15,6 +15,9 @@ struct numberstate_Tag { int *sectionlevels; int maxsectlevel; int listitem; + wchar_t *chaptertext; /* the word for a chapter */ + wchar_t *sectiontext; /* the word for a section */ + wchar_t *apptext; /* the word for an appendix */ }; numberstate *number_init(void) { @@ -89,6 +92,27 @@ static void doanumber(word ***wret, int num) { dotext(wret, p); } +void number_cfg(numberstate *state, paragraph *source) { + /* + * Defaults + */ + state->chaptertext = L"Chapter"; + state->sectiontext = L"Section"; + state->apptext = L"Appendix"; + + for (; source; source = source->next) { + if (source->type == para_Config) { + if (!ustricmp(source->keyword, L"chapter")) { + state->chaptertext = uadv(source->keyword); + } else if (!ustricmp(source->keyword, L"section")) { + state->sectiontext = uadv(source->keyword); + } else if (!ustricmp(source->keyword, L"appendix")) { + state->apptext = uadv(source->keyword); + } + } + } +} + word *number_mktext(numberstate *state, int para, int aux, int prev, word **auxret) { word *ret = NULL; @@ -101,7 +125,7 @@ word *number_mktext(numberstate *state, int para, int aux, int prev, state->chapternum++; for (i = 0; i < state->maxsectlevel; i++) state->sectionlevels[i] = 0; - dotext(&pret, L"Chapter"); + dotext(&pret, state->chaptertext); dospace(&pret); ret2 = pret; donumber(&pret, state->chapternum); @@ -118,7 +142,7 @@ word *number_mktext(numberstate *state, int para, int aux, int prev, state->sectionlevels[level]++; for (i = level+1; i < state->maxsectlevel; i++) state->sectionlevels[i] = 0; - dotext(&pret, L"Section"); + dotext(&pret, state->sectiontext); dospace(&pret); ret2 = pret; if (state->ischapter) @@ -136,7 +160,7 @@ word *number_mktext(numberstate *state, int para, int aux, int prev, state->appendixnum++; for (i = 0; i < state->maxsectlevel; i++) state->sectionlevels[i] = 0; - dotext(&pret, L"Appendix"); + dotext(&pret, state->apptext); dospace(&pret); ret2 = pret; doanumber(&pret, state->appendixnum); @@ -69,7 +69,7 @@ void index_merge(index *idx, int is_explicit, wchar_t *tags, word *text) { /* * FIXME: want to warn on overlapping source sets. */ - for (; *tags; tags += 1+ustrlen(tags)) { + for (; *tags; tags = uadv(tags)) { t = make_indextag(); t->name = tags; existing = add23(idx->tags, t, compare_tags); @@ -176,6 +176,7 @@ enum { c_W, /* Web hyperlink */ c_b, /* bulletted list */ c_c, /* code */ + c_cfg, /* configuration directive */ c_copyright, /* copyright statement */ c_cw, /* weak code */ c_date, /* document processing date */ @@ -239,6 +240,7 @@ static void match_kw(token *tok) { {"\\", c__escaped}, /* escaped backslash (\\) */ {"b", c_b}, /* bulletted list */ {"c", c_c}, /* code */ + {"cfg", c_cfg}, /* configuration directive */ {"copyright", c_copyright}, /* copyright statement */ {"cw", c_cw}, /* weak code */ {"date", c_date}, /* document processing date */ @@ -623,6 +625,7 @@ static void read_file(paragraph ***ret, input *in, index *idx) { /* For \b and \n the keyword is optional */ case c_b: needkw = 4; par.type = para_Bullet; break; case c_n: needkw = 4; par.type = para_NumberedList; break; + case c_cfg: needkw = 8; par.type = para_Config; break; case c_copyright: needkw = 32; par.type = para_Copyright; break; case c_define: is_macro = TRUE; needkw = 1; break; /* For \nocite the keyword is _everything_ */ @@ -697,10 +700,10 @@ static void read_file(paragraph ***ret, input *in, index *idx) { /* Move to EOP in case of needkw==8 or 16 (no body) */ if (needkw & 24) { - if (t.type != tok_eop) { + if (t.type != tok_eop && t.type != tok_eof) { error(err_bodyillegal, &t.pos); /* Error recovery: eat the rest of the paragraph */ - while (t.type != tok_eop) + while (t.type != tok_eop && t.type != tok_eof) dtor(t), t = get_token(in); } addpara(par, ret); @@ -90,6 +90,8 @@ keywordlist *get_keywords(paragraph *source) { numberstate *n = number_init(); int prevpara = para_NotParaType; + number_cfg(n, source); + kl->nkeywords = 0; kl->size = 0; kl->keys = NULL; @@ -112,7 +114,7 @@ keywordlist *get_keywords(paragraph *source) { kw->text = source->kwtext; kw->para = source; heap_add(kl, kw); - p += ustrlen(p) + 1; + p = uadv(p); } } } else { @@ -39,6 +39,10 @@ int ustrlen(wchar_t *s) { return len; } +wchar_t *uadv(wchar_t *s) { + return s + 1 + ustrlen(s); +} + wchar_t *ustrcpy(wchar_t *dest, wchar_t *source) { wchar_t *ret = dest; do { |