1 // winsupport.h                                 Copyright (C) 2021 Codemist
2 
3 // $Id: winsupport.h 5728 2021-03-13 14:54:03Z arthurcnorman $
4 
5 
6 /**************************************************************************
7  * Copyright (C) 2021, Codemist.                         A C Norman       *
8  *                                                                        *
9  * Redistribution and use in source and binary forms, with or without     *
10  * modification, are permitted provided that the following conditions are *
11  * met:                                                                   *
12  *                                                                        *
13  *     * Redistributions of source code must retain the relevant          *
14  *       copyright notice, this list of conditions and the following      *
15  *       disclaimer.                                                      *
16  *     * Redistributions in binary form must reproduce the above          *
17  *       copyright notice, this list of conditions and the following      *
18  *       disclaimer in the documentation and/or other materials provided  *
19  *       with the distribution.                                           *
20  *                                                                        *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    *
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      *
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS      *
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE         *
25  * COPYRIGHT OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,   *
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,   *
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS  *
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR  *
30  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF     *
31  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
32  * DAMAGE.                                                                *
33  *************************************************************************/
34 
35 #ifndef __header_winsupport_h
36 #define __header_winsupport_h 1
37 
38 
39 extern uintptr_t *C_stackbase;
40 extern const char *fullProgramName;
41 extern const char *programName;
42 extern bool programNameDotCom;
43 extern const char *programDir;
44 
45 #ifdef WIN32
46 
47 // Various definitions in <windows.h> clash with other things I use in CSL
48 // and so I am putting all code that references such Windows specific stuff
49 // in a separate file, winsupport.cpp. This file declares the entrypoints
50 // that it provides.
51 
52 // The aim here is to avoid use of the Microsoft versions of printf and
53 // friends and (hence) allow g++ to parse and check format strings reliably.
54 #define __USE_MINGW_ANSI_STDIO 1
55 
56 #include <cstdint>
57 #include <cinttypes>
58 #include <cctype>
59 #include <ctime>
60 #include <new>
61 
62 #include <windows.h>
63 #include <winsock.h>
64 #include <process.h>
65 
66 extern void win32_stacklimit(uintptr_t &C_stacklimit);
67 extern int find_program_directory(const char *argv0);
68 extern size_t getMemorySize();
69 extern int windowsGetPid();
70 extern const char *WSAErrName(int i);
71 extern int windowsPrepareSockets();
72 extern HANDLE gnuplot_process;
73 extern HWND gnuplot_handle;
74 extern bool gnuplotActive;
75 class GnuplotClass
76 {
77 public:
GnuplotClass()78     GnuplotClass()
79     {   gnuplotActive = false;
80     }
~GnuplotClass()81     ~GnuplotClass()
82     {   if (gnuplotActive)
83             TerminateProcess(gnuplot_process, 0);
84     }
85 };
86 extern BOOL CALLBACK find_text(HWND h, LPARAM);
87 extern FILE *windowsFindGnuplot(const char *command, const char *direction);
88 extern int my_pipe_putc(int c, std::FILE *f);
89 extern int my_pipe_flush(std::FILE *f);
90 extern void my_pclose(std::FILE *stream);
91 extern uint64_t read_clock();
92 extern int windowsFindGnuplot1(char *name);
93 extern size_t windowsGetTempPath(size_t n, char *s);
94 extern bool valid_address(void *pointer);
95 extern int windowsFindGnuplot2(char *name);
96 
97 #else
98 #ifdef __CYGWIN__
99 
100 extern size_t windowsGetTempPath(size_t n, char *s);
101 extern int windowsFindGnuplot2(char *name);
102 
103 #endif // __CYGWIN__
104 #endif // WIN32
105 
106 #endif // __header_winsupport_h
107 
108 
109 // end of winsupport.h
110