---------- 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