一个文本格式转化程序.mht
来自「精华BBS贴子」· MHT 代码 · 共 1,468 行 · 第 1/5 页
MHT
1,468 行
if(write(dfd,s,2)>=3D0) ;<BR> =
=20
else return=20
(-1);<BR> =20
else =
if(write(dfd,&c,1)<0)=20
return (-1);<BR> =
}<BR> =20
if(flag=3D=3D0){<BR> =
=20
close(sfd);<BR> =20
=
if((newfd=3Dopen(sfname,O_TRUNC|O_WRONLY))<0)<BR> =20
=
err("can't=20
modify the sourse file");<BR> =
=20
<BR> if((buf=3D(char=20
*)malloc(BUFSIZE))=3D=3DNULL)<BR> =
=20
err("can't creat=20
buffer");<BR> =
<BR> =20
=
lseek(dfd,0,SEEK_SET);<BR> =20
=
for(;bytes>0;){<BR> =20
=20
=
bytes=3Dread(dfd,buf,BUFSIZE);<BR>#ifdef=20
DEBUG<BR> =20
printf("%d bytes=20
read\n",bytes);<BR>#endif<BR> =
=20
=20
=
if((bytes=3Dwrite(newfd,buf,bytes))>=3D0){<BR> =
=20
=
;<BR>#ifdef DEBUG<BR> =
=20
printf("%d bytes write=20
\n",bytes);<BR>#endif<BR> =20
}<BR> =
=20
else =
break;<BR> =20
}<BR> =
}<BR> =20
close(sfd);<BR> =20
close(dfd);<BR> =
close(newfd);<BR> =20
if(buf!=3DNULL) free(buf);<BR> =
return=20
0;<BR>}<BR><BR>int cWtoU(int sfd,int dfd,int=20
flag)<BR>{<BR> char c;<BR> =
=20
char s[2];<BR> char =
*buf=3DNULL;<BR> =20
int ret;<BR> int =
bytes=3D1;<BR> =20
int newfd;<BR> <BR> =
=20
for(;read(sfd,&c,1);){<BR> =
=20
if(c=3D=3D0xd){<BR> =
=20
s[0]=3Dc;<BR> =
=20
=20
=
if(read(sfd,&c,1)){<BR> =20
=
if((s[1]=3Dc)=3D=3D0xa)<BR> =
=20
=20
=
ret=3Dwrite(dfd,&c,1);<BR> =20
=
else<BR> =
=20
=20
=
ret=3Dwrite(dfd,s,2);<BR> =20
=
}<BR> =20
=20
if(ret<0)<BR> =
=20
=
=20
return -1;<BR> =
=20
=
continue;<BR> =20
}<BR> =20
else=20
if(write(dfd,&c,1)<0) return =
(-1);<BR> =20
}<BR> =
if(flag=3D=3D0){<BR> =20
close(sfd);<BR> =
=20
=
if((newfd=3Dopen(sfname,O_TRUNC|O_WRONLY))<0)<BR> =20
=
err("can't=20
modify the sourse file");<BR> =
=20
if((buf=3D(char =
*)malloc(BUFSIZE))=3D=3DNULL)<BR> =20
err("can't =
creat=20
buffer");<BR> =20
lseek(dfd,0,SEEK_SET);<BR> =
=20
for(;bytes>0;){<BR> =
=20
=
bytes=3Dread(dfd,buf,BUFSIZE);<BR>#ifdef=20
DEBUG<BR> =20
printf("%d bytes=20
read\n",bytes);<BR>#endif<BR> =
=20
<BR> =
=20
=20
=
if((bytes=3Dwrite(newfd,buf,bytes))>=3D0){<BR> =
=20
=
;<BR>#ifdef DEBUG<BR> =
=20
printf("%d bytes write=20
\n",bytes);<BR>#endif<BR> =20
}<BR> =
=20
else =20
break;<BR> =
}<BR> =20
}<BR> close(sfd);<BR> =
=20
close(dfd);<BR> =
close(newfd);<BR> =20
if(buf!=3DNULL) free(buf);<BR> =
return=20
0;<BR><BR>}<BR><BR>void Uerr(){<BR> =
=20
printf("Usage:convert <sourseFile>=20
[destFile] <option>\n");<BR> =
=20
printf("option:<BR> =
=20
\t-u:from unix to=20
windows.<BR> =
=20
\t-w:from windows to =
unix.\n");<BR> =20
exit(1);<BR>}<BR><BR>void =
err(char=20
*msg)<BR>{<BR> =
perror(msg);<BR> =20
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 =20
=
=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> <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> <A=20
=
href=3D"http://25.20.176.12/bbs/search.php?srchuname=3Djyarmy&srchfid=
=3Dall&srchfrom=3D0&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> <A=20
=
href=3D"http://25.20.176.12/bbs/pm.php?action=3Dsend&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> </TD>
<TD align=3Dright> <A=20
=
href=3D"http://25.20.176.12/bbs/post.php?action=3Dreply&fid=3D144&=
;tid=3D33134&repquote=3D317568&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> <A=20
=
href=3D"http://25.20.176.12/bbs/misc.php?action=3Dreport&fid=3D144&am=
p;tid=3D33134&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> <SELECT=20
=
onchange=3D"if(this.options[this.selectedIndex].value !=3D '') =
{ window.location=3D('misc.php?action=3Dkarma&tid=3D33134&pid=
=3D317568&username=3Djyarmy&score=3D'+this.options[this.selectedI=
ndex].value+'&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 + -
显示快捷键?