* Add a new module (printf_ext.c) to contain some printf extensions (C99 printf variants for MSVC)
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2803 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
ff28313711
commit
7711572f0a
|
@ -11,11 +11,11 @@ CLEANFILES = resource_lexer.lex.c strres_lexer.lex.c resource_parser.tab.c strre
|
|||
|
||||
noinst_LIBRARIES = libframework.a
|
||||
noinst_HEADERS = configfile.h cursors.h cursors16.h debug.h fractions.h frame.h \
|
||||
frameint.h frameresource.h input.h listmacs.h resly.h strlfuncs.h \
|
||||
strnlen1.h strres.h strresly.h treap.h treapint.h trig.h types.h \
|
||||
tagfile.h
|
||||
frameint.h frameresource.h input.h listmacs.h printf_ext.h resly.h \
|
||||
strlfuncs.h strnlen1.h strres.h strresly.h treap.h treapint.h trig.h \
|
||||
types.h tagfile.h
|
||||
|
||||
libframework_a_SOURCES = SDL_framerate.c configfile.c debug.c exceptionhandler.c \
|
||||
frame.c frameresource.c input.c resource_lexer.lex.c resource_parser.tab.c \
|
||||
strnlen1.c strres.c strres_lexer.lex.c strres_parser.tab.c treap.c trig.c \
|
||||
tagfile.c
|
||||
frame.c frameresource.c input.c printf_ext.c resource_lexer.lex.c \
|
||||
resource_parser.tab.c strnlen1.c strres.c strres_lexer.lex.c \
|
||||
strres_parser.tab.c treap.c trig.c tagfile.c
|
||||
|
|
|
@ -7,6 +7,7 @@ SRC=configfile.c \
|
|||
frame.c \
|
||||
frameresource.c \
|
||||
input.c \
|
||||
printf_ext.c \
|
||||
resource_parser.tab.c \
|
||||
resource_lexer.lex.c \
|
||||
strnlen1.c \
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "debug.h"
|
||||
|
||||
#include "treap.h"
|
||||
#include "printf_ext.h"
|
||||
|
||||
#include "fractions.h"
|
||||
#include "trig.h"
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
This file is part of Warzone 2100.
|
||||
Copyright (C) 1992-2007 Trolltech ASA.
|
||||
Copyright (C) 2005-2007 Warzone Resurrection Project
|
||||
|
||||
Warzone 2100 is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Warzone 2100 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Warzone 2100; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "frame.h"
|
||||
#include "printf_ext.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(WZ_CC_MSVC)
|
||||
int vsnprintf(char* str, size_t size, const char* format, va_list ap)
|
||||
{
|
||||
int count;
|
||||
|
||||
// Find out how long the resulting string is
|
||||
count = _vscprintf(format, ap);
|
||||
|
||||
if (count > 0
|
||||
&& str != NULL)
|
||||
{
|
||||
// Perfrom the actual string formatting
|
||||
_vsnprintf_s(str, size, _TRUNCATE, format, ap);
|
||||
}
|
||||
|
||||
// Return the amount of characters that would be written if _no_ truncation occurred
|
||||
return count;
|
||||
}
|
||||
|
||||
int snprintf(char* str, size_t size, const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int count;
|
||||
|
||||
va_start(ap, format);
|
||||
count = vsnprintf(str, size, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return count;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
This file is part of Warzone 2100.
|
||||
Copyright (C) 2007 Giel van Schijndel
|
||||
Copyright (C) 2007 Warzone Resurrection Project
|
||||
|
||||
Warzone 2100 is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Warzone 2100 is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Warzone 2100; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __INCLUDE_LIB_FRAMEWORK_PRINTF_EXT_H__
|
||||
#define __INCLUDE_LIB_FRAMEWORK_PRINTF_EXT_H__
|
||||
|
||||
#include "frame.h"
|
||||
|
||||
#if defined(WZ_CC_MSVC)
|
||||
// Make sure that these functions are available, and work according to the C99 spec on MSVC also
|
||||
|
||||
extern int vsnprintf(char* str, size_t size, const char* format, va_list ap);
|
||||
extern int snprintf(char* str, size_t size, const char* format, ...);
|
||||
#endif
|
||||
|
||||
#endif // __INCLUDE_LIB_FRAMEWORK_PRINTF_EXT_H__
|
|
@ -417,40 +417,6 @@
|
|||
# define strncasecmp _strnicmp
|
||||
# define inline __inline
|
||||
# define alloca _alloca
|
||||
|
||||
// Required for the below two inline functions
|
||||
# include <stdio.h>
|
||||
|
||||
static inline int vsnprintf(char* str, size_t size, const char* format, va_list ap)
|
||||
{
|
||||
int count;
|
||||
|
||||
// Find out how long the resulting string is
|
||||
count = _vscprintf(format, ap);
|
||||
|
||||
if (count > 0
|
||||
&& str != NULL)
|
||||
{
|
||||
// Perfrom the actual string formatting
|
||||
_vsnprintf_s(str, size, _TRUNCATE, format, ap);
|
||||
}
|
||||
|
||||
// Return the amount of characters that would be written if _no_ truncation occurred
|
||||
return count;
|
||||
}
|
||||
|
||||
static inline int snprintf(char* str, size_t size, const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int count;
|
||||
|
||||
va_start(ap, format);
|
||||
count = vsnprintf(str, size, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
# define fileno _fileno
|
||||
# define isfinite _finite
|
||||
# define PATH_MAX MAX_PATH
|
||||
|
|
|
@ -315,6 +315,19 @@
|
|||
<Option target="DBGWindows" />
|
||||
<Option target="NDBGWindows" />
|
||||
</Unit>
|
||||
<Unit filename="lib/framework/printf_ext.c">
|
||||
<Option compilerVar="CC" />
|
||||
<Option target="DBGUnix" />
|
||||
<Option target="NDBGUnix" />
|
||||
<Option target="DBGWindows" />
|
||||
<Option target="NDBGWindows" />
|
||||
</Unit>
|
||||
<Unit filename="lib/framework/printf_ext.h">
|
||||
<Option target="DBGUnix" />
|
||||
<Option target="NDBGUnix" />
|
||||
<Option target="DBGWindows" />
|
||||
<Option target="NDBGWindows" />
|
||||
</Unit>
|
||||
<Unit filename="lib/framework/resly.h">
|
||||
<Option target="DBGUnix" />
|
||||
<Option target="NDBGUnix" />
|
||||
|
|
|
@ -245,6 +245,10 @@
|
|||
RelativePath="..\lib\framework\strnlen1.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\lib\framework\printf_ext.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\lib\framework\strres.c"
|
||||
>
|
||||
|
@ -1294,6 +1298,10 @@
|
|||
RelativePath="..\lib\framework\frameresource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\lib\framework\printf_ext.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\frend.h"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue