view src/sprite.c @ 1299:6949e2b6cae2

Add unlink clone checker. - Monitor changes of DOM-tree of the document - Unlinking a clone is actually removing the clone and copying nodes from the source. - Copy value of ID of a node to saved_id to track source of copy nodes. - For a new node with 'saved_id' is a copy of another node. - Copy vulae of 'saved_id' to 'ns0:duplicate-src' to keep the source - Change value of 'saved_id' to the value of ID of the node for later copying. - For a new node without 'saved_id' is not a copy of another node. - only set 'saved_id' to the value of its ID.
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 16 Jan 2011 16:13:37 +0800
parents 8679b03f72e8
children
line wrap: on
line source

// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
// vim: sw=4:ts=8:sts=4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <sys/stat.h>
#include "mb_types.h"
#include "mb_redraw_man.h"
#include "mb_sprite.h"

#define ASSERT(x)
#define OK 0
#define ERR 1

static char *sprite_search_path = NULL;

static char *sprite_search_so(const char *name) {
    struct stat st;
    int fsz;
    char *fullname;
    int r;

    if(sprite_search_path == NULL)
	sprite_search_path = strdup("/usr/share/madbutterffly");

    fsz = strlen(sprite_search_path) + strlen(name) + 5;
    fullname = (char *)malloc(fsz);

    snprintf(fullname, fsz, "%s/%s.so", sprite_search_path, name);
    r = stat(fullname, &st);
    if(r != 0) {
	free(fullname);
	return NULL;
    }

    return fullname;
}

void sprite_set_search_path(const char *path) {
    int sz;

    if (sprite_search_path)
	free(sprite_search_path);

    sprite_search_path = strdup(path);

    sz = strlen(sprite_search_path);
    if(sprite_search_path[sz - 1] == '/')
	sprite_search_path[sz - 1] = 0;
}

mb_sprite_t *
sprite_load(const char *name, redraw_man_t *rdman, coord_t *root) {
    char cnstr_name[256];
    char *so_path;
    const char *bname;
    void *handle;
    mb_sprite_t *(*cnstr)(redraw_man_t *, coord_t *);
    mb_sprite_t *obj;
    int r;

    so_path = sprite_search_so(name);
    if(so_path == NULL)
	return NULL;

    handle = dlopen(so_path, RTLD_LAZY);
    free(so_path);
    if (handle == NULL)
	return NULL;

    bname = strrchr(name, '/');
    if(bname != NULL && strlen(bname) > 250)
	return NULL;

    if(bname == NULL)
	bname = name;
    else
	bname++;

    snprintf(cnstr_name, sizeof(cnstr_name), "%s_new", bname);
    cnstr = dlsym(handle, cnstr_name);
    if (cnstr == NULL)
	return NULL;

    obj = cnstr(rdman, root);

    return obj;
}