473,623 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_str eam << '\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 7425

"Kevin Frey" <ke**********@h otmail.com> wrote in message
news:e5******** *************** ***@posting.goo gle.com...
Hello,

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

output_file_str eam << '\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_str eam << '\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_str eam << '\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_str eam << '\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**********@ho tmail.com (Kevin Frey) wrote in message news:<e5******* *************** ****@posting.go ogle.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**********@h otmail.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_seq uence = 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**********@h otmail.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_seq uence = 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************ *********@never box.com> wrote in message news:3f4cedd1@s hknews01...
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
3999
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. Please do not suggest default value solutions. Thanks.
48
3068
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
1717
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 the address space of the process that originally created the shared memory and therefore unavailable to the other processes that may wish to use these instances of the classes. Every so often I forget this and introduce a virtual function causing...
4
1287
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) /*buffer1 ---------------------> 4 buffer1 ---------------------> 8 buffer1 ----------> 18 buffer1 -----------------> 28
31
1354
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
6143
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 ways I have thought detecting 64bit are: 1. struct.calcsize("P") == 8 2. '64' in os.uname() I'm not convinced that either one of these is really adequate. Does
6
3795
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 way to do that without limiting the target platform set to FreeBSD + Linux + NetBSD + OpenBSD or adding the requirement of conformance to some combination of SUS v2, SUS v3 and C99, I'll settle for that. Overflow-safe versions of + and * would...
285
8788
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/ specs gcc version 2.95.3 20010315 (release)
23
1449
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
8217
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8661
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8603
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6104
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1467
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.