Mail Archives: djgpp/1997/08/27/02:17:35
> So, if you want a text file to be portable to Unix, you should write
> it in binary mode on MS-DOS, so it doesn't have those CRs.
Last night I did up a program to do exactly this (It was to convert a
Unix mail file into DOS CR/LF text so Eudora could read it).
Hope this counts as an ObHack too (It kinda falls into the definition of a hack :)
#include <iostream.h>
#include <fstream.h>
long filelen(char *name)
{
long len=0;
fstream file(name,ios::in|ios::bin);
while(!file.eof())
{
file.get();
len++;
}
len--;
file.close();
return(len);
}
void main(int argc,char **argv)
{
cout << "UNIX2DOS DOS/UNIX Text file converter" << endl;
cout << "Free (F) 1997 COLOSSAL Software" << endl;
if(argc<3)
{
cout << "Not enough arguments!" << endl;
cout << "format : unix2dos <option> <infile> <outfile>" << endl;
cout << "options:" << endl;
cout << "d - Convert a Unix text file to a DOS text file" << endl;
cout << "u - Convert a DOS text file to a Unix text file" << endl;
return(0);
}
long inlen;
unsigned char bit;
char option=*argv[1];
char *infile=argv[2];
char *outfile=argv[3];
inlen=filelen(infile);
fstream in(infile,ios::in|ios::bin);
fstream out(outfile,ios::out|ios::bin);
if(option=='d')
{
for(long x=0;x<inlen;x++)
{
in.get(bit);
if(bit!=10)
{
out.put(bit);
}else{
out.put(13);
out.put(10);
}
}
}
if(option=='u')
{
for(long x=0;x<inlen;x++)
{
in.get(bit);
if(bit!=13)
{
out.put(bit);
}else{
}
}
}
}
Colin Walsh
cwalsh AT nf DOT sympatico DOT ca
BTW - Does adding Cc: to the header list automatically send the post to the
Cc: address or does the news program have to have mail support? (I dont
think the one I'm using has any)
- Raw text -