Skip to content

Commit 8ad76f3

Browse files
akaveltike
authored andcommitted
replace some functions not working in MinGW
1 parent 9cb9776 commit 8ad76f3

File tree

5 files changed

+54
-30
lines changed

5 files changed

+54
-30
lines changed

GOnpp/DockingFeature/CmdDlg.cpp

+33-19
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,22 @@
3131
//along with this program; if not, write to the Free Software
3232
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3333

34+
#include <string>
3435
#include "CmdDlg.h"
3536
#include "PluginDefinition.h"
3637

3738
extern NppData nppData;
3839

40+
typedef std::basic_string<TCHAR> tstring;
41+
42+
#ifdef max
43+
#undef max
44+
#endif
45+
46+
#ifdef min
47+
#undef min
48+
#endif
49+
3950
BOOL CALLBACK CmdDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
4051
{
4152
switch (message)
@@ -72,30 +83,33 @@ void CmdDlg::reshape(int width)
7283

7384
LPTSTR CmdDlg::prettyfy(LPTSTR text)
7485
{
75-
size_t size = _tcslen(text) + 50;
76-
LPTSTR res = (LPTSTR) calloc(size+1, sizeof(TCHAR));
77-
78-
LPTSTR rest = NULL;
79-
LPTSTR current = _tcstok_s(text, _T("\n"), &rest);
80-
while(current != NULL){
81-
if (_tcslen(current) > _maxLine){
82-
_maxLine = _tcslen(current);
83-
}
84-
if( _tcslen(current) > size - _tcslen(res)){
85-
size += 500;
86-
res = (LPTSTR) realloc(res, size * sizeof(TCHAR));
87-
if (res == NULL){
88-
return NULL;
86+
try {
87+
tstring src = tstring(text);
88+
tstring dst;
89+
tstring::size_type i = 0;
90+
for (;;) {
91+
const tstring::size_type j = src.find(_T("\n"), i);
92+
dst.append(src, i, j-i);
93+
dst.append(_T("\r\n"));
94+
_maxLine = std::max(_maxLine, std::min(j-i, src.length()-i));
95+
if (j == tstring::npos) {
96+
break;
8997
}
98+
i = j+1;
9099
}
91-
_tcsncat(res, current, __min(size -_tcslen(res), _tcslen(current)));
92-
_tcsncat(res, _T("\r\n"), __min(size - _tcslen(res), 2 * sizeof(TCHAR)));
93-
current = _tcstok_s(NULL, _T("\n"), &rest);
100+
101+
LPTSTR res = (LPTSTR) calloc(dst.length()+1, sizeof(TCHAR));
102+
if (res == NULL) {
103+
return NULL;
104+
}
105+
dst.copy(res, dst.length());
106+
res[dst.length()] = TCHAR(0);
107+
return res;
108+
} catch (...) {
109+
return NULL;
94110
}
95-
return res;
96111
}
97112

98-
99113
void CmdDlg::setText(LPTSTR text)
100114
{
101115
LPTSTR lines = prettyfy(text);

GOnpp/goCommands/CommandExec.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
//along with this program; if not, write to the Free Software
1515
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1616

17+
#include <algorithm>
1718
#include "CommandExec.h"
1819

20+
#ifdef min
21+
#undef min
22+
#endif
1923

2024
CommandExec::CommandExec(LPCTSTR cmd, LPCTSTR dir)
2125
{
@@ -151,7 +155,7 @@ BOOL CommandExec::readOutput(HANDLE handle, LPTSTR* output){
151155
}
152156
}
153157

154-
_tcsncat(*output, TBuf, __min(BUFSIZE, outputLen - _tcslen(*output)));
158+
_tcsncat(*output, TBuf, std::min<DWORD>(BUFSIZE, outputLen - _tcslen(*output)));
155159
}
156160
return TRUE;
157161
}
@@ -204,8 +208,8 @@ LPTSTR CommandExec::GetCombined()
204208
LPTSTR out = (LPTSTR) calloc(length + 1, sizeof(TCHAR));
205209
if (*out == NULL) return NULL;
206210

207-
_tcsncat(out, stdOut, __min(_tcslen(stdOut), length - _tcslen(out)));
208-
_tcsncat(out, stdErr, __min(_tcslen(stdErr), length - _tcslen(out)));
211+
_tcsncat(out, stdOut, std::min(_tcslen(stdOut), length - _tcslen(out)));
212+
_tcsncat(out, stdErr, std::min(_tcslen(stdErr), length - _tcslen(out)));
209213

210214
return out;
211215
}

GOnpp/goCommands/goCommand.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
//along with this program; if not, write to the Free Software
1515
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1616

17+
#include <algorithm>
1718
#include "goCommand.h"
1819
#include <shlwapi.h>
1920

21+
#ifdef min
22+
#undef min
23+
#endif
24+
2025
goCommand::goCommand(LPCTSTR cmd, LPCTSTR flags)
2126
{
2227
this->cmd = cmd;
@@ -132,7 +137,7 @@ BOOL goCommand::initializeFileVals(LPTSTR current_file)
132137
{
133138
this->currentFile = (LPTSTR) calloc(MAX_PATH, sizeof(TCHAR));
134139
if (this->currentFile == NULL) return FALSE;
135-
_tcsncpy(this->currentFile, current_file, __min(MAX_PATH, _tcslen(current_file)));
140+
_tcsncpy(this->currentFile, current_file, std::min<size_t>(MAX_PATH, _tcslen(current_file)));
136141

137142
this->currentDir = (LPTSTR) _tcsdup(this->currentFile);
138143
if (this->currentDir == NULL) return FALSE;
@@ -193,11 +198,11 @@ BOOL goCommand::combineCommandLine(LPCTSTR go_cmd, LPTSTR pkg)
193198
LPTSTR args = (LPTSTR) calloc(size + 1, sizeof(TCHAR));
194199
if (args == NULL) return FALSE;
195200

196-
_tcsncat(args, go_cmd, __min(_tcslen(go_cmd), size - _tcslen(args)));
197-
_tcsncat(args, _T(" "), __min(sizeof(args), size - _tcslen(args)));
198-
_tcsncat(args, cmd, __min( _tcslen(cmd), size -_tcslen(args)));
199-
_tcsncat(args, _T(" "), __min(sizeof(args), size - _tcslen(args)));
200-
_tcsncat(args, pkg, __min( _tcslen(pkg), size -_tcslen(args)));
201+
_tcsncat(args, go_cmd, std::min(_tcslen(go_cmd), size - _tcslen(args)));
202+
_tcsncat(args, _T(" "), std::min(sizeof(args), size - _tcslen(args)));
203+
_tcsncat(args, cmd, std::min( _tcslen(cmd), size -_tcslen(args)));
204+
_tcsncat(args, _T(" "), std::min(sizeof(args), size - _tcslen(args)));
205+
_tcsncat(args, pkg, std::min( _tcslen(pkg), size -_tcslen(args)));
201206

202207
this->commandLine = args;
203208
return TRUE;

GOnpp/no_ms_shit.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010
<ItemDefinitionGroup>
1111
<ClCompile>
12-
<PreprocessorDefinitions>__STDC_WANT_SECURE_LIB__=0;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
12+
<PreprocessorDefinitions>__STDC_WANT_SECURE_LIB__=1;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>
1313
</ClCompile>
1414
</ItemDefinitionGroup>
1515
<ItemGroup />

makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ CC = $(ARCH)-gcc
3636
CXX = $(ARCH)-g++
3737
WINDRES = windres -O coff
3838
CFLAGS = -O2 -mtune=i686 -DBUILD_DLL -W -Wall -gstabs -mwindows \
39-
$(foreach dir,$(SRC_DIRS),-I$(dir))
39+
$(foreach dir,$(SRC_DIRS),-I$(dir)) \
40+
-DUNICODE -D_UNICODE
4041
LIBS = -lws2_32 -lz -lm -Wl,-Map,$@.map,--cref -static-libgcc
4142
LDFLAGS = -Wl,--out-implib,$(TARGET) -shared -lshlwapi $(CFLAGS)
4243
OBJDIR = .objs

0 commit comments

Comments
 (0)