Skip to content

Commit 16eb0f1

Browse files
committed
[ZH] Fix iostream errors for Zero Hour Tools build (TheSuperHackers#509)
1 parent 18f022f commit 16eb0f1

File tree

23 files changed

+145
-82
lines changed

23 files changed

+145
-82
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// TheSuperHackers
2+
// This file helps adapting modern iostream to legacy vs6 iostream,
3+
// where symbols are not contained in the std namespace.
4+
5+
#pragma once
6+
7+
#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)
8+
9+
#include <iostream.h>
10+
11+
#else
12+
13+
#include <iostream>
14+
15+
inline auto& cout = std::cout;
16+
inline auto& cerr = std::cerr;
17+
18+
using streambuf = std::streambuf;
19+
using ostream = std::ostream;
20+
21+
template <class _Elem, class _Traits>
22+
std::basic_ostream<_Elem, _Traits>& endl(std::basic_ostream<_Elem, _Traits>& _Ostr)
23+
{
24+
return std::endl(_Ostr);
25+
}
26+
27+
template <class _Elem, class _Traits>
28+
std::basic_ostream<_Elem, _Traits>& flush(std::basic_ostream<_Elem, _Traits>& _Ostr)
29+
{
30+
return std::flush(_Ostr);
31+
}
32+
33+
#endif

GeneralsMD/Code/Libraries/Source/WWVegas/WWLib/sha.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@
3939
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
4040

4141
#include "sha.h"
42-
#ifdef USING_STLPORT
43-
#include <iostream.h>
44-
#else
45-
#include <iostream>
46-
#endif
42+
#include <Utility/iostream_adapter.h>
4743
#include <stdlib.h>
4844

4945

GeneralsMD/Code/Tools/CRCDiff/CRCDiff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "expander.h"
2121
#include "KVPair.h"
2222
#include "misc.h"
23-
#include <iostream>
23+
#include <Utility/iostream_adapter.h>
2424
#include <list>
2525
#include <stdlib.h>
2626
#include <stdio.h>

GeneralsMD/Code/Tools/Launcher/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ target_compile_definitions(z_launcher PRIVATE
6565

6666
target_link_libraries(z_launcher PRIVATE
6767
comctl32
68+
gz_utility
6869
safedisc
6970
)
7071

GeneralsMD/Code/Tools/Launcher/streamer.cpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,29 @@
2222
#include <windows.h>
2323
#endif
2424

25+
#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)
26+
#define STREAMER_UNBUFFERED unbuffered()
27+
#else
28+
#define STREAMER_UNBUFFERED 0
29+
#endif
2530

26-
Streamer::Streamer() : streambuf()
31+
Streamer::Streamer() : streambuf(), Output_Device(NULL), Buf(NULL)
2732
{
33+
#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)
2834
int state=unbuffered();
2935
unbuffered(0); // 0 = buffered, 1 = unbuffered
36+
#else
37+
static_assert(STREAMER_UNBUFFERED==0, "std::streambuf is assumed to be buffered by default");
38+
#endif
3039
}
3140

3241
Streamer::~Streamer()
3342
{
34-
sync();
35-
delete[](base());
43+
///////// calling sync seems to cause crashes here on Win32
44+
//sync();
45+
/////////
46+
if (Buf)
47+
delete[] Buf;
3648
}
3749

3850
int Streamer::setOutputDevice(OutputDevice *device)
@@ -45,7 +57,6 @@ int Streamer::setOutputDevice(OutputDevice *device)
4557
// put n chars from string into buffer
4658
int Streamer::xsputn(const char* buf, int size) //implementation of sputn
4759
{
48-
4960
if (size<=0) // Nothing to do
5061
return(0);
5162

@@ -66,7 +77,6 @@ int Streamer::xsputn(const char* buf, int size) //implementation of sputn
6677
// Flush the buffer and make more room if needed
6778
int Streamer::overflow(int c)
6879
{
69-
7080
if (c==EOF)
7181
return(sync());
7282
if ((pbase()==0) && (doallocate()==0))
@@ -75,7 +85,7 @@ int Streamer::overflow(int c)
7585
return(EOF);
7686
else {
7787
sputc(c);
78-
if ((unbuffered() && c=='\n' || pptr() >= epptr())
88+
if ((STREAMER_UNBUFFERED && c=='\n' || pptr() >= epptr())
7989
&& sync()==EOF) {
8090
return(EOF);
8191
}
@@ -91,27 +101,30 @@ int Streamer::underflow(void)
91101

92102
int Streamer::doallocate()
93103
{
94-
95-
if (base()==NULL)
104+
if (Buf==NULL)
96105
{
97-
char *buf=new char[(2*STREAMER_BUFSIZ)]; // deleted by destructor
98-
memset(buf,0,2*STREAMER_BUFSIZ);
106+
Buf=new char[(2*STREAMER_BUFSIZ)]; // deleted by destructor
107+
memset(Buf,0,2*STREAMER_BUFSIZ);
99108

100109
// Buffer
110+
#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)
101111
setb(
102-
buf, // base pointer
103-
buf+STREAMER_BUFSIZ, // ebuf pointer (end of buffer);
112+
Buf, // base pointer
113+
Buf+STREAMER_BUFSIZ, // ebuf pointer (end of buffer);
104114
0); // 0 = manual deletion of buff
115+
#else
116+
pubsetbuf(Buf, 2*STREAMER_BUFSIZ);
117+
#endif
105118

106119
// Get area
107120
setg(
108-
buf, // eback
109-
buf, // gptr
110-
buf); // egptr
121+
Buf, // eback
122+
Buf, // gptr
123+
Buf); // egptr
111124

112-
buf+=STREAMER_BUFSIZ;
125+
Buf+=STREAMER_BUFSIZ;
113126
// Put area
114-
setp(buf,buf+STREAMER_BUFSIZ);
127+
setp(Buf,Buf+STREAMER_BUFSIZ);
115128
return(1);
116129
}
117130
else
@@ -132,7 +145,7 @@ int Streamer::sync()
132145
Output_Device->print(pbase(),wlen);
133146
}
134147

135-
if (unbuffered()) {
148+
if (STREAMER_UNBUFFERED) {
136149
setp(pbase(),pbase());
137150
}
138151
else {

GeneralsMD/Code/Tools/Launcher/streamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <stdlib.h>
2323
#include <stdio.h>
2424
#include <stdarg.h>
25-
#include <iostream.h>
25+
#include <Utility/iostream_adapter.h>
2626
#include <string.h>
2727

2828
#include "odevice.h"
@@ -55,6 +55,7 @@ class Streamer : public streambuf
5555

5656

5757
OutputDevice *Output_Device;
58+
char *Buf;
5859
};
5960

6061
#endif

GeneralsMD/Code/Tools/Launcher/wdebug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ will you be ready to leave grasshopper.
5353
#ifndef WDEBUG_HEADER
5454
#define WDEBUG_HEADER
5555

56-
#include <iostream.h>
56+
#include <Utility/iostream_adapter.h>
5757
#include "odevice.h"
5858
#include "streamer.h"
5959
#include <time.h>

GeneralsMD/Code/Tools/mangler/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ set_target_properties(z_manglerlib PROPERTIES OUTPUT_NAME manglerlib)
6262
target_sources(z_manglerlib PUBLIC ${MANGLERLIB_SRC})
6363
target_include_directories(z_manglerlib PRIVATE . wlib wnet)
6464
target_link_libraries(z_manglerlib PRIVATE wsock32)
65-
65+
target_link_libraries(z_manglerlib PUBLIC gz_utility)
6666

6767
# mangler app
6868

GeneralsMD/Code/Tools/mangler/crc.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919

20-
#include <iostream>
2120
#include <signal.h>
2221
#ifdef _WINDOWS
2322
#include <process.h> // *MUST* be included before ANY Wnet/Wlib headers if _REENTRANT is defined

GeneralsMD/Code/Tools/mangler/mangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
*/
1818

1919

20-
#include <iostream.h>
20+
#include <Utility/iostream_adapter.h>
21+
2122
#include <signal.h>
2223
#ifdef _WINDOWS
2324
#include <process.h> // *MUST* be included before ANY Wnet/Wlib headers if _REENTRANT is defined

0 commit comments

Comments
 (0)