version 1.52, 2015/02/19 11:14:27 |
version 1.53, 2015/02/19 13:50:45 |
Line 1059 verbatim(struct state *st, char *buf, size_t start, si |
|
Line 1059 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 1627 dofile(const struct args *args, const char *fname, |
|
Line 1660 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 1733 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(); |
} |
} |