Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Aug 1997 16:15:24 +1000
From:      Robert Chalmers <robert@chalmers.com.au>
To:        freebsd-questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: Stripping ^M from llines?[solved]
Message-ID:  <3407BA7B.3D5278DC@chalmers.com.au>
References:  <34076F58.B5DBAC3F@chalmers.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
Robert Chalmers wrote:

> Hi,
> Anyone got a handy program for stripping the ^M from text
> lines in fbsd?
> I currently use tr -d '\015', but this falls over text that
> has the : chararacter in it, complaining about it being a
> directory?
>
> cheers,
> Bob

Got sick of messing around and wrote a dos2unix thing in C.
Works fine for what I want.
Thanks for all the help folks.
========================== d2u.c
==============================
#include <stdio.h>
#define MAXCHAR 128

main(int argc, char *argv[])
{
 int len;
 int foo;
 char string[128];
 FILE *fileptr;

/* check arguements */
 if (argc != 2)
  error("Usage: d2u filename1 > filename2");

/* open file */
 if ((fileptr = fopen(argv[1], "r")) == NULL)
  error("Cannot open file");


/* read material and display */
 for (;;) {
  if (fgets(string, MAXCHAR, fileptr) != NULL) {
  len = strlen(string);
  for (foo = 0; foo <= len-1; foo++) {
   if (string[foo] != '\015')
   printf("%c", string[foo]);
   }
  }
  else
  exit(0);
 }
}
/* Process errors */
error(message)
char *message;
{
 printf("%s\n", message);
 exit(1);
}


--
http://www.chalmers.com.au Books-New & Secondhand  Support
Whirled Peas.
Agents for CIBTC. Associate of Amazon.com, and Partner Program
with iBS.
Books about China, books from China.         Sheng huo jiu shi
dou zheng
Business Links in Dalian, and Beijing.          Building the
China Trade





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3407BA7B.3D5278DC>