c++ conversion files

J

jcoffin

You have code that reads a file in MacOS format, but never even once
mentions MacOS anywhere, and you find that "transparent".

Just to make the situation really clear, I'll narrow things down to one
point: IMO, there are only two choices:

1) point out what part of your code tells anybody that it reads data in
MacOS format,
or:
2) Admit that the code is unreadable.

There is no third option here: your code reads data in MacOS format,
but I see precisely NOTHING that can possibly be interpreted as even a
hint to the reader that this could possibly be the case. How can you
_possibly_ expect anybody to consider it readable?

The closest thing you've given to a reply is:
To me, remembering that a newline_filter performs line-ending conversions not a
spectacular feat of memorization. YMMV.

but this is vague to the point that it's meaningless at best. Simply
"does line-end conversions" means nothing.

Just to make sure you can't misunderstand I'll repeat: what tells the
reader that this code is intended to deal with data in MacOS format?
 
J

Jonathan Turkanis

Just to make sure you can't misunderstand I'll repeat: what tells the
reader that this code is intended to deal with data in MacOS format?

Here's the answer from my last message

Jonathan Turkanis said:
It's not.

I.e., it converts from any OS text file format to windows. True, the filter may
be slightly more efficient if you can assume that the source format is Mac, and
if you find this to be a performance bottleneck, you can switch to this
(modified from an earlier post to include the name "mac":

struct mac_to_windows : boost::io::eek:utput_filter {
template<typename Sink>
void put(Sink& sink, char c)
{
boost::io::put(Sink, c);
if (ch == '\r')
boost::io::put(Sink, '\n');
}
};

Finally, if this is too slow at runtime, increases the size of the executable
too much, or increases compile time to much (all of which I doubt), you can
switch to your original version, which works only for files and is not
chainable.

Jonathan
 
K

Konstantin Litvinenko

Hello, (e-mail address removed)!
You wrote on 6 Dec 2004 11:08:25 -0800:

j> I've reread your code a number of times, and I'm _utterly_ lost as to
j> what you think would give the reader even the faintest hint that it
j> does anything related to MacOS at all.

j> By contrast, looking at:

j> FILE *fin = fopen("src", "rb");
j> FILE *fout = fopen("dest", "wb");
j> int ch;

j> while ( EOF!=(ch=getc(fin))) {
j> putc(ch, fout);
j> if (ch == '\r')
j> putc('\n', fout);
j> }

This code doesn't mention MacOS too. It do some CR/LF processing. if I
choose good name for filter, readed will just read boost::io code.

j> The actual conversion seems (to me) almost impossible to miss. The
j> only part open to any question at all is whether the reader realizes
j> what
j> OSes are associated with CR-only vs. CR/LF line-ends. I'd have to
j> guess, however, that any programmer who cares to read Mac text files
j> under Windows would immediately recognize what it does.

This code, if I new boost::iostream library, I simply can read as any
other text - you code I can't.

filtering_istream fin;
fin.push(newline_filter(newline::windows));
fin.push(in);
boost::io::copy(fin, out);

In a large scale low-level code like you show totaly unreadable and
unmanaged. Using boost::iostream I can write code that simply use a stream
and forget about pre/post processing. I can simply enable/disable some
processing by adding/removing filters and it is cool. I can separate main
program flow from secondary issues like CR/LF.

With best regards, Konstantin Litvinenko. E-mail: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top