Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: Pat Gunn <pgunn01@ibm.net>
Subject: Re: dos 2 unix
Date: 1998/08/04	[thread overview]
Message-ID: <35C7A9C0.267@ibm.net> (raw)
In-Reply-To: 35C73769.9BC50362@sandia.gov

Anji Morris wrote:
> 
> Hi,
> 
> I am running Digital Unix (OSF1 alf.sandia.gov V4.0 878 alpha).  I
> cannot seem to find a basic utility that comes with most installations
> of unix to convert carriage return/line feeds to new lines (ie. dos2ux,
> dos2unix, dtox).  Any ideas?

Fortunately, it's fairly trivial to write such programs. Something
along the lines of the following should do the trick. Note that
this is just off the top of my head, and might not work without a
bit of debugging.



#include <fcntl.h>
#include <sys/types.h>

#define CHAR1 '\r' /* This is the one I'm not sure about.
			DOS text files use both CR and NL to
			indicate end of line. I think Unix only
			uses newlines... */

int main(int argc, char *argv[])
{
FILE *ifile, *ofile;
int mychar;
if(argc != 3)
	{
	printf("\nUsage: mytranslater infile outfile\n");
	exit(1);
	}
ifile = fopen(argv[1],"rb"); /* Open our input file */
if(ifile == NULL)
	{
	printf("Cannot open file %s: error %d\n", argv[1], errno);
	exit(1);
	}
ofile = fopen(argv[2],"wb+"); /* Open our output file */
if(ofile == NULL)
	{
	printf("Cannot open file %s: error %d\n", argv[2], errno);
	exit(1);
	}
while(mychar = fgetc(ifile))
	{
	if(mychar == EOF)
		break;
	if(mychar == 'CHAR1')
		continue; /* Diddle with logic here to go the other way */
	fputc(ofile,mychar);
	}
fclose(ofile);
fclose(ifile);
exit(1);
}



-- 
---------------------------------------------------
Pat Gunn, moderator:comp.sys.newton.announce
comoderator:comp.os.os2.moderated
"You can always judge a man by the quality of his enemies." -- Dr Who
http://junior.apk.net/~qc
------------------------------------------------



  reply	other threads:[~1998-08-04  4:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-08-04  4:00 dos 2 unix Anji Morris
1998-08-04  4:00 ` Pat Gunn [this message]
1998-08-04  4:00   ` John Wilson
1998-08-08  4:00     ` Pat Gunn
1998-08-04  4:00 ` Nick Manka
1998-08-04  4:00 ` Stephen Thompson
1998-08-06  4:00 ` Hans Schwengeler
1998-08-07  4:00   ` dos 2 unix (Try "flip") Jeff Sullivan
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox