From 247dec4d1ae585c811af1b7d050dfada78b9b507 Mon Sep 17 00:00:00 2001 From: Scott McCreary Date: Sat, 28 Nov 2009 22:11:01 +0000 Subject: [PATCH] Initial source files for dos2unix and unix2dos, not sure of the origin of the files, but I did list the page I got them from. I had to make several changes to get them to build. --- app-text/dos2unix/DOS2UNIX.C | 107 +++++++++++++++++++++++++++++ app-text/dos2unix/UNIX2DOS.C | 107 +++++++++++++++++++++++++++++ app-text/dos2unix/dos2unix-1.0.bep | 17 +++++ 3 files changed, 231 insertions(+) create mode 100644 app-text/dos2unix/DOS2UNIX.C create mode 100644 app-text/dos2unix/UNIX2DOS.C create mode 100644 app-text/dos2unix/dos2unix-1.0.bep diff --git a/app-text/dos2unix/DOS2UNIX.C b/app-text/dos2unix/DOS2UNIX.C new file mode 100644 index 000000000..83f84e8f1 --- /dev/null +++ b/app-text/dos2unix/DOS2UNIX.C @@ -0,0 +1,107 @@ +/* + * DOS2UNIX.C + * + * Clean out cr/lf combinations in a file but keep it's original + * date/time stamp. + */ + +#include +#include +#include +#include +#include +#include +#include +#ifndef TRUE +# define TRUE (1) +# define FALSE (0) +#endif + +#define R_CNTRL "r" +#define W_CNTRL "w" + +struct stat s_buf; + + +int dos2u (char *path); + + +main (int argc, char **argv) +{ + char *path; + while (--argc>0) + { + if (stat (path=*++argv, &s_buf) != -1) + { + printf ("Dos2Unix: Cleaning file %s ...\n", path); + if (dos2u (path)) + { + fprintf (stderr, "Dos2Unix: Problems cleaning file %s\n", path); + } + } + else + { + fprintf (stderr, "Dos2Unix: Can't stat '%s'\n", path); + } + } +} + + + + + + + +int dos2u (char *path) +{ + FILE *in, *out; + int ch, + rval = FALSE; + char temppath [16]; +/* struct utimbuf { time_t actime, modtime; } ut_buf; */ + struct utimbuf ut_buf; + + strcpy (temppath, "./clntmp"); + if ((in=fopen (path, R_CNTRL)) == (FILE *) 0) + return TRUE; + if ((out=fopen (temppath, W_CNTRL)) == (FILE *) 0) + { + fclose (in); + return TRUE; + } + while ((ch = getc (in)) != EOF) + if ((ch != '\015' && ch != '\032') && + (putc (ch, out) == EOF) ) + { + rval = TRUE; + break; + } + if (fclose (in) == EOF) + { + rval = TRUE; + } + if (fclose (out) == EOF) + { + rval = TRUE; + } + ut_buf.actime = s_buf.st_atime; + ut_buf.modtime = s_buf.st_mtime; + if (utime (temppath, &ut_buf) == -1) + rval = TRUE; + if (unlink (path) == -1) + rval = TRUE; + if (rval) + { + unlink (temppath); + return TRUE; + } + if (link (temppath,path) == -1) + { + fprintf (stderr, "Dos2Unix: Problems renaming '%s' to '%s'\n", temppath, path); + fprintf (stderr, " However, file '%s' remains\n", temppath); + exit (1); + } + unlink (temppath); + return FALSE; +} + diff --git a/app-text/dos2unix/UNIX2DOS.C b/app-text/dos2unix/UNIX2DOS.C new file mode 100644 index 000000000..842fb31e2 --- /dev/null +++ b/app-text/dos2unix/UNIX2DOS.C @@ -0,0 +1,107 @@ +/* + * UNIX2DOS.C + * + * Convert lf's to crlf combinations in a file but keep it's original + * date/time stamp. + */ + +#include +#include +#include +#include +#include +#include +#include +#ifndef TRUE +# define TRUE (1) +# define FALSE (0) +#endif + +#define R_CNTRL "r" +#define W_CNTRL "w" + + + +struct stat s_buf; + +int u2dos (char *path); + + +main (int argc, char **argv) +{ + char *path; + while (--argc>0) + { + if (stat (path=*++argv, &s_buf) != -1) + { + printf ("Unix2Dos: Cleaning file %s ...\n", path); + if (u2dos (path)) + { + fprintf (stderr, "Unix2Dos: Problems cleaning file %s\n", path); + } + } + else + { + fprintf (stderr, "Unix2Dos: Can't stat '%s'\n", path); + } + } +} + + + + +int u2dos (char *path) +{ + FILE *in, *out; + int ch, + rval = FALSE; + char temppath [16]; +/* struct utimbuf { time_t actime, modtime; } ut_buf; */ + struct utimbuf ut_buf; + + strcpy (temppath, "./clntmp"); + if ((in=fopen (path, R_CNTRL)) == (FILE *) 0) + return TRUE; + if ((out=fopen (temppath, W_CNTRL)) == (FILE *) 0) + { + fclose (in); + return TRUE; + } + while ((ch = getc (in)) != EOF) + if (((ch == '\012') && (putc ('\015', out) == EOF)) || + (putc (ch, out) == EOF) ) + { + rval = TRUE; + break; + } + if (fclose (in) == EOF) + { + rval = TRUE; + } + if (fclose (out) == EOF) + { + rval = TRUE; + } + ut_buf.actime = s_buf.st_atime; + ut_buf.modtime = s_buf.st_mtime; + if (utime (temppath, &ut_buf) == -1) + rval = TRUE; + if (unlink (path) == -1) + rval = TRUE; + if (rval) + { + unlink (temppath); + return TRUE; + } + if (link (temppath,path) == -1) + { + fprintf (stderr, "Unix2Dos: Problems renaming '%s' to '%s'\n", temppath, path); + fprintf (stderr, " However, file '%s' remains\n", temppath); + exit (1); + } + unlink (temppath); + return FALSE; +} + + + diff --git a/app-text/dos2unix/dos2unix-1.0.bep b/app-text/dos2unix/dos2unix-1.0.bep new file mode 100644 index 000000000..d647e1f06 --- /dev/null +++ b/app-text/dos2unix/dos2unix-1.0.bep @@ -0,0 +1,17 @@ +DESCRIPTION="dos2unix and unix2dos end of line file converters." +HOMEPAGE="http://www.programmersheaven.com/download/3118/download.aspx" +SRC_URI="http://www.haiku-ports.de/packages/app-text/dos2unix/source/dos2unix-1.0.zip" +REVISION="1" +STATUS_HAIKU="untested" +DEPEND="" +BUILD { + cd dos2unix-1.0 + gcc -O -o dos2unix DOS2UNIX.C + gcc -O -o unix2dos UNIX2DOS.C +} + +INSTALL { + cd dos2unix-1.0 + cp dos2unix `finddir B_COMMON_BIN_DIRECTORY`/dos2unix + cp unix2dos `finddir B_COMMON_BIN_DIRECTORY`/unix2dos +}