1 /* HERCWIND.H (c) Copyright Roger Bowler, 2005-2009 */
2 /* MSVC Environment Specific Definitions */
3
4 /*-------------------------------------------------------------------*/
5 /* Header file containing additional data structures and function */
6 /* prototypes required by Hercules in the MSVC environment */
7 /*-------------------------------------------------------------------*/
8
9 #if !defined(_HERCWIND_H)
10 #define _HERCWIND_H
11
12 // PROGRAMMING NOTE: Cygwin has a bug in setvbuf requiring us
13 // to do an 'fflush()' after each stdout/err write, and it doesn't
14 // hurt doing it for the MSVC build either...
15 #define NEED_LOGMSG_FFLUSH
16
17 #if !defined( _MSVC_ )
18 #error This file is only for building Hercules with MSVC
19 #endif
20
21 #if defined( _MSC_VER ) && (_MSC_VER < 1300)
22 #error MSVC compiler versions less than 13.0 not supported.
23 #endif
24
25 #pragma intrinsic( memset, memcmp, memcpy )
26
27 ///////////////////////////////////////////////////////////////////////
28 // The following is mostly for issuing "warning" messages since MS's
29 // compiler doesn't support #warning. Instead, we must use #pragma
30 // message as follows:
31 //
32 // #pragma message( MSVC_MESSAGE_LINENUM "blah, blah..." )
33 //
34 // which results in:
35 //
36 // foobar.c(123) : blah, blah...
37 //
38 // which is really handy when using their Visual Studio IDE since
39 // it allows us to quickly jump to that specific source statement
40 // with just the press of a function key...
41
42 #if !defined( MSVC_MESSAGE_LINENUM )
43 #define MSVC_STRINGIZE( L ) #L
44 #define MSVC_MAKESTRING( M, L ) M( L )
45 #define MSVC_QUOTED_LINENUM MSVC_MAKESTRING( MSVC_STRINGIZE, __LINE__ )
46 #define MSVC_MESSAGE_LINENUM __FILE__ "(" MSVC_QUOTED_LINENUM ") : "
47 #endif
48
49 ///////////////////////////////////////////////////////////////////////
50 // Disable some warnings that tend to get in the way...
51 //
52 // FIXME: purposely disabling warning C4244 is dangerous IMO and might
53 // come back to haunt us in the future when we DO happen to introduce
54 // an unintentional coding error that results in unexpected data loss.
55 //
56 // We should instead take the time to fix all places where it's issued
57 // (being sure to add comments when we do) so that we can then rely on
58 // C4244 to warn us of real/actual coding errors. - Fish, April 2006
59
60 #pragma warning( disable: 4142 ) // C4142: benign redefinition of type
61 #pragma warning( disable: 4244 ) // C4244: conversion from 'type' to 'type', possible loss of data
62
63 ///////////////////////////////////////////////////////////////////////
64
65 #ifdef _MAX_PATH
66 #define PATH_MAX _MAX_PATH
67 #else
68 #ifdef FILENAME_MAX
69 #define PATH_MAX FILENAME_MAX
70 #else
71 #define PATH_MAX 260
72 #endif
73 #endif
74
75 struct dirent {
76 long d_ino;
77 char d_name[FILENAME_MAX + 1];
78 };
79
80 typedef unsigned __int32 in_addr_t;
81 typedef unsigned char u_char;
82 typedef unsigned int u_int;
83 typedef unsigned long u_long;
84 typedef unsigned __int8 u_int8_t;
85 typedef unsigned __int16 u_int16_t;
86 typedef unsigned __int32 u_int32_t;
87 typedef unsigned __int64 u_int64_t;
88 typedef signed __int8 int8_t;
89 typedef signed __int16 int16_t;
90 typedef signed __int32 int32_t;
91 typedef signed __int64 int64_t;
92 typedef int ssize_t;
93 typedef int pid_t;
94 typedef int mode_t;
95
96 #include <io.h>
97 #include <share.h>
98 #include <process.h>
99 #include <signal.h>
100 #include <direct.h>
101
102 #define STDIN_FILENO fileno(stdin)
103 #define STDOUT_FILENO fileno(stdout)
104 #define STDERR_FILENO fileno(stderr)
105
106 /* Bit settings for open() and stat() functions */
107 #define S_IRUSR _S_IREAD
108 #define S_IWUSR _S_IWRITE
109 #define S_IRGRP _S_IREAD
110 #define S_IROTH _S_IREAD
111 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
112 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
113 #define S_ISCHR(m) (((m) & _S_IFMT) == _S_IFCHR)
114 #define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
115
116 /* Bit settings for access() function */
117 #define F_OK 0
118 #define W_OK 2
119 #define R_OK 4
120
121 #define hopen w32_hopen
122
123 #define strcasecmp stricmp
124 #define strncasecmp strnicmp
125
126 #define snprintf _snprintf
127 #define vsnprintf _vsnprintf
128 #define strerror w32_strerror
129 #define strerror_r w32_strerror_r
130
131 #define srandom srand
132 #define random rand
133
134 #define inline __inline
135 #define __inline__ __inline
136
137 #define HAVE_STRUCT_IN_ADDR_S_ADDR
138 #define HAVE_U_INT
139 #define HAVE_U_INT8_T
140 #define HAVE_LIBMSVCRT
141 #define HAVE_SYS_MTIO_H // (ours is called 'w32mtio.h')
142
143 #ifndef MAX_CPU_ENGINES
144 #define MAX_CPU_ENGINES 8
145 #endif
146
147 #define OPTION_CONFIG_SYMBOLS
148 #define OPTION_ENHANCED_CONFIG_SYMBOLS
149 #define OPTION_ENHANCED_CONFIG_INCLUDE
150 #define OPTION_FTHREADS
151 #define HAVE_STRSIGNAL
152 #define EXTERNALGUI
153 #define NO_SETUID
154 #define NO_SIGABEND_HANDLER
155
156 #undef NO_ATTR_REGPARM // ( ATTR_REGPARM(x) == __fastcall )
157 #define HAVE_ATTR_REGPARM // ( ATTR_REGPARM(x) == __fastcall )
158 #define C99_FLEXIBLE_ARRAYS // ("DEVBLK *memdev[];" supported)
159
160 //#include "getopt.h"
161 #define HAVE_GETOPT_LONG
162
163 #include <math.h>
164 #define HAVE_SQRTL
165 #define HAVE_LDEXPL
166 #define HAVE_FABSL
167 #define HAVE_FMODL
168 #define HAVE_FREXPL
169
170 // The following are needed by hostopts.h...
171
172 #define HAVE_DECL_SIOCSIFNETMASK 1 // (manually defined in tuntap.h)
173 #define HAVE_DECL_SIOCSIFHWADDR 1 // (manually defined in tuntap.h)
174 #define HAVE_DECL_SIOCADDRT 0 // (unsupported by CTCI-W32)
175 #define HAVE_DECL_SIOCDELRT 0 // (unsupported by CTCI-W32)
176 #define HAVE_DECL_SIOCDIFADDR 0 // (unsupported by CTCI-W32)
177
178 // SCSI tape handling transparency/portability
179
180 #define HAVE_DECL_MTEOTWARN 1 // (always true since I made it up!)
181 #define HAVE_DECL_MTEWARN 1 // (same as HAVE_DECL_MTEOTWARN)
182
183 // GNUWin32 PCRE (Perl-Compatible Regular Expressions) support...
184
185 #if defined(HAVE_PCRE)
186 // (earlier packages failed to define this so we must do so ourselves)
187 #define PCRE_DATA_SCOPE extern __declspec(dllimport)
188 #include PCRE_INCNAME // (passed by makefile)
189 #define OPTION_HAO // Hercules Automatic Operator
190 #endif
191
192 #if defined( _WIN64 )
193 #define SIZEOF_INT_P 8
194 #define SIZEOF_SIZE_T 8
195 #else
196 #define SIZEOF_INT_P 4
197 #define SIZEOF_SIZE_T 4
198 #endif
199
200 #define DBGTRACE DebugTrace
201
DebugTrace(char * fmt,...)202 inline void DebugTrace(char* fmt, ...)
203 {
204 const int chunksize = 512;
205 int buffsize = 0;
206 char* buffer = NULL;
207 int rc = -1;
208 va_list args;
209 va_start( args, fmt );
210 do
211 {
212 if (buffer) free( buffer );
213 buffsize += chunksize;
214 buffer = malloc( buffsize );
215 if (!buffer) __debugbreak();
216 rc = vsnprintf( buffer, buffsize, fmt, args);
217 }
218 while (rc < 0 || rc >= buffsize);
219 OutputDebugStringA( buffer );
220 free( buffer );
221 va_end( args );
222 }
223
224 #endif /*!defined(_HERCWIND_H)*/
225