1 /*$Id: md.h,v 26.138 2013/04/24 02:32:27 al Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
4 *
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
6 *
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)
10 * any later version.
11 *
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.
16 *
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
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * Machine dependent, configuration, and standard includes
23 */
24 //testing=trivial 2006.07.17
25 #ifndef MD_H_INCLUDED
26 #define MD_H_INCLUDED
27 /*--------------------------------------------------------------------------*/
28 /* autoconf stuff */
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 /*--------------------------------------------------------------------------*/
33 /* std collection of includes */
34 // system
35 #include <new>
36 #include <cstdarg>
37 #include <cassert>
38 #include <cfloat>
39 #include <cmath>
40 #include <climits>
41 #include <limits>
42 #include <cstdio>
43 #include <cerrno>
44 #include <csetjmp>
45 #include <csignal>
46 #include <cstring>
47 #include <iostream>
48 #include <ctime>
49 // types
50 #include <complex>
51 #include <string>
52 // containers
53 #include <list>
54 #include <vector>
55 #include <queue>
56 #include <map>
57 #include <valarray>
58 // algorithms
59 #include <typeinfo>
60 #include <algorithm>
61 /* usual but non-standard (POSIX??) collection of includes */
62 #include <unistd.h> /* chdir, access, getcwd */
63 #include <fcntl.h> /* old style unix files */
64 /*--------------------------------------------------------------------------*/
65 /* constants related to memory size, word size, etc */
66 enum {
67 BUFLEN = 256,
68 BIGBUFLEN = 4096
69 };
70 /*--------------------------------------------------------------------------*/
71 /* user interface preferences */
72 #define I_PROMPT "gnucap> "
73 #define CKT_PROMPT ">"
74 #define ANTI_COMMENT "*>"
75 #define DEFAULT_LANGUAGE "acs"
76 /*--------------------------------------------------------------------------*/
77 #if defined(__WIN32__)
78 #define ENDDIR "/\\"
79 #define PATHSEP ';'
80 #define DEFAULT_PLUGINS "libgnucap-default-plugins.dll"
81 #define SYSTEMSTARTFILE "gnucap.rc"
82 #define SYSTEMSTARTPATH OS::getenv("PATH")
83 #define USERSTARTFILE "gnucap.rc"
84 #define USERSTARTPATH OS::getenv("HOME")
85 #define STEPFILE "/tmp/SXXXXXX"
86 #define SHELL OS::getenv("COMSPEC")
87 /*--------------------------------------------------------------------------*/
88 #else
89 #define ENDDIR "/"
90 #define PATHSEP ':'
91 #define DEFAULT_PLUGINS "libgnucap-default-plugins.so"
92 #define SYSTEMSTARTFILE "gnucap.rc"
93 #define SYSTEMSTARTPATH OS::getenv("PATH")
94 #define USERSTARTFILE ".gnucaprc"
95 #define USERSTARTPATH OS::getenv("HOME")
96 #define STEPFILE "/tmp/SXXXXXX"
97 #define SHELL OS::getenv("SHELL")
98 #endif
99 /*--------------------------------------------------------------------------*/
100 /* machine and compiler patches */
101 #if defined(__MINGW32__)
102 #define SIGSETJMP_IS_BROKEN
103 #define MS_DLL
104 #endif
105 /*--------------------------------------------------------------------------*/
106 /* some convenient names */
107 typedef std::complex<double> COMPLEX;
108 typedef std::pair<double,double> DPAIR;
109 /*--------------------------------------------------------------------------*/
110 // dynamic cast kluge.
111 // Strictly, this should always be dynamic_cast, but if it has already
112 // been checked, don't bother checking again, hence static_cast.
113 // It works and is faster.
114 #if defined(NDEBUG)
115 #define prechecked_cast static_cast
116 #else
117 #define prechecked_cast dynamic_cast
118 #endif
119
120 /*--------------------------------------------------------------------------*/
121 /* portability hacks */
122
123 #if !defined(MS_DLL)
124 // The usual way for POSIX compliant systems
125 #include <dlfcn.h>
126 #define INTERFACE
127 #else
128 // Microsoft DLL hacks -- thanks to Holger Vogt and Cesar Strauss for the info
129 // Make the MS DLL functions look like the posix ones.
130 #include <windows.h>
131 #undef min
132 #undef max
133 #undef INTERFACE
134 #ifdef MAKE_DLL
135 #define INTERFACE __declspec(dllimport)
136 #else
137 #define INTERFACE __declspec(dllexport)
138 #endif
139
dlopen(const char * f,int)140 inline void* dlopen(const char* f, int)
141 {
142 return LoadLibrary(const_cast<char*>(f));
143 }
144
dlclose(void * h)145 inline void dlclose(void* h)
146 {
147 FreeLibrary((HINSTANCE)h);
148 }
149
dlerror()150 inline char* dlerror()
151 {
152 static LPVOID lpMsgBuf = NULL;
153 // free the error message buffer
154 if (lpMsgBuf) {
155 LocalFree(lpMsgBuf);
156 }
157 // get the error code
158 DWORD dw = GetLastError();
159 // get the corresponding error message
160 FormatMessage(
161 FORMAT_MESSAGE_ALLOCATE_BUFFER |
162 FORMAT_MESSAGE_FROM_SYSTEM |
163 FORMAT_MESSAGE_IGNORE_INSERTS,
164 NULL,
165 dw,
166 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
167 (LPTSTR) &lpMsgBuf,
168 0, NULL);
169 return (char*)lpMsgBuf;
170 }
171 #define RTLD_LAZY 0x00001 /* Lazy function call binding. */
172 #define RTLD_NOW 0x00002 /* Immediate function call binding. */
173 #define RTLD_BINDING_MASK 0x3 /* Mask of binding time value. */
174 #define RTLD_NOLOAD 0x00004 /* Do not load the object. */
175 #define RTLD_DEEPBIND 0x00008 /* Use deep binding. */
176 #define RTLD_GLOBAL 0x00100
177 #define RTLD_LOCAL 0
178 #define RTLD_NODELETE 0x01000
179 #endif
180
181 #if defined(SIGSETJMP_IS_BROKEN)
182 #undef sigjmp_buf
183 #undef siglongjmp
184 #undef sigsetjmp
185 #define sigjmp_buf jmp_buf
186 #define siglongjmp(a,b) longjmp(a,b)
187 #define sigsetjmp(a,b) setjmp(a)
188 #endif
189
190 #if !defined(SIGNALARGS)
191 #define SIGNALARGS int
192 #endif
193 /*--------------------------------------------------------------------------*/
194 /* temporary hacks */
195 enum RUN_MODE {
196 rPRE_MAIN, /* it hasn't got to main yet */
197 rPRESET, /* do set up commands now, but not simulation */
198 /* store parameters, so bare invocation of a */
199 /* simulation command will do it this way. */
200 rINTERACTIVE, /* run the commands, interactively */
201 rSCRIPT, /* execute now, as a command, then restore mode */
202 rBATCH /* execute now, as a command, then exit */
203 };
204 class INTERFACE ENV {
205 public:
206 static RUN_MODE run_mode; // variations on handling of dot commands
207 };
208 /*--------------------------------------------------------------------------*/
209 /* my standard collection of includes */
210 #include "io_trace.h"
211 #include "io_error.h"
212 /*--------------------------------------------------------------------------*/
213 /*--------------------------------------------------------------------------*/
214 #endif
215