From 8585a00243a934e658f50b1094c2d91938ca8941 Mon Sep 17 00:00:00 2001 From: dwarning Date: Sat, 30 Jan 2010 13:21:27 +0000 Subject: [PATCH] controlled_exit implementation --- src/frontend/error.c | 16 +++++++ src/frontend/error.h | 4 +- src/frontend/inpcom.c | 48 ++++++-------------- src/frontend/measure.c | 11 ++--- src/frontend/numparam/mystring.c | 12 ++--- src/frontend/numparam/spicenum.c | 8 ++-- src/misc/alloc.c | 15 ++---- src/spicelib/devices/bsim3soi_dd/b3soiddld.c | 4 +- src/spicelib/devices/bsim3soi_fd/b3soifdld.c | 4 +- src/spicelib/devices/cpl/cplload.c | 4 +- src/spicelib/devices/cpl/cplsetup.c | 16 +++---- src/spicelib/devices/txl/txlsetup.c | 12 ++--- 12 files changed, 69 insertions(+), 85 deletions(-) diff --git a/src/frontend/error.c b/src/frontend/error.c index f59039a24..12382a2d5 100644 --- a/src/frontend/error.c +++ b/src/frontend/error.c @@ -19,6 +19,22 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group char ErrorMessage[1024]; +#ifdef HAS_WINDOWS +void winmessage(char* new_msg); +#endif + +void +controlled_exit(int status) +{ +#ifdef HAS_WINDOWS + winmessage("Fatal error in NGSPICE"); +#else + fprintf(stderr, "Fatal error in NGSPICE - Return"); + getc(stdin); +#endif + exit(status); +} + void fperror(char *mess, int code) diff --git a/src/frontend/error.h b/src/frontend/error.h index 3105cc41b..0592b78b9 100644 --- a/src/frontend/error.h +++ b/src/frontend/error.h @@ -6,12 +6,10 @@ #ifndef ERROR_H_INCLUDED #define ERROR_H_INCLUDED +void controlled_exit(int status); void fperror(char *mess, int code); void ft_sperror(int code, char *mess); void fatal(void); void internalerror(char *message); - - - #endif diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index d715abb2d..73a2eb1bc 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -64,9 +64,7 @@ Author: 1985 Wayne A. Christopher /* SJB - Uncomment this line for debug tracing */ /*#define TRACE*/ -#ifdef HAS_WINDOWS -void winmessage(char* new_msg); -#endif +#include "error.h" /* controlled_exit() */ /* globals -- wanted to avoid complicating inp_readall interface */ static char *library_file[1000]; @@ -925,13 +923,13 @@ inp_fix_ternary_operator_str( char *line ) } if ( count != 0 ) { fprintf(stderr, "ERROR: problem parsing 'if' of ternary string %s!\n", line); - exit (-1); + controlled_exit(EXIT_FAILURE); } colon = str_ptr2 + 1; while ( *colon != ':' && *colon != '\0' ) colon++; if ( *colon != ':' ) { fprintf(stderr,"ERROR: problem parsing ternary string (finding ':') %s!\n", line); - exit(-1); + controlled_exit(EXIT_FAILURE); } } else if ( ( colon = strstr( str_ptr, ":" ) ) ) { @@ -940,7 +938,7 @@ inp_fix_ternary_operator_str( char *line ) } else { fprintf(stderr,"ERROR: problem parsing ternary string (missing ':') %s!\n", line); - exit(-1); + controlled_exit(EXIT_FAILURE); } str_ptr2++; keep = *str_ptr2; *str_ptr2 = '\0'; if_str = inp_fix_ternary_operator_str(strdup(str_ptr)); @@ -961,7 +959,7 @@ inp_fix_ternary_operator_str( char *line ) } if ( found_paren && count != 0 ) { fprintf( stderr, "ERROR: problem parsing ternary line %s!\n", line ); - exit(-1); + controlled_exit(EXIT_FAILURE); } keep = *str_ptr2; *str_ptr2 = '\0'; @@ -1118,7 +1116,7 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) strcat(buffer, "\n"); } else { /* No good way to report this so just die */ - exit(1); + controlled_exit(EXIT_FAILURE); } } @@ -1429,10 +1427,7 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) if ( ciprefix(".lib", buffer) ) { if ( found_lib_name == TRUE ) { fprintf( stderr, "ERROR: .lib is missing .endl!\n" ); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit(-1); + controlled_exit(EXIT_FAILURE); } for ( s = buffer; *s && !isspace(*s); s++ ); /* skip over .lib */ @@ -2543,10 +2538,7 @@ inp_expand_macro_in_str( char *str ) } if ( close_paren_ptr == NULL ) { fprintf( stderr, "ERROR: did not find closing parenthesis for function call in str: %s\n", orig_str ); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit( -1 ); + controlled_exit(EXIT_FAILURE); } *close_paren_ptr = '\0'; @@ -2579,10 +2571,7 @@ inp_expand_macro_in_str( char *str ) if ( num_parameters[i] != num_params ) { fprintf( stderr, "ERROR: parameter mismatch for function call in str: %s\n", orig_ptr ); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit( -1 ); + controlled_exit(EXIT_FAILURE); } macro_str = inp_do_macro_param_replace( i, params ); @@ -2877,7 +2866,7 @@ inp_fix_param_values( struct line *deck ) static char* get_param_name( char *line ) { - char *name, *equal_ptr, *beg; + char *name = NULL, *equal_ptr, *beg; char keep; if ( ( equal_ptr = strstr( line, "=" ) ) ) @@ -2897,10 +2886,7 @@ get_param_name( char *line ) else { fprintf( stderr, "ERROR: could not find '=' on parameter line '%s'!\n", line ); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit(-1); + controlled_exit(EXIT_FAILURE); } return name; } @@ -2935,11 +2921,8 @@ inp_get_param_level( int param_num, char ***depends_on, char **param_names, char if ( index2 > total_params ) { fprintf( stderr, "ERROR: unable to find dependency parameter for %s!\n", param_names[param_num] ); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit( -1 ); - } + controlled_exit(EXIT_FAILURE); + } temp_level = inp_get_param_level( index2, depends_on, param_names, param_strs, total_params, level ); temp_level++; @@ -3236,10 +3219,7 @@ inp_sort_params( struct line *start_card, struct line *end_card, struct line *ca if ( ind != num_params ) { fprintf( stderr, "ERROR: found wrong number of parameters during levelization ( %d instead of %d parameter s)!\n", ind, num_params ); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit(-1); + controlled_exit(EXIT_FAILURE); } /* fix next ptrs */ diff --git a/src/frontend/measure.c b/src/frontend/measure.c index a7b12a1bb..da1d7f390 100644 --- a/src/frontend/measure.c +++ b/src/frontend/measure.c @@ -18,13 +18,11 @@ #include "numparam/numpaif.h" #include "missing_math.h" #include "com_measure2.h" + +#include "error.h" /* controlled_exit() */ #define EOS '\0' -#ifdef HAS_WINDOWS -void winmessage(char* new_msg); -#endif - static wordlist *measure_parse_line( char *line ) ; static bool measure_valid[20000];/* TRUE: if measurement no. [xxx] has been done successfully @@ -300,10 +298,7 @@ do_measure( /* see if number of measurements exceeds fixed array size of 20,000 */ if ( idx >= 20000 ) { fprintf( stderr, "ERROR: number of measurements exceeds 20,000!\nAborting...\n" ); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit(-1); + controlled_exit(EXIT_FAILURE); } } /* end of for loop (first pass through .meas lines) */ diff --git a/src/frontend/numparam/mystring.c b/src/frontend/numparam/mystring.c index 0c7ebd79f..703f7b359 100644 --- a/src/frontend/numparam/mystring.c +++ b/src/frontend/numparam/mystring.c @@ -19,7 +19,7 @@ #include "general.h" -extern void winmessage(char* new_msg); +#include "../error.h" /* controlled_exit() */ #define Getmax(s,ls) (((unsigned char)(s[ls+1])) << 8) + (unsigned char)(s[ls+2]) @@ -76,7 +76,7 @@ rs (char *s) { /* basic line input, limit= 80 chars */ int max, i; char c; -/* exit (-1); */ + max = maxlen (s); i = 0; sini (s, max); @@ -140,8 +140,7 @@ stringbug (char *op, char *s, char *t, char c) fprintf (stderr, "{%c}\n", c); fprintf (stderr, "Aborting...\n"); - winmessage("Fatal error in SPICE"); - exit (1); + controlled_exit(EXIT_FAILURE); /* The code below cannot be reached */ /* Remnants of old interface ?*/ @@ -149,7 +148,7 @@ stringbug (char *op, char *s, char *t, char c) ws (" [A]bort [I]gnore ? "); rep = rc (); if (upcase (rep) == 'A') - exit (1); + controlled_exit(EXIT_FAILURE); } void @@ -774,8 +773,7 @@ new (long sz) if (p == NULL) { /* fatal error */ ws (" new() failure. Program halted.\n"); - winmessage("Fatal error in SPICE"); - exit (1); + controlled_exit(EXIT_FAILURE); } return p; } diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index 2d540a558..637bb10e3 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -27,8 +27,9 @@ Todo: #include "numparam.h" #include "ngspice.h" +#include "../error.h" /* controlled_exit() */ + extern void txfree (void *ptr); -extern void winmessage(char* new_msg); char *nupa_inst_name; static tdico *inst_dico; @@ -489,7 +490,7 @@ nupa_done (void) ws ("Numparam expansion errors: Run Spice anyway? y/n ? \n"); rs (rep); if (upcase (rep[0]) != 'Y') - exit (-1); + controlled_exit(EXIT_FAILURE); } linecount = 0; @@ -665,8 +666,7 @@ nupa_copy (char *s, int linenum) if (t == NULL) { fputs ("Fatal: String malloc crash in nupa_copy()\n", stderr); - winmessage("Fatal error in SPICE"); - exit (-1); + controlled_exit(EXIT_FAILURE); } else { diff --git a/src/misc/alloc.c b/src/misc/alloc.c index 0081fbb95..1ff6b2a72 100644 --- a/src/misc/alloc.c +++ b/src/misc/alloc.c @@ -20,10 +20,10 @@ $Id$ #undef BOOLEAN #include extern HANDLE outheap; -extern void winmessage(char* new_msg); #endif #endif +#include "../frontend/error.h" /* controlled_exit() */ /* Malloc num bytes and initialize to zero. Fatal error if the space can't * be tmalloc'd. Return NULL for a request for 0 bytes. @@ -53,10 +53,7 @@ tmalloc(size_t num) #endif if (!s){ fprintf(stderr,"malloc: Internal Error: can't allocate %ld bytes. \n",(long)num); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit(EXIT_BAD); + controlled_exit(EXIT_FAILURE); } return(s); } @@ -139,10 +136,7 @@ trealloc(void *ptr, size_t num) } if (!s) { fprintf(stderr,"realloc: Internal Error: can't allocate %ld bytes.\n", (long)num); -#ifdef HAS_WINDOWS - winmessage("Fatal error in SPICE"); -#endif - exit(EXIT_BAD); + controlled_exit(EXIT_FAILURE); } return(s); } @@ -183,8 +177,7 @@ hrealloc(void *ptr, size_t num) } if (!s) { fprintf(stderr,"HeapReAlloc: Internal Error: can't allocate %ld bytes.\n", (long)num); - winmessage("Fatal error in SPICE"); - exit(EXIT_BAD); + controlled_exit(EXIT_FAILURE); } return(s); } diff --git a/src/spicelib/devices/bsim3soi_dd/b3soiddld.c b/src/spicelib/devices/bsim3soi_dd/b3soiddld.c index db1019bdf..919b62c82 100644 --- a/src/spicelib/devices/bsim3soi_dd/b3soiddld.c +++ b/src/spicelib/devices/bsim3soi_dd/b3soiddld.c @@ -21,6 +21,8 @@ File: b3soiddld.c 98/5/01 #include "devdefs.h" #include "suffix.h" +#include "../../../frontend/error.h" /* controlled_exit() */ + #define MAX_EXP 5.834617425e14 #define MIN_EXP 1.713908431e-15 #define EXP_THRESHOLD 34.0 @@ -4334,7 +4336,7 @@ if (here->B3SOIDDdebugMod > 2) fprintf(stderr, "Alberto says: YOU TURKEY! %s is NaN for instance %s at time %g!\n", nanmessage, here->B3SOIDDname, ckt->CKTtime); nanfound = nandetect; fprintf(stderr, " The program exit!\n"); - exit(-1); + controlled_exit(EXIT_FAILURE); } if (here->B3SOIDDdebugMod > 2) diff --git a/src/spicelib/devices/bsim3soi_fd/b3soifdld.c b/src/spicelib/devices/bsim3soi_fd/b3soifdld.c index cc5bbe883..ba408dc8f 100644 --- a/src/spicelib/devices/bsim3soi_fd/b3soifdld.c +++ b/src/spicelib/devices/bsim3soi_fd/b3soifdld.c @@ -21,6 +21,8 @@ File: b3soifdld.c 98/5/01 #include "devdefs.h" #include "suffix.h" +#include "../../../frontend/error.h" /* controlled_exit() */ + #define MAX_EXP 5.834617425e14 #define MIN_EXP 1.713908431e-15 #define EXP_THRESHOLD 34.0 @@ -3422,7 +3424,7 @@ if (here->B3SOIFDdebugMod > 2) fprintf(stderr, "Alberto says: YOU TURKEY! %s is NaN for instance %s at time %g!\n", nanmessage, here->B3SOIFDname, ckt->CKTtime); nanfound = nandetect; fprintf(stderr, " The program exit!\n"); - exit(-1); + controlled_exit(EXIT_FAILURE); } if (here->B3SOIFDdebugMod > 2) diff --git a/src/spicelib/devices/cpl/cplload.c b/src/spicelib/devices/cpl/cplload.c index aca4d29e9..d7c6c7d63 100644 --- a/src/spicelib/devices/cpl/cplload.c +++ b/src/spicelib/devices/cpl/cplload.c @@ -10,6 +10,8 @@ Author: 1992 Charles Hough #include "sperror.h" #include "suffix.h" +#include "../../../frontend/error.h" /* controlled_exit() */ + VI_list *pool_vi; static double ratio[MAX_CP_TX_LINES]; static VI_list *new_vi(void); @@ -25,8 +27,6 @@ static int divC(double, double, double, double, double*, double*); static void update_cnv_a(TMS*, float, double, double, double, double, double, double); static void copy_cp(CPLine*, CPLine*); -void controlled_exit(int); - /*ARGSUSED*/ int CPLload(GENmodel *inModel, CKTcircuit *ckt) diff --git a/src/spicelib/devices/cpl/cplsetup.c b/src/spicelib/devices/cpl/cplsetup.c index 9d27b982c..387fff139 100644 --- a/src/spicelib/devices/cpl/cplsetup.c +++ b/src/spicelib/devices/cpl/cplsetup.c @@ -14,6 +14,8 @@ Modified: 2004 Paolo Nenzi - (ng)spice integration #include "multi_line.h" +#include "../../../frontend/error.h" /* controlled_exit() */ + #define VECTOR_ALLOC(vec, n) { \ vec = (double **) tmalloc(n * sizeof(double *)); \ @@ -128,8 +130,6 @@ static int rotate(int, int, int); #define epsi 1.0e-16 static char *message = "tau of coupled lines is larger than max time step"; -void controlled_exit(int); - /* ARGSUSED */ int CPLsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *state) @@ -543,7 +543,7 @@ static double if (!v) { fprintf(stderr, "Memory Allocation Error by tmalloc in vector().\n"); fprintf(stderr, "...now exiting to system ...\n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } return v-nl; } @@ -587,7 +587,7 @@ polint(double *xa, double *ya, int n, double x, double *y, double *dy) if ((den=ho-hp) == 0.0) { fprintf(stderr, "(Error) in routine POLINT\n"); fprintf(stderr, "...now exiting to system ...\n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } den = w/den; d[i] = hp * den; @@ -731,7 +731,7 @@ Gaussian_Elimination2(int dims, int type) } if (max < epsilon) { fprintf(stderr, " can not choose a pivot (misc)\n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } if (imax != i) for (k = i; k <= dim; k++) { @@ -950,7 +950,7 @@ loop_ZY(int dim, double y) fmin = D[i]; if (fmin < 0) { fprintf(stderr, "(Error) The capacitance matrix of the multiconductor system is not positive definite.\n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } else { fmin = sqrt(fmin); fmin1 = 1 / fmin; @@ -1101,7 +1101,7 @@ eval_frequency(int dim, int deg_o) if (min <= 0) { fprintf(stderr, "A mode frequency is not positive. Abort!\n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } Scaling_F2 = 1.0 / min; @@ -1660,7 +1660,7 @@ Gaussian_Elimination(int dims) } if (max < epsi_mult) { fprintf(stderr, " can not choose a pivot (mult)\n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } if (imax != i) for (k = i; k <= dim; k++) { diff --git a/src/spicelib/devices/txl/txlsetup.c b/src/spicelib/devices/txl/txlsetup.c index 1b94dc721..3a2d7b0bf 100644 --- a/src/spicelib/devices/txl/txlsetup.c +++ b/src/spicelib/devices/txl/txlsetup.c @@ -11,6 +11,8 @@ Author: 1992 Charles Hough #include "sperror.h" #include "suffix.h" +#include "../../../frontend/error.h" /* controlled_exit() */ + static int ReadTxL(TXLinstance*, CKTcircuit*); /*static int multC();*/ static int main_pade(double, double, double, double, double, TXLine*); @@ -71,8 +73,6 @@ static double AA[3][4]; #define epsi 1.0e-16 #define epsi2 1.0e-28 -void controlled_exit(int); - /* ARGSUSED */ int TXLsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit*ckt, int *state) @@ -239,7 +239,7 @@ ReadTxL(TXLinstance *tx, CKTcircuit *ckt) if (l == 0.0) { fprintf(stderr, "(Error) transmission line of zero length\n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } else { if (R / L < 5.0e+5) { @@ -516,7 +516,7 @@ Gaussian_Elimination1(int dims) } if (max < epsi) { fprintf(stderr, " can not choose a pivot \n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } if (imax != i) for (k = i; k <= dim; k++) { @@ -876,7 +876,7 @@ Gaussian_Elimination2(int dims) } if (max < epsi2) { fprintf(stderr, " can not choose a pivot \n"); - controlled_exit(0); + controlled_exit(EXIT_FAILURE); } if (imax != i) for (k = i; k <= dim; k++) { @@ -1125,7 +1125,7 @@ find_roots(double a1, double a2, double a3, double *x1, double *x2, double *x3) t = a1 * a1 - 4.0 * a2; if (t < 0) { printf("***** Two Imaginary Roots in Characteristic Admittance.\n"); - exit(0); + exit(EXIT_FAILURE); } t *= 1.0e-18;