replace gpl getopt by BSD getopt

This commit is contained in:
h_vogt 2009-04-12 21:08:18 +00:00
parent c9b58436f6
commit 6f4cdcac47
7 changed files with 338 additions and 307 deletions

View File

@ -1,11 +1,23 @@
2009-04-12 Holger Vogt 2009-04-12 Holger Vogt
* spicenum.c, xpressn.c: dico and inst_dico not removed in nupa_done * spicenum.c, xpressn.c: dico and inst_dico no longer removed in nupa_done
because they are needed in .measure because they are needed in .measure
* lexical.c: size of arrays doubled in cp_lexer() to avoid "line too long" * lexical.c: size of arrays doubled in cp_lexer() to avoid "line too long"
message message
* runcoms.c: enter do_measure() only if ft_curckt->ci_last_an has a value * runcoms.c: enter do_measure() only if ft_curckt->ci_last_an has a value
(bug no. 2751855) (bug no. 2751855)
* winmain.c: winmessage() only if message not into log file * winmain.c: winmessage() only if message not into log file
* windisp.c: WIN_Text() now uses True Type Fonts and may display text
vertically
* misc/getopt_long_bsd.c getopt_bsd.h: add a BSD version of getopt_long()
getopt.c, getopt1.c, getopt.h removed
* misc/makefile.am: add (remove) files
* configure.in: check for getopt.h and getopt_long(), if not found, use
internal functions in getopt_long_bsd.c
Replace package name ng-spice-rework with ngspice
Change version number to 19
* main.c: chosse proper getopt_long(), winmessage()
* visualc/vngspice.vcproj: files added (removed)
* visualc/include/config.h: new version 19
2009-04-10 Holger Vogt 2009-04-10 Holger Vogt
* spicenum.c: memory leak removed * spicenum.c: memory leak removed

View File

@ -12,7 +12,7 @@ dnl Initialisation
dnl --------------- dnl ---------------
dnl Initialisation of configure dnl Initialisation of configure
AC_INIT(ng-spice-rework,18,ngspice-bugs@lists.sourceforge.net) AC_INIT(ngspice,19,ngspice-bugs@lists.sourceforge.net)
dnl Unique file in the source directory dnl Unique file in the source directory
AC_CONFIG_SRCDIR([src/ngspice.c]) AC_CONFIG_SRCDIR([src/ngspice.c])
@ -643,8 +643,12 @@ fi
dnl Check for the dirname function: dnl Check for the dirname function:
AC_CHECK_FUNCS(dirname,,AC_CHECK_LIB(gen,dirname,AC_DEFINE(HAVE_DIRNAME,1,[Have dirname in libgen]) LIBS="$LIBS -lgen")) AC_CHECK_FUNCS(dirname,,AC_CHECK_LIB(gen,dirname,AC_DEFINE(HAVE_DIRNAME,1,[Have dirname in libgen]) LIBS="$LIBS -lgen"))
# AC_CHECK_FUNC(getopt_long, getopt_long=true) AC_CHECK_HEADERS(getopt.h)
AC_CHECK_FUNC(getopt_long, getopt_long=true)
# AM_CONDITIONAL(HAVE_GETOPT_LONG, test "$getopt_long" = "true") # AM_CONDITIONAL(HAVE_GETOPT_LONG, test "$getopt_long" = "true")
if test "$getopt_long" = "true"; then
AC_DEFINE(HAVE_GETOPT_LONG,1,[Have fcn getopt_long()])
fi
# Expand the prefix variable (this is really annoying!) # Expand the prefix variable (this is really annoying!)
if eval "test x$prefix = xNONE"; then if eval "test x$prefix = xNONE"; then

View File

