Requesting advice how to clean up C code for validating string represents integer

  • Thread starter robert maas, see http://tinyurl.com/uh3t
  • Start date
M

Mark McIntyre

CBFalconer said:


Sure - just as soon as Robert tells us where 42 may be found.

At the end of Chapter 27, page 152 in my copy.

Oh, and on a scrabble set around 4my ago, surrounded by a load of
telephone sanitisers.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
R

Robert Maas, see http://tinyurl.com/uh3t

From: Keith Thompson said:
if you have Emacs, then you have Gnus, the newsreader I use.

Does it have a feature of scanning *all* the newsgroups in the
whole world to find any followups to articles you have posted, so
that you can continue back-and-forth exchanges? Or do you first use
Google Groups to scan for followups, then somehow transfer the
message-ID from Google Groups to Gnus to do your actual followup?
What if the article has expired from your local NNTP server, so the
transfer from GG to NNTP doesn't work. What do you do then?

Do you use Gnus remotely over VT100 dialup?

How do you like editing with emacs through VT100 dialup compared to
having the text right there locally on your Macintosh where you can
use mouse to sweep text to copy&pages instead of the more laborous
way you have to do it with vt100-remote-emacs?

From 1975, when I got my first terminal (Beehive 3A) and modem, for
just a few years after that, my only from-home text editing was SOS
(Son Of Stopgap) via 300 baud acoustic coupler into Stanford A.I.
dialup. But then I discovered emacs at MIT-ML and later MIT-MC, and
with DM2500 emulator I wrote myself in 2k bytes of RAM on MOS-6502,
that was a great improvement over SOS. But then in 1990 I got my
own Macintosh, with various GUI text-editors which was a great
improvement over dialup/remote emacs. I still use emacs and vi for
special purposes, especially emacs for making tiny tweaks to lisp
code for live CGI applications, such as just last night and earlier
today I was improving my "all but one" flashcard program to fix two
problems, namely users who accidently back up to an earlier screen
and try to refresh (which totally confused the program as well as
the user, now it detects the problem and issues a clean ERROR
screen with link to reset to the top of the algorithm), and the
rare case where there is o card due yet and only one card coming up
due in the next five seconds but that card coming up is the same
card they had just-before done so it has to be skipped (until today
it'd sit for up to five seconds waiting for that card, and *then*
notice it couldn't be used because it was the just-previous card
and switch to whatever it would do if nothing were due, but now it
recognizes that special situation by a cleaner algorithm and
immediately goes on to whatever else it would do without the
wasteful up-to-5-second delay). But even those upgrades weren't
done entirely using remote emacs. At the start of the upgrade, I
copied fragments of useful code from the VT100 screen to a local
McSink edit, used local editing with mouse to compose my first
draft of the patch, used copy&pasge to transmit the patch back into
the remote-emacs edit buffer, and then used emacs parens-matching
to make sure I hadn't goofed the parens, then did the rest of the
edit with mostly emacs. It's quite rare that I do an entire edit
from begin to end using nothing but VT100-to-remote-emacs. It's
just too awkward when jumping all over a source file to collect
pieces of stuff and trying to assemble them together. Yeah, I can
use two-window mode with a scratch buffer in the other half, but
then the part of the code I can see at one time is so tiny as to be
painful in itself. So much more user/programmer friendly to have
access to two full-size windows, one remote-emacs and one
local-edit.
I don't know what you're using now.

Yeah, mySituation.html just tells the situation I have to deal with
here, not the coping strategies I use, such as how to browse
newsgroups and post to newsgroups and browse e-mail and send e-mail
etc. without any InterNet access at home. I wonder if I should
write a companion document that tells how I do such things? Until I
decide to write such a document, this below will have to suffice:

To browse newsgroups, I use mostly-broken Google Groups. There's no
longer (since 2.5 years ago) any way to browse threads in tree
view, only a very broken indented-outline view, and no way to jump
from outline view to the single article, making outline view
virtually useless. And since a few weeks ago there's no longer the
time-of-day in the search-result page, so when I click on an
article and get taken to first article in a group of 25 (instead of
the particular article I clicked on), it's a royal pain to find
which of those 25 is the article I wanted. So for the most part
it's hit-or-miss trying to find followups to what I previously
posted so that I can continue back-and-forth discussions. But at
least it's *possible* to find *some* of followups to what I posted,
so it's better than anything else that is availiable AFAIK.

To bookmark an article I want to respond to but don't have time
right away, or to actually compose my reply, I switch to "original"
version, which is **not** the original, it's *mostly* the original,
but with anything of the form alphanum@alphanum munged so I can't
see people's e-mail addresses. Also it has crap at top and bottom
of the Web page it shows. Still it does have the Message-ID field
and other key fields.

To bookmark an article, I copy the Message-ID from the "original"
page, and paste into a local McSink edit.

Later to fetch a bookmarked article, I go to Google Groups search
form where it has a place for look up message by ID, copy
Message-ID from McSink edit and past into GG form. Fortunately that
currently brings up just the one article, not group of 25, so it's
quick to skip two screens of garbage and click on "original" link.

Then to compose my reply, I copy the relevant header lines from the
GG "original" page and paste into McSink, manually rearrange them
so that References is immediately before Message-ID, delete the
Message-ID tag so it chains after the References, then check the
total size of that and trim the oldest parts as needed to reduce it
to 255 or fewer bytes (plus the newline making 256). Then I move
the From: line to be last of the header lines, and add two
characters "> " before it. Then I scroll lynx to bring up the body
of your message and copy various parts of it from lynx/GG screen
and paste into local McSink edit, paragraph-fill, and use
copy&paste to semi-manually insert "> " before each quoted line.
Then I compose my response.

When I'm ready to post, I copy&paste from the headers in that
message to the NNTP template just before it in the file. Then I
ctrl-Z out of lynx, ask Unix for the date&time, copy&paste the
time-of-day from Unix to McSink, but manually patch the date if
it's changed since I previously posted. Then I manually patch my
personal message-ID in the NNTP form. Then I copy&paste the TELNET
to NNTP server, wait for it to respond, type POST, wait for it to
respond, copy&paste the header from my template, wait for it to
finish uploading, copy&paste the message-body, wait for it to
finish uploading, manually type period on line by itself, wait for
it to respond that posting was successful, manually type QUIT
command, wait for it to quit telnet, then CUT the message body from
McSink and paste into a different McSink edit which is
already-posted but not-yet-verified.
Unless you're typing NNTP protocol commands directly,

Well, I think you now know I'm in the "unless" case here, OK?
I haven't a clue what your problem with attribution lines is, ...

It's not my problem. It's your problem.
There's nothing wrong with my methods. It's your nitpicking which is wrong.
 
S

Spiros Bousbouras

To browse newsgroups, I use mostly-broken Google Groups. There's no
longer (since 2.5 years ago) any way to browse threads in tree
view, only a very broken indented-outline view, and no way to jump
from outline view to the single article, making outline view
virtually useless.

To jump from "outline view" to single article you just click on it.
And since a few weeks ago there's no longer the
time-of-day in the search-result page, so when I click on an
article and get taken to first article in a group of 25 (instead of
the particular article I clicked on), it's a royal pain to find
which of those 25 is the article I wanted.

Perhaps your browser is broken ?
To bookmark an article I want to respond to but don't have time
right away, or to actually compose my reply, I switch to "original"
version, which is **not** the original, it's *mostly* the original,
but with anything of the form alphanum@alphanum munged so I can't
see people's e-mail addresses.

Ypu can if you click on the address and then type the phrase it asks
you.
Also it has crap at top and bottom
of the Web page it shows.

The only "crap" I see at the top and bottom are the title of the
thread
and some navigation links.

<Long tedious recital snipped>
 
F

Flash Gordon

Robert Maas, see http://tinyurl.com/uh3t wrote, On 01/04/07 00:41:
It's not my problem. It's your problem.
There's nothing wrong with my methods. It's your nitpicking which is wrong.

No, you failing to follow long established convention despite repeated
requests is the problem. The reason for following the convention is to
make it easy to identify who said what, by not following it you make it
hard. The only reason I can see for you to do this is because you want
to be annoying.
 
R

Robert Maas, see http://tinyurl.com/uh3t

From: Keith Thompson <[email protected]>
The Unix system you dial into probably has the bzip2 and bunzip2
programs.

Indeed it does, but when the .bz2 file came up as garbage in the
Web browser, I had no idea that bunzip2 would be the appropriate
program for uncompressing it, in fact I had no sure knowledge it
was a compressed text file in the first place. For all I knew it
could have been yet another proprietory format such as .doc means
MicroSoft Word and .ps means PostScript and .pdf means Portable
[sic] Document Format and .tt means TeachText and .wav means some
sort of music or sound file I have no idea what program would be
able to render it. Even if I had guessed it might be compressed,
there's no Unix utility that I know of that maps filename
extensions to decompressor/renderer program names. So I had no idea
what program name to look for on Unix, until that earlie poster
stated that .bz2 means compressed with bzip2 (which I never heard
of before), and **then** finally I could say "whereis bzip2" to
find if it was at all available and "man bzip2" to learn how to
undo the compression. I regard it as a bug in the implemention of
this ISP that bunzip2 is available but lynx fails to use it when it
sees a file with .bz2 extension, in fact unlike .doc and .wav files
where it offers to download instead of showing as if text, it's a
double bug that lynx shows .bz2 as if text.

Downloaded just now:
% ls -lt *.gz
272 -rw------- 1 rem user 255909 Mar 31 16:56 n1124.txt.gz
% gunzip n1124.txt.gz
% ls -lt *.txt
1056 -rw------- 1 rem user 1063922 Mar 31 16:56 n1124.txt
% more n1124.txt
WG14/N1124 Committee Draft <97> May 6, 2005 ISO/IEC 9899:TC2

Hmm, that's not a US-ASCII file. What character encoding does it
use? My guess is Latin-1. Is that correct? If Latin-1, that <97>
byte (decimal 151) codes for ... um
<http://www.ramsch.org/martin/uni/fmi-hp/iso8859-1.html>
doesn't show it as a valid character. Let me try the UniCode table
and see if I can find it...
<http://www.fileformat.info/info/unicode/char/0097/index.htm>
Name <control>
Old name END OF GUARDED AREA
Character.isISOControl() Yes
Character.isJavaIdentifierPart() Yes
Char.IsControl() True
Do you have any clear idea why that strange UniCode control
character is in the middle of the title of the document you
provided for me to download?

When I have time I'll have to find that program I wrote that scans
a binary file to compile statistics of the various bytes,
classifies them according to (1) US-ASCII (2) Known Latin-1 (3)
Other, and check if there are any other (3) characters, or any (2)
characters, in that document. Or I could run my program that
converts all non-US-ASCII characters into brace-pictures (if known
Latin-1) or brace-hexadecimal (if unknown), then use grep to find
all lines with open-brace in them.
Ok, you're broke. We get it. Nobody here is responsible for that
fact, or in a position to do anything about it. Do you *have* to
bring up your personal economic situation every time you post here?

Only when some asshole harasses me yet again by telling me yet
again that I **should** buy something I have no money to buy, or
recommends or suggests I buy something ditto, etc. etc. If you-all
would stop telling me to spend money I don't have, and instead
offer me a job whereby I could earn some money to pay off debts and
eventually have money left over to buy something, that would be
much better. Or help me sue spammers for $1000 per spam (California
law), whereby we both profit. In that direction, I'm thinking of
setting up a system whereby people who have info about legal names
and addresses of people who have sent me spam can bid on how much
of the legal proceeds they expect for some piece of information,
lowest bidder wins the contract. 50% to anyone who acts as my
lawyer to fully investigate and file papers and appear in court
etc., 1% to the smallest useful piece of information toward
successful lawsuit, intermediate amounts for intermediate amounts
of usefulness toward successful lawsuit.
 
R

Robert Maas, see http://tinyurl.com/uh3t

From: Keith Thompson said:
A Von Neumann architecture is one with a single address space for
both data and code. This is by contrast to a Harvard
architecture, in which data and code are stored disjointly.
Nothing in C specifies or prefers one over the other.

If you're correct, then there's no portable way in C to cast a
function pointer to a byte pointer and thereby be able to obtain
the machine code for the function, nor to modify the machine code
such as planting a breakpoint.
 
R

Robert Maas, see http://tinyurl.com/uh3t

From: Mark McIntyre said:
Lynx knows all about it - heck,. the linux implementation of
Lynx is /released/ in bzip format. See http://lynx.isc.org/release/

I'm not talking about the shipping department that as you claim
compresses lynx to make shipping more compact. I'm talking about
the programming/testing department, which introduced a total bug by
classifying the extension .bz2 as signifying a **TEXT** file
instead of a **COMPRESSED** file when such a link is clicked-on by
the user of lynx. Do you understand the difference between the two,
and understand how your remark is totally irrelevant except to
emphasize how stupid a bug it must be if they know about bzip
format and actually use it themselves yet totally screw up
implementing .bz2 links in the broswer?
Read up on mime types, and how to configure lynx.

I'm not an administrator on this ISP, so I don't have the ability
to reconfigure system software that the admin has installed for
hundreds of users of the ISP. The best I can do is supply options
when I start up the already-configured program, such as specifying
an editor for text areas.

Besides, why do you think each of several hundred users on an ISP
should have to separately read all about MIME types, and about lynx
config, and then each re-configure their own private copy of lynx
just to overcome a bug in it? Why shouldn't the admin configure it
correctly once for everyone to share??
 
R

Robert Maas, see http://tinyurl.com/uh3t

... you can get text conversions, but you tend to lose some
From: Richard Heathfield <[email protected]>
Feel free to write a better one.

If you have the money to pay for my time, I might be willing to do it.
Has it ever occurred to you to find out?

Before anybody ever told me the name of it? How would you expect me
to have found out myself before I knew what the name was of the
thing I was supposed to find out? I don't know of any search engine
where I could have typed in .bz2 and gotten back bzip2/bunzip2 as a
response. Do you know of any such??
And by the same reasoning, my C compiler can't parse HTML, so
putting C source onto the World Wide Web is obviously a pointless
waste of time.

If C source is plain text that anybody can see and read without
needing to decompress first. Like a foreign language it may not be
immediately understandable to the novice who sees it on a Web site,
but still it's plain text not binary garbage, so a human can view
it directly and make some sense of it even not knowing c
previously, and various function names can be used as search keys
in Google etc. if the reader wishes to get some idea what they do.

By comparison, what shows on-screen when lynx sees a .bz2 file is
totally useless for any purpose, direct understanding, Google
search, or even copy-and-paste to a newsgroup asking what this
bunch of funny characters means.

Your comparison, equating the two, is totally invalid.
 
R

Robert Maas, see http://tinyurl.com/uh3t

If you're on a unix-ish system, try "man func" ...
From: Richard Heathfield <[email protected]>
So now you're saying you don't even understand metasyntactic variables?

No, I'm saying that in English and most other natural languages,
and in lisp, c (this newsgroup), c++, algol, and most other
programming languages, putting double quotes around some text means
to take it *literally* (verbatim, no substitutions allowed or
intended). I honestly thought you meant that as a way to get
general information about the C/machine function-call mechanism, or
some utility called "func", etc., and I was letting you know that
what you told me to do didn't work exactly as you told me, so maybe
you were mistaken in how you communicated, or alternately maybe the
Unix I'm using doesn't implement that command which *is*
implemented on *your* system.

Even in perl and shell, where substitution is allowed, and BNF, but
not inside quotes there, special notation is used to indicate a
substitution, for example:
- perl/sh: "man $func"
- BNF: man <func>
If you had used either of those notations, I might have guessed you
weren't talking C strings, but perl/sh or BNF respectively instead.
It wasn't apparent what you had meant until later when you used a
specific example of a function, which was after I had already spent
considerable time trying what you had told me to literally do which
didn't work and writing up a report of it not working.
I recommend that you consider a career change. Marketing,
perhaps. Or management.

Those are extremely stupid (ignorant) and inappropriate recommedations.
 
K

Keith Thompson

Does it have a feature of scanning *all* the newsgroups in the
whole world to find any followups to articles you have posted, so
that you can continue back-and-forth exchanges?

No, there's no need for that. I read a few newsgroups, and post to
fewer; I don't have any trouble finding followups in the same
newsgroup where I posted.
Or do you first use
Google Groups to scan for followups, then somehow transfer the
message-ID from Google Groups to Gnus to do your actual followup?

No, or course not.

[...]
Do you use Gnus remotely over VT100 dialup?

I don't currently use dialup.
How do you like editing with emacs through VT100 dialup compared to
having the text right there locally on your Macintosh where you can
use mouse to sweep text to copy&pages instead of the more laborous
way you have to do it with vt100-remote-emacs?

I don't generally use GUI-based text editors. I usually use vi; I
occasionally use Emacs. Both work just fine under VT100 emulators,
even via dialup.
From 1975, when I got my first terminal (Beehive 3A) and modem,

[big snip]
Then to compose my reply, I copy the relevant header lines from the
GG "original" page and paste into McSink, manually rearrange them
so that References is immediately before Message-ID, delete the
Message-ID tag so it chains after the References, then check the
total size of that and trim the oldest parts as needed to reduce it
to 255 or fewer bytes (plus the newline making 256). Then I move
the From: line to be last of the header lines, and add two
characters "> " before it. Then I scroll lynx to bring up the body
of your message and copy various parts of it from lynx/GG screen
and paste into local McSink edit, paragraph-fill, and use
copy&paste to semi-manually insert "> " before each quoted line.
Then I compose my response.

Since you're going to all that trouble, and creating your own
attribution lines, it shouldn't be that much harder to *do it right*.
Delete the leading "> From:", and add " writes:" to the end of the
line.

[snip]
Then I copy&paste the TELNET
to NNTP server, wait for it to respond, type POST, wait for it to
respond, copy&paste the header from my template, wait for it to
finish uploading, copy&paste the message-body, wait for it to
finish uploading, manually type period on line by itself, wait for
it to respond that posting was successful, manually type QUIT
command, wait for it to quit telnet, then CUT the message body from
McSink and paste into a different McSink edit which is
already-posted but not-yet-verified.


