Browse Source

some clean-up's to come through MSC

pre-master-46
dwarning 19 years ago
parent
commit
41325622fd
  1. 2
      src/frontend/com_chdir.c
  2. 6
      src/frontend/inp.c
  3. 24
      src/frontend/inpcom.c
  4. 3
      src/frontend/inpcom.h
  5. 3
      src/frontend/measure.c
  6. 2
      src/frontend/parser/complete.c
  7. 1
      src/frontend/spec.c
  8. 6
      src/include/ngspice.h
  9. 2
      src/main.c
  10. 4
      src/maths/ni/niiter.c
  11. 5
      src/misc/tilde.c
  12. 81
      src/misc/util.c
  13. 3
      src/misc/util.h
  14. 4
      src/spicelib/analysis/dctran.c
  15. 3
      src/spicelib/devices/res/resparam.c
  16. 3
      src/spicelib/devices/vsrc/vsrcacct.c

2
src/frontend/com_chdir.c

@ -21,7 +21,9 @@ void
com_chdir(wordlist *wl) com_chdir(wordlist *wl)
{ {
char *s; char *s;
#ifdef HAVE_PWD_H
struct passwd *pw; struct passwd *pw;
#endif
char localbuf[257]; char localbuf[257];
int copied = 0; int copied = 0;

6
src/frontend/inp.c

@ -15,7 +15,9 @@ $Id$
* the listing routines. * the listing routines.
*/ */
#ifndef _MSC_VER
#include <libgen.h> #include <libgen.h>
#endif
#include "ngspice.h" #include "ngspice.h"
#include "cpdefs.h" #include "cpdefs.h"
#include "inpdefs.h" #include "inpdefs.h"
@ -24,6 +26,7 @@ $Id$
#include "fteinp.h" #include "fteinp.h"
#include "inp.h" #include "inp.h"
#include "inpcom.h"
#include "circuits.h" #include "circuits.h"
#include "completion.h" #include "completion.h"
#include "variable.h" #include "variable.h"
@ -640,6 +643,7 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse,
wordlist *wl; wordlist *wl;
bool noparse, ii; bool noparse, ii;
bool brief; bool brief;
int print_listing;
/* First throw away any old error messages there might be and fix /* First throw away any old error messages there might be and fix
* the case of the lines. */ * the case of the lines. */
@ -761,7 +765,7 @@ inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse,
/* output deck */ /* output deck */
out_printf( "\nProcessed Netlist\n" ); out_printf( "\nProcessed Netlist\n" );
out_printf( "=================\n" ); out_printf( "=================\n" );
int print_listing = 1;
print_listing = 1;
for (dd = deck; dd; dd = dd->li_next) { for (dd = deck; dd; dd = dd->li_next) {
if ( ciprefix(".prot", dd->li_line) ) print_listing = 0; if ( ciprefix(".prot", dd->li_line) ) print_listing = 0;
if ( print_listing == 1 ) out_printf( "%s\n", dd->li_line ); if ( print_listing == 1 ) out_printf( "%s\n", dd->li_line );

24
src/frontend/inpcom.c

@ -30,8 +30,10 @@ Author: 1985 Wayne A. Christopher
* Fixed crash where a NULL pointer gets freed in inp_readall() * Fixed crash where a NULL pointer gets freed in inp_readall()
*/ */
#include <config.h>
#ifndef _MSC_VER
#include <libgen.h> #include <libgen.h>
#endif
#include <config.h>
#include "ngspice.h" #include "ngspice.h"
#include "cpdefs.h" #include "cpdefs.h"
#include "ftedefs.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; 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; char *buffer = NULL, *s, *t, *y, *z, c;
/* segfault fix */ /* segfault fix */
char *copys=NULL, big_buff[5000], big_buff2[5000];
char *copys=NULL, big_buff2[5000];
char *global_copy = NULL, keep_char; char *global_copy = NULL, keep_char;
int line_number = 1; /* sjb - renamed to avoid confusion with struct line */ int line_number = 1; /* sjb - renamed to avoid confusion with struct line */
int line_count = 0; 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; bool dir_name_flag = FALSE;
struct variable *v; struct variable *v;
char *s_ptr, *s_lower;
/* Must set this to NULL or non-tilde includes segfault. -- Tim Molteno */ /* Must set this to NULL or non-tilde includes segfault. -- Tim Molteno */
/* copys = NULL; */ /* This caused a parse error with gcc 2.96. Why??? */ /* 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; break;
} }
else if(ipc_status == IPC_STATUS_OK) { 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); strcpy(buffer, ipc_buffer);
strcat(buffer, "\n"); 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 */ /* 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); for(s_ptr = s_lower; *s_ptr && (*s_ptr != '\n'); s_ptr++) *s_ptr = tolower(*s_ptr);
found_library = FALSE; found_library = FALSE;
@ -2074,6 +2079,8 @@ inp_fix_inst_calls_for_numparam(struct line *deck)
int num_inst_params = 0; int num_inst_params = 0;
int i,j,k; int i,j,k;
bool flag = FALSE; 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 // 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 // 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 ); sprintf( name_w_space, "%s ", subckt_name );
/* find .subckt line */ /* find .subckt line */
bool found_subckt = FALSE;
found_subckt = FALSE;
d = deck; d = deck;
while ( d != NULL ) { 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 ); 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 // 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; if ( num_inst_params == 0 ) found_param_match = TRUE;
else { else {
for ( j = 0; j < num_inst_params; j++ ) { 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 *open_paren_ptr, *close_paren_ptr, *fcn_name, *comma_ptr, *params[1000];
char *curr_ptr, *new_str, *macro_str, *curr_str = NULL; char *curr_ptr, *new_str, *macro_str, *curr_str = NULL;
int num_parens, num_params; 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; char keep;
while ( ( open_paren_ptr = strstr( search_ptr, "(" ) ) ) { 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 *param_names[12000], *param_strs[12000], *curr_line;
char *depends_on[12000][100], *str_ptr, *beg, *end, *new_str; char *depends_on[12000][100], *str_ptr, *beg, *end, *new_str;
int level[12000], param_skip[12000], skipped = 0; int level[12000], param_skip[12000], skipped = 0;
bool found_in_list = FALSE;
if ( start_card == NULL ) return; 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)) != '_' ) !isalnum( *(param_ptr+strlen(param_name)) ) && *(param_ptr+strlen(param_name)) != '_' )
{ {
index = 0; index = 0;
bool found_in_list = FALSE;
found_in_list = FALSE;
while ( depends_on[j][index] != NULL ) { while ( depends_on[j][index] != NULL ) {
if ( strcmp( param_name, depends_on[j][index] ) == 0 ) { found_in_list = TRUE; break; } if ( strcmp( param_name, depends_on[j][index] ) == 0 ) { found_in_list = TRUE; break; }
index++; index++;

3
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_readall(FILE *fp, struct line **data, int, char *dirname);
void inp_casefix(register char *string); void inp_casefix(register char *string);
char *basename(char *name);
char *dirname(char *name);
/* globals -- wanted to avoid complicating inp_readall interface */ /* globals -- wanted to avoid complicating inp_readall interface */
static char *library_file[1000]; static char *library_file[1000];
static char *library_name[1000][1000]; static char *library_name[1000][1000];

3
src/frontend/measure.c

@ -17,12 +17,13 @@ static bool measures_passed;
// some limitations. // some limitations.
static bool AlmostEqualUlps(float A, float B, int maxUlps) static bool AlmostEqualUlps(float A, float B, int maxUlps)
{ {
int intDiff;
assert(sizeof(float) == sizeof(int)); assert(sizeof(float) == sizeof(int));
if (A == B) if (A == B)
return TRUE; return TRUE;
int intDiff = abs(*(int*)&A - *(int*)&B);
intDiff = abs(*(int*)&A - *(int*)&B);
if (intDiff <= maxUlps) if (intDiff <= maxUlps)
return TRUE; return TRUE;

2
src/frontend/parser/complete.c

@ -35,7 +35,7 @@ Modified: 1999 Paolo Nenzi
#include <pwd.h> #include <pwd.h>
#endif #endif
#ifndef __MINGW32__
#if !defined(__MINGW32__) && !defined(_MSC_VER)
/* MW. We also need ioctl.h here I think */ /* MW. We also need ioctl.h here I think */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif

1
src/frontend/spec.c

@ -15,6 +15,7 @@ $Id$
#include "spec.h" #include "spec.h"
#include "variable.h" #include "variable.h"
#include "missing_math.h"
void void
com_spec(wordlist *wl) com_spec(wordlist *wl)

6
src/include/ngspice.h

@ -135,17 +135,17 @@ extern int scannum(char *str);
extern int ciprefix(register char *p, register char *s); extern int ciprefix(register char *p, register char *s);
extern int cieq(register char *p, register char *s); extern int cieq(register char *p, register char *s);
extern void strtolower(char *str); extern void strtolower(char *str);
extern char *tildexpand(char *string);
extern char *tildexpand(char *str);
extern char *canonicalize_pathname(char *path); 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 *smktemp(char *id);
extern char *copy(char *str); extern char *copy(char *str);
extern int prefix(char *p, char *str); extern int prefix(char *p, char *str);
extern int substring(char *sub, 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 char *datestring(void);
extern double seconds(void); extern double seconds(void);

2
src/main.c

@ -842,7 +842,7 @@ main(int argc, char **argv)
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 */

4
src/maths/ni/niiter.c

@ -35,11 +35,11 @@ NIiter(CKTcircuit *ckt, int maxIter)
double startTime; double startTime;
static char *msg = "Too many iterations without convergence"; 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 */ CKTnode *node; /* current matrix entry */
double diff, maxdiff, damp_factor, *OldCKTstate0=NULL; double diff, maxdiff, damp_factor, *OldCKTstate0=NULL;
if ( maxIter < 100 ) maxIter = 100; /* some convergence issues that get resolved by increasing max iter */
iterno=0; iterno=0;
ipass=0; ipass=0;

5
src/misc/tilde.c

@ -30,8 +30,11 @@ Modified: 2002 R. Oktas, <roktas@omu.edu.tr>
char * char *
tildexpand(char *string) tildexpand(char *string)
{ {
#ifdef HAVE_PWD_H
char buf[BSIZE_SP]; char buf[BSIZE_SP];
char *result = NULL, *k, c;
char *k, c;
#endif
char *result = NULL;
if (!string) if (!string)
return NULL; return NULL;

81
src/misc/util.c

@ -149,3 +149,84 @@ char * absolute_pathname(char *string, char *dot_path)
return (result); 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

3
src/misc/util.h

@ -9,4 +9,7 @@
char *canonicalize_pathname(char *path); char *canonicalize_pathname(char *path);
char *absolute_pathname(char *string, char *dot_path); char *absolute_pathname(char *string, char *dot_path);
const char *basename(const char *name);
const char *dirname(const char *name);
#endif #endif

4
src/spicelib/analysis/dctran.c

@ -14,6 +14,7 @@ Modified: 2000 AlansFixes
#include <cktaccept.h> #include <cktaccept.h>
#include <trandefs.h> #include <trandefs.h>
#include <sperror.h> #include <sperror.h>
#include "fteext.h"
#ifdef XSPICE #ifdef XSPICE
/* gtri - add - wbk - Add headers */ /* gtri - add - wbk - Add headers */
@ -40,12 +41,13 @@ void SetAnalyse( char * Analyse, int Percent);
// some limitations. // some limitations.
static bool AlmostEqualUlps(float A, float B, int maxUlps) static bool AlmostEqualUlps(float A, float B, int maxUlps)
{ {
int intDiff;
assert(sizeof(float) == sizeof(int)); assert(sizeof(float) == sizeof(int));
if (A == B) if (A == B)
return TRUE; return TRUE;
int intDiff = abs(*(int*)&A - *(int*)&B);
intDiff = abs(*(int*)&A - *(int*)&B);
if (intDiff <= maxUlps) if (intDiff <= maxUlps)
return TRUE; return TRUE;

3
src/spicelib/devices/res/resparam.c

@ -15,12 +15,13 @@ Modified: Apr 2000 - Paolo Nenzi
// some limitations. // some limitations.
static bool AlmostEqualUlps(float A, float B, int maxUlps) static bool AlmostEqualUlps(float A, float B, int maxUlps)
{ {
int intDiff;
assert(sizeof(float) == sizeof(int)); assert(sizeof(float) == sizeof(int));
if (A == B) if (A == B)
return TRUE; return TRUE;
int intDiff = abs(*(int*)&A - *(int*)&B);
intDiff = abs(*(int*)&A - *(int*)&B);
if (intDiff <= maxUlps) if (intDiff <= maxUlps)
return TRUE; return TRUE;

3
src/spicelib/devices/vsrc/vsrcacct.c

@ -18,12 +18,13 @@ Author: 1985 Thomas L. Quarles
// some limitations. // some limitations.
static bool AlmostEqualUlps(float A, float B, int maxUlps) static bool AlmostEqualUlps(float A, float B, int maxUlps)
{ {
int intDiff;
assert(sizeof(float) == sizeof(int)); assert(sizeof(float) == sizeof(int));
if (A == B) if (A == B)
return TRUE; return TRUE;
int intDiff = abs(*(int*)&A - *(int*)&B);
intDiff = abs(*(int*)&A - *(int*)&B);
if (intDiff <= maxUlps) if (intDiff <= maxUlps)
return TRUE; return TRUE;

Loading…
Cancel
Save