rem
stringlengths 0
274k
| add
stringlengths 0
169k
| context
stringlengths 9
471k
|
---|---|---|
static int function_argument=0; | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
|
case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } return 0; break; case REQ_An: c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; c=c+j; i=V(c[0],c[1]); if (*c=='\n') { | case REQ_ab: { h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } return 0; break; } case REQ_An: { c+=j; c=scan_troff_mandoc(c,1,0); break; } case REQ_di: { STRDEF *de; c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else | h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; break; } case REQ_br: { if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; } case REQ_c2: { c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; } case REQ_cc: { c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; } case REQ_ce: { c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; } case REQ_ec: { c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); } case REQ_eo: { escapesym='\0'; c=skip_till_newline(c); break; } case REQ_ex: { return 0; break; } case REQ_fc: { c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; } case REQ_fi: { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; } case REQ_ft: { c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; } case REQ_el: { int ifelseval = s_ifelseval.pop(); if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: case REQ_if: { c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: { if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; } case REQ_ps: { c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0; i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; } case REQ_sp: { c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_so: { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: { c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; } case REQ_ti: { | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) | c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; } case REQ_tm: { c=c+j; h=c; while (*c!='\n') c++; *c='\0'; #if 1 out_html("<-- STDOUT: "); out_html(h); out_html("-->"); #else fprintf(stderr,"%s\n", h); #endif *c='\n'; break; } case REQ_B: case REQ_I: { out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Fd: { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: case REQ_if: { c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; *c='\n'; break; case REQ_B: case REQ_I: out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { | wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; | } function_argument=1; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc: { c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; break; } case REQ_Fa: { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_DT: { for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; } case REQ_IP: { sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; } case REQ_TP: { if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; } case REQ_IX: { c=skip_till_newline(c); break; } case REQ_P: case REQ_LP: case REQ_PP: { if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_HP: { if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; } case REQ_PD: { c=skip_till_newline(c); break; } case REQ_Rs: case REQ_RS: { sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } } case REQ_Re: case REQ_RE: { if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; } case REQ_SB: { out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; } case REQ_SM: { c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; } case REQ_Ss: mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: mandoc_command = !mode || mandoc_command; case REQ_SH: { c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; } case REQ_Sx: { out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_TS: { c=scan_table(c); break; } case REQ_Dt: mandoc_command = true; case REQ_TH: { if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n"); #ifdef SIMPLE_MAN2HTML out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n"); #else out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n"); #endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; } case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; break; } case REQ_rm: case REQ_rn: { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: case REQ_in: { c=skip_till_newline(c); break; } case REQ_nr: { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: mode=1; case REQ_de: { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } } function_argument=1; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc: { c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; break; } case REQ_Fa: { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case REQ_Ft: case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: mandoc_command = !mode || mandoc_command; case REQ_SH: c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; | de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n"); #ifdef SIMPLE_MAN2HTML out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n"); #else out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n"); #endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) | h[j]=0; if (de) | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); | delete [] de->st; de->st=h; | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
out_html("Section not specified"); | de = new STRDEF(); de->nr=0; de->name = name; de->next=defdef; de->st=h; defdef=de; | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
*sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: case REQ_rn: { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: case REQ_in: c=skip_till_newline(c); break; case REQ_nr: { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: mode=1; case REQ_de: { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') | } c=skip_till_newline(c); break; } case REQ_Bl: { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) itemdepth++; if (nl) { strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: { c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_It: { c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
h[j++]='\\'; sl++; | c++; c=scan_troff(c,1,NULL); | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) itemdepth++; if (nl) strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { c++; c=scan_troff(c,1,NULL); } else { c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; | { c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; } | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
else if (request==REQ_Nx)) | else if (request==REQ_Nx) | static char *scan_request(char *c){ /* mdoc(7) stuff */ static bool mandoc_synopsis=false; /* True if we are in the synopsis section */ static bool mandoc_command=false; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ static bool ur_ignore=false; // Has .UR a parameter : (for .UE to know if or not to write </a>) static int function_argument=0; // Number of function argument (.Fo, .Fa, .Fc) int i,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { int j, nlen; if (c[1]=='\n') j=1; else j=2; nlen = 0; while ((c[nlen] != ' ') && (c[nlen] != '\t') && (c[nlen] != '\n') && (c[nlen] != escapesym)) nlen++; j = nlen; while (c[j]==' ' || c[j]=='\t') j++; i=V(c[0],c[1]); /* search macro database of self-defined macros */ owndef = defdef; while (owndef && strncmp(c, owndef->name, strlen(owndef->name))) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) scan_troff_mandoc(wordlist[i],1,&h); else scan_troff(wordlist[i],1,&h); wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); else scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else { switch (int request = get_request(c, nlen)) { case REQ_ab: h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case REQ_An: // mdoc(7) "Author Name" c+=j; c=scan_troff_mandoc(c,1,0); break; case REQ_di: { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++; break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case REQ_ds: mode=1; case REQ_as: { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case REQ_br: if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) c=scan_escape(c+1); c=skip_till_newline(c); break; case REQ_c2: c=c+j; if (*c!='\n') nobreaksym=*c; else nobreaksym='\''; c=skip_till_newline(c); break; case REQ_cc: c=c+j; if (*c!='\n') controlsym=*c; else controlsym='.'; c=skip_till_newline(c); break; case REQ_ce: c=c+j; if (*c=='\n') i=1; else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case REQ_ec: c=c+j; if (*c!='\n') escapesym=*c; else escapesym='\\'; break; c=skip_till_newline(c); case REQ_eo: escapesym='\0'; c=skip_till_newline(c); break; case REQ_ex: return 0; break; case REQ_fc: c=c+j; if (*c=='\n') fieldsym=padsym='\0'; else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case REQ_fi: if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_ft: c=c+j; if (*c=='\n') out_html(change_to_font(0)); else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case REQ_el: { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case REQ_ie: /* .ie c anything : then part of if else */ case REQ_if: { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); if (request == REQ_ie) { int ifelseval=!i; s_ifelseval.push( ifelseval ); } if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case REQ_ig: { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case REQ_nf: if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case REQ_ps: c=c+j; if (*c=='\n') out_html(change_to_size('0')); else { j=0;i=0; if (*c=='-') { j= -1; c++; } else if (*c=='+') j=1;c++; c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case REQ_sp: c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_so: { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') h=c; else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else scan_troff(buf+1,0,NULL); delete [] buf; delete [] name; *c++='\n'; break; } case REQ_ta: c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case REQ_ti: /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case REQ_tm: c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case REQ_B: case REQ_I: /* parse one line in a certain font */ out_html(change_to_font(*c)); fill_words(c, wordlist, &words, false, 0); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Fd: // mdoc(7) "Function Definition" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } if (mandoc_synopsis) { out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fn: // mdoc(7) for "Function calls" ### FIXME { // brackets and commas have to be inserted automatically char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); if (!words) { out_html(" ()"); } else { for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } else if (i<words-1) out_html(", "); } out_html(")"); } out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fo: // mdoc(7) "Function definition Opening" { char font[2]; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words, true, &c); // Normally a .Fo has only one parameter for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (i==0) { out_html(" ("); } // ### TODO What should happen if there is more than one argument // else if (i<words-1) out_html(", "); } function_argument=1; // Must be > 0 out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; break; } case REQ_Fc:// mdoc(7) "Function definition Close" { // .Fc has no parameter c+=j; c=skip_till_newline(c); char font[2]; font[0] = 'B'; font[1] = 'B'; out_html(change_to_font(font[i&1])); out_html(")"); out_html(change_to_font('R')); if (mandoc_synopsis) out_html("<br>"); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; function_argument=0; // Reset the count variable break; } case REQ_Fa: // mdoc(7) "Function definition argument" { char font[2] ; font[0] = 'B'; font[1] = 'B'; c+=j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font(font[i&1])); // function_argument==0 means that we had no .Fo before, e.g. in mdoc.samples(7) if (function_argument > 1) { out_html(", "); curpos+=2; function_argument++; } else if (function_argument==1) { // We are only at the first parameter function_argument++; } for (i=0; i<words; i++) { wordlist[i][-1]=' '; scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (!fillout) curpos=0; else curpos++; break; } case REQ_OP: /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; // Do not break! case REQ_Ft: //perhaps "Function return type" case REQ_BR: case REQ_BI: case REQ_IB: case REQ_IR: case REQ_RB: case REQ_RI: { // ### VERIFY bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words, true, &c); /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case REQ_DT: for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case REQ_IP: sl=fill_words(c+j, wordlist, &words, true, &c); if (!dl_set[itemdepth]) { out_html("<DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) scan_troff(wordlist[0], 1,NULL); out_html("<DD>"); curpos=0; break; case REQ_TP: if (!dl_set[itemdepth]) { out_html("<br><br><DL>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case REQ_IX: /* general index */ c=skip_till_newline(c); break; case REQ_P: case REQ_LP: case REQ_PP: if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_HP: if (!dl_set[itemdepth]) { out_html("<DL>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case REQ_PD: c=skip_till_newline(c); break; case REQ_Rs: /* mdoc(7) */ case REQ_RS: sl=fill_words(c+j, wordlist, &words, true, 0); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case REQ_Re: /* mdoc(7) */ case REQ_RE: if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case REQ_SB: out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case REQ_SM: c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case REQ_Ss: /* mdoc(7) */ mandoc_command = 1; case REQ_SS: mode=1; case REQ_Sh: /* mdoc(7) */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case REQ_SH: // man(7) "Sub Header" c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case REQ_Sx: // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_TS: c=scan_table(c); break; case REQ_Dt: /* mdoc(7) */ mandoc_command = true; case REQ_TH: if (!output_possible) { sl = fill_words(c+j, wordlist, &words, true, &c); if (words>=1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; for (i=0; i<words; i++) { if (wordlist[i][0] == '\007') wordlist[i]++; if (wordlist[i][strlen(wordlist[i])-1] == '\007') wordlist[i][strlen(wordlist[i])-1] = 0; } output_possible=1; out_html( DOCTYPE"<HTML>\n<HEAD>\n");#ifdef SIMPLE_MAN2HTML // Most English man pages are in ISO-8859-1 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n");#else // kio_man transforms from local to UTF-8 out_html("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); out_html(QTextCodec::codecForLocale()->mimeName()); out_html("\">\n");#endif out_html("<TITLE>"); out_html(scan_troff(wordlist[0], 0, NULL)); out_html( " Manpage</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\""); out_html(htmlPath); out_html("/kde-default.css\" type=\"text/css\">\n" ); out_html( "<meta name=\"Mandoc Type\" content=\""); if (mandoc_command) out_html("mdoc"); else out_html("man"); out_html("\">\n"); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div style=\"background-image: url("); out_html(cssPath); out_html("/top-middle.png); width: 100%; height: 131pt;\">\n" ); out_html("<div style=\"position: absolute; right: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-right-konqueror.png\" style=\"margin: 0pt\" alt=\"Top right\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; left: 0pt;\">\n"); out_html("<img src=\""); out_html(htmlPath); out_html("/top-left.png\" style=\"margin: 0pt\" alt=\"Top left\">\n"); out_html("</div>\n"); out_html("<div style=\"position: absolute; top: 25pt; right: 100pt; text-align: right; font-size: xx-large; font-weight: bold; text-shadow: #fff 0pt 0pt 5pt; color: #444\">\n"); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html("</div>\n"); out_html("</div>\n"); out_html("<div style=\"margin-left: 5em; margin-right: 5em;\">\n"); out_html("<h1>" ); out_html( scan_troff(wordlist[0], 0, NULL ) ); out_html( "</h1>\n" ); if (words>1) { out_html("Section: " ); if (!mandoc_command && words>4) out_html(scan_troff(wordlist[4], 0, NULL) ); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(scan_troff(wordlist[1], 0, NULL)); out_html(")\n"); } else { out_html("Section not specified"); } *sl='\n'; } } else { fprintf(stderr, "%s", ".TH found but output not possible"); c=skip_till_newline(c); } curpos=0; break; case REQ_TX: { sl=fill_words(c+j, wordlist, &words, true, &c); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; } break; case REQ_rm: /* .rm xx : Remove request, macro or string */ case REQ_rn: /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case REQ_nx: /* .nx filename : next file. */ case REQ_in: /* .in +-N : Indent */ c=skip_till_newline(c); break; case REQ_nr: /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case REQ_am: /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case REQ_de: /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char endmacro[SMALL_STR_MAX]; c=c+j; char *next_line; sl = fill_words(c, wordlist, &words, true, &next_line); char *name = wordlist[0]; c = name; while ((*c != ' ') && (*c != '\n')) c++; *c = '\0'; if (words == 1) { endmacro[0] = '.'; endmacro[1] = '.'; endmacro[2] = '\0'; } else { char *p = endmacro; *p++ = '.'; c = wordlist[1]; while ((*c != ' ') && (*c != '\n')) *p++ = *c++; *p = '\0'; } c = next_line; sl=c; while (*c && strncmp(c,endmacro, strlen(endmacro))) c=skip_till_newline(c); de=defdef; while (de && strncmp(name, de->name, strlen(de->name))) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=0; // not used for macro's. de->name = name; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); break; case REQ_Bl: /* mdoc(7) */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) /* These things can nest. */ itemdepth++; if (nl) /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL>\n"); } if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; } case REQ_El: /* mdoc(7) */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) out_html("</DL>\n"); else if (dl_set[itemdepth] & BL_BULLET_LIST) out_html("</UL>\n"); else if (dl_set[itemdepth] & BL_ENUM_LIST) out_html("</OL>\n"); dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_It: /* mdoc(7) */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) c = skip_till_newline(c); if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case REQ_Bk: /* mdoc(7) */ case REQ_Ek: /* mdoc(7) */ case REQ_Dd: /* mdoc(7) */ case REQ_Os: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Bt: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case REQ_At: /* mdoc(7) */ case REQ_Fx: /* mdoc(7) */ case REQ_Nx: /* mdoc(7) */ case REQ_Ox: /* mdoc(7) */ case REQ_Bx: /* mdoc(7) */ case REQ_Ux: /* mdoc(7) */ { bool parsable=true; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (request==REQ_At) { out_html("AT&T UNIX "); parsable=false; } else if (request==REQ_Fx) { out_html("FreeBSD "); parsable=false; } else if (request==REQ_Nx)) out_html("NetBSD "); else if (request==REQ_Ox) out_html("OpenBSD "); else if (request==REQ_Bx) out_html("BSD "); else if (request==REQ_Ux) out_html("UNIX "); if (parsable) c=scan_troff_mandoc(c,1,0); else c=scan_troff(c,1,0); if (fillout) curpos++; else curpos=0; break; } case REQ_Dl: /* mdoc(7) */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case REQ_Bd: /* mdoc(7) */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case REQ_Ed: /* mdoc(7) */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case REQ_Be: /* mdoc(7) */ c=c+j; if (fillout) out_html("<br><br>"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Xr: /* mdoc(7) */ // ### FIXME: it should issue a <a href="man:somewhere(x)"> directly { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '.' || *c == ':' || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case REQ_Fl: // mdoc(7) "FLags" { trans_char(c,'"','\a'); c+=j; sl=fill_words(c, wordlist, &words, true, &c); out_html(change_to_font('B')); if (!words) { out_html("-"); // stdin or stdout } else { for (i=0;i<words;++i) { if (ispunct(wordlist[i][0]) && wordlist[i][0]!='-') { scan_troff_mandoc(wordlist[i], 1, NULL); } else { if (i>0) out_html(" "); // Put a space between flags out_html("-"); scan_troff_mandoc(wordlist[i], 1, NULL); } } } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Pa: /* mdoc(7) */ case REQ_Pf: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Pp: /* mdoc(7) */ if (fillout) out_html("<br><br>\n"); else { out_html(NEWLINE); } curpos=0; c=skip_till_newline(c); break; case REQ_Aq: // mdoc(7) "Angle bracket Quote" c=process_quote(c,j,"<",">"); break; case REQ_Bq: // mdoc(7) "Bracket Quote" c=process_quote(c,j,"[","]"); break; case REQ_Dq: // mdoc(7) "Double Quote" c=process_quote(c,j,"“","”"); break; case REQ_Pq: // mdoc(7) "Parenthese Quote" c=process_quote(c,j,"(",")"); break; case REQ_Qq: // mdoc(7) "straight double Quote" c=process_quote(c,j,""","""); break; case REQ_Sq: // mdoc(7) "Single Quote" c=process_quote(c,j,"‘","’"); break; case REQ_Op: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Oo: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case REQ_Oc: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case REQ_Ql: /* mdoc(7) */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case REQ_Ar: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') /* An empty Ar means "file ..." */ out_html("file ..."); else c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Em: /* mdoc(7) */ out_html("<em>"); trans_char(c,'"','\a'); c+=j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html("</em>"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Ad: /* mdoc(7) */ case REQ_Va: /* mdoc(7) */ case REQ_Xc: /* mdoc(7) */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nd: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Nm: // mdoc(7) "Name Macro" ### FIXME { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; // ### TODO Use QCString trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis && mandoc_name_count) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ out_html("<BR>"); } else if (!mandoc_name_count) { const char *nextbreak = strchr(c, '\n'); const char *nextspace = strchr(c, ' '); if (nextspace < nextbreak) nextbreak = nextspace; if (nextbreak) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, nextbreak - c, SMALL_STR_MAX); } } mandoc_name_count++; out_html(change_to_font('B')); // ### FIXME: fill_words must be used while (*c == ' '|| *c == '\t') c++; if ((tolower(*c) >= 'a' && tolower(*c) <= 'z' ) || (*c >= '0' && *c <= '9')) { // alphanumeric argument c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); } else { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); out_html(change_to_font('R')); } if (fillout) curpos++; else curpos=0; break; } case REQ_Cd: /* mdoc(7) */ case REQ_Cm: /* mdoc(7) */ case REQ_Ic: /* mdoc(7) */ case REQ_Ms: /* mdoc(7) */ case REQ_Or: /* mdoc(7) */ case REQ_Sy: /* mdoc(7) */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_Dv: /* mdoc(7) */ case REQ_Ev: /* mdoc(7) */ case REQ_Fr: /* mdoc(7) */ case REQ_Li: /* mdoc(7) */ case REQ_No: /* mdoc(7) */ case REQ_Ns: /* mdoc(7) */ case REQ_Tn: /* mdoc(7) */ case REQ_nN: /* mdoc(7) */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case REQ_perc_A: /* mdoc(7) biblio stuff */ case REQ_perc_D: case REQ_perc_N: case REQ_perc_O: case REQ_perc_P: case REQ_perc_Q: case REQ_perc_V: c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case REQ_perc_B: case REQ_perc_J: case REQ_perc_R: case REQ_perc_T: c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; case REQ_UR: // ### FIXME { ignore_links=true; c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; // A parameter : means that we do not want an URL, not here and not until .UE ur_ignore=(!qstrcmp(h,":")); } else { // We cannot find the URL, assume : ur_ignore=true; h=0; } if (!ur_ignore && words>0) { out_html("<a href=\""); out_html(h); out_html("\">"); } c=newc; // Go to next line break; } case REQ_UE: // ### FIXME { c+=j; c = skip_till_newline(c); if (!ur_ignore) { out_html("</a>"); } ur_ignore=false; ignore_links=false; break; } case REQ_UN: // ### FIXME { c+=j; char* newc; h=fill_words(c, wordlist, &words, false, &newc); *h=0; if (words>0) { h=wordlist[0]; out_html("<a name=\">"); out_html(h); out_html("\" id=\""); out_html(h); out_html("\">"); } c=newc; break; } default: if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any mdoc(7) commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else c=skip_till_newline(c); break; } } } if (fillout) { out_html(NEWLINE); curpos++; } return c;} |
rc = (jint)gnome_vfs_mime_get_default_application(lparg0); | rc = (jint)gnome_vfs_mime_get_default_application((const char *)lparg0); | JNIEXPORT jint JNICALL GNOME_NATIVE(_1gnome_1vfs_1mime_1get_1default_1application) (JNIEnv *env, jclass that, jbyteArray arg0){ jbyte *lparg0=NULL; jint rc = 0; GNOME_NATIVE_ENTER(env, that, _1gnome_1vfs_1mime_1get_1default_1application_FUNC); if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; rc = (jint)gnome_vfs_mime_get_default_application(lparg0);fail: if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); GNOME_NATIVE_EXIT(env, that, _1gnome_1vfs_1mime_1get_1default_1application_FUNC); return rc;} |
kDebugError("Exiting on signal %d", sig); | kdDebug(1205) << "Exiting on signal " << sig << "\n"; | void signal_exit(int sig){ kDebugError("Exiting on signal %d", sig); kdesud_cleanup(); exit(1);} |
KApplication app( false, false ); | KApplication app( false ); | int KDE_EXPORT kdemain( int argc, char **argv ) { // KApplication is necessary to use other ioslaves putenv(strdup("SESSION_MANAGER=")); KCmdLineArgs::init(argc, argv, "kio_media", 0, 0, 0); KCmdLineArgs::addCmdLineOptions( options ); KApplication app( false, false ); // We want to be anonymous even if we use DCOP app.dcopClient()->attach(); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); MediaProtocol slave( args->arg(0), args->arg(1), args->arg(2) ); slave.dispatchLoop(); return 0; } |
info.exe_base = VG_PGROUNDUP(&_end); | static void main2(void){ int err, padfile; struct exeinfo info; extern char _end; int *esp; char buf[strlen(valgrind_lib) + sizeof(stage2) + 16]; info.exe_end = VG_PGROUNDDN(init_sp); // rounding down printf("info.exe_end = %p\n", info.exe_end);#ifdef HAVE_PIE info.exe_base = VG_ROUNDDN(info.exe_end - 0x02000000, 0x10000000); assert(info.exe_base >= VG_PGROUNDUP(&_end)); info.map_base = info.exe_base + 0x01000000 ;#else // If this system doesn't have PIE (position-independent executables), // we have to choose a hardwired location for stage2. info.exe_base = VG_PGROUNDUP(&_end); printf("info.exe_base = %p\n", info.exe_base); info.map_base = KICKSTART_BASE /* + 0x01000000 */; printf("info.map_base = %p\n", info.map_base);#endif info.argv = NULL; snprintf(buf, sizeof(buf), "%s/%s", valgrind_lib, stage2); printf("valgrind_lib = %s\n",valgrind_lib); err = do_exec(buf, &info); if (err != 0) { fprintf(stderr, "valgrind: failed to load %s: %s\n", buf, strerror(err)); exit(1); } /* Make sure stage2's dynamic linker can't tromp on the lower part of the address space. */ padfile = as_openpadfile(); as_pad(0, (void *)info.map_base, padfile); // map base is the start of our stuff printf("init sp : %x\n", init_sp); esp = fix_auxv(init_sp, &info, padfile); printf("after fix_auxb\n"); if (1) { printf("---------- launch stage 2 ----------\n"); printf("eip=%p esp=%p\n", (void *)info.init_eip, esp); foreach_map(prmap, /*dummy*/NULL); } VG_(debugLog)(1, "stage1", "main2(): starting stage2\n"); printf("jumping to stage 2 \n"); printf("esp : %x \n eip : %x\n",esp, info.init_eip); jump_and_switch_stacks( (Addr) esp, /* stack */ (Addr) info.init_eip /* Where to jump */ ); /*NOTREACHED*/ assert(0); } |
|
info.map_base = KICKSTART_BASE ; | info.map_base = KICKSTART_BASE + 0x01000000 ; | static void main2(void){ int err, padfile; struct exeinfo info; extern char _end; int *esp; char buf[strlen(valgrind_lib) + sizeof(stage2) + 16]; info.exe_end = VG_PGROUNDDN(init_sp); // rounding down printf("info.exe_end = %p\n", info.exe_end);#ifdef HAVE_PIE info.exe_base = VG_ROUNDDN(info.exe_end - 0x02000000, 0x10000000); assert(info.exe_base >= VG_PGROUNDUP(&_end)); info.map_base = info.exe_base + 0x01000000 ;#else // If this system doesn't have PIE (position-independent executables), // we have to choose a hardwired location for stage2. info.exe_base = VG_PGROUNDUP(&_end); printf("info.exe_base = %p\n", info.exe_base); info.map_base = KICKSTART_BASE /* + 0x01000000 */; printf("info.map_base = %p\n", info.map_base);#endif info.argv = NULL; snprintf(buf, sizeof(buf), "%s/%s", valgrind_lib, stage2); printf("valgrind_lib = %s\n",valgrind_lib); err = do_exec(buf, &info); if (err != 0) { fprintf(stderr, "valgrind: failed to load %s: %s\n", buf, strerror(err)); exit(1); } /* Make sure stage2's dynamic linker can't tromp on the lower part of the address space. */ padfile = as_openpadfile(); as_pad(0, (void *)info.map_base, padfile); // map base is the start of our stuff printf("init sp : %x\n", init_sp); esp = fix_auxv(init_sp, &info, padfile); printf("after fix_auxb\n"); if (1) { printf("---------- launch stage 2 ----------\n"); printf("eip=%p esp=%p\n", (void *)info.init_eip, esp); foreach_map(prmap, /*dummy*/NULL); } VG_(debugLog)(1, "stage1", "main2(): starting stage2\n"); printf("jumping to stage 2 \n"); printf("esp : %x \n eip : %x\n",esp, info.init_eip); jump_and_switch_stacks( (Addr) esp, /* stack */ (Addr) info.init_eip /* Where to jump */ ); /*NOTREACHED*/ assert(0); } |
if (off < payload.length()) | if ((unsigned)off < payload.length()) | virtual void decode_payload() { int off = 0; payload.copy(off, sizeof(pcid), (char*)&pcid); off += sizeof(pcid); if (off < payload.length()) payload.splice( off, payload.length()-off, &osd_cluster_state); } |
for (list<CFile*>::iterator it = fh_list.begin(); it != fh_list.end(); it++) delete *it; | ~CInodeExport() { for (list<CFile*>::iterator it = fh_list.begin(); it != fh_list.end(); it++) delete *it; } |
|
void encode_state(crope& r) { r.append((char*)&type, sizeof(char)); r.append((char*)&state, sizeof(state)); r.append((char*)&mode, sizeof(mode)); r.append((char*)&nread, sizeof(nread)); r.append((char*)&nwrite, sizeof(nwrite)); | void encode_state(bufferlist& bl) { bl.append((char*)&type, sizeof(char)); bl.append((char*)&state, sizeof(state)); bl.append((char*)&mode, sizeof(mode)); bl.append((char*)&nread, sizeof(nread)); bl.append((char*)&nwrite, sizeof(nwrite)); | void encode_state(crope& r) { r.append((char*)&type, sizeof(char)); r.append((char*)&state, sizeof(state)); r.append((char*)&mode, sizeof(mode)); r.append((char*)&nread, sizeof(nread)); r.append((char*)&nwrite, sizeof(nwrite)); //r.append((char*)&req_read, sizeof(req_read)); //r.append((char*)&req_write, sizeof(req_write)); int n = gather_set.size(); r.append((char*)&n, sizeof(n)); for (set<int>::iterator it = gather_set.begin(); it != gather_set.end(); it++) { n = *it; r.append((char*)&n, sizeof(n)); } } |
int n = gather_set.size(); r.append((char*)&n, sizeof(n)); for (set<int>::iterator it = gather_set.begin(); it != gather_set.end(); it++) { n = *it; r.append((char*)&n, sizeof(n)); } | _encode(gather_set, bl); | void encode_state(crope& r) { r.append((char*)&type, sizeof(char)); r.append((char*)&state, sizeof(state)); r.append((char*)&mode, sizeof(mode)); r.append((char*)&nread, sizeof(nread)); r.append((char*)&nwrite, sizeof(nwrite)); //r.append((char*)&req_read, sizeof(req_read)); //r.append((char*)&req_write, sizeof(req_write)); int n = gather_set.size(); r.append((char*)&n, sizeof(n)); for (set<int>::iterator it = gather_set.begin(); it != gather_set.end(); it++) { n = *it; r.append((char*)&n, sizeof(n)); } } |
struct sigaction act; memset(&act,0,sizeof(act)); act.sa_handler = ripper; act.sa_flags = 0 #ifdef SA_NOCLDSTOP | SA_NOCLDSTOP #endif #ifdef SA_RESTART | SA_RESTART #endif ; sigaction(SIGCLD,&act,NULL); | int kdemain( int argc, char **argv ){ KInstance instance("fish"); myDebug( << "*** Starting fish " << endl); if (argc != 4) { myDebug( << "Usage: fish protocol domain-socket1 domain-socket2" << endl); exit(-1); } fishProtocol slave(argv[2], argv[3]); slave.dispatchLoop(); myDebug( << "*** fish Done" << endl); return 0;} |
|
if (arg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0); | JNIEXPORT void JNICALL OS_NATIVE(gtk_1editable_1insert_1text) (JNIEnv *env, jclass that, jint arg0, jbyteArray arg1, jint arg2, jintArray arg3){ jbyte *lparg1=NULL; jint *lparg3=NULL; NATIVE_ENTER(env, that, "gtk_1editable_1insert_1text\n") if (arg1) lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL); if (arg3) lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL); gtk_editable_insert_text((GtkEditable *)arg0, (gchar *)lparg1, (gint)arg2, (gint *)lparg3); if (arg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); if (arg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0); NATIVE_EXIT(env, that, "gtk_1editable_1insert_1text\n")} |
|
if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); | JNIEXPORT jboolean JNICALL OS_NATIVE(gtk_1init_1check) (JNIEnv *env, jclass that, jintArray arg0, jintArray arg1){ jint *lparg0=NULL; jint *lparg1=NULL; jboolean rc; NATIVE_ENTER(env, that, "gtk_1init_1check\n") if (arg0) lparg0 = (*env)->GetIntArrayElements(env, arg0, NULL); if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); rc = (jboolean)gtk_init_check((int *)lparg0, (char ***)lparg1); if (arg0) (*env)->ReleaseIntArrayElements(env, arg0, lparg0, 0); if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); NATIVE_EXIT(env, that, "gtk_1init_1check\n") return rc;} |
|
if (arg2) (*env)->ReleaseDoubleArrayElements(env, arg2, lparg2, 0); | JNIEXPORT jboolean JNICALL OS_NATIVE(gdk_1event_1get_1coords) (JNIEnv *env, jclass that, jint arg0, jdoubleArray arg1, jdoubleArray arg2){ jdouble *lparg1=NULL; jdouble *lparg2=NULL; jboolean rc; NATIVE_ENTER(env, that, "gdk_1event_1get_1coords\n") if (arg1) lparg1 = (*env)->GetDoubleArrayElements(env, arg1, NULL); if (arg2) lparg2 = (*env)->GetDoubleArrayElements(env, arg2, NULL); rc = (jboolean)gdk_event_get_coords((GdkEvent *)arg0, (gdouble *)lparg1, (gdouble *)lparg2); if (arg1) (*env)->ReleaseDoubleArrayElements(env, arg1, lparg1, 0); if (arg2) (*env)->ReleaseDoubleArrayElements(env, arg2, lparg2, 0); NATIVE_EXIT(env, that, "gdk_1event_1get_1coords\n") return rc;} |
|
if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); | JNIEXPORT jint JNICALL OS_NATIVE(gdk_1window_1at_1pointer) (JNIEnv *env, jclass that, jintArray arg0, jintArray arg1){ jint *lparg0=NULL; jint *lparg1=NULL; jint rc; NATIVE_ENTER(env, that, "gdk_1window_1at_1pointer\n") if (arg0) lparg0 = (*env)->GetIntArrayElements(env, arg0, NULL); if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); rc = (jint)gdk_window_at_pointer((gint *)lparg0, (gint *)lparg1); if (arg0) (*env)->ReleaseIntArrayElements(env, arg0, lparg0, 0); if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); NATIVE_EXIT(env, that, "gdk_1window_1at_1pointer\n") return rc;} |
|
if (arg0) lparg0 = getGtkTargetPairFields(env, arg0, &_arg0); | if (arg0) lparg0 = &_arg0; | JNIEXPORT void JNICALL Java_org_eclipse_swt_internal_gtk_OS_memmove__Lorg_eclipse_swt_internal_gtk_GtkTargetPair_2II (JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2){ GtkTargetPair _arg0, *lparg0=NULL; DEBUG_CALL("memmove__Lorg_eclipse_swt_internal_gtk_GtkTargetPair_2II\n") if (arg0) lparg0 = getGtkTargetPairFields(env, arg0, &_arg0); memmove(lparg0, arg1, arg2); if (arg0) setGtkTargetPairFields(env, arg0, lparg0);} |
setPixmap( 0, SmallIcon( open ? "contents" : "contents2" ) ); | if ( open && childCount() > 0 ) setPixmap( 0, SmallIcon( "contents" ) ); else setPixmap( 0, SmallIcon( "contents2" ) ); | void TOCChapterItem::setOpen( bool open ){ TOCItem::setOpen( open ); setPixmap( 0, SmallIcon( open ? "contents" : "contents2" ) );} |
if (arg6) (*env)->ReleaseIntArrayElements(env, arg6, lparg6, 0); if (arg7) (*env)->ReleaseIntArrayElements(env, arg7, lparg7, 0); | JNIEXPORT jint JNICALL OS_NATIVE(ATSUCreateTextLayoutWithTextPtr) (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3, jint arg4, jintArray arg5, jintArray arg6, jintArray arg7){ jint *lparg5=NULL; jint *lparg6=NULL; jint *lparg7=NULL; jint rc; NATIVE_ENTER(env, that, "ATSUCreateTextLayoutWithTextPtr\n") if (arg5) lparg5 = (*env)->GetIntArrayElements(env, arg5, NULL); if (arg6) lparg6 = (*env)->GetIntArrayElements(env, arg6, NULL); if (arg7) lparg7 = (*env)->GetIntArrayElements(env, arg7, NULL); rc = (jint)ATSUCreateTextLayoutWithTextPtr((ConstUniCharArrayPtr)arg0, arg1, arg2, arg3, arg4, (const UniCharCount *)lparg5, (ATSUStyle *)lparg6, (ATSUTextLayout *)lparg7); if (arg5) (*env)->ReleaseIntArrayElements(env, arg5, lparg5, 0); if (arg6) (*env)->ReleaseIntArrayElements(env, arg6, lparg6, 0); if (arg7) (*env)->ReleaseIntArrayElements(env, arg7, lparg7, 0); NATIVE_EXIT(env, that, "ATSUCreateTextLayoutWithTextPtr\n") return rc;} |
|
if (arg8) (*env)->ReleaseIntArrayElements(env, arg8, lparg8, 0); | JNIEXPORT jint JNICALL OS_NATIVE(ATSUGetGlyphBounds__IIIIISILorg_eclipse_swt_internal_carbon_ATSTrapezoid_2_3I) (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3, jint arg4, jshort arg5, jint arg6, jobject arg7, jintArray arg8){ ATSTrapezoid _arg7, *lparg7=NULL; jint *lparg8=NULL; jint rc; NATIVE_ENTER(env, that, "ATSUGetGlyphBounds__IIIIISILorg_eclipse_swt_internal_carbon_ATSTrapezoid_2_3I\n") if (arg7) lparg7 = getATSTrapezoidFields(env, arg7, &_arg7); if (arg8) lparg8 = (*env)->GetIntArrayElements(env, arg8, NULL); rc = (jint)ATSUGetGlyphBounds((ATSUTextLayout)arg0, (ATSUTextMeasurement)arg1, (ATSUTextMeasurement)arg2, (UniCharArrayOffset)arg3, arg4, arg5, arg6, (ATSTrapezoid *)lparg7, (ItemCount *)lparg8); if (arg7) setATSTrapezoidFields(env, arg7, lparg7); if (arg8) (*env)->ReleaseIntArrayElements(env, arg8, lparg8, 0); NATIVE_EXIT(env, that, "ATSUGetGlyphBounds__IIIIISILorg_eclipse_swt_internal_carbon_ATSTrapezoid_2_3I\n") return rc;} |
|
if (arg5) (*env)->ReleaseIntArrayElements(env, arg5, lparg5, 0); | JNIEXPORT jint JNICALL OS_NATIVE(ATSUGetSoftLineBreaks) (JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2, jint arg3, jintArray arg4, jintArray arg5){ jint *lparg4=NULL; jint *lparg5=NULL; jint rc; NATIVE_ENTER(env, that, "ATSUGetSoftLineBreaks\n") if (arg4) lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL); if (arg5) lparg5 = (*env)->GetIntArrayElements(env, arg5, NULL); rc = (jint)ATSUGetSoftLineBreaks((ATSUTextLayout)arg0, (UniCharArrayOffset)arg1, (UniCharCount)arg2, (ItemCount)arg3, (UniCharArrayOffset *)lparg4, (ItemCount *)lparg5); if (arg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); if (arg5) (*env)->ReleaseIntArrayElements(env, arg5, lparg5, 0); NATIVE_EXIT(env, that, "ATSUGetSoftLineBreaks\n") return rc;} |
|
if (arg3) (*env)->ReleaseShortArrayElements(env, arg3, lparg3, 0); | JNIEXPORT jint JNICALL OS_NATIVE(ATSUSetFontFeatures) (JNIEnv *env, jclass that, jint arg0, jint arg1, jshortArray arg2, jshortArray arg3){ jshort *lparg2=NULL; jshort *lparg3=NULL; jint rc; NATIVE_ENTER(env, that, "ATSUSetFontFeatures\n") if (arg2) lparg2 = (*env)->GetShortArrayElements(env, arg2, NULL); if (arg3) lparg3 = (*env)->GetShortArrayElements(env, arg3, NULL); rc = (jint)ATSUSetFontFeatures((ATSUStyle)arg0, (ItemCount)arg1, (const ATSUFontFeatureType *)lparg2, (const ATSUFontFeatureSelector *)lparg3); if (arg2) (*env)->ReleaseShortArrayElements(env, arg2, lparg2, 0); if (arg3) (*env)->ReleaseShortArrayElements(env, arg3, lparg3, 0); NATIVE_EXIT(env, that, "ATSUSetFontFeatures\n") return rc;} |
|
if (arg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0); if (arg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); | JNIEXPORT jint JNICALL OS_NATIVE(ATSUSetLayoutControls) (JNIEnv *env, jclass that, jint arg0, jint arg1, jintArray arg2, jintArray arg3, jintArray arg4){ jint *lparg2=NULL; jint *lparg3=NULL; jint *lparg4=NULL; jint rc; NATIVE_ENTER(env, that, "ATSUSetLayoutControls\n") if (arg2) lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL); if (arg3) lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL); if (arg4) lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL); rc = (jint)ATSUSetLayoutControls((ATSUTextLayout)arg0, (ItemCount)arg1, (ATSUAttributeTag *)lparg2, (ByteCount *)lparg3, (ATSUAttributeValuePtr *)lparg4); if (arg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); if (arg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0); if (arg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); NATIVE_EXIT(env, that, "ATSUSetLayoutControls\n") return rc;} |
|
if (arg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); | JNIEXPORT jint JNICALL OS_NATIVE(GetDataBrowserSelectionAnchor) (JNIEnv *env, jclass that, jint arg0, jintArray arg1, jintArray arg2){ jint *lparg1=NULL; jint *lparg2=NULL; jint rc; NATIVE_ENTER(env, that, "GetDataBrowserSelectionAnchor\n") if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); if (arg2) lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL); rc = (jint)GetDataBrowserSelectionAnchor((ControlRef)arg0, (UInt32 *)lparg1, (UInt32 *)lparg2); if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); if (arg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); NATIVE_EXIT(env, that, "GetDataBrowserSelectionAnchor\n") return rc;} |
|
if (arg3) (*env)->ReleaseByteArrayElements(env, arg3, lparg3, 0); | JNIEXPORT jint JNICALL OS_NATIVE(GetScrapFlavorData) (JNIEnv *env, jclass that, jint arg0, jint arg1, jintArray arg2, jbyteArray arg3){ jint *lparg2=NULL; jbyte *lparg3=NULL; jint rc; NATIVE_ENTER(env, that, "GetScrapFlavorData\n") if (arg2) lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL); if (arg3) lparg3 = (*env)->GetByteArrayElements(env, arg3, NULL); rc = (jint)GetScrapFlavorData((ScrapRef)arg0, (ScrapFlavorType)arg1, (Size *)lparg2, (void *)lparg3); if (arg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); if (arg3) (*env)->ReleaseByteArrayElements(env, arg3, lparg3, 0); NATIVE_EXIT(env, that, "GetScrapFlavorData\n") return rc;} |
|
if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); | if (arg1) lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL); | JNIEXPORT void JNICALL OS_NATIVE(memcpy__I_3II) (JNIEnv *env, jclass that, jint arg0, jintArray arg1, jint arg2){ jint *lparg1=NULL; NATIVE_ENTER(env, that, "memcpy__I_3II\n") if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); memcpy((void *)arg0, (const void *)lparg1, (size_t)arg2); if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, JNI_ABORT); NATIVE_EXIT(env, that, "memcpy__I_3II\n")} |
if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, JNI_ABORT); | if (arg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); | JNIEXPORT void JNICALL OS_NATIVE(memcpy__I_3II) (JNIEnv *env, jclass that, jint arg0, jintArray arg1, jint arg2){ jint *lparg1=NULL; NATIVE_ENTER(env, that, "memcpy__I_3II\n") if (arg1) lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL); memcpy((void *)arg0, (const void *)lparg1, (size_t)arg2); if (arg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, JNI_ABORT); NATIVE_EXIT(env, that, "memcpy__I_3II\n")} |
if (arg0) lparg0 = (*env)->GetCharArrayElements(env, arg0, NULL); if (arg1) lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL); | if (arg0) lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL); if (arg1) lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL); | JNIEXPORT void JNICALL OS_NATIVE(memcpy___3C_3BI) (JNIEnv *env, jclass that, jcharArray arg0, jbyteArray arg1, jint arg2){ jchar *lparg0=NULL; jbyte *lparg1=NULL; NATIVE_ENTER(env, that, "memcpy___3C_3BI\n") if (arg0) lparg0 = (*env)->GetCharArrayElements(env, arg0, NULL); if (arg1) lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL); memcpy((void *)lparg0, (const void *)lparg1, (size_t)arg2); if (arg0) (*env)->ReleaseCharArrayElements(env, arg0, lparg0, 0); if (arg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, JNI_ABORT); NATIVE_EXIT(env, that, "memcpy___3C_3BI\n")} |
if (arg0) (*env)->ReleaseCharArrayElements(env, arg0, lparg0, 0); if (arg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, JNI_ABORT); | if (arg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); if (arg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); | JNIEXPORT void JNICALL OS_NATIVE(memcpy___3C_3BI) (JNIEnv *env, jclass that, jcharArray arg0, jbyteArray arg1, jint arg2){ jchar *lparg0=NULL; jbyte *lparg1=NULL; NATIVE_ENTER(env, that, "memcpy___3C_3BI\n") if (arg0) lparg0 = (*env)->GetCharArrayElements(env, arg0, NULL); if (arg1) lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL); memcpy((void *)lparg0, (const void *)lparg1, (size_t)arg2); if (arg0) (*env)->ReleaseCharArrayElements(env, arg0, lparg0, 0); if (arg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, JNI_ABORT); NATIVE_EXIT(env, that, "memcpy___3C_3BI\n")} |
return new Plugin(theQGisAppPointer, theQgisInterfacePointer); | return new QgsScaleBarPlugin(theQGisAppPointer, theQgisInterfacePointer); | QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer){ return new Plugin(theQGisAppPointer, theQgisInterfacePointer);} |
CFile *f, | Capability& cap, | MClientFileCaps(CInode *in, CFile *f, bool need_ack, int new_mds = -1) : Message(MSG_CLIENT_FILECAPS) { f->last_sent++; this->seq = f->last_sent; this->inode = in->inode; this->fh = f->fh; this->caps = f->pending_caps; this->need_ack = need_ack; this->mds = new_mds; } |
f->last_sent++; this->seq = f->last_sent; | this->seq = cap.get_last_seq(); this->caps = cap.pending(); | MClientFileCaps(CInode *in, CFile *f, bool need_ack, int new_mds = -1) : Message(MSG_CLIENT_FILECAPS) { f->last_sent++; this->seq = f->last_sent; this->inode = in->inode; this->fh = f->fh; this->caps = f->pending_caps; this->need_ack = need_ack; this->mds = new_mds; } |
this->fh = f->fh; this->caps = f->pending_caps; | MClientFileCaps(CInode *in, CFile *f, bool need_ack, int new_mds = -1) : Message(MSG_CLIENT_FILECAPS) { f->last_sent++; this->seq = f->last_sent; this->inode = in->inode; this->fh = f->fh; this->caps = f->pending_caps; this->need_ack = need_ack; this->mds = new_mds; } |
|
s.copy(off, sizeof(fh), (char*)&fh); off += sizeof(fh); | virtual void decode_payload(crope& s, int& off) { s.copy(off, sizeof(seq), (char*)&seq); off += sizeof(seq); s.copy(off, sizeof(inode), (char*)&inode); off += sizeof(inode); s.copy(off, sizeof(fh), (char*)&fh); off += sizeof(fh); s.copy(off, sizeof(mds), (char*)&mds); off += sizeof(mds); s.copy(off, sizeof(caps), (char*)&caps); off += sizeof(caps); s.copy(off, sizeof(need_ack), (char*)&need_ack); off += sizeof(need_ack); } |
|
s.copy(off, sizeof(client), (char*)&client); off += sizeof(client); | virtual void decode_payload(crope& s, int& off) { s.copy(off, sizeof(seq), (char*)&seq); off += sizeof(seq); s.copy(off, sizeof(inode), (char*)&inode); off += sizeof(inode); s.copy(off, sizeof(fh), (char*)&fh); off += sizeof(fh); s.copy(off, sizeof(mds), (char*)&mds); off += sizeof(mds); s.copy(off, sizeof(caps), (char*)&caps); off += sizeof(caps); s.copy(off, sizeof(need_ack), (char*)&need_ack); off += sizeof(need_ack); } |
|
prop = xmlGetNsProp(cur, | prop = xsltGetNsProp(cur, | xsltParseTemplateContent(xsltStylesheetPtr style, xsltTemplatePtr ret, xmlNodePtr template) { xmlNodePtr cur, delete; /* * This content comes from the stylesheet * For stylesheets, the set of whitespace-preserving * element names consists of just xsl:text. */ ret->elem = template; cur = template->children; delete = NULL; while (cur != NULL) { if (delete != NULL) {#ifdef WITH_XSLT_DEBUG_BLANKS xsltGenericDebug(xsltGenericDebugContext, "xsltParseTemplateContent: removing text\n");#endif xmlUnlinkNode(delete); xmlFreeNode(delete); delete = NULL; } if (IS_XSLT_ELEM(cur)) { if (IS_XSLT_NAME(cur, "text")) { if (cur->children != NULL) { xmlChar *prop; xmlNodePtr text = cur->children, next; int noesc = 0; prop = xmlGetNsProp(cur, (const xmlChar *)"disable-output-escaping", XSLT_NAMESPACE); if (prop != NULL) {#ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "Disable escaping: %s\n", text->content);#endif if (xmlStrEqual(prop, (const xmlChar *)"yes")) { noesc = 1; } else if (!xmlStrEqual(prop, (const xmlChar *)"no")){ xsltGenericError(xsltGenericErrorContext, "xslt:text: disable-output-escaping allow only yes or no\n"); style->warnings++; } xmlFree(prop); } while (text != NULL) { if (((text->type != XML_TEXT_NODE) && (text->type != XML_CDATA_SECTION_NODE)) || (text->next != NULL)) { xsltGenericError(xsltGenericErrorContext, "xsltParseTemplateContent: xslt:text content problem\n"); style->errors++; break; } if (noesc) text->name = xmlStringTextNoenc; text = text->next; } /* * replace xsl:text by the list of childs */ if (text == NULL) { text = cur->children; while (text != NULL) { next = text->next; xmlUnlinkNode(text); xmlAddPrevSibling(cur, text); text = next; } } } delete = cur; goto skip_children; } } else if ((cur->ns != NULL) && (style->nsDefs != NULL)) { if (xsltCheckExtPrefix(style, cur->ns->prefix)) { /* * okay this is an extension element compile it too */ xsltStylePreCompute(style, cur); } } /* * Skip to next node */ if (cur->children != NULL) { if (cur->children->type != XML_ENTITY_DECL) { cur = cur->children; continue; } }skip_children: if (cur->next != NULL) { cur = cur->next; continue; } do { cur = cur->parent; if (cur == NULL) break; if (cur == template) { cur = NULL; break; } if (cur->next != NULL) { cur = cur->next; break; } } while (cur != NULL); } if (delete != NULL) {#ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "xsltParseStylesheetTemplate: removing text\n");#endif xmlUnlinkNode(delete); xmlFreeNode(delete); delete = NULL; } /* * Skip the first params */ cur = template->children; while (cur != NULL) { if ((IS_XSLT_ELEM(cur)) && (!(IS_XSLT_NAME(cur, "param")))) break; cur = cur->next; } /* * Browse the remaining of the template */ while (cur != NULL) { if ((IS_XSLT_ELEM(cur)) && (IS_XSLT_NAME(cur, "param"))) { xmlNodePtr param = cur; cur = cur->next; xsltGenericError(xsltGenericErrorContext, "xsltParseStylesheetTop: ignoring misplaced param element\n"); style->warnings++; xmlUnlinkNode(param); xmlFreeNode(param); continue; } else break; cur = cur->next; } ret->content = template->children;} |
elements = xmlGetNsProp(cur, (const xmlChar *)"elements", XSLT_NAMESPACE); | elements = xsltGetNsProp(cur, (const xmlChar *)"elements", XSLT_NAMESPACE); | xsltParseStylesheetStripSpace(xsltStylesheetPtr style, xmlNodePtr cur) { xmlChar *elements; xmlChar *element, *end; if ((cur == NULL) || (style == NULL)) return; elements = xmlGetNsProp(cur, (const xmlChar *)"elements", XSLT_NAMESPACE); if (elements == NULL) { xsltGenericError(xsltGenericErrorContext, "xsltParseStylesheetStripSpace: missing elements attribute\n"); style->warnings++; return; } if (style->stripSpaces == NULL) style->stripSpaces = xmlHashCreate(10); if (style->stripSpaces == NULL) return; element = elements; while (*element != 0) { while (IS_BLANK(*element)) element++; if (*element == 0) break; end = element; while ((*end != 0) && (!IS_BLANK(*end))) end++; element = xmlStrndup(element, end - element); if (element) {#ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "add stripped space element %s\n", element);#endif if (xmlStrEqual(element, (const xmlChar *)"*")) { style->stripAll = 1; } else { xmlHashAddEntry(style->stripSpaces, element, (xmlChar *) "strip"); } xmlFree(element); } element = end; } xmlFree(elements);} |
prop = xmlGetNsProp(template, (const xmlChar *)"mode", XSLT_NAMESPACE); | prop = xsltGetNsProp(template, (const xmlChar *)"mode", XSLT_NAMESPACE); | xsltParseStylesheetTemplate(xsltStylesheetPtr style, xmlNodePtr template) { xsltTemplatePtr ret; xmlChar *prop; xmlChar *mode; xmlChar *modeURI; double priority; if (template == NULL) return; /* * Create and link the structure */ ret = xsltNewTemplate(); if (ret == NULL) return; ret->next = style->templates; style->templates = ret; ret->style = style; /* * Get arguments */ prop = xmlGetNsProp(template, (const xmlChar *)"mode", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *prefix = NULL; mode = xmlSplitQName2(prop, &prefix); if (mode != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(mode); mode = prop; modeURI = NULL; } else { modeURI = xmlStrdup(ns->href); xmlFree(prefix); xmlFree(prop); } } else { xmlFree(prop); modeURI = NULL; } } else { mode = prop; modeURI = NULL; }#ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "xslt:template: mode %s\n", mode);#endif } else { mode = NULL; modeURI = NULL; } prop = xmlGetNsProp(template, (const xmlChar *)"match", XSLT_NAMESPACE); if (prop != NULL) { if (ret->match != NULL) xmlFree(ret->match); ret->match = prop; } prop = xmlGetNsProp(template, (const xmlChar *)"priority", XSLT_NAMESPACE); if (prop != NULL) { priority = xmlXPathStringEvalNumber(prop); ret->priority = priority; xmlFree(prop); } prop = xmlGetNsProp(template, (const xmlChar *)"name", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *ncname; xmlChar *prefix = NULL; if (ret->name != NULL) xmlFree(ret->name); ret->name = NULL; if (ret->nameURI != NULL) xmlFree(ret->nameURI); ret->nameURI = NULL; ncname = xmlSplitQName2(prop, &prefix); if (ncname != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(ncname); ret->name = prop; } else { ret->nameURI = xmlStrdup(ns->href); ret->name = ncname; xmlFree(prefix); xmlFree(prop); } } else { ret->name = ncname; xmlFree(prop); } } else { ret->name = prop; } } /* * parse the content and register the pattern */ xsltParseTemplateContent(style, ret, template); xsltAddTemplate(style, ret, mode, modeURI); if (mode != NULL) xmlFree(mode); if (modeURI != NULL) xmlFree(modeURI);} |
prop = xmlGetNsProp(template, (const xmlChar *)"match", XSLT_NAMESPACE); | prop = xsltGetNsProp(template, (const xmlChar *)"match", XSLT_NAMESPACE); | xsltParseStylesheetTemplate(xsltStylesheetPtr style, xmlNodePtr template) { xsltTemplatePtr ret; xmlChar *prop; xmlChar *mode; xmlChar *modeURI; double priority; if (template == NULL) return; /* * Create and link the structure */ ret = xsltNewTemplate(); if (ret == NULL) return; ret->next = style->templates; style->templates = ret; ret->style = style; /* * Get arguments */ prop = xmlGetNsProp(template, (const xmlChar *)"mode", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *prefix = NULL; mode = xmlSplitQName2(prop, &prefix); if (mode != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(mode); mode = prop; modeURI = NULL; } else { modeURI = xmlStrdup(ns->href); xmlFree(prefix); xmlFree(prop); } } else { xmlFree(prop); modeURI = NULL; } } else { mode = prop; modeURI = NULL; }#ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "xslt:template: mode %s\n", mode);#endif } else { mode = NULL; modeURI = NULL; } prop = xmlGetNsProp(template, (const xmlChar *)"match", XSLT_NAMESPACE); if (prop != NULL) { if (ret->match != NULL) xmlFree(ret->match); ret->match = prop; } prop = xmlGetNsProp(template, (const xmlChar *)"priority", XSLT_NAMESPACE); if (prop != NULL) { priority = xmlXPathStringEvalNumber(prop); ret->priority = priority; xmlFree(prop); } prop = xmlGetNsProp(template, (const xmlChar *)"name", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *ncname; xmlChar *prefix = NULL; if (ret->name != NULL) xmlFree(ret->name); ret->name = NULL; if (ret->nameURI != NULL) xmlFree(ret->nameURI); ret->nameURI = NULL; ncname = xmlSplitQName2(prop, &prefix); if (ncname != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(ncname); ret->name = prop; } else { ret->nameURI = xmlStrdup(ns->href); ret->name = ncname; xmlFree(prefix); xmlFree(prop); } } else { ret->name = ncname; xmlFree(prop); } } else { ret->name = prop; } } /* * parse the content and register the pattern */ xsltParseTemplateContent(style, ret, template); xsltAddTemplate(style, ret, mode, modeURI); if (mode != NULL) xmlFree(mode); if (modeURI != NULL) xmlFree(modeURI);} |
prop = xmlGetNsProp(template, (const xmlChar *)"priority", XSLT_NAMESPACE); | prop = xsltGetNsProp(template, (const xmlChar *)"priority", XSLT_NAMESPACE); | xsltParseStylesheetTemplate(xsltStylesheetPtr style, xmlNodePtr template) { xsltTemplatePtr ret; xmlChar *prop; xmlChar *mode; xmlChar *modeURI; double priority; if (template == NULL) return; /* * Create and link the structure */ ret = xsltNewTemplate(); if (ret == NULL) return; ret->next = style->templates; style->templates = ret; ret->style = style; /* * Get arguments */ prop = xmlGetNsProp(template, (const xmlChar *)"mode", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *prefix = NULL; mode = xmlSplitQName2(prop, &prefix); if (mode != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(mode); mode = prop; modeURI = NULL; } else { modeURI = xmlStrdup(ns->href); xmlFree(prefix); xmlFree(prop); } } else { xmlFree(prop); modeURI = NULL; } } else { mode = prop; modeURI = NULL; }#ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "xslt:template: mode %s\n", mode);#endif } else { mode = NULL; modeURI = NULL; } prop = xmlGetNsProp(template, (const xmlChar *)"match", XSLT_NAMESPACE); if (prop != NULL) { if (ret->match != NULL) xmlFree(ret->match); ret->match = prop; } prop = xmlGetNsProp(template, (const xmlChar *)"priority", XSLT_NAMESPACE); if (prop != NULL) { priority = xmlXPathStringEvalNumber(prop); ret->priority = priority; xmlFree(prop); } prop = xmlGetNsProp(template, (const xmlChar *)"name", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *ncname; xmlChar *prefix = NULL; if (ret->name != NULL) xmlFree(ret->name); ret->name = NULL; if (ret->nameURI != NULL) xmlFree(ret->nameURI); ret->nameURI = NULL; ncname = xmlSplitQName2(prop, &prefix); if (ncname != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(ncname); ret->name = prop; } else { ret->nameURI = xmlStrdup(ns->href); ret->name = ncname; xmlFree(prefix); xmlFree(prop); } } else { ret->name = ncname; xmlFree(prop); } } else { ret->name = prop; } } /* * parse the content and register the pattern */ xsltParseTemplateContent(style, ret, template); xsltAddTemplate(style, ret, mode, modeURI); if (mode != NULL) xmlFree(mode); if (modeURI != NULL) xmlFree(modeURI);} |
prop = xmlGetNsProp(template, (const xmlChar *)"name", XSLT_NAMESPACE); | prop = xsltGetNsProp(template, (const xmlChar *)"name", XSLT_NAMESPACE); | xsltParseStylesheetTemplate(xsltStylesheetPtr style, xmlNodePtr template) { xsltTemplatePtr ret; xmlChar *prop; xmlChar *mode; xmlChar *modeURI; double priority; if (template == NULL) return; /* * Create and link the structure */ ret = xsltNewTemplate(); if (ret == NULL) return; ret->next = style->templates; style->templates = ret; ret->style = style; /* * Get arguments */ prop = xmlGetNsProp(template, (const xmlChar *)"mode", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *prefix = NULL; mode = xmlSplitQName2(prop, &prefix); if (mode != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(mode); mode = prop; modeURI = NULL; } else { modeURI = xmlStrdup(ns->href); xmlFree(prefix); xmlFree(prop); } } else { xmlFree(prop); modeURI = NULL; } } else { mode = prop; modeURI = NULL; }#ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "xslt:template: mode %s\n", mode);#endif } else { mode = NULL; modeURI = NULL; } prop = xmlGetNsProp(template, (const xmlChar *)"match", XSLT_NAMESPACE); if (prop != NULL) { if (ret->match != NULL) xmlFree(ret->match); ret->match = prop; } prop = xmlGetNsProp(template, (const xmlChar *)"priority", XSLT_NAMESPACE); if (prop != NULL) { priority = xmlXPathStringEvalNumber(prop); ret->priority = priority; xmlFree(prop); } prop = xmlGetNsProp(template, (const xmlChar *)"name", XSLT_NAMESPACE); if (prop != NULL) { xmlChar *ncname; xmlChar *prefix = NULL; if (ret->name != NULL) xmlFree(ret->name); ret->name = NULL; if (ret->nameURI != NULL) xmlFree(ret->nameURI); ret->nameURI = NULL; ncname = xmlSplitQName2(prop, &prefix); if (ncname != NULL) { if (prefix != NULL) { xmlNsPtr ns; ns = xmlSearchNs(template->doc, template, prefix); if (ns == NULL) { xsltGenericError(xsltGenericErrorContext, "no namespace bound to prefix %s\n", prefix); style->warnings++; xmlFree(prefix); xmlFree(ncname); ret->name = prop; } else { ret->nameURI = xmlStrdup(ns->href); ret->name = ncname; xmlFree(prefix); xmlFree(prop); } } else { ret->name = ncname; xmlFree(prop); } } else { ret->name = prop; } } /* * parse the content and register the pattern */ xsltParseTemplateContent(style, ret, template); xsltAddTemplate(style, ret, mode, modeURI); if (mode != NULL) xmlFree(mode); if (modeURI != NULL) xmlFree(modeURI);} |
const char* appName() const { return m_aboutData->appName(); }; | virtual QCString appName() const { return m_aboutData->appName(); }; | const char* appName() const { return m_aboutData->appName(); }; |
if (arg0) lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL); | JNIEXPORT void JNICALL OS_NATIVE(MoveMemory___3BLorg_eclipse_swt_internal_win32_ACCEL_2I) (JNIEnv *env, jclass that, jbyteArray arg0, jobject arg1, jint arg2){ jbyte *lparg0=NULL; ACCEL _arg1, *lparg1=NULL; NATIVE_ENTER(env, that, "MoveMemory___3BLorg_eclipse_swt_internal_win32_ACCEL_2I\n") if (arg0) lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL); if (arg1) lparg1 = getACCELFields(env, arg1, &_arg1); MoveMemory((PVOID)lparg0, (CONST VOID *)lparg1, arg2); if (arg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); NATIVE_EXIT(env, that, "MoveMemory___3BLorg_eclipse_swt_internal_win32_ACCEL_2I\n")} |
|
if (arg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); | if (arg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); | JNIEXPORT void JNICALL OS_NATIVE(MoveMemory___3BLorg_eclipse_swt_internal_win32_ACCEL_2I) (JNIEnv *env, jclass that, jbyteArray arg0, jobject arg1, jint arg2){ jbyte *lparg0=NULL; ACCEL _arg1, *lparg1=NULL; NATIVE_ENTER(env, that, "MoveMemory___3BLorg_eclipse_swt_internal_win32_ACCEL_2I\n") if (arg0) lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL); if (arg1) lparg1 = getACCELFields(env, arg1, &_arg1); MoveMemory((PVOID)lparg0, (CONST VOID *)lparg1, arg2); if (arg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); NATIVE_EXIT(env, that, "MoveMemory___3BLorg_eclipse_swt_internal_win32_ACCEL_2I\n")} |
ThumbCreator *new_creator() | KDE_EXPORT ThumbCreator *new_creator() | ThumbCreator *new_creator() { return new DjVuCreator; } |
if (impact > 0.0 && safety1 == INESSENTIAL && is_self_atari(tt, board[dragona])) impact = 0.0; | connection_value(int dragona, int dragonb, int tt, float margin){ int ai = I(dragona); int aj = J(dragona); int bi = I(dragonb); int bj = J(dragonb); int safety1 = DRAGON2(ai, aj).safety; int safety2 = DRAGON2(bi, bj).safety; int true_genus1 = 2 * DRAGON2(ai, aj).genus + DRAGON2(ai, aj).heyes; int true_genus2 = 2 * DRAGON2(bi, bj).genus + DRAGON2(bi, bj).heyes; float impact; /* If the connected dragon gets sufficient eyespace to live on its * own, although neither of the unconnected ones did, we simulate * this by upgrading the safety of the second dragon to ALIVE. */ if (true_genus1 < 4 && true_genus2 < 4) { if (true_genus1 + true_genus2 >= 4 || (true_genus1 + true_genus2 >= 3 && (DRAGON2(ai, aj).heye == tt || DRAGON2(bi, bj).heye == tt))) safety2 = ALIVE; } /* If the b dragon is critical but has genus 0 and no moyo, we * assume it doesn't help dragon a to connect to b. */ if (safety2 == CRITICAL && true_genus2 == 0 && DRAGON2(bi, bj).moyo == 0) return 0.0; /* When scoring, we want to be restrictive with reinforcement moves * inside own territory. Thus if both dragons are strongly alive or * invincible, or if one is and the other is alive, no bonus is * awarded. * * Notice that this requires that the territorial value is computed * before the strategical value. */ if (doing_scoring && move[tt].territorial_value < 0.0) { if (safety1 == ALIVE && (safety2 == STRONGLY_ALIVE || safety2 == INVINCIBLE)) return 0.0; if ((safety1 == STRONGLY_ALIVE || safety1 == INVINCIBLE) && (safety2 == ALIVE || safety2 == STRONGLY_ALIVE || safety2 == INVINCIBLE)) return 0.0; } if (doing_scoring || margin < 0.0) impact = impact_values[safety1][safety2]; else if (margin > 20.0) impact = cautious_impact_values[safety1][safety2]; else impact = 0.05*margin*cautious_impact_values[safety1][safety2] + (1-0.05*margin)*impact_values[safety1][safety2]; return impact * 2.0 * dragon[ai][aj].effective_size;} |
|
if (sgf_dump) sgffile_write_line(")\n"); else if (sgf_dumptree) { | if (sgf_dumptree) { | popgo(){ stackp--; if (showstack) gprintf("<= *** STACK after pop: %d\n", stackp); undo_move(); memcpy(&hashdata, &(hashdata_stack[stackp]), sizeof(hashdata)); if (sgf_dump) sgffile_write_line(")\n"); else if (sgf_dumptree) { sgf_dumptree->lastnode = sgf_dumptree->lastnode->parent; /* After tryko() we need to undo two pass nodes too. Since we have * no other way to identify ko moves, we skip all pass nodes. */ while (is_pass_node(sgf_dumptree->lastnode, board_size)) sgf_dumptree->lastnode = sgf_dumptree->lastnode->parent; }} |
QString url="devices:/"+(*it); ++it; | ++it; QString url="devices:/"+(*it); | void DevicesProtocol::listRoot(){ KIO::UDSEntry entry; uint count; QStringList list=deviceList(); count=0; for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { if ((*it)=="!!!ERROR!!!") { error(KIO::ERR_SLAVE_DEFINED,i18n("The KDE mountwatcher is not running. Please activate it in Control Center->KDE Components->Service Manager, if you want to use the devices:/ protocol")); return; }// FIXME: look for the real ending QString url="devices:/"+(*it); ++it; QString name=*it; ++it; ++it; ++it; QString type=*it; ++it; ++it; createFileEntry(entry,name,url,type); listEntry(entry,false); count++; } totalSize(count); listEntry(entry, true); // Jobs entry // finish finished();} |
QString path = url.path(); | QString path = url.encodedPathAndQuery(); | void DevicesProtocol::mountAndRedirect(const KURL& url){ QString device; QString path = url.path(); int i = path.find('/', 1); if (i > 0) { device = path.mid(1, i-1); path = path.mid(i+1); } else { device = path.mid(1); path = QString::null; } QStringList info = deviceInfo(device); if (info.empty()) { error(KIO::ERR_SLAVE_DEFINED,i18n("Unknown device %1").arg(url.fileName())); return; } QStringList::Iterator it=info.begin(); if (it!=info.end()) { QString device=*it; ++it; if (it!=info.end()) { ++it; ++it; if (it!=info.end()) { QString mp=*it; ++it;++it; if (it!=info.end()) { bool mounted=((*it)=="true"); if (!mounted) { if (!mp.startsWith("file:/")) { error(KIO::ERR_SLAVE_DEFINED,i18n("Device not accessible") +mp); return; } KProcess *proc = new KProcess; *proc << "kio_devices_mounthelper"; *proc << "-m" << url.url(); proc->start(KProcess::Block); int ec = 0; if (proc->normalExit()) ec = proc->exitStatus(); delete proc; if (ec) { error(KIO::ERR_SLAVE_DEFINED,i18n("Device not mounted")); return; } } KURL newUrl(mp); if (!path.isEmpty()) newUrl.cd(path); redirection(newUrl); finished(); return; } } } } error(KIO::ERR_SLAVE_DEFINED,i18n("Illegal data received")); return;} |
QStringList info = deviceInfo(device); | QStringList info = deviceInfo(KURL::decode_string(device)); | void DevicesProtocol::mountAndRedirect(const KURL& url){ QString device; QString path = url.path(); int i = path.find('/', 1); if (i > 0) { device = path.mid(1, i-1); path = path.mid(i+1); } else { device = path.mid(1); path = QString::null; } QStringList info = deviceInfo(device); if (info.empty()) { error(KIO::ERR_SLAVE_DEFINED,i18n("Unknown device %1").arg(url.fileName())); return; } QStringList::Iterator it=info.begin(); if (it!=info.end()) { QString device=*it; ++it; if (it!=info.end()) { ++it; ++it; if (it!=info.end()) { QString mp=*it; ++it;++it; if (it!=info.end()) { bool mounted=((*it)=="true"); if (!mounted) { if (!mp.startsWith("file:/")) { error(KIO::ERR_SLAVE_DEFINED,i18n("Device not accessible") +mp); return; } KProcess *proc = new KProcess; *proc << "kio_devices_mounthelper"; *proc << "-m" << url.url(); proc->start(KProcess::Block); int ec = 0; if (proc->normalExit()) ec = proc->exitStatus(); delete proc; if (ec) { error(KIO::ERR_SLAVE_DEFINED,i18n("Device not mounted")); return; } } KURL newUrl(mp); if (!path.isEmpty()) newUrl.cd(path); redirection(newUrl); finished(); return; } } } } error(KIO::ERR_SLAVE_DEFINED,i18n("Illegal data received")); return;} |
UWord w = (irusr ? VKI_R_OK : 0) | (iwusr ? VKI_W_OK : 0) | (ixusr ? VKI_X_OK : 0); | Int VG_(access) ( HChar* path, Bool irusr, Bool iwusr, Bool ixusr ){#if defined(VGO_linux) /* Very annoyingly, I cannot find any definition for R_OK et al in the kernel interfaces. Therefore I reluctantly resort to hardwiring in these magic numbers that I determined by experimentation. */ UWord w = (irusr ? 4/*R_OK*/ : 0) | (iwusr ? 2/*W_OK*/ : 0) | (ixusr ? 1/*X_OK*/ : 0); SysRes res = VG_(do_syscall2)(__NR_access, (UWord)path, w); return res.isError ? 1 : res.val;#else# error "Don't know how to do VG_(access) on this OS"#endif} |
|
CARD8 tmp; tmp = inb(pVesa->ioBase + VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET); | (void) inb(pVesa->ioBase + VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET); | WriteAttr(VESAPtr pVesa, int index, int value){ CARD8 tmp; tmp = inb(pVesa->ioBase + VGA_IOBASE_COLOR + VGA_IN_STAT_1_OFFSET); index |= 0x20; outb(pVesa->ioBase + VGA_ATTR_INDEX, index); outb(pVesa->ioBase + VGA_ATTR_DATA_W, value);} |
if (arg1) setXClientMessageEventFields(env, arg1, lparg1); | JNIEXPORT void JNICALL OS_NATIVE(memmove__ILorg_eclipse_swt_internal_motif_XClientMessageEvent_2I) (JNIEnv *env, jclass that, jint arg0, jobject arg1, jint arg2){ XClientMessageEvent _arg1, *lparg1=NULL; NATIVE_ENTER(env, that, "memmove__ILorg_eclipse_swt_internal_motif_XClientMessageEvent_2I\n") if (arg1) lparg1 = getXClientMessageEventFields(env, arg1, &_arg1); memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); if (arg1) setXClientMessageEventFields(env, arg1, lparg1); NATIVE_EXIT(env, that, "memmove__ILorg_eclipse_swt_internal_motif_XClientMessageEvent_2I\n")} |
|
if (arg1) setXConfigureEventFields(env, arg1, lparg1); | JNIEXPORT void JNICALL OS_NATIVE(memmove__ILorg_eclipse_swt_internal_motif_XConfigureEvent_2I) (JNIEnv *env, jclass that, jint arg0, jobject arg1, jint arg2){ XConfigureEvent _arg1, *lparg1=NULL; NATIVE_ENTER(env, that, "memmove__ILorg_eclipse_swt_internal_motif_XConfigureEvent_2I\n") if (arg1) lparg1 = getXConfigureEventFields(env, arg1, &_arg1); memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); if (arg1) setXConfigureEventFields(env, arg1, lparg1); NATIVE_EXIT(env, that, "memmove__ILorg_eclipse_swt_internal_motif_XConfigureEvent_2I\n")} |
|
if (arg1) setXKeyEventFields(env, arg1, lparg1); | JNIEXPORT void JNICALL OS_NATIVE(memmove__ILorg_eclipse_swt_internal_motif_XKeyEvent_2I) (JNIEnv *env, jclass that, jint arg0, jobject arg1, jint arg2){ XKeyEvent _arg1, *lparg1=NULL; NATIVE_ENTER(env, that, "memmove__ILorg_eclipse_swt_internal_motif_XKeyEvent_2I\n") if (arg1) lparg1 = getXKeyEventFields(env, arg1, &_arg1); memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); if (arg1) setXKeyEventFields(env, arg1, lparg1); NATIVE_EXIT(env, that, "memmove__ILorg_eclipse_swt_internal_motif_XKeyEvent_2I\n")} |
|
if (arg1) (*env)->ReleaseShortArrayElements(env, arg1, lparg1, 0); | if (arg1) (*env)->ReleaseShortArrayElements(env, arg1, lparg1, JNI_ABORT); | JNIEXPORT void JNICALL OS_NATIVE(memmove__I_3SI) (JNIEnv *env, jclass that, jint arg0, jshortArray arg1, jint arg2){ jshort *lparg1=NULL; NATIVE_ENTER(env, that, "memmove__I_3SI\n") if (arg1) lparg1 = (*env)->GetShortArrayElements(env, arg1, NULL); memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); if (arg1) (*env)->ReleaseShortArrayElements(env, arg1, lparg1, 0); NATIVE_EXIT(env, that, "memmove__I_3SI\n")} |
if (arg0) lparg0 = getXDestroyWindowEventFields(env, arg0, &_arg0); | if (arg0) lparg0 = &_arg0; | JNIEXPORT void JNICALL OS_NATIVE(memmove__Lorg_eclipse_swt_internal_motif_XDestroyWindowEvent_2II) (JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2){ XDestroyWindowEvent _arg0, *lparg0=NULL; NATIVE_ENTER(env, that, "memmove__Lorg_eclipse_swt_internal_motif_XDestroyWindowEvent_2II\n") if (arg0) lparg0 = getXDestroyWindowEventFields(env, arg0, &_arg0); memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); if (arg0) setXDestroyWindowEventFields(env, arg0, lparg0); NATIVE_EXIT(env, that, "memmove__Lorg_eclipse_swt_internal_motif_XDestroyWindowEvent_2II\n")} |
if (arg0) lparg0 = getXPropertyEventFields(env, arg0, &_arg0); | if (arg0) lparg0 = &_arg0; | JNIEXPORT void JNICALL OS_NATIVE(memmove__Lorg_eclipse_swt_internal_motif_XPropertyEvent_2II) (JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2){ XPropertyEvent _arg0, *lparg0=NULL; NATIVE_ENTER(env, that, "memmove__Lorg_eclipse_swt_internal_motif_XPropertyEvent_2II\n") if (arg0) lparg0 = getXPropertyEventFields(env, arg0, &_arg0); memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); if (arg0) setXPropertyEventFields(env, arg0, lparg0); NATIVE_EXIT(env, that, "memmove__Lorg_eclipse_swt_internal_motif_XPropertyEvent_2II\n")} |
if (arg0) lparg0 = getXReparentEventFields(env, arg0, &_arg0); | if (arg0) lparg0 = &_arg0; | JNIEXPORT void JNICALL OS_NATIVE(memmove__Lorg_eclipse_swt_internal_motif_XReparentEvent_2II) (JNIEnv *env, jclass that, jobject arg0, jint arg1, jint arg2){ XReparentEvent _arg0, *lparg0=NULL; NATIVE_ENTER(env, that, "memmove__Lorg_eclipse_swt_internal_motif_XReparentEvent_2II\n") if (arg0) lparg0 = getXReparentEventFields(env, arg0, &_arg0); memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); if (arg0) setXReparentEventFields(env, arg0, lparg0); NATIVE_EXIT(env, that, "memmove__Lorg_eclipse_swt_internal_motif_XReparentEvent_2II\n")} |
gtp_printf("\n"); | gtp_printf("\n\n"); | gtp_top_moves_black(char *s, int id){ int i, j, k; UNUSED(s); genmove(&i, &j, BLACK); gtp_printid(id, GTP_SUCCESS); for (k = 0; k < 10; k++) if (best_move_values[k] > 0.0) { gtp_print_vertex(best_movei[k], best_movej[k]); gtp_printf(" %.2f ", best_move_values[k]); } gtp_printf("\n"); return GTP_OK;} |
gtp_printf("\n"); | gtp_printf("\n\n"); | gtp_top_moves_white(char *s, int id){ int i, j, k; UNUSED(s); genmove(&i, &j, WHITE); gtp_printid(id, GTP_SUCCESS); for (k = 0; k < 10; k++) if (best_move_values[k] > 0.0) { gtp_print_vertex(best_movei[k], best_movej[k]); gtp_printf(" %.2f ", best_move_values[k]); } gtp_printf("\n"); return GTP_OK;} |
else if (approxlib(libs[k], other, 3, libs2) == 2) { for (r = 0; r < 2; r++) { | liberties2 = approxlib(libs[k], other, 3, libs2); if (liberties2 <= 2) { for (r = 0; r < liberties2; r++) { | defend2(int str, int *move, int komaster, int kom_pos){ int color, other; int xpos; int liberties; int libs[2]; int liberties2; int libs2[6]; int moves[MAX_MOVES]; int scores[MAX_MOVES]; int num_moves = 0; int savemove = 0; int savecode = 0; int bc; int k; int r; int s; int found_read_result; Read_result *read_result; SETUP_TRACE_INFO("defend2", str); reading_node_counter++; RTRACE("trying to rescue %1m\n", str); color = board[str]; other = OTHER_COLOR(color); gg_assert(board[str] != EMPTY); gg_assert(countlib(str) == 2); if ((stackp <= depth) && (hashflags & HASH_DEFEND2)) { found_read_result = get_read_result(DEFEND2, komaster, kom_pos, &str, &read_result); if (found_read_result) { TRACE_CACHED_RESULT(*read_result); if (rr_get_result(*read_result) != 0) *move = rr_get_move(*read_result); SGFTRACE(rr_get_move(*read_result), rr_get_result(*read_result), "cached"); return rr_get_result(*read_result); } /* This data should always be recorded. */ if (read_result) { rr_set_compressed_data(*read_result, DEFEND2, komaster, kom_pos, str, stackp); } } else read_result = NULL; liberties = findlib(str, 2, libs); ASSERT1(liberties == 2, str); /* Collect moves to try in the first batch. * 1. First order liberties. * 2. Chain breaking moves. * 3. Second order liberties moving up from first line to second. * 4. Edge clamps. */ for (k = 0; k < liberties; k++) { moves[k] = libs[k]; scores[k] = 0; } num_moves = liberties; break_chain_moves(str, moves, scores, &num_moves); break_chain2_efficient_moves(str, moves, scores, &num_moves); propose_edge_moves(str, libs, liberties, moves, scores, &num_moves, color); edge_clamp(str, moves, scores, &num_moves); order_moves(str, num_moves, moves, scores, color, read_function_name); for (k = 0; k < num_moves; k++) { int new_komaster; int new_kom_pos; int ko_move; xpos = moves[k]; if (komaster_trymove(xpos, color, "defend2-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { int acode = do_attack(str, NULL, new_komaster, new_kom_pos); popgo(); if (acode == 0) { SGFTRACE(xpos, WIN, "defense effective - A"); READ_RETURN(read_result, move, xpos, WIN); } /* if the move works with ko we save it, then look for something * better. */ UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos); } else { if (do_attack(str, NULL, new_komaster, new_kom_pos) != WIN) { savemove = xpos; savecode = KO_B; } popgo(); } } } /* Look for backfilling moves. */ for (k = 0; k < liberties; k++) { if (is_self_atari(libs[k], other)) { liberties2 = approxlib(libs[k], color, 6, libs2); for (r = 0; r < liberties2; r++) { xpos = libs2[r]; /* Don't reconsider previously tested moves. */ for (s = 0; s < num_moves; s++) if (xpos == moves[s]) break; if (s < num_moves) continue; if (trymove(xpos, color, "defend2-C", str, komaster, kom_pos)) { int acode; /* If the newly placed stone is in atari, we give up without * fight. */ if (countlib(xpos) == 1 && countstones(xpos) > 1) acode = WIN; else acode = do_attack(str, NULL, komaster, kom_pos); popgo(); if (acode == 0) { SGFTRACE(xpos, WIN, "backfill effective"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos); } } } else if (approxlib(libs[k], other, 3, libs2) == 2) { for (r = 0; r < 2; r++) { xpos = libs2[r]; /* Don't reconsider previously tested moves. */ for (s = 0; s < num_moves; s++) if (xpos == moves[s]) break; if (s < num_moves) continue; if (!is_self_atari(xpos, color) && trymove(xpos, color, "defend2-D", str, komaster, kom_pos)) { int acode = do_attack(str, NULL, komaster, kom_pos); popgo(); if (acode == 0) { SGFTRACE(xpos, WIN, "backfill effective"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, xpos); } } } } if (stackp <= depth) { for (k = 0; k < liberties; k++) { int dcode = special_rescue(str, libs[k], &xpos, komaster, kom_pos); if (dcode == WIN) { SGFTRACE(xpos, WIN, "special rescue"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos); } } if (stackp <= backfill_depth) { int dcode = special_rescue2(str, libs, &xpos, komaster, kom_pos); if (dcode == WIN) { SGFTRACE(xpos, WIN, "special rescue2"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos); } if (level >= 10 && stackp <= superstring_depth) { int dcode = superstring_breakchain(str, &xpos, komaster, kom_pos, 4); if (dcode == WIN) { SGFTRACE(xpos, WIN, "superstring_breakchain"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos); } /* If nothing else works, we try playing a liberty of the * super_string. */ if (level >= 10 && stackp <= superstring_depth) { int liberties; int libs[MAX_LIBERTIES + 4]; find_superstring_liberties(str, &liberties, libs, 3); for (k = 0; k < liberties; k++) { int apos = libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, color, "defend2-E", str, komaster, kom_pos)) { int acode; /* If the newly placed stone is in atari, we give up without fight. */ if (countlib(apos) == 1) acode = WIN; else acode = do_attack(str, NULL, komaster, kom_pos); popgo(); if (acode == 0) { SGFTRACE(apos, WIN, "superstring liberty"); READ_RETURN(read_result, move, apos, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savemove, acode, apos); } } /* Now we are truly desperate. Try playing second order liberties of * the superstring. */ for (k = 0; k < liberties; k++) { int apos = libs[k]; int dcode; if (liberty_of_string(apos, str)) continue; dcode = special_rescue(str, apos, &xpos, komaster, kom_pos); if (dcode == WIN) { SGFTRACE(xpos, WIN, "special rescue"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, dcode, xpos); } } /* We place the more speculative moves trying to break chain links * with 2 or 3 liberties last, because these moves often are not * really relevant. */ bc = break_chain2(str, &xpos, komaster, kom_pos); if (bc == WIN) { SGFTRACE(xpos, bc, "break chain2"); READ_RETURN(read_result, move, xpos, bc); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, bc, xpos); if (stackp <= backfill2_depth) { bc = break_chain3(str, &xpos, komaster, kom_pos); if (bc == WIN) { SGFTRACE(xpos, bc, "break chain3"); READ_RETURN(read_result, move, xpos, bc); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, bc, xpos); } if (savecode != 0) { SGFTRACE(savemove, savecode, "saved move"); READ_RETURN(read_result, move, savemove, savecode); } RTRACE("failed to find rescuing move.\n"); SGFTRACE(0, 0, NULL); READ_RETURN0(read_result);} |
for (r = 0; r < 4; r++) { int bpos = libs2[0] + delta[r]; if (board[bpos] == other && chainlinks2(bpos, adjs, 1) > 0) { findlib(adjs[0], 1, &xpos); ADD_CANDIDATE_MOVE(xpos, 0, moves, scores, num_moves); } } | attack2(int str, int *move, int komaster, int kom_pos){ int color = board[str]; int other = OTHER_COLOR(color); int apos; int hpos; int xpos; int liberties, r; int libs[2]; int libs2[2]; int adj, adjs[MAXCHAIN]; int savemove = 0; int savecode = 0; int acode; int dcode; int k; int atari_possible = 0; int moves[MAX_MOVES]; int scores[MAX_MOVES]; int num_moves = 0; int adjacent_liberties = 0; int found_read_result; Read_result *read_result; SETUP_TRACE_INFO("attack2", str); reading_node_counter++; str = find_origin(str); ASSERT1(board[str] != EMPTY, str); ASSERT1(countlib(str) == 2, str); RTRACE("checking attack on %1m with 2 liberties\n", str); if ((stackp <= depth) && (hashflags & HASH_ATTACK2)) { found_read_result = get_read_result(ATTACK2, komaster, kom_pos, &str, &read_result); if (found_read_result) { TRACE_CACHED_RESULT(*read_result); if (rr_get_result(*read_result) != 0) *move = rr_get_move(*read_result); SGFTRACE(rr_get_move(*read_result), rr_get_result(*read_result), "cached"); return rr_get_result(*read_result); } /* This data should always be recorded. */ if (read_result) { rr_set_compressed_data(*read_result, ATTACK2, komaster, kom_pos, str, stackp); } } else read_result = NULL; /* The attack may fail if a boundary string is in atari and cannot * be defended. First we must try defending such a string. * * We start by trying to defend the boundary string by looking for an * adjacent string which is in atari. */ adj = chainlinks2(str, adjs, 1); for (r = 0; r < adj; r++) { /* if stackp > depth and any boundary chain is in atari, assume safe. * However, if the captured chain is only of size 1, there can still * be a working ladder, so continue if that is the case. */ if (stackp > depth && countstones(adjs[r]) > 1) { SGFTRACE(0, 0, "boundary in atari"); READ_RETURN0(read_result); } /* Pick up moves breaking the second order chain. */ if (stackp <= depth) break_chain_moves(adjs[r], moves, scores, &num_moves); findlib(adjs[r], 1, &hpos); ADD_CANDIDATE_MOVE(hpos, 0, moves, scores, num_moves); } /* Get the two liberties of (str). */ liberties = findlib(str, 2, libs); ASSERT1(liberties == 2, str); if (libs[0] == SOUTH(libs[1]) || libs[0] == WEST(libs[1]) || libs[0] == NORTH(libs[1]) || libs[0] == EAST(libs[1])) adjacent_liberties = 1; for (k = 0; k < 2; k++) { apos = libs[k]; if (!is_self_atari(apos, other)) atari_possible = 1; /* we only want to consider the move at (apos) if: * stackp <= backfill_depth * -or- stackp <= depth and it is an isolated stone * -or- it is not in immediate atari */ if (stackp <= backfill_depth || ((stackp <= depth || adjacent_liberties) && board[SOUTH(apos)] != other && board[WEST(apos)] != other && board[NORTH(apos)] != other && board[EAST(apos)] != other) || !is_self_atari(apos, other)) ADD_CANDIDATE_MOVE(apos, 0, moves, scores, num_moves); /* Try backfilling if atari is impossible. */ if (stackp <= backfill_depth && approxlib(apos, other, 2, libs2) == 1) { ADD_CANDIDATE_MOVE(libs2[0], 0, moves, scores, num_moves); } } /* If we can't make a direct atari, look for edge blocking moves. */ if (!atari_possible) for (k = 0; k < 2; k++) edge_block(str, libs[k], moves, scores, &num_moves); /* If one of the surrounding chains have only two liberties, which * coincide with the liberties of the attacked string, we try to * backcapture. */ adj = chainlinks2(str, adjs, 2); for (r = 0; r < adj; r++) { apos = adjs[r]; if (liberty_of_string(libs[0], apos) && liberty_of_string(libs[1], apos)) break_chain_moves(apos, moves, scores, &num_moves); } propose_edge_moves(str, libs, liberties, moves, scores, &num_moves, other); order_moves(str, num_moves, moves, scores, other, read_function_name); for (k = 0; k < num_moves; k++) { int new_komaster; int new_kom_pos; int ko_move; apos = moves[k]; if (komaster_trymove(apos, other, "attack2-A", str, komaster, kom_pos, &new_komaster, &new_kom_pos, &ko_move, stackp <= ko_depth && savecode == 0)) { if (!ko_move) { dcode = do_find_defense(str, NULL, new_komaster, new_kom_pos); if (dcode != WIN && do_attack(str, NULL, new_komaster, new_kom_pos)) { if (dcode == 0) { popgo(); SGFTRACE(apos, WIN, "attack effective"); READ_RETURN(read_result, move, apos, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, apos); } } else { if (do_find_defense(str, NULL, new_komaster, new_kom_pos) != WIN && do_attack(str, NULL, new_komaster, new_kom_pos) != 0) { savemove = apos; savecode = KO_B; } } popgo(); } } /* The simple ataris didn't work. Try something more fancy. */ acode = find_cap2(str, libs[0], libs[1], &xpos, komaster, kom_pos); if (acode == WIN) { SGFTRACE(xpos, WIN, "find cap2"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos); if (stackp <= backfill_depth) { acode = special_attack2(str, libs, &xpos, komaster, kom_pos); if (acode == WIN) { SGFTRACE(xpos, WIN, "special attack2"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos); } if (stackp <= backfill_depth) { acode = special_attack3(str, libs, &xpos, komaster, kom_pos); if (acode == WIN) { SGFTRACE(xpos, WIN, "special attack3"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos); } if (stackp <= backfill_depth) { acode = special_attack4(str, libs, &xpos, komaster, kom_pos); if (acode == WIN) { SGFTRACE(xpos, WIN, "special attack4"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT_UNREVERSED(savecode, savemove, acode, xpos); } /* If it is not possible to make a direct atari, we try filling * a liberty of the superstring. */ if (level >= 10 && stackp <= backfill_depth && (stackp <= superstring_depth || !atari_possible)) { int liberties; int libs[MAX_LIBERTIES + 4]; int liberty_cap = 2; if (stackp <= backfill2_depth) liberty_cap = 3; find_superstring_liberties(str, &liberties, libs, liberty_cap); if (liberties <= 5) { for (k = 0; k < liberties; k++) { int apos = libs[k]; if (liberty_of_string(apos, str)) continue; if (trymove(apos, other, "attack2-C", str, komaster, kom_pos)) { if (countlib(apos) == 1) { /* can't atari, try backfilling. */ findlib(apos, 1, &xpos); if (approxlib(xpos, other, 2, NULL) > 1) { popgo(); if (trymove(xpos, other, "attack2-D", str, komaster, kom_pos)) { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { if (dcode == 0) { popgo(); SGFTRACE(xpos, WIN, "attack effective"); READ_RETURN(read_result, move, xpos, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, xpos); } popgo(); } } else popgo(); } else { dcode = do_find_defense(str, NULL, komaster, kom_pos); if (dcode != WIN && do_attack(str, NULL, komaster, kom_pos)) { if (dcode == 0) { popgo(); SGFTRACE(apos, WIN, "attack effective"); READ_RETURN(read_result, move, apos, WIN); } UPDATE_SAVED_KO_RESULT(savecode, savemove, dcode, apos); } popgo(); } } } } } if (savecode == 0) { RTRACE("ALIVE!!\n"); SGFTRACE(0, 0, NULL); READ_RETURN0(read_result); } SGFTRACE(savemove, savecode, "saved move"); READ_RETURN(read_result, move, savemove, savecode);} |
|
trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T Unix "); | case V('U','x'): trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T UNIX "); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,j,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[1]=='\n') j=1; else j=2; while (c[j]==' ' || c[j]=='\t') j++; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { i=V(c[0],c[1]); switch (i) { case V('a','b'): h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case V('d','i'): { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++;break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case V('d','s'): mode=1; case V('a','s'): { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case V('b','r'): if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) { c=scan_escape(c+1); } c=skip_till_newline(c);break; case V('c','2'): c=c+j; if (*c!='\n') { nobreaksym=*c; } else nobreaksym='\''; c=skip_till_newline(c); break; case V('c','c'): c=c+j; if (*c!='\n') { controlsym=*c; } else controlsym='.'; c=skip_till_newline(c); break; case V('c','e'): c=c+j; if (*c=='\n') { i=1; } else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case V('e','c'): c=c+j; if (*c!='\n') { escapesym=*c; } else escapesym='\\'; break; c=skip_till_newline(c); case V('e','o'): escapesym='\0'; c=skip_till_newline(c); break; case V('e','x'): return 0; break; case V('f','c'): c=c+j; if (*c=='\n') { fieldsym=padsym='\0'; } else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case V('f','i'): if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case V('f','t'): c=c+j; if (*c=='\n') { out_html(change_to_font(0)); } else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case V('e','l'): { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case V('i','e'): /* .ie c anything : then part of if else */ case V('i','f'): { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case V('i','g'): { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case V('n','f'): if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case V('p','s'): c=c+j; if (*c=='\n') { out_html(change_to_size('0')); } else { j=0;i=0; if (*c=='-') { j= -1;c++; } else if (*c=='+') { j=1;c++;} c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case V('s','p'): c=c+j; if (fillout) out_html("<P>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('s','o'): { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') { h=c; } else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else { scan_troff(buf+1,0,NULL); } if (buf) delete [] buf; if (name) delete [] name; *c++='\n'; break; } case V('t','a'): c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case V('t','i'): /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case V('t','m'): c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case V('B',' '): case V('B','\n'): case V('I',' '): case V('I','\n'): /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('F','d'): //for "Function definitions", mdoc package case V('F','n'): //for "Function calls": brackets and commas have to be inserted automatically case V('F','o'): case V('F','c'): { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; }; break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case V('F','t'): //perhaps "Function return type" case V('F','a'): //"Function argument" case V('B','R'): case V('B','I'): case V('I','B'): case V('I','R'): case V('R','B'): case V('R','I'): { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('D','T'): for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case V('I','P'): sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) { scan_troff(wordlist[0], 1,NULL); } out_html("<DD>"); curpos=0; break; case V('T','P'): if (!dl_set[itemdepth]) { out_html("<P><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case V('I','X'): /* general index */ c=skip_till_newline(c); break; case V('P',' '): case V('P','\n'): case V('L','P'): case V('P','P'): if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('H','P'): if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case V('P','D'): c=skip_till_newline(c); break; case V('R','s'): /* BSD mandoc */ case V('R','S'): sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case V('R','e'): /* BSD mandoc */ case V('R','E'): if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case V('S','B'): out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case V('S','M'): c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case V('S','s'): /* BSD mandoc */ mandoc_command = 1; case V('S','S'): mode=1; case V('S','h'): /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case V('S','H'): c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case V('S','x'): // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('T','S'): c=scan_table(c); break; case V('D','t'): /* BSD mandoc */ mandoc_command = 1; case V('T','H'): if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>Manpage of "); out_html( wordlist[0]); out_html( "</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( wordlist[0] ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<h1>" ); out_html( wordlist[0] ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(wordlist[4]); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(wordlist[1]); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case V('T','X'): { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case V('r','m'): /* .rm xx : Remove request, macro or string */ case V('r','n'): /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case V('n','x'): /* .nx filename : next file. */ case V('i','n'): /* .in +-N : Indent */ c=skip_till_newline(c); break; case V('n','r'): /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case V('a','m'): /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case V('d','e'): /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char c2; c=c+j; sl=fill_words(c, wordlist, &words); c2 = c[1]; if (c2 == '\n') c2 = ' '; i=V(c[0],c2);j=2; if (words==1) { wordlist[1] = qstrdup(".."); } else { wordlist[1]--; wordlist[1][0]='.'; j=3; } c=sl+1; sl=c; while (*c && strncmp(c,wordlist[1],j)) c=skip_till_newline(c); de=defdef; while (de && de->nr!= i) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=i; de->next=defdef; de->st=h; defdef=de; } } if (words==1) { delete [] wordlist[1]; } } c=skip_till_newline(c); break; case V('B','l'): /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) { /* These things can nest. */ itemdepth++; } if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case V('E','l'): /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("</DL>\n"); } else if (dl_set[itemdepth] & BL_BULLET_LIST) { out_html("</UL>\n"); } else if (dl_set[itemdepth] & BL_ENUM_LIST) { out_html("</OL>\n"); } dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('I','t'): /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) { c = skip_till_newline(c); } if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case V('B','k'): /* BSD mandoc */ case V('E','k'): /* BSD mandoc */ case V('D','d'): /* BSD mandoc */ case V('O','s'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('B','t'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case V('A','t'): /* BSD mandoc */ case V('F','x'): /* BSD mandoc */ case V('N','x'): /* BSD mandoc */ case V('O','x'): /* BSD mandoc */ case V('B','x'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T Unix "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case V('D','l'): /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case V('B','d'): /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) { strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); } out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case V('E','d'): /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case V('B','e'): /* BSD mandoc */ c=c+j; if (fillout) out_html("<P>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('X','r'): /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case V('F','l'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('P','a'): /* BSD mandoc */ case V('P','f'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('P','p'): /* BSD mandoc */ if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('D','q'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('O','p'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('O','o'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case V('O','c'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case V('P','q'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('Q','l'): /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case V('S','q'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('A','r'): /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else { c=scan_troff_mandoc(c, 1, NULL); } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('A','d'): /* BSD mandoc */ case V('E','m'): /* BSD mandoc */ case V('V','a'): /* BSD mandoc */ case V('X','c'): /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('N','d'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('N','m'): /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ static int count = 0; /* Don't break on the first Nm */ if (count) { out_html("<BR>"); } else { char *end = strchr(c, '\n'); if (end) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, end - c, SMALL_STR_MAX); } } count++; } out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if (*c == '\n') { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); } else { c=scan_troff_mandoc(c, 1, NULL); } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case V('C','d'): /* BSD mandoc */ case V('C','m'): /* BSD mandoc */ case V('I','c'): /* BSD mandoc */ case V('M','s'): /* BSD mandoc */ case V('O','r'): /* BSD mandoc */ case V('S','y'): /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('D','v'): /* BSD mandoc */ case V('E','v'): /* BSD mandoc */ case V('F','r'): /* BSD mandoc */ case V('L','i'): /* BSD mandoc */ case V('N','o'): /* BSD mandoc */ case V('N','s'): /* BSD mandoc */ case V('T','n'): /* BSD mandoc */ case V('n','N'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('%','A'): /* BSD mandoc biblio stuff */ case V('%','D'): case V('%','N'): case V('%','O'): case V('%','P'): case V('%','Q'): case V('%','V'): c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case V('%','B'): case V('%','J'): case V('%','R'): case V('%','T'): c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: /* search macro database of self-defined macros */ owndef = defdef; while (owndef && owndef->nr!=i) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) { scan_troff_mandoc(wordlist[i],1,&h); } else { scan_troff(wordlist[i],1,&h); } wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) { scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); } else { scan_troff(owndef->st+deflen+2, 0, NULL); } newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else { c=skip_till_newline(c); } break; } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} |
else if (i==V('U','x')) out_html("UNIX "); | static char *scan_request(char *c){ /* BSD Mandoc stuff */ static int mandoc_synopsis=0; /* True if we are in the synopsis section */ static int mandoc_command=0; /* True if this is mandoc page */ static int mandoc_bd_options; /* Only copes with non-nested Bd's */ int i,j,mode=0; char *h; char *wordlist[MAX_WORDLIST]; int words; char *sl; STRDEF *owndef; while (*c==' ' || *c=='\t') c++; if (c[0]=='\n') return c+1; if (c[1]=='\n') j=1; else j=2; while (c[j]==' ' || c[j]=='\t') j++; if (c[0]==escapesym) { /* some pages use .\" .\$1 .\} */ /* .\$1 is too difficult/stuppid */ if (c[1]=='$') c=skip_till_newline(c); else c = scan_escape(c+1); } else { i=V(c[0],c[1]); switch (i) { case V('a','b'): h=c+j; while (*h && *h !='\n') h++; *h='\0'; if (scaninbuff && buffpos) { buffer[buffpos]='\0'; puts(buffer); } /* fprintf(stderr, "%s\n", c+2); */ return 0; break; case V('d','i'): { STRDEF *de; /* int oldcurpos=curpos; */ c=c+j; i=V(c[0],c[1]); if (*c=='\n') { c++;break; } while (*c && *c!='\n') c++; c++; h=c; while (*c && strncmp(c,".di",3)) while (*c && *c++!='\n'); *c='\0'; de=strdef; while (de && de->nr !=i) de=de->next; if (!de) { de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; } else { delete [] de->st; de->slen=0; de->st=NULL; } scan_troff(h,0,&de->st); if (*c) *c='.'; while (*c && *c++!='\n'); break; } case V('d','s'): mode=1; case V('a','s'): { STRDEF *de; int oldcurpos=curpos; c=c+j; i=V(c[0],c[1]); j=0; while (c[j] && c[j]!='\n') j++; if (j<3) { c=c+j; break; } if (c[1]==' ') c=c+1; else c=c+2; while (isspace(*c)) c++; if (*c=='"') c++; de=strdef; while (de && de->nr != i) de=de->next; single_escape=1; curpos=0; if (!de) { char *h; de=new STRDEF(); de->nr=i; de->slen=0; de->next=strdef; de->st=NULL; strdef=de; h=NULL; c=scan_troff(c, 1, &h); de->st=h; de->slen=curpos; } else { if (mode) { char *h=NULL; c=scan_troff(c, 1, &h); delete [] de->st; de->slen=0; de->st=h; } else c=scan_troff(c,1,&de->st); de->slen+=curpos; } single_escape=0; curpos=oldcurpos; } break; case V('b','r'): if (still_dd) out_html("<DD>"); else out_html("<BR>\n"); curpos=0; c=c+j; if (c[0]==escapesym) { c=scan_escape(c+1); } c=skip_till_newline(c);break; case V('c','2'): c=c+j; if (*c!='\n') { nobreaksym=*c; } else nobreaksym='\''; c=skip_till_newline(c); break; case V('c','c'): c=c+j; if (*c!='\n') { controlsym=*c; } else controlsym='.'; c=skip_till_newline(c); break; case V('c','e'): c=c+j; if (*c=='\n') { i=1; } else { i=0; while ('0'<=*c && *c<='9') { i=i*10+*c-'0'; c++; } } c=skip_till_newline(c); /* center next i lines */ if (i>0) { out_html("<CENTER>\n"); while (i && *c) { char *line=NULL; c=scan_troff(c,1, &line); if (line && strncmp(line, "<BR>", 4)) { out_html(line); out_html("<BR>\n"); delete [] line; i--; } } out_html("</CENTER>\n"); curpos=0; } break; case V('e','c'): c=c+j; if (*c!='\n') { escapesym=*c; } else escapesym='\\'; break; c=skip_till_newline(c); case V('e','o'): escapesym='\0'; c=skip_till_newline(c); break; case V('e','x'): return 0; break; case V('f','c'): c=c+j; if (*c=='\n') { fieldsym=padsym='\0'; } else { fieldsym=c[0]; padsym=c[1]; } c=skip_till_newline(c); break; case V('f','i'): if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } curpos=0; fillout=1; c=skip_till_newline(c); break; case V('f','t'): c=c+j; if (*c=='\n') { out_html(change_to_font(0)); } else { if (*c==escapesym) { int fn; c=scan_expression(c, &fn); c--; out_html(change_to_font(fn)); } else { out_html(change_to_font(*c)); c++; } } c=skip_till_newline(c); break; case V('e','l'): { int ifelseval = s_ifelseval.pop(); /* .el anything : else part of if else */ if (ifelseval) { c=c+j; c[-1]='\n'; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c+j); break; } case V('i','e'): /* .ie c anything : then part of if else */ case V('i','f'): { /* .if c anything * .if !c anything * .if N anything * .if !N anything * .if 'string1'string2' anything * .if !'string1'string2' anything */ c=c+j; c=scan_expression(c, &i); int ifelseval=!i; s_ifelseval.push( ifelseval ); if (i) { *c='\n'; c++; c=scan_troff(c,1,NULL); } else c=skip_till_newline(c); break; } case V('i','g'): { const char *endwith="..\n"; i=3; c=c+j; if (*c!='\n' && *c != '\\') { /* Not newline or comment */ endwith=c-1;i=1; c[-1]='.'; while (*c && *c!='\n') c++,i++; } c++; while (*c && strncmp(c,endwith,i)) while (*c++!='\n'); while (*c && *c++!='\n'); break; } case V('n','f'): if (fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; c=skip_till_newline(c); break; case V('p','s'): c=c+j; if (*c=='\n') { out_html(change_to_size('0')); } else { j=0;i=0; if (*c=='-') { j= -1;c++; } else if (*c=='+') { j=1;c++;} c=scan_expression(c, &i); if (!j) { j=1; if (i>5) i=i-10; } out_html(change_to_size(i*j)); } c=skip_till_newline(c); break; case V('s','p'): c=c+j; if (fillout) out_html("<P>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('s','o'): { /* FILE *f; */ char *buf; char *name=NULL; curpos=0; c=c+j; if (*c=='/') { h=c; } else { h=c-3; h[0]='.'; h[1]='.'; h[2]='/'; } while (*c!='\n') c++; *c='\0'; scan_troff(h,1, &name); if (name[3]=='/') h=name+3; else h=name; /* this works alright, except for section 3 */ buf=read_man_page(h); if (!buf) { fprintf(stderr, "man2html: unable to open or read file %s.\n", h); out_html("<BLOCKQUOTE>" "man2html: unable to open or read file.\n"); out_html(h); out_html("</BLOCKQUOTE>\n"); } else { scan_troff(buf+1,0,NULL); } if (buf) delete [] buf; if (name) delete [] name; *c++='\n'; break; } case V('t','a'): c=c+j; j=0; while (*c!='\n') { sl=scan_expression(c, &tabstops[j]); if (j>0 && (*c=='-' || *c=='+')) tabstops[j]+=tabstops[j-1]; c=sl; while (*c==' ' || *c=='\t') c++; j++; } maxtstop=j; curpos=0; break; case V('t','i'): /*while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else itemdepth--; }*/ out_html("<BR>\n"); c=c+j; c=scan_expression(c, &j); for (i=0; i<j; i++) out_html(" "); curpos=j; c=skip_till_newline(c); break; case V('t','m'): c=c+j; h=c; while (*c!='\n') c++; *c='\0'; /* fprintf(stderr,"%s\n", h); */ *c='\n'; break; case V('B',' '): case V('B','\n'): case V('I',' '): case V('I','\n'): /* parse one line in a certain font */ out_html(change_to_font(*c)); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('F','d'): //for "Function definitions", mdoc package case V('F','n'): //for "Function calls": brackets and commas have to be inserted automatically case V('F','o'): case V('F','c'): { bool inFdMode=(c[1]=='d'); char font[2] ; font[0] = 'B'; font[1] = 'B'; c=c+j; if (*c=='\n') c++; char *eol=strchr(c,'\n'); char *semicolon=strchr(c,';'); if ((semicolon!=0) && (semicolon<eol)) *semicolon=' '; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); if (inFdMode) continue; if (i==0) { out_html(" ("); if (!mandoc_synopsis) out_html(") "); } else if (i<words-1) out_html(", "); } if (mandoc_synopsis) { if (!inFdMode) out_html(");"); out_html("<br>"); }; out_html(change_to_font('R')); out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; }; break; case V('O','P'): /* groff manpages use this construction */ /* .OP a b : [ <B>a</B> <I>b</I> ] */ mode=1; c[0]='B'; c[1]='I'; out_html(change_to_font('R')); out_html("["); curpos++; case V('F','t'): //perhaps "Function return type" case V('F','a'): //"Function argument" case V('B','R'): case V('B','I'): case V('I','B'): case V('I','R'): case V('R','B'): case V('R','I'): { bool inFMode=(c[0]=='F'); if (inFMode) { c[0]='B'; c[1]='I'; }; char font[2] ; font[0] = c[0]; font[1] = c[1]; c=c+j; if (*c=='\n') c++; sl=fill_words(c, wordlist, &words); c=sl+1; /* .BR name (section) ** indicates a link. It will be added in the output routine. */ for (i=0; i<words; i++) { if ((mode) || (inFMode)) { out_html(" "); curpos++; } wordlist[i][-1]=' '; out_html(change_to_font(font[i&1])); scan_troff(wordlist[i],1,NULL); } out_html(change_to_font('R')); if (mode) { out_html(" ]"); curpos++; } out_html(NEWLINE); if (!fillout) curpos=0; else curpos++; } break; case V('D','T'): for (j=0;j<20; j++) tabstops[j]=(j+1)*8; maxtstop=20; c=skip_till_newline(c); break; case V('I','P'): sl=fill_words(c+j, wordlist, &words); c=sl+1; if (!dl_set[itemdepth]) { out_html("<DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); if (words) { scan_troff(wordlist[0], 1,NULL); } out_html("<DD>"); curpos=0; break; case V('T','P'): if (!dl_set[itemdepth]) { out_html("<P><DL COMPACT>\n"); dl_set[itemdepth]=1; } out_html("<DT>"); c=skip_till_newline(c); /* somewhere a definition ends with '.TP' */ if (!*c) still_dd=1; else { c=scan_troff(c,1,NULL); out_html("<DD>"); } curpos=0; break; case V('I','X'): /* general index */ c=skip_till_newline(c); break; case V('P',' '): case V('P','\n'): case V('L','P'): case V('P','P'): if (dl_set[itemdepth]) { out_html("</DL>\n"); dl_set[itemdepth]=0; } if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('H','P'): if (!dl_set[itemdepth]) { out_html("<DL COMPACT>"); dl_set[itemdepth]=1; } out_html("<DT>\n"); still_dd=1; c=skip_till_newline(c); curpos=0; break; case V('P','D'): c=skip_till_newline(c); break; case V('R','s'): /* BSD mandoc */ case V('R','S'): sl=fill_words(c+j, wordlist, &words); j=1; if (words>0) scan_expression(wordlist[0], &j); if (j>=0) { itemdepth++; dl_set[itemdepth]=0; out_html("<DL COMPACT><DT><DD>"); c=skip_till_newline(c); curpos=0; break; } case V('R','e'): /* BSD mandoc */ case V('R','E'): if (itemdepth > 0) { if (dl_set[itemdepth]) out_html("</DL>"); out_html("</DL>\n"); itemdepth--; } c=skip_till_newline(c); curpos=0; break; case V('S','B'): out_html(change_to_size(-1)); out_html(change_to_font('B')); c=scan_troff(c+j, 1, NULL); out_html(change_to_font('R')); out_html(change_to_size('0')); break; case V('S','M'): c=c+j; if (*c=='\n') c++; out_html(change_to_size(-1)); trans_char(c,'"','\a'); c=scan_troff(c,1,NULL); out_html(change_to_size('0')); break; case V('S','s'): /* BSD mandoc */ mandoc_command = 1; case V('S','S'): mode=1; case V('S','h'): /* BSD mandoc */ /* hack for fallthru from above */ mandoc_command = !mode || mandoc_command; case V('S','H'): c=c+j; if (*c=='\n') c++; while (itemdepth || dl_set[itemdepth]) { out_html("</DL>\n"); if (dl_set[itemdepth]) dl_set[itemdepth]=0; else if (itemdepth > 0) itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); /* for mosaic users */ if (section) { out_html("</div>\n"); section=0; } if (mode) out_html("\n<H3>"); else out_html("\n<H2>"); mandoc_synopsis = strncmp(c, "SYNOPSIS", 8) == 0; c = mandoc_command ? scan_troff_mandoc(c,1,NULL) : scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); out_html("<div>\n"); section=1; curpos=0; break; case V('S','x'): // reference to a section header out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('T','S'): c=scan_table(c); break; case V('D','t'): /* BSD mandoc */ mandoc_command = 1; case V('T','H'): if (!output_possible) { sl = fill_words(c+j, wordlist, &words); if (words>1) { for (i=1; i<words; i++) wordlist[i][-1]='\0'; *sl='\0'; output_possible=1; out_html( DOCTYPE"<HTML><HEAD><TITLE>Manpage of "); out_html( wordlist[0]); out_html( "</TITLE>\n"); out_html( "<link rel=\"stylesheet\" href=\"KDE_COMMON_DIR/kde-default.css\" type=\"text/css\">\n" ); out_html( "</HEAD>\n\n" ); out_html("<BODY BGCOLOR=\"#FFFFFF\">\n\n" ); out_html("<div id=\"headline\" style=\"position : absolute; height : 85px; z-index :\n" ); out_html("100; background : transparent; text-align : center; text-transform:\n" ); out_html("smallcaps; width : 100%; top : 0px; left : 0px; width : 100%; color :\n" ); out_html("#000000;\">\n" ); out_html("\n" ); out_html("<H1>" ); out_html( wordlist[0] ); out_html("</H1>\n" ); out_html("</div>\n" ); out_html("<div id=\"navbackground\" style=\"position : absolute; width : 100%; height\n" ); out_html(": 124px; background-image : url('KDE_COMMON_DIR/doctop2.png'); z-index : 5; left\n" ); out_html(": 0px; top : 0px; padding : 0px;\"> <div id=\"bulb1\" style=\"padding : 0px;\n" ); out_html("position : absolute; z-index : 15; width : 150px; height : 85px; top :\n" ); out_html("0px; left : 0px; background : url('KDE_COMMON_DIR/doctop1.png') repeat;\"></div>\n" ); out_html("<div id=\"gradient\" style=\"position : absolute; width : 275px; height :\n" ); out_html("85px; z-index : 19px; top : 0px; padding : 0px; left : 150px;\n" ); out_html("background-image : url('KDE_COMMON_DIR/doctop1a.png'); background-repeat :\n" ); out_html("no-repeat; background-color : transparent; visibility : visible;\"></div>\n" ); out_html("\n" ); out_html("<div id=\"bulb-bit\" style=\"position : absolute; width : 100%; height :\n" ); out_html("25px; top : 85px; left : 0px; background-image :\n" ); out_html("url('KDE_COMMON_DIR/doctop1b.png'); background-repeat : no-repeat;\n" ); out_html("background-color : transparent; z-index : 5;\"></div></div>\n" ); out_html("<h1>" ); out_html( wordlist[0] ); out_html( "</h1>\n" ); out_html("\n" ); out_html("Section: " ); if (words>4) out_html(wordlist[4]); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(wordlist[1]); out_html(")\n"); *sl='\n'; if (mandoc_command) out_html("<BR>BSD mandoc<BR>"); } c=sl+1; } else c=skip_till_newline(c); curpos=0; break; case V('T','X'): { sl=fill_words(c+j, wordlist, &words); *sl='\0'; out_html(change_to_font('I')); if (words>1) wordlist[1][-1]='\0'; const char *c2=lookup_abbrev(wordlist[0]); curpos+=strlen(c2); out_html(c2); out_html(change_to_font('R')); if (words>1) out_html(wordlist[1]); *sl='\n'; c=sl+1; } break; case V('r','m'): /* .rm xx : Remove request, macro or string */ case V('r','n'): /* .rn xx yy : Rename request, macro or string xx to yy */ { STRDEF *de; c=c+j; i=V(c[0],c[1]); c=c+2; while (isspace(*c) && *c!='\n') c++; j=V(c[0],c[1]); while (*c && *c!='\n') c++; c++; de=strdef; while (de && de->nr!=j) de=de->next; if (de) { delete [] de->st; de->st=0; de->nr=0; } de=strdef; while (de && de->nr!=i) de=de->next; if (de) de->nr=j; break; } case V('n','x'): /* .nx filename : next file. */ case V('i','n'): /* .in +-N : Indent */ c=skip_till_newline(c); break; case V('n','r'): /* .nr R +-N M: define and set number register R by +-N; ** auto-increment by M */ { INTDEF *intd; c=c+j; i=V(c[0],c[1]); c=c+2; intd=intdef; while (intd && intd->nr!=i) intd=intd->next; if (!intd) { intd = new INTDEF(); intd->nr=i; intd->val=0; intd->incr=0; intd->next=intdef; intdef=intd; } while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->val); if (*c!='\n') { while (*c==' ' || *c=='\t') c++; c=scan_expression(c,&intd->incr); } c=skip_till_newline(c); break; } case V('a','m'): /* .am xx yy : append to a macro. */ /* define or handle as .ig yy */ mode=1; case V('d','e'): /* .de xx yy : define or redefine macro xx; end at .yy (..) */ /* define or handle as .ig yy */ { STRDEF *de; int olen=0; char c2; c=c+j; sl=fill_words(c, wordlist, &words); c2 = c[1]; if (c2 == '\n') c2 = ' '; i=V(c[0],c2);j=2; if (words==1) { wordlist[1] = qstrdup(".."); } else { wordlist[1]--; wordlist[1][0]='.'; j=3; } c=sl+1; sl=c; while (*c && strncmp(c,wordlist[1],j)) c=skip_till_newline(c); de=defdef; while (de && de->nr!= i) de=de->next; if (mode && de) olen=strlen(de->st); j=olen+c-sl; h = stralloc(j*2+4); if (h) { for (j=0; j<olen; j++) h[j]=de->st[j]; if (!j || h[j-1]!='\n') h[j++]='\n'; while (sl!=c) { if (sl[0]=='\\' && sl[1]=='\\') { h[j++]='\\'; sl++; } else h[j++]=*sl; sl++; } h[j]=0; if (de) { delete [] de->st; de->st=h; } else { de = new STRDEF(); de->nr=i; de->next=defdef; de->st=h; defdef=de; } } if (words==1) { delete [] wordlist[1]; } } c=skip_till_newline(c); break; case V('B','l'): /* BSD mandoc */ { char list_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (dl_set[itemdepth]) { /* These things can nest. */ itemdepth++; } if (nl) { /* Parse list options */ strlimitcpy(list_options, c, nl - c, MED_STR_MAX); } if (strstr(list_options, "-bullet")) { /* HTML Unnumbered List */ dl_set[itemdepth] = BL_BULLET_LIST; out_html("<UL>\n"); } else if (strstr(list_options, "-enum")) { /* HTML Ordered List */ dl_set[itemdepth] = BL_ENUM_LIST; out_html("<OL>\n"); } else { /* HTML Descriptive List */ dl_set[itemdepth] = BL_DESC_LIST; out_html("<DL COMPACT>\n"); } if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; } case V('E','l'): /* BSD mandoc */ c=c+j; if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("</DL>\n"); } else if (dl_set[itemdepth] & BL_BULLET_LIST) { out_html("</UL>\n"); } else if (dl_set[itemdepth] & BL_ENUM_LIST) { out_html("</OL>\n"); } dl_set[itemdepth]=0; if (itemdepth > 0) itemdepth--; if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('I','t'): /* BSD mandoc */ c=c+j; if (strncmp(c, "Xo", 2) == 0 && isspace(*(c+2))) { c = skip_till_newline(c); } if (dl_set[itemdepth] & BL_DESC_LIST) { out_html("<DT>"); out_html(change_to_font('B')); if (*c=='\n') { /* Don't allow embedded comms after a newline */ c++; c=scan_troff(c,1,NULL); } else { /* Do allow embedded comms on the same line. */ c=scan_troff_mandoc(c,1,NULL); } out_html(change_to_font('R')); out_html(NEWLINE); out_html("<DD>"); } else if (dl_set[itemdepth] & (BL_BULLET_LIST | BL_ENUM_LIST)) { out_html("<LI>"); c=scan_troff_mandoc(c,1,NULL); out_html(NEWLINE); } if (fillout) curpos++; else curpos=0; break; case V('B','k'): /* BSD mandoc */ case V('E','k'): /* BSD mandoc */ case V('D','d'): /* BSD mandoc */ case V('O','s'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('B','t'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html(" is currently in beta test."); if (fillout) curpos++; else curpos=0; break; case V('A','t'): /* BSD mandoc */ case V('F','x'): /* BSD mandoc */ case V('N','x'): /* BSD mandoc */ case V('O','x'): /* BSD mandoc */ case V('B','x'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; if (i==V('A','t')) out_html("AT&T Unix "); else if (i==V('F','x')) out_html("FreeBSD "); else if (i==V('N','x')) out_html("NetBSD "); else if (i==V('O','x')) out_html("OpenBSD "); else if (i==V('B','x')) out_html("BSD "); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case V('D','l'): /* BSD mandoc */ c=c+j; out_html(NEWLINE); out_html("<BLOCKQUOTE>"); out_html(change_to_font('L')); if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("</BLOCKQUOTE>"); if (fillout) curpos++; else curpos=0; break; case V('B','d'): /* BSD mandoc */ { /* Seems like a kind of example/literal mode */ char bd_options[NULL_TERMINATED(MED_STR_MAX)]; char *nl = strchr(c,'\n'); c=c+j; if (nl) { strlimitcpy(bd_options, c, nl - c, MED_STR_MAX); } out_html(NEWLINE); mandoc_bd_options = 0; /* Remember options for terminating Bl */ if (strstr(bd_options, "-offset indent")) { mandoc_bd_options |= BD_INDENT; out_html("<BLOCKQUOTE>\n"); } if ( strstr(bd_options, "-literal") || strstr(bd_options, "-unfilled")) { if (fillout) { mandoc_bd_options |= BD_LITERAL; out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("<PRE>\n"); } curpos=0; fillout=0; } c=skip_till_newline(c); break; } case V('E','d'): /* BSD mandoc */ if (mandoc_bd_options & BD_LITERAL) { if (!fillout) { out_html(change_to_font(0)); out_html(change_to_size('0')); out_html("</PRE>\n"); } } if (mandoc_bd_options & BD_INDENT) out_html("</BLOCKQUOTE>\n"); curpos=0; fillout=1; c=skip_till_newline(c); break; case V('B','e'): /* BSD mandoc */ c=c+j; if (fillout) out_html("<P>"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('X','r'): /* BSD mandoc */ { /* Translate xyz 1 to xyz(1) * Allow for multiple spaces. Allow the section to be missing. */ char buff[NULL_TERMINATED(MED_STR_MAX)]; char *bufptr; trans_char(c,'"','\a'); bufptr = buff; c = c+j; if (*c == '\n') c++; /* Skip spaces */ while (isspace(*c) && *c != '\n') c++; while (isalnum(*c) || *c == '_' || *c == '-') { /* Copy the xyz part */ *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } while (isspace(*c) && *c != '\n') c++; /* Skip spaces */ if (isdigit(*c)) { /* Convert the number if there is one */ *bufptr = '('; bufptr++; if (bufptr < buff + MED_STR_MAX) { while (isalnum(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; c++; } if (bufptr < buff + MED_STR_MAX) { *bufptr = ')'; bufptr++; } } } while (*c != '\n') { /* Copy the remainder */ if (!isspace(*c)) { *bufptr = *c; bufptr++; if (bufptr >= buff + MED_STR_MAX) break; } c++; } *bufptr = '\n'; bufptr[1] = 0; scan_troff_mandoc(buff, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } break; case V('F','l'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; out_html("-"); if (*c!='\n') { out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); } out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('P','a'): /* BSD mandoc */ case V('P','f'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('P','p'): /* BSD mandoc */ if (fillout) out_html("<P>\n"); else { out_html(NEWLINE); NEWLINE[0]='\n'; } curpos=0; c=skip_till_newline(c); break; case V('D','q'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("``"); c=scan_troff_mandoc(c, 1, NULL); out_html("''"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('O','p'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('O','o'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('R')); out_html("["); c=scan_troff_mandoc(c, 1, NULL); if (fillout) curpos++; else curpos=0; break; case V('O','c'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html("]"); if (fillout) curpos++; else curpos=0; break; case V('P','q'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("("); c=scan_troff_mandoc(c, 1, NULL); out_html(")"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('Q','l'): /* BSD mandoc */ { /* Single quote first word in the line */ char *sp; trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; sp = c; do { /* Find first whitespace after the * first word that isn't a mandoc macro */ while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; } while (*sp && isupper(*(sp-2)) && islower(*(sp-1))); /* Use a newline to mark the end of text to * be quoted */ if (*sp) *sp = '\n'; out_html("`"); /* Quote the text */ c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case V('S','q'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html("`"); c=scan_troff_mandoc(c, 1, NULL); out_html("'"); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('A','r'): /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') { /* An empty Ar means "file ..." */ out_html("file ..."); } else { c=scan_troff_mandoc(c, 1, NULL); } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('A','d'): /* BSD mandoc */ case V('E','m'): /* BSD mandoc */ case V('V','a'): /* BSD mandoc */ case V('X','c'): /* BSD mandoc */ /* parse one line in italics */ out_html(change_to_font('I')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('N','d'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(" - "); c=scan_troff_mandoc(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('N','m'): /* BSD mandoc */ { static char mandoc_name[NULL_TERMINATED(SMALL_STR_MAX)] = ""; trans_char(c,'"','\a'); c=c+j; if (mandoc_synopsis) { /* Break lines only in the Synopsis. * The Synopsis section seems to be treated * as a special case - Bummer! */ static int count = 0; /* Don't break on the first Nm */ if (count) { out_html("<BR>"); } else { char *end = strchr(c, '\n'); if (end) { /* Remember the name for later. */ strlimitcpy(mandoc_name, c, end - c, SMALL_STR_MAX); } } count++; } out_html(change_to_font('B')); while (*c == ' '|| *c == '\t') c++; if (*c == '\n') { /* If Nm has no argument, use one from an earlier * Nm command that did have one. Hope there aren't * too many commands that do this. */ out_html(mandoc_name); } else { c=scan_troff_mandoc(c, 1, NULL); } out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; } case V('C','d'): /* BSD mandoc */ case V('C','m'): /* BSD mandoc */ case V('I','c'): /* BSD mandoc */ case V('M','s'): /* BSD mandoc */ case V('O','r'): /* BSD mandoc */ case V('S','y'): /* BSD mandoc */ /* parse one line in bold */ out_html(change_to_font('B')); trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('D','v'): /* BSD mandoc */ case V('E','v'): /* BSD mandoc */ case V('F','r'): /* BSD mandoc */ case V('L','i'): /* BSD mandoc */ case V('N','o'): /* BSD mandoc */ case V('N','s'): /* BSD mandoc */ case V('T','n'): /* BSD mandoc */ case V('n','N'): /* BSD mandoc */ trans_char(c,'"','\a'); c=c+j; if (*c=='\n') c++; out_html(change_to_font('B')); c=scan_troff_mandoc(c, 1, NULL); out_html(change_to_font('R')); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; break; case V('%','A'): /* BSD mandoc biblio stuff */ case V('%','D'): case V('%','N'): case V('%','O'): case V('%','P'): case V('%','Q'): case V('%','V'): c=c+j; if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ if (fillout) curpos++; else curpos=0; break; case V('%','B'): case V('%','J'): case V('%','R'): case V('%','T'): c=c+j; out_html(change_to_font('I')); if (*c=='\n') c++; c=scan_troff(c, 1, NULL); /* Don't allow embedded mandoc coms */ out_html(change_to_font('R')); if (fillout) curpos++; else curpos=0; break; default: /* search macro database of self-defined macros */ owndef = defdef; while (owndef && owndef->nr!=i) owndef=owndef->next; if (owndef) { char **oldargument; int deflen; int onff; sl=fill_words(c+j, wordlist, &words); c=sl+1; *sl='\0'; for (i=1;i<words; i++) wordlist[i][-1]='\0'; for (i=0; i<words; i++) { char *h=NULL; if (mandoc_command) { scan_troff_mandoc(wordlist[i],1,&h); } else { scan_troff(wordlist[i],1,&h); } wordlist[i] = qstrdup(h); delete [] h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; if (mandoc_command) { scan_troff_mandoc(owndef->st+deflen+2, 0, NULL); } else { scan_troff(owndef->st+deflen+2, 0, NULL); } newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) delete [] wordlist[i]; *sl='\n'; } else if (mandoc_command && ((isupper(*c) && islower(*(c+1))) || (islower(*c) && isupper(*(c+1)))) ) { /* Let through any BSD mandoc commands that haven't * been delt with. * I don't want to miss anything out of the text. */ char buf[4]; strncpy(buf,c,2); buf[2] = ' '; buf[3] = '\0'; out_html(buf); /* Print the command (it might just be text). */ c=c+j; trans_char(c,'"','\a'); if (*c=='\n') c++; out_html(change_to_font('R')); c=scan_troff(c, 1, NULL); out_html(NEWLINE); if (fillout) curpos++; else curpos=0; } else { c=skip_till_newline(c); } break; } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;} |
|
QString signalName() const { return m_signalName; }; | virtual QString signalName() const { return m_signalName; }; | QString signalName() const { return m_signalName; }; |
int signalNumber() const { return m_signalnum; }; | virtual int signalNumber() const { return m_signalnum; }; | int signalNumber() const { return m_signalnum; }; |
VG_(debugLog)(1, "syswrap-x86-netbsd", "entering VG_(main_thread_wrapper_NORETURN)\n"); | VG_(printf)( "syswrap-x86-netbsd entering VG_(main_thread_wrapper_NORETURN)\n"); | void VG_(main_thread_wrapper_NORETURN)(ThreadId tid){ VG_(debugLog)(1, "syswrap-x86-netbsd", "entering VG_(main_thread_wrapper_NORETURN)\n"); UWord* esp = allocstack(tid); /* shouldn't be any other threads around yet */ vg_assert( VG_(count_living_threads)() == 1 ); call_on_new_stack_0_1( (Addr)esp, /* stack */ 0, /*bogus return address*/ run_a_thread_NORETURN, /* fn to call */ (Word)tid /* arg to give it */ ); /*NOTREACHED*/ vg_assert(0);} |
VG_(printf)("calling call on new_stack\n"); | void VG_(main_thread_wrapper_NORETURN)(ThreadId tid){ VG_(debugLog)(1, "syswrap-x86-netbsd", "entering VG_(main_thread_wrapper_NORETURN)\n"); UWord* esp = allocstack(tid); /* shouldn't be any other threads around yet */ vg_assert( VG_(count_living_threads)() == 1 ); call_on_new_stack_0_1( (Addr)esp, /* stack */ 0, /*bogus return address*/ run_a_thread_NORETURN, /* fn to call */ (Word)tid /* arg to give it */ ); /*NOTREACHED*/ vg_assert(0);} |
|
qDebug( "[%s] ", (*i) ); | qDebug( "[%s] ", (const char*)(*i).utf8() ); | virtual void dump( ) const { if ( QVariant::StringList == value_.type() ) { QStringList sl = value_.toStringList(); for ( QStringList::const_iterator i = sl.begin(); i != sl.end(); ++i ) { qDebug( "[%s] ", (*i) ); } } else { qDebug( "%s", value_.toString() ); } } |
qDebug( "%s", value_.toString() ); | qDebug( "%s", (const char*)value_.toString().utf8() ); | virtual void dump( ) const { if ( QVariant::StringList == value_.type() ) { QStringList sl = value_.toStringList(); for ( QStringList::const_iterator i = sl.begin(); i != sl.end(); ++i ) { qDebug( "[%s] ", (*i) ); } } else { qDebug( "%s", value_.toString() ); } } |
WNDCLASSFc.lpszMenuName = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "lpszMenuName", "I"); WNDCLASSFc.hbrBackground = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hbrBackground", "I"); WNDCLASSFc.hCursor = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hCursor", "I"); WNDCLASSFc.hIcon = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hIcon", "I"); WNDCLASSFc.hInstance = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hInstance", "I"); WNDCLASSFc.cbWndExtra = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "cbWndExtra", "I"); WNDCLASSFc.cbClsExtra = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "cbClsExtra", "I"); WNDCLASSFc.lpfnWndProc = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "lpfnWndProc", "I"); WNDCLASSFc.style = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "style", "I"); | void cacheWNDCLASSFields(JNIEnv *env, jobject lpObject){ if (WNDCLASSFc.cached) return; WNDCLASSFc.clazz = (*env)->GetObjectClass(env, lpObject); WNDCLASSFc.lpszClassName = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "lpszClassName", "I"); WNDCLASSFc.lpszMenuName = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "lpszMenuName", "I"); WNDCLASSFc.hbrBackground = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hbrBackground", "I"); WNDCLASSFc.hCursor = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hCursor", "I"); WNDCLASSFc.hIcon = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hIcon", "I"); WNDCLASSFc.hInstance = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "hInstance", "I"); WNDCLASSFc.cbWndExtra = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "cbWndExtra", "I"); WNDCLASSFc.cbClsExtra = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "cbClsExtra", "I"); WNDCLASSFc.lpfnWndProc = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "lpfnWndProc", "I"); WNDCLASSFc.style = (*env)->GetFieldID(env, WNDCLASSFc.clazz, "style", "I"); WNDCLASSFc.cached = 1;} |
|
int read = f.readLine( buf.data(), buf.size() ); | int read = f.readBlock( buf.data(), buf.size() ); | static void copyFile(QFile& tmp, QString const& filename, bool ){ QFile f( filename ); if ( f.open(IO_ReadOnly) ) { QCString buf( 8192 ); while ( !f.atEnd() ) { int read = f.readLine( buf.data(), buf.size() ); if ( read > 0 ) tmp.writeBlock( buf.data(), read ); } }} |
KHMainWindow *mw = new KHMainWindow(url); | MainWindow *mw = new MainWindow(url); | extern "C" int kdemain(int argc, char *argv[]){ KAboutData aboutData( "khelpcenter", I18N_NOOP("KDE HelpCenter"), HELPCENTER_VERSION, I18N_NOOP("The KDE Help Center"), KAboutData::License_GPL, "(c) 1999-2000, Matthias Elter"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); KApplication::addCmdLineOptions(); KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KURL url; if (args->count()) url = args->url(0); KHMainWindow *mw = new KHMainWindow(url); mw->show(); return app.exec();} |
ref++; | return ++ref; | int get() { assert(ref >= 0); if (ref == 0) lru_pin(); ref++; } |
t << "# Themes/Styles in the control center and disable the checkbox " << endl; | t << "# Look and Feel/Styles in the control center and disable the checkbox " << endl; | static void createGtkrc( bool exportColors, const QColorGroup& cg ){ QCString filename = ::getenv("HOME"); filename += "/.gtkrc-kde"; QFile f( filename ); if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Latin1 ); t << "# created by KDE, " << QDateTime::currentDateTime().toString() << endl; t << "#" << endl; t << "# If you do not want KDE to override your GTK settings, select" << endl; t << "# Themes/Styles in the control center and disable the checkbox " << endl; t << "# \"Apply fonts and colors to non-KDE apps\"" << endl; t << "#" << endl; t << endl; t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; }} |
error("Exiting on signal %d", sig); | fprintf(stderr, "Exiting on signal %d\n", sig); | void signal_exit(int sig){ error("Exiting on signal %d", sig); exit(1);} |
QFile f( locateLocal("config", "gtkrc" ) ); | KSaveFile saveFile( locateLocal( "config", "gtkrc" ) ); if ( saveFile.status() != 0 || saveFile.textStream() == 0L ) return; | static void createGtkrc( bool exportColors, const QColorGroup& cg ){ QFile f( locateLocal("config", "gtkrc" ) ); // lukas: why does it create in ~/.kde/share/config ??? if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Locale ); t << i18n( "# created by KDE, %1\n" "#\n" "# If you do not want KDE to override your GTK settings, select\n" "# Appearance & Themes -> Colors in the Control Center and disable the checkbox\n" "# \"Apply colors to non-KDE applications\"\n" "#\n" "#\n").arg(QDateTime::currentDateTime().toString()).local8Bit(); t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; }} |
if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Locale ); | QTextStream& t = *saveFile.textStream(); t.setEncoding( QTextStream::Locale ); | static void createGtkrc( bool exportColors, const QColorGroup& cg ){ QFile f( locateLocal("config", "gtkrc" ) ); // lukas: why does it create in ~/.kde/share/config ??? if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Locale ); t << i18n( "# created by KDE, %1\n" "#\n" "# If you do not want KDE to override your GTK settings, select\n" "# Appearance & Themes -> Colors in the Control Center and disable the checkbox\n" "# \"Apply colors to non-KDE applications\"\n" "#\n" "#\n").arg(QDateTime::currentDateTime().toString()).local8Bit(); t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; }} |
"#\n").arg(QDateTime::currentDateTime().toString()).local8Bit(); | "#\n").arg(QDateTime::currentDateTime().toString()); | static void createGtkrc( bool exportColors, const QColorGroup& cg ){ QFile f( locateLocal("config", "gtkrc" ) ); // lukas: why does it create in ~/.kde/share/config ??? if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Locale ); t << i18n( "# created by KDE, %1\n" "#\n" "# If you do not want KDE to override your GTK settings, select\n" "# Appearance & Themes -> Colors in the Control Center and disable the checkbox\n" "# \"Apply colors to non-KDE applications\"\n" "#\n" "#\n").arg(QDateTime::currentDateTime().toString()).local8Bit(); t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; }} |
t << "style \"default\"" << endl; | t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } | static void createGtkrc( bool exportColors, const QColorGroup& cg ){ QFile f( locateLocal("config", "gtkrc" ) ); // lukas: why does it create in ~/.kde/share/config ??? if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Locale ); t << i18n( "# created by KDE, %1\n" "#\n" "# If you do not want KDE to override your GTK settings, select\n" "# Appearance & Themes -> Colors in the Control Center and disable the checkbox\n" "# \"Apply colors to non-KDE applications\"\n" "#\n" "#\n").arg(QDateTime::currentDateTime().toString()).local8Bit(); t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; }} |
if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } | QColorGroup group = QToolTip::palette().active(); t << " bg[NORMAL] = " << color( group.background() ) << endl; t << " base[NORMAL] = " << color( group.base() ) << endl; t << " text[NORMAL] = " << color( group.text() ) << endl; t << " fg[NORMAL] = " << color( group.foreground() ) << endl; | static void createGtkrc( bool exportColors, const QColorGroup& cg ){ QFile f( locateLocal("config", "gtkrc" ) ); // lukas: why does it create in ~/.kde/share/config ??? if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Locale ); t << i18n( "# created by KDE, %1\n" "#\n" "# If you do not want KDE to override your GTK settings, select\n" "# Appearance & Themes -> Colors in the Control Center and disable the checkbox\n" "# \"Apply colors to non-KDE applications\"\n" "#\n" "#\n").arg(QDateTime::currentDateTime().toString()).local8Bit(); t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; }} |
t << "class \"*\" style \"default\"" << endl; | t << "widget \"gtk-tooltips\" style \"ToolTip\"" << endl; t << endl; t << "style \"MenuItem\"" << endl; t << "{" << endl; t << " bg[PRELIGHT] = " << color( cg.highlight() ) << endl; t << "}" << endl; t << endl; t << "class \"*MenuItem\" style \"MenuItem\"" << endl; | static void createGtkrc( bool exportColors, const QColorGroup& cg ){ QFile f( locateLocal("config", "gtkrc" ) ); // lukas: why does it create in ~/.kde/share/config ??? if ( f.open( IO_WriteOnly) ) { QTextStream t( &f ); t.setEncoding( QTextStream::Locale ); t << i18n( "# created by KDE, %1\n" "#\n" "# If you do not want KDE to override your GTK settings, select\n" "# Appearance & Themes -> Colors in the Control Center and disable the checkbox\n" "# \"Apply colors to non-KDE applications\"\n" "#\n" "#\n").arg(QDateTime::currentDateTime().toString()).local8Bit(); t << "style \"default\"" << endl; t << "{" << endl; if (exportColors) { t << " bg[NORMAL] = " << color( cg.background() ) << endl; t << " bg[SELECTED] = " << color( cg.highlight() ) << endl; t << " bg[INSENSITIVE] = " << color( cg.background() ) << endl; t << " bg[ACTIVE] = " << color( cg.mid() ) << endl; t << " bg[PRELIGHT] = " << color( cg.background() ) << endl; t << endl; t << " base[NORMAL] = " << color( cg.base() ) << endl; t << " base[SELECTED] = " << color( cg.highlight() ) << endl; t << " base[INSENSITIVE] = " << color( cg.background() ) << endl; t << " base[ACTIVE] = " << color( cg.base() ) << endl; t << " base[PRELIGHT] = " << color( cg.base() ) << endl; t << endl; t << " text[NORMAL] = " << color( cg.text() ) << endl; t << " text[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " text[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " text[ACTIVE] = " << color( cg.text() ) << endl; t << " text[PRELIGHT] = " << color( cg.text() ) << endl; t << endl; t << " fg[NORMAL] = " << color( cg.foreground() ) << endl; t << " fg[SELECTED] = " << color( cg.highlightedText() ) << endl; t << " fg[INSENSITIVE] = " << color( cg.mid() ) << endl; t << " fg[ACTIVE] = " << color( cg.foreground() ) << endl; t << " fg[PRELIGHT] = " << color( cg.foreground() ) << endl; } t << "}" << endl; t << endl; t << "class \"*\" style \"default\"" << endl; t << endl; }} |
if (cur == NULL) return(NULL); if (cur->type != XML_NAMESPACE_DECL) return(NULL); if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) node = NULL; | xsltCopyNamespaceList(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNsPtr cur) { xmlNsPtr ret = NULL; xmlNsPtr p = NULL,q; const xmlChar *URI; while (cur != NULL) { if (!xmlStrEqual(cur->href, XSLT_NAMESPACE)) { /* TODO apply cascading */ URI = (const xmlChar *) xmlHashLookup(ctxt->style->nsAliases, cur->href); if (URI != NULL) { q = xmlNewNs(node, URI, cur->prefix); } else { q = xmlNewNs(node, cur->href, cur->prefix); } if (p == NULL) { ret = p = q; } else { p->next = q; p = q; } } cur = cur->next; } return(ret);} |
|
"xsltApplyStylesheet: insupported method xhtml, using html\n", | "xsltApplyStylesheet: unsupported method xhtml, using html\n", | xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc, const char **params) { xmlDocPtr res = NULL; xsltTransformContextPtr ctxt = NULL; xmlNodePtr root; const xmlChar *method; const xmlChar *doctypePublic; const xmlChar *doctypeSystem; const xmlChar *version; xsltStackElemPtr variables; xsltStackElemPtr vptr; if ((style == NULL) || (doc == NULL)) return(NULL); ctxt = xsltNewTransformContext(style, doc); xsltRegisterExtras(ctxt); if (ctxt == NULL) return(NULL); XSLT_GET_IMPORT_PTR(method, style, method) XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic) XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem) XSLT_GET_IMPORT_PTR(version, style, version) if ((method != NULL) && (!xmlStrEqual(method, (const xmlChar *) "xml"))) { if (xmlStrEqual(method, (const xmlChar *) "html")) { ctxt->type = XSLT_OUTPUT_HTML; if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res = htmlNewDoc(doctypeSystem, doctypePublic); else { if (version == NULL) version = (const xmlChar *) "4.0";#ifdef XSLT_GENERATE_HTML_DOCTYPE xsltGetHTMLIDs(version, &doctypePublic, &doctypeSystem);#endif res = htmlNewDoc(doctypeSystem, doctypePublic); } if (res == NULL) goto error; } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) { xsltGenericError(xsltGenericErrorContext, "xsltApplyStylesheet: insupported method xhtml, using html\n", style->method); ctxt->type = XSLT_OUTPUT_HTML; res = htmlNewDoc(doctypeSystem, doctypePublic); if (res == NULL) goto error; } else if (xmlStrEqual(style->method, (const xmlChar *) "text")) { ctxt->type = XSLT_OUTPUT_TEXT; res = xmlNewDoc(style->version); if (res == NULL) goto error; } else { xsltGenericError(xsltGenericErrorContext, "xsltApplyStylesheet: insupported method %s\n", style->method); goto error; } } else { ctxt->type = XSLT_OUTPUT_XML; res = xmlNewDoc(style->version); if (res == NULL) goto error; } res->charset = XML_CHAR_ENCODING_UTF8; if (style->encoding != NULL) res->encoding = xmlStrdup(style->encoding); variables = style->variables; /* * Start the evaluation, evaluate the params, the stylesheets globals * and start by processing the top node. */ ctxt->output = res; ctxt->insert = (xmlNodePtr) res; ctxt->globalVars = xmlHashCreate(20); if (params != NULL) xsltEvalUserParams(ctxt, params); xsltEvalGlobalVariables(ctxt); ctxt->node = (xmlNodePtr) doc; varsPush(ctxt, NULL); xsltProcessOneNode(ctxt, ctxt->node); xsltFreeStackElemList(varsPop(ctxt)); xsltCleanupTemplates(style); /* TODO: <- style should be read only */ /* * Now cleanup our variables so stylesheet can be re-used * * TODO: this is not needed anymore global variables are copied * and not evaluated directly anymore, keep this as a check */ if (style->variables != variables) { vptr = style->variables; while (vptr->next!=variables) vptr = vptr->next; vptr->next = NULL; xsltFreeStackElemList(style->variables); style->variables = variables; } vptr = style->variables; while(vptr!=NULL) { if (vptr->computed) { if (vptr->value != NULL) { xmlXPathFreeObject(vptr->value); vptr->value = NULL; vptr->computed = 0; } } vptr = vptr->next; } /* * Do some post processing work depending on the generated output */ root = xmlDocGetRootElement(res); if (root != NULL) { /* * Apply the default selection of the method */ if ((method == NULL) && (root->ns == NULL) && (!xmlStrcasecmp(root->name, (const xmlChar *) "html"))) { xmlNodePtr tmp; tmp = res->children; while ((tmp != NULL) && (tmp != root)) { if (tmp->type == XML_ELEMENT_NODE) break; if ((tmp->type == XML_TEXT_NODE) && (!xmlIsBlankNode(tmp))) break; } if (tmp == root) { ctxt->type = XSLT_OUTPUT_HTML; res->type = XML_HTML_DOCUMENT_NODE; if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res->intSubset = xmlCreateIntSubset(res, root->name, doctypePublic, doctypeSystem);#ifdef XSLT_GENERATE_HTML_DOCTYPE else { if (version == NULL) version = (const xmlChar *) "4.0"; xsltGetHTMLIDs(version, &doctypePublic, &doctypeSystem); if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res->intSubset = xmlCreateIntSubset(res, root->name, doctypePublic, doctypeSystem); }#endif } } if (ctxt->type == XSLT_OUTPUT_XML) { XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic) XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem) if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res->intSubset = xmlCreateIntSubset(res, root->name, doctypePublic, doctypeSystem); } } xmlXPathFreeNodeSet(ctxt->nodeList); xsltFreeTransformContext(ctxt); return(res);error: if (res != NULL) xmlFreeDoc(res); if (ctxt != NULL) xsltFreeTransformContext(ctxt); return(NULL);} |
"xsltApplyStylesheet: insupported method %s\n", | "xsltApplyStylesheet: unsupported method %s\n", | xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc, const char **params) { xmlDocPtr res = NULL; xsltTransformContextPtr ctxt = NULL; xmlNodePtr root; const xmlChar *method; const xmlChar *doctypePublic; const xmlChar *doctypeSystem; const xmlChar *version; xsltStackElemPtr variables; xsltStackElemPtr vptr; if ((style == NULL) || (doc == NULL)) return(NULL); ctxt = xsltNewTransformContext(style, doc); xsltRegisterExtras(ctxt); if (ctxt == NULL) return(NULL); XSLT_GET_IMPORT_PTR(method, style, method) XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic) XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem) XSLT_GET_IMPORT_PTR(version, style, version) if ((method != NULL) && (!xmlStrEqual(method, (const xmlChar *) "xml"))) { if (xmlStrEqual(method, (const xmlChar *) "html")) { ctxt->type = XSLT_OUTPUT_HTML; if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res = htmlNewDoc(doctypeSystem, doctypePublic); else { if (version == NULL) version = (const xmlChar *) "4.0";#ifdef XSLT_GENERATE_HTML_DOCTYPE xsltGetHTMLIDs(version, &doctypePublic, &doctypeSystem);#endif res = htmlNewDoc(doctypeSystem, doctypePublic); } if (res == NULL) goto error; } else if (xmlStrEqual(method, (const xmlChar *) "xhtml")) { xsltGenericError(xsltGenericErrorContext, "xsltApplyStylesheet: insupported method xhtml, using html\n", style->method); ctxt->type = XSLT_OUTPUT_HTML; res = htmlNewDoc(doctypeSystem, doctypePublic); if (res == NULL) goto error; } else if (xmlStrEqual(style->method, (const xmlChar *) "text")) { ctxt->type = XSLT_OUTPUT_TEXT; res = xmlNewDoc(style->version); if (res == NULL) goto error; } else { xsltGenericError(xsltGenericErrorContext, "xsltApplyStylesheet: insupported method %s\n", style->method); goto error; } } else { ctxt->type = XSLT_OUTPUT_XML; res = xmlNewDoc(style->version); if (res == NULL) goto error; } res->charset = XML_CHAR_ENCODING_UTF8; if (style->encoding != NULL) res->encoding = xmlStrdup(style->encoding); variables = style->variables; /* * Start the evaluation, evaluate the params, the stylesheets globals * and start by processing the top node. */ ctxt->output = res; ctxt->insert = (xmlNodePtr) res; ctxt->globalVars = xmlHashCreate(20); if (params != NULL) xsltEvalUserParams(ctxt, params); xsltEvalGlobalVariables(ctxt); ctxt->node = (xmlNodePtr) doc; varsPush(ctxt, NULL); xsltProcessOneNode(ctxt, ctxt->node); xsltFreeStackElemList(varsPop(ctxt)); xsltCleanupTemplates(style); /* TODO: <- style should be read only */ /* * Now cleanup our variables so stylesheet can be re-used * * TODO: this is not needed anymore global variables are copied * and not evaluated directly anymore, keep this as a check */ if (style->variables != variables) { vptr = style->variables; while (vptr->next!=variables) vptr = vptr->next; vptr->next = NULL; xsltFreeStackElemList(style->variables); style->variables = variables; } vptr = style->variables; while(vptr!=NULL) { if (vptr->computed) { if (vptr->value != NULL) { xmlXPathFreeObject(vptr->value); vptr->value = NULL; vptr->computed = 0; } } vptr = vptr->next; } /* * Do some post processing work depending on the generated output */ root = xmlDocGetRootElement(res); if (root != NULL) { /* * Apply the default selection of the method */ if ((method == NULL) && (root->ns == NULL) && (!xmlStrcasecmp(root->name, (const xmlChar *) "html"))) { xmlNodePtr tmp; tmp = res->children; while ((tmp != NULL) && (tmp != root)) { if (tmp->type == XML_ELEMENT_NODE) break; if ((tmp->type == XML_TEXT_NODE) && (!xmlIsBlankNode(tmp))) break; } if (tmp == root) { ctxt->type = XSLT_OUTPUT_HTML; res->type = XML_HTML_DOCUMENT_NODE; if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res->intSubset = xmlCreateIntSubset(res, root->name, doctypePublic, doctypeSystem);#ifdef XSLT_GENERATE_HTML_DOCTYPE else { if (version == NULL) version = (const xmlChar *) "4.0"; xsltGetHTMLIDs(version, &doctypePublic, &doctypeSystem); if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res->intSubset = xmlCreateIntSubset(res, root->name, doctypePublic, doctypeSystem); }#endif } } if (ctxt->type == XSLT_OUTPUT_XML) { XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic) XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem) if (((doctypePublic != NULL) || (doctypeSystem != NULL))) res->intSubset = xmlCreateIntSubset(res, root->name, doctypePublic, doctypeSystem); } } xmlXPathFreeNodeSet(ctxt->nodeList); xsltFreeTransformContext(ctxt); return(res);error: if (res != NULL) xmlFreeDoc(res); if (ctxt != NULL) xsltFreeTransformContext(ctxt); return(NULL);} |
int i, second; | int i, count = 0; if (domainlist == NULL) return; | find_domain (const char *domain, ypbind_resp *result){ int i, second; pthread_rdwr_rlock_np (&domainlock); second = 0; /* Try only once to find a new server for a unbounded domain */ i = 0; while (i < max_domains) { if (strcmp (domainlist[i].domain, domain) == 0) { if (domainlist[i].active >= 0) { result->ypbind_status = YPBIND_SUCC_VAL; memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, &domainlist[i].server[domainlist[i].active].addr, sizeof (struct in_addr)); memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, &domainlist[i].server[domainlist[i].active].port, sizeof (unsigned short int)); if (debug_flag) log_msg (LOG_DEBUG, "YPBINDPROC_DOMAIN: server '%s', port %d", inet_ntoa(domainlist[i].server[domainlist[i].active].addr), ntohs(domainlist[i].server[domainlist[i].active].port)); break; } else if (domainlist[i].active == -2) { result->ypbind_status = YPBIND_SUCC_VAL; memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, &domainlist[i].ypset.addr, sizeof (struct in_addr)); memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, &domainlist[i].ypset.port, sizeof (unsigned short int)); if (debug_flag) log_msg (LOG_DEBUG, "YPBINDPROC_DOMAIN: server '%s', port %d", inet_ntoa(domainlist[i].ypset.addr), ntohs(domainlist[i].ypset.port)); break; } else { if (second) { second = 0; break; } /* Look, if we could find a new server for this domain. But only, if the other thread is not searching already */ pthread_rdwr_runlock_np (&domainlock); if (pthread_mutex_trylock (&search_lock) == 0) { if (debug_flag) log_msg (LOG_DEBUG, "trylock = success"); if (!ping_all (&domainlist[i]) && domainlist[i].use_broadcast) do_broadcast (&domainlist[i]); pthread_mutex_unlock (&search_lock); ++second; /* Get the read lock again for next run. */ pthread_rdwr_rlock_np (&domainlock); continue; } else return; pthread_rdwr_rlock_np (&domainlock); } } ++i; } pthread_rdwr_runlock_np (&domainlock); return;} |
second = 0; i = 0; while (i < max_domains) | for (i = 0; i < max_domains; ++i) if (strcmp (domainlist[i].domain, domain) == 0) break; if ( i >= max_domains) | find_domain (const char *domain, ypbind_resp *result){ int i, second; pthread_rdwr_rlock_np (&domainlock); second = 0; /* Try only once to find a new server for a unbounded domain */ i = 0; while (i < max_domains) { if (strcmp (domainlist[i].domain, domain) == 0) { if (domainlist[i].active >= 0) { result->ypbind_status = YPBIND_SUCC_VAL; memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, &domainlist[i].server[domainlist[i].active].addr, sizeof (struct in_addr)); memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, &domainlist[i].server[domainlist[i].active].port, sizeof (unsigned short int)); if (debug_flag) log_msg (LOG_DEBUG, "YPBINDPROC_DOMAIN: server '%s', port %d", inet_ntoa(domainlist[i].server[domainlist[i].active].addr), ntohs(domainlist[i].server[domainlist[i].active].port)); break; } else if (domainlist[i].active == -2) { result->ypbind_status = YPBIND_SUCC_VAL; memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, &domainlist[i].ypset.addr, sizeof (struct in_addr)); memcpy (&result->ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port, &domainlist[i].ypset.port, sizeof (unsigned short int)); if (debug_flag) log_msg (LOG_DEBUG, "YPBINDPROC_DOMAIN: server '%s', port %d", inet_ntoa(domainlist[i].ypset.addr), ntohs(domainlist[i].ypset.port)); break; } else { if (second) { second = 0; break; } /* Look, if we could find a new server for this domain. But only, if the other thread is not searching already */ pthread_rdwr_runlock_np (&domainlock); if (pthread_mutex_trylock (&search_lock) == 0) { if (debug_flag) log_msg (LOG_DEBUG, "trylock = success"); if (!ping_all (&domainlist[i]) && domainlist[i].use_broadcast) do_broadcast (&domainlist[i]); pthread_mutex_unlock (&search_lock); ++second; /* Get the read lock again for next run. */ pthread_rdwr_rlock_np (&domainlock); continue; } else return; pthread_rdwr_rlock_np (&domainlock); } } ++i; } pthread_rdwr_runlock_np (&domainlock); return;} |