enable setting an output path
This commit is contained in:
parent
3056f1d81e
commit
da1b23b3c0
|
|
@ -1080,7 +1080,7 @@ inp_read(FILE *fp, int call_depth, char *dir_name, bool comfile, bool intfile)
|
|||
}
|
||||
|
||||
|
||||
static bool
|
||||
bool
|
||||
is_absolute_pathname(const char *p)
|
||||
{
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
return;
|
||||
}
|
||||
|
||||
/* add user defined path (nnmae has to be freed after usage) */
|
||||
char *nname = set_output_path(name);
|
||||
|
||||
if (raw_prec != -1)
|
||||
prec = raw_prec;
|
||||
else
|
||||
|
|
@ -67,29 +70,33 @@ raw_write(char *name, struct plot *pl, bool app, bool binary)
|
|||
|
||||
/* - Binary file binary write - hvogt 15.03.2000 ---------------------*/
|
||||
if (binary) {
|
||||
if ((fp = fopen(name, app ? "ab" : "wb")) == NULL) {
|
||||
perror(name);
|
||||
if ((fp = fopen(nname, app ? "ab" : "wb")) == NULL) {
|
||||
perror(nname);
|
||||
tfree(nname);
|
||||
return;
|
||||
}
|
||||
fprintf(cp_out, "binary raw file \"%s\"\n", name);
|
||||
fprintf(cp_out, "binary raw file \"%s\"\n", nname);
|
||||
} else {
|
||||
if ((fp = fopen(name, app ? "a" : "w")) == NULL) {
|
||||
perror(name);
|
||||
if ((fp = fopen(nname, app ? "a" : "w")) == NULL) {
|
||||
perror(nname);
|
||||
tfree(nname);
|
||||
return;
|
||||
}
|
||||
fprintf(cp_out, "ASCII raw file \"%s\"\n", name);
|
||||
fprintf(cp_out, "ASCII raw file \"%s\"\n", nname);
|
||||
}
|
||||
/* --------------------------------------------------------------------*/
|
||||
|
||||
#else
|
||||
|
||||
if (!(fp = fopen(name, app ? "a" : "w"))) {
|
||||
perror(name);
|
||||
if (!(fp = fopen(nname, app ? "a" : "w"))) {
|
||||
perror(nname);
|
||||
tfree(nname);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
tfree(nname);
|
||||
numdims = nvars = length = 0;
|
||||
for (v = pl->pl_dvecs; v; v = v->v_next) {
|
||||
if (iscomplex(v))
|
||||
|
|
@ -793,3 +800,36 @@ spar_write(char *name, struct plot *pl, double Rbaseval)
|
|||
|
||||
(void) fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
/* Add a user selectable path to the filename for output. Directory given must already exist.
|
||||
* absolute mingw path + filename: transform to Windows path, copy and return
|
||||
* absolute path + filename: copy and return
|
||||
* variable outputpath contains an output path: add filename to path, copy and return
|
||||
* environment variable NGSPICE_OUTPUT_DIR has output path: add filename to path, copy and return
|
||||
* neither outputpath nor NGSPICE_OUTPUT_DIR is set: copy and return filename */
|
||||
char *
|
||||
set_output_path(char *filename)
|
||||
{
|
||||
char varpath[BSIZE_SP];
|
||||
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
/* If variable 'mingwpath' is set: convert mingw /d/... to d:/... */
|
||||
if (cp_getvar("mingwpath", CP_BOOL, NULL) && filename[0] == DIR_TERM_LINUX && isalpha_c(filename[1]) && filename[2] == DIR_TERM_LINUX) {
|
||||
char buf[BSIZE_SP];
|
||||
strcpy(buf, filename);
|
||||
buf[0] = buf[1];
|
||||
buf[1] = ':';
|
||||
return set_output_path(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is_absolute_pathname(filename))
|
||||
return copy(filename);
|
||||
else if (cp_getvar("outputpath", CP_STRING, &varpath))
|
||||
return tprintf("%s/%s", varpath, filename);
|
||||
else if (Outp_Path)
|
||||
return tprintf("%s/%s", Outp_Path, filename);
|
||||
else
|
||||
return copy(filename);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,6 +226,10 @@ void eval_seed_opt(struct line *deck);
|
|||
extern char **circarray;
|
||||
extern void rem_tlist(struct pt_temper *p);
|
||||
|
||||
/* inpcom.c */
|
||||
|
||||
extern bool is_absolute_pathname(const char *p);
|
||||
|
||||
/* nutinp.c */
|
||||
|
||||
void inp_nutsource(FILE *fp, bool comfile, char *filename);
|
||||
|
|
@ -286,6 +290,7 @@ extern int raw_prec;
|
|||
extern void raw_write(char *name, struct plot *pl, bool app, bool binary);
|
||||
extern void spar_write(char *name, struct plot *pl, double val);
|
||||
extern struct plot *raw_read(char *name);
|
||||
extern char *set_output_path(char *filename);
|
||||
|
||||
/* meas.c */
|
||||
extern bool do_measure(char *what, bool chk_only);
|
||||
|
|
|
|||
|
|
@ -265,6 +265,7 @@ extern char *Spice_Path;
|
|||
extern char *Help_Path;
|
||||
extern char *Lib_Path;
|
||||
extern char *Inp_Path;
|
||||
extern char *Outp_Path;
|
||||
extern char *Infile_Path;
|
||||
|
||||
#ifdef TCL_MODULE
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ char *News_File;
|
|||
char *Help_Path;
|
||||
char *Lib_Path;
|
||||
char *Inp_Path;
|
||||
char *Outp_Path;
|
||||
|
||||
#if defined (SHARED_MODULE) && defined (HAS_RELPATH)
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
|
|
@ -135,6 +136,8 @@ ivars(char *argv0)
|
|||
env_overr(&Inp_Path, "NGSPICE_INPUT_DIR");
|
||||
Inp_Path = copy(Inp_Path); /* allow tfree */
|
||||
#endif
|
||||
env_overr(&Outp_Path, "NGSPICE_OUTPUT_DIR");
|
||||
Outp_Path = copy(Outp_Path); /* allow tfree */
|
||||
env_overr(&Spice_Host, "SPICE_HOST"); /* aspice */
|
||||
env_overr(&Bug_Addr, "SPICE_BUGADDR");
|
||||
env_overr(&Def_Editor, "SPICE_EDITOR");
|
||||
|
|
@ -156,4 +159,5 @@ destroy_ivars(void)
|
|||
tfree(Lib_Path);
|
||||
tfree(Spice_Path);
|
||||
tfree(Inp_Path);
|
||||
tfree(Outp_Path);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue