Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Define __cdecl for non-Microsoft compilers */
#if ( !defined(_MSC_VER) && !defined(__cdecl) )
#define __cdecl
#endif
#include <ctime>
using namespace std;
#include "cmdline.h"
#include "gcd.h"
using namespace pictcli_gcd;
//
//
//
void printTimeDifference( time_t start, time_t end )
{
int diff = static_cast<int> ( difftime( end, start ) );
// hours
int hrs = diff / 3600;
wcout << hrs << L":";
// minutes
diff -= hrs * 3600;
int mins = diff / 60;
wcout << ( mins < 10 ? L"0" : L"" ) << mins << L":";
// seconds
diff -= mins * 60;
wcout << ( diff < 10 ? L"0" : L"" ) << diff;
wcout << endl;
}
//
//
//
int __cdecl wmain
(
IN int argc,
IN wchar_t* args[]
)
{
time_t start = time( NULL );
CModelData modelData;
if( !ParseArgs( argc, args, modelData ) )
{
return( ErrorCode_BadOption );
}
if( !modelData.ReadModel( static_cast<wstring&> ( wstring( args[ 1 ] ))))
{
return( ErrorCode_BadModel );
}
if( !modelData.ReadRowSeedFile( modelData.RowSeedsFile ))
{
return( ErrorCode_BadRowSeedFile );
}
GcdRunner gcdRunner( modelData );
ErrorCode err = gcdRunner.Generate();
if( err != ErrorCode_Success )
{
return err;
}
time_t end = time( NULL );
// if r has been provided then print out the seed
// TODO: change to not use SWITCH_RANDOMIZE const
if( modelData.ProvidedArguments.find( SWITCH_RANDOMIZE ) != modelData.ProvidedArguments.end() )
{
wcerr << L"Used seed: " << static_cast<int>( modelData.RandSeed ) << endl;
}
CResult result = gcdRunner.GetResult();
if( modelData.Statistics )
{
modelData.PrintStatistics();
result.PrintStatistics();
PrintStatisticsCaption( static_cast<wstring&> ( wstring( L"Generation time" )));
printTimeDifference( start, end );
}
else
{
result.PrintConstraintWarnings();
result.PrintOutput( modelData );
}
return( ErrorCode_Success );
}
#if !defined(_MSC_VER)
//
// Gcc doesn't understand wchar_t args
// This entry point is a workaround for compiling with a non-MS compiler
//
int main
(
IN int argc,
IN char* args[]
)
{
// convert all args to wchar_t's
wchar_t** wargs = new wchar_t*[ argc ];
for ( int ii = 0; ii < argc; ++ii )
{
size_t len = strlen( args[ ii ] );
wargs[ ii ] = new wchar_t[ len + 1 ];
for( size_t jj = 0; jj < len; ++jj )
{
wargs[ ii ][ jj ] = (wchar_t) args[ ii ][ jj ];
}
wargs[ ii ][ jj ] = L'\0';
}
// invoke wmain
int ret = wmain( argc, wargs );
// clean up
for ( int ii = 0; ii < argc; ++ii )
{
delete wargs[ ii ];
}
delete wargs;
return( ret );
}
#endif