Article View: comp.bbs.waffle
Article #3414Re: The woes of ^Z
From: David Keegel
Date: Fri, 08 Jan 1993 08:54
Date: Fri, 08 Jan 1993 08:54
53 lines
3276 bytes
3276 bytes
In <1993Jan4.022937.3932@smoke.marlboro.vt.us> jhood@smoke.marlboro.vt.us (Lord Yertle) writes: >The problem is not in the MS-DOS operating system code. MS-DOS itself >treats files as dull boring binary streams, just like unix. (An >exception is character devices, but we're not concerned with that >here, and Unix has lots of its own peculiarities here too.) >The problem is that to stay close to CP/M roots, MS-DOS utilities and >COMMAND.COM (and by extension most other MS-DOS programs) follow the >CP/M convention that text files have CR/LF and end at ^Z. MSDOS C >compilers optionally do goofy stuff in the libraries to make it all >look like Unix text format inside user programs. EXACTLY. This is spot on. Listen to this man, people. >The option of reading a file as text with line breaks or as non-text >data is (or at least should be) unrelated to this conversion goo. This, I'm not so sure about. As far as I know, when you are programming in C with stdio (and I mean *any* environment with a half-way decent stdio, including non-ASCII machines), each time you open a file you make a decision about whether this is nominally a text file or nominally a binary file. If it's a binary file (you write a 'b' in the second argument to fopen) you get the bytes exactly as they are on disk. It it's a text file, the C library will make whatever conversions are necessary in your environment to make the file appear as a sequence of lines separated by '\n' and just stopping at whatever the local equivalent of EOF is. Strangely enough, on Unix (where C was developed), this text conversion is a no-op; like converting to network byte order on a Sun. So the question is whether the file in question is a text file or a binary file. If it is a text file, it should obey local conventions. In the case of MS-DOS, it should have \015\012 (\r\n) separated lines, and a \032 (^Z) character denoting EOF, which is of course stripped. I think a news item is (should be) a text file. Perhaps we should be complaining about Waffle not translating the ^Z into something innoculous when it *writes* the file (when \n -> \r\n is done) rather than when it *reads* the file. But then tell me, what is the MS-DOS convention for quoting a ^Z? Answer: none. If there was one, the compiler writers could implement it as an extra translation for text files (eg: when writing text ^Z --> ???; like \n --> \r\n). Then the applications wouldn't need to worry about this rubbish. -- <David.Keegel@apana.org.au> <werple!tuple!boombox!djk> Tel: +61 3 593-1460 aka: djk@boombox.apana.org.au, djk@cs.mu.oz.au. Formerly: djk@bby.com.au.
Technical Details
Message-ID:
<dJiTrAYEBh107h@boombox.apana.org.au>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!ariel.ucs.unimelb.EDU.AU!werple.apana.org.au!tuple.apana.org.au!boombox!djkReferences:
<3Ng0VB3w165w@cybrspc.UUCP> <22Dec92043311@miracle.com> <1993Jan4.022937.3932@smoke.marlboro.vt.us>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!ariel.ucs.unimelb.EDU.AU!werple.apana.org.au!tuple.apana.org.au!boombox!djk From: djk@boombox.apana.org.au (David Keegel) Newsgroups: comp.bbs.waffle Subject: Re: The woes of ^Z Summary: The issue is in the C libraries. Text file vs binary file. Message-ID: <dJiTrAYEBh107h@boombox.apana.org.au> Date: Fri, 8 Jan 93 19:54:53 +1100 References: <3Ng0VB3w165w@cybrspc.UUCP> <22Dec92043311@miracle.com> <1993Jan4.022937.3932@smoke.marlboro.vt.us> Reply-To: David.Keegel@apana.org.au Organization: Private site, Melbourne, Australia. Lines: 53