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