version 1.13, 2014/04/01 13:05:50 |
version 1.16, 2014/04/02 16:41:02 |
Line 239 trylink(const char *buf, size_t *start, size_t end, si |
|
Line 239 trylink(const char *buf, size_t *start, size_t end, si |
|
return(1); |
return(1); |
} |
} |
|
|
|
|
/* |
/* |
* Doclifting: if we're a bold "-xx" and we're in the SYNOPSIS section, |
* Doclifting: if we're a bold "-xx" and we're in the SYNOPSIS section, |
* then it's likely that we're a flag. |
* then it's likely that we're a flag. |
Line 252 dosynopsisfl(const char *buf, size_t *start, size_t en |
|
Line 251 dosynopsisfl(const char *buf, size_t *start, size_t en |
|
{ |
{ |
size_t i; |
size_t i; |
again: |
again: |
|
assert(*start + 1 < end); |
|
assert('-' == buf[*start]); |
|
|
|
if ( ! isalnum((int)buf[*start + 1]) && |
|
'?' != buf[*start + 1] && |
|
'-' != buf[*start + 1]) { |
|
(*start)--; |
|
fputs("Ar ", stdout); |
|
return; |
|
} |
|
|
(*start)++; |
(*start)++; |
for (i = *start; i < end; i++) |
for (i = *start; i < end; i++) |
if (isalnum((int)buf[i])) |
if (isalnum((int)buf[i])) |
continue; |
continue; |
|
else if ('?' == buf[i]) |
|
continue; |
else if ('-' == buf[i]) |
else if ('-' == buf[i]) |
continue; |
continue; |
else if ('_' == buf[i]) |
else if ('_' == buf[i]) |
|
|
* been printed to the current line. |
* been printed to the current line. |
* If "nomacro", then we don't print any macros, just contained data |
* If "nomacro", then we don't print any macros, just contained data |
* (e.g., following "Sh" or "Nm"). |
* (e.g., following "Sh" or "Nm"). |
|
* "pos" is only significant in SYNOPSIS, and should be 0 when invoked |
|
* as the first format code on a line (for decoration as an "Nm"), |
|
* non-zero otherwise. |
* Return whether we've printed a macro or not--in other words, whether |
* Return whether we've printed a macro or not--in other words, whether |
* this should trigger a subsequent newline (this should be ignored when |
* this should trigger a subsequent newline (this should be ignored when |
* reentrant). |
* reentrant). |
*/ |
*/ |
static int |
static int |
formatcode(struct state *st, const char *buf, |
formatcode(struct state *st, const char *buf, size_t *start, |
size_t *start, size_t end, int reentrant, int nomacro) |
size_t end, int reentrant, int nomacro, int pos) |
{ |
{ |
enum fmt fmt; |
enum fmt fmt; |
size_t i, j, dsz; |
size_t i, j, dsz; |
Line 414 formatcode(struct state *st, const char *buf, |
|
Line 429 formatcode(struct state *st, const char *buf, |
|
printf("Em "); |
printf("Em "); |
break; |
break; |
case (FMT_BOLD): |
case (FMT_BOLD): |
if (SECT_SYNOPSIS == st->sect && |
if (SECT_SYNOPSIS == st->sect) { |
1 == dsz && |
if (1 == dsz && '-' == buf[*start]) |
'-' == buf[*start]) |
dosynopsisfl(buf, start, end); |
dosynopsisfl(buf, start, end); |
else if (0 == pos) |
else |
printf("Nm "); |
printf("Sy "); |
else |
|
printf("Ar "); |
|
break; |
|
} |
|
printf("Sy "); |
break; |
break; |
case (FMT_CODE): |
case (FMT_CODE): |
printf("Qo Li "); |
printf("Qo Li "); |
Line 467 formatcode(struct state *st, const char *buf, |
|
Line 486 formatcode(struct state *st, const char *buf, |
|
} |
} |
} |
} |
if (*start + 1 < end && '<' == buf[*start + 1]) { |
if (*start + 1 < end && '<' == buf[*start + 1]) { |
formatcode(st, buf, start, end, 1, nomacro); |
formatcode(st, buf, start, end, 1, nomacro, 1); |
continue; |
continue; |
} |
} |
|
|
Line 529 formatcodeln(struct state *st, const char *buf, |
|
Line 548 formatcodeln(struct state *st, const char *buf, |
|
last = ' '; |
last = ' '; |
while (*start < end) { |
while (*start < end) { |
if (*start + 1 < end && '<' == buf[*start + 1]) { |
if (*start + 1 < end && '<' == buf[*start + 1]) { |
formatcode(st, buf, start, end, 1, nomacro); |
formatcode(st, buf, start, end, 1, nomacro, 1); |
continue; |
continue; |
} |
} |
/* |
/* |
|
|
ordinary(struct state *st, const char *buf, size_t start, size_t end) |
ordinary(struct state *st, const char *buf, size_t start, size_t end) |
{ |
{ |
size_t i, j, opstack; |
size_t i, j, opstack; |
|
int seq; |
|
|
if ( ! st->parsing || st->paused) |
if ( ! st->parsing || st->paused) |
return; |
return; |
Line 869 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 889 ordinary(struct state *st, const char *buf, size_t sta |
|
* To wit, print out a "Nm" and "Nd" in that format. |
* To wit, print out a "Nm" and "Nd" in that format. |
*/ |
*/ |
if (SECT_NAME == st->sect) { |
if (SECT_NAME == st->sect) { |
for (i = end - 1; i > start; i--) |
for (i = end - 2; i > start; i--) |
if ('-' == buf[i]) |
if ('-' == buf[i] && ' ' == buf[i + 1]) |
break; |
break; |
if ('-' == buf[i]) { |
if ('-' == buf[i]) { |
j = i; |
j = i; |
Line 878 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 898 ordinary(struct state *st, const char *buf, size_t sta |
|
for ( ; i > start; i--) |
for ( ; i > start; i--) |
if ('-' != buf[i]) |
if ('-' != buf[i]) |
break; |
break; |
printf(".Nm "); |
fputs(".Nm ", stdout); |
formatcodeln(st, buf, &start, i + 1, 1); |
formatcodeln(st, buf, &start, i + 1, 1); |
putchar('\n'); |
putchar('\n'); |
start = j + 1; |
start = j + 1; |
printf(".Nd "); |
fputs(".Nd ", stdout); |
formatcodeln(st, buf, &start, end, 1); |
formatcodeln(st, buf, &start, end, 1); |
putchar('\n'); |
putchar('\n'); |
return; |
return; |
Line 896 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 916 ordinary(struct state *st, const char *buf, size_t sta |
|
last = '\n'; |
last = '\n'; |
opstack = 0; |
opstack = 0; |
|
|
while (start < end) { |
for (seq = 0; start < end; seq++) { |
/* |
/* |
* Loop til we get either to a newline or escape. |
* Loop til we get either to a newline or escape. |
* Escape initial control characters. |
* Escape initial control characters. |
Line 935 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 955 ordinary(struct state *st, const char *buf, size_t sta |
|
* following that, a newline. |
* following that, a newline. |
* Consume all whitespace so we don't |
* Consume all whitespace so we don't |
* accidentally start an implicit literal line. |
* accidentally start an implicit literal line. |
|
* If the macro ends with a flush comma or |
|
* period, let mdoc(7) handle it for us. |
*/ |
*/ |
if (formatcode(st, buf, &start, end, 0, 0)) { |
if (formatcode(st, buf, &start, end, 0, 0, seq)) { |
|
if ((start == end - 1 || |
|
(start < end - 1 && |
|
(' ' == buf[start + 1] || |
|
'\n' == buf[start + 1]))) && |
|
('.' == buf[start] || |
|
',' == buf[start])) { |
|
putchar(' '); |
|
putchar(buf[start++]); |
|
} |
putchar(last = '\n'); |
putchar(last = '\n'); |
while (start < end && ' ' == buf[start]) |
while (start < end && ' ' == buf[start]) |
start++; |
start++; |