Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ethan (3163)

ethan
  reversethis-{ed. ... rap.nov.olissat}

Being a 25-year old chap living in the western-most town of Germany. Stuying communication and information science and being a huge fan of XS-related things.

Journal of ethan (3163)

Friday November 01, 2002
06:50 AM

XS pleasures

[ #8721 ]

After my rants about Halloween I decided to become a useful part of society again by turning back to my current XS port of the mplib.

Doing XS is actually pretty cool, despite what people generally tend to say about it. But sometimes it is just a little too verbose for my taste. Consider the following chatty code that maps and i3v1_tag structure to a Perl hash (HV):


int fill_sv_v1tag(HV * hv, id3_tag * t) {

        id3_content * content;

        content = mp_get_content(t, MP_ARTIST);
        hv_store(hv, "ARTIST", 6, newSVpv(content ? mp_parse_artist(content)->text : "", 0), 0);

        content = mp_get_content(t, MP_TITLE);
        hv_store(hv, "TITLE", 5, newSVpv(content ? mp_parse_title(content)->text : "", 0), 0);

        content = mp_get_content(t, MP_ALBUM);
        hv_store(hv, "ALBUM", 5, newSVpv(content ? mp_parse_album(content)->text : "", 0), 0);

        content = mp_get_content(t, MP_GENRE);
        hv_store(hv, "GENRE", 5, newSVpv(content ? mp_parse_genre(content)->text : "", 0), 0);

        content = mp_get_content(t, MP_TRACK);
        hv_store(hv, "TRACK", 5, newSVpv(content ? mp_parse_track(content)->text : "", 0), 0);

        content = mp_get_content(t, MP_YEAR);
        hv_store(hv, "YEAR", 4, newSVpv(content ? mp_parse_year(content)->text : "", 0), 0);

        content = mp_get_content(t, MP_COMMENT);
        hv_store(hv, "COMMENT", 7, newSVpv(content ? mp_parse_comment(content)->text : "", 0), 0);

}

The mplib's author had the guts to create all those pesky little mp_parse_FIELD functions so I can't that easily do that in a simple for-loop. I wish C had an eval() function! Perhaps I can come up with a macro that does this work for me.

If you wonder how I do the corresponding thing for id3v2 tags with 74 different frames: omission to the rescue! There are no such mp_parse_* functions for those so I have to do that myself. Thanks God!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.