Skip to content

Commit fc98559

Browse files
Reworked File2Include to use standard io functions
1 parent 6423947 commit fc98559

File tree

12 files changed

+25
-248
lines changed

12 files changed

+25
-248
lines changed

Utilities/File2Include/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

Utilities/File2Include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if(PLATFORM_WIN32)
1313
if(MSVC)
1414
set(MSVC_DBG_COMPILE_OPTIONS /MTd)
1515
set(MSVC_REL_COMPILE_OPTIONS /MT)
16+
target_compile_options(File2String PRIVATE /wd4996)
1617
target_compile_options(File2String PRIVATE "$<$<CONFIG:DEBUG>:${MSVC_DBG_COMPILE_OPTIONS}>")
1718
target_compile_options(File2String PRIVATE "$<$<CONFIG:RELEASE>:${MSVC_REL_COMPILE_OPTIONS}>")
1819
target_compile_options(File2String PRIVATE "$<$<CONFIG:MINSIZEREL>:${MSVC_REL_COMPILE_OPTIONS}>")
Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// File2Include.cpp : Defines the entry point for the console application.
22
//
33

4-
#include "stdafx.h"
5-
#include "stdio.h"
6-
#include "tchar.h"
4+
#include <stdio.h>
5+
#include <string.h>
76

8-
int _tmain(int argc, _TCHAR* argv[])
7+
int main(int argc, char* argv[])
98
{
109
if( argc < 3 )
1110
{
@@ -14,45 +13,51 @@ int _tmain(int argc, _TCHAR* argv[])
1413
}
1514
auto SrcFile = argv[1];
1615
auto DstFile = argv[2];
17-
FILE *pSrcFile = nullptr;
18-
if( _tfopen_s( &pSrcFile, SrcFile, _T( "r" ) ) != 0 )
16+
if (strcmp(SrcFile, DstFile) == 0)
1917
{
20-
_tprintf( _T("Failed to open source file %s\n"), SrcFile );
18+
printf( "Source and destination files must be different\n");
2119
return -1;
2220
}
2321

24-
FILE *pDstFile = nullptr;
25-
if( _tfopen_s(&pDstFile, DstFile, _T( "w" ) ) != 0 )
22+
FILE *pSrcFile = fopen( SrcFile, "r" );
23+
if( pSrcFile == nullptr )
2624
{
27-
_tprintf( _T("Failed to open destination file %s\n"), DstFile );
25+
printf( "Failed to open source file %s\n", SrcFile );
26+
return -1;
27+
}
28+
29+
FILE *pDstFile = fopen( DstFile, "w" );
30+
if( pDstFile == nullptr )
31+
{
32+
printf( "Failed to open destination file %s\n", DstFile );
2833
fclose(pSrcFile);
2934
return -1;
3035
}
3136

3237

33-
_TCHAR Buff[1024];
34-
_TCHAR SpecialChars[] = _T( "\'\"\\" );
38+
char Buff[2048];
39+
char SpecialChars[] = "\'\"\\";
3540
while( !feof( pSrcFile ) )
3641
{
37-
auto Line = _fgetts( Buff, sizeof( Buff )/sizeof(Buff[0]) , pSrcFile );
42+
auto Line = fgets( Buff, sizeof( Buff )/sizeof(Buff[0]) , pSrcFile );
3843
if( Line == nullptr )
3944
break;
40-
_fputtc( _T( '\"' ), pDstFile );
45+
fputc( '\"', pDstFile );
4146
auto CurrChar = Line;
4247
while( CurrChar && *CurrChar != '\n' )
4348
{
44-
if( _tcschr( SpecialChars, *CurrChar) )
45-
_fputtc( _T( '\\' ), pDstFile );
46-
_fputtc( *CurrChar, pDstFile );
49+
if( strchr( SpecialChars, *CurrChar) )
50+
fputc( '\\', pDstFile );
51+
fputc( *CurrChar, pDstFile );
4752
++CurrChar;
4853
}
49-
_fputts( _T("\\n\"\n"), pDstFile );
54+
fputs( "\\n\"\n", pDstFile );
5055
}
5156

5257
fclose(pDstFile);
5358
fclose(pSrcFile);
5459

55-
_tprintf( _T("File2String: sucessfully converted %s to %s\n"), SrcFile, DstFile );
60+
printf( "File2String: sucessfully converted %s to %s\n", SrcFile, DstFile );
5661

5762
return 0;
5863
}

Utilities/File2Include/File2String.sln

Lines changed: 0 additions & 22 deletions
This file was deleted.

Utilities/File2Include/File2String.vcxproj

Lines changed: 0 additions & 98 deletions
This file was deleted.

Utilities/File2Include/File2String.vcxproj.filters

Lines changed: 0 additions & 36 deletions
This file was deleted.

Utilities/File2Include/ReadMe.txt

Lines changed: 0 additions & 40 deletions
This file was deleted.
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Utilities/File2Include/stdafx.cpp

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)