version 1.7, 2014/03/23 23:35:59 |
version 1.8, 2014/03/23 23:57:38 |
Line 158 formatescape(const char *buf, size_t *start, size_t en |
|
Line 158 formatescape(const char *buf, size_t *start, size_t en |
|
} |
} |
|
|
/* |
/* |
* Skip space characters. |
|
*/ |
|
static int |
|
skipspace(const char *buf, size_t *start, size_t end) |
|
{ |
|
size_t sv = *start; |
|
|
|
while (*start < end && ' ' == buf[*start]) |
|
(*start)++; |
|
|
|
return(*start > sv); |
|
} |
|
|
|
/* |
|
* We're at the character in front of a format code, which is structured |
* We're at the character in front of a format code, which is structured |
* like X<...> and can contain nested format codes. |
* like X<...> and can contain nested format codes. |
* This consumes the whole format code, and any nested format codes, til |
* This consumes the whole format code, and any nested format codes, til |
Line 204 formatcode(const char *buf, size_t *start, |
|
Line 190 formatcode(const char *buf, size_t *start, |
|
|
|
if (FMT__MAX == fmt) { |
if (FMT__MAX == fmt) { |
putchar(last = buf[(*start)++]); |
putchar(last = buf[(*start)++]); |
|
if ('\\' == last) |
|
putchar('e'); |
return(0); |
return(0); |
} |
} |
|
|
Line 363 formatcode(const char *buf, size_t *start, |
|
Line 351 formatcode(const char *buf, size_t *start, |
|
else |
else |
putchar(last = buf[*start]); |
putchar(last = buf[*start]); |
|
|
|
/* Protect against character escapes. */ |
|
if ('\\' == last) |
|
putchar('e'); |
|
|
(*start)++; |
(*start)++; |
|
|
if (' ' == last) |
if (' ' == last) |
Line 412 formatcodeln(const char *buf, size_t *start, size_t en |
|
Line 404 formatcodeln(const char *buf, size_t *start, size_t en |
|
' ' == buf[*start + 2])) |
' ' == buf[*start + 2])) |
printf("\\&"); |
printf("\\&"); |
|
|
if ('\n' != buf[*start]) |
if ('\n' == buf[*start]) |
putchar(last = buf[*start]); |
|
else |
|
putchar(last = ' '); |
putchar(last = ' '); |
|
else |
|
putchar(last = buf[*start]); |
|
|
|
/* Protect against character escapes. */ |
|
if ('\\' == last) |
|
putchar('e'); |
|
|
(*start)++; |
(*start)++; |
} |
} |
} |
} |
Line 471 command(struct state *st, const char *buf, size_t star |
|
Line 468 command(struct state *st, const char *buf, size_t star |
|
return; |
return; |
|
|
start += csz; |
start += csz; |
skipspace(buf, &start, end); |
while (start < end && ' ' == buf[start]) |
|
start++; |
|
|
len = end - start; |
len = end - start; |
|
|
if (st->paused) { |
if (st->paused) { |
Line 624 command(struct state *st, const char *buf, size_t star |
|
Line 623 command(struct state *st, const char *buf, size_t star |
|
static void |
static void |
verbatim(struct state *st, const char *buf, size_t start, size_t end) |
verbatim(struct state *st, const char *buf, size_t start, size_t end) |
{ |
{ |
size_t sv = start; |
int last; |
|
|
if ( ! st->parsing || st->paused) |
if ( ! st->parsing || st->paused) |
return; |
return; |
|
|
puts(".Bd -literal"); |
puts(".Bd -literal"); |
while (start < end) { |
for (last = ' '; start < end; start++) { |
if (start > sv && '\n' == buf[start - 1]) |
/* |
|
* Handle accidental macros (newline starting with |
|
* control character) and escapes. |
|
*/ |
|
if ('\n' == last) |
if ('.' == buf[start] || '\'' == buf[start]) |
if ('.' == buf[start] || '\'' == buf[start]) |
printf("\\&"); |
printf("\\&"); |
putchar(buf[start++]); |
putchar(last = buf[start]); |
|
if ('\\' == buf[start]) |
|
printf("e"); |
} |
} |
putchar('\n'); |
putchar('\n'); |
puts(".Ed"); |
puts(".Ed"); |
Line 704 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 709 ordinary(struct state *st, const char *buf, size_t sta |
|
else if ('\n' == last && '\'' == buf[start]) |
else if ('\n' == last && '\'' == buf[start]) |
printf("\\&"); |
printf("\\&"); |
putchar(last = buf[start++]); |
putchar(last = buf[start++]); |
|
if ('\\' == last) |
|
putchar('e'); |
} |
} |
|
|
if (start < end - 1 && '<' == buf[start + 1]) { |
if (start < end - 1 && '<' == buf[start + 1]) { |
Line 713 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 720 ordinary(struct state *st, const char *buf, size_t sta |
|
* what, so print a newline now. |
* what, so print a newline now. |
* Then print the (possibly nested) macros and |
* Then print the (possibly nested) macros and |
* following that, a newline. |
* following that, a newline. |
|
* Consume all whitespace so we don't |
|
* accidentally start an implicit literal line. |
*/ |
*/ |
if (formatcode(buf, &start, end, 0, 0)) { |
if (formatcode(buf, &start, end, 0, 0)) { |
putchar(last = '\n'); |
putchar(last = '\n'); |
Line 753 ordinary(struct state *st, const char *buf, size_t sta |
|
Line 762 ordinary(struct state *st, const char *buf, size_t sta |
|
else if ('\n' == last && '\'' == buf[start]) |
else if ('\n' == last && '\'' == buf[start]) |
printf("\\&"); |
printf("\\&"); |
putchar(last = buf[start++]); |
putchar(last = buf[start++]); |
|
if ('\\' == last) |
|
putchar('e'); |
} |
} |
} |
} |
|
|