version 1.25, 2015/02/20 12:25:25 |
version 1.26, 2015/02/20 15:37:33 |
Line 158 static const struct texitok __texitoks[TEXICMD__MAX] = |
|
Line 158 static const struct texitok __texitoks[TEXICMD__MAX] = |
|
{ dovalue, "ifclear", 7 }, /* TEXICMD_IFCLEAR */ |
{ dovalue, "ifclear", 7 }, /* TEXICMD_IFCLEAR */ |
{ doignblock, "ifdocbook", 9 }, /* TEXICMD_IFDOCBOOK */ |
{ doignblock, "ifdocbook", 9 }, /* TEXICMD_IFDOCBOOK */ |
{ doignblock, "ifhtml", 6 }, /* TEXICMD_IFHTML */ |
{ doignblock, "ifhtml", 6 }, /* TEXICMD_IFHTML */ |
{ doignblock, "ifinfo", 6 }, /* TEXICMD_IFINFO */ |
{ doblock, "ifinfo", 6 }, /* TEXICMD_IFINFO */ |
{ doblock, "ifnotdocbook", 12 }, /* TEXICMD_IFNOTDOCBOOK */ |
{ doblock, "ifnotdocbook", 12 }, /* TEXICMD_IFNOTDOCBOOK */ |
{ doblock, "ifnothtml", 9 }, /* TEXICMD_IFNOTHTML */ |
{ doblock, "ifnothtml", 9 }, /* TEXICMD_IFNOTHTML */ |
{ doblock, "ifnotinfo", 9 }, /* TEXICMD_IFNOTINFO */ |
{ doblock, "ifnotinfo", 9 }, /* TEXICMD_IFNOTINFO */ |
|
|
doignblock(struct texi *p, enum texicmd cmd, |
doignblock(struct texi *p, enum texicmd cmd, |
const char *buf, size_t sz, size_t *pos) |
const char *buf, size_t sz, size_t *pos) |
{ |
{ |
|
char end[32]; |
p->ign++; |
const char *term; |
parseto(p, buf, sz, pos, texitoks[cmd].tok); |
size_t endsz, endpos; |
p->ign--; |
|
|
/* |
|
* We want to completely ignore everything in these blocks, so |
|
* simply jump to the @end block. |
|
*/ |
|
endsz = snprintf(end, sizeof(end), |
|
"\n@end %s\n", texitoks[cmd].tok); |
|
assert(endsz < sizeof(end)); |
|
|
|
/* |
|
* Look up where our end token occurs. |
|
* Set our end position based on the relative offset of that |
|
* from our current position, or the EOF if we don't have a |
|
* proper ending point. |
|
*/ |
|
term = memmem(&buf[*pos], sz, end, endsz); |
|
endpos = NULL == term ? sz : |
|
*pos + term - &buf[*pos]; |
|
assert(endpos <= sz); |
|
while (*pos < endpos) |
|
advance(p, buf, pos); |
|
|
|
/* Only do this if we're not already at the end. */ |
|
if (endpos < sz) |
|
advanceto(p, buf, pos, endpos + endsz); |
} |
} |
|
|
static void |
static void |
Line 464 doverb(struct texi *p, enum texicmd cmd, |
|
Line 488 doverb(struct texi *p, enum texicmd cmd, |
|
const char *end, *term; |
const char *end, *term; |
size_t endsz, endpos; |
size_t endsz, endpos; |
|
|
|
advanceeoln(p, buf, sz, pos, 1); |
|
|
/* We end at exactly this token. */ |
/* We end at exactly this token. */ |
end = "\n@end verbatim\n"; |
end = "\n@end verbatim\n"; |
endsz = strlen(end); |
endsz = strlen(end); |
Line 479 doverb(struct texi *p, enum texicmd cmd, |
|
Line 505 doverb(struct texi *p, enum texicmd cmd, |
|
|
|
teximacro(p, "Bd -literal -offset indent"); |
teximacro(p, "Bd -literal -offset indent"); |
assert(endpos <= sz); |
assert(endpos <= sz); |
/* Run to the point inclusive the endpoint newline. */ |
while (*pos < endpos) { |
while (*pos < endpos + 1) { |
if (buf[*pos] == '\n') |
|
p->outcol = 0; |
|
else |
|
p->outcol++; |
if (*pos > 0 && '.' == buf[*pos]) |
if (*pos > 0 && '.' == buf[*pos]) |
if ('\n' == buf[*pos - 1]) |
if ('\n' == buf[*pos - 1]) |
fputs("\\&", stdout); |
fputs("\\&", stdout); |
Line 490 doverb(struct texi *p, enum texicmd cmd, |
|
Line 519 doverb(struct texi *p, enum texicmd cmd, |
|
advance(p, buf, pos); |
advance(p, buf, pos); |
} |
} |
teximacro(p, "Ed"); |
teximacro(p, "Ed"); |
advanceto(p, buf, pos, *pos + endpos + endsz); |
advanceto(p, buf, pos, endpos + endsz); |
} |
} |
|
|
static void |
static void |
Line 681 dotitle(struct texi *p, enum texicmd cmd, |
|
Line 710 dotitle(struct texi *p, enum texicmd cmd, |
|
start = end = *pos; |
start = end = *pos; |
while (end < sz && '\n' != buf[end]) |
while (end < sz && '\n' != buf[end]) |
end++; |
end++; |
|
advanceeoln(p, buf, sz, pos, 1); |
free(p->subtitle); |
free(p->subtitle); |
p->subtitle = malloc(end - start + 1); |
p->subtitle = malloc(end - start + 1); |
memcpy(p->subtitle, &buf[start], end - start); |
memcpy(p->subtitle, &buf[start], end - start); |
Line 894 dovalue(struct texi *p, enum texicmd cmd, |
|
Line 924 dovalue(struct texi *p, enum texicmd cmd, |
|
const char *buf, size_t sz, size_t *pos) |
const char *buf, size_t sz, size_t *pos) |
{ |
{ |
size_t start, end; |
size_t start, end; |
int clr; |
|
char *key, *val; |
char *key, *val; |
const char *cp; |
const char *cp; |
|
|
Line 942 dovalue(struct texi *p, enum texicmd cmd, |
|
Line 971 dovalue(struct texi *p, enum texicmd cmd, |
|
else |
else |
texiputchars(p, cp); |
texiputchars(p, cp); |
} else if (TEXICMD_IFCLEAR == cmd) { |
} else if (TEXICMD_IFCLEAR == cmd) { |
clr = NULL != valuellookup(p, buf, sz, pos); |
if (NULL != valuellookup(p, buf, sz, pos)) |
if (clr) |
doignblock(p, cmd, buf, sz, pos); |
p->ign++; |
else |
parseto(p, buf, sz, pos, texitoks[cmd].tok); |
parseto(p, buf, sz, pos, texitoks[cmd].tok); |
if (clr) |
|
p->ign--; |
|
} else if (TEXICMD_CLEAR == cmd) |
} else if (TEXICMD_CLEAR == cmd) |
valuelclear(p, buf, sz, pos); |
valuelclear(p, buf, sz, pos); |
} |
} |
Line 1121 dotop(struct texi *p, enum texicmd cmd, |
|
Line 1148 dotop(struct texi *p, enum texicmd cmd, |
|
time_t t; |
time_t t; |
char date[32]; |
char date[32]; |
|
|
|
if (--p->ign) |
|
texierr(p, "@top command while ignoring (%d)", p->ign); |
|
|
/* |
/* |
* Here we print our standard mdoc(7) prologue. |
* Here we print our standard mdoc(7) prologue. |
* We use the title set with @settitle for the `Nd' description |
* We use the title set with @settitle for the `Nd' description |
Line 1131 dotop(struct texi *p, enum texicmd cmd, |
|
Line 1161 dotop(struct texi *p, enum texicmd cmd, |
|
t = time(NULL); |
t = time(NULL); |
strftime(date, sizeof(date), "%F", localtime(&t)); |
strftime(date, sizeof(date), "%F", localtime(&t)); |
|
|
p->ign--; |
|
teximacroopen(p, "Dd"); |
teximacroopen(p, "Dd"); |
texiputchars(p, date); |
texiputchars(p, date); |
teximacroclose(p); |
teximacroclose(p); |