delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/27/02:17:35

From: cwalsh AT nf DOT sympatico DOT ca (Colin Walsh)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Writing a struct to disk
Date: 26 Aug 97 20:05:22 GMT
Organization: Colossal Software
Lines: 80
Approved: By the Department of Silly Walks
Distribution: world
Message-ID: <34033702.0@204.101.95.15>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970826100900 DOT 5294F-100000 AT is>
Reply-To: cwalsh AT nf DOT sympatico DOT ca
NNTP-Posting-Host: 204.101.95.15
Cc: djgpp AT delorie DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019