Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Some kind of landmark

As of right now, my cus­tomers owe me more than I billed in the sec­ond half of last year, and more comes due each month.

I sup­pose that's bad be­cause I am suck­ing at col­lect­ing. On the oth­er hand, it al­so means I am not suck­ing at billing. Or maybe yes, but much less than last year.

New look for this blog.

Af­ter many years, this is the first rad­i­cal change of look.

It's not very nice, be­cause my HTML skil­lz sux0rz, but hey, it's dark­er!

There are many lit­tle things wrong (like the col­or of vis­it­ed links) but I like it.

It's al­so a bit sim­pler, and I did the ban­ner us­ing inkscape (I had it done much nicer us­ing Kar­bon, but then I could­n't fig­ure out how to do the gra­di­en­t. Oh, well).

Up­date1: It looks in­cred­i­bly aw­ful on IE6, from the un­trans­par­ente PNG to the un­sup­port­ed over­flow:au­to I think I caught ev­ery damn thing that does­n't work :-)

Update2: Both IE and Konqueror will not use overflow: auto if the object is inside a table. In a blog that posts code and logs, and so on, that's a big problem.

So, to make this kin­da work, I had to get rid of (al­most) all ta­bles.

It looks ok now, ex­cept on IE the side­bar is at the bot­tom right, which is prob­a­bly be­cause it cal­cu­lates el­e­ment widths dif­fer­ent­ly.

My SPF lib improving

It now can do a bunch of things like ex­pand­ing macros and (in some cas­es) val­i­dat­ing mech­a­nism­s.

I am mak­ing very heavy use of unit test­ing, be­cause it's a pret­ty com­plex piece and each func­tion needs to do ex­act­ly the right thing or ev­ery­thing else fails (it's pret­ty hard to fig­ure out where it will fail ;-)

You can check the 947 LOC thing at http://­code.­google.­com/p/raspf (the Code tab).

If you do check it, jeep in mind the fol­low­ing:

  • It us­es a few lib­s, and they are in­­­clud­ed in the source code for sim­­plic­i­­ty.

  • I do some­­times com­mit code that does­n't com­pile

  • I do some­­times com­mit code that fails tests

  • You need cmake

  • I am not giv­ing a damn about mem­o­ry man­age­­ment right now, so don't both­­er wor­ry­ing about leak­s: ev­ery­thing leaks in this code. I want to make it func­­tion­al first, then I can plug it one func­­tion at a time (sim­­ply by run­n­ing the unit test­ing code with a mem­o­ry check­­er).

En­joy (although it's not pre­cise­ly en­joy­able code right now ;-)

C is not Python

I am port­ing pyspf to C (long sto­ry, and I am stupid for try­ing). But of course, C is not python.

So you don't have anything nearly as nice as re.­com­pile("what­ev­er").s­plit("­somestring").

What is that good for, you may ask? Well, to do things like split­ting email ad­dress­es while val­i­dat­ing them, or in this spe­cif­ic case, to val­i­date SPF mech­a­nisms (n­ev­er­mind what those are).

But hey, you can al­ways do this (ex­cuse me while I weep a lit­tle):

struct bstrList *re_split(const char *string, const char *pattern)
    int status;
    regex_t re;
    regmatch_t pmatch[20];

    if (regcomp(&re, pattern, REG_ICASE|REG_EXTENDED) != 0)
        return(0);      /* Report error. */

    bstring tmp=bfromcstr("");
    char *ptr=(char *)string;

    for (;;)
        status = regexec(&re, ptr, (size_t)20, pmatch, 0);
        if (status==REG_NOMATCH)
        bcatblk (tmp,ptr,pmatch[0].rm_so);
        bconchar (tmp,0);
        bcatblk (tmp,ptr+pmatch[0].rm_so,pmatch[0].rm_eo-pmatch[0].rm_so);
        bconchar (tmp,0);

    bcatblk (tmp,ptr,strlen(string)-(ptr-string));
    struct bstrList *l= bsplit(tmp,0);
    return l;

And that is prob­a­bly wrong for some cas­es (and it does­n't split the ex­act same way as Python, but that's what unit test­ing is for).

I must be miss­ing some­thing that makes reg­comp & friends nicer to use. Right? Right?

Any regex wizard reading this?

If so, what is the C POSIX regex (y­ou know reg­comp & friend­s) equiv­a­lent of this python reg­u­lar ex­pre­sion:

re.compile(r'^([a-z][a-z0-9_\-\.]*)=', re.IGNORECASE)

Be­cause it sure is­n't this:


I have been play­ing with it for two hours and am bored :-)

Contents © 2000-2024 Roberto Alsina