Path: utzoo!dciem!nrcaer!scs!spl1!laidbak!att!pacbell!ames!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!natinst!bigtex!juniper!cutter!markh From: markh@cutter.UUCP (Mark Hebets) Newsgroups: comp.sys.ibm.pc Subject: Re: CR? LF? CRLF???? Message-ID: <384@cutter.UUCP> Date: 3 Jun 88 13:49:25 GMT Article-I.D.: cutter.384 References: <1770@loral.UUCP> Lines: 78 Summary: Use kermit, PC-NFS, or the following C code... In article <1770@loral.UUCP>, jlh@loral.UUCP (The Mad Merkin Hunter) writes: > I've downloaded some text files from a UN*X machine... > So, is there an easy way in DOS or MKS vi > to automatically do this conversion [LF->CR/LF] ? > Jim - If you use kermit to do the download, you can set the transfer mode to text instead of binary, and it fixes line endings on the fly. If you have access to a copy of PC-NFS, it includes the programs DOS2UNIX and UNIX2DOS that will do the conversion for you. The following programs are filters that will work on a Unix system. Feel free to hack them up. ----------------------------------------------------------- /** ** MJH 11/16/87 ** ** Read in an ASCII text file in Unix format, ** change all LF line endings to CR-LF **/ #include main() { int ch; /* if ch is a LF, write out CR first */ while( (ch=getchar())!=EOF ) { if(ch=='\n') putchar('\015'); putchar(ch); } exit(0); } ----------------------------------------------------- /** ** MJH 11/16/87 ** ** Read in an ASCII text file in MS-DOS format, ** change all CR-LF line endings to LF, ** and strip trailing control-Z **/ #include main() { int ch, lastch; /* initialize lastch */ if( (lastch=getchar())==EOF ) exit(0); /* if lastch isn't CR in a CR-LF pair, write it out & get next one */ /* note that this will write out CRs, if they're not succeeded by LFs */ while( (ch=getchar())!=EOF ) { if(lastch!='\015' || ch!='\n') putchar(lastch); lastch = ch; } /* flush lastch, unless it's DOS EOF (control-Z) */ if(lastch!='\032') putchar(lastch); exit(0); } -- Mark Hebets, Software Applications Department, Radian Corp. PO 201088, Austin, TX 78720 (512)-454-4797 sun!texsun!radian!markh im4u!ut-sally!ut-emx!juniper/