Watt-32 tcp/ip  2.2 dev-rel.10
version.c
Go to the documentation of this file.
1 
5 #include <stdio.h>
6 #include <string.h>
7 
8 #ifdef __CYGWIN__
9 #include <cygwin/version.h>
10 #endif
11 
12 #include "wattcp.h"
13 #include "wdpmi.h"
14 #include "strings.h"
15 #include "misc.h"
16 
17 #if 0
18 #undef init_misc
19 #undef Random
20 #endif
21 
22 #if defined(_WIN64)
23  #if defined(_DEBUG)
24  #define DBG_RELEASE "debug"
25  #else
26  #define DBG_RELEASE "release"
27  #endif
28  #undef VARIANT
29  #define VARIANT " Win64"
30 
31 #elif defined(_WIN32) || defined(WIN32)
32  #if defined(_DEBUG)
33  #define DBG_RELEASE "debug" /* Only with MSVC */
34  #else
35  #define DBG_RELEASE "release"
36  #endif
37  #undef VARIANT
38  #define VARIANT " Win32"
39 
40 #else
41  #define VARIANT ""
42 #endif
43 
44 const char *wattcpCopyright = "See COPYRIGHT.H for details";
45 
46 
47 #if defined(_MSC_VER) && (_MSC_VER >= 1000) /* Visual-C 4+ */
48  _declspec(naked) static DWORD echo_stack_arg (DWORD arg)
49  {
50  __asm mov eax, [esp]
51  __asm ret
52  }
53  static const char *check_fastcall (void)
54  {
55  if (echo_stack_arg(0xDEADBEEF) != 0xDEADBEEF)
56  return ("fastcall");
57  return ("cdecl");
58  }
59 #endif
60 
61 
74 #if defined(MAKE_TSR)
75 
76 const char * W32_CALL wattcpVersion (void)
77 {
78  static char buf[15];
79  char *p = buf + 8;
80 
81  strcpy (buf, "Watt-32 ");
82  *p++ = '0' + WATTCP_MAJOR_VER;
83  *p++ = '.';
84  *p++ = '0' + WATTCP_MINOR_VER;
85  *p = '\0';
86  return (buf);
87 }
88 
89 #else
90 
91 const char * W32_CALL wattcpVersion (void)
92 {
93  static char buf[100];
94  char *p = buf;
95 
96 #if defined(WATTCP_DEVEL_REL) && (WATTCP_DEVEL_REL > 0)
97  p += sprintf (p, "Watt-32 (%d.%d.%d",
98  WATTCP_MAJOR_VER, WATTCP_MINOR_VER, WATTCP_DEVEL_REL);
99 #else
100  p += sprintf (p, "Watt-32 (%d.%d",
101  WATTCP_MAJOR_VER, WATTCP_MINOR_VER);
102 #endif
103 
104 #if defined(UNICODE) || defined(_UNICODE)
105  p += sprintf (p, "%s Unicode), ", VARIANT);
106 #else
107  p += sprintf (p, "%s), ", VARIANT);
108 #endif
109 
110 #if defined(__GNUC__)
111  p += sprintf (p, "GNU-C %d.%d", __GNUC__, __GNUC_MINOR__);
112 
113  #if defined(__GNUC_PATCHLEVEL__) && (__GNUC_PATCHLEVEL__ > 0)
114  p += sprintf (p, ".%d", __GNUC_PATCHLEVEL__);
115  #endif
116 
117  /* The builtin `__tune_xx' defines were introduced in gcc 2.95.1 (?)
118  */
119  #if defined(__tune_i386__) /* -mcpu=i386 */
120  strcpy (p, " (386), ");
121  #elif defined(__tune_i486__) /* -mcpu=i486 */
122  strcpy (p, " (486), ");
123  #elif defined(__tune_pentium__) /* -mcpu=pentium */
124  strcpy (p, " (Pent), ");
125  #elif defined(__tune_pentiumpro__) /* -mcpu=pentiumpro */
126  strcpy (p, " (PentPro), ");
127  #elif defined(__x86_64__) /* -m64 (MinGW64, AMD) */
128  strcpy (p, " (x86-64), ");
129  #else
130  strcpy (p, ", ");
131  #endif
132 
133 #elif defined(__HIGHC__)
134  p += sprintf (p, "Metaware High-C, "); /* no way to get version */
135 
136 #elif defined(__POCC__)
137  p += sprintf (p, "PellesC %d.%d, ", __POCC__/100, __POCC__ % 100);
138 
139 #elif defined(__WATCOMC__)
140  #if (__WATCOMC__ >= 1200)
141  p += sprintf (p, "OpenWatcom %d.%d",
142  (__WATCOMC__/100) - 11, (__WATCOMC__ % 100) / 10);
143  #else
144  p += sprintf (p, "Watcom C %d.%d", __WATCOMC__/100, __WATCOMC__ % 100);
145  #endif
146 
147  #if defined(__SMALL__)
148  strcpy (p, " (small model), ");
149  #elif defined(__LARGE__)
150  strcpy (p, " (large model), ");
151  #else
152  #if (_M_IX86 >= 600) /* -6r/s */
153  strcpy (p, " (686");
154  #elif (_M_IX86 >= 500) /* -5r/s */
155  strcpy (p, " (586");
156  #elif (_M_IX86 >= 400) /* -4r/s */
157  strcpy (p, " (486");
158  #else /* -3r/s */
159  strcpy (p, " (386");
160  #endif
161 
162  p += 5;
163 
164  #if defined(__SW_3S) /* -3/4/5/6s */
165  strcpy (p, "S), ");
166  #else
167  strcpy (p, "R), "); /* Register based calls is default */
168  #endif
169  #endif
170 
171 #elif defined(__BORLANDC__)
172  p += sprintf (p, "Borland C %X.%X", __BORLANDC__ >> 8, __BORLANDC__ & 0xFF);
173 
174  #if defined(__SMALL__)
175  strcpy (p, " (small model), ");
176  #elif defined(__LARGE__)
177  strcpy (p, " (large model), ");
178  #else
179  strcpy (p, ", ");
180  #endif
181 
182 #elif defined(__TURBOC__)
183  p += sprintf (p, "Turbo C %X.%X", (__TURBOC__ >> 8) - 1, __TURBOC__ & 0xFF);
184 
185  #if defined(__SMALL__)
186  strcpy (p, " (small model), ");
187  #elif defined(__LARGE__)
188  strcpy (p, " (large model), ");
189  #else
190  strcpy (p, ", ");
191  #endif
192 
193 #elif defined(_MSC_VER)
194  /*
195  * Really is:
196  *
197  * #if (_MSC_VER == 1600)
198  * p += sprintf (p, "Microsoft Visual Studio 2010 (%s), ", DBG_RELEASE);
199  * #elif (_MSC_VER == 1500)
200  * p += sprintf (p, "Microsoft Visual Studio 2008 (%s), ", DBG_RELEASE);
201  * #elif (_MSC_VER == 1400)
202  * p += sprintf (p, "Microsoft Visual Studio 2005 (%s), ", DBG_RELEASE);
203  * #elif (_MSC_VER == 1310)
204  * p += sprintf (p, "Microsoft Visual Studio 2003 (%s), ", DBG_RELEASE);
205  * #elif (_MSC_VER == 1300)
206  * p += sprintf (p, "Microsoft Visual Studio 2002 (%s), ", DBG_RELEASE);
207  */
208  #if (_MSC_VER >= 1000) /* Visual-C 4+ */
209  p += sprintf (p, "Microsoft Visual-C %d.%d (%s, %s), ",
210  (_MSC_VER / 100) - 6, _MSC_VER % 100, DBG_RELEASE, check_fastcall());
211  #else /* DOS only */
212  p += sprintf (p, "Microsoft Quick-C %d.%d",
213  _MSC_VER / 100, _MSC_VER % 100);
214 
215  #if defined(__SMALL__)
216  strcpy (p, " (small model), ");
217  #elif defined(__LARGE__)
218  strcpy (p, " (large model), ");
219  #else
220  strcpy (p, ", ");
221  #endif
222  #endif
223 
224 #elif defined(__DMC__)
225  p += sprintf (p, "Digital Mars C %X.%X", __DMC__ >> 8, __DMC__ & 0xFF);
226 
227  #if defined(DOS386)
228  strcpy (p, " (32-bit), ");
229  #elif defined(__SMALL__)
230  strcpy (p, " (small model), ");
231  #elif defined(__LARGE__)
232  strcpy (p, " (large model), ");
233  #else
234  strcpy (p, ", ");
235  #endif
236 
237 #elif defined(__CCDL__)
238  p += sprintf (p, "LadSoft C %d.%d, ", __CCDL__/100, __CCDL__ % 100);
239 
240 #elif defined(__LCC__) && defined(WIN32)
241  p += sprintf (p, "lcc-win32, ");
242 
243 #elif defined(__ICC__)
244  p += sprintf (p, "Intel C %d.%d, ", __ICC__/100, __ICC__ % 100);
245 #endif
246 
247  p = strchr (buf, '\0');
248 
249  /* '__MINGW32__' is defined by BOTH mingw.org and by the MinGW-w64
250  * project [1], because both can target Win32. '__MINGW64__' is defined
251  * only when targetting Win64 (__x86_64__).
252  *
253  * [1] http://mingw-w64.sourceforge.net/
254  */
255 #if defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)
256  p += sprintf (p, "MinGW-w64 %d.%d (%s), ",
257  __MINGW64_VERSION_MAJOR, __MINGW64_VERSION_MINOR, __MINGW64_VERSION_STATE);
258 
259 #elif defined(__MINGW32__) /* mingw.org MinGW. MingW-RT-4+ defines '__MINGW_MAJOR_VERSION' */
260  #if defined(__MINGW_MAJOR_VERSION)
261  p += sprintf (p, "MinGW %d.%d, ", __MINGW_MAJOR_VERSION, __MINGW_MINOR_VERSION);
262  #else
263  p += sprintf (p, "MinGW %d.%d, ", __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
264  #endif
265 
266 #elif defined(__CYGWIN__)
267  p += sprintf (p, "CygWin %d.%d.%d, ", CYGWIN_VERSION_DLL_MAJOR/1000,
268  CYGWIN_VERSION_DLL_MAJOR % 1000, CYGWIN_VERSION_DLL_MINOR);
269 
270 #elif (DOSX == DJGPP)
271  p += sprintf (p, "djgpp %d.%02d, ", __DJGPP__, __DJGPP_MINOR__);
272 
273 #elif (DOSX == DOS4GW)
274  {
275  const char *extender = dos_extender_name();
276  p += sprintf (p, "%s, ", extender ? extender : "unknown");
277  }
278 
279 #elif (DOSX == PHARLAP)
280  p += sprintf (p, "Pharlap, ");
281 
282 #elif (DOSX == X32VM)
283  p += sprintf (p, "X32VM, ");
284 
285 #elif (DOSX == POWERPAK)
286  p += sprintf (p, "PowerPak, ");
287 #endif
288 
289 #if defined(WIN32)
290  if (_watt_is_wow64)
291  p += sprintf (p, "WOW64, ");
292 #endif
293 
294  strcpy (p, __DATE__);
295  return (buf);
296 }
297 #endif /* MAKE_TSR */
298 
299 
300 #if defined(__DJGPP__)
301  #define CC_DEFINE "__DJGPP__"
302  #define CFLAGS "djgpp/cflags.h"
303 
304 #elif defined(__BORLANDC__)
305  #define CC_DEFINE "__BORLANDC__"
306 
307  #ifdef __SMALL__
308  #define CFLAGS "borland/small/cflags.h"
309  #elif defined(__LARGE__)
310  #define CFLAGS "borland/large/cflags.h"
311  #elif defined(__FLAT__)
312  #define CFLAGS "borland/flat/cflags.h"
313  #elif defined(WIN32)
314  #define CFLAGS "borland/win32/cflags.h"
315  #endif
316 
317 #elif defined(__TURBOC__)
318  #define CC_DEFINE "__TURBOC__"
319  #ifdef __SMALL__
320  #define CFLAGS "turboc/small/cflags.h"
321  #elif defined(__LARGE__)
322  #define CFLAGS "turboc/large/cflags.h"
323  #endif
324 
325 #elif defined(__DMC__)
326  #define CC_DEFINE "__DMC__"
327 
328  #if defined(__SMALL__)
329  #define CFLAGS "digmars/small/cflags.h"
330  #elif defined(__LARGE__)
331  #define CFLAGS "digmars/large/cflags.h"
332  #elif defined(WIN32)
333  #define CFLAGS "digmars/win32/cflags.h"
334  #elif (DOSX == PHARLAP)
335  #define CFLAGS "digmars/phar/cflags.h"
336  #elif (DOSX == X32VM)
337  #define CFLAGS "digmars/x32vm/cflags.h"
338  #endif
339 
340 #elif defined(__POCC__) /* Win32 only */
341  #define CC_DEFINE "__POCC__"
342  #define CFLAGS "pellesc/cflags.h"
343 
344 #elif defined(__LCC__) /* Win32 only */
345  #define CC_DEFINE "__LCC__"
346  #define CFLAGS "lcc/cflags.h"
347 
348 #elif defined(__CCDL__) /* DOS4GW only */
349  #define CC_DEFINE "__CCDL__"
350  #define CFLAGS "ladsoft/cflags.h"
351 
352 #elif defined(__ICC__)
353  #define CC_DEFINE "__ICC__"
354  #define CFLAGS "intel/cflags.h"
355 
356 #elif defined(__HIGHC__)
357  #define CC_DEFINE "__HIGHC__"
358  #define CFLAGS "HighC/cflags.h"
359 
360 #elif defined(__WATCOMC__)
361  #define CC_DEFINE "__WATCOMC__"
362 
363  #if defined(WIN32)
364  #define CFLAGS "watcom/win32/cflags.h"
365  #elif defined(__SMALL__)
366  #define CFLAGS "watcom/small/cflags.h"
367  #elif defined(__LARGE__)
368  #define CFLAGS "watcom/large/cflags.h"
369  #elif defined(__FLAT__)
370  #define CFLAGS "watcom/flat/cflags.h"
371  #endif
372 
373  /* Both of these combos can be true for the "MinGW-w64" project [1].
374  * Depend
375  */
376 #elif defined(__MINGW64__) && defined(__MINGW64_VERSION_MAJOR)
377  #define CC_DEFINE "__MINGW64__"
378  #define CFLAGS "MinGW64/cflags.h"
379 
380 #elif defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR)
381  #define CC_DEFINE "__MINGW32__"
382  #define CFLAGS "MinGW64/cflags.h"
383 
384 #elif defined(__MINGW32__)
385  #define CC_DEFINE "__MINGW32__"
386  #define CFLAGS "MinGW32/cflags.h"
387 
388 #elif defined(__CYGWIN__)
389  #define CC_DEFINE "__CYGWIN__"
390  #define CFLAGS "CygWin/cflags.h"
391 
392 #elif defined(_MSC_VER)
393  #define CC_DEFINE "_MSC_VER"
394 
395  #if (_MSC_VER >= 1000) /* Visual-C 4+ (debug/release) */
396  #if defined(_DEBUG)
397  #define CFLAGS "visualc/debug/cflags.h"
398  #else
399  #define CFLAGS "visualc/release/cflags.h"
400  #endif
401  #elif defined(__SMALL__)
402  #define CFLAGS "quickc/small/cflags.h"
403  #elif defined(__LARGE__)
404  #define CFLAGS "quickc/large/cflags.h"
405  #endif
406 #endif
407 
411 const char * W32_CALL wattcpBuildCC (void)
412 {
413 #ifdef CC_DEFINE
414  return (CC_DEFINE);
415 #else
416  return ("Unknown");
417 #endif
418 }
419 
427 #if defined(CFLAGS)
428 #include CFLAGS
429 #endif
430 
431 const char * W32_CALL wattcpBuildCflags (void)
432 {
433 #if defined(CFLAGS)
434  static char buf [400]; /* should be enough for High-C */
435 
436  _strlcpy (buf, w32_cflags, sizeof(buf));
437 #if !defined(__GNUC__)
438  {
439  char *p = strstr (buf, "-I..");
440  if (p && p[5] && p[4] != '/')
441  {
442  memmove (p+5, p+4, p+5-buf);
443  p[4] = '/';
444  }
445  }
446 #endif
447  return (buf);
448 #else
449  return ("Unknown");
450 #endif
451 }
452 
456 const char * W32_CALL wattcpBuildCCexe (void)
457 {
458 #if defined(CFLAGS)
459  static char buf [40];
460  _strlcpy (buf, w32_cc, sizeof(buf));
461  return (buf);
462 #else
463  return ("Unknown");
464 #endif
465 }
466 
467 static const char *capa[] = {
468 #if defined(MAKE_TSR)
469  "TSR",
470 #endif
471 #if defined(USE_DEBUG)
472  "debug",
473 #endif
474 #if defined(USE_MULTICAST)
475  "mcast",
476 #endif
477 #if defined(USE_BIND)
478  "bind",
479 #endif
480 #if defined(USE_BSD_API)
481  "BSDsock",
482 #endif
483 #if defined(USE_BSD_FATAL)
484  "BSDfatal",
485 #endif
486 #if defined(USE_BOOTP)
487  "bootp",
488 #endif
489 #if defined(USE_DHCP)
490  "dhcp",
491 #endif
492 #if defined(USE_RARP)
493  "rarp",
494 #endif
495 #if defined(USE_LANGUAGE)
496  "lang",
497 #endif
498 #if defined(USE_FRAGMENTS)
499  "frag",
500 #endif
501 #if defined(USE_STATISTICS)
502  "stat",
503 #endif
504 #if defined(USE_FORTIFY)
505  "fortify",
506 #endif
507 #if defined(USE_CRTDBG)
508  "crt-dbg",
509 #endif
510 #if defined(USE_FSEXT)
511  "fsext",
512 #endif
513 #if defined(USE_LOOPBACK)
514  "loopback",
515 #endif
516 #if defined(USE_EMBEDDED)
517  "embedded",
518 #endif
519 #if defined(USE_TFTP)
520  "tftp",
521 #endif
522 #if defined(USE_TCP_SACK)
523  "sack",
524 #endif
525 #if defined(USE_UDP_ONLY)
526  "udp-only",
527 #endif
528 #if defined(USE_ECHO_DISC)
529  "echo",
530 #endif
531 #if defined(USE_PPPOE)
532  "PPPoE",
533 #endif
534 #if defined(USE_IPV6)
535  "IPv6",
536 #endif
537 #if defined(USE_RS232_DBG)
538  "RS232",
539 #endif
540 #if defined(USE_DEAD_GWD)
541  "dead-gw",
542 #endif
543 #if defined(USE_GZIP)
544  "gzip",
545 #endif
546 #if defined(USE_TCP_MD5)
547  "TCP-MD5",
548 #endif
549 #if defined(USE_DYNIP_CLI)
550  "DynIP",
551 #endif
552 #if defined(USE_PROFILER)
553  "profiler",
554 #endif
555 #if defined(USE_FAST_PKT)
556  "fast-pkt",
557 #endif
558 #if defined(USE_SCTP)
559  "SCTP",
560 #endif
561  NULL
562  };
563 
568 const char * W32_CALL wattcpCapabilities (void)
569 {
570  static char buf[240];
571  char *p = buf;
572  int i;
573 
574  for (i = 0; capa[i]; i++)
575  {
576  *p++ = '/';
577  if (p + strlen(capa[i]) - 2 >= buf + sizeof(buf))
578  {
579  *p++ = '.';
580  *p++ = '.';
581  break;
582  }
583  strcpy (p, capa[i]);
584  p += strlen (capa[i]);
585  }
586  *p = '\0';
587  return (buf);
588 }
589 
const char *W32_CALL wattcpBuildCC(void)
Return the target/compiler.
Definition: version.c:411
const char *W32_CALL wattcpCapabilities(void)
Return compiled-in capabilities and features.
Definition: version.c:568
Core definitions.
const char *W32_CALL wattcpBuildCCexe(void)
Return the the name if the compiler used.
Definition: version.c:456
char * _strlcpy(char *dst, const char *src, size_t len)
Similar to strncpy(), but always returns 'dst' with 0-termination.
Definition: strings.c:226
const char *W32_CALL wattcpBuildCflags(void)
Return the used.
Definition: version.c:431
Definition: esp.h:48
const char *W32_CALL wattcpVersion(void)
Return string for Watt-32 version.
Definition: version.c:76