Hopefully readable now: indent -nut -kr -bl -bli0 -i2 *
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2423 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
e1bc9f0971
commit
0e30afb5d9
16 changed files with 6231 additions and 5689 deletions
|
@ -11,7 +11,8 @@ static wchar_t *gentext(int num)
|
|||
wchar_t *p = text + sizeof(text);
|
||||
*--p = L'\0';
|
||||
*--p = L']';
|
||||
while (num != 0) {
|
||||
while (num != 0)
|
||||
{
|
||||
assert(p > text);
|
||||
*--p = L"0123456789"[num % 10];
|
||||
num /= 10;
|
||||
|
@ -26,12 +27,14 @@ static void cite_biblio(keywordlist * kl, wchar_t * key, filepos fpos)
|
|||
keyword *kw = kw_lookup(kl, key);
|
||||
if (!kw)
|
||||
error(err_nosuchkw, &fpos, key);
|
||||
else {
|
||||
else
|
||||
{
|
||||
/*
|
||||
* We've found a \k reference. If it's a
|
||||
* bibliography entry ...
|
||||
*/
|
||||
if (kw->para->type == para_Biblio) {
|
||||
if (kw->para->type == para_Biblio)
|
||||
{
|
||||
/*
|
||||
* ... then mark the paragraph as cited.
|
||||
*/
|
||||
|
@ -51,24 +54,31 @@ void gen_citations(paragraph * source, keywordlist * kl)
|
|||
paragraph *para;
|
||||
int bibnum = 0;
|
||||
|
||||
for (para = source; para; para = para->next) {
|
||||
for (para = source; para; para = para->next)
|
||||
{
|
||||
word *ptr;
|
||||
|
||||
/*
|
||||
* \BR and \nocite paragraphs get special processing here.
|
||||
*/
|
||||
if (para->type == para_BR) {
|
||||
if (para->type == para_BR)
|
||||
{
|
||||
keyword *kw = kw_lookup(kl, para->keyword);
|
||||
if (!kw) {
|
||||
if (!kw)
|
||||
{
|
||||
error(err_nosuchkw, ¶->fpos, para->keyword);
|
||||
} else if (kw->text) {
|
||||
} else if (kw->text)
|
||||
{
|
||||
error(err_multiBR, ¶->fpos, para->keyword);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
kw->text = dup_word_list(para->words);
|
||||
}
|
||||
} else if (para->type == para_NoCite) {
|
||||
} else if (para->type == para_NoCite)
|
||||
{
|
||||
wchar_t *wp = para->keyword;
|
||||
while (*wp) {
|
||||
while (*wp)
|
||||
{
|
||||
cite_biblio(kl, wp, para->fpos);
|
||||
wp = uadv(wp);
|
||||
}
|
||||
|
@ -77,8 +87,10 @@ void gen_citations(paragraph * source, keywordlist * kl)
|
|||
/*
|
||||
* Scan for keyword references.
|
||||
*/
|
||||
for (ptr = para->words; ptr; ptr = ptr->next) {
|
||||
if (ptr->type == word_UpperXref || ptr->type == word_LowerXref || ptr->type == word_FreeTextXref)
|
||||
for (ptr = para->words; ptr; ptr = ptr->next)
|
||||
{
|
||||
if (ptr->type == word_UpperXref || ptr->type == word_LowerXref
|
||||
|| ptr->type == word_FreeTextXref)
|
||||
cite_biblio(kl, ptr->text, ptr->fpos);
|
||||
}
|
||||
}
|
||||
|
@ -89,11 +101,14 @@ void gen_citations(paragraph * source, keywordlist * kl)
|
|||
* texts for the ones that don't already have explicitly
|
||||
* provided \BR text.
|
||||
*/
|
||||
for (para = source; para; para = para->next) {
|
||||
if (para->type == para_BiblioCited) {
|
||||
for (para = source; para; para = para->next)
|
||||
{
|
||||
if (para->type == para_BiblioCited)
|
||||
{
|
||||
keyword *kw = kw_lookup(kl, para->keyword);
|
||||
assert(kw != NULL);
|
||||
if (!kw->text) {
|
||||
if (!kw->text)
|
||||
{
|
||||
word *wd = smalloc(sizeof(word));
|
||||
wd->text = gentext(++bibnum);
|
||||
wd->type = word_Normal;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -74,7 +74,8 @@ static void donumber(word *** wret, int num)
|
|||
wchar_t text[20];
|
||||
wchar_t *p = text + sizeof(text);
|
||||
*--p = L'\0';
|
||||
while (num != 0) {
|
||||
while (num != 0)
|
||||
{
|
||||
assert(p > text);
|
||||
*--p = L"0123456789"[num % 10];
|
||||
num /= 10;
|
||||
|
@ -89,7 +90,8 @@ static void doanumber(word *** wret, int num)
|
|||
int nletters, aton;
|
||||
nletters = 1;
|
||||
aton = 25;
|
||||
while (num > aton) {
|
||||
while (num > aton)
|
||||
{
|
||||
nletters++;
|
||||
num -= aton + 1;
|
||||
if (aton < INT_MAX / 26)
|
||||
|
@ -99,7 +101,8 @@ static void doanumber(word *** wret, int num)
|
|||
}
|
||||
p = text + sizeof(text);
|
||||
*--p = L'\0';
|
||||
while (nletters--) {
|
||||
while (nletters--)
|
||||
{
|
||||
assert(p > text);
|
||||
*--p = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[num % 26];
|
||||
num /= 26;
|
||||
|
@ -116,13 +119,18 @@ void number_cfg(numberstate * state, paragraph * source)
|
|||
state->sectiontext = L"Section";
|
||||
state->apptext = L"Appendix";
|
||||
|
||||
for (; source; source = source->next) {
|
||||
if (source->type == para_Config) {
|
||||
if (!ustricmp(source->keyword, L"chapter")) {
|
||||
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")) {
|
||||
} else if (!ustricmp(source->keyword, L"section"))
|
||||
{
|
||||
state->sectiontext = uadv(source->keyword);
|
||||
} else if (!ustricmp(source->keyword, L"appendix")) {
|
||||
} else if (!ustricmp(source->keyword, L"appendix"))
|
||||
{
|
||||
state->apptext = uadv(source->keyword);
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +146,8 @@ word *number_mktext(numberstate * state, paragraph * p, wchar_t * category,
|
|||
int i, level;
|
||||
|
||||
level = -2; /* default for non-section-heading */
|
||||
switch (p->type) {
|
||||
switch (p->type)
|
||||
{
|
||||
case para_Chapter:
|
||||
state->chapternum++;
|
||||
for (i = 0; i < state->maxsectlevel; i++)
|
||||
|
@ -154,14 +163,16 @@ word *number_mktext(numberstate * state, paragraph * p, wchar_t * category,
|
|||
case para_Heading:
|
||||
case para_Subsect:
|
||||
level = (p->type == para_Heading ? 0 : p->aux);
|
||||
if (level > state->oklevel) {
|
||||
if (level > state->oklevel)
|
||||
{
|
||||
error(err_sectjump, &p->fpos);
|
||||
*errflag = TRUE;
|
||||
ret = NULL;
|
||||
break;
|
||||
}
|
||||
state->oklevel = level + 1;
|
||||
if (state->maxsectlevel <= level) {
|
||||
if (state->maxsectlevel <= level)
|
||||
{
|
||||
state->maxsectlevel = level + 32;
|
||||
state->sectionlevels = resize(state->sectionlevels,
|
||||
state->maxsectlevel);
|
||||
|
@ -176,7 +187,8 @@ word *number_mktext(numberstate * state, paragraph * p, wchar_t * category,
|
|||
donumber(&pret, state->chapternum);
|
||||
else
|
||||
doanumber(&pret, state->appendixnum);
|
||||
for (i = 0; i <= level; i++) {
|
||||
for (i = 0; i <= level; i++)
|
||||
{
|
||||
dotext(&pret, L".");
|
||||
if (state->sectionlevels[i] == 0)
|
||||
state->sectionlevels[i] = 1;
|
||||
|
@ -211,10 +223,12 @@ word *number_mktext(numberstate * state, paragraph * p, wchar_t * category,
|
|||
* Now set up parent, child and sibling links.
|
||||
*/
|
||||
p->parent = p->child = p->sibling = NULL;
|
||||
if (level != -2) {
|
||||
if (level != -2)
|
||||
{
|
||||
if (state->currentsects[level + 1])
|
||||
state->currentsects[level + 1]->sibling = p;
|
||||
if (level >= 0 && state->currentsects[level]) {
|
||||
if (level >= 0 && state->currentsects[level])
|
||||
{
|
||||
p->parent = state->currentsects[level];
|
||||
if (!state->currentsects[level]->child)
|
||||
state->currentsects[level]->child = p;
|
||||
|
@ -222,7 +236,8 @@ word *number_mktext(numberstate * state, paragraph * p, wchar_t * category,
|
|||
state->currentsects[level + 1] = state->lastsect = p;
|
||||
for (i = level + 2; i < state->maxsectlevel + 1; i++)
|
||||
state->currentsects[i] = NULL;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
p->parent = state->lastsect;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ static void do_error(int code, va_list ap)
|
|||
filepos fpos, fpos2;
|
||||
int flags;
|
||||
|
||||
switch (code) {
|
||||
switch (code)
|
||||
{
|
||||
case err_nomemory: /* no arguments */
|
||||
sprintf(error, "out of memory");
|
||||
flags = PREFIX;
|
||||
|
@ -52,8 +53,7 @@ static void do_error(int code, va_list ap)
|
|||
break;
|
||||
case err_brokencodepara:
|
||||
fpos = *va_arg(ap, filepos *);
|
||||
sprintf(error,
|
||||
"every line of a code paragraph should begin `\\c'");
|
||||
sprintf(error, "every line of a code paragraph should begin `\\c'");
|
||||
flags = FILEPOS;
|
||||
break;
|
||||
case err_kwunclosed:
|
||||
|
@ -135,8 +135,7 @@ static void do_error(int code, va_list ap)
|
|||
fpos = *va_arg(ap, filepos *);
|
||||
wsp = va_arg(ap, wchar_t *);
|
||||
sp = ustrtoa(wsp, auxbuf, sizeof(auxbuf));
|
||||
sprintf(error, "unable to resolve cross-reference to `%.200s'",
|
||||
sp);
|
||||
sprintf(error, "unable to resolve cross-reference to `%.200s'", sp);
|
||||
flags = FILEPOS;
|
||||
break;
|
||||
case err_multiBR:
|
||||
|
@ -183,10 +182,8 @@ static void do_error(int code, va_list ap)
|
|||
fpos2 = *va_arg(ap, filepos *);
|
||||
wsp = va_arg(ap, wchar_t *);
|
||||
sp = ustrtoa(wsp, auxbuf, sizeof(auxbuf));
|
||||
sprintf(error, "paragraph keyword `%.200s' already defined at ",
|
||||
sp);
|
||||
sprintf(error + strlen(error), "%s:%d", fpos2.filename,
|
||||
fpos2.line);
|
||||
sprintf(error, "paragraph keyword `%.200s' already defined at ", sp);
|
||||
sprintf(error + strlen(error), "%s:%d", fpos2.filename, fpos2.line);
|
||||
flags = FILEPOS;
|
||||
break;
|
||||
case err_whatever:
|
||||
|
@ -198,7 +195,8 @@ static void do_error(int code, va_list ap)
|
|||
|
||||
if (flags & PREFIX)
|
||||
fputs("halibut: ", stderr);
|
||||
if (flags & FILEPOS) {
|
||||
if (flags & FILEPOS)
|
||||
{
|
||||
fprintf(stderr, "%s:%d:", fpos.filename, fpos.line);
|
||||
if (fpos.col > 0)
|
||||
fprintf(stderr, "%d:", fpos.col);
|
||||
|
|
|
@ -71,11 +71,13 @@ index_merge(indexdata * idx, int is_explicit, wchar_t * tags, word * text)
|
|||
/*
|
||||
* FIXME: want to warn on overlapping source sets.
|
||||
*/
|
||||
for (; *tags; tags = uadv(tags)) {
|
||||
for (; *tags; tags = uadv(tags))
|
||||
{
|
||||
t = make_indextag();
|
||||
t->name = tags;
|
||||
existing = add234(idx->tags, t);
|
||||
if (existing == t) {
|
||||
if (existing == t)
|
||||
{
|
||||
/*
|
||||
* Duplicate this so we can free it independently.
|
||||
*/
|
||||
|
@ -86,7 +88,8 @@ index_merge(indexdata * idx, int is_explicit, wchar_t * tags, word * text)
|
|||
* doesn't exist and we're explicit, then we should
|
||||
* warn (and drop it, since it won't be referenced).
|
||||
*/
|
||||
if (is_explicit) {
|
||||
if (is_explicit)
|
||||
{
|
||||
error(err_nosuchidxtag, tags);
|
||||
continue;
|
||||
}
|
||||
|
@ -95,10 +98,12 @@ index_merge(indexdata * idx, int is_explicit, wchar_t * tags, word * text)
|
|||
* Otherwise, this is a new tag with an implicit \IM.
|
||||
*/
|
||||
t->implicit_text = text;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
sfree(t);
|
||||
t = existing;
|
||||
if (!is_explicit) {
|
||||
if (!is_explicit)
|
||||
{
|
||||
/*
|
||||
* An implicit \IM for a tag that's had an implicit
|
||||
* \IM before. FIXME: we should check the text
|
||||
|
@ -106,20 +111,22 @@ index_merge(indexdata * idx, int is_explicit, wchar_t * tags, word * text)
|
|||
* differences. And check the tag for case match
|
||||
* against the existing tag, likewise.
|
||||
*/
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
/*
|
||||
* An explicit \IM added to a valid tag. In
|
||||
* particular, this removes the implicit \IM if
|
||||
* present.
|
||||
*/
|
||||
if (t->implicit_text) {
|
||||
if (t->implicit_text)
|
||||
{
|
||||
free_word_list(t->implicit_text);
|
||||
t->implicit_text = NULL;
|
||||
}
|
||||
if (t->nexplicit >= t->explicit_size) {
|
||||
if (t->nexplicit >= t->explicit_size)
|
||||
{
|
||||
t->explicit_size = t->nexplicit + 8;
|
||||
t->explicit_texts = resize(t->explicit_texts,
|
||||
t->explicit_size);
|
||||
t->explicit_texts = resize(t->explicit_texts, t->explicit_size);
|
||||
}
|
||||
t->explicit_texts[t->nexplicit++] = text;
|
||||
}
|
||||
|
@ -141,17 +148,22 @@ void build_index(indexdata * i)
|
|||
int ti;
|
||||
int j;
|
||||
|
||||
for (ti = 0; (t = (indextag *) index234(i->tags, ti)) != NULL; ti++) {
|
||||
if (t->implicit_text) {
|
||||
for (ti = 0; (t = (indextag *) index234(i->tags, ti)) != NULL; ti++)
|
||||
{
|
||||
if (t->implicit_text)
|
||||
{
|
||||
t->nrefs = 1;
|
||||
ta = &t->implicit_text;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
t->nrefs = t->nexplicit;
|
||||
ta = t->explicit_texts;
|
||||
}
|
||||
if (t->nrefs) {
|
||||
if (t->nrefs)
|
||||
{
|
||||
t->refs = mknewa(indexentry *, t->nrefs);
|
||||
for (j = 0; j < t->nrefs; j++) {
|
||||
for (j = 0; j < t->nrefs; j++)
|
||||
{
|
||||
indexentry *ent = mknew(indexentry);
|
||||
ent->text = *ta++;
|
||||
t->refs[j] = add234(i->entries, ent);
|
||||
|
@ -168,7 +180,8 @@ void cleanup_index(indexdata * i)
|
|||
indexentry *ent;
|
||||
int ti;
|
||||
|
||||
for (ti = 0; (t = (indextag *) index234(i->tags, ti)) != NULL; ti++) {
|
||||
for (ti = 0; (t = (indextag *) index234(i->tags, ti)) != NULL; ti++)
|
||||
{
|
||||
sfree(t->name);
|
||||
free_word_list(t->implicit_text);
|
||||
sfree(t->explicit_texts);
|
||||
|
@ -177,7 +190,8 @@ void cleanup_index(indexdata * i)
|
|||
}
|
||||
freetree234(i->tags);
|
||||
for (ti = 0; (ent = (indexentry *) index234(i->entries, ti)) != NULL;
|
||||
ti++) {
|
||||
ti++)
|
||||
{
|
||||
sfree(ent);
|
||||
}
|
||||
freetree234(i->entries);
|
||||
|
@ -195,7 +209,8 @@ void index_debug(indexdata * i)
|
|||
int j;
|
||||
|
||||
printf("\nINDEX TAGS\n==========\n\n");
|
||||
for (ti = 0; (t = (indextag *) index234(i->tags, ti)) != NULL; ti++) {
|
||||
for (ti = 0; (t = (indextag *) index234(i->tags, ti)) != NULL; ti++)
|
||||
{
|
||||
printf("\n");
|
||||
if (t->implicit_text)
|
||||
dbg_prtmerge(0, t->name, t->implicit_text);
|
||||
|
@ -204,8 +219,8 @@ void index_debug(indexdata * i)
|
|||
}
|
||||
|
||||
printf("\nINDEX ENTRIES\n=============\n\n");
|
||||
for (ti = 0; (y = (indexentry *) index234(i->entries, ti)) != NULL;
|
||||
ti++) {
|
||||
for (ti = 0; (y = (indexentry *) index234(i->entries, ti)) != NULL; ti++)
|
||||
{
|
||||
printf("\n");
|
||||
printf("{\n");
|
||||
dbg_prtwordlist(1, y->text);
|
||||
|
@ -225,17 +240,20 @@ static void dbg_prtmerge(int is_explicit, wchar_t * tag, word * text)
|
|||
|
||||
static void dbg_prtwordlist(int level, word * w)
|
||||
{
|
||||
for (; w; w = w->next) {
|
||||
for (; w; w = w->next)
|
||||
{
|
||||
wchar_t *wp;
|
||||
printf("%*sword %d ", level * 4, "", w->type);
|
||||
if (w->text) {
|
||||
if (w->text)
|
||||
{
|
||||
printf("\"");
|
||||
for (wp = w->text; *wp; wp++)
|
||||
putchar(*wp);
|
||||
printf("\"");
|
||||
} else
|
||||
printf("(no text)");
|
||||
if (w->alt) {
|
||||
if (w->alt)
|
||||
{
|
||||
printf(" alt = {\n");
|
||||
dbg_prtwordlist(level + 1, w->alt);
|
||||
printf("%*s}", level * 4, "");
|
||||
|
|
|
@ -18,7 +18,8 @@ static void setpos(input * in, char *fname)
|
|||
|
||||
static void unget(input * in, int c, filepos * pos)
|
||||
{
|
||||
if (in->npushback >= in->pushbacksize) {
|
||||
if (in->npushback >= in->pushbacksize)
|
||||
{
|
||||
in->pushbacksize = in->npushback + 16;
|
||||
in->pushback = resize(in->pushback, in->pushbacksize);
|
||||
}
|
||||
|
@ -52,7 +53,8 @@ macrodef(tree234 * macros, wchar_t * name, wchar_t * text, filepos fpos)
|
|||
macro *m = mknew(macro);
|
||||
m->name = name;
|
||||
m->text = text;
|
||||
if (add234(macros, m) != m) {
|
||||
if (add234(macros, m) != m)
|
||||
{
|
||||
error(err_macroexists, &fpos, name);
|
||||
sfree(name);
|
||||
sfree(text);
|
||||
|
@ -64,7 +66,8 @@ macrolookup(tree234 * macros, input * in, wchar_t * name, filepos * pos)
|
|||
macro m, *gotit;
|
||||
m.name = name;
|
||||
gotit = find234(macros, &m, NULL);
|
||||
if (gotit) {
|
||||
if (gotit)
|
||||
{
|
||||
macrostack *expansion = mknew(macrostack);
|
||||
expansion->next = in->stack;
|
||||
expansion->text = gotit->text;
|
||||
|
@ -80,7 +83,8 @@ static void macrocleanup(tree234 * macros)
|
|||
{
|
||||
int ti;
|
||||
macro *m;
|
||||
for (ti = 0; (m = (macro *) index234(macros, ti)) != NULL; ti++) {
|
||||
for (ti = 0; (m = (macro *) index234(macros, ti)) != NULL; ti++)
|
||||
{
|
||||
sfree(m->name);
|
||||
sfree(m->text);
|
||||
sfree(m);
|
||||
|
@ -94,31 +98,38 @@ static void macrocleanup(tree234 * macros)
|
|||
static int get(input * in, filepos * pos)
|
||||
{
|
||||
int pushbackpt = in->stack ? in->stack->npushback : 0;
|
||||
if (in->npushback > pushbackpt) {
|
||||
if (in->npushback > pushbackpt)
|
||||
{
|
||||
--in->npushback;
|
||||
if (pos)
|
||||
*pos = in->pushback[in->npushback].pos; /* structure copy */
|
||||
return in->pushback[in->npushback].chr;
|
||||
} else if (in->stack) {
|
||||
} else if (in->stack)
|
||||
{
|
||||
wchar_t c = in->stack->text[in->stack->ptr];
|
||||
if (in->stack->text[++in->stack->ptr] == L'\0') {
|
||||
if (in->stack->text[++in->stack->ptr] == L'\0')
|
||||
{
|
||||
macrostack *tmp = in->stack;
|
||||
in->stack = tmp->next;
|
||||
sfree(tmp);
|
||||
}
|
||||
return c;
|
||||
} else if (in->currfp) {
|
||||
} else if (in->currfp)
|
||||
{
|
||||
int c = getc(in->currfp);
|
||||
|
||||
if (c == EOF) {
|
||||
if (c == EOF)
|
||||
{
|
||||
fclose(in->currfp);
|
||||
in->currfp = NULL;
|
||||
}
|
||||
/* Track line numbers, for error reporting */
|
||||
if (pos)
|
||||
*pos = in->pos;
|
||||
if (in->reportcols) {
|
||||
switch (c) {
|
||||
if (in->reportcols)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\t':
|
||||
in->pos.col = 1 + (in->pos.col + TAB_STOP - 1) % TAB_STOP;
|
||||
break;
|
||||
|
@ -130,7 +141,8 @@ static int get(input * in, filepos * pos)
|
|||
in->pos.col++;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
in->pos.col = -1;
|
||||
if (c == '\n')
|
||||
in->pos.line++;
|
||||
|
@ -217,7 +229,8 @@ enum {
|
|||
static int kwcmp(wchar_t const *p, char const *q)
|
||||
{
|
||||
int i;
|
||||
do {
|
||||
do
|
||||
{
|
||||
i = *p - *q;
|
||||
}
|
||||
while (*p++ && *q++ && !i);
|
||||
|
@ -350,33 +363,40 @@ static void match_kw(token * tok)
|
|||
* doesn't match correctly, we just fall through to the
|
||||
* binary-search phase.
|
||||
*/
|
||||
if (tok->text[0] == 'S') {
|
||||
if (tok->text[0] == 'S')
|
||||
{
|
||||
/* We expect numeric characters thereafter. */
|
||||
wchar_t *p = tok->text + 1;
|
||||
int n;
|
||||
if (!*p)
|
||||
n = 1;
|
||||
else {
|
||||
else
|
||||
{
|
||||
n = 0;
|
||||
while (*p && isdec(*p)) {
|
||||
while (*p && isdec(*p))
|
||||
{
|
||||
n = 10 * n + fromdec(*p);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
if (!*p) {
|
||||
if (!*p)
|
||||
{
|
||||
tok->cmd = c_S;
|
||||
tok->aux = n;
|
||||
return;
|
||||
}
|
||||
} else if (tok->text[0] == 'u') {
|
||||
} else if (tok->text[0] == 'u')
|
||||
{
|
||||
/* We expect hex characters thereafter. */
|
||||
wchar_t *p = tok->text + 1;
|
||||
int n = 0;
|
||||
while (*p && ishex(*p)) {
|
||||
while (*p && ishex(*p))
|
||||
{
|
||||
n = 16 * n + fromhex(*p);
|
||||
p++;
|
||||
}
|
||||
if (!*p) {
|
||||
if (!*p)
|
||||
{
|
||||
tok->cmd = c_u;
|
||||
tok->aux = n;
|
||||
return;
|
||||
|
@ -385,14 +405,16 @@ static void match_kw(token * tok)
|
|||
|
||||
i = -1;
|
||||
j = sizeof(keywords) / sizeof(*keywords);
|
||||
while (j - i > 1) {
|
||||
while (j - i > 1)
|
||||
{
|
||||
k = (i + j) / 2;
|
||||
c = kwcmp(tok->text, keywords[k].name);
|
||||
if (c < 0)
|
||||
j = k;
|
||||
else if (c > 0)
|
||||
i = k;
|
||||
else { /* c == 0 */
|
||||
else
|
||||
{ /* c == 0 */
|
||||
|
||||
tok->cmd = keywords[k].id;
|
||||
return;
|
||||
|
@ -418,40 +440,50 @@ token get_token(input * in)
|
|||
ret.text = NULL; /* default */
|
||||
c = get(in, &cpos);
|
||||
ret.pos = cpos;
|
||||
if (iswhite(c)) { /* tok_white or tok_eop */
|
||||
if (iswhite(c))
|
||||
{ /* tok_white or tok_eop */
|
||||
nls = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (isnl(c))
|
||||
nls++;
|
||||
}
|
||||
while ((c = get(in, &cpos)) != EOF && iswhite(c));
|
||||
if (c == EOF) {
|
||||
if (c == EOF)
|
||||
{
|
||||
ret.type = tok_eof;
|
||||
return ret;
|
||||
}
|
||||
unget(in, c, &cpos);
|
||||
ret.type = (nls > 1 ? tok_eop : tok_white);
|
||||
return ret;
|
||||
} else if (c == EOF) { /* tok_eof */
|
||||
} else if (c == EOF)
|
||||
{ /* tok_eof */
|
||||
ret.type = tok_eof;
|
||||
return ret;
|
||||
} else if (c == '\\') { /* tok_cmd */
|
||||
} else if (c == '\\')
|
||||
{ /* tok_cmd */
|
||||
c = get(in, &cpos);
|
||||
if (c == '-' || c == '\\' || c == '_' ||
|
||||
c == '#' || c == '{' || c == '}') {
|
||||
c == '#' || c == '{' || c == '}')
|
||||
{
|
||||
/* single-char command */
|
||||
rdadd(&rs, c);
|
||||
} else if (c == 'u') {
|
||||
} else if (c == 'u')
|
||||
{
|
||||
int len = 0;
|
||||
do {
|
||||
do
|
||||
{
|
||||
rdadd(&rs, c);
|
||||
len++;
|
||||
c = get(in, &cpos);
|
||||
}
|
||||
while (ishex(c) && len < 5);
|
||||
unget(in, c, &cpos);
|
||||
} else if (iscmd(c)) {
|
||||
do {
|
||||
} else if (iscmd(c))
|
||||
{
|
||||
do
|
||||
{
|
||||
rdadd(&rs, c);
|
||||
c = get(in, &cpos);
|
||||
}
|
||||
|
@ -467,13 +499,16 @@ token get_token(input * in)
|
|||
match_kw(&ret);
|
||||
sfree(rs.text);
|
||||
return ret;
|
||||
} else if (c == '{') { /* tok_lbrace */
|
||||
} else if (c == '{')
|
||||
{ /* tok_lbrace */
|
||||
ret.type = tok_lbrace;
|
||||
return ret;
|
||||
} else if (c == '}') { /* tok_rbrace */
|
||||
} else if (c == '}')
|
||||
{ /* tok_rbrace */
|
||||
ret.type = tok_rbrace;
|
||||
return ret;
|
||||
} else { /* tok_word */
|
||||
} else
|
||||
{ /* tok_word */
|
||||
/*
|
||||
* Read a word: the longest possible contiguous sequence of
|
||||
* things other than whitespace, backslash, braces and
|
||||
|
@ -483,15 +518,18 @@ token get_token(input * in)
|
|||
* a hyphen.
|
||||
*/
|
||||
ret.aux = FALSE; /* assumed for now */
|
||||
while (1) {
|
||||
if (iswhite(c) || c == '{' || c == '}' || c == '\\'
|
||||
|| c == EOF) {
|
||||
while (1)
|
||||
{
|
||||
if (iswhite(c) || c == '{' || c == '}' || c == '\\' || c == EOF)
|
||||
{
|
||||
/* Put back the character that caused termination */
|
||||
unget(in, c, &cpos);
|
||||
break;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
rdadd(&rs, c);
|
||||
if (c == '-') {
|
||||
if (c == '-')
|
||||
{
|
||||
ret.aux = TRUE;
|
||||
break; /* hyphen terminates word */
|
||||
}
|
||||
|
@ -534,11 +572,13 @@ token get_codepar_token(input * in)
|
|||
ret.type = tok_word;
|
||||
c = get(in, &cpos); /* expect (and discard) one space */
|
||||
ret.pos = cpos;
|
||||
if (c == ' ') {
|
||||
if (c == ' ')
|
||||
{
|
||||
c = get(in, &cpos);
|
||||
ret.pos = cpos;
|
||||
}
|
||||
while (!isnl(c) && c != EOF) {
|
||||
while (!isnl(c) && c != EOF)
|
||||
{
|
||||
int c2 = c;
|
||||
c = get(in, &cpos);
|
||||
/* Discard \r just before \n. */
|
||||
|
@ -627,7 +667,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
/*
|
||||
* Loop on each paragraph.
|
||||
*/
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
int start_cmd = c__invalid;
|
||||
par.words = NULL;
|
||||
par.keyword = NULL;
|
||||
|
@ -636,7 +677,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
/*
|
||||
* Get a token.
|
||||
*/
|
||||
if (!already) {
|
||||
if (!already)
|
||||
{
|
||||
dtor(t), t = get_token(in);
|
||||
}
|
||||
already = FALSE;
|
||||
|
@ -646,10 +688,12 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
/*
|
||||
* Parse code paragraphs separately.
|
||||
*/
|
||||
if (t.type == tok_cmd && t.cmd == c_c && !isbrace(in)) {
|
||||
if (t.type == tok_cmd && t.cmd == c_c && !isbrace(in))
|
||||
{
|
||||
par.type = para_Code;
|
||||
par.fpos = t.pos;
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
dtor(t), t = get_codepar_token(in);
|
||||
wd.type = word_WeakCode;
|
||||
wd.breaks = FALSE; /* shouldn't need this... */
|
||||
|
@ -658,7 +702,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
wd.fpos = t.pos;
|
||||
addword(wd, &whptr);
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type == tok_white) {
|
||||
if (t.type == tok_white)
|
||||
{
|
||||
/*
|
||||
* The newline after a code-paragraph line
|
||||
*/
|
||||
|
@ -666,7 +711,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
}
|
||||
if (t.type == tok_eop || t.type == tok_eof)
|
||||
break;
|
||||
else if (t.type != tok_cmd || t.cmd != c_c) {
|
||||
else if (t.type != tok_cmd || t.cmd != c_c)
|
||||
{
|
||||
error(err_brokencodepara, &t.pos);
|
||||
addpara(par, ret);
|
||||
while (t.type != tok_eop) /* error recovery: */
|
||||
|
@ -687,12 +733,14 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
* text)
|
||||
*/
|
||||
par.type = para_Normal;
|
||||
if (t.type == tok_cmd) {
|
||||
if (t.type == tok_cmd)
|
||||
{
|
||||
int needkw;
|
||||
int is_macro = FALSE;
|
||||
|
||||
par.fpos = t.pos;
|
||||
switch (t.cmd) {
|
||||
switch (t.cmd)
|
||||
{
|
||||
default:
|
||||
needkw = -1;
|
||||
break;
|
||||
|
@ -703,7 +751,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
case c__comment:
|
||||
if (isbrace(in))
|
||||
break; /* `\#{': isn't a comment para */
|
||||
do {
|
||||
do
|
||||
{
|
||||
dtor(t), t = get_token(in);
|
||||
}
|
||||
while (t.type != tok_eop && t.type != tok_eof);
|
||||
|
@ -799,7 +848,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
break;
|
||||
}
|
||||
|
||||
if (needkw > 0) {
|
||||
if (needkw > 0)
|
||||
{
|
||||
rdstring rs = { 0, 0, NULL };
|
||||
int nkeys = 0;
|
||||
filepos fp;
|
||||
|
@ -807,7 +857,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
/* Get keywords. */
|
||||
dtor(t), t = get_token(in);
|
||||
fp = t.pos;
|
||||
while (t.type == tok_lbrace) {
|
||||
while (t.type == tok_lbrace)
|
||||
{
|
||||
/* This is a keyword. */
|
||||
nkeys++;
|
||||
/* FIXME: there will be bugs if anyone specifies an
|
||||
|
@ -816,14 +867,16 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
t.type == tok_word ||
|
||||
t.type == tok_white ||
|
||||
(t.type == tok_cmd && t.cmd == c__nbsp) ||
|
||||
(t.type == tok_cmd && t.cmd == c__escaped)) {
|
||||
(t.type == tok_cmd && t.cmd == c__escaped))
|
||||
{
|
||||
if (t.type == tok_white ||
|
||||
(t.type == tok_cmd && t.cmd == c__nbsp))
|
||||
rdadd(&rs, ' ');
|
||||
else
|
||||
rdadds(&rs, t.text);
|
||||
}
|
||||
if (t.type != tok_rbrace) {
|
||||
if (t.type != tok_rbrace)
|
||||
{
|
||||
error(err_kwunclosed, &t.pos);
|
||||
continue;
|
||||
}
|
||||
|
@ -841,7 +894,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
if ((needkw & 5) && nkeys > 1)
|
||||
error(err_kwtoomany, &fp);
|
||||
|
||||
if (is_macro) {
|
||||
if (is_macro)
|
||||
{
|
||||
/*
|
||||
* Macro definition. Get the rest of the line
|
||||
* as a code-paragraph token, repeatedly until
|
||||
|
@ -849,7 +903,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
* with newlines.
|
||||
*/
|
||||
rdstring macrotext = { 0, 0, NULL };
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
dtor(t), t = get_codepar_token(in);
|
||||
if (macrotext.pos > 0)
|
||||
rdadd(¯otext, L'\n');
|
||||
|
@ -865,13 +920,15 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
par.keyword = rdtrim(&rs);
|
||||
|
||||
/* Move to EOP in case of needkw==8 or 16 (no body) */
|
||||
if (needkw & 24) {
|
||||
if (needkw & 24)
|
||||
{
|
||||
/* We allow whitespace even when we expect no para body */
|
||||
while (t.type == tok_white)
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type != tok_eop && t.type != tok_eof &&
|
||||
(start_cmd == c__invalid ||
|
||||
t.type != tok_cmd || t.cmd != start_cmd)) {
|
||||
t.type != tok_cmd || t.cmd != start_cmd))
|
||||
{
|
||||
error(err_bodyillegal, &t.pos);
|
||||
/* Error recovery: eat the rest of the paragraph */
|
||||
while (t.type != tok_eop && t.type != tok_eof &&
|
||||
|
@ -908,28 +965,33 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
spcstyle = word_WhiteSpace;
|
||||
indexing = FALSE;
|
||||
seenwhite = TRUE;
|
||||
while (t.type != tok_eop && t.type != tok_eof) {
|
||||
while (t.type != tok_eop && t.type != tok_eof)
|
||||
{
|
||||
iswhite = FALSE;
|
||||
already = FALSE;
|
||||
|
||||
/* Handle implicit paragraph breaks after \IM, \BR etc */
|
||||
if (start_cmd != c__invalid &&
|
||||
t.type == tok_cmd && t.cmd == start_cmd) {
|
||||
t.type == tok_cmd && t.cmd == start_cmd)
|
||||
{
|
||||
already = TRUE; /* inhibit get_token at top of loop */
|
||||
break;
|
||||
}
|
||||
|
||||
if (t.type == tok_cmd && t.cmd == c__escaped) {
|
||||
if (t.type == tok_cmd && t.cmd == c__escaped)
|
||||
{
|
||||
t.type = tok_word; /* nice and simple */
|
||||
t.aux = 0; /* even if `\-' - nonbreaking! */
|
||||
}
|
||||
if (t.type == tok_cmd && t.cmd == c__nbsp) {
|
||||
if (t.type == tok_cmd && t.cmd == c__nbsp)
|
||||
{
|
||||
t.type = tok_word; /* nice and simple */
|
||||
sfree(t.text);
|
||||
t.text = ustrdup(L" "); /* text is ` ' not `_' */
|
||||
t.aux = 0; /* (nonbreaking) */
|
||||
}
|
||||
switch (t.type) {
|
||||
switch (t.type)
|
||||
{
|
||||
case tok_white:
|
||||
if (whptr == &par.words)
|
||||
break; /* strip whitespace at start of para */
|
||||
|
@ -945,7 +1007,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
* newline) before a repeat \IM / \BR type
|
||||
* directive.
|
||||
*/
|
||||
if (start_cmd != c__invalid) {
|
||||
if (start_cmd != c__invalid)
|
||||
{
|
||||
dtor(t), t = get_token(in);
|
||||
already = TRUE;
|
||||
if (t.type == tok_cmd && t.cmd == start_cmd)
|
||||
|
@ -968,11 +1031,13 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
wd.aux = 0;
|
||||
wd.fpos = t.pos;
|
||||
wd.breaks = t.aux;
|
||||
if (!indexing || index_visible) {
|
||||
if (!indexing || index_visible)
|
||||
{
|
||||
wd.text = ustrdup(t.text);
|
||||
addword(wd, &whptr);
|
||||
}
|
||||
if (indexing) {
|
||||
if (indexing)
|
||||
{
|
||||
wd.text = ustrdup(t.text);
|
||||
addword(wd, &idximplicit);
|
||||
}
|
||||
|
@ -988,26 +1053,30 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
sitem = stk_pop(parsestk);
|
||||
if (!sitem)
|
||||
error(err_unexbrace, &t.pos);
|
||||
else {
|
||||
if (sitem->type & stack_ualt) {
|
||||
else
|
||||
{
|
||||
if (sitem->type & stack_ualt)
|
||||
{
|
||||
whptr = sitem->whptr;
|
||||
idximplicit = sitem->idximplicit;
|
||||
}
|
||||
if (sitem->type & stack_style) {
|
||||
if (sitem->type & stack_style)
|
||||
{
|
||||
style = word_Normal;
|
||||
spcstyle = word_WhiteSpace;
|
||||
}
|
||||
if (sitem->type & stack_idx) {
|
||||
if (sitem->type & stack_idx)
|
||||
{
|
||||
indexword->text = ustrdup(indexstr.text);
|
||||
if (index_downcase)
|
||||
ustrlow(indexword->text);
|
||||
indexing = FALSE;
|
||||
rdadd(&indexstr, L'\0');
|
||||
index_merge(idx, FALSE, indexstr.text,
|
||||
idxwordlist);
|
||||
index_merge(idx, FALSE, indexstr.text, idxwordlist);
|
||||
sfree(indexstr.text);
|
||||
}
|
||||
if (sitem->type & stack_hyper) {
|
||||
if (sitem->type & stack_hyper)
|
||||
{
|
||||
wd.text = NULL;
|
||||
wd.type = word_HyperEnd;
|
||||
wd.alt = NULL;
|
||||
|
@ -1019,7 +1088,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
if (indexing)
|
||||
addword(wd, &idximplicit);
|
||||
}
|
||||
if (sitem->type & stack_quote) {
|
||||
if (sitem->type & stack_quote)
|
||||
{
|
||||
wd.text = NULL;
|
||||
wd.type = toquotestyle(style);
|
||||
wd.alt = NULL;
|
||||
|
@ -1028,7 +1098,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
wd.breaks = FALSE;
|
||||
if (!indexing || index_visible)
|
||||
addword(wd, &whptr);
|
||||
if (indexing) {
|
||||
if (indexing)
|
||||
{
|
||||
rdadd(&indexstr, L'"');
|
||||
addword(wd, &idximplicit);
|
||||
}
|
||||
|
@ -1037,7 +1108,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
sfree(sitem);
|
||||
break;
|
||||
case tok_cmd:
|
||||
switch (t.cmd) {
|
||||
switch (t.cmd)
|
||||
{
|
||||
case c__comment:
|
||||
/*
|
||||
* In-paragraph comment: \#{ balanced braces }
|
||||
|
@ -1047,26 +1119,32 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
* there was whitespace before the \#.
|
||||
*/
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type != tok_lbrace) {
|
||||
if (t.type != tok_lbrace)
|
||||
{
|
||||
error(err_explbr, &t.pos);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
int braces = 1;
|
||||
while (braces > 0) {
|
||||
while (braces > 0)
|
||||
{
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type == tok_lbrace)
|
||||
braces++;
|
||||
else if (t.type == tok_rbrace)
|
||||
braces--;
|
||||
else if (t.type == tok_eof) {
|
||||
else if (t.type == tok_eof)
|
||||
{
|
||||
error(err_commenteof, &t.pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (seenwhite) {
|
||||
if (seenwhite)
|
||||
{
|
||||
already = TRUE;
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type == tok_white) {
|
||||
if (t.type == tok_white)
|
||||
{
|
||||
iswhite = TRUE;
|
||||
already = FALSE;
|
||||
}
|
||||
|
@ -1074,9 +1152,11 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
break;
|
||||
case c_q:
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type != tok_lbrace) {
|
||||
if (t.type != tok_lbrace)
|
||||
{
|
||||
error(err_explbr, &t.pos);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
wd.text = NULL;
|
||||
wd.type = toquotestyle(style);
|
||||
wd.alt = NULL;
|
||||
|
@ -1085,7 +1165,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
wd.breaks = FALSE;
|
||||
if (!indexing || index_visible)
|
||||
addword(wd, &whptr);
|
||||
if (indexing) {
|
||||
if (indexing)
|
||||
{
|
||||
rdadd(&indexstr, L'"');
|
||||
addword(wd, &idximplicit);
|
||||
}
|
||||
|
@ -1117,51 +1198,62 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
else
|
||||
wd.type = word_Normal;
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type != tok_lbrace) {
|
||||
if (wd.type == word_Normal) {
|
||||
if (t.type != tok_lbrace)
|
||||
{
|
||||
if (wd.type == word_Normal)
|
||||
{
|
||||
time_t thetime = time(NULL);
|
||||
struct tm *broken = localtime(&thetime);
|
||||
already = TRUE;
|
||||
wdtext = ustrftime(NULL, broken);
|
||||
wd.type = style;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
error(err_explbr, &t.pos);
|
||||
wdtext = NULL;
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
rdstring rs = { 0, 0, NULL };
|
||||
while (dtor(t), t = get_token(in),
|
||||
t.type == tok_word || t.type == tok_white) {
|
||||
t.type == tok_word || t.type == tok_white)
|
||||
{
|
||||
if (t.type == tok_white)
|
||||
rdadd(&rs, ' ');
|
||||
else
|
||||
rdadds(&rs, t.text);
|
||||
}
|
||||
if (wd.type == word_Normal) {
|
||||
if (wd.type == word_Normal)
|
||||
{
|
||||
time_t thetime = time(NULL);
|
||||
struct tm *broken = localtime(&thetime);
|
||||
wdtext = ustrftime(rs.text, broken);
|
||||
wd.type = style;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
wdtext = ustrdup(rs.text);
|
||||
}
|
||||
sfree(rs.text);
|
||||
if (t.type != tok_rbrace) {
|
||||
if (t.type != tok_rbrace)
|
||||
{
|
||||
error(err_kwexprbr, &t.pos);
|
||||
}
|
||||
}
|
||||
wd.alt = NULL;
|
||||
wd.aux = 0;
|
||||
if (!indexing || index_visible) {
|
||||
if (!indexing || index_visible)
|
||||
{
|
||||
wd.text = ustrdup(wdtext);
|
||||
addword(wd, &whptr);
|
||||
}
|
||||
if (indexing) {
|
||||
if (indexing)
|
||||
{
|
||||
wd.text = ustrdup(wdtext);
|
||||
addword(wd, &idximplicit);
|
||||
}
|
||||
sfree(wdtext);
|
||||
if (wd.type == word_FreeTextXref || wd.type == word_HyperLink) {
|
||||
if (wd.type == word_FreeTextXref || wd.type == word_HyperLink)
|
||||
{
|
||||
/*
|
||||
* Hyperlinks are different: they then
|
||||
* expect another left brace, to begin
|
||||
|
@ -1174,23 +1266,25 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
sitem = mknew(struct stack_item);
|
||||
sitem->type = stack_hyper;
|
||||
if (t.type == tok_cmd &&
|
||||
(t.cmd == c_e || t.cmd == c_c
|
||||
|| t.cmd == c_cw)) {
|
||||
(t.cmd == c_e || t.cmd == c_c || t.cmd == c_cw))
|
||||
{
|
||||
if (style != word_Normal)
|
||||
error(err_nestedstyles, &t.pos);
|
||||
else {
|
||||
else
|
||||
{
|
||||
style = (t.cmd == c_c ? word_Code :
|
||||
t.cmd == c_cw ? word_WeakCode :
|
||||
word_Emph);
|
||||
t.cmd == c_cw ? word_WeakCode : word_Emph);
|
||||
spcstyle = tospacestyle(style);
|
||||
sitem->type |= stack_style;
|
||||
}
|
||||
dtor(t), t = get_token(in);
|
||||
}
|
||||
if (t.type != tok_lbrace) {
|
||||
if (t.type != tok_lbrace)
|
||||
{
|
||||
error(err_explbr, &t.pos);
|
||||
sfree(sitem);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
stk_push(parsestk, sitem);
|
||||
}
|
||||
}
|
||||
|
@ -1199,7 +1293,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
case c_cw:
|
||||
case c_e:
|
||||
type = t.cmd;
|
||||
if (style != word_Normal) {
|
||||
if (style != word_Normal)
|
||||
{
|
||||
error(err_nestedstyles, &t.pos);
|
||||
/* Error recovery: eat lbrace, push nop. */
|
||||
dtor(t), t = get_token(in);
|
||||
|
@ -1208,9 +1303,11 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
stk_push(parsestk, sitem);
|
||||
}
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type != tok_lbrace) {
|
||||
if (t.type != tok_lbrace)
|
||||
{
|
||||
error(err_explbr, &t.pos);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
style = (type == c_c ? word_Code :
|
||||
type == c_cw ? word_WeakCode : word_Emph);
|
||||
spcstyle = tospacestyle(style);
|
||||
|
@ -1223,7 +1320,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
case c_ii:
|
||||
case c_I:
|
||||
type = t.cmd;
|
||||
if (indexing) {
|
||||
if (indexing)
|
||||
{
|
||||
error(err_nestedindex, &t.pos);
|
||||
/* Error recovery: eat lbrace, push nop. */
|
||||
dtor(t), t = get_token(in);
|
||||
|
@ -1239,22 +1337,25 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
*/
|
||||
wd.fpos = t.pos;
|
||||
if (t.type == tok_cmd &&
|
||||
(t.cmd == c_e || t.cmd == c_c || t.cmd == c_cw)) {
|
||||
(t.cmd == c_e || t.cmd == c_c || t.cmd == c_cw))
|
||||
{
|
||||
if (style != word_Normal)
|
||||
error(err_nestedstyles, &t.pos);
|
||||
else {
|
||||
else
|
||||
{
|
||||
style = (t.cmd == c_c ? word_Code :
|
||||
t.cmd ==
|
||||
c_cw ? word_WeakCode : word_Emph);
|
||||
t.cmd == c_cw ? word_WeakCode : word_Emph);
|
||||
spcstyle = tospacestyle(style);
|
||||
sitem->type |= stack_style;
|
||||
}
|
||||
dtor(t), t = get_token(in);
|
||||
}
|
||||
if (t.type != tok_lbrace) {
|
||||
if (t.type != tok_lbrace)
|
||||
{
|
||||
sfree(sitem);
|
||||
error(err_explbr, &t.pos);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
/* Add an index-reference word with no text as yet */
|
||||
wd.type = word_IndexRef;
|
||||
wd.text = NULL;
|
||||
|
@ -1283,18 +1384,21 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
wd.alt = NULL;
|
||||
wd.aux = 0;
|
||||
wd.fpos = t.pos;
|
||||
if (!indexing || index_visible) {
|
||||
if (!indexing || index_visible)
|
||||
{
|
||||
wd.text = ustrdup(utext);
|
||||
uword = addword(wd, &whptr);
|
||||
} else
|
||||
uword = NULL;
|
||||
if (indexing) {
|
||||
if (indexing)
|
||||
{
|
||||
wd.text = ustrdup(utext);
|
||||
iword = addword(wd, &idximplicit);
|
||||
} else
|
||||
iword = NULL;
|
||||
dtor(t), t = get_token(in);
|
||||
if (t.type == tok_lbrace) {
|
||||
if (t.type == tok_lbrace)
|
||||
{
|
||||
/*
|
||||
* \u with a left brace. Until the brace
|
||||
* closes, all further words go on a
|
||||
|
@ -1308,7 +1412,8 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
stk_push(parsestk, sitem);
|
||||
whptr = uword ? &uword->alt : NULL;
|
||||
idximplicit = iword ? &iword->alt : NULL;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
if (indexing)
|
||||
rdadd(&indexstr, uchr);
|
||||
already = TRUE;
|
||||
|
@ -1325,8 +1430,10 @@ static void read_file(paragraph *** ret, input * in, indexdata * idx)
|
|||
seenwhite = iswhite;
|
||||
}
|
||||
/* Check the stack is empty */
|
||||
if (NULL != (sitem = stk_pop(parsestk))) {
|
||||
do {
|
||||
if (NULL != (sitem = stk_pop(parsestk)))
|
||||
{
|
||||
do
|
||||
{
|
||||
sfree(sitem);
|
||||
sitem = stk_pop(parsestk);
|
||||
}
|
||||
|
@ -1350,9 +1457,11 @@ paragraph *read_input(input * in, indexdata * idx)
|
|||
paragraph *head = NULL;
|
||||
paragraph **hptr = &head;
|
||||
|
||||
while (in->currindex < in->nfiles) {
|
||||
while (in->currindex < in->nfiles)
|
||||
{
|
||||
in->currfp = fopen(in->filenames[in->currindex], "r");
|
||||
if (in->currfp) {
|
||||
if (in->currfp)
|
||||
{
|
||||
setpos(in, in->filenames[in->currindex]);
|
||||
read_file(&hptr, in, idx);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ keywordlist *get_keywords(paragraph * source)
|
|||
kl->keys = newtree234(kwcmp);
|
||||
kl->nlooseends = kl->looseendssize = 0;
|
||||
kl->looseends = NULL;
|
||||
for (; source; source = source->next) {
|
||||
for (; source; source = source->next)
|
||||
{
|
||||
wchar_t *p, *q;
|
||||
p = q = source->keyword;
|
||||
|
||||
|
@ -54,7 +55,8 @@ keywordlist *get_keywords(paragraph * source)
|
|||
* `question' or whatever - to replace `chapter' or
|
||||
* `section' on a per-section basis).
|
||||
*/
|
||||
if (q) {
|
||||
if (q)
|
||||
{
|
||||
q = uadv(q); /* point q at the word beyond */
|
||||
if (!*q)
|
||||
q = NULL;
|
||||
|
@ -68,8 +70,10 @@ keywordlist *get_keywords(paragraph * source)
|
|||
source->kwtext = number_mktext(n, source, q, prevpara, &errors);
|
||||
prevpara = source->type;
|
||||
|
||||
if (p && *p) {
|
||||
if (source->kwtext || source->type == para_Biblio) {
|
||||
if (p && *p)
|
||||
{
|
||||
if (source->kwtext || source->type == para_Biblio)
|
||||
{
|
||||
keyword *kw, *ret;
|
||||
|
||||
kw = mknew(keyword);
|
||||
|
@ -77,14 +81,17 @@ keywordlist *get_keywords(paragraph * source)
|
|||
kw->text = source->kwtext;
|
||||
kw->para = source;
|
||||
ret = add234(kl->keys, kw);
|
||||
if (ret != kw) {
|
||||
if (ret != kw)
|
||||
{
|
||||
error(err_multikw, &source->fpos, &ret->para->fpos, p);
|
||||
sfree(kw);
|
||||
/* FIXME: what happens to kw->text? Does it leak? */
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (kl->nlooseends >= kl->looseendssize) {
|
||||
} else
|
||||
{
|
||||
if (kl->nlooseends >= kl->looseendssize)
|
||||
{
|
||||
kl->looseendssize = kl->nlooseends + 32;
|
||||
kl->looseends = resize(kl->looseends, kl->looseendssize);
|
||||
}
|
||||
|
@ -94,7 +101,8 @@ keywordlist *get_keywords(paragraph * source)
|
|||
|
||||
number_free(n);
|
||||
|
||||
if (errors) {
|
||||
if (errors)
|
||||
{
|
||||
free_keywords(kl);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -108,7 +116,8 @@ void free_keywords(keywordlist * kl)
|
|||
while (kl->nlooseends)
|
||||
free_word_list(kl->looseends[--kl->nlooseends]);
|
||||
sfree(kl->looseends);
|
||||
while ((kw = index234(kl->keys, 0)) != NULL) {
|
||||
while ((kw = index234(kl->keys, 0)) != NULL)
|
||||
{
|
||||
delpos234(kl->keys, 0);
|
||||
free_word_list(kw->text);
|
||||
sfree(kw);
|
||||
|
@ -119,15 +128,19 @@ void free_keywords(keywordlist * kl)
|
|||
|
||||
void subst_keywords(paragraph * source, keywordlist * kl)
|
||||
{
|
||||
for (; source; source = source->next) {
|
||||
for (; source; source = source->next)
|
||||
{
|
||||
word *ptr;
|
||||
for (ptr = source->words; ptr; ptr = ptr->next) {
|
||||
if (ptr->type == word_UpperXref || ptr->type == word_LowerXref) {
|
||||
for (ptr = source->words; ptr; ptr = ptr->next)
|
||||
{
|
||||
if (ptr->type == word_UpperXref || ptr->type == word_LowerXref)
|
||||
{
|
||||
keyword *kw;
|
||||
word **endptr, *close, *subst;
|
||||
|
||||
kw = kw_lookup(kl, ptr->text);
|
||||
if (!kw) {
|
||||
if (!kw)
|
||||
{
|
||||
error(err_nosuchkw, &ptr->fpos, ptr->text);
|
||||
subst = NULL;
|
||||
} else
|
||||
|
@ -147,8 +160,7 @@ void subst_keywords(paragraph * source, keywordlist * kl)
|
|||
close->next = ptr->next;
|
||||
ptr->next = subst;
|
||||
|
||||
for (endptr = &ptr->next; *endptr;
|
||||
endptr = &(*endptr)->next)
|
||||
for (endptr = &ptr->next; *endptr; endptr = &(*endptr)->next)
|
||||
(*endptr)->fpos = ptr->fpos;
|
||||
|
||||
*endptr = close;
|
||||
|
|
|
@ -30,7 +30,8 @@ int main(int argc, char **argv)
|
|||
reportcols = 0;
|
||||
debug = 0;
|
||||
|
||||
if (argc == 1) {
|
||||
if (argc == 1)
|
||||
{
|
||||
usage();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
@ -38,15 +39,19 @@ int main(int argc, char **argv)
|
|||
/*
|
||||
* Parse command line arguments.
|
||||
*/
|
||||
while (--argc) {
|
||||
while (--argc)
|
||||
{
|
||||
char *p = *++argv;
|
||||
if (*p == '-') {
|
||||
if (*p == '-')
|
||||
{
|
||||
/*
|
||||
* An option.
|
||||
*/
|
||||
while (p && *++p) {
|
||||
while (p && *++p)
|
||||
{
|
||||
char c = *p;
|
||||
switch (c) {
|
||||
switch (c)
|
||||
{
|
||||
case '-':
|
||||
/*
|
||||
* Long option.
|
||||
|
@ -56,26 +61,32 @@ int main(int argc, char **argv)
|
|||
opt = p++; /* opt will have _one_ leading - */
|
||||
while (*p && *p != '=')
|
||||
p++; /* find end of option */
|
||||
if (*p == '=') {
|
||||
if (*p == '=')
|
||||
{
|
||||
*p++ = '\0';
|
||||
val = p;
|
||||
} else
|
||||
val = NULL;
|
||||
if (!strcmp(opt, "-version")) {
|
||||
if (!strcmp(opt, "-version"))
|
||||
{
|
||||
showversion();
|
||||
nogo = TRUE;
|
||||
} else if (!strcmp(opt, "-licence") ||
|
||||
!strcmp(opt, "-license")) {
|
||||
!strcmp(opt, "-license"))
|
||||
{
|
||||
licence();
|
||||
nogo = TRUE;
|
||||
} else if (!strcmp(opt, "-output")) {
|
||||
} else if (!strcmp(opt, "-output"))
|
||||
{
|
||||
if (!val)
|
||||
errs = TRUE, error(err_optnoarg, opt);
|
||||
else
|
||||
outfile = val;
|
||||
} else if (!strcmp(opt, "-precise")) {
|
||||
} else if (!strcmp(opt, "-precise"))
|
||||
{
|
||||
reportcols = 1;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
errs = TRUE, error(err_nosuchopt, opt);
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +99,8 @@ int main(int argc, char **argv)
|
|||
/*
|
||||
* Option requiring no parameter.
|
||||
*/
|
||||
switch (c) {
|
||||
switch (c)
|
||||
{
|
||||
case 'V':
|
||||
showversion();
|
||||
nogo = TRUE;
|
||||
|
@ -112,7 +124,8 @@ int main(int argc, char **argv)
|
|||
p++;
|
||||
if (!*p && argc > 1)
|
||||
--argc, p = *++argv;
|
||||
else if (!*p) {
|
||||
else if (!*p)
|
||||
{
|
||||
char opt[2];
|
||||
opt[0] = c;
|
||||
opt[1] = '\0';
|
||||
|
@ -121,7 +134,8 @@ int main(int argc, char **argv)
|
|||
/*
|
||||
* Now c is the option and p is the parameter.
|
||||
*/
|
||||
switch (c) {
|
||||
switch (c)
|
||||
{
|
||||
case 'o':
|
||||
outfile = p;
|
||||
break;
|
||||
|
@ -140,7 +154,8 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
/*
|
||||
* A non-option argument.
|
||||
*/
|
||||
|
@ -156,7 +171,8 @@ int main(int argc, char **argv)
|
|||
/*
|
||||
* Do the work.
|
||||
*/
|
||||
if (nfiles == 0) {
|
||||
if (nfiles == 0)
|
||||
{
|
||||
error(err_noinput);
|
||||
usage();
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -201,7 +217,8 @@ int main(int argc, char **argv)
|
|||
|
||||
build_index(idx);
|
||||
|
||||
if (debug) {
|
||||
if (debug)
|
||||
{
|
||||
index_debug(idx);
|
||||
dbg_prtkws(keywords);
|
||||
dbg_prtsource(sourceform);
|
||||
|
@ -224,12 +241,15 @@ static void dbg_prtsource(paragraph * sourceform)
|
|||
*/
|
||||
|
||||
paragraph *p;
|
||||
for (p = sourceform; p; p = p->next) {
|
||||
for (p = sourceform; p; p = p->next)
|
||||
{
|
||||
wchar_t *wp;
|
||||
printf("para %d ", p->type);
|
||||
if (p->keyword) {
|
||||
if (p->keyword)
|
||||
{
|
||||
wp = p->keyword;
|
||||
while (*wp) {
|
||||
while (*wp)
|
||||
{
|
||||
putchar('\"');
|
||||
for (; *wp; wp++)
|
||||
putchar(*wp);
|
||||
|
@ -254,11 +274,13 @@ static void dbg_prtkws(keywordlist * kws)
|
|||
int i;
|
||||
keyword *kw;
|
||||
|
||||
for (i = 0; (kw = index234(kws->keys, i)) != NULL; i++) {
|
||||
for (i = 0; (kw = index234(kws->keys, i)) != NULL; i++)
|
||||
{
|
||||
wchar_t *wp;
|
||||
printf("keyword ");
|
||||
wp = kw->key;
|
||||
while (*wp) {
|
||||
while (*wp)
|
||||
{
|
||||
putchar('\"');
|
||||
for (; *wp; wp++)
|
||||
putchar(*wp);
|
||||
|
@ -274,17 +296,20 @@ static void dbg_prtkws(keywordlist * kws)
|
|||
|
||||
static void dbg_prtwordlist(int level, word * w)
|
||||
{
|
||||
for (; w; w = w->next) {
|
||||
for (; w; w = w->next)
|
||||
{
|
||||
wchar_t *wp;
|
||||
printf("%*sword %d ", level * 4, "", w->type);
|
||||
if (w->text) {
|
||||
if (w->text)
|
||||
{
|
||||
printf("\"");
|
||||
for (wp = w->text; *wp; wp++)
|
||||
putchar(*wp);
|
||||
printf("\"");
|
||||
} else
|
||||
printf("(no text)");
|
||||
if (w->alt) {
|
||||
if (w->alt)
|
||||
{
|
||||
printf(" alt = {\n");
|
||||
dbg_prtwordlist(level + 1, w->alt);
|
||||
printf("%*s}", level * 4, "");
|
||||
|
|
|
@ -15,9 +15,11 @@ static void loginc(void)
|
|||
}
|
||||
static void logallocinit(void)
|
||||
{
|
||||
if (!logallocfp) {
|
||||
if (!logallocfp)
|
||||
{
|
||||
logallocfp = fopen("malloc.log", "w");
|
||||
if (!logallocfp) {
|
||||
if (!logallocfp)
|
||||
{
|
||||
fprintf(stderr, "panic: unable to open malloc.log\n");
|
||||
exit(10);
|
||||
}
|
||||
|
@ -60,7 +62,8 @@ void *(smalloc) (LOGPARAMS int size) {
|
|||
* sfree should guaranteeably deal gracefully with freeing NULL
|
||||
*/
|
||||
void (sfree) (LOGPARAMS void *p) {
|
||||
if (p) {
|
||||
if (p)
|
||||
{
|
||||
LOGINC;
|
||||
LOGPRINT(("%s %d free(%p)\n", file, line, p));
|
||||
free(p);
|
||||
|
@ -72,12 +75,14 @@ void (sfree) (LOGPARAMS void *p) {
|
|||
*/
|
||||
void *(srealloc) (LOGPARAMS void *p, int size) {
|
||||
void *q;
|
||||
if (p) {
|
||||
if (p)
|
||||
{
|
||||
LOGINC;
|
||||
LOGPRINT(("%s %d realloc(%p,%ld)", file, line, p, (long) size));
|
||||
q = realloc(p, size);
|
||||
LOGPRINT((" returns %p\n", q));
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
LOGINC;
|
||||
LOGPRINT(("%s %d malloc(%ld)", file, line, (long) size));
|
||||
q = malloc(size);
|
||||
|
@ -106,7 +111,8 @@ word *dup_word_list(word * w)
|
|||
{
|
||||
word *head, **eptr = &head;
|
||||
|
||||
while (w) {
|
||||
while (w)
|
||||
{
|
||||
word *newwd = mknew(word);
|
||||
*newwd = *w; /* structure copy */
|
||||
newwd->text = ustrdup(w->text);
|
||||
|
@ -128,7 +134,8 @@ word *dup_word_list(word * w)
|
|||
void free_word_list(word * w)
|
||||
{
|
||||
word *t;
|
||||
while (w) {
|
||||
while (w)
|
||||
{
|
||||
t = w;
|
||||
w = w->next;
|
||||
sfree(t->text);
|
||||
|
@ -144,7 +151,8 @@ void free_word_list(word * w)
|
|||
void free_para_list(paragraph * p)
|
||||
{
|
||||
paragraph *t;
|
||||
while (p) {
|
||||
while (p)
|
||||
{
|
||||
t = p;
|
||||
p = p->next;
|
||||
sfree(t->keyword);
|
||||
|
|
|
@ -30,7 +30,8 @@ void stk_free(stack s)
|
|||
|
||||
void stk_push(stack s, void *item)
|
||||
{
|
||||
if (s->size <= s->sp) {
|
||||
if (s->size <= s->sp)
|
||||
{
|
||||
s->size = s->sp + 32;
|
||||
s->data = resize(s->data, s->size);
|
||||
}
|
||||
|
@ -53,7 +54,8 @@ const rdstringc empty_rdstringc = { 0, 0, NULL };
|
|||
|
||||
void rdadd(rdstring * rs, wchar_t c)
|
||||
{
|
||||
if (rs->pos >= rs->size - 1) {
|
||||
if (rs->pos >= rs->size - 1)
|
||||
{
|
||||
rs->size = rs->pos + 128;
|
||||
rs->text = resize(rs->text, rs->size);
|
||||
}
|
||||
|
@ -64,7 +66,8 @@ void rdadd(rdstring * rs, wchar_t c)
|
|||
void rdadds(rdstring * rs, wchar_t * p)
|
||||
{
|
||||
int len = ustrlen(p);
|
||||
if (rs->pos >= rs->size - len) {
|
||||
if (rs->pos >= rs->size - len)
|
||||
{
|
||||
rs->size = rs->pos + len + 128;
|
||||
rs->text = resize(rs->text, rs->size);
|
||||
}
|
||||
|
@ -80,7 +83,8 @@ wchar_t *rdtrim(rdstring * rs)
|
|||
|
||||
void rdaddc(rdstringc * rs, char c)
|
||||
{
|
||||
if (rs->pos >= rs->size - 1) {
|
||||
if (rs->pos >= rs->size - 1)
|
||||
{
|
||||
rs->size = rs->pos + 128;
|
||||
rs->text = resize(rs->text, rs->size);
|
||||
}
|
||||
|
@ -91,7 +95,8 @@ void rdaddc(rdstringc * rs, char c)
|
|||
void rdaddsc(rdstringc * rs, char *p)
|
||||
{
|
||||
int len = strlen(p);
|
||||
if (rs->pos >= rs->size - len) {
|
||||
if (rs->pos >= rs->size - len)
|
||||
{
|
||||
rs->size = rs->pos + len + 128;
|
||||
rs->text = resize(rs->text, rs->size);
|
||||
}
|
||||
|
@ -108,14 +113,17 @@ char *rdtrimc(rdstringc * rs)
|
|||
int compare_wordlists(word * a, word * b)
|
||||
{
|
||||
int t;
|
||||
while (a && b) {
|
||||
while (a && b)
|
||||
{
|
||||
if (a->type != b->type)
|
||||
return (a->type < b->type ? -1 : +1); /* FIXME? */
|
||||
t = a->type;
|
||||
if ((t != word_Normal && t != word_Code &&
|
||||
t != word_WeakCode && t != word_Emph) || a->alt || b->alt) {
|
||||
t != word_WeakCode && t != word_Emph) || a->alt || b->alt)
|
||||
{
|
||||
int c;
|
||||
if (a->text && b->text) {
|
||||
if (a->text && b->text)
|
||||
{
|
||||
c = ustricmp(a->text, b->text);
|
||||
if (c)
|
||||
return c;
|
||||
|
@ -125,17 +133,17 @@ int compare_wordlists(word * a, word * b)
|
|||
return c;
|
||||
a = a->next;
|
||||
b = b->next;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
wchar_t *ap = a->text, *bp = b->text;
|
||||
while (*ap && *bp) {
|
||||
while (*ap && *bp)
|
||||
{
|
||||
wchar_t ac = utolower(*ap), bc = utolower(*bp);
|
||||
if (ac != bc)
|
||||
return (ac < bc ? -1 : +1);
|
||||
if (!*++ap && a->next && a->next->type == t
|
||||
&& !a->next->alt)
|
||||
if (!*++ap && a->next && a->next->type == t && !a->next->alt)
|
||||
a = a->next, ap = a->text;
|
||||
if (!*++bp && b->next && b->next->type == t
|
||||
&& !b->next->alt)
|
||||
if (!*++bp && b->next && b->next->type == t && !b->next->alt)
|
||||
b = b->next, bp = b->text;
|
||||
}
|
||||
if (*ap || *bp)
|
||||
|
@ -155,10 +163,13 @@ void mark_attr_ends(paragraph * sourceform)
|
|||
{
|
||||
paragraph *p;
|
||||
word *w, *wp;
|
||||
for (p = sourceform; p; p = p->next) {
|
||||
for (p = sourceform; p; p = p->next)
|
||||
{
|
||||
wp = NULL;
|
||||
for (w = p->words; w; w = w->next) {
|
||||
if (isattr(w->type)) {
|
||||
for (w = p->words; w; w = w->next)
|
||||
{
|
||||
if (isattr(w->type))
|
||||
{
|
||||
int before = (wp && isattr(wp->type) &&
|
||||
sameattr(wp->type, w->type));
|
||||
int after = (w->next && isattr(w->next->type) &&
|
||||
|
@ -191,14 +202,17 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
*/
|
||||
nwords = wordsize = 0;
|
||||
wrapwords = NULL;
|
||||
while (text) {
|
||||
if (nwords >= wordsize) {
|
||||
while (text)
|
||||
{
|
||||
if (nwords >= wordsize)
|
||||
{
|
||||
wordsize = nwords + 64;
|
||||
wrapwords = srealloc(wrapwords, wordsize * sizeof(*wrapwords));
|
||||
}
|
||||
wrapwords[nwords].width = 0;
|
||||
wrapwords[nwords].begin = text;
|
||||
while (text) {
|
||||
while (text)
|
||||
{
|
||||
wrapwords[nwords].width += widthfn(text);
|
||||
wrapwords[nwords].end = text->next;
|
||||
if (text->next && (text->next->type == word_WhiteSpace ||
|
||||
|
@ -208,10 +222,12 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
text = text->next;
|
||||
}
|
||||
if (text && text->next && (text->next->type == word_WhiteSpace ||
|
||||
text->next->type == word_EmphSpace)) {
|
||||
text->next->type == word_EmphSpace))
|
||||
{
|
||||
wrapwords[nwords].spacewidth = widthfn(text->next);
|
||||
text = text->next;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
wrapwords[nwords].spacewidth = 0;
|
||||
}
|
||||
nwords++;
|
||||
|
@ -224,7 +240,8 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
* nwords-1, determining the optimal wrapping for each terminal
|
||||
* subsequence of the paragraph.
|
||||
*/
|
||||
for (i = nwords; i--;) {
|
||||
for (i = nwords; i--;)
|
||||
{
|
||||
int best = -1;
|
||||
int bestcost = 0;
|
||||
int cost;
|
||||
|
@ -234,7 +251,8 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
|
||||
j = 0;
|
||||
seenspace = 0;
|
||||
while (i + j < nwords) {
|
||||
while (i + j < nwords)
|
||||
{
|
||||
/*
|
||||
* See what happens if we put j+1 words on this line.
|
||||
*/
|
||||
|
@ -243,7 +261,8 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
linelen += spacewidth + wrapwords[i + j].width;
|
||||
spacewidth = wrapwords[i + j].spacewidth;
|
||||
j++;
|
||||
if (linelen > thiswidth) {
|
||||
if (linelen > thiswidth)
|
||||
{
|
||||
/*
|
||||
* If we're over the width limit, abandon ship,
|
||||
* _unless_ there is no best-effort yet (which will
|
||||
|
@ -253,14 +272,16 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
if (best > 0)
|
||||
break;
|
||||
}
|
||||
if (i + j == nwords) {
|
||||
if (i + j == nwords)
|
||||
{
|
||||
/*
|
||||
* Special case: if we're at the very end of the
|
||||
* paragraph, we don't score penalty points for the
|
||||
* white space left on the line.
|
||||
*/
|
||||
cost = 0;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
cost = (thiswidth - linelen) * (thiswidth - linelen);
|
||||
cost += wrapwords[i + j].cost;
|
||||
}
|
||||
|
@ -273,7 +294,8 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
* there's no point violating the Principle of Least
|
||||
* Surprise if it doesn't actually gain anything.
|
||||
*/
|
||||
if (best < 0 || bestcost >= cost) {
|
||||
if (best < 0 || bestcost >= cost)
|
||||
{
|
||||
bestcost = cost;
|
||||
best = j;
|
||||
}
|
||||
|
@ -291,7 +313,8 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
* `wrappedline' list.
|
||||
*/
|
||||
i = 0;
|
||||
while (i < nwords) {
|
||||
while (i < nwords)
|
||||
{
|
||||
wrappedline *w = mknew(wrappedline);
|
||||
*ptr = w;
|
||||
ptr = &w->next;
|
||||
|
@ -306,9 +329,11 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
*/
|
||||
w->nspaces = 0;
|
||||
w->shortfall = width;
|
||||
for (j = 0; j < n; j++) {
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
w->shortfall -= wrapwords[i + j].width;
|
||||
if (j < n - 1 && wrapwords[i + j].spacewidth) {
|
||||
if (j < n - 1 && wrapwords[i + j].spacewidth)
|
||||
{
|
||||
w->nspaces++;
|
||||
w->shortfall -= wrapwords[i + j].spacewidth;
|
||||
}
|
||||
|
@ -323,7 +348,8 @@ wrappedline *wrap_para(word * text, int width, int subsequentwidth,
|
|||
|
||||
void wrap_free(wrappedline * w)
|
||||
{
|
||||
while (w) {
|
||||
while (w)
|
||||
{
|
||||
wrappedline *t = w->next;
|
||||
sfree(w);
|
||||
w = t;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,10 +9,12 @@
|
|||
wchar_t *ustrdup(wchar_t * s)
|
||||
{
|
||||
wchar_t *r;
|
||||
if (s) {
|
||||
if (s)
|
||||
{
|
||||
r = mknewa(wchar_t, 1 + ustrlen(s));
|
||||
ustrcpy(r, s);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
r = mknew(wchar_t);
|
||||
*r = 0;
|
||||
}
|
||||
|
@ -22,7 +24,8 @@ wchar_t *ustrdup(wchar_t * s)
|
|||
char *ustrtoa(wchar_t * s, char *outbuf, int size)
|
||||
{
|
||||
char *p;
|
||||
if (!s) {
|
||||
if (!s)
|
||||
{
|
||||
*outbuf = '\0';
|
||||
return outbuf;
|
||||
}
|
||||
|
@ -51,7 +54,8 @@ wchar_t *uadv(wchar_t * s)
|
|||
wchar_t *ustrcpy(wchar_t * dest, wchar_t * source)
|
||||
{
|
||||
wchar_t *ret = dest;
|
||||
do {
|
||||
do
|
||||
{
|
||||
*dest++ = *source;
|
||||
}
|
||||
while (*source++);
|
||||
|
@ -101,7 +105,8 @@ int ustricmp(wchar_t * lhs, wchar_t * rhs)
|
|||
wchar_t *ustrlow(wchar_t * s)
|
||||
{
|
||||
wchar_t *p = s;
|
||||
while (*p) {
|
||||
while (*p)
|
||||
{
|
||||
*p = utolower(*p);
|
||||
p++;
|
||||
}
|
||||
|
@ -113,13 +118,15 @@ int utoi(wchar_t * s)
|
|||
int sign = +1;
|
||||
int n;
|
||||
|
||||
if (*s == L'-') {
|
||||
if (*s == L'-')
|
||||
{
|
||||
s++;
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
n = 0;
|
||||
while (*s && *s >= L'0' && *s <= L'9') {
|
||||
while (*s && *s >= L'0' && *s <= L'9')
|
||||
{
|
||||
n *= 10;
|
||||
n += (*s - '0');
|
||||
s++;
|
||||
|
@ -157,7 +164,8 @@ wchar_t *ustrftime(wchar_t * wfmt, struct tm * timespec)
|
|||
* generate the empty string. Somebody throw a custard pie at
|
||||
* whoever was responsible for that. Please?
|
||||
*/
|
||||
if (wfmt) {
|
||||
if (wfmt)
|
||||
{
|
||||
len = ustrlen(wfmt);
|
||||
fmt = mknewa(char, 2 + len);
|
||||
ustrtoa(wfmt, fmt + 1, len + 1);
|
||||
|
@ -165,7 +173,8 @@ wchar_t *ustrftime(wchar_t * wfmt, struct tm * timespec)
|
|||
} else
|
||||
fmt = " %c";
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
size += USTRFTIME_DELTA;
|
||||
blk = resize((char *) blk, size);
|
||||
len = strftime((char *) blk, size - 1, fmt, timespec);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue