473,320 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Detecting CR/LF or LF behaviour on a particular C++ platform.

Hello,

Can anyone suggest a way, that does not involve writing a temporary
file, that would permit me to discover whether writing:

output_file_stream << '\n';

will write either a LF (eg. under unix) or CR/LF (eg. under Win32).

The Adobe Acrobat specification (V1.3) has a section called a
cross-reference table which must be padded to exactly 20 bytes per
line. If the operating system writes LF-only then each line has a
space appended before the LF. If the operating system writes CR/LF
then no space is appended.

Taking an entirely lateral approach, my colleague has suggested to me
that only the Win32 platform actually writes CR/LF so I should just
conditionalise the code for Win32 and *assume* all other platforms are
LF. So as a separate question - can anyone think of any other
mainstream platform that uses CR/LF. I'm under the impression this
"hangover" came from CP/M but that O/S has pretty much gone the way of
the Dodo.

Thanks

Kevin.
Jul 19 '05 #1
9 7399

"Kevin Frey" <ke**********@hotmail.com> wrote in message
news:e5**************************@posting.google.c om...
Hello,

Can anyone suggest a way, that does not involve writing a temporary
file, that would permit me to discover whether writing:

output_file_stream << '\n';

will write either a LF (eg. under unix) or CR/LF (eg. under Win32).

The Adobe Acrobat specification (V1.3) has a section called a
cross-reference table which must be padded to exactly 20 bytes per
line. If the operating system writes LF-only then each line has a
space appended before the LF. If the operating system writes CR/LF
then no space is appended.

Taking an entirely lateral approach, my colleague has suggested to me
that only the Win32 platform actually writes CR/LF so I should just
conditionalise the code for Win32 and *assume* all other platforms are
LF. So as a separate question - can anyone think of any other
mainstream platform that uses CR/LF. I'm under the impression this
"hangover" came from CP/M but that O/S has pretty much gone the way of
the Dodo.

Thanks

Kevin.


Do not assume such thing.
cr-separated = mac :-)
crlf - windows
lf - unix systems

i have seen vlaid PDFs which have been CR separated. Kinda headache.
It broke our program which was conditioned same way as your colleague
suggested.

Jul 19 '05 #2
Kevin Frey wrote:
Hello,

Can anyone suggest a way, that does not involve writing a temporary
file, that would permit me to discover whether writing:

output_file_stream << '\n';

will write either a LF (eg. under unix) or CR/LF (eg. under Win32).

....

Sounds like the job of a binary file.

FAQ city:

http://www.fmi.uni-konstanz.de/~kueh...html#faq-15.12

Jul 19 '05 #3
Kevin Frey wrote:


Can anyone suggest a way, that does not involve writing a temporary
file, that would permit me to discover whether writing:

output_file_stream << '\n';

will write either a LF (eg. under unix) or CR/LF (eg. under Win32).

The Adobe Acrobat specification (V1.3) has a section called a
cross-reference table which must be padded to exactly 20 bytes per
line. If the operating system writes LF-only then each line has a
space appended before the LF. If the operating system writes CR/LF
then no space is appended.

Taking an entirely lateral approach, my colleague has suggested to me
that only the Win32 platform actually writes CR/LF so I should just
conditionalise the code for Win32 and *assume* all other platforms are
LF. So as a separate question - can anyone think of any other
mainstream platform that uses CR/LF. I'm under the impression this
"hangover" came from CP/M but that O/S has pretty much gone the way of
the Dodo.


In C++, the end of a line is always represented
by the line feed or new line character '\n'.
This is converted automatically to the End Of Line (EOL) sequence
recognized by your operation system on output
and converted from the EOL sequence to `\n' on input.

Jul 19 '05 #4
Kevin Frey wrote:
Hello,

Can anyone suggest a way, that does not involve writing a temporary
file, that would permit me to discover whether writing:

output_file_stream << '\n';

will write either a LF (eg. under unix) or CR/LF (eg. under Win32).


There's a bigger issue: What value(s) does it write? Don't assume ASCII
encoding if you expect your code to be portable.

The bottom line, really, is that it doesn't matter at all how many
characters are actually written. There are two possibilities:

1) You are writing a text file. The library will do the Right Thing
without you having to worry about it (as long as you open the file in
text mode).

2) You are writing a binary file. It will output exactly what you tell
it to (as long as you open the file in binary mode). You have complete
control.

If you are dealing with a file format that specifies things like how a
newline should be written, then clearly you are dealing with a binary
file, not a text file (if it were text there'd be no reason to specify
it - it's inherent in the system). So stop trying to find a way to trick
the library into doing what you want it to do and use a binary file.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #5
I think the question has been misunderstood. Nowhere did I say that
the specification dictates what the end-of-line convention is. Rather,
the specification says that this is the requirement depending on
*what* the standard end-of-line convention is for the platform.

Let's ignore the issue of non-ASCII platforms for the moment since
that is a completely different kettle of fish in terms of complexity -
particularly when I am talking about a document interchange format
that must be ASCII.

Does anyone have an ideas for solving my problem, rather than:

a. Second-guessing why I need to solve the problem.
b. Telling me that I don't really need to solve the problem.

Thanks

Kevin.
Jul 19 '05 #6
ke**********@hotmail.com (Kevin Frey) wrote in message news:<e5**************************@posting.google. com>...
I think the question has been misunderstood. Nowhere did I say that
the specification dictates what the end-of-line convention is. Rather,
the specification says that this is the requirement depending on
*what* the standard end-of-line convention is for the platform.
Dumb question: What good's a portable document format (that's what
Acrobat uses, right?) whose end-of-line sequence is platform-dependent
-- and therefore, by definition, unportable? Or is it simply that
you're allowed to use any of several end-of-line sequences, including
-- but not limited to -- the one typically used on your platform?

In the latter case, then your solution lies in binary I/O, as Gianni
mentioned earlier. You get to write exactly how many bytes you need
per line, and you can cap it off with whatever end-of-line sequence
you feel like writing (typically '\r' or '\n' or "\r\n" on ASCII
systems like the ones you support). If the PDF format is truly
portable, that ought to be sufficient.

If not... There's no way to detect the end-of-line sequence without
checking when your program runs or hard-coding it per system ahead of
time. And yes, "checking" involves writing an endline to a file and
opening it *in binary mode* to see what was written.
Does anyone have an ideas for solving my problem, rather than:

a. Second-guessing why I need to solve the problem.
b. Telling me that I don't really need to solve the problem.


How about this:

c. Telling you that your problem isn't what you think it is.
d. Telling you a way to solve the (actual) problem.

At least, that is what I hope to have accomplished here. Good luck!

- Shane
Jul 19 '05 #7

"Kevin Frey" <ke**********@hotmail.com> wrote in message >
a. Second-guessing why I need to solve the problem.
b. Telling me that I don't really need to solve the problem.


Is this what you want

ostringstream oss;

oss << '\n'; // textual newline.

string end_of_line_sequence = oss.str();

Fills the string with whatever the implementation defined end of line
sequence is.
Jul 19 '05 #8
Ron Natalie wrote:
"Kevin Frey" <ke**********@hotmail.com> wrote in message >
a. Second-guessing why I need to solve the problem.
b. Telling me that I don't really need to solve the problem.

Is this what you want

ostringstream oss;

oss << '\n'; // textual newline.

string end_of_line_sequence = oss.str();

Fills the string with whatever the implementation defined end of line
sequence is.


Does it? I considered that, but figured it would not do the end-of-line
translation in that case since it is not being written to a file. I was
sort of guessing that this translation would occur in the filebuf class.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #9

"Kevin Goodsell" <us*********************@neverbox.com> wrote in message news:3f4cedd1@shknews01...
Fills the string with whatever the implementation defined end of line
sequence is.


Does it? I considered that, but figured it would not do the end-of-line
translation in that case since it is not being written to a file. I was
sort of guessing that this translation would occur in the filebuf class.


Yeah, you're probably right. I guess you could always create a file somewhere
write it with text mode and read it back with binary.
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sam Smith | last post by:
I am using optparse for the commandline parsing for my programs. I was wondering if it is possible to detect if an option or option-arg has been specified on the commandline by the user or not....
48
by: marbac | last post by:
Hi, i heard a lot about "undefined behaviour" in this and other newsgroups dealing with c/c++. Is there a list where all cases with undefined behaviour in C++ are listed? regards marbac
5
by: News Admin | last post by:
I have a bunch of classes, instances of which that need to live in shared memory and be accessed by multiple processes. This means that they cannot have a vtable as the addresses in it will be in...
4
by: gautam | last post by:
can anyone pls tell me y is the memory allocation not alligned to 4 Bytes. Note : compiled with gcc in linux 9 void function(int a,int b,int c) { char buffer1; Bytes allocated(as shown by gdb)...
31
by: grid | last post by:
Hi, A collegue of mine is of the opinion that the behaviour of the following program is defined,but I am a little apprehensive. #include<stdio.h> #include<string.h> int main() { char *c;
8
by: dwelch91 | last post by:
I need to detect whether the operating system I am running on (not the Python version) is 64bit or 32bit. One requirement is that I need to include support for non-Intel/AMD architectures. The 2...
6
by: Andre Majorel | last post by:
How do you compute an off_t with overflow detection ? Ideally, the target language is C89/C90 and the target platform is reasonably recent versions of the major Unixen. If there is no practical...
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
23
by: Spiros Bousbouras | last post by:
#include <stdio.h> int main(void) { int i ; for (i=1 ; i != 0 ; i++) ; printf("Finished !\n") ; return 0 ; }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.