📄 man2html.c
字号:
free(h); } fprintf(idxfile,"\n");#endif out_html("<A NAME=\""); out_html(idxlabel); /* this will not work in mosaic (due to a bug). ** Adding ' ' between '>' and '<' solves it, but creates ** some space. A normal space does not work. */ out_html("\"></A>"); break; 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'): 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'): if (itemdepth) { 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'): mode=1; 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 itemdepth--; } out_html(change_to_font(0)); out_html(change_to_size(0)); if (!fillout) { fillout=1; out_html("</PRE>"); } trans_char(c,'"', '\a'); add_to_index(mode, c); out_html("<A NAME=\""); out_html(label); /* for mosaic users */ if (mode) out_html("\"> </A>\n<H3>"); else out_html("\"> </A>\n<H2>"); c=scan_troff(c,1,NULL); if (mode) out_html("</H3>\n"); else out_html("</H2>\n"); curpos=0; break; case V('T','S'): c=scan_table(c); break; 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("<HTML><HEAD><TITLE>Manpage of "); out_html(wordlist[0]); out_html("</TITLE>\n</HEAD><BODY>\n<H1>"); out_html(wordlist[0]); out_html("</H1>\nSection: "); if (words>4) out_html(wordlist[4]); else out_html(section_name(wordlist[1])); out_html(" ("); out_html(wordlist[1]); if (words>2) { out_html(")<BR>Updated: "); scan_troff(wordlist[2], 1, NULL); } else out_html(")"); out_html("<BR><A HREF=\"#index\">Index</A>\n"); *sl='\n'; out_html("<HR>\n"); } 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'; c=lookup_abbrev(wordlist[0]); curpos+=strlen(c); out_html(c); 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) { if (de->st) free(de->st); 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 = (INTDEF*) malloc(sizeof(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; c=c+j; sl=fill_words(c, wordlist, &words); i=V(c[0],c[1]);j=2; if (words==1) wordlist[1]=".."; 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= (char*) malloc((j*2+4)*sizeof(char)); 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) { if (de->st) free(de->st); de->st=h; } else { de = (STRDEF*) malloc(sizeof(STRDEF)); de->nr=i; de->next=defdef; de->st=h; defdef=de; } } } c=skip_till_newline(c); 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; scan_troff(wordlist[i],1,&h); wordlist[i]=h; } for (i=words;i<20; i++) wordlist[i]=NULL; deflen = strlen(owndef->st); owndef->st[deflen+1]='a'; for (i=0; (owndef->st[deflen+2+i]=owndef->st[i]); i++); oldargument=argument; argument=wordlist; onff=newline_for_fun; scan_troff(owndef->st+deflen+2, 0, NULL); newline_for_fun=onff; argument=oldargument; for (i=0; i<words; i++) if (wordlist[i]) free(wordlist[i]); *sl='\n'; } else c=skip_till_newline(c); break; } } if (fillout) { out_html(NEWLINE); curpos++; } NEWLINE[0]='\n'; return c;}void flush(void){}static int contained_tab=0;char *scan_troff(char *c, int san, char **result){ /* san : stop at newline */ char *h; char intbuff[500]; int ibp=0;#define FLUSHIBP if (ibp) { intbuff[ibp]=0; out_html(intbuff); ibp=0; } char *exbuffer; int exbuffpos, exbuffmax, exscaninbuff, exnewline_for_fun; int usenbsp=0; exbuffer=buffer; exbuffpos=buffpos; exbuffmax=buffmax; exnewline_for_fun=newline_for_fun; exscaninbuff=scaninbuff; newline_for_fun=0; if (result) { if (*result) { buffer=*result; buffpos=strlen(buffer); buffmax=buffpos; } else { buffer=(char *) malloc(1000*sizeof(char)); buffpos=0; buffmax=1000; } scaninbuff=1; } h=c; /* start scanning */ while (*h && (!san || newline_for_fun || *h!='\n')) { if (*h==escapesym) { h++; FLUSHIBP; h = scan_escape(h); } else if (*h==controlsym && h[-1]=='\n') { h++; FLUSHIBP; h = scan_request(h); if (san && h[-1]=='\n') h--; } else if (*h==nobreaksym && h[-1]=='\n') { h++; FLUSHIBP; h = scan_request(h); if (san && h[-1]=='\n') h--; } else { if (h[-1]=='\n' && still_dd && isalnum(*h)) { /* sometimes a .HP request is not followed by a .br request */ FLUSHIBP; out_html("<DD>"); curpos=0; still_dd=0; } switch (*h) { case '&': intbuff[ibp++]='&'; intbuff[ibp++]='a'; intbuff[ibp++]='m'; intbuff[ibp++]='p'; intbuff[ibp++]=';'; curpos++; break; case '<': intbuff[ibp++]='&'; intbuff[ibp++]='l'; intbuff[ibp++]='t'; intbuff[ibp++]=';'; curpos++; break; case '>': intbuff[ibp++]='&'; intbuff[ibp++]='g'; intbuff[ibp++]='t'; intbuff[ibp++]=';'; curpos++; break; case '"': intbuff[ibp++]='&'; intbuff[ibp++]='q'; intbuff[ibp++]='u'; intbuff[ibp++]='o'; intbuff[ibp++]='t'; intbuff[ibp++]=';'; curpos++; break; case '\n': if (h[-1]=='\n' && fillout) { intbuff[ibp++]='<'; intbuff[ibp++]='P'; intbuff[ibp++]='>'; } if (contained_tab && fillout) { intbuff[ibp++]='<'; intbuff[ibp++]='B'; intbuff[ibp++]='R'; intbuff[ibp++]='>'; } contained_tab=0; curpos=0; usenbsp=0; intbuff[ibp++]='\n'; break; case '\t': { int curtab=0; contained_tab=1; FLUSHIBP; /* like a typewriter, not like TeX */ tabstops[19]=curpos+1; while (curtab<maxtstop && tabstops[curtab]<=curpos) curtab++; if (curtab<maxtstop) { if (!fillout) { while (curpos<tabstops[curtab]) { intbuff[ibp++]=' '; if (ibp>480) { FLUSHIBP; } curpos++; } } else { out_html("<TT>"); while (curpos<tabstops[curtab]) { out_html(" "); curpos++; } out_html("</TT>"); } } } break; default: if (*h==' ' && (h[-1]=='\n' || usenbsp)) { FLUSHIBP; if (!usenbsp && fillout) { out_html("<BR>"); curpos=0; } usenbsp=fillout; if (usenbsp) out_html(" "); else intbuff[ibp++]=' '; } else if (*h>31 && *h<127) intbuff[ibp++]=*h; else if (((unsigned char)(*h))>127) { intbuff[ibp++]='&'; intbuff[ibp++]='#'; intbuff[ibp++]='0'+((unsigned char)(*h))/100; intbuff[ibp++]='0'+(((unsigned char)(*h))%100)/10; intbuff[ibp++]='0'+((unsigned char)(*h))%10; intbuff[ibp++]=';'; } curpos++; break; } if (ibp>480) FLUSHIBP; h++; } } FLUSHIBP; if (buffer) buffer[buffpos]='\0'; if (san && *h) h++; newline_for_fun=exnewline_for_fun; if (result) { *result = buffer; buffer=exbuffer; buffpos=exbuffpos; buffmax=exbuffmax; scaninbuff=exscaninbuff; } return h;}char *sectionname=NULL;STRDEF *foundpages=NULL;int search_manpath_all(char *name){ char smfbuf[1000]; char cmpbuf[100]; int i,j,n,l,nr=0; DIR *dr; struct dirent *de; STRDEF *h=NULL; strcpy(cmpbuf,name); n=strlen(name); cmpbuf[n++]='.'; cmpbuf[n+1]='\0'; for (i=0; manpath[i]; i++) { strcpy(smfbuf, manpath[i]); l=strlen(smfbuf); strcpy(smfbuf+l, "man"); l+=3; smfbuf[l+1]='\0'; for (j=0; sections[j]; j++) { smfbuf[l]=sections[j]; cmpbuf[n]=sections[j]; if ((dr=opendir(smfbuf))) { while ((de=readdir(dr))) { if (!strncmp(de->d_name, cmpbuf, n+1)) { int stlen; if (h) { h->next=(STRDEF*) malloc(sizeof(STRDEF)); h=h->next; } else h=foundpages=(STRDEF*) malloc(sizeof(STRDEF)); h->nr=i*256+j; stlen=strlen(de->d_name)+1; h->st=(char*) malloc(stlen*sizeof(char)); nr++; strcpy(h->st, de->d_name); h->next=NULL; } } closedir(dr); } } } return nr;}int search_manpath_section(char *name, char* section){ char smfbuf[1000]; char cmpbuf[100]; int i,j,n,l,nr=0; DIR *dr; struct dirent *de; STRDEF *h=NULL; if (!section) return search_manpath_all(name); j=0; while (sections[j] && sections[j]!=section[0]) j++; if (!sections[j]) return search_manpath_all(name); strcpy(cmpbuf,name); n=strlen(name); cmpbuf[n++]='.'; cmpbuf[n++]=section[0]; cmpbuf[n]='\0'; for (i=0; manpath[i]; i++) { strcpy(smfbuf, manpath[i]); l=strlen(smfbuf); strcpy(smfbuf+l,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -