trim whitespace v3

J

John Kelly

It seems to me that having a two level API would be most beneficial. A low
level trim_ex() function which returns offset and length of trimmed string,
and a higher level function trim() that actually does in-place
modifications. The high level trim() function could easily be based on the
lower level trim_ex().

Or trim_(). Another level would be trim__(), etc.

If you want to pursue that idea, the code is available to you.
 
J

John Kelly

So you go to extraordinary lengths to find a portable way to generate an
impractical maximum size, but use a non-standard error value?

Who says it's non standard? You?

Do you want to help, or waste my time?
 
K

Keith Thompson

John Kelly said:
Who says it's non standard? You?

The ISO C Standard, specifically section 7.5.

The fact that a reasonably popular implementation doesn't support it
should also be a clue that it's non-standard.

Do dispute the statement that it's non-standard?
Do you want to help, or waste my time?

He's trying to help, but he appears to be wasting his time (though
someone else might benefit from the discussion).
 
F

Francesco S. Carta

Sometimes the visibility depends on another define:

+/* On OSF/1 5.1, when _XOPEN_SOURCE_EXTENDED is not defined, the macros
+ EMULTIHOP, ENOLINK, EOVERFLOW are not defined. */

Maybe you can learn more from the MinGW community.

As I have repeatedly stated, there is no physical evidence about the
existence of such a define in the whole MinGW packages I downloaded, and
once more, the problem about EOVERFLOW is completely up to you to solve,
assuming you consider it a problem.

I'm not accustomed to impose my contribution where it is not welcome,
custom which lead to one and only logical conclusion.
 
S

Seebs

Who says it's non standard? You?

Well, the language spec. :)
Do you want to help, or waste my time?

If you could perceive anything as help which did not consist entirely of
supporting you in whatever idiocy you've undertaken, whether or not it
makes any sense, I think a lot of people would be glad to help you.

Instead, you're sitting here demanding that skilled marksmen and gunsmiths
help you smooth out the inside of the barrel of a gun because the reason
it doesn't shoot straight is that there's some kind of grooves on the inside
of the barrel that make the bullet spin, and that makes it shoot wrong.

-s
 
J

John Kelly

The ISO C Standard, specifically section 7.5.

If many platforms have it, that's a practical standard more important to
me.

The fact that a reasonably popular implementation doesn't support it
should also be a clue that it's non-standard.

Do dispute the statement that it's non-standard?

I don't dispute that you and your tag team partners are wasting my time.
 
S

Seebs

If many platforms have it, that's a practical standard more important to
me.

That's not a standard, that's a common occurrence.

And the thing is...

This actually IS an interesting and topical discussion. How do you decide
what's "standard enough"? As a general rule, I advocate the following
policy:

When considering the use of a feature, weigh its portability against its
value to you.

As an example: I believe that snprintf() is close enough to universally
accessible that I don't even consider not-using-snprintf. I use it, I use
it consistently, and if some day I encounter a system which lacks it, I
figure I'll grab the source from one of the BSDs. (Since I work on embedded
Linux mostly these days, I'm not worried about people being afraid of
open source.)

But I do that because I've found that snprintf() is extremely useful to me
in clearly, idiomatically, and safely implementing a common requirement.

I would never use EOVERFLOW unless it were mandated by a specification, and
I would object to any specification which mandated it. That's because I
consider it an unnecessary extension that doesn't give much specific
information. (I'm not even sure it's sensical in the context of a trim
function, for that matter.) It's not that it's all that unportable; it's
just that there's no marginal benefit.

I'll put up with a great deal of non-portability if necessary; I use
the RTLD_NEXT feature of a dynamic linker, even though it's a local
extension that isn't particularly portable, because there is NO other
way to accomplish the thing I want to do, so far as I can tell. Certainly
no practical one.

I think the issue here is not just how portable or non-portable EOVERFLOW
is, but that it's not particularly improving the utility of the code to
rely on it. That, and more generally, your complete lack of interest in
anyone's needs but your own is pretty much pathological. That is not a sane
way for a human to live.

-s
 
J

James

John Kelly said:
Or trim_(). Another level would be trim__(), etc.

Sounds okay to me.

If you want to pursue that idea, the code is available to you.

I already did the low level trim_ex() here:

http://groups.google.com/group/comp.lang.c/msg/297f4cd484882b20

Coding the trim() would be trivial due to the "detailed" information
provided by trim_ex().

BTW, the trim_ex() function returns failure (e.g., returns zero), if you
pass it a string that happens to have a size grater than SIZE_MAX. Not sure
how practical that safe guard is, but its there anyway.
 
G

Geoff

I cannot compile your code with MinGW (4.4.0 32bit nor 4.5 64bit).
I pointed out the two missing macros above just to let you know about an
implementation which needs further attention.

Just for the records I'll report this here:

#define EPERM 1 /* Operation not permitted */
#define ENOFILE 2 /* No such file or directory */ [snip]
#define ENOTEMPTY 41 /* Directory not empty (90 in Cyg?) */
#define EILSEQ 42 /* Illegal byte sequence */


They say "oil is where you find it."

On linux

# find /usr/include -type f -exec grep -Hn EOVERFLOW {} \;
/usr/include/asm-generic/errno.h:48:#define EOVERFLOW 75


On Interix

# find /usr/include -type f -exec grep -on EOVERFLOW {} \;
/usr/include/errno.h:122:#define EOVERFLOW 88


On MinGW I don't know where EOVERFLOW or PTRDIFF_MAX reside. I can only
suggest using tools like "find" and "grep" to locate them.

First of all let me clarify that this is not a big issue for me: the
code is yours and it should be up to you to make it portable (assuming
that target falls within your aims).

I'm just doing my best to help in the few spots that I can (testing your
code with a toolchain and a system that you have not at your disposal).

Going on with the same spirit: in my implementation PTRDIFF_MAX resides
in <stdint.h> (it didn't find it because you didn't include that header).

EOVERFLOW is definitely missing.

I must agree with Keith, check the documentation for your implementation.
Grepping might find it but it won't tell you the proper way to include it for
your implementation. For example, in VS 2010 it's defined in <errno.h>, has the
value 132 and is documented as being a POSIX supplement. John is using it
because it fits his environment because Interix is a POSIX based implementation
of UNIX services for Windows. The values in his environment for EINVAL and
EOVERFLOW are different from mine.
 
U

Uno

Seebs said:
Why so personal? I can be a real grade-A jerk, but I happen to know a
fair bit about the subject matter, and I'm usually pretty willing to
answer interesting questions.

The more-troubling scenario is when we who are looking to improve our
game with C run onto a question that isn't pure enough to be discussed
around you and your pushy, ideological friends.
Now, I recognize that you don't read my posts, but I suppose this is
something that I think is of use to general readers, whether they program
in C or not:

If you want to learn, it is nearly always devastatingly bad form to
write people off based on personality conflicts. If someone knows the
material, pay attention to what they have to say, and if they annoy
you, deal with it on your own time. As you say, life is short; you
don't have time to be a prima donna. If the advice you need is available
from an asshole, it's time to learn to filter content from the writing
of an asshole.

.... or ... you can just not post the "go somewhere else to find an
answer," and of course leave that place unnamed. In the Southwest, we
just usually say "**** off."
Robustness in the face of poor behavior is a core skill for ANYONE who
wants to learn to program, or really, who wants to do anything which
may at some point involve other people. It's not an optional thing that
comes long after developing skill at the field.

You know, Peter, I'm a practicing lousy Christian, and I thought I'd try
to figure out what you're damage is, so I googled you:

http://i34.tinypic.com/35hkdwg.jpg

One thing I learned in so doing is that you are an englishman. I didn't
know that, but that is the nationality of the majority of Topic Fundies
in c.l.c., so that would make sense.

However, you looked like a guy I would be friends with in real life. I
was honestly expecting you to be twenty years older and freakishly
scarred or malformed. Why is that?

Peter, a person's C source is more personal than poetry. It's hard
enough to not take criticism emotionally, and the vicissitudes of usenet
don't make that easier. Many times, others can't read all the posts. I
notice this very frequently, as I have several newsreaders on different
platforms.

C.l.c. has come a long way since Chuck was management. Do you consider
a Topic Guard to be necessary?
 
J

John Kelly

The more-troubling scenario is when we who are looking to improve our
game with C run onto a question that isn't pure enough to be discussed
around you and your pushy, ideological friends.

To Seebs it's all a mind game. But I'm old and grouchy and I don't have
time to play.
 
S

Seebs

Er, uhm. Actually, no, the problem is that you're a lunatic who has to
change posting names and addresses every so often because the old ones
get killfiled. And who steadfastly refuses to reason things through,
instead trying things at random, or grabbing random unrelated things
and asking whether they're related.

Uno, your approach to debugging is like doing geneaology by getting a
phone book, picking a name at random, then picking another name at random,
and asking them whether they are related. There's no method, no attempt
to apply available information to the task of finding new information.
To Seebs it's all a mind game.

Not really, no.
But I'm old and grouchy and I don't have time to play.

As is so often the case, people who think they are too busy to do something
right take more time than people who take the "extra" time to do it right.

Hint: If you seriously want to learn, you *MUST* play. There is no
effective way to learn any topic, any field of study, without play. If
you are not having fun when you are programming, you are not learning
as efficiently as someone who is having a great time at it, no matter
how much effort you put in.

The brain is built to learn -- and has well-designed tools for doing so.
Work with them, rather than against them.

-s
 
M

Malcolm McLean

    Trim leading and trailing whitespace from any null terminated string
    found in memory, no matter whether data or garbage.  Reports failure
    and quits if null terminator not found within system defined limit.

Encountering such a specification for code to be written, a programmer
might think that the program should look through memory to find any
null terminated strings, and remove leading and trailing whitespace
from each such string.
It's a weird specification. 'Found in memory', OK, means we don't have
to write special code to trim strings in backing store. But that would
be assumed. "Whether data or garbage", you can't produce sensible
results from garbage. There's no system defined limit for a maximium
string size, except the range of a size_t. Whilst the last requirement
is possible to fulfil, it is fiddly, and most systems entirely
irrelevant (the program will surely segfault long before the size_t
index clocks rounds).
 
U

Uno

John said:
To Seebs it's all a mind game. But I'm old and grouchy and I don't have
time to play.

You're OP, and he's sitting on your thread saying that you're not sane.
There's always a dozen obnoxious Seebses in clc.
 
U

Uno

Seebs said:
Er, uhm. Actually, no, the problem is that you're a lunatic who has to
change posting names and addresses every so often because the old ones
get killfiled. And who steadfastly refuses to reason things through,
instead trying things at random, or grabbing random unrelated things
and asking whether they're related.

Uno, your approach to debugging is like doing geneaology by getting a
phone book, picking a name at random, then picking another name at random,
and asking them whether they are related. There's no method, no attempt
to apply available information to the task of finding new information.

So my programming is not up to snuff for you, right?

Maybe I'm asking about the things I don't get. I'm certain that I have
a much greater correspondence than you with the authors of C Unleashed,
which you use as an image.

Yeah Heathfield and I spend time in each other's killfiles.

Maybe I'm on a platform that is new to me.

Maybe I learn differently than you.

I can think of a million ways to insult you, all of them true.

Have a good night.
 
F

Francesco S. Carta

On Mon, 23 Aug 2010 18:14:45 +0200, "Francesco S. Carta"


I cannot compile your code with MinGW (4.4.0 32bit nor 4.5 64bit).

I pointed out the two missing macros above just to let you know about an
implementation which needs further attention.

Just for the records I'll report this here:

#define EPERM 1 /* Operation not permitted */
#define ENOFILE 2 /* No such file or directory */
[snip]
#define ENOTEMPTY 41 /* Directory not empty (90 in Cyg?) */
#define EILSEQ 42 /* Illegal byte sequence */


They say "oil is where you find it."

On linux

# find /usr/include -type f -exec grep -Hn EOVERFLOW {} \;
/usr/include/asm-generic/errno.h:48:#define EOVERFLOW 75


On Interix

# find /usr/include -type f -exec grep -on EOVERFLOW {} \;
/usr/include/errno.h:122:#define EOVERFLOW 88


On MinGW I don't know where EOVERFLOW or PTRDIFF_MAX reside. I can only
suggest using tools like "find" and "grep" to locate them.

First of all let me clarify that this is not a big issue for me: the
code is yours and it should be up to you to make it portable (assuming
that target falls within your aims).

I'm just doing my best to help in the few spots that I can (testing your
code with a toolchain and a system that you have not at your disposal).

Going on with the same spirit: in my implementation PTRDIFF_MAX resides
in<stdint.h> (it didn't find it because you didn't include that header).

EOVERFLOW is definitely missing.

I must agree with Keith, check the documentation for your implementation.
Grepping might find it but it won't tell you the proper way to include it for
your implementation. For example, in VS 2010 it's defined in<errno.h>, has the
value 132 and is documented as being a POSIX supplement. John is using it
because it fits his environment because Interix is a POSIX based implementation
of UNIX services for Windows. The values in his environment for EINVAL and
EOVERFLOW are different from mine.

I'm not so sure I understand the reference you're making about Keith,
and actually, neither I am sure that you're really addressing the above
reply to me, although it seems to be so.

As you could read in the other thread-branch that descends from the
message you have just quoted from me, the issue about the presence of
EOVERFLOW in MinGW (and I suppose in GCC in general) should be already
ascertained, and the result should be that such a macro is not defined,
nowhere in the package it seems to be.
 
I

Ian Collins

I'm not so sure I understand the reference you're making about Keith,
and actually, neither I am sure that you're really addressing the above
reply to me, although it seems to be so.

As you could read in the other thread-branch that descends from the
message you have just quoted from me, the issue about the presence of
EOVERFLOW in MinGW (and I suppose in GCC in general) should be already
ascertained, and the result should be that such a macro is not defined,
nowhere in the package it seems to be.

EOVERFLOW is from POSIX, so it will be defined in the system headers
(rather than those supplied by the compiler) on any POSIX compliant system.
 
F

Francesco S. Carta

EOVERFLOW is from POSIX, so it will be defined in the system headers
(rather than those supplied by the compiler) on any POSIX compliant system.

Fine, I think I have already understood that a conforming C
implementation is not required to provide such a macro.

What puzzles me is whether I give the impression that I didn't
understood the issue, or whether I give the impression that I'm even
remotely worried about it. I pointed out and discussed it just to the
advantage of the OP.
 
J

John Kelly

Seebs treats people like video game characters, then questions why not
everyone will tolerate it. He thinks his knowledge is so valuable that
it should excuse anything he says.

Common sense says, what goes around, comes around. Or if you understand
farming, you can only reap what you sow.
 

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

Similar Threads

trim whitespace, bullet proof version 63
trim whitespace 194
trim 6
Trim string 42
Request for source code review of simple Ising model 88
Strange bug 65
malloc and maximum size 56
Dead Code? 4

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top