Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, March 28, 2024

File: [Platon] / libco / libco / co_module.c (download)

Revision 1.5, Sat Mar 15 15:23:07 2003 UTC (21 years ago) by yenar


Changes since 1.4: +1 -0 lines

debug ++ [co_module.c]

/***{{{*******************************************************************
 * This file is part of libco - object library for C                     *
 * Copyright (c) 2002                                                    *
 *     Peter Rockai (yenar) <yenar@host.sk>                              *
 *                                                                       *
 * This library is free software; you can redistribute it and/or         *
 * modify it under the terms of the GNU Lesser General Public            *
 * License as published by the Free Software Foundation; either          *
 * version 2 of the License, or (at your option) any later version.      *
 *                                                                       *
 * This library is distributed in the hope that it will be useful,       *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 * Lesser General Public License for more details.                       *
 *                                                                       *
 * You should have received a copy of the GNU Lesser General Public      *
 * License along with this library; if not, write to the Free Software   *
 * Foundation, Inc., 59 Temple Place, Suite 330,                         *
 * Boston, MA 02111-1307  USA                                            *
 *******************************************************************}}}***/
/* {{{ file description */
/**
 * @file co_module.c
 * @brief Dynamic module-loading for libco.
 **/
/* }}} */

#include <ltdl.h>
#include <stdio.h>

#include "co_object.h"
#include "co_util.h"
#include "co_conv.h"
#include "co_module.h"
#include "co_super.h"

/* {{{ */
void __co_module_init (void)
{
    lt_dlinit ();
}
/* }}} */
/* {{{ */
void __co_module_fini (void)
{
    lt_dlexit ();
}
/* }}} */

/* {{{ */
static void *try_init (lt_dlhandle m, const char *p1, const char *p2)
{
    const char *init = 0;
    char *n = 0;
    void *ret;
    if (!p1) return 0;
    if (p2) {
        n = new_ar (char, strlen (p1) + strlen (p2) + 1);
        strcpy (n, p1);
        strcat (n, p2);
        init = n;
    } else {
        init = p1;
    }
    CO_DEBUG (2, "trying to call: %s", init);
    ret = lt_dlsym (m, init);
    if (p2)
        cox_del (n);
    return ret;
}
/* }}} */

/* {{{ */
co co_module_load (co_super super, const char *mod)
{
    lt_dlhandle m;
    co (*init) (co_super);
    CO_DEBUG (1, "trying to get module (mod = %s)\n", mod);
    m = lt_dlopenext (mod);
    if (!m) {
        printf ("error: %s\n", lt_dlerror ());
        return 0;
    }
    /* init_n = new_ar (char, strlen (mod) + 16);
    CO_DEBUG (1, "got module (m = %p)\n", m);
    strcpy (init_n, "__co_mod_init_");
    strcat (init_n, mod);
    init = lt_dlsym (m, init_n);
    cox_del (init_n); */
    if ((init = try_init (m, "__co_mod_autoinit", mod))) {
        init (super);
    }
    if ((init = try_init (m, "__co_mod_init_", mod))) {
        return init (super);
    } else if ((init = try_init (m, "__co_mod_init", 0))) {
        return init (super);
    } else {
        return 0;
    }
}
/* }}} */

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top