Re: [exim-dev] ${index}

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Phil Pennock
Datum:  
To: Mike Cardwell
CC: exim-dev
Betreff: Re: [exim-dev] ${index}
On 2010-10-20 at 10:48 +0100, Mike Cardwell wrote:
> On 20/10/2010 02:48, Phil Pennock wrote:
> > Note that Exim doesn't really do much sequential work with variables
> > holding results, although it can of course be so abused, so I'm curious
> > about the desire to use an expansion operator instead of an expansion
> > condition for the basic check. What's the use-case?
>
> Can you clarify the above please. How would it work as an expansion
> condition? Can you show me an example of what the Exim config would look
> like? I did initially think of writing a "contains" condition, ie:
>
> condition = ${if contains{string}{substring}{true}{false}}


That's exactly what an expansion condition is: something which can be an
argument to ${if...}; as opposed to an expansion operator, which
converts a string to a string.

My concern is the use-cases, but it seems fairly harmless to just do
what you did (which is actually an expansion item, not an expansion
operator, and is an example of Exim being confusing).

> > Is %d cross-platform safe formatting for a ptrdiff_t type?
>
> I don't know. I'm used to programming in languages that don't have this
> sort of issue. How would I find out if that's cross-platform safe? Or is
> the only way testing and experience? Is there a better way of doing that
> part that doesn't involve string_sprintf?


Research. And pain.
>
> So I'd just need to use %ld instead of %d in that sprintf? You said a
> "long long" would be more portable but I came across this which makes me
> wonder: http://track.sipfoundry.org/browse/XCL-92


The C99 standard says %lld and Windows differs. It looks like Windows
does support %lld these days, and someone was encountering issues with
a rather old compiler. Since Windows is the environment where ptrdiff_t
might be 64-bit and %ld might be 32-bit and Windows is the environment
where we can't count on %lld and Exim rarely runs on Windows and we
should never be dealing with strings long enough for this to matter (the
string is already in memory), I suggest %ld with a (long) cast.

> > And there's no PRIi* macro for ptrdiff_t. *sigh*
>
> Err, I've no idea what that means. PRIi*?


There are semi-portable portability macros which can be used for sizing
numbers for printing and scanning, so that you can make the string even
harder for the programmer to read, in exchange for always having the
right s/l/whatever in front of the number specifier. You get them from
<inttypes.h> and they're basically a poor quality band-aid for not
changing the language to allow the printf length modifiers to be
unnecessary, by inferring the correct specifier from the types of the
arguments [in fairness, it would be a rather large change to C's model].

> I spend most of my time in Perl, so that's where the naming and -1 came
> from. It's not a perfect name though no. Javascript uses indexOf. I like
> "find", but it wouldn't be clear if you're trying to find a string in a
> string, or a string in a list, or something else. I think strindex is
> the best name, but it doesn't look Eximy enough.


Does to me, but I'm weird.

-Phil