2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
22 * Machine dependent, configuration, and standard includes
26 /*--------------------------------------------------------------------------*/
27 // float type to use for currents, voltages & stuff
28 // typedef double double; // has to be double
29 //typedef long double hp_float_t;
30 #define HAVE_DOUBLE_TYPES
31 typedef double voltage_t
;
32 typedef double current_t
;
33 typedef double charge_t
;
34 typedef double conductance_t
;
35 typedef double hp_float_t
;
37 typedef unsigned int uint_t
;
38 /*--------------------------------------------------------------------------*/
39 // some functions are not const in upstream yet.
40 #define GCUF_CONST const
41 /*--------------------------------------------------------------------------*/
44 inline double to_fun_t(double x
){return x
;}
45 /*--------------------------------------------------------------------------*/
46 /* std collection of includes */
73 /* usual but non-standard (POSIX??) collection of includes */
74 #include <unistd.h> /* chdir, access, getcwd */
75 #include <fcntl.h> /* old style unix files */
76 /*--------------------------------------------------------------------------*/
77 /* constants related to memory size, word size, etc */
82 /*--------------------------------------------------------------------------*/
83 /* user interface preferences */
84 #define I_PROMPT "gnucap> "
85 #define CKT_PROMPT ">"
86 #define ANTI_COMMENT "*>"
87 #define DEFAULT_LANGUAGE "acs"
88 /*--------------------------------------------------------------------------*/
89 #if defined(__WIN32__)
92 #define SYSTEMSTARTFILE "gnucap.rc"
93 #define SYSTEMSTARTPATH OS::getenv("PATH")
94 #define CWDSTARTFILE "gnucap.rc"
95 #define USERSTARTFILE "gnucap.rc"
96 #define USERSTARTPATH OS::getenv("HOME")
97 #define STEPFILE "/tmp/SXXXXXX"
98 #define SHELL OS::getenv("COMSPEC")
99 /*--------------------------------------------------------------------------*/
103 #define SYSTEMSTARTFILE "gnucap.rc"
104 #define SYSTEMSTARTPATH "/etc"
105 #define CWDSTARTFILE "gnucap.rc"
106 #define USERSTARTFILE ".gnucaprc"
107 #define USERSTARTPATH OS::getenv("HOME")
108 #define STEPFILE "/tmp/SXXXXXX"
109 #define SHELL OS::getenv("SHELL")
111 /*--------------------------------------------------------------------------*/
113 // for pointer hashing.
115 /*--------------------------------------------------------------------------*/
116 /* machine and compiler patches */
117 #if defined(__MINGW32__)
118 #define SIGSETJMP_IS_BROKEN
121 /*--------------------------------------------------------------------------*/
122 /* some convenient names */
123 typedef std::complex<hp_float_t
> hCOMPLEX
;
124 typedef std::pair
<hp_float_t
,hp_float_t
> hDPAIR
;
128 typedef std::complex<double> COMPLEX
;
129 typedef std::pair
<double,double> DPAIR
;
130 const double inf
= std::numeric_limits
<float>::infinity( );
131 /*--------------------------------------------------------------------------*/
132 // dynamic cast kluge.
133 // Strictly, this should always be dynamic_cast, but if it has already
134 // been checked, don't bother checking again, hence static_cast.
135 // It works and is faster.
137 #define prechecked_cast static_cast
139 #define prechecked_cast dynamic_cast
143 template <class T
, class S
>
144 inline T
asserted_cast(S s
){
145 T x
= prechecked_cast
<T
>(s
);
150 /*--------------------------------------------------------------------------*/
151 /* portability hacks */
154 // The usual way for POSIX compliant systems
158 // Microsoft DLL hacks -- thanks to Holger Vogt and Cesar Strauss for the info
159 // Make the MS DLL functions look like the posix ones.
165 #define INTERFACE __declspec(dllimport)
167 #define INTERFACE __declspec(dllexport)
170 inline void* dlopen(const char* f
, int)
172 trace0("Loadlibrary wrapper");
173 return LoadLibrary(const_cast<char*>(f
));
176 inline void dlclose(void* h
)
178 FreeLibrary((HINSTANCE
)h
);
181 inline char* dlerror()
183 static LPVOID lpMsgBuf
= NULL
;
184 // free the error message buffer
188 // get the error code
189 DWORD dw
= GetLastError();
190 // get the corresponding error message
192 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
193 FORMAT_MESSAGE_FROM_SYSTEM
|
194 FORMAT_MESSAGE_IGNORE_INSERTS
,
197 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
200 return (char*)lpMsgBuf
;
202 #define RTLD_LAZY 0x00001 /* Lazy function call binding. */
203 #define RTLD_NOW 0x00002 /* Immediate function call binding. */
204 #define RTLD_BINDING_MASK 0x3 /* Mask of binding time value. */
205 #define RTLD_NOLOAD 0x00004 /* Do not load the object. */
206 #define RTLD_DEEPBIND 0x00008 /* Use deep binding. */
207 #define RTLD_GLOBAL 0x00100
209 #define RTLD_NODELETE 0x01000
212 #if defined(SIGSETJMP_IS_BROKEN)
216 #define sigjmp_buf jmp_buf
217 #define siglongjmp(a,b) longjmp(a,b)
218 #define sigsetjmp(a,b) setjmp(a)
221 #if !defined(SIGNALARGS)
222 #define SIGNALARGS int
224 /*--------------------------------------------------------------------------*/
225 /* temporary hacks */
227 rPRE_MAIN
, /* it hasn't got to main yet */
228 rPRESET
, /* do set up commands now, but not simulation */
229 /* store parameters, so bare invocation of a */
230 /* simulation command will do it this way. */
231 rINTERACTIVE
, /* run the commands, interactively */
232 rSCRIPT
, /* execute now, as a command, then restore mode */
233 rBATCH
, /* execute now, as a command, then exit */
234 rPIPE
// unbuffered, like script.
236 class INTERFACE ENV
{
238 static RUN_MODE run_mode
; // variations on handling of dot commands
239 static int error
; // error return code
241 /*--------------------------------------------------------------------------*/
242 /* my standard collection of includes */
243 #include "io_trace.h"
244 #include "io_error.h"
245 /*--------------------------------------------------------------------------*/
249 /*--------------------------------------------------------------------------*/
250 inline double fmin(double x
, double y
, double z
){
251 return ( fmin(fmin(x
,y
),z
));
253 inline double fmax(double x
, double y
, double z
){
254 return ( fmax(fmax(x
,y
),z
));
256 #define HAVE_IS_NUMBER
257 inline bool is_number(long double x
){
258 return (( x
!= inf
) && (x
!= -inf
) && (x
== x
)) ;
260 inline bool is_number(double x
){
261 return (( x
!= inf
) && (x
!= -inf
) && (x
== x
)) ;
263 inline bool is_almost(double x
, double y
){
264 return ( fabs(x
-y
) / ( fmax(fabs(x
),fabs(y
))+1e-20) < 1e-10 || fabs(x
-y
)<1e-12);
266 inline double square(double x
){return x
*x
;}
267 inline long double square(long double x
){return x
*x
;}
268 /*--------------------------------------------------------------------------*/
270 // vim:ts=8:sw=2:noet: