Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!lll-winken!uunet!metaware!ken From: ken@metaware.metaware.com (ken) Newsgroups: comp.unix.sysv386 Subject: Re: Converting DOS text files Keywords: SCO ODT Message-ID: <629@metaware.metaware.com> Date: 17 Oct 90 16:16:00 GMT References: <1477@pai.UUCP> <1990Oct16.134008.22319@esegue.segue.boston.ma.us> Reply-To: ken@metaware.UUCP (ken) Organization: Metaware Incorporated, Santa Cruz, CA Lines: 61 In article <1990Oct16.134008.22319@esegue.segue.boston.ma.us> johnl@esegue.segue.boston.ma.us (John R. Levine) writes: >In article <1477@pai.UUCP> erc@pai.UUCP (Eric Johnson) writes: >>The problem is this: when you use a DOS-based copy command to copy a text >>file onto your system (from a PC floppy, say), that DOS text file >>is full of CR/LFs (instead of the UNIX line feed) and has a trailing >>Ctrl-Z. [172 line program follows] Here's yet another solution. This closely emulates Sun's dos2unix program. #include #include #include main(argc, argv) int argc; char *argv[]; { int c; FILE *ifp=NULL, *ofp=NULL; extern void exit(); if (argc != 3 && argc != 2 && argc != 1) printf("\n\tUsage: %s [infile [outfile]]\n\n", argv[0]); else { switch (argc) { case 1: ifp = stdin; ofp = stdout; break; case 2: if ((ifp = fopen(argv[1], "r")) == NULL) { perror(argv[1]); exit(errno); } ofp = stdout; break; case 3: if ((ifp = fopen(argv[1], "r")) == NULL) { perror(argv[1]); exit(errno); } if ((ofp = fopen(argv[2], "w")) == NULL) { perror(argv[1]); exit(errno); } break; } while ((c = getc(ifp)) != EOF) { if ((c != ' putc(c, ofp); } if (ifp != NULL) fclose(ifp); if (ofp != NULL) fclose(ofp); exit(0); } exit(-1); }