From 41325622fdcb58c3c124662cb7c7e6266eafe652 Mon Sep 17 00:00:00 2001 From: dwarning Date: Thu, 18 Oct 2007 19:34:30 +0000 Subject: [PATCH] some clean-up's to come through MSC --- src/frontend/com_chdir.c | 2 + src/frontend/inp.c | 6 ++- src/frontend/inpcom.c | 24 ++++++--- src/frontend/inpcom.h | 3 ++ src/frontend/measure.c | 3 +- src/frontend/parser/complete.c | 2 +- src/frontend/spec.c | 1 + src/include/ngspice.h | 6 +-- src/main.c | 2 +- src/maths/ni/niiter.c | 4 +- src/misc/tilde.c | 5 +- src/misc/util.c | 81 ++++++++++++++++++++++++++++ src/misc/util.h | 3 ++ src/spicelib/analysis/dctran.c | 4 +- src/spicelib/devices/res/resparam.c | 3 +- src/spicelib/devices/vsrc/vsrcacct.c | 3 +- 16 files changed, 131 insertions(+), 21 deletions(-) diff --git a/src/frontend/com_chdir.c b/src/frontend/com_chdir.c index 7057ad0f1..cd06bb01f 100644 --- a/src/frontend/com_chdir.c +++ b/src/frontend/com_chdir.c @@ -21,7 +21,9 @@ void com_chdir(wordlist *wl) { char *s; +#ifdef HAVE_PWD_H struct passwd *pw; +#endif char localbuf[257]; int copied = 0; diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 170d8b0ce..a864bf042 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -15,7 +15,9 @@ $Id$ * the listing routines. */ +#ifndef _MSC_VER #include +#endif #include "ngspice.h" #include "cpdefs.h" #include "inpdefs.h" @@ -24,6 +26,7 @@ $Id$ #include "fteinp.h" #include "inp.h" +#include "inpcom.h" #include "circuits.h" #include "completion.h" #include "variable.h" @@ -640,6 +643,7 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, wordlist *wl; bool noparse, ii; bool brief; + int print_listing; /* First throw away any old error messages there might be and fix * the case of the lines. */ @@ -761,7 +765,7 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, /* output deck */ out_printf( "\nProcessed Netlist\n" ); out_printf( "=================\n" ); - int print_listing = 1; + print_listing = 1; for (dd = deck; dd; dd = dd->li_next) { if ( ciprefix(".prot", dd->li_line) ) print_listing = 0; if ( print_listing == 1 ) out_printf( "%s\n", dd->li_line ); diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index d9f557505..816979eaf 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -30,8 +30,10 @@ Author: 1985 Wayne A. Christopher * Fixed crash where a NULL pointer gets freed in inp_readall() */ -#include +#ifndef _MSC_VER #include +#endif +#include #include "ngspice.h" #include "cpdefs.h" #include "ftedefs.h" @@ -973,7 +975,7 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) struct line *end = NULL, *cc = NULL, *prev = NULL, *working, *newcard, *start_lib, *global_card, *tmp_ptr = NULL, *tmp_ptr2 = NULL; char *buffer = NULL, *s, *t, *y, *z, c; /* segfault fix */ - char *copys=NULL, big_buff[5000], big_buff2[5000]; + char *copys=NULL, big_buff2[5000]; char *global_copy = NULL, keep_char; int line_number = 1; /* sjb - renamed to avoid confusion with struct line */ int line_count = 0; @@ -983,6 +985,7 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) bool dir_name_flag = FALSE; struct variable *v; + char *s_ptr, *s_lower; /* Must set this to NULL or non-tilde includes segfault. -- Tim Molteno */ /* copys = NULL; */ /* This caused a parse error with gcc 2.96. Why??? */ @@ -1030,7 +1033,8 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) break; } else if(ipc_status == IPC_STATUS_OK) { - buffer = (void *) MALLOC(strlen(ipc_buffer) + 3); +// buffer = (void *) MALLOC(strlen(ipc_buffer) + 3); + buffer = (void *) tmalloc(strlen(ipc_buffer) + 3); strcpy(buffer, ipc_buffer); strcat(buffer, "\n"); } @@ -1092,7 +1096,8 @@ inp_readall(FILE *fp, struct line **data, int call_depth, char *dir_name) } /* lower case the file name for later string compares */ - char *s_ptr, *s_lower = strdup(s); + s_ptr = strdup(s); + s_lower = strdup(s); for(s_ptr = s_lower; *s_ptr && (*s_ptr != '\n'); s_ptr++) *s_ptr = tolower(*s_ptr); found_library = FALSE; @@ -2074,6 +2079,8 @@ inp_fix_inst_calls_for_numparam(struct line *deck) int num_inst_params = 0; int i,j,k; bool flag = FALSE; + bool found_subckt = FALSE; + bool found_param_match = FALSE; // first iterate through instances and find occurences where 'm' multiplier needs to be // added to the subcircuit -- subsequent instances will then need this parameter as well @@ -2126,7 +2133,7 @@ inp_fix_inst_calls_for_numparam(struct line *deck) sprintf( name_w_space, "%s ", subckt_name ); /* find .subckt line */ - bool found_subckt = FALSE; + found_subckt = FALSE; d = deck; while ( d != NULL ) { @@ -2140,7 +2147,7 @@ inp_fix_inst_calls_for_numparam(struct line *deck) num_inst_params = inp_get_params( inst_line, inst_param_names, inst_param_values ); // make sure that if have inst params that one matches subckt - bool found_param_match = FALSE; + found_param_match = FALSE; if ( num_inst_params == 0 ) found_param_match = TRUE; else { for ( j = 0; j < num_inst_params; j++ ) { @@ -2363,7 +2370,7 @@ inp_expand_macro_in_str( char *str ) char *open_paren_ptr, *close_paren_ptr, *fcn_name, *comma_ptr, *params[1000]; char *curr_ptr, *new_str, *macro_str, *curr_str = NULL; int num_parens, num_params; - char *orig_ptr = str, *search_ptr = str, *orig_str = strdup(str);; + char *orig_ptr = str, *search_ptr = str, *orig_str = strdup(str); char keep; while ( ( open_paren_ptr = strstr( search_ptr, "(" ) ) ) { @@ -2666,6 +2673,7 @@ inp_sort_params( struct line *start_card, struct line *end_card, struct line *ca char *param_names[12000], *param_strs[12000], *curr_line; char *depends_on[12000][100], *str_ptr, *beg, *end, *new_str; int level[12000], param_skip[12000], skipped = 0; + bool found_in_list = FALSE; if ( start_card == NULL ) return; @@ -2724,7 +2732,7 @@ inp_sort_params( struct line *start_card, struct line *end_card, struct line *ca !isalnum( *(param_ptr+strlen(param_name)) ) && *(param_ptr+strlen(param_name)) != '_' ) { index = 0; - bool found_in_list = FALSE; + found_in_list = FALSE; while ( depends_on[j][index] != NULL ) { if ( strcmp( param_name, depends_on[j][index] ) == 0 ) { found_in_list = TRUE; break; } index++; diff --git a/src/frontend/inpcom.h b/src/frontend/inpcom.h index 1599bb929..b58d37ef4 100644 --- a/src/frontend/inpcom.h +++ b/src/frontend/inpcom.h @@ -10,6 +10,9 @@ FILE * inp_pathopen(char *name, char *mode); void inp_readall(FILE *fp, struct line **data, int, char *dirname); void inp_casefix(register char *string); +char *basename(char *name); +char *dirname(char *name); + /* globals -- wanted to avoid complicating inp_readall interface */ static char *library_file[1000]; static char *library_name[1000][1000]; diff --git a/src/frontend/measure.c b/src/frontend/measure.c index 318dccce0..e4e309276 100644 --- a/src/frontend/measure.c +++ b/src/frontend/measure.c @@ -17,12 +17,13 @@ static bool measures_passed; // some limitations. static bool AlmostEqualUlps(float A, float B, int maxUlps) { + int intDiff; assert(sizeof(float) == sizeof(int)); if (A == B) return TRUE; - int intDiff = abs(*(int*)&A - *(int*)&B); + intDiff = abs(*(int*)&A - *(int*)&B); if (intDiff <= maxUlps) return TRUE; diff --git a/src/frontend/parser/complete.c b/src/frontend/parser/complete.c index f05f727b6..6e9a1f40e 100644 --- a/src/frontend/parser/complete.c +++ b/src/frontend/parser/complete.c @@ -35,7 +35,7 @@ Modified: 1999 Paolo Nenzi #include #endif -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(_MSC_VER) /* MW. We also need ioctl.h here I think */ #include #endif diff --git a/src/frontend/spec.c b/src/frontend/spec.c index d649904b3..935d518eb 100644 --- a/src/frontend/spec.c +++ b/src/frontend/spec.c @@ -15,6 +15,7 @@ $Id$ #include "spec.h" #include "variable.h" +#include "missing_math.h" void com_spec(wordlist *wl) diff --git a/src/include/ngspice.h b/src/include/ngspice.h index 5f87ba3c6..a2d1e381e 100644 --- a/src/include/ngspice.h +++ b/src/include/ngspice.h @@ -135,17 +135,17 @@ extern int scannum(char *str); extern int ciprefix(register char *p, register char *s); extern int cieq(register char *p, register char *s); extern void strtolower(char *str); -extern char *tildexpand(char *string); +extern char *tildexpand(char *str); extern char *canonicalize_pathname(char *path); -extern char *absolute_pathname(char *string, char *dot_path); +extern char *absolute_pathname(char *str, char *dot_path); extern char *smktemp(char *id); extern char *copy(char *str); extern int prefix(char *p, char *str); extern int substring(char *sub, char *str); -extern void cp_printword(char *string, FILE *fp); +extern void cp_printword(char *str, FILE *fp); extern char *datestring(void); extern double seconds(void); diff --git a/src/main.c b/src/main.c index a2da1cdc6..649fe51e1 100644 --- a/src/main.c +++ b/src/main.c @@ -842,7 +842,7 @@ main(int argc, char **argv) if (optarg) { cp_vset("rawfile", VT_STRING, optarg); } - //rflag = TRUE; + /* rflag = TRUE; */ break; case 's': /* Server mode */ diff --git a/src/maths/ni/niiter.c b/src/maths/ni/niiter.c index dc4043ef9..c3a2b3b99 100644 --- a/src/maths/ni/niiter.c +++ b/src/maths/ni/niiter.c @@ -35,11 +35,11 @@ NIiter(CKTcircuit *ckt, int maxIter) double startTime; static char *msg = "Too many iterations without convergence"; - if ( maxIter < 100 ) maxIter = 100; /* some convergence issues that get resolved by increasing max iter */ - CKTnode *node; /* current matrix entry */ double diff, maxdiff, damp_factor, *OldCKTstate0=NULL; + if ( maxIter < 100 ) maxIter = 100; /* some convergence issues that get resolved by increasing max iter */ + iterno=0; ipass=0; diff --git a/src/misc/tilde.c b/src/misc/tilde.c index 135b7f52c..769cc783e 100644 --- a/src/misc/tilde.c +++ b/src/misc/tilde.c @@ -30,8 +30,11 @@ Modified: 2002 R. Oktas, char * tildexpand(char *string) { +#ifdef HAVE_PWD_H char buf[BSIZE_SP]; - char *result = NULL, *k, c; + char *k, c; +#endif + char *result = NULL; if (!string) return NULL; diff --git a/src/misc/util.c b/src/misc/util.c index 369641dec..41457b66e 100644 --- a/src/misc/util.c +++ b/src/misc/util.c @@ -149,3 +149,84 @@ char * absolute_pathname(char *string, char *dot_path) return (result); } + + +#ifdef _MSC_VER + +const char * +basename(const char *name) +{ + const char *base; + char *p; + static char *tmp = NULL; + int len; + + if (tmp) { + free(tmp); + tmp = NULL; + } + + if (!name || !strcmp(name, "")) + return ""; + + if (!strcmp(name, "/")) + return "/"; + + len = strlen(name); + if (name[len - 1] == '/') { + // ditch the trailing '/' + p = tmp = malloc(len); + strncpy(p, name, len - 1); + } else { + p = (char *) name; + } + + for (base = p; *p; p++) + if (*p == '/') + base = p + 1; + + return base; +} + +const char * +dirname(const char *name) +{ + static char *ret = NULL; + int len; + int size = 0; + const char *p; + + if (ret) { + free(ret); + ret = NULL; + } + + if (!name || !strcmp(name, "") || !strstr(name, "/")) + return("."); + + if (!strcmp(name, "/")) + return(name); + + // find the last slash in the string + + len = strlen(name); + p = &name[len - 1]; + + if (*p == '/') p--; // skip the trailing / + + while (p != name && *p != '/') p--; + + size = p - name; + if (size) { + ret = malloc(size + 1); + memcpy(ret, name, size); + ret[size] = '\0'; + } else if (*p == '/') + return "/"; + else + return ""; + + return (const char *) ret; +} + +#endif diff --git a/src/misc/util.h b/src/misc/util.h index af071e72f..ff6c5bf8b 100644 --- a/src/misc/util.h +++ b/src/misc/util.h @@ -9,4 +9,7 @@ char *canonicalize_pathname(char *path); char *absolute_pathname(char *string, char *dot_path); +const char *basename(const char *name); +const char *dirname(const char *name); + #endif diff --git a/src/spicelib/analysis/dctran.c b/src/spicelib/analysis/dctran.c index 318b7127d..0f14b32ae 100644 --- a/src/spicelib/analysis/dctran.c +++ b/src/spicelib/analysis/dctran.c @@ -14,6 +14,7 @@ Modified: 2000 AlansFixes #include #include #include +#include "fteext.h" #ifdef XSPICE /* gtri - add - wbk - Add headers */ @@ -40,12 +41,13 @@ void SetAnalyse( char * Analyse, int Percent); // some limitations. static bool AlmostEqualUlps(float A, float B, int maxUlps) { + int intDiff; assert(sizeof(float) == sizeof(int)); if (A == B) return TRUE; - int intDiff = abs(*(int*)&A - *(int*)&B); + intDiff = abs(*(int*)&A - *(int*)&B); if (intDiff <= maxUlps) return TRUE; diff --git a/src/spicelib/devices/res/resparam.c b/src/spicelib/devices/res/resparam.c index 059e7c308..9b80dae21 100644 --- a/src/spicelib/devices/res/resparam.c +++ b/src/spicelib/devices/res/resparam.c @@ -15,12 +15,13 @@ Modified: Apr 2000 - Paolo Nenzi // some limitations. static bool AlmostEqualUlps(float A, float B, int maxUlps) { + int intDiff; assert(sizeof(float) == sizeof(int)); if (A == B) return TRUE; - int intDiff = abs(*(int*)&A - *(int*)&B); + intDiff = abs(*(int*)&A - *(int*)&B); if (intDiff <= maxUlps) return TRUE; diff --git a/src/spicelib/devices/vsrc/vsrcacct.c b/src/spicelib/devices/vsrc/vsrcacct.c index 89f7f3914..5e73f8303 100644 --- a/src/spicelib/devices/vsrc/vsrcacct.c +++ b/src/spicelib/devices/vsrc/vsrcacct.c @@ -18,12 +18,13 @@ Author: 1985 Thomas L. Quarles // some limitations. static bool AlmostEqualUlps(float A, float B, int maxUlps) { + int intDiff; assert(sizeof(float) == sizeof(int)); if (A == B) return TRUE; - int intDiff = abs(*(int*)&A - *(int*)&B); + intDiff = abs(*(int*)&A - *(int*)&B); if (intDiff <= maxUlps) return TRUE;