guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setting env variable from Guile


From: Thien-Thi Nguyen
Subject: Re: setting env variable from Guile
Date: Sat, 30 Jul 2005 11:12:45 -0400

   From: Mike Gran <address@hidden>
   Date: Sat, 30 Jul 2005 06:47:57 -0700 (PDT)

   You could wrap the function lt_dladdsearchdir as
   a Guile function and call it from your script.

fyi, this is the approach taken in Guile 1.4.x,
as implemented in libguile/lt.c, below.  works fine.


thi


_____________________________________________________
/* lt.c */

/*      Copyright (C) 2002 Free Software Foundation, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * As a special exception, the Free Software Foundation gives permission
 * for additional uses of the text contained in its release of GUILE.
 *
 * The exception is that, if you link the GUILE library with other files
 * to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the GUILE library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the
 * Free Software Foundation under the name GUILE.  If you copy
 * code from other Free Software Foundation releases into a copy of
 * GUILE, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for GUILE, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.  */

/* This is wrapper code for libltdl.  It should be possible to generate
   it completely at some point.  */


#include <stdio.h>
#include "libguile/_scm.h"
#include "libguile/eq.h"
#include "libguile/list.h"

#include "libguile/validate.h"
#include "libguile/strings.h"
#include "libguile/lt.h"

#include "libltdl/ltdl.h"

static SCM
add_search_dir_x (char *dir)
{
  if (0 == lt_dladdsearchdir (dir))
    return SCM_UNSPECIFIED;
  scm_misc_error (NULL, (char *) lt_dlerror (), SCM_EOL);
}

static SCM
set_search_path_x (char *path)
{
  return ((0 == lt_dlsetsearchpath (path))
          ? SCM_BOOL_T
          : SCM_BOOL_F);
}

static SCM
get_search_path (void)
{
  return scm_makfrom0str_opt (lt_dlgetsearchpath ());
}

/* This is an experimental interface so we use a named command approach
   and use a "double %" prefix.  */

SCM_GLOBAL_SYMBOL (scm_sym_add_search_dir_x, "add-search-dir!");
SCM_GLOBAL_SYMBOL (scm_sym_set_search_path_x, "set-search-path!");
SCM_GLOBAL_SYMBOL (scm_sym_get_search_path, "get-search-path");

SCM_DEFINE (scm_percent_percent_ltdl, "%%ltdl", 1, 0, 1,
            (SCM command, SCM args),
            "Dispatch @var{command} given @var{args}, where\n"
            "@var{command} is one of @code{add-search-dir!},\n"
            "@code{set-search-path!}, or @code{get-search-path}\n"
            "(a symbol).  This interface is highly experimental.\n")
#define FUNC_NAME s_scm_percent_percent_ltdl
{
  SCM_VALIDATE_SYMBOL (1, command);

  /* add-search-dir! */
  if (SCM_EQ_P (command, scm_sym_add_search_dir_x))
    return add_search_dir_x (SCM_ROCHARS (SCM_CAR (args)));

  /* set-search-path! */
  if (SCM_EQ_P (command, scm_sym_set_search_path_x))
    return set_search_path_x (SCM_ROCHARS (SCM_CAR (args)));

  /* get-search-path */
  if (SCM_EQ_P (command, scm_sym_get_search_path))
    return get_search_path ();

  /* badness */
  scm_misc_error (NULL, "bad command", SCM_EOL);
}
#undef FUNC_NAME


void
scm_init_lt ()
{
#include "libguile/lt.x"
}

/* lt.c ends here */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]