env. var NGSPICE_INPUT to hold additional path for input files

This commit is contained in:
h_vogt 2011-06-25 16:03:05 +00:00
parent d4667d17c5
commit 661d287029
7 changed files with 61 additions and 15 deletions

View File

@ -1,6 +1,11 @@
2011-06-25 Holger Vogt
* main.c, defines.h: improved shutdown message for Windows GUI
* cpitf.c, ngspice.h, ivars.c, ivars.h, analog/file_source/cfunc.mod:
Add reading an environmental variable NGSPICE_INPUT to hold a path
where input files are searched for (in addition to existing search paths),
e.g. *.cir in -b and interactive mode, include and library files,
filesource input file.
2011-06-24 Robert Larice
* src/main.c ,
* src/frontend/com_ahelp.c ,

View File

@ -222,7 +222,10 @@ ft_cpinit(void)
Lib_Path has been set to Spice_Lib_Dir adding /scripts in ivars() */
if (Lib_Path && *Lib_Path) {
/* set variable 'sourcepath' */
(void) sprintf(buf, "sourcepath = ( %s %s )", DIR_CWD, Lib_Path);
if (Inp_Path && *Inp_Path)
(void) sprintf(buf, "sourcepath = ( %s %s %s )", DIR_CWD, Lib_Path, Inp_Path);
else
(void) sprintf(buf, "sourcepath = ( %s %s )", DIR_CWD, Lib_Path);
wl = cp_doglob(cp_lexer(buf));
cp_striplist(wl);
com_set(wl);

View File

@ -222,6 +222,7 @@ extern char *Default_MFB_Cap;
extern char *Spice_Path;
extern char *Help_Path;
extern char *Lib_Path;
extern char *Inp_Path;
extern int ARCHme; /* My logical process number */
extern int ARCHsize; /* Total number of processes */

View File

@ -103,6 +103,7 @@ extern void winmessage(char* new_msg); /* display a message box (defined in winm
extern void SetSource( char * Name); /* display the source file name in the source window */
bool oflag = FALSE; /* Output over redefined I/O functions */
FILE *flogp = NULL; /* log file ('-o logfile' command line option) */
int xmain(int argc, char **argv); /* main function prototype */
#endif /* HAS_WINDOWS */
/* Frontend and circuit options */
@ -824,7 +825,7 @@ main(int argc, char **argv)
ARCHsize = 1;
#endif /* PARALLEL_ARCH */
ivars( );
ivars(argv[0]);
cp_in = stdin;
cp_out = stdout;
@ -1179,9 +1180,21 @@ bot:
arg = argv[optind++];
tp = fopen(arg, "r");
if (!tp) {
perror(arg);
err = 1;
break;
char *lbuffer, *p;
lbuffer = getenv("NGSPICE_INPUT");
// fprintf(stdout, "Such-Dir %s\n", lbuffer);
if (lbuffer && *lbuffer) {
p = TMALLOC(char, strlen(lbuffer) + strlen(DIR_PATHSEP) + strlen(arg) + 1);
sprintf(p, "%s%s%s", lbuffer, DIR_PATHSEP, arg);
// fprintf(stdout, "Suchpfad %s\n", p);
tp = fopen(p, "r");
tfree(p);
}
if (!tp) {
perror(arg);
err = 1;
break;
}
}
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
/* Copy the input file name which otherwise will be lost due to the

View File

@ -4,6 +4,7 @@ Copyright 1991 Regents of the University of California. All rights reserved.
#include "ngspice.h"
#include "ivars.h"
#include "util.h"
#ifdef HAVE_ASPRINTF
#ifdef HAVE_LIBIBERTY_H /* asprintf */
@ -20,6 +21,7 @@ char *News_File;
char *Default_MFB_Cap;
char *Help_Path;
char *Lib_Path;
char *Inp_Path;
static void
@ -58,9 +60,9 @@ mkvar(char **p, char *path_prefix, char *var_dir, char *env_var)
}
void
ivars(void)
ivars(char *argv0)
{
char *temp=NULL;
char *temp=NULL, *ngpath=NULL;
/* $dprefix has been set to /usr/local or C:/Spice (Windows) in configure.ac,
NGSPICEBINDIR has been set to $dprefix/bin in configure.ac,
Spice_Exec_Dir has been set to NGSPICEBINDIR in conf.c,
@ -78,6 +80,13 @@ ivars(void)
mkvar(&Lib_Path, Spice_Lib_Dir, "scripts", "SPICE_SCRIPTS");
/* used to call ngspice with aspice command, not used in Windows mode */
mkvar(&Spice_Path, Spice_Exec_Dir, "ngspice", "SPICE_PATH");
/* may be used to store input files (*.lib, *.include, ...) */
/* get directory where ngspice resides */
ngpath = dirname(argv0);
/* set path either to <ngspice-directory>/input or, if set, to
environment variable NGSPICE_INPUT */
mkvar(&Inp_Path, ngpath, "input", "NGSPICE_INPUT");
if (ngpath) tfree(ngpath);
env_overr(&Spice_Host, "SPICE_HOST"); /* aspice */
env_overr(&Bug_Addr, "SPICE_BUGADDR");
@ -100,4 +109,5 @@ cleanvars(void)
tfree(Help_Path);
tfree(Lib_Path);
tfree(Spice_Path);
tfree(Inp_Path);
}

View File

@ -7,7 +7,7 @@
#define IVARS_H_INCLUDED
void ivars(void);
void ivars(char*);
void cleanvars(void);
#endif

View File

@ -46,6 +46,7 @@ NON-STANDARD FEATURES
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/*=== CONSTANTS ========================*/
@ -54,8 +55,11 @@ NON-STANDARD FEATURES
/*=== MACROS ===========================*/
#if defined(__MINGW32__) || defined(_MSC_VER)
#define DIR_PATHSEP "\\"
#else
#define DIR_PATHSEP "/"
#endif
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
@ -143,10 +147,20 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
state->pos = 0;
state->atend = 0;
if (!state->fp) {
char msg[512];
snprintf(msg, sizeof(msg), "cannot open file %s", PARAM(file));
cm_message_send(msg);
state->atend = 1;
char *lbuffer, *p;
lbuffer = getenv("NGSPICE_INPUT");
if (lbuffer && *lbuffer) {
p = (char*) malloc(strlen(lbuffer) + strlen(DIR_PATHSEP) + strlen(PARAM(file)) + 1);
sprintf(p, "%s%s%s", lbuffer, DIR_PATHSEP, PARAM(file));
state->fp = fopen(p, "r");
free(p);
}
if (!state->fp) {
char msg[512];
snprintf(msg, sizeof(msg), "cannot open file %s", PARAM(file));
cm_message_send(msg);
state->atend = 1;
}
}
}
amplscalesize = PARAM_NULL(amplscale) ? 0 : PARAM_SIZE(amplscale);