@ -675,7 +675,7 @@ int WIN_Arc(int x0, int y0, int radius, double theta1, double theta2)
return 0; return 0;
} }
/*
int WIN_Text_old( char * text, int x, int y, int degrees) int WIN_Text_old( char * text, int x, int y, int degrees)
{ {
tpWindowData wd; tpWindowData wd;
@ -688,7 +688,7 @@ int WIN_Text_old( char * text, int x, int y, int degrees)
return (0); return (0);
} }
*/
int WIN_Text( char * text, int x, int y, int CentiDegrees) int WIN_Text( char * text, int x, int y, int CentiDegrees)
{ {

View File

@ -43,7 +43,7 @@ extern void srandom (unsigned int seed);
/* SJB added editline support 2005-05-05 */ /* SJB added editline support 2005-05-05 */
#include <editline/readline.h> #include <editline/readline.h>
extern VFunction *rl_event_hook; /* missing from editline/readline.h */ extern VFunction *rl_event_hook; /* missing from editline/readline.h */
extern int rl_catch_signals; /* missing from editline/readline.h */ extern int rl_catch_signals; /* missing from editline/readline.h */
#endif /* HAVE_BSDEDITLINE */ #endif /* HAVE_BSDEDITLINE */
#ifndef HAVE_GETRUSAGE #ifndef HAVE_GETRUSAGE
@ -58,7 +58,11 @@ extern int rl_catch_signals; /* missing from editline/readline.h */
#include "spicelib/devices/dev.h" #include "spicelib/devices/dev.h"
#include "spicelib/analysis/analysis.h" #include "spicelib/analysis/analysis.h"
#include "misc/ivars.h" #include "misc/ivars.h"
#include "misc/getopt.h" #if defined(HAVE_GETOPT_LONG) && defined(HAVE_GETOPT_H)
#include <getopt.h>
#else
#include "misc/getopt_bsd.h"
#endif
#include "frontend/resource.h" #include "frontend/resource.h"
#include "frontend/variable.h" #include "frontend/variable.h"
#include "frontend/display.h" /* added by SDB to pick up Input() fcn */ #include "frontend/display.h" /* added by SDB to pick up Input() fcn */
@ -95,6 +99,7 @@ bool ft_setflag = FALSE; /* TRUE = Don't abort simulation after an interrupt.
char *ft_rawfile = "rawspice.raw"; char *ft_rawfile = "rawspice.raw";
#ifdef HAS_WINDOWS #ifdef HAS_WINDOWS
extern void winmessage(char* new_msg);
bool oflag = FALSE; /* Output over redefined I/O functions */ bool oflag = FALSE; /* Output over redefined I/O functions */
FILE *flogp; /* hvogt 15.12.2001 */ FILE *flogp; /* hvogt 15.12.2001 */
#endif /* HAS_WINDOWS */ #endif /* HAS_WINDOWS */
@ -184,7 +189,7 @@ static void append_to_stream(FILE *dest, FILE *source);
#ifndef HAVE_GETRUSAGE #ifndef HAVE_GETRUSAGE
#ifdef HAVE_FTIME #ifdef HAVE_FTIME
extern struct timeb timebegin; /* for use w/ ftime */ extern struct timeb timebegin; /* for use w/ ftime */
#endif #endif
#endif #endif
@ -201,21 +206,21 @@ extern int OUTwData(), OUTwEnd(), OUTendPlot(), OUTbeginDomain();
extern int OUTendDomain(), OUTstopnow(), OUTerror(), OUTattributes(); extern int OUTendDomain(), OUTstopnow(), OUTerror(), OUTattributes();
IFfrontEnd nutmeginfo = { IFfrontEnd nutmeginfo = {
IFnewUid, IFnewUid,
IFdelUid, IFdelUid,
OUTstopnow, OUTstopnow,
seconds, seconds,
OUTerror, OUTerror,
OUTpBeginPlot, OUTpBeginPlot,
OUTpData, OUTpData,
OUTwBeginPlot, OUTwBeginPlot,
OUTwReference, OUTwReference,
OUTwData, OUTwData,
OUTwEnd, OUTwEnd,
OUTendPlot, OUTendPlot,
OUTbeginDomain, OUTbeginDomain,
OUTendDomain, OUTendDomain,
OUTattributes OUTattributes
}; };
#else /* SIMULATOR */ #else /* SIMULATOR */
@ -335,6 +340,13 @@ struct dvec *EVTfindvec(char *node){
#endif /* SIMULATOR */ #endif /* SIMULATOR */
#ifndef HAS_WINDOWS
/* dummy of MS Windows message function */
void winmessage(char* new_msg) {
return;
}
#endif
char *hlp_filelist[] = { "ngspice", 0 }; char *hlp_filelist[] = { "ngspice", 0 };
@ -358,13 +370,13 @@ SIMinit(IFfrontEnd *frontEnd, IFsimulator **simulator)
SIMinfo.numAnalyses = spice_num_analysis(); SIMinfo.numAnalyses = spice_num_analysis();
SIMinfo.analyses = (IFanalysis **)spice_analysis_ptr(); /* va: we recast, because we use SIMinfo.analyses = (IFanalysis **)spice_analysis_ptr(); /* va: we recast, because we use
* only the public part * only the public part
*/ */
#ifdef CIDER #ifdef CIDER
/* Evaluates limits of machine accuracy for CIDER */ /* Evaluates limits of machine accuracy for CIDER */
evalAccLimits(); evalAccLimits();
#endif /* CIDER */ #endif /* CIDER */
#endif /* SIMULATOR */ #endif /* SIMULATOR */
SPfrontEnd = frontEnd; SPfrontEnd = frontEnd;
@ -384,12 +396,18 @@ sp_shutdown(int exitval)
{ {
cleanvars(); cleanvars();
#ifdef PARALLEL_ARCH #ifdef PARALLEL_ARCH
if (exitval == EXIT_BAD) { {
Error("Fatal error in SPICE", -1); Error("Fatal error in SPICE", -1);
} else { } else {
PEND_(); PEND_();
} }
#endif /* PARALLEL_ARCH */ #endif /* PARALLEL_ARCH */
#ifdef HAS_WINDOWS
if (exitval == EXIT_BAD)
winmessage("Fatal error in SPICE");
else
winmessage("Information during setup, see text window!");
#endif
exit (exitval); exit (exitval);
} }
@ -404,40 +422,40 @@ prompt(void)
char *p = pbuf, *s; char *p = pbuf, *s;
if (cp_interactive == FALSE) if (cp_interactive == FALSE)
return NULL; /* NULL means no prompt */ return NULL; /* NULL means no prompt */
s = get_alt_prompt(); s = get_alt_prompt();
if(s==NULL) if(s==NULL)
s = cp_promptstring; s = cp_promptstring;
if(s==NULL) if(s==NULL)
s = "->"; s = "->";
while (*s) { while (*s) {
switch (strip(*s)) { switch (strip(*s)) {
case '!': case '!':
#ifdef HAVE_BSDEDITLINE #ifdef HAVE_BSDEDITLINE
{ {
/* SJB In the present version of editline (v2.9) /* SJB In the present version of editline (v2.9)
it seems that where_history() is broken. it seems that where_history() is broken.
This is a hack that works round this problem. This is a hack that works round this problem.
WARNING: It may fail to work in the future WARNING: It may fail to work in the future
as it relies on undocumented structure */ as it relies on undocumented structure */
int where = 0; int where = 0;
HIST_ENTRY * he = current_history(); HIST_ENTRY * he = current_history();
if(he!=NULL) where = *(int*)(he->data); if(he!=NULL) where = *(int*)(he->data);
p += sprintf(p, "%d", where + 1); p += sprintf(p, "%d", where + 1);
} }
#else #else
p += sprintf(p, "%d", where_history() + 1); p += sprintf(p, "%d", where_history() + 1);
#endif /* HAVE_BSDEDITLINE*/ #endif /* HAVE_BSDEDITLINE*/
break; break;
case '\\': case '\\':
if (*(s + 1)) if (*(s + 1))
p += sprintf(p, "%c", strip(*++s)); p += sprintf(p, "%c", strip(*++s));
default: default:
*p = strip(*s); ++p; *p = strip(*s); ++p;
break; break;
} }
s++; s++;
} }
*p = 0; *p = 0;
@ -540,22 +558,22 @@ static void
show_help(void) show_help(void)
{ {
printf("Usage: %s [OPTION]... [FILE]...\n" printf("Usage: %s [OPTION]... [FILE]...\n"
"Simulate the electical circuits in FILE.\n" "Simulate the electical circuits in FILE.\n"
"\n" "\n"
" -a --autorun run the loaded netlist\n" " -a --autorun run the loaded netlist\n"
" -b, --batch process FILE in batch mode\n" " -b, --batch process FILE in batch mode\n"
" -c, --circuitfile=FILE set the circuitfile\n" " -c, --circuitfile=FILE set the circuitfile\n"
" -i, --interactive run in interactive mode\n" " -i, --interactive run in interactive mode\n"
" -n, --no-spiceinit don't load the local or user's config file\n" " -n, --no-spiceinit don't load the local or user's config file\n"
" -o, --output=FILE set the outputfile\n" " -o, --output=FILE set the outputfile\n"
" -q, --completion activate command completion\n" " -q, --completion activate command completion\n"
" -r, --rawfile=FILE set the rawfile output\n" " -r, --rawfile=FILE set the rawfile output\n"
" -s, --server run spice as a server process\n" " -s, --server run spice as a server process\n"
" -t, --term=TERM set the terminal type\n" " -t, --term=TERM set the terminal type\n"
" -h, --help display this help and exit\n" " -h, --help display this help and exit\n"
" -v, --version output version information and exit\n" " -v, --version output version information and exit\n"
"\n" "\n"
"Report bugs to %s.\n", cp_program, Bug_Addr); "Report bugs to %s.\n", cp_program, Bug_Addr);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -563,12 +581,12 @@ static void
show_version(void) show_version(void)
{ {
printf("%s compiled from %s revision %s\n" printf("%s compiled from %s revision %s\n"
"Written originally by Berkeley University\n" "Written originally by Berkeley University\n"
"Currently maintained by the NGSpice Project\n\n" "Currently maintained by the NGSpice Project\n\n"
"Copyright (C) 1985-1996," "Copyright (C) 1985-1996,"
" The Regents of the University of California\n" " The Regents of the University of California\n"
"Copyright (C) 1999-2008," "Copyright (C) 1999-2008,"
" The NGSpice Project\n", cp_program, PACKAGE, VERSION); " The NGSpice Project\n", cp_program, PACKAGE, VERSION);
} }
#ifdef SIMULATOR #ifdef SIMULATOR
@ -580,7 +598,7 @@ append_to_stream(FILE *dest, FILE *source)
int i; int i;
while ((i = fread(buf, 1, BSIZE_SP, source)) > 0) while ((i = fread(buf, 1, BSIZE_SP, source)) > 0)
fwrite(buf, i, 1, dest); fwrite(buf, i, 1, dest);
} }
#endif /* SIMULATOR */ #endif /* SIMULATOR */
@ -593,7 +611,7 @@ append_to_stream(FILE *dest, FILE *source)
static bool static bool
read_initialisation_file(char * dir, char * name) read_initialisation_file(char * dir, char * name)
{ {
#ifndef HAVE_ASPRINTF #ifndef HAVE_UNISTD_H
FILE * fp = NULL; FILE * fp = NULL;
#endif /* not HAVE_ASPRINTF */ #endif /* not HAVE_ASPRINTF */
char * path; char * path;
@ -601,42 +619,42 @@ read_initialisation_file(char * dir, char * name)
/* check name */ /* check name */
if(name==NULL || name[0]=='\0') if(name==NULL || name[0]=='\0')
return FALSE; /* Fail; name needed */ return FALSE; /* Fail; name needed */
/* contruct the full path */ /* contruct the full path */
if(dir == NULL || dir[0]=='\0') { if(dir == NULL || dir[0]=='\0') {
path = name; path = name;
} else { } else {
#ifdef HAVE_ASPRINTF #ifdef HAVE_ASPRINTF
asprintf(&path, "%s" DIR_PATHSEP "%s", dir,name); asprintf(&path, "%s" DIR_PATHSEP "%s", dir,name);
if(path==NULL) return FALSE; /* memory allocation error */ if(path==NULL) return FALSE; /* memory allocation error */
#else /* ~ HAVE_ASPRINTF */ #else /* ~ HAVE_ASPRINTF */
path=(char*)tmalloc(2 + strlen(dir)+strlen(name)); path=(char*)tmalloc(2 + strlen(dir)+strlen(name));
if(path==NULL) return FALSE; /* memory allocation error */ if(path==NULL) return FALSE; /* memory allocation error */
sprintf(path,"%s" DIR_PATHSEP "%s",dir,name); sprintf(path,"%s" DIR_PATHSEP "%s",dir,name);
#endif /* HAVE_ASPRINTF */ #endif /* HAVE_ASPRINTF */
} }
/* now access the file */ /* now access the file */
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
if (access(path, R_OK) == 0) { if (access(path, R_OK) == 0) {
#else #else
if ((fp = fopen(path, "r")) != NULL) { if ((fp = fopen(path, "r")) != NULL) {
(void) fclose(fp); (void) fclose(fp);
#endif /* HAVE_UNISTD_H */ #endif /* HAVE_UNISTD_H */
inp_source(path); inp_source(path);
#ifdef TRACE #ifdef TRACE
printf("Init file: '%s'\n",path); printf("Init file: '%s'\n",path);
#endif /* TRACE */ #endif /* TRACE */
result = TRUE; /* loaded okay */ result = TRUE; /* loaded okay */
} }
/* if dir was not NULL and not empty then we allocated memory above */ /* if dir was not NULL and not empty then we allocated memory above */
if(dir!=NULL && dir[0] !='\0') if(dir!=NULL && dir[0] !='\0')
#ifdef HAVE_ASPRINTF #ifdef HAVE_ASPRINTF
free(path); free(path);
#else #else
tfree(path); tfree(path);
#endif /* HAVE_ASPRINTF */ #endif /* HAVE_ASPRINTF */
return result; return result;
@ -653,10 +671,10 @@ main(int argc, char **argv)
#endif /* HAS_WINDOWS */ #endif /* HAS_WINDOWS */
{ {
int c; int c;
int err; int err;
bool gotone = FALSE; bool gotone = FALSE;
char* copystring;/*DG*/ char* copystring;/*DG*/
char addctrlsect = TRUE; /* PN: for autorun */ char addctrlsect = TRUE; /* PN: for autorun */
#ifdef SIMULATOR #ifdef SIMULATOR
@ -675,7 +693,7 @@ main(int argc, char **argv)
bool rflag = FALSE; bool rflag = FALSE;
FILE *fp; FILE *fp;
FILE *circuit_file; FILE *circuit_file;
bool orflag = FALSE; bool orflag = FALSE;
#ifdef TRACE #ifdef TRACE
/* this is used to detect memory leaks during debugging */ /* this is used to detect memory leaks during debugging */
@ -710,7 +728,7 @@ main(int argc, char **argv)
SETDBG_(&debug_flag); SETDBG_(&debug_flag);
fprintf( stderr, "On-line: process %d of %d total.\n", ARCHme, ARCHsize ); fprintf( stderr, "On-line: process %d of %d total.\n", ARCHme, ARCHsize );
evlog(EVKEY_ENABLE, EVKEY_EVENT, "On-line", EVKEY_DUMP, EVKEY_DISABLE, evlog(EVKEY_ENABLE, EVKEY_EVENT, "On-line", EVKEY_DUMP, EVKEY_DISABLE,
EVKEY_LAST_ARG); EVKEY_LAST_ARG);
#else #else
ARCHme = 0; ARCHme = 0;
ARCHsize = 1; ARCHsize = 1;
@ -744,113 +762,113 @@ main(int argc, char **argv)
/* --- Process command line options --- */ /* --- Process command line options --- */
while (1) { while (1) {
int option_index = 0; int option_index = 0;
static struct option long_options[] = { static struct option long_options[] = {
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"version", 0, 0, 'v'}, {"version", 0, 0, 'v'},
{"batch", 0, 0, 'b'}, {"batch", 0, 0, 'b'},
{"autorun", 0, 0, 'a'}, {"autorun", 0, 0, 'a'},
{"circuitfile", 0, 0, 'c'}, {"circuitfile", 1, 0, 'c'},
{"interactive", 0, 0, 'i'}, {"interactive", 0, 0, 'i'},
{"no-spiceinit", 0, 0, 'n'}, {"no-spiceinit", 0, 0, 'n'},
{"output", 0, 0, 'o'}, {"output", 1, 0, 'o'},
{"completion", 0, 0, 'q'}, {"completion", 0, 0, 'q'},
{"rawfile", 1, 0, 'r'}, {"rawfile", 1, 0, 'r'},
{"server", 0, 0, 's'}, {"server", 0, 0, 's'},
{"terminal", 1, 0, 't'}, {"terminal", 1, 0, 't'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
c = getopt_long (argc, argv, "hvbac:ihno:qr:st:", c = getopt_long (argc, argv, "hvbac:ihno:qr:st:",
long_options, &option_index); long_options, &option_index);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'h': /* Help */ case 'h': /* Help */
show_help(); show_help();
sp_shutdown (EXIT_NORMAL); sp_shutdown (EXIT_NORMAL);
break; break;
case 'v': /* Version info */ case 'v': /* Version info */
show_version(); show_version();
sp_shutdown (EXIT_NORMAL); sp_shutdown (EXIT_NORMAL);
break; break;
case 'b': /* Batch mode */ case 'b': /* Batch mode */
ft_batchmode = TRUE; ft_batchmode = TRUE;
addctrlsect = FALSE; addctrlsect = FALSE;
cp_vset("addcontrol",VT_BOOL,&addctrlsect); cp_vset("addcontrol",VT_BOOL,&addctrlsect);
break; break;
case 'a': /* Add control section for autorun */ case 'a': /* Add control section for autorun */
if (!ft_batchmode) { if (!ft_batchmode) {
addctrlsect = TRUE; addctrlsect = TRUE;
cp_vset("addcontrol",VT_BOOL, &addctrlsect); cp_vset("addcontrol",VT_BOOL, &addctrlsect);
} }
break; break;
case 'c': /* Circuit file */ case 'c': /* Circuit file */
if (optarg) { if (optarg) {
if (!(circuit_file = fopen(optarg, "r"))) { if (!(circuit_file = fopen(optarg, "r"))) {
perror("circuit file not available"); perror(optarg);
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
} }
istty = FALSE; istty = FALSE;
} }
break; break;
case 'i': /* Interactive mode */ case 'i': /* Interactive mode */
iflag = TRUE; iflag = TRUE;
break; break;
case 'n': /* Don't read initialisation file */ case 'n': /* Don't read initialisation file */
readinit = FALSE; readinit = FALSE;
break; break;
case 'o': /* Output file */ case 'o': /* Output file */
if (optarg) { if (optarg) {
/* turn off buffering for stdout */ /* turn off buffering for stdout */
setbuf(stdout, NULL); setbuf(stdout, NULL);
#ifdef PARALLEL_ARCH #ifdef PARALLEL_ARCH
sprintf (buf, "%s%03d", optarg, ARCHme); sprintf (buf, "%s%03d", optarg, ARCHme);
#else #else
sprintf (buf, "%s", optarg); sprintf (buf, "%s", optarg);
#endif #endif
orflag = TRUE; orflag = TRUE;
} }
break; break;
case 'q': /* Command completion */ case 'q': /* Command completion */
qflag = TRUE; qflag = TRUE;
break; break;
case 'r': /* The raw file */ case 'r': /* The raw file */
if (optarg) { if (optarg) {
cp_vset("rawfile", VT_STRING, optarg); cp_vset("rawfile", VT_STRING, optarg);
} }
rflag = TRUE; rflag = TRUE;
break; break;
case 's': /* Server mode */ case 's': /* Server mode */
ft_servermode = TRUE; ft_servermode = TRUE;
break; break;
case 't': case 't':
if (optarg) { if (optarg) {
cp_vset("term", VT_STRING, optarg); cp_vset("term", VT_STRING, optarg);
} }
break; break;
case '?': case '?':
break; break;
default: default:
printf ("?? getopt returned character code 0%o ??\n", c); printf ("?? getopt returned character code 0%o ??\n", c);
} }
} /* --- End of command line option processing --- */ } /* --- End of command line option processing (While(1)-loop) --- */
if (orflag) { /* -o option has been set */ if (orflag) { /* -o option has been set */
com_version(NULL); com_version(NULL);
if (ft_batchmode && !ft_servermode) fprintf(stdout, "\nBatch mode\n\n"); if (ft_batchmode && !ft_servermode) fprintf(stdout, "\nBatch mode\n\n");
else if (ft_servermode) fprintf(stdout, "\nServer mode\n\n"); else if (ft_servermode) fprintf(stdout, "\nServer mode\n\n");
@ -860,9 +878,9 @@ main(int argc, char **argv)
/* Open the log file */ /* Open the log file */
#ifdef HAS_WINDOWS #ifdef HAS_WINDOWS
/* flogp goes to winmain's putc and writes to file buf */ /* flogp goes to winmain's putc and writes to file buf */
if (!(flogp = fopen(buf, "w"))) { if (!(flogp = fopen(buf, "w"))) {
#else #else
/* Connect stdout to file buf and log stdout */ /* Connect stdout to file buf and log stdout */
if (!(freopen (buf, "w", stdout))) { if (!(freopen (buf, "w", stdout))) {
#endif #endif
perror (buf); perror (buf);
@ -878,8 +896,8 @@ main(int argc, char **argv)
if_getparam = nutif_getparam; if_getparam = nutif_getparam;
if (optind == argc) { if (optind == argc) {
/* No raw file */ /* No raw file */
gdata = FALSE; gdata = FALSE;
} }
#endif #endif
@ -936,42 +954,42 @@ main(int argc, char **argv)
/* load user's initialisation file */ /* load user's initialisation file */
if (readinit) { if (readinit) {
bool good; bool good;
/* Try accessing the initialisation file in the current directory */ /* Try accessing the initialisation file in the current directory */
good = read_initialisation_file("",INITSTR); good = read_initialisation_file("",INITSTR);
/* if that fail try the alternate name */ /* if that fail try the alternate name */
if(good == FALSE) if(good == FALSE)
good = read_initialisation_file("",ALT_INITSTR); good = read_initialisation_file("",ALT_INITSTR);
/* if that failed try in the user's home directory /* if that failed try in the user's home directory
if their HOME environment variable is set */ if their HOME environment variable is set */
if(good == FALSE) { if(good == FALSE) {
char * homedir; char * homedir;
homedir = getenv("HOME"); homedir = getenv("HOME");
if(homedir !=NULL) { if(homedir !=NULL) {
good = read_initialisation_file(homedir,INITSTR); good = read_initialisation_file(homedir,INITSTR);
if(good == FALSE) { if(good == FALSE) {
good = read_initialisation_file(homedir,ALT_INITSTR); good = read_initialisation_file(homedir,ALT_INITSTR);
} }
} }
} }
} }
if (!ft_batchmode) { if (!ft_batchmode) {
com_version(NULL); com_version(NULL);
DevInit( ); DevInit( );
if (News_File && *News_File) { if (News_File && *News_File) {
copystring=cp_tildexpand(News_File);/*DG Memory leak */ copystring=cp_tildexpand(News_File);/*DG Memory leak */
fp = fopen(copystring, "r"); fp = fopen(copystring, "r");
tfree(copystring); tfree(copystring);
if (fp) { if (fp) {
while (fgets(buf, BSIZE_SP, fp)) while (fgets(buf, BSIZE_SP, fp))
fputs(buf, stdout); fputs(buf, stdout);
(void) fclose(fp); (void) fclose(fp);
} }
} }
} }
@ -990,78 +1008,80 @@ bot:
#ifdef SIMULATOR #ifdef SIMULATOR
if (!ft_servermode && !ft_nutmeg) { if (!ft_servermode && !ft_nutmeg) {
/* Concatenate all non-option arguments into a temporary file /* Concatenate all non-option arguments into a temporary file
and load that file into the spice core. and load that file into the spice core.
The original routine took a special path if there was only The original routine took a special path if there was only
one non-option argument. In that case, it didn't create one non-option argument. In that case, it didn't create
the temporary file but used the original file instead. The the temporary file but used the original file instead. The
current algorithm is uniform at the expense of a little current algorithm is uniform at the expense of a little
startup time. */ startup time. */
FILE *tempfile; FILE *tempfile;
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__) #if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
char *tpf; /* temporary file */ char *tpf; /* temporary file */
char *dname = NULL; /* directory of input file*/ char *dname = NULL; /* directory of input file*/
bool has_smk = FALSE; bool has_smk = FALSE;
#endif #endif
tempfile = tmpfile(); tempfile = tmpfile();
/* tmpfile() returns NULL, if in MS Windows as non admin user /* tmpfile() returns NULL, if in MS Windows as non admin user
then we add a tempfile in the local directory */ then we add a tempfile in the local directory */
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__) #if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
if (tempfile == NULL) { if (tempfile == NULL) {
tpf = smktemp("sp"); tpf = smktemp("sp");
tempfile = fopen(tpf, "w+b"); tempfile = fopen(tpf, "w+b");
if (tempfile == NULL) { if (tempfile == NULL) {
fprintf(stderr, "Could not open a temporary file to save and use optional arguments."); fprintf(stderr, "Could not open a temporary file to save and use optional arguments.");
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
} }
has_smk = TRUE; has_smk = TRUE;
} }
#endif #endif
if (optind == argc && !istty) { if (optind == argc && !istty) {
append_to_stream(tempfile, stdin); append_to_stream(tempfile, stdin);
} }
while (optind < argc) {
char *arg;
FILE *tp;
/* Copy all the arguments into the temporary file */ while (optind < argc) {
arg = argv[optind++]; char *arg;
tp = fopen(arg, "r"); FILE *tp;
if (!tp) {
perror(arg); /* Copy all the arguments into the temporary file */
err = 1; arg = argv[optind++];
break; tp = fopen(arg, "r");
} if (!tp) {
perror(arg);
err = 1;
break;
}
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__) #if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
/* Copy the input file name which otherwise will be lost due to the /* Copy the input file name which otherwise will be lost due to the
temporary file */ temporary file */
dname = copy(arg); dname = copy(arg);
#endif #endif
append_to_stream(tempfile, tp); append_to_stream(tempfile, tp);
fclose(tp); fclose(tp);
} }
fseek(tempfile, (long) 0, 0); fseek(tempfile, (long) 0, 0);
if (tempfile && (!err || !ft_batchmode)) { if (tempfile && (!err || !ft_batchmode)) {
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__) #if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
/* Copy the input file name for adding another file search path */ /* Copy the input file name for adding another file search path */
inp_spsource(tempfile, FALSE, dname); inp_spsource(tempfile, FALSE, dname);
tfree(dname); tfree(dname);
#else #else
inp_spsource(tempfile, FALSE, NULL); inp_spsource(tempfile, FALSE, NULL);
#endif #endif
gotone = TRUE; gotone = TRUE;
} }
#if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__) #if defined(HAS_WINDOWS) || defined(_MSC_VER) || defined(__MINGW32__)
if (tempfile && has_smk) { if (tempfile && has_smk) {
if (remove(tpf)) if (remove(tpf))
perror("Could not delete temp file"); perror("Could not delete temp file");
} }
#endif #endif
if (ft_batchmode && err) if (ft_batchmode && err) {
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
}
} /* --- if (!ft_servermode && !ft_nutmeg) --- */ } /* --- if (!ft_servermode && !ft_nutmeg) --- */
if (!gotone && ft_batchmode && !ft_nutmeg) if (!gotone && ft_batchmode && !ft_nutmeg)
@ -1078,7 +1098,7 @@ evl:
if (st == TRUE) { if (st == TRUE) {
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
} }
st = TRUE; st = TRUE;
if (ft_servermode) { if (ft_servermode) {
if (ft_curckt == NULL) { if (ft_curckt == NULL) {
@ -1086,7 +1106,7 @@ evl:
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
} }
if (ft_dorun("")) if (ft_dorun(""))
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
sp_shutdown(EXIT_NORMAL); sp_shutdown(EXIT_NORMAL);
} }
@ -1095,19 +1115,19 @@ evl:
* save too much. */ * save too much. */
cp_interactive = FALSE; cp_interactive = FALSE;
if (rflag) { if (rflag) {
/* saj done already in inp_spsource ft_dotsaves();*/ /* saj done already in inp_spsource ft_dotsaves();*/
error2 = ft_dorun(ft_rawfile); error2 = ft_dorun(ft_rawfile);
if (ft_cktcoms(TRUE) || error2) if (ft_cktcoms(TRUE) || error2)
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
} else if (ft_savedotargs()) { } else if (ft_savedotargs()) {
error2 = ft_dorun(NULL); error2 = ft_dorun(NULL);
if (ft_cktcoms(FALSE) || error2) if (ft_cktcoms(FALSE) || error2)
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
} else { } else {
fprintf(stderr, fprintf(stderr,
"Note: No \".plot\", \".print\", or \".fourier\" lines; " "Note: No \".plot\", \".print\", or \".fourier\" lines; "
"no simulations run\n"); "no simulations run\n");
sp_shutdown(EXIT_BAD); sp_shutdown(EXIT_BAD);
} }
} /* --- if (ft_batchmode) --- */ } /* --- if (ft_batchmode) --- */
else { else {
@ -1118,10 +1138,10 @@ evl:
#else /* ~ SIMULATOR */ #else /* ~ SIMULATOR */
if (ft_nutmeg && gdata) { if (ft_nutmeg && gdata) {
while (optind < argc) { while (optind < argc) {
ft_loadfile(argv[optind++]); ft_loadfile(argv[optind++]);
gotone = TRUE; gotone = TRUE;
} }
if (!gotone) if (!gotone)
ft_loadfile(ft_rawfile); ft_loadfile(ft_rawfile);
} }

View File

@ -5,9 +5,8 @@ noinst_LTLIBRARIES = libmisc.la
libmisc_la_SOURCES = \ libmisc_la_SOURCES = \
getopt1.c \ getopt_long_bsd.c \
getopt.c \ getopt_bsd.h \
getopt.h \
alloc.c \ alloc.c \
alloc.h \ alloc.h \
dup2.c \ dup2.c \

View File

@ -460,22 +460,22 @@
/* #undef NOSQRT */ /* #undef NOSQRT */
/* Name of package */ /* Name of package */
#define PACKAGE "ng-spice-rework" #define PACKAGE "ngspice"
/* Define to the address where bug reports for this package should be sent. */ /* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "ngspice-bugs@lists.sourceforge.net" #define PACKAGE_BUGREPORT "ngspice-bugs@lists.sourceforge.net"
/* Define to the full name of this package. */ /* Define to the full name of this package. */
#define PACKAGE_NAME "ng-spice-rework" #define PACKAGE_NAME "ngspice"
/* Define to the full name and version of this package. */ /* Define to the full name and version of this package. */
#define PACKAGE_STRING "ng-spice-rework 18" #define PACKAGE_STRING "ngspice 19"
/* Define to the one symbol short name of this package. */ /* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "ng-spice-rework" #define PACKAGE_TARNAME "ngspice"
/* Define to the version of this package. */ /* Define to the version of this package. */
#define PACKAGE_VERSION "18" #define PACKAGE_VERSION "19"
/* Define if we want predictor algorithm */ /* Define if we want predictor algorithm */
/* #undef PREDICTOR */ /* #undef PREDICTOR */
@ -530,7 +530,7 @@
/* #undef TM_IN_SYS_TIME */ /* #undef TM_IN_SYS_TIME */
/* Version number of package */ /* Version number of package */
#define VERSION "18" #define VERSION "19"
/* Define if we want spice2 sensitivity analysis */ /* Define if we want spice2 sensitivity analysis */
/* #undef WANT_SENSE2 */ /* #undef WANT_SENSE2 */

View File

@ -40,7 +40,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="&quot;$(ProjectDir)..\src\maths\poly&quot;;&quot;$(ProjectDir)..\src\frontend&quot;;&quot;$(ProjectDir)..\src\spicelib\devices&quot;;&quot;$(ProjectDir)..\src\include&quot;;&quot;$(ProjectDir)include&quot;" AdditionalIncludeDirectories="&quot;$(ProjectDir)..\src\maths\poly&quot;;&quot;$(ProjectDir)..\src\frontend&quot;;&quot;$(ProjectDir)..\src\spicelib\devices&quot;;&quot;$(ProjectDir)..\src\include&quot;;&quot;$(ProjectDir)include&quot;"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;SIMULATOR" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;SIMULATOR;OUTDECK"
MinimalRebuild="true" MinimalRebuild="true"
ExceptionHandling="0" ExceptionHandling="0"
BasicRuntimeChecks="0" BasicRuntimeChecks="0"
@ -1076,7 +1076,7 @@
> >
</File> </File>
<File <File
RelativePath="..\src\misc\getopt.h" RelativePath="..\src\misc\getopt_bsd.h"
> >
</File> </File>
<File <File
@ -4964,11 +4964,7 @@
> >
</File> </File>
<File <File
RelativePath="..\src\misc\getopt.c" RelativePath="..\src\misc\getopt_long_bsd.c"
>
</File>
<File
RelativePath="..\src\misc\getopt1.c"
> >
</File> </File>
<File <File