version 1.50, 2015/02/19 11:05:24 |
version 1.54, 2015/02/19 15:26:45 |
Line 185 outbuf_flush(struct state *st) |
|
Line 185 outbuf_flush(struct state *st) |
|
if (OUST_TXT == st->oust && st->wantws) |
if (OUST_TXT == st->oust && st->wantws) |
putchar(' '); |
putchar(' '); |
|
|
fputs(st->outbuf, stdout); |
if (OUST_MAC == st->oust && '"' == *st->outbuf) |
|
printf("\\(dq%s", st->outbuf + 1); |
|
else |
|
fputs(st->outbuf, stdout); |
|
|
*st->outbuf = '\0'; |
*st->outbuf = '\0'; |
st->outbuflen = 0; |
st->outbuflen = 0; |
|
|
Line 480 formatcode(struct state *st, const char *buf, size_t * |
|
Line 484 formatcode(struct state *st, const char *buf, size_t * |
|
{ |
{ |
size_t i, j, dsz; |
size_t i, j, dsz; |
enum fmt fmt; |
enum fmt fmt; |
int wantws; |
|
unsigned char uc; |
unsigned char uc; |
|
|
assert(*start + 1 < end); |
assert(*start + 1 < end); |
Line 559 formatcode(struct state *st, const char *buf, size_t * |
|
Line 562 formatcode(struct state *st, const char *buf, size_t * |
|
if (FMT__MAX != fmt && !nomacro) { |
if (FMT__MAX != fmt && !nomacro) { |
|
|
/* |
/* |
* We may already have wantws if there was whitespace |
|
* before the code ("text B<text"), but initial |
|
* whitespace inside our scope ("textB< text") |
|
* allows to break at this point as well. |
|
*/ |
|
|
|
wantws = ' ' == buf[*start] || |
|
(OUST_MAC == st->oust ? st->wantws : ! st->outbuflen); |
|
|
|
/* |
|
* If we are on a text line and there is no |
* If we are on a text line and there is no |
* whitespace before our content, we have to make |
* whitespace before our content, we have to make |
* the previous word a prefix to the macro line. |
* the previous word a prefix to the macro line. |
* In the following, mdoc_newln() must not be used |
|
* lest we clobber out output state. |
|
*/ |
*/ |
|
|
if (OUST_MAC != st->oust && ! wantws) { |
if (OUST_MAC != st->oust && ' ' != buf[*start] && |
|
st->outbuflen) { |
if (OUST_NL != st->oust) |
if (OUST_NL != st->oust) |
putchar('\n'); |
mdoc_newln(st); |
printf(".Pf "); |
printf(".Pf "); |
st->wantws = 0; |
st->oust = OUST_MAC; |
|
st->wantws = 1; |
} |
} |
|
|
outbuf_flush(st); |
outbuf_flush(st); |
|
|
/* Whitespace is easier to suppress on macro lines. */ |
/* |
|
* Whitespace is easier to suppress on macro lines. |
|
* We may already have wantws if there was whitespace |
|
* before the code ("text B<text"), or there may be |
|
* whitespace inside our scope ("textB< text"). |
|
*/ |
|
|
if (OUST_MAC == st->oust && ! wantws) |
if (OUST_MAC == st->oust && ' ' != buf[*start] && |
printf(" Ns "); |
! st->wantws) |
|
printf(" Ns"); |
|
|
/* Unless we are on a macro line, start one. */ |
/* Unless we are on a macro line, start one. */ |
|
|
if (OUST_MAC != st->oust && wantws) { |
if (OUST_MAC != st->oust) { |
if (OUST_NL != st->oust) |
if (OUST_NL != st->oust) |
putchar('\n'); |
mdoc_newln(st); |
putchar('.'); |
putchar('.'); |
|
st->oust = OUST_MAC; |
} else |
} else |
putchar(' '); |
putchar(' '); |
|
st->wantws = 1; |
|
|
/* |
/* |
* Print the macro corresponding to this format code, |
* Print the macro corresponding to this format code, |
Line 657 formatcode(struct state *st, const char *buf, size_t * |
|
Line 658 formatcode(struct state *st, const char *buf, size_t * |
|
default: |
default: |
abort(); |
abort(); |
} |
} |
st->oust = OUST_MAC; |
|
st->wantws = 1; |
|
} else |
} else |
outbuf_flush(st); |
outbuf_flush(st); |
|
|
Line 1059 verbatim(struct state *st, char *buf, size_t start, si |
|
Line 1058 verbatim(struct state *st, char *buf, size_t start, si |
|
{ |
{ |
size_t i, ift, ifo, ifa, ifc, inl; |
size_t i, ift, ifo, ifa, ifc, inl; |
char *cp, *cp2; |
char *cp, *cp2; |
int nopen; |
int indisplay, nopen, wantsp; |
|
|
if ( ! st->parsing || st->paused || start == end) |
if (st->paused || ! st->parsing) |
return; |
return; |
|
|
|
indisplay = wantsp = 0; |
|
|
again: |
again: |
|
if (start == end) { |
|
if (indisplay) |
|
puts(".Ed"); |
|
return; |
|
} |
|
|
|
if ('\n' == buf[start]) { |
|
wantsp = 1; |
|
start++; |
|
goto again; |
|
} |
|
|
/* |
/* |
* If we're in the SYNOPSIS, see if we're an #include block. |
* If we're in the SYNOPSIS, see if we're an #include block. |
* If we are, then print the "In" macro and re-loop. |
* If we are, then print the "In" macro and re-loop. |
|
|
while (i < end && buf[i] == ' ') |
while (i < end && buf[i] == ' ') |
i++; |
i++; |
if (i == end) |
if (i == end) |
return; |
goto again; |
|
|
/* We're an include block! */ |
/* We're an include block! */ |
if (end - i > 10 && |
if (end - i > 10 && |
|
|
start = i + 10; |
start = i + 10; |
while (start < end && ' ' == buf[start]) |
while (start < end && ' ' == buf[start]) |
start++; |
start++; |
|
if (indisplay) |
|
puts(".Ed"); |
|
indisplay = wantsp = 0; |
fputs(".In ", stdout); |
fputs(".In ", stdout); |
/* Stop til the '>' marker or we hit eoln. */ |
/* Stop til the '>' marker or we hit eoln. */ |
while (start < end && |
while (start < end && |
|
|
|
|
/* Other preprocessor directives. */ |
/* Other preprocessor directives. */ |
if ('#' == buf[i]) { |
if ('#' == buf[i]) { |
|
if (indisplay) |
|
puts(".Ed"); |
|
indisplay = wantsp = 0; |
fputs(".Fd ", stdout); |
fputs(".Fd ", stdout); |
start = i; |
start = i; |
while(start < end && '\n' != buf[start]) |
while(start < end && '\n' != buf[start]) |
|
|
buf[i] = ' '; |
buf[i] = ' '; |
buf[ifo++] = '\0'; |
buf[ifo++] = '\0'; |
register_type(buf + ift); |
register_type(buf + ift); |
|
if (indisplay) |
|
puts(".Ed"); |
|
indisplay = wantsp = 0; |
printf(".Ft %s", buf + ift); |
printf(".Ft %s", buf + ift); |
if (buf[ifo] == '*') { |
if (buf[ifo] == '*') { |
fputs(" *", stdout); |
fputs(" *", stdout); |
|
|
buf[inl] = '\0'; |
buf[inl] = '\0'; |
puts(buf + ifc); |
puts(buf + ifc); |
} |
} |
start = inl + 1; |
start = inl < end ? inl + 1 : end; |
if (start < end) |
goto again; |
goto again; |
|
return; |
|
} |
} |
} |
} |
|
|
puts(".Bd -literal"); |
if ( ! indisplay) |
for (last = ' '; start < end; start++) { |
puts(".Bd -literal"); |
|
else if (wantsp) |
|
putchar('\n'); |
|
indisplay = 1; |
|
wantsp = 0; |
|
|
|
for (last = '\n'; start < end; start++) { |
/* |
/* |
* Handle accidental macros (newline starting with |
* Handle accidental macros (newline starting with |
* control character) and escapes. |
* control character) and escapes. |
*/ |
*/ |
if ('\n' == last) |
if ('\n' == last) { |
|
if ('\n' == buf[start]) |
|
goto again; |
if ('.' == buf[start] || '\'' == buf[start]) |
if ('.' == buf[start] || '\'' == buf[start]) |
printf("\\&"); |
printf("\\&"); |
|
} |
putchar(last = buf[start]); |
putchar(last = buf[start]); |
if ('\\' == buf[start]) |
if ('\\' == buf[start]) |
printf("e"); |
printf("e"); |
} |
} |
putchar(last = '\n'); |
if ('\n' != last) |
puts(".Ed"); |
putchar('\n'); |
|
if (indisplay) |
|
puts(".Ed"); |
} |
} |
|
|
/* |
/* |
Line 1428 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 1460 ordinary(struct state *st, const char *buf, size_t sta |
|
if ( ! isspace(last)) |
if ( ! isspace(last)) |
outbuf_addchar(st); |
outbuf_addchar(st); |
if (start < end && |
if (start < end && |
|
! isspace((unsigned char)buf[start - 1]) && |
! isspace((unsigned char)buf[start])) |
! isspace((unsigned char)buf[start])) |
continue; |
continue; |
|
|
Line 1532 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 1565 ordinary(struct state *st, const char *buf, size_t sta |
|
* XXX Some punctuation characters |
* XXX Some punctuation characters |
* are not handled yet. |
* are not handled yet. |
*/ |
*/ |
if ((start == end - 1 || |
if ((start == end - 1 || |
(start < end - 1 && |
(start < end - 1 && |
(' ' == buf[start + 1] || |
(' ' == buf[start + 1] || |
'\n' == buf[start + 1]))) && |
'\n' == buf[start + 1]))) && |
('.' == buf[start] || |
NULL != strchr("|.,;:?!)]", buf[start])) { |
',' == buf[start])) { |
|
putchar(' '); |
putchar(' '); |
putchar(buf[start++]); |
putchar(buf[start++]); |
} |
} |
Line 1627 dofile(const struct args *args, const char *fname, |
|
Line 1659 dofile(const struct args *args, const char *fname, |
|
struct state st; |
struct state st; |
const char *fbase, *fext, *section, *date, *format; |
const char *fbase, *fext, *section, *date, *format; |
char *title, *cp; |
char *title, *cp; |
size_t sup, end, i, cur = 0; |
size_t cur, end; |
|
int verb; |
|
|
if (0 == sz) |
if (0 == sz) |
return; |
return; |
Line 1699 dofile(const struct args *args, const char *fname, |
|
Line 1732 dofile(const struct args *args, const char *fname, |
|
|
|
/* Main loop over file contents. */ |
/* Main loop over file contents. */ |
|
|
while (cur < sz) { |
cur = 0; |
|
for (;;) { |
|
while (cur < sz && '\n' == buf[cur]) |
|
cur++; |
|
if (cur >= sz) |
|
break; |
|
|
|
verb = isspace((unsigned char)buf[cur]); |
|
|
/* Read until next paragraph. */ |
/* Read until next paragraph. */ |
for (i = cur + 1; i < sz; i++) |
|
if ('\n' == buf[i] && '\n' == buf[i - 1]) { |
for (end = cur + 1; end + 1 < sz; end++) |
/* Consume blank paragraphs. */ |
if ('\n' == buf[end] && '\n' == buf[end + 1] && |
while (i + 1 < sz && '\n' == buf[i + 1]) |
!(verb && end + 2 < sz && |
i++; |
isspace((unsigned char)buf[end + 2]))) |
break; |
break; |
} |
|
|
|
/* Adjust end marker for EOF. */ |
/* Adjust end marker for EOF. */ |
end = i < sz ? i - 1 : |
|
('\n' == buf[sz - 1] ? sz - 1 : sz); |
|
sup = i < sz ? end + 2 : sz; |
|
|
|
|
if (end < sz && '\n' != buf[end]) |
|
end++; |
|
|
/* Process paragraph and adjust start. */ |
/* Process paragraph and adjust start. */ |
|
|
dopar(&st, buf, cur, end); |
dopar(&st, buf, cur, end); |
cur = sup; |
cur = end + 2; |
} |
} |
dict_destroy(); |
dict_destroy(); |
} |
} |