/***************************************************************************
* *
* File: DOS to UNIX TEXT CONVERT *
* Function: This program demostrating text convert managment *
* *
* Author: Long Yun Liang *
* Copyright (c) 12,26,1996 All rights reserved *
* *
***************************************************************************/
#include <stdio.h>
//#include <prototypes.h>
FILE * infile;
FILE * outfile;
char infilename [128];
char outfilename [128];
int mode = 1;
void filter ()
{
int ok = 1;
int ch;
long fsize;
do
{
ok = 1;
printf ("\n\nSource text filename : ");
if (mode) scanf ("%s",infilename); else printf ("%s\n",infilename);
if ((infile = fopen (infilename,"rb")) == NULL)
{
printf ("Can't open %s\n",infilename);
ok = 0;
mode = 1;
}
}
while (!ok) ;
do
{
ok = 1;
printf ("\nTarget text filename : ");
if (mode) scanf ("%s",outfilename); else printf ("%s\n",outfilename);
if ((outfile = fopen (outfilename,"rb+")) == NULL)
{
printf ("Can't open %s\n",outfilename);
ok = 0;
mode = 1;
}
}
while (!ok) ;
fsize=0;
while ((ch=fgetc (infile))!= EOF)
{
if (ch=='\x0d') continue;
else fputc (ch,outfile);
fsize++;
}
chsize (fileno(outfile),fsize);
fclose (infile);
fclose (outfile);
printf ("\nFinished .\n\n");
}
void main (int argc,char *argv[])
{
int choice;
if (argc>3) {
printf ("Text Convert Utility Version 1.20\n");
printf ("Copyright (c) Software Engineering 1994-1996. All rights reserved.\n\n");
printf ("Usage: CODE InputFile OutputFile\n");
return ;
}
else if (argc==2) {
strcpy (infilename,argv[1]);
strcpy (outfilename,argv[1]);
mode = 0;
}
else if (argc==3) {
strcpy (infilename,argv[1]);
strcpy (outfilename,argv[2]);
mode = 0;
}
else mode = 1;
printf ("DOS to UNIX Text Convert Utility Version 1.20\n");
printf ("Copyright (c) Software Engineering 1996. All rights reserved.");
filter ();
}
echo "DOS to UNIX Text Convert Utility Version 1.20"
echo "Copyright (c) Software Engineering 1996 .\n"
if test $# -lt 1
then
echo "Usage: D2U FileName\n "
elif test -r $1
then
dos2unix $1 temp$$
mv temp$$ $1
echo "Finished .\n"
else
echo "File not found .\n"
fi