Beispiel #1
0
static gboolean id3v24_write_tag (const Tuple * tuple, VFSFile * f)
{
    gint version, header_size, data_size, footer_size;
    gboolean syncsafe;
    gint64 offset;

    if (! read_header (f, & version, & syncsafe, & offset, & header_size,
     & data_size, & footer_size))
        return FALSE;

    //read all frames into generic frames;
    mowgli_dictionary_t * dict = mowgli_dictionary_create (strcasecmp);
    read_all_frames (f, version, syncsafe, data_size, dict);

    //make the new frames from tuple and replace in the dictionary the old frames with the new ones
    add_frameFromTupleStr (tuple, FIELD_TITLE, ID3_TITLE, dict);
    add_frameFromTupleStr (tuple, FIELD_ARTIST, ID3_ARTIST, dict);
    add_frameFromTupleStr (tuple, FIELD_ALBUM, ID3_ALBUM, dict);
    add_frameFromTupleInt (tuple, FIELD_YEAR, ID3_YEAR, dict);
    add_frameFromTupleInt (tuple, FIELD_TRACK_NUMBER, ID3_TRACKNR, dict);
    add_frameFromTupleStr (tuple, FIELD_GENRE, ID3_GENRE, dict);
    add_comment_frame (tuple_get_string (tuple, FIELD_COMMENT, NULL), dict);

    if (! offset)
    {
        if (! cut_beginning_tag (f, header_size + data_size + footer_size))
            goto ERR;
    }
    else
    {
        if (offset + header_size + data_size + footer_size != vfs_fsize (f))
            goto ERR;
        if (vfs_ftruncate (f, offset))
            goto ERR;
    }

    offset = vfs_fsize (f);

    if (offset < 0 || vfs_fseek (f, offset, SEEK_SET) || ! write_header (f, 0,
     FALSE))
        goto ERR;

    data_size = writeAllFramesToFile (f, dict);

    if (! write_header (f, data_size, TRUE) || vfs_fseek (f, offset, SEEK_SET)
     || ! write_header (f, data_size, FALSE))
        goto ERR;

    mowgli_dictionary_destroy (dict, free_frame_cb, NULL);
    return TRUE;

ERR:
    mowgli_dictionary_destroy (dict, free_frame_cb, NULL);
    return FALSE;
}
Beispiel #2
0
Formatter *
formatter_register(const gchar *key, const gchar *format, int args)
{
    Formatter *f;

    if (!formatter_initialized)
    {
        formatters = mowgli_dictionary_create(g_ascii_strcasecmp);
        formatter_initialized++;
    }

    f = g_slice_new0(Formatter);
    f->key = g_strdup(key);
    f->format = g_strdup(format);
    f->args = args;

    mowgli_dictionary_add(formatters, key, f);

    return f;
}
Beispiel #3
0
int main(int argc, const char *argv[])
{
    mowgli_dictionary_t *test_dict;
    mowgli_random_t *r;
    char key[10];
    long ans[100], i;
    int pass = 0, fail = 0;

    mowgli_init();

    test_dict = mowgli_dictionary_create(strcasecmp);
    r = mowgli_random_create();

    for (i = 0; i < 100; i++)
    {
        ans[i] = mowgli_random_int(r);
        snprintf(key, 10, "%ldkey%ld", i, i);
        mowgli_dictionary_add(test_dict, key, (void *) ans[i]);
    }

    for (i = 0; i < 100; i++)
    {
        snprintf(key, 10, "%ldkey%ld", i, i);

        if ( (long) mowgli_dictionary_retrieve(test_dict, key) != ans[i])
        {
            printf("FAIL %ld %p[%p]\n", i, mowgli_dictionary_retrieve(test_dict, key), (void*) ans[i]);
            fail++;
        }
        else
        {
            printf("PASS %ld %p[%p]\n", i, mowgli_dictionary_retrieve(test_dict, key), (void*) ans[i]);
            pass++;
        }
    }

    printf("%d tests failed, %d tests passed.\n", fail, pass);
    return 0;
}
Beispiel #4
0
void
mowgli_global_storage_init(void)
{
	mowgli_global_storage_dict = mowgli_dictionary_create(strcasecmp);
	mowgli_global_storage_lock = mowgli_spinlock_create();
}