Well, I think you now know I'm in the "unless" case here, OK?

You have real newsreaders available to you, on the Unix system you
dial into. Find one and learn how to use it. It's a lot easier than
what you're doing now.
It's not my problem. It's your problem.
There's nothing wrong with my methods. It's your nitpicking which is wrong.

You are mistaken. And you are boring. It's no longer my problem,
because I intend to ignore you from now on, unless you start posting
something that's actually relevant to the topic of this newsgroup.
 
K

Keith Thompson

Indeed it does, but when the .bz2 file came up as garbage in the
Web browser, I had no idea that bunzip2 would be the appropriate
program for uncompressing it, in fact I had no sure knowledge it
was a compressed text file in the first place.

And now you know, but you're still whining about it.

[snip]

Downloaded just now: [snip]
% more n1124.txt
WG14/N1124 Committee Draft <97> May 6, 2005 ISO/IEC 9899:TC2

Hmm, that's not a US-ASCII file. What character encoding does it
use? My guess is Latin-1. Is that correct?
[...]

It appears to be some Windows encoding. It shows up as a dash in
n1124.pdf; the <97> character also shows up as a dash in Wordpad and
Notepad under Windows. I think you can safely ignore any non-ASCII
characters.

[snip]
Only when some asshole harasses me yet again by telling me yet
again that I **should** buy something I have no money to buy, or
recommends or suggests I buy something ditto, etc. etc.
[snip]

I don't recall telling you to buy anything. If I have, I've also
mentioned free alternatives.

I even went out of my way to make a plain-text copy of the latest
draft of the C99 standard available to you.

<SARCASM>You're welcome.</SARCASM>

And good-bye.
 
K

Keith Thompson

If you're correct, then there's no portable way in C to cast a
function pointer to a byte pointer and thereby be able to obtain
the machine code for the function, nor to modify the machine code
such as planting a breakpoint.

Correct.
 
S

SM Ryan

(e-mail address removed) (Robert Maas, see http://tinyurl.com/uh3t) wrote:
# > From: Keith Thompson <[email protected]>
# > A Von Neumann architecture is one with a single address space for
# > both data and code. This is by contrast to a Harvard
# > architecture, in which data and code are stored disjointly.
# > Nothing in C specifies or prefers one over the other.
#
# If you're correct, then there's no portable way in C to cast a
# function pointer to a byte pointer and thereby be able to obtain
# the machine code for the function, nor to modify the machine code
# such as planting a breakpoint.

There's no ANSI C portable way because they don't define a
conversion between data and code pointer. You can come up with
a rationale (there are others) but that's not the reason, just
a rationale for the reason. There is a Unix portable way, because
various Unix standards do define a conversion.

On some systems the function pointer is a pointer to code
paired with a pointer to static data; on this a code pointer
is twice as wide as a data pointer.
 
K

Keith Thompson

SM Ryan said:
There's no ANSI C portable way because they don't define a
conversion between data and code pointer. You can come up with
a rationale (there are others) but that's not the reason, just
a rationale for the reason. There is a Unix portable way, because
various Unix standards do define a conversion.

On some systems the function pointer is a pointer to code
paired with a pointer to static data; on this a code pointer
is twice as wide as a data pointer.

Also, you can convert an integer to any pointer type, and vice versa,
so you could convert a function pointer to a sufficiently large
integer, and then convert the integer to an object pointer. But
there's no guarantee that a sufficiently large integer type exists, or
that the result of the conversion will be meaningful, or, even if it
is meaningful, that you'll be permitted to modify, or even to read,
whatever it points to.
 
R

Richard Heathfield

Robert Maas, see http://tinyurl.com/uh3t said:
If you have the money to pay for my time, I might be willing to do it.

Why would I want to hire someone so manifestly incompetent and unable to
learn?
Before anybody ever told me the name of it? How would you expect me
to have found out myself before I knew what the name was of the
thing I was supposed to find out? I don't know of any search engine
where I could have typed in .bz2 and gotten back bzip2/bunzip2 as a
response. Do you know of any such??

Yes; Google. Did you ever hear of that one? First Google hit for bz2 is:

bzip2 : Home
You can use the library in your own programs, to directly read and write
..bz2 files, or even just to compress data in memory using the bzip2
algorithms. ...
www.bzip.org/ - 5k - 30 Mar 2007 - Cached - Similar pages

Sheesh, FCOL, etc. Do you realise how lame you make yourself sound with
every single article? You're not the only one with problems, bub - but
the world doesn't owe you a living. Deal with it.
 

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,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top