From ec3351b96a7d1c05562dc761efd18c1aa61c205e Mon Sep 17 00:00:00 2001 From: pnenzi Date: Wed, 16 May 2001 18:55:56 +0000 Subject: [PATCH] Added contributed file from Jon. This is the first step towards win32 support. --- patches/README | 5 +- patches/win32/OS_WIN32.H | 258 ++++++++++ patches/win32/jon_message.txt | 858 ++++++++++++++++++++++++++++++++++ patches/win32/resource.c | 444 ++++++++++++++++++ 4 files changed, 1564 insertions(+), 1 deletion(-) create mode 100644 patches/win32/OS_WIN32.H create mode 100644 patches/win32/jon_message.txt create mode 100644 patches/win32/resource.c diff --git a/patches/README b/patches/README index 2edf511de..4bb7d03b5 100644 --- a/patches/README +++ b/patches/README @@ -21,4 +21,7 @@ readline-patch: This patch is not included in the source since the readline If you want to know more about the license issue, look at the GNU site: htt://www.gnu.org - +win32/: This directory contains a patch to run ngspice under windows. + This code is not yet inserted into the main code but will be + in the next ones. + diff --git a/patches/win32/OS_WIN32.H b/patches/win32/OS_WIN32.H new file mode 100644 index 000000000..685be2cf9 --- /dev/null +++ b/patches/win32/OS_WIN32.H @@ -0,0 +1,258 @@ +/* + * Win32... + */ + +/* + * MS-DOS + */ +#ifndef WIN32_H +#define WIN32_H + +#define STDC_HEADERS + +#define DIR_CWD "." +#define DIR_PATHSEP "\\" +#define DIR_TERM '\\' +#define TEMPFORMAT "%s%d.tmp" + +#define RETSIGTYPE void* +/* ----- System capabilities */ +#define HAS_FLAT_INCLUDES +//#define HAS_QUICKDRAW +//#define HAS_MACCLOCK +//#define HAS_LOCALTIME +//#define HAS_NO_ERFC + +#define FTEDEBUG /* Enable general debugging */ +#define CPDEBUG /* Enable cshpar debugging */ +#define CAPZEROBYPASS +#define NEWCONV +//#define HAS_MAC_ARGCARGV +#define HAS_ASCII +#define HAS_CHDIR /* for tree filesystems, chdir( ) */ +#define HAS_CLEARERR /* clearerr( ), should be in stdio */ +#define HAS_CTYPE /* , iswhite( ), etc. */ +#define HAS_DOSDIRS /* Emulate opendir, etc. */ +//#define HAS_MEMAVL /*_memavl( ) not available in Win32 console mode. */ +#define HAS_ENVIRON +#define HAS_FTIME +#define HAS_GETCWD /* getcwd(buf, size) */ +#define HAS_LOCALTIME +#define HAS_LONGJUMP /* setjmp( ), longjmp( ) */ +// #define HAS_MINDATA // only needed for MS-DOS +// #define HAS_NOINLINE // only needed for MS-DOS +// #define HAS_NOVM // only needed for MS-DOS +#define HAS_PCTERM +#define HAS_QSORT /* qsort( ) */ +#define HAVE_QSORT /* qsort( ) */ +#define HAS_SHORTMACRO +#define HAS_STAT +#define HAS_STDLIB +#define HAS_STRCHR /* strchr( ) instead of index( ) */ +#define HAS_SYSTEM +#define HAS_UNIX_SIGS +#define HAS_UNLINK +#define HAS_LIMITS_H +#define HAS_FLOAT_H +#define HAS_NO_IEEE_LOGB +#define HAS_NO_ERFC +#define HAS_BATCHSIM + +#define WANT_PCHARDCOPY +#define WANT_MFB + +#define X_DISPLAY_MISSING +// from Mac world?? +#define SIMULATOR /* There should be a better way */ + +#define PACKAGE "NG-SPICE" +#define VERSION "13" +#define NGSPICEBUILDDATE "??" +#define NGSPICEBINDIR "??" +#define NGSPICEDATADIR "??" + +#define MAX_EXP_ARG 709.0 + +#ifndef DBL_EPSILON +# define DBL_EPSILON 8.9e-15 +#endif + +// from misc.h +#define BSIZE_SP 512 + +#ifdef HAS_EXIT1 +# define EXIT_NORMAL 1 +# define EXIT_BAD 0 +#else +# define EXIT_NORMAL 0 +# define EXIT_BAD 1 +#endif + +#ifdef HAS_CTYPE +# ifndef isalpha +# include +# endif +#endif + +#define eq(a,b) (!strcmp((a), (b))) +#define eqc(a,b) (cieq((a), (b))) +#define isalphanum(c) (isalpha(c) || isdigit(c)) +#define hexnum(c) ((((c) >= '0') && ((c) <= '9')) ? ((c) - '0') : ((((c) >= \ + 'a') && ((c) <= 'f')) ? ((c) - 'a' + 10) : ((((c) >= 'A') && \ + ((c) <= 'F')) ? ((c) - 'A' + 10) : 0))) + +#include + +//extern char *tmalloc(); +//extern char *trealloc(); +//extern void txfree(); +//#define tfree(x) (txfree(x), x = 0) +//#define alloc(TYPE) ((TYPE *) tmalloc(sizeof(TYPE))) + +//extern int externalerror(char *message); + +extern char *copy(); +extern char *gettok(); +extern void appendc(); +extern int scannum(); +extern int prefix(); +extern int ciprefix(); +extern int cieq(); +extern void strtolower(); +extern int substring(); +extern char *tilde_expand( ); +extern void cp_printword(); + +extern char *datestring(); +extern double seconds(); + +extern char *smktemp(); + +/* Externs from libc */ + +#ifdef HAS_STDLIB + +# ifndef _STDLIB_INCLUDED +# define _STDLIB_INCLUDED +# include +# endif +# ifndef HAS_BSDRAND +# define random rand +# define srandom srand +# endif +# ifdef HAS_DOSDIRS +#ifndef WIN32 +char *getcwd( ); +#endif +# endif + +#else + +# ifdef HAS_BSDRAND +extern long random(); +extern void srandom(); +# else +# define random rand +# define srandom srand +# endif + +extern char *calloc(); +extern char *malloc(); +extern char *realloc(); +extern char *getenv(); +extern int errno; +extern char *sys_errlist[]; +extern char *getenv(); +extern char *getwd(); +extern int rand(); +extern int srand(); +extern int atoi(); +extern int kill(); +extern int getpid(); +extern int qsort(); +# ifdef notdef +extern void exit(); +# endif + +# ifdef HAS_GETCWD +extern char *getcwd( ); +# endif + +# ifdef HAS_CLEARERR +# ifndef clearerr +extern void clearerr(); +# endif /* clearerr */ +# endif /* HAS_CLEARERR */ + +# ifndef bzero +extern int bzero(); +# endif +# ifndef bcopy +extern void bcopy(); +# endif + +# ifndef index +# ifdef HAS_INDEX +extern char *rindex(); +extern char *index(); +# else +# ifdef HAS_STRCHR +extern char *strchr(); +extern char *strrchr(); +# else +# endif +# endif +# endif + +#endif /* else STDLIB */ + +#ifndef HAS_INDEX +# ifndef index +# ifdef HAS_STRCHR +# define index strchr +# define rindex strrchr +# endif +# endif +#endif + +#ifdef HAS_VPERROR +extern void perror(); +#endif + +#ifdef HAS_TIME_ +# ifdef HAS_BSDTIME +extern char *timezone(); +# endif +extern char *asctime(); +extern struct tm *localtime(); +#endif + +#ifndef HAS_MEMAVL +# ifdef HAS_RLIMIT_ +extern char *sbrk(); +# endif +#endif + +#define false 0 +#define true 1 + +#ifdef HAS_DOSDIRS +typedef int *DIR; +struct direct { + int d_reclen; + short d_ino; + short d_namelen; + char d_name[20]; + }; + +# ifdef __STDC__ +extern DIR *opendir(char *); +extern struct direct *readdir(DIR *); +# else +extern DIR *opendir( ); +extern struct direct *readdir( ); +# endif + +#endif + +#endif WIN32_H \ No newline at end of file diff --git a/patches/win32/jon_message.txt b/patches/win32/jon_message.txt new file mode 100644 index 000000000..054ab5312 --- /dev/null +++ b/patches/win32/jon_message.txt @@ -0,0 +1,858 @@ +---------- Forwarded message ---------- +Date: Tue, 24 Apr 2001 15:19:56 -0400 +From: Jon Engelbert +Reply-To: ng-spice-devel@ieee.ing.uniroma1.it +To: ng-spice-devel@ieee.ing.uniroma1.it +Subject: [ng-spice-devel] Changes to ng-spice v13 for WIN32. + +I didn't get a chance to download the preliminary v14 yet. Also, please +note that this is not 100% complete or tested yet. +Also, I don't have cvs on my Windows machine, so these reports are from +Visual SourceSafe. There are no line numbers (ouch!) + +I hope that someone can go through these changes and make them to the +official ng-spice source code so that the relevant changes are in v14. + +Some of the big changes are: +I added a new file, os_win32.h, that I took from my old xspice project, and +this new file is included in conf.h. +Os_win32.h contains definitions particular to the WIN32 environment. + +I changed complex field references (cxreal, cximag) to the functions that +return the same values. +This is because Microsoft defines the complex fields as x and y. + +I changed a lot of headers from <> to "" enclosures, and I gave explicit +paths in some cases. +This is because the compiler was having trouble finding the header files. + +I bracketed #include of some files with #ifndef WIN32 ... #endif +This is because Win32 didn't have these files on the system. + +I basically replaced resource.c because there were a lot of +incompatibilities with WIN32. +I replaced it with the file from my old xspice project. + +If anyone has suggestions on a better way to communicate my changes in the +future, please don't hesitate. + + +Files that are included separately... frontend/resource.c, os_win32.h + +FILE: Main.c + +******** +#define _GNU_SOURCE #define _GNU_SOURCE + > + > #ifndef WIN32 +#include #include + > #endif + +******** +#include #include +#include | #include "spicelib/devices/dev.h" +#include | #include "misc/ivars.h" +#include | #include "frontend/resource.h" +#include | #include "frontend/variable.h" + +******** + pw = getpwuid(getuid()); pw = +getpwuid(getuid()); + asprintf(&s, "%s/.spiceinit", p | #ifndef WIN32 + > asprintf(&s, "%s/.spiceinit", +pw- + > #endif + if (access(s, 0) == 0) if (access(s, 0) == 0) + + +----------------------------------- +FILE: frontend/com_ghelp.c + +******** +#include #include + > + > #ifndef WIN32 +#include #include + > #endif + > +#include #include + + + +FILE: frontend/outitf.c + +******** +#include "cktdefs.h" #include "cktdefs.h" + | #ifdef WIN32 + > #include + > #endif + +******** + + > #ifndef WIN32 + if (strncasecmp(run->type,"AC",2 if +(strncasecmp(run->type,"AC",2 +******** + }; }; + > #else + > if +(strnicmp(run->type,"AC",2)==0) { + > sprintf(buf, "AC Sweep"); + > sweep=2; + > } else if +(strnicmp(run->type,"DC",2)==0) { + > sprintf(buf, "DC Sweep"); + > sweep=1; + > } else if +(strnicmp(run->type,"Tran",4)==0) { + > sprintf(buf, "Transient +An + > sweep=4; + > }; + > #endif + i += strlen(buf); i += strlen(buf); +******** + sizeof (complex) * (v->v sizeof (complex) * +(v->v_length + 1)); + v->v_compdata[v->v_length].cx_ | +realpart(&v->v_compdata[v->v_length]) = value; + v->v_compdata[v->v_length].cx_ | +imagpart(&v->v_compdata[v->v_length]) = (double) 0; + } } +******** + sizeof (complex) * (v->v sizeof (complex) * +(v->v_length + 1)); + v->v_compdata[v->v_length].cx_re | +realpart(&v->v_compdata[v->v_length]) = value; + v->v_compdata[v->v_length].cx_im | +imagpart(&v->v_compdata[v->v_length]) = value.imag; + v->v_length++; v->v_length++; + +FILE: frontend/rawfile.c + +******** + } else { } else { + if (fread((char *) &v->v_compdat | if (fread((char *) +&realpart(&v->v_compdata[i]), + sizeof (double), 1, fp) != 1) sizeof (double), 1, fp) != 1) +******** + "Error: bad rawfile\n"); "Error: bad rawfile\n"); + if (fread((char *) &v->v_compdat | if (fread((char *) +&imagpart(&v->v_compdata[i]), + sizeof (double), 1, fp) != 1) sizeof (double), 1, fp) != 1) + + +FILE: frontend/resource.c +******** So many changes that I'm also attaching the resource.c file +separately. + + > #include + > + > #ifdef HAS_BSDRLIMIT + > # include + > # include + > #endif + > #ifdef HAS_BSDRUSAGE + > # ifndef HAS_BSDRLIMIT + > # include + > # include + > # endif + > #else + > # ifdef HAS_SYSVRUSAGE + > # include + > # include + > # else + > # ifdef HAS_FTIME + > # include + > struct timeb timebegin; + > # endif + > # endif + > #endif + > +/* static declarations */ /* static declarations */ +******** + + | #ifdef HAS_RLIMIT_ + | # ifdef HAS_MEMAVL + > size_t mem_avail; + > # else +char *startdata; char *startdata; +char *enddata; char *enddata; + | # endif + > #endif + +******** +{ { + | #ifdef HAS_RLIMIT_ + > # ifdef HAS_MEMAVL + > mem_avail = _memavl( ); + > # else + startdata = (char *) baseaddr( ) startdata = (char *) +aseaddr( ) + enddata = sbrk(0); enddata = sbrk(0); + | # endif + > #endif +} } +******** +{ { + > #ifdef HAS_RLIMIT_ + long usage, limit; long usage, limit; + static long old_usage = 0; static long old_usage = 0; + > + > # ifdef HAS_MEMAVL + > + > size_t mem_avail_now; + > + > mem_avail_now = _memavl( ); + > usage = mem_avail - +mem_avail_now + > limit = mem_avail; + > + > # else + > + char *hi; char *hi; + + | # ifdef HAS_BSDRLIMIT +# ifdef HAVE_GETRLIMIT < + +******** +# endif # endif + hi=sbrk(0); | + usage = (long) (hi - enddata); | usage = sbrk(0) - enddata; + + > # endif + +******** + + > #endif + return; return; +******** +{ { + bool yy = FALSE; | bool yy = false; + static long lastsec = 0, lastuse static long lastsec = 0, +lastuse + struct variable *v; struct variable *v; + > long realt; + char *cpu_elapsed; char *cpu_elapsed; +******** + +# ifdef HAVE_GETRUSAGE | # ifdef HAS_BSDRUSAGE + struct rusage ruse; struct rusage ruse; +******** +# else # else +# ifdef HAVE_TIMES | # ifdef HAS_SYSVRUSAGE + struct tms ruse; struct tms ruse; +******** +# else # else +# ifdef HAVE_FTIME | # ifdef HAS_FTIME + struct timeb timenow; struct timeb timenow; +******** + totalu %= 1000; totalu %= 1000; + fprintf(cp_out, "Total %s time: | fprintf(cp_out, "Total %s +time: %lu.%03lu seconds.\n", + cpu_elapsed, total, totalu); cpu_elapsed, total, totalu); +******** + + fprintf(cp_out, "%s time since | out_printf("%s time since last +call: %lu.%03lu seconds.\n", + cpu_elapsed, lastsec, lastusec); cpu_elapsed, lastsec, lastusec); +******** + + yy = TRUE; | yy = true; +#else #else +******** + fprintf(cp_out, "CPU time since fprintf(cp_out, "CPU time +since + yy = TRUE; | yy = true; +#endif #endif +******** +#else #else +# ifdef HAVE_GETRLIMIT | # ifdef HAS_BSDRLIMIT + struct rlimit rld; struct rlimit rld; +******** +# else # else +# ifdef HAVE_ULIMIT | # ifdef HAS_SYSVRLIMIT + char *hi; char *hi; +******** + usage = (long) (hi - enddata); usage = (long) (hi - enddata); + > # else + > # ifdef HAS_MEMAVL + > + > size_t mem_avail_now; + > mem_avail_now = _memavl( ); + > limit = mem_avail; + > usage = mem_avail - mem_avail_now; + > +# endif # endif +******** +#endif # endif + > #endif + fprintf(cp_out, "Current dyn fprintf(cp_out, "Current +dynamic memory usage = %ld,\n", usage); + fprintf(cp_out, "Dynamic mem fprintf(cp_out, "Dynamic +memory limit = %ld.\n", limit); + yy = TRUE; | yy = true; + } } +******** + if (!name || eq(name, "faults")) if (!name || eq(name, +"faults")) +#ifdef HAVE_GETRUSAGE | #ifdef HAS_BSDRUSAGE + struct rusage ruse; struct rusage ruse; +******** + ruse.ru_nvcsw + ruse ruse.ru_majflt, +ruse.ru_nvcsw, ruse.ru_nivcsw, + yy = TRUE; | yy = true; +#endif #endif +******** + (void) putc('\n', cp_out (void) putc('\n', +cp_out); + yy = TRUE; | yy = true; + } else if (v) { } else if (v) { +******** + } } + yy = TRUE; | yy = true; + } } +******** + + > #ifdef HAS_UNIX_SEGMENT_HACK + +******** +static void * static void * +baseaddr(void) | baseaddr( ) +{ { + char *low, *high, *at; char *low, *high, *at; + /* char *sbrk(int); */ | char *sbrk( ); + long x; long x; + RETSIGTYPE (*orig_signal)( ); | SIGNAL_TYPE (*orig_signal)( ); + +******** + << (LOG2_PAGESIZE - 1)); << (LOG2_PAGESIZE - 1)); + > # ifdef notdef + > at = (char *) ((((int) low + +(int) high) / 2 + 0x7ff) + > & ~(long) 0xfff); + > /* nearest page */ + > # endif + > # ifdef notdef + > printf( + > "high = %#8x low = %#8x at += %#8x\n", + > high, low, at); + > # endif + +******** + + > # ifdef notdef + > printf ("start is at %#x, end is +at %#x\n", high, sbrk(0)); + > # endif + (void) signal(SIGSEGV, (SIGNAL_FUNC (void) signal(SIGSEGV, +(SIGNAL_FUNCTION) orig_signal); +******** + + > #else + > + > static void * + > baseaddr( ) + > { + > return 0; + > } + > + > #endif + + +FILE: frontend/signal_handler.c + +******** + + | #ifdef WIN32 + | #include + > #endif + +******** + + > #ifdef WIN32 + > //extern pid_t _getpid (void); + > #else +extern pid_t getpid (void); extern pid_t getpid (void); + > #endif + + + +FILE: frontend/spec.c + +******** + for (i = 0; i #ifndef WIN32 +#include #include + > #endif + + + +FILE: frontend/parser/lexical.c + +******** + /* MW. Linux has TIOCSTI, so we inc /* MW. Linux has TIOCSTI, so we +inc + > #ifndef WIN32 +#include #include + > #endif + + + +FILE: frontend/parser/std.c + +******** +#include "cpstd.h" #include "cpstd.h" + | #include + > #include + +FILE: frontend/plotting/agraf.c + + +******** + +#include | #include <../frontend/variable.h> + + + +FILE: frontend/plotting/graf.c + + +******** +#include #include +#include | #include <../frontend/variable.h> + +******** + printf("%s", printf("%s", + getitright(buf, u->v_compdata[le | getitright(buf, +realpart(&u->v_compdata[len - 1]))); + printf(", %s", printf(", %s", + getitright(buf, u->v_compdat | getitright(buf, +imagpart(&u->v_compdata[len - 1]))); + } } + +******** + /* MW. Complex data again */ /* MW. Complex data again */ +printf("%s", getitright(buf, v | printf("%s", getitright(buf, +realpart(&v->v_compdata[len - 1]))); +printf(", %s", getitright(buf, | printf(", %s", getitright(buf, +imagpart(&v->v_compdata[len - 1]))); + } } + +FILE: frontend/plotting/plotcurv.c + + +******** +#include #include +#include | #include "..\variable.h" + + + +FILE: frontend/plotting/plotit.c + +******** + +#include | #include "../circuits.h" +#include | #include "../variable.h" + + + +FILE: frontend/plotting/pvec.c + +******** + default: default: + > break; + } } +******** + default: default: + > break; + } } + + +FILE: frontend/plotting/xgraph.c + + +******** + +#include | #include <../frontend/variable.h> + + + +FILE: /maths/cmaths/cmath2.c + +******** replace random with rand + k = floor(imagpart(&cc[i k = +floor(imagpart(&cc[i + realpart(&c[i]) = j ? random | realpart(&c[i]) = j +? rand + imagpart(&c[i]) = k ? random | imagpart(&c[i]) = k +? rand + } } +******** + j = floor(dd[i]); j = floor(dd[i]); + d[i] = j ? random() % j | d[i] = j ? rand() % j : + } } + + +FILE: /maths/cmaths/cmath4.c + +******** + +#include | #include +<../maths/poly/interpolate. +#include | #include <../maths/poly/polyfit.h> +#include | #include <../maths/poly/polyeval.h> +#include | #include +<../maths/poly/polyderiv.h> + + + +FILE: /maths/cmaths/test_cx_ph.c + +******** +#include "cmath1.h" #include "cmath1.h" + > #ifdef WIN32 + > #include "defines.h" + > #endif + + +FILE: /include/complex.h + +******** +/* Complex numbers. */ /* Complex numbers. */ + > + > + > #ifndef WIN32 + > +struct _complex { /* IBM portabili struct _complex { /* IBM +portabili +******** + + > #else + > #ifndef _COMPLEX_DEFINED + > // Jon changed this... 4/15/01 + > // Complex has been defined by MSVC +include, so don't redefine it. + > // if it hasn't, then define it the +same way as it's defined in vc + > // i.e., use x & y rather than +cx_real and cx_imag, and define + > // complex and _complex as the +same. + > struct _complex { /* IBM +portability*/ + > double x; + > double y; + > } ; + > #define _COMPLEX_DEFINED + > #endif // _COMPLEX_DEFINED + > // end of jon's change + > #endif + > +typedef struct _complex complex; typedef struct _complex complex; + + > #ifndef WIN32 +#define realpart(cval) ((struct _co #define realpart(cval) ((struct +_co ... +#define imagpart(cval) ((struct _co #define imagpart(cval) ((struct +_co ... + | #else + | #define realpart(cval) ((struct +_complex *) (cval))->x + > #define imagpart(cval) ((struct _ +complex *) (cval))->y + > #endif +/* /* + + +FILE: /include/config.h + + > #ifndef CONFIG_H + > #define CONFIG_H + > + > # include "os_win32.h" // add to +project + > #define SIMULATOR +#ifdef HAS_NOVM #ifdef HAS_NOVM +******** +#endif #endif + > + > #endif CONFIG_H + + +FILE: /include/defines.h + +******** + + | // Jon's change, otherwise +conflict. + > #ifndef WIN32_H +#define DIR_PATHSEP "/" #define DIR_PATHSEP "/" +******** +#define DIR_CWD "." #define DIR_CWD "." + > #define TEMPFORMAT "/tmp/%s%d" + > #endif + +#define TEMPFORMAT "/tmp/%s%d" < +#define SYSTEM_PLOT5LPR "lpr -P%s -g #define SYSTEM_PLOT5LPR +"lpr -P%s -g %s" +******** +#define HAS_TIME_ #define HAS_TIME_ + > + > #ifndef WIN32 +#define HAS_RLIMIT_ #define HAS_RLIMIT_ + | #endif + +******** + +#define DIR_PATHSEP "/" < +#define DIR_TERM '/' < +#define DIR_CWD "." < + < +#define TEMPFORMAT "/tmp/%s%d" < +#define SYSTEM_PLOT5LPR "lpr -P%s -g < +#define SYSTEM_PSLPR "lpr -P%s %s" < +#define SYSTEM_MAIL "Mail -s \"%s (% < + + + +FILE: /include/terminal.h + + > #ifndef WIN32 +#include "../misc/terminal.h" #include "../misc/terminal.h" + > #endif + +FILE: misc/ivars.c + +******** + buffer = getenv(env_var); buffer = getenv(env_var); + > #ifndef WIN32 + if (buffer) if (buffer) +******** + asprintf(p, "%s%s%s", path_prefix, asprintf(p, "%s%s%s", path_prefix, + > #endif +} } + + +FILE: spicelib/analysis/cktdisto.c + +******** +#include "devdefs.h" #include "devdefs.h" +#include "vsrc/vsrcdefs.h" | #include +"../devices/vsrc/vsrcdefs.h" +#include "isrc/isrcdefs.h" | #include +"../devices/isrc/isrcdefs.h" +#include "iferrmsg.h" #include "iferrmsg.h" + + +FILE: spicelib/analysis/ckttroub.c + +******** +#include "devdefs.h" #include "devdefs.h" +#include "vsrc/vsrcdefs.h" | #include +"../devices/vsrc/vsrcdefs.h" +#include "isrc/isrcdefs.h" | #include +"../devices/isrc/isrcdefs.h" +#include "jobdefs.h" #include "jobdefs.h" + + +FILE: spicelib/analysis/dctran.c + +******** +#include #include +#include | #include "../devices/cktaccept.h" +#include #include + + +FILE: spicelib/analysis/dctrcurv.c + +******** + +#include "vsrc/vsrcdefs.h" | #include +"../devices/vsrc/vsrcdefs.h" +#include "isrc/isrcdefs.h" | #include +"../devices/isrc/isrcdefs.h" +#include "res/resdefs.h" | #include "../devices/res/resdefs.h" + + + +FILE: spicelib/analysis/noisean.c + +******** +#include "sperror.h" #include "sperror.h" +#include "vsrc/vsrcdefs.h" | #include +"../devices/vsrc/vsrcdefs.h" +#include "isrc/isrcdefs.h" | #include +"../devices/isrc/isrcdefs.h" + + +FILE: spicelib/devices/asrc/asrcinit.c +******** + > #ifndef WIN32 + DEVparam : ASRCparam, DEVparam : ASRCparam, +******** + DEVmodSize : &ASRCmSize DEVmodSize : &ASRCmSize + > #else + > ASRCparam, + > NULL, + > ASRCload, + > ASRCsetup, + > ASRCunsetup, + > ASRCsetup, + > NULL, + > NULL, + > ASRCfindBr, + > ASRCacLoad, /* ac and normal + > NULL, + > ASRCdestroy, + > ASRCmDelete, + > ASRCdelete, + > NULL, + > NULL, + > NULL, + > ASRCpzLoad, + > ASRCconvTest, + > NULL, + > NULL, + > NULL, + > NULL, + > NULL, + > NULL, + > NULL, /* DISTO */ + > NULL, /* NOISE */ + > + > &ASRCiSize, + > &ASRCmSize + > #endif +}; }; + +****************************** +**** the same changes for all other device init routines. +****************************** + +FILE: spicelib/parser/ifnewuid.c + +******** +#include #include +#include | #include "../frontend/circuits.h" +#include #include +******** + + > #ifndef WIN32 + if (olduid) { if (olduid) { +******** + } } + | #endif + switch (type) { switch (type) { + + +FILE: spicelib/parser/inperror.c + +******** + + > #ifndef WIN32 + if (errRtn) if (errRtn) +******** + asprintf(&ebuf, "%s\n", val); asprintf(&ebuf, "%s\n", val); + | #endif + return ebuf; return ebuf; + + + +**************************************************************************** +***************** +FILE: include/OS_WIN32.H +/* + * Win32... + */ + +/* + * MS-DOS + */ +#define DIR_CWD "." +#define DIR_PATHSEP "\\" +#define DIR_TERM '\\' +#define TEMPFORMAT "%s%d.tmp" + +/* ----- System capabilities */ +#define HAS_FLAT_INCLUDES +//#define HAS_QUICKDRAW +//#define HAS_MACCLOCK +//#define HAS_LOCALTIME +//#define HAS_NO_ERFC + +#define FTEDEBUG /* Enable general debugging */ +#define CPDEBUG /* Enable cshpar debugging */ +#define CAPZEROBYPASS +#define NEWCONV +//#define HAS_MAC_ARGCARGV +#define HAS_ASCII +#define HAS_CHDIR /* for tree filesystems, chdir( ) */ +#define HAS_CLEARERR /* clearerr( ), should be in stdio */ +#define HAS_CTYPE /* , iswhite( ), etc. */ +#define HAS_DOSDIRS /* Emulate opendir, etc. */ +//#define HAS_MEMAVL /*_memavl( ) not available in Win32 console mode. */ +#define HAS_ENVIRON +#define HAS_FTIME +#define HAS_GETCWD /* getcwd(buf, size) */ +#define HAS_LOCALTIME +#define HAS_LONGJUMP /* setjmp( ), longjmp( ) */ +// #define HAS_MINDATA // only needed for MS-DOS +// #define HAS_NOINLINE // only needed for MS-DOS +// #define HAS_NOVM // only needed for MS-DOS +#define HAS_PCTERM +#define HAS_QSORT /* qsort( ) */ +#define HAS_SHORTMACRO +#define HAS_STAT +#define HAS_STDLIB +#define HAS_STRCHR /* strchr( ) instead of index( ) */ +#define HAS_SYSTEM +#define HAS_UNIX_SIGS +#define HAS_UNLINK +#define HAS_LIMITS_H +#define HAS_FLOAT_H +#define HAS_NO_IEEE_LOGB +#define HAS_NO_ERFC +#define HAS_BATCHSIM + +#define WANT_PCHARDCOPY +#define WANT_MFB + +// from Mac world?? +#define SIMULATOR /* There should be a better way */ + +********************************** + + +Jon Engelbert +President, Beige Bag Software +279 E. Liberty, Ann Arbor, MI 48105 +jon@beigebag.com + + diff --git a/patches/win32/resource.c b/patches/win32/resource.c new file mode 100644 index 000000000..932bae4c8 --- /dev/null +++ b/patches/win32/resource.c @@ -0,0 +1,444 @@ +/********** +Copyright 1990 Regents of the University of California. All rights reserved. +Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group +**********/ + +/* + * Resource-related routines. + */ + +#include +#include "ngspice.h" +#include "cpdefs.h" +#include "ftedefs.h" + +#include "circuits.h" +#include "quote.h" +#include "resource.h" +#include "variable.h" + +#include + +#ifdef HAS_BSDRLIMIT +# include +# include +#endif +#ifdef HAS_BSDRUSAGE +# ifndef HAS_BSDRLIMIT +# include +# include +# endif +#else +# ifdef HAS_SYSVRUSAGE +# include +# include +# else +# ifdef HAS_FTIME +# include +struct timeb timebegin; +# endif +# endif +#endif + +/* static declarations */ +static void printres(char *name); +static RETSIGTYPE fault(void); +static void * baseaddr(void); + +#ifdef HAS_RLIMIT_ +# ifdef HAS_MEMAVL +size_t mem_avail; +# else +char *startdata; +char *enddata; +# endif +#endif + + +void +init_rlimits(void) +{ +#ifdef HAS_RLIMIT_ +# ifdef HAS_MEMAVL + mem_avail = _memavl( ); +# else + startdata = (char *) baseaddr( ); + enddata = sbrk(0); +# endif +#endif +} + +void +init_time(void) +{ + +#ifdef HAVE_GETRUSAGE +#else +# ifdef HAVE_TIMES +# else +# ifdef HAVE_FTIME + ftime(&timebegin); +# endif +# endif +#endif + +} + + +void +com_rusage(wordlist *wl) +{ +char* copyword; + /* Fill in the SPICE accounting structure... */ + + if (wl && (eq(wl->wl_word, "everything") || eq(wl->wl_word, "all"))) { + printres((char *) NULL); + } else if (wl) { + for (; wl; wl = wl->wl_next) { + /* printres(cp_unquote(wl->wl_word)); DG: bad, memory leak*/ + copyword=cp_unquote(wl->wl_word);/*DG*/ + printres(copyword); + tfree(copyword); + if (wl->wl_next) + (void) putc('\n', cp_out); + } + } else { + printres("cputime"); + (void) putc('\n', cp_out); + printres("totalcputime"); + (void) putc('\n', cp_out); + printres("space"); + } + return; +} + +/* Find out if the user is approaching his maximum data size. */ + +void +ft_ckspace(void) +{ +#ifdef HAS_RLIMIT_ + long usage, limit; + static long old_usage = 0; + +# ifdef HAS_MEMAVL + + size_t mem_avail_now; + + mem_avail_now = _memavl( ); + usage = mem_avail - mem_avail_now; + limit = mem_avail; + +# else + + char *hi; + +# ifdef HAS_BSDRLIMIT + + struct rlimit rld; + getrlimit(RLIMIT_DATA, &rld); + if (rld.rlim_cur == RLIM_INFINITY) + return; + limit = rld.rlim_cur - (enddata - startdata); /* rlim_max not used */ + +# else + + /* SYSVRLIMIT */ + limit = ulimit(3, 0L) - (enddata - startdata); + +# endif + + usage = sbrk(0) - enddata; + +# endif + + if (limit < 0) + return; /* what else do you do? */ + + if (usage <= old_usage) + return; + + old_usage = usage; + + if (usage > limit * 0.9) { + fprintf(cp_err, "Warning - approaching max data size: "); + fprintf(cp_err, "current size = %ld, limit = %ld.\n", usage, limit); + } + +#endif + return; +} + +/* Print out one piece of resource usage information. */ + + +static void +printres(name) + char *name; +{ + bool yy = false; + static long lastsec = 0, lastusec = 0; + struct variable *v; + long realt; + char *cpu_elapsed; + + if (!name || eq(name, "totalcputime") || eq(name, "cputime")) { + int total, totalu; + +#ifdef ipsc +# define NO_RUDATA +#else + +# ifdef HAS_BSDRUSAGE + struct rusage ruse; + (void) getrusage(RUSAGE_SELF, &ruse); + total = ruse.ru_utime.tv_sec + ruse.ru_stime.tv_sec; + totalu = (ruse.ru_utime.tv_usec + ruse.ru_stime.tv_usec) / 1000; + cpu_elapsed = "CPU"; +# else +# ifdef HAS_SYSVRUSAGE + struct tms ruse; + realt = times(&ruse); + total = (ruse.tms_utime + ruse.tms_stime)/ HZ; + totalu = (ruse.tms_utime + ruse.tms_utime) * 1000 / HZ; + cpu_elapsed = "CPU"; +# else +# ifdef HAS_FTIME + struct timeb timenow; + int sec, msec; + ftime(&timenow); + timediff(&timenow, &timebegin, &total, &totalu); + totalu /= 1000; + cpu_elapsed = "elapsed"; +# else +# define NO_RUDATA +# endif +# endif +# endif +#endif + + +#ifndef NO_RUDATA + if (!name || eq(name, "totalcputime")) { + total += totalu / 1000; + totalu %= 1000; + fprintf(cp_out, "Total %s time: %lu.%03lu seconds.\n", + cpu_elapsed, total, totalu); + } + + if (!name || eq(name, "cputime")) { + lastusec = totalu - lastusec; + lastsec = total - lastsec; + while (lastusec < 0) { + lastusec += 1000; + lastsec -= 1; + } + while (lastusec > 1000) { + lastusec -= 1000; + lastsec += 1; + } + + out_printf("%s time since last call: %lu.%03lu seconds.\n", + cpu_elapsed, lastsec, lastusec); + + lastsec = total; + lastusec = totalu; + } + + yy = true; +#else + if (!name || eq(name, "totalcputime")) + fprintf(cp_out, "Total CPU time: ??.??? seconds.\n"); + if (!name || eq(name, "cputime")) + fprintf(cp_out, "CPU time since last call: ??.??? seconds.\n"); + yy = true; +#endif + + } + + if (!name || eq(name, "space")) { + long usage = 0, limit = 0; +#ifdef ipsc + NXINFO cur = nxinfo, start = nxinfo_snap; + + usage = cur.dataend - cur.datastart; + limit = start.availmem; +#else +# ifdef HAS_BSDRLIMIT + struct rlimit rld; + char *hi; + + getrlimit(RLIMIT_DATA, &rld); + limit = rld.rlim_cur - (enddata - startdata); + hi = sbrk(0); + usage = (long) (hi - enddata); +# else +# ifdef HAS_SYSVRLIMIT + char *hi; + + limit = ulimit(3, 0L) - (enddata - startdata); + hi = sbrk(0); + usage = (long) (hi - enddata); +# else +# ifdef HAS_MEMAVL + + size_t mem_avail_now; + mem_avail_now = _memavl( ); + limit = mem_avail; + usage = mem_avail - mem_avail_now; + +# endif +# endif +# endif +#endif + fprintf(cp_out, "Current dynamic memory usage = %ld,\n", usage); + fprintf(cp_out, "Dynamic memory limit = %ld.\n", limit); + yy = true; + } + + if (!name || eq(name, "faults")) { +#ifdef HAS_BSDRUSAGE + struct rusage ruse; + + (void) getrusage(RUSAGE_SELF, &ruse); + fprintf(cp_out, + "%lu page faults, %lu vol + %lu invol = %lu context switches.\n", + ruse.ru_majflt, ruse.ru_nvcsw, ruse.ru_nivcsw, + ruse.ru_nvcsw + ruse.ru_nivcsw); + yy = true; +#endif + } + + /* Now get all the spice resource stuff. */ + if (ft_curckt && ft_curckt->ci_ckt) { + if (name && eq(name, "task")) + v = if_getstat(ft_curckt->ci_ckt, NULL); + else + v = if_getstat(ft_curckt->ci_ckt, name); + if (name && v) { + fprintf(cp_out, "%s = ", v->va_name); + wl_print(cp_varwl(v), cp_out); + (void) putc('\n', cp_out); + yy = true; + } else if (v) { + (void) putc('\n', cp_out); + while (v) { + fprintf(cp_out, "%s = ", v->va_name); + wl_print(cp_varwl(v), cp_out); + (void) putc('\n', cp_out); + v = v->va_next; + } + yy = true; + } + } + + if (!yy) { + fprintf(cp_err, "Note: no resource usage information for '%s',\n", + name); + fprintf(cp_err, "\tor no active circuit available\n"); + + } + return; +} + +#ifdef HAS_UNIX_SEGMENT_HACK + +#include +#include + +/* + * baseaddr( ) returns the base address of the data segment on most Unix + * systems. It's an ugly hack for info that should be provided by the OS. + */ + +/* Does anyone use a pagesize < 256 bytes?? I'll bet not; + * too small doesn't hurt + */ + +#define LOG2_PAGESIZE 8 + +static jmp_buf env; + +static RETSIGTYPE +fault(void) +{ + signal(SIGSEGV, (SIGNAL_FUNCTION) fault); /* SysV style */ + longjmp(env, 1); +} + +static void * +baseaddr( ) +{ + char *low, *high, *at; + char *sbrk( ); + long x; + SIGNAL_TYPE (*orig_signal)( ); + + if (getenv("SPICE_NO_DATASEG_CHECK")) + return 0; + + low = 0; + high = (char *) ((unsigned long) sbrk(0) & ~((1 << LOG2_PAGESIZE) - 1)); + + orig_signal = signal(SIGSEGV, (SIGNAL_FUNCTION) fault); + + do { + + at = (char *) ((((long)low >> LOG2_PAGESIZE) + + ((long)high >> LOG2_PAGESIZE)) + << (LOG2_PAGESIZE - 1)); +# ifdef notdef + at = (char *) ((((int) low + (int) high) / 2 + 0x7ff) + & ~(long) 0xfff); + /* nearest page */ +# endif +# ifdef notdef + printf( + "high = %#8x low = %#8x at = %#8x\n", + high, low, at); +# endif + + if (at == low || at == high) { + break; + } + + if (setjmp(env)) { + low = at; + continue; + } else + x = *at; + + if (setjmp(env)) { + low = at; + continue; + } else + *at = x; + + high = at; + + } while (1); + +# ifdef notdef + printf ("start is at %#x, end is at %#x\n", high, sbrk(0)); +# endif + (void) signal(SIGSEGV, (SIGNAL_FUNCTION) orig_signal); + return (void *) high; +} + +# ifdef notdef +main( ) +{ + printf("testing\n"); + printf("baseaddr: %#8x topaddr: %#8x\n", baseaddr( ), sbrk(0)); +} +# endif + +#else + +static void * +baseaddr( ) +{ + return 0; +} + +#endif