一个文本格式转化程序.mht

来自「精华BBS贴子」· MHT 代码 · 共 1,468 行 · 第 1/5 页

MHT
1,468
字号

                        if(write(dfd,s,2)&gt;=3D0) ;<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else return=20
                        (-1);<BR>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;=20
                        &nbsp;&nbsp;&nbsp;else =
if(write(dfd,&amp;c,1)&lt;0)=20
                        return (-1);<BR>&nbsp; &nbsp; &nbsp; &nbsp; =
}<BR>&nbsp;=20
                        &nbsp; if(flag=3D=3D0){<BR>&nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        close(sfd);<BR>&nbsp; &nbsp; &nbsp; &nbsp;=20
                        =
if((newfd=3Dopen(sfname,O_TRUNC|O_WRONLY))&lt;0)<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;err("can't=20
                        modify the sourse file");<BR>&nbsp; &nbsp; =
&nbsp; &nbsp;=20
                        <BR>&nbsp; &nbsp; &nbsp; &nbsp; if((buf=3D(char=20
                        *)malloc(BUFSIZE))=3D=3DNULL)<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;err("can't creat=20
                        buffer");<BR>&nbsp; &nbsp; &nbsp; &nbsp; =
<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; =
lseek(dfd,0,SEEK_SET);<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; =
for(;bytes&gt;0;){<BR>&nbsp; &nbsp;=20
                        &nbsp; &nbsp;&nbsp;=20
                        =
&nbsp;&nbsp;&nbsp;bytes=3Dread(dfd,buf,BUFSIZE);<BR>#ifdef=20
                        DEBUG<BR>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;=20
                        &nbsp;&nbsp;&nbsp;printf("%d bytes=20
                        read\n",bytes);<BR>#endif<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp;&nbsp;=20
                        =
&nbsp;&nbsp;&nbsp;if((bytes=3Dwrite(newfd,buf,bytes))&gt;=3D0){<BR>&nbsp;=
=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =

                        ;<BR>#ifdef DEBUG<BR>&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; printf("%d bytes write=20
                        \n",bytes);<BR>#endif<BR>&nbsp; &nbsp; &nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<BR>&nbsp; =
&nbsp; &nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else =
break;<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; =
}<BR>&nbsp;=20
                        &nbsp; close(sfd);<BR>&nbsp; &nbsp;=20
                        close(dfd);<BR>&nbsp; &nbsp; =
close(newfd);<BR>&nbsp;=20
                        &nbsp; if(buf!=3DNULL) free(buf);<BR>&nbsp; =
&nbsp; return=20
                        0;<BR>}<BR><BR>int cWtoU(int sfd,int dfd,int=20
                        flag)<BR>{<BR>&nbsp; &nbsp; char c;<BR>&nbsp; =
&nbsp;=20
                        char s[2];<BR>&nbsp; &nbsp; char =
*buf=3DNULL;<BR>&nbsp;=20
                        &nbsp; int ret;<BR>&nbsp; &nbsp; int =
bytes=3D1;<BR>&nbsp;=20
                        &nbsp; int newfd;<BR>&nbsp; &nbsp; <BR>&nbsp; =
&nbsp;=20
                        for(;read(sfd,&amp;c,1);){<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; if(c=3D=3D0xd){<BR>&nbsp; &nbsp; &nbsp; =
&nbsp;&nbsp;=20
                        &nbsp;&nbsp;&nbsp;s[0]=3Dc;<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp;&nbsp;=20
                        =
&nbsp;&nbsp;&nbsp;if(read(sfd,&amp;c,1)){<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =

                        if((s[1]=3Dc)=3D=3D0xa)<BR>&nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp;=20
                        &nbsp; &nbsp; &nbsp;&nbsp;=20
                        =
&nbsp;&nbsp;&nbsp;ret=3Dwrite(dfd,&amp;c,1);<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =

                        else<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp;=20
                        &nbsp;&nbsp;=20
                        =
&nbsp;&nbsp;&nbsp;ret=3Dwrite(dfd,s,2);<BR>&nbsp; &nbsp;=20
                        &nbsp; &nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;}<BR>&nbsp; &nbsp;=20
                        &nbsp; &nbsp;&nbsp;=20
                        &nbsp;&nbsp;&nbsp;if(ret&lt;0)<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;=20
                        &nbsp; &nbsp; &nbsp; return -1;<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;continue;<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; }<BR>&nbsp; &nbsp; &nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else=20
                        if(write(dfd,&amp;c,1)&lt;0) return =
(-1);<BR>&nbsp;=20
                        &nbsp; }<BR>&nbsp; &nbsp; =
if(flag=3D=3D0){<BR>&nbsp; &nbsp;=20
                        &nbsp; &nbsp; close(sfd);<BR>&nbsp; &nbsp; =
&nbsp; &nbsp;=20
                        =
if((newfd=3Dopen(sfname,O_TRUNC|O_WRONLY))&lt;0)<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;err("can't=20
                        modify the sourse file");<BR>&nbsp; &nbsp; =
&nbsp; &nbsp;=20
                        if((buf=3D(char =
*)malloc(BUFSIZE))=3D=3DNULL)<BR>&nbsp; &nbsp;=20
                        &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;err("can't =
creat=20
                        buffer");<BR>&nbsp; &nbsp; &nbsp; &nbsp;=20
                        lseek(dfd,0,SEEK_SET);<BR>&nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        for(;bytes&gt;0;){<BR>&nbsp; &nbsp; &nbsp; =
&nbsp;&nbsp;=20
                        =
&nbsp;&nbsp;&nbsp;bytes=3Dread(dfd,buf,BUFSIZE);<BR>#ifdef=20
                        DEBUG<BR>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;=20
                        &nbsp;&nbsp;&nbsp;printf("%d bytes=20
                        read\n",bytes);<BR>#endif<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp;&nbsp;=20
                        =
&nbsp;&nbsp;&nbsp;if((bytes=3Dwrite(newfd,buf,bytes))&gt;=3D0){<BR>&nbsp;=
=20
                        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =

                        ;<BR>#ifdef DEBUG<BR>&nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; printf("%d bytes write=20
                        \n",bytes);<BR>#endif<BR>&nbsp; &nbsp; &nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<BR>&nbsp; =
&nbsp; &nbsp;=20
                        &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else&nbsp;=20
                        &nbsp;break;<BR>&nbsp; &nbsp; &nbsp; &nbsp; =
}<BR>&nbsp;=20
                        &nbsp; }<BR>&nbsp; &nbsp; close(sfd);<BR>&nbsp; =
&nbsp;=20
                        close(dfd);<BR>&nbsp; &nbsp; =
close(newfd);<BR>&nbsp;=20
                        &nbsp; if(buf!=3DNULL) free(buf);<BR>&nbsp; =
&nbsp; return=20
                        0;<BR><BR>}<BR><BR>void Uerr(){<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; printf("Usage:convert &lt;sourseFile&gt;=20
                        [destFile] &lt;option&gt;\n");<BR>&nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; printf("option:<BR>&nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; &nbsp; &nbsp; \t-u:from unix to=20
                        windows.<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp;=20
                        &nbsp; &nbsp; \t-w:from windows to =
unix.\n");<BR>&nbsp;=20
                        &nbsp; &nbsp; &nbsp; exit(1);<BR>}<BR><BR>void =
err(char=20
                        *msg)<BR>{<BR>&nbsp; &nbsp; =
perror(msg);<BR>&nbsp;=20
                        &nbsp; exit(1);<BR>}<A name=3Dendpid317568></A> =
<BR></TD></TR>
                    <TR align=3Dright>
                      <TD vAlign=3Dbottom><BR><BR><BR><BR><BR><IMG=20
                        =
src=3D"http://25.20.176.12/bbs/images/common/sigline.gif"><BR>
                        <MARQUEE scrollAmount=3D3 behavior=3Dalternate=20
                        width=3D"90%"><FONT =
color=3D#0000ff>=BD=F0=A1=B0=D6=A5=A1=B1=D3=F1=A1=B0=D2=B6=A1=B1&nbsp;=20
                        =
&nbsp;=A1=B0=C3=CF=A1=B1=A1=B0=C3=C0=A1=B1=D2=D4=C7=F3</FONT></MARQUEE><I=
MG=20
                        onmouseover=3D"if(this.alt) =
this.style.cursor=3D'hand';"=20
                        =
onclick=3D"javascript:window.open('http://25.20.176.12/bbs/attachments/ex=
t_gif/Z5qC_sign.gif');"=20
                        =
src=3D"http://25.20.176.12/bbs/attachments/ext_gif/Z5qC_sign.gif"=20
                        =
onload=3D"javascript:if(this.width>screen.width-333) =
{this.width=3Dscreen.width-333;this.alt=3D'=B5=E3=BB=F7=D5=E2=C0=EF=D4=DA=
=D0=C2=B4=B0=BF=DA=D4=A4=C0=C0';}"=20
                        border=3D0><BR><FONT=20
                        =
color=3D#0000ff>=CA=C0=BC=E4=D7=EE=CD=B4=BF=E0=B5=C4=CA=C2=C4=AA=B9=FD=D3=
=DA=D4=B5=D2=D1=BE=A1=B6=F8=C7=E9=CE=B4=C1=CB=A1=AD=A1=AD</FONT></TD></TR=
></TBODY></TABLE></TD></TR>
              <TR bgColor=3D#e8f2ff>
                <TD class=3Dsmalltxt vAlign=3Dcenter><A=20
                  =
href=3D"http://25.20.176.12/bbs/viewthread.php?tid=3D33134#pid317568"><IM=
G=20
                  alt=3D=BB=D8=B5=BD=B5=DA1=CC=F9=BF=AA=CD=B7=20
                  =
src=3D"http://25.20.176.12/bbs/images/default/threadforward.gif"=20
                  align=3DabsMiddle border=3D0></A> 2004-6-7 09:34 =
PM</A> </TD>
                <TD vAlign=3Dcenter>
                  <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" =
border=3D0>
                    <TBODY>
                    <TR class=3Dsmalltxt>
                      <TD align=3Dleft><A=20
                        =
href=3D"http://25.20.176.12/bbs/viewpro.php?username=3Djyarmy"><IMG=20
                        alt=3D=B2=E9=BF=B4=D7=CA=C1=CF=20
                        =
src=3D"http://25.20.176.12/bbs/images/default/profile.gif"=20
                        border=3D0></A>&nbsp; <A href=3D"http:///"=20
                        target=3D_blank><IMG =
alt=3D=B7=C3=CE=CA=D6=F7=D2=B3=20
                        =
src=3D"http://25.20.176.12/bbs/images/default/site.gif"=20
                        border=3D0></A>&nbsp; <A=20
                        =
href=3D"http://25.20.176.12/bbs/search.php?srchuname=3Djyarmy&amp;srchfid=
=3Dall&amp;srchfrom=3D0&amp;searchsubmit=3Dyes"><IMG=20
                        =
alt=3D=CB=D1=CB=F7=B8=C3=D3=C3=BB=A7=B5=C4=C8=AB=B2=BF=CC=FB=D7=D3=20
                        =
src=3D"http://25.20.176.12/bbs/images/default/find.gif"=20
                        border=3D0></A>&nbsp; <A=20
                        =
href=3D"http://25.20.176.12/bbs/pm.php?action=3Dsend&amp;username=3Djyarm=
y"=20
                        target=3D_blank><IMG =
alt=3D=B7=A2=B6=CC=CF=FB=CF=A2=20
                        =
src=3D"http://25.20.176.12/bbs/images/default/pm.gif"=20
                        border=3D0></A>&nbsp; </TD>
                      <TD align=3Dright>&nbsp;<A=20
                        =
href=3D"http://25.20.176.12/bbs/post.php?action=3Dreply&amp;fid=3D144&amp=
;tid=3D33134&amp;repquote=3D317568&amp;page=3D1"><IMG=20
                        alt=3D=D2=FD=D3=C3=BB=D8=B8=B4=20
                        =
src=3D"http://25.20.176.12/bbs/images/default/quote.gif"=20
                        border=3D0></A> &nbsp;<A=20
                        =
href=3D"http://25.20.176.12/bbs/misc.php?action=3Dreport&amp;fid=3D144&am=
p;tid=3D33134&amp;pid=3D317568"><IMG=20
                        =
alt=3D=CF=F2=B0=E6=D6=F7=B7=B4=D3=A6=D5=E2=B8=F6=CC=FB=D7=D3=20
                        =
src=3D"http://25.20.176.12/bbs/images/default/report.gif"=20
                        border=3D0></A> &nbsp;<SELECT=20
                        =
onchange=3D"if(this.options[this.selectedIndex].value !=3D '') =
{&#10;window.location=3D('misc.php?action=3Dkarma&amp;tid=3D33134&amp;pid=
=3D317568&amp;username=3Djyarmy&amp;score=3D'+this.options[this.selectedI=
ndex].value+'&amp;sid=3DIylZQBeP') }"=20
                        align=3DabsMiddle name=3Dfid> <OPTION value=3D"" =

                          selected>=C6=C0=B7=D6</OPTION> <OPTION =
value=3D"">----</OPTION>=20
                          <OPTION value=3D-4>-4</OPTION> <OPTION=20
                          value=3D-3>-3</OPTION> <OPTION =
value=3D-2>-2</OPTION>=20
                          <OPTION value=3D-1>-1</OPTION> <OPTION=20
                          value=3D1>+1</OPTION> <OPTION =
value=3D2>+2</OPTION>=20
                          <OPTION value=3D3>+3</OPTION> <OPTION=20
                          value=3D4>+4</OPTION> <OPTION =
value=3D5>+5</OPTION></SELECT>=20
                      =
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></T=
ABLE></A><A=20
      name=3Dpid319697>
      <TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" =
align=3Dcenter border=3D0>
        <TBODY>
        <TR>
          <TD bgColor=3Ddarkblue>
            <TABLE style=3D"TABLE-LAYOUT: fixed; WORD-WRAP: break-word"=20
            cellSpacing=3D1 cellPadding=3D4 width=3D"100%" border=3D0>
              <TBODY>
              <TR bgColor=3D#e8f2cf>
                <TD vAlign=3Dtop width=3D160>
                  <FIELDSET><LEGEND><A=20
                  =
href=3D"http://25.20.176.12/bbs/viewthread.php?tid=3D33134#endpid319697">=
<IMG=20
                  alt=3D=D7=AA=B5=BD=B5=DA2=CC=F9=C4=A9=CE=B2=20
                  =
src=3D"http://25.20.176.12/bbs/images/default/threadnext.gif"=20
                  border=3D0></A> <FONT =

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?