🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.privacy.anon-server
Article #46658

Re: Free reliable wordcount utility available (final version)

#46658
From: Richard Heathfield
Date: Fri, 08 Nov 2002 16:43
205 lines
9071 bytes
"Thomas J. Boschloo" wrote:
> 
> Richard Heathfield wrote:
> 
> > Hmmm? What, to compile it, you mean? Well, it's hardly even necessary to
> > compile the code. The non-standard header sticks out like a sore thumb.
> 
> Which I already pointed out in the post you replied to in your own kind
> and special way. You were not the first to notice.

<shrug> I did not see any other article which mentioned it. Otherwise, I
would not have done so myself.

> Besides, I was asking
> for comments to the code in order to make it more ANSI, portable, secure
> and crash-resistant.

Okay, here's one: remove <values.h> from the includes, and fix the
problems that causes using, perhaps, <limits.h>

<snip>

> > > Perhaps it is not safe
> > > because it reads characters unbuffered?
> >
> > Why would that make it unsafe?
> 
> Since I am not sure all the different types of ISO-whatever fit inside a
> single char.

All characters fit into a single byte, by definition. Wide characters
(which are not the same beast as characters) fit into a single wchar_t,
by definition.

> The array I store them into (static char buffer[64])
> assumes octets.

A char is not necessarily 8 bits. It *is* necessarily CHAR_BIT bits.
Depending on char having 8 bits is not uncommon, but you ought to be
aware that it makes your code less portable than it might otherwise be.
If you want to support wide characters, you need to use wchar_t instead.

<snip>

> ISO is not such a big deal to me. I just want my code to be portable

Perhaps we are talking at cross-purposes. ISO defines the C language in
order to make it possible to write programs that are portable across
various platforms, provided the programs are written to conform to the
ISO C Standard and provided that the compilers used conform to that
standard. Most C compilers nowadays conform to ISO/IEC 9899:1990,
although there is at least one that conforms to the later 1999 Standard.

ISO *also* defines a number of character sets, and I suspect that that's
what you're talking about here. Frankly, I'm not terribly interested in
wide character sets either, so I sympathise with you in that respect.

> and
> be able to compile on a lot of different platforms (Solaris and Windows
> 2000 at least). I own neither.

Windows 2000: Borland compiler

D:\var\scratch>bcc32 -A boschwcount.c
Borland C++ 5.4 for Win32 Copyright (c) 1993, 1999 Inprise Corporation
boschwcount.c:
Turbo Incremental Link 4.00 Copyright (c) 1997, 1999 Inprise Corporation

Windows 2000: Microsoft compiler

D:\var\scratch>cl -W4 -Za -nologo boschwcount.c
boschwcount.c
boschwcount.c(23) : fatal error C1083: Cannot open include file:
'values.h': No
such file or directory

> > <snip>
> >
> > > Besides, Turbo C 2.0 hasn't got a locale function according to the
> > > online help file
> >
> > ANSI C has a setlocale() function, which is probably what Phil was
> > talking about.
> 
> Well, I guess Turbo C 2.0 doesn't conform to ANSI-C then,

Nope. It comes pretty close, though.

> so why
> complain about the values.h in the first place?

Because you said the code conformed to the ANSI standard.

> I only added it for
> people who set the #define MAXWORDSIZE to an incorrect value. It was a
> last minute modification and I got it wrong. So what?

So fix it?

> Do we need to go
> over this oven and over again until one of use apologizes for flaming
> the other? I know I won't apologize, how about you?

I'm not interested in flame wars. If you want one, please try arguing
with someone else.


> > > and to Rich, isalpha is just a macro in Turbo C 2.0:
> > >
> > > #ctype.h
> > > # define isalpha(c) (_ctype[(c) + 1] & (_IS_UPP | _IS_LOW))
> >
> > No, isalpha() is not *just* a macro in Turbo C 2.0. It is a portable way
> > to determine whether a character is alphabetic. rc = isalpha((unsigned
> > char)ch) is portable at a source code level, whereas rc = (ch >= 'A' &&
> > ch <= 'Z') is not.
> 
> Have you notices _ctype[] is an array of ints?

_ctype[] is an implementation detail which is irrelevant to a portable
program.

> Do you think it is wise
> to waste at least (256+1)*2 bytes of valuable 64kb segmented memory on?
> Besides, I don't think Turbo C libraries have the ultimate knowledge on
> what is a character for ISO-xxxx-1. I just might have that info for
> myself and I can do it in less code (0 bytes in the data segment of my
> program).

If you take advantage of implementation-dependent hacks, you lose
portability. I can see why you might want to do that (speed), but the
portability cost is non-zero.

