From c0de4379d2a97a61afe862d2d8b246951f44b1c5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 13 Sep 2014 21:47:02 -0700 Subject: Fixes: font escape, macros, crash. Macros can have up to four letter names, not just two. The \f[..] parsing is fixed so inline font changes work. The CR font is supported. Crash fixed when the section table is empty. --- man2html/man2html.c | 76 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/man2html/man2html.c b/man2html/man2html.c index b37eef6..6565b30 100644 --- a/man2html/man2html.c +++ b/man2html/man2html.c @@ -53,12 +53,13 @@ static char *scan_troff_mandoc(char *c, int san, char **result); static char **argument=NULL; -static char charb[3]; +static char charb[5]; static char * expand_char(int nr) { STRDEF *h; + int i; if (!nr) return NULL; @@ -74,10 +75,15 @@ expand_char(int nr) curpos += h->slen; return h->st; } - charb[0] = nr/256; - charb[1] = nr%256; - charb[2] = 0; - curpos += 2; + + charb[0] = 0; + + for (i = 0; nr && i < 4; i++) { + memmove(charb+1, charb, 4); + charb[0] = nr%256; + nr /= 256; + curpos++; + } return charb; } @@ -96,6 +102,15 @@ expand_string(int nr) return NULL; } +static int str_to_code(char *str) +{ + int code = 0; + while (*str && !isspace(*str)) { + code *= 256; + code += *str++; + } + return code; +} static char outbuffer[1024]; static int obp=0; @@ -452,7 +467,7 @@ change_to_font(int nr) case '0': nr++; case '1': case '2': case '3': case '4': nr = nr-'1'; break; - case V('C','W'): break; + case V('C','W'): case V('C','R'): nr=3; break; case 'L': nr=3; break; case 'B': nr=2; break; case 'I': nr=1; break; @@ -570,12 +585,20 @@ scan_escape(char *c) { c=scan_escape(c); c--; i=intresult; - } else if (*c != '(') - i=*c; - else { - c++; - i=c[0]*256+c[1]; + } else if (*c == '[' || *c == '(') { c++; + if (*c == ']' || *c == ')') { + i = 0; + } else if (c[1] == ']' || c[1] == ')') { + i = *c++; + } else if (c[2] == ']' || c[2] == ')') { + i=c[0]*256+c[1]; + c += 2; + } else { + abort(); + } + } else { + i=*c; } if (!skip_escape) h=change_to_font(i); else h=""; break; @@ -1535,12 +1558,10 @@ scan_request(char *c) { c++; if (c[0] == '\n') return c+1; - if (c[1] == '\n') - j = 1; - else - j = 2; - while (c[j] == ' ' || c[j] == '\t') - j++; + + j = strcspn(c, " \n\t"); + j += strspn(c + j, " \t"); + if (c[0] == escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stupid */ @@ -1549,7 +1570,7 @@ scan_request(char *c) { else c = scan_escape(c+1); } else { - i=V(c[0],c[1]); + i=str_to_code(c); switch (i) { case V('a','b'): h=c+j; @@ -1566,7 +1587,7 @@ scan_request(char *c) { { STRDEF *de; c=c+j; - i=V(c[0],c[1]); + i=str_to_code(c); if (*c == '\n') { c++;break; } while (*c && *c!='\n') c++; c++; @@ -1600,7 +1621,7 @@ scan_request(char *c) { int oldcurpos=curpos; c=c+j; while (*c == ' ') c++; - i=V(c[0],c[1]); + i=str_to_code(c); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } @@ -2212,11 +2233,14 @@ scan_request(char *c) { int olen=0; c=c+j; sl=fill_words(c, wordlist, SIZE(wordlist), &words, '\n'); - i=V(c[0],c[1]);j=2; - if (words == 1) wordlist[1]=".."; else { + i=str_to_code(c); + if (words == 1) { + wordlist[1]=".."; + j = 2; + } else { wordlist[1]--; wordlist[1][0]='.'; - j=3; + j+=1; } c=sl+1; sl=c; @@ -3212,8 +3236,10 @@ main(int argc, char **argv) { if (output_possible) { /*   for mosaic users */ printf("
\n 

Index

\n
\n"); - manidx[mip]=0; - printf("%s", manidx); + if (manidx) { + manidx[mip]=0; + printf("%s", manidx); + } if (subs) printf("
\n"); printf("\n"); print_sig(); -- cgit v1.2.3