2000-04-27 22:03:57 +02:00
|
|
|
/**********
|
|
|
|
|
Copyright 1991 Regents of the University of California. All rights reserved.
|
|
|
|
|
**********/
|
|
|
|
|
|
|
|
|
|
#include "ngspice.h"
|
|
|
|
|
#include "ivars.h"
|
2001-04-16 11:58:25 +02:00
|
|
|
|
2007-11-28 18:38:00 +01:00
|
|
|
#ifdef HAVE_LIBIBERTY_H /* asprintf */
|
|
|
|
|
#include <libiberty.h>
|
|
|
|
|
#endif
|
2000-04-27 22:03:57 +02:00
|
|
|
|
|
|
|
|
char *Spice_Path;
|
|
|
|
|
char *News_File;
|
|
|
|
|
char *Default_MFB_Cap;
|
|
|
|
|
char *Help_Path;
|
|
|
|
|
char *Lib_Path;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
env_overr(char **v, char *e)
|
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
if (v && e && (p = getenv(e)))
|
2009-06-11 16:12:07 +02:00
|
|
|
*v = p;
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
mkvar(char **p, char *path_prefix, char *var_dir, char *env_var)
|
|
|
|
|
{
|
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
|
|
/* Override by environment variables */
|
|
|
|
|
buffer = getenv(env_var);
|
2001-04-16 11:58:25 +02:00
|
|
|
|
|
|
|
|
#ifdef HAVE_ASPRINTF
|
2000-04-27 22:03:57 +02:00
|
|
|
if (buffer)
|
|
|
|
|
asprintf(p, "%s", buffer);
|
|
|
|
|
else
|
|
|
|
|
asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir);
|
2004-01-10 22:39:36 +01:00
|
|
|
#else /* ~ HAVE_ASPRINTF */
|
2001-04-16 11:58:25 +02:00
|
|
|
if (buffer){
|
2009-06-11 16:12:07 +02:00
|
|
|
*p = (char *) tmalloc(strlen(buffer)+1);
|
|
|
|
|
sprintf(*p,"%s",buffer);
|
|
|
|
|
/* asprintf(p, "%s", buffer); */
|
2001-04-16 11:58:25 +02:00
|
|
|
}
|
|
|
|
|
else{
|
2009-06-11 16:12:07 +02:00
|
|
|
*p = (char *) tmalloc(strlen(path_prefix) +
|
|
|
|
|
strlen(DIR_PATHSEP) + strlen(var_dir) + 1);
|
|
|
|
|
sprintf(*p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir);
|
|
|
|
|
/* asprintf(p, "%s%s%s", path_prefix, DIR_PATHSEP, var_dir); */
|
2001-04-16 11:58:25 +02:00
|
|
|
}
|
|
|
|
|
#endif /* HAVE_ASPRINTF */
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
ivars(void)
|
|
|
|
|
{
|
2001-11-22 21:43:36 +01:00
|
|
|
char *temp=NULL;
|
2010-09-08 19:14:44 +02:00
|
|
|
/* $dprefix has been set to /usr/local or C:/Spice (Windows) in configure.ac,
|
|
|
|
|
NGSPICEBINDIR has been set to $dprefix/bin in configure.ac,
|
2009-06-11 16:12:07 +02:00
|
|
|
Spice_Exec_Dir has been set to NGSPICEBINDIR in conf.c,
|
|
|
|
|
may be overridden here by environmental variable SPICE_EXEC_DIR */
|
2000-04-27 22:03:57 +02:00
|
|
|
env_overr(&Spice_Exec_Dir, "SPICE_EXEC_DIR");
|
|
|
|
|
env_overr(&Spice_Lib_Dir, "SPICE_LIB_DIR");
|
|
|
|
|
|
2009-06-11 16:12:07 +02:00
|
|
|
/* for printing a news file */
|
2000-04-27 22:03:57 +02:00
|
|
|
mkvar(&News_File, Spice_Lib_Dir, "news", "SPICE_NEWS");
|
2009-06-11 16:12:07 +02:00
|
|
|
/* not used in ngspice */
|
2000-04-27 22:03:57 +02:00
|
|
|
mkvar(&Default_MFB_Cap, Spice_Lib_Dir, "mfbcap", "SPICE_MFBCAP");
|
2009-06-11 16:12:07 +02:00
|
|
|
/* help directory, not used in Windows mode */
|
2000-04-27 22:03:57 +02:00
|
|
|
mkvar(&Help_Path, Spice_Lib_Dir, "helpdir", "SPICE_HELP_DIR");
|
2009-06-11 16:12:07 +02:00
|
|
|
/* where spinit is found */
|
2000-04-27 22:03:57 +02:00
|
|
|
mkvar(&Lib_Path, Spice_Lib_Dir, "scripts", "SPICE_SCRIPTS");
|
2009-06-11 16:12:07 +02:00
|
|
|
/* used to call ngspice with aspice command, not used in Windows mode */
|
2000-04-27 22:03:57 +02:00
|
|
|
mkvar(&Spice_Path, Spice_Exec_Dir, "ngspice", "SPICE_PATH");
|
|
|
|
|
|
2009-06-11 16:12:07 +02:00
|
|
|
env_overr(&Spice_Host, "SPICE_HOST"); /* aspice */
|
2000-04-27 22:03:57 +02:00
|
|
|
env_overr(&Bug_Addr, "SPICE_BUGADDR");
|
|
|
|
|
env_overr(&Def_Editor, "SPICE_EDITOR");
|
2001-02-09 14:27:21 +01:00
|
|
|
|
2009-06-11 16:12:07 +02:00
|
|
|
/* Set raw file mode, 0 by default (binary) set in conf.c,
|
|
|
|
|
may be overridden by environmental
|
|
|
|
|
variable, not sure if acknowledged everywhere in ngspice */
|
|
|
|
|
env_overr(&temp, "SPICE_ASCIIRAWFILE");
|
2001-11-22 21:43:36 +01:00
|
|
|
if(temp)
|
|
|
|
|
AsciiRawFile = atoi(temp);
|
2001-02-09 14:27:21 +01:00
|
|
|
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
cleanvars(void)
|
|
|
|
|
{
|
2003-07-23 21:36:39 +02:00
|
|
|
tfree(News_File);
|
|
|
|
|
tfree(Default_MFB_Cap);
|
|
|
|
|
tfree(Help_Path);
|
|
|
|
|
tfree(Lib_Path);
|
|
|
|
|
tfree(Spice_Path);
|
2000-04-27 22:03:57 +02:00
|
|
|
}
|