> > > So why aren't you flaming Phil here to learn the simple stuff before
> > > moving to the ISO stuff?
> >
> > I'm not aware that you've shown him to be in error.
> 
> That is my whole point.

You want me to flame Phil for NOT getting something wrong? Weird.

> This is getting tiresome..

Learning is tiresome? Well, okay...

> 
> > > Besides, I am thinking about a preprocessor
> > > that will turn =%2x strings into EBCDIC characters.
> >
> > I'm surprised that you are so concerned about EBCDIC (not that there's
> > anything wrong with that), but I can't help feeling that you may have
> > misunderstood what EBCDIC is. (I might be wrong about that, of course.)
> 
> I understood that it is the character set that is in my BIOS and in the
> BIOS of most desktop computers around the world. What is your
> understanding of EBCDIC?? (don't reply if you don't want to look stupid)

How ironic that you should offer me the chance not to look stupid. Most
desktop computers in the world use ASCII, not EBCDIC. IBM mainframes use
EBCDIC. Are you claiming to have an IBM mainframe on your desktop? If
so, you must have one hell of a desk.

> > > Would that be nice
> > > or is it better to put the whole code into one lump of program? After
> > > all, l33t coders don't make programming mistakes, do they?!
> >
> > All programmers make mistakes.
> 
> That is why strong typing was invented. That is why Dijkstra spend most
> of his life writting EWD's. That's why we have compiler warnings.

But we cannot assume that a diagnostic-free compilation means a correct
program. Witness your program's failure to compile under the Microsoft C
compiler, despite its compiling without diagnostics under the Borland C
compiler.

> > > If anyone still has any more constructive criticism, fire away but be
> > > aware that my clothing is asbestos coated as you might have figured by
> > > now. Also, my flamethrower is a lot better I think you
> > > math/crypto-sissies!
> >
> > If you want to bandy words, please find someone else to do it with.
> 
> You seem like an easy target.

I'm sorry that you find it necessary to look for targets.

> Please educate me if I am underestimating
> your skills on the points you tried to flame me on when this all
> started.

I haven't been flaming you. I have merely been pointing out one or two
things which, if you choose to learn from them, may be of benefit to
you. If you are not interested in learning (and in *un*learning some
strange ideas you seem to have picked up along the way), then there is
no point in continuing this discussion.

<snip>

-- 
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Technical Details
Message-ID: <3DCBE9CD.D33C572F@eton.powernet.co.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.security.pgp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!opentransit.net!newsfeed.icl.net!newsfeed.fjserv.net!newspeer.clara.net!news.clara.net!lon1-news.nildram.net!195.60.31.14.MISMATCH!news2.power.net.uk!news.power.net.uk
References: <3DC1596C.6D2B55BD@hccnet.nl.invalid> <3DC526FC.CBCFE9B6@hccnet.nl.invalid> <3DC5451F.DBF3CDDA@eton.powernet.co.uk> <pan.2002.11.03.17.05.02.482162@yahoo.co.uk> <3DC81975.45915377@hccnet.nl.invalid> <3DC98ABC.27E67263@eton.powernet.co.uk> <3DCBC8E4.3933993A@hccnet.nl.invalid>

Show Full Headers
Complete Article Headers
Message-ID: <3DCBE9CD.D33C572F@eton.powernet.co.uk>
Subject: Re: Free reliable wordcount utility available (final version)
Date: Fri, 08 Nov 2002 16:43:57 +0000
From: Richard Heathfield <binary@eton.powernet.co.uk>
References: <3DC1596C.6D2B55BD@hccnet.nl.invalid> <3DC526FC.CBCFE9B6@hccnet.nl.invalid> <3DC5451F.DBF3CDDA@eton.powernet.co.uk> <pan.2002.11.03.17.05.02.482162@yahoo.co.uk> <3DC81975.45915377@hccnet.nl.invalid> <3DC98ABC.27E67263@eton.powernet.co.uk> <3DCBC8E4.3933993A@hccnet.nl.invalid>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.security.pgp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!opentransit.net!newsfeed.icl.net!newsfeed.fjserv.net!newspeer.clara.net!news.clara.net!lon1-news.nildram.net!195.60.31.14.MISMATCH!news2.power.net.uk!news.power.net.uk
Organization: Eton Computer Systems Ltd
X-Mailer: Mozilla 4.6 [en-gb]C-CCK-MCD NetscapeOnline.co.uk (WinNT; I)
X-Accept-Language: en-GB,en
MIME-Version: 1.0
Newsgroups: alt.privacy.anon-server,sci.crypt,alt.fan.cult-dead-cow,alt.security.pgp
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 195.60.5.99
X-Trace: news.power.net.uk 1036783546 195.60.5.99 (8 Nov 2002 19:25:46 GMT)
Lines: 207