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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "classcheck_util.h"
#include "icodeprocessor.h"
#include "tier1/strtools.h"
#include "tier0/dbg.h"
SpewRetval_t SpewFunc( SpewType_t type, char const *pMsg )
{
printf( "%s", pMsg );
OutputDebugString( pMsg );
if ( type == SPEW_ERROR )
{
printf( "\n" );
OutputDebugString( "\n" );
}
return SPEW_CONTINUE;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void printusage( void )
{
vprint( 0, "usage: classcheck -q -h -m -t <root source directory> <game: hl2 | tf2>\n\
\t-q = quiet\n\
\t-h = print class hierarchy\n\
\t-m = don't print member functions/variables of class\n\
\t-t = don't print type description errors\n\
\t-p = don't print prediction description errors\n\
\t-c = create missing save descriptions\n\
\t-x = create missing prediction descriptions\n\
\t-i = specify specific input file to parse\n\
\t-b = similar to -i, allows specifying files outside client\\server directories\n\
\t-j = check for Crazy Jay Stelly's mismatched Hungarian notation errors\n\
\t-l = log to file log.txt\n" );
// Exit app
exit( 1 );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *sourcetreebase -
// *subdir -
// *baseentityclass -
//-----------------------------------------------------------------------------
void ProcessDirectory( const char *game, const char *sourcetreebase, const char *subdir, const char *baseentityclass )
{
char rootdirectory[ 256 ];
sprintf( rootdirectory, "%s\\%s", sourcetreebase, subdir );
// check for existence
if ( COM_DirectoryExists( rootdirectory ) )
{
processor->Process( baseentityclass, game, sourcetreebase, subdir );
}
else
{
vprint( 0, "Couldn't find directory %s, check path %s\n", rootdirectory, sourcetreebase );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *sourcetreebase -
// *subdir -
// *baseentityclass -
//-----------------------------------------------------------------------------
void ProcessFile( const char *game, const char *sourcetreebase, const char *subdir, const char *baseentityclass, const char *pFileName )
{
char rootdirectory[ 256 ];
sprintf( rootdirectory, "%s\\%s", sourcetreebase, subdir );
// check for existence
if ( COM_DirectoryExists( rootdirectory ) )
{
processor->Process( baseentityclass, game, sourcetreebase, subdir, pFileName );
}
else
{
vprint( 0, "Couldn't find directory %s, check path %s\n", rootdirectory, sourcetreebase );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CheckLogFile( void )
{
if ( processor->GetLogFile() )
{
_unlink( "log.txt" );
vprint( 0, " Outputting to log.txt\n" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : argc -
// argv[] -
// Output : int
//-----------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
SpewOutputFunc( SpewFunc );
vprint( 0, "Valve Software - classcheck.exe (%s)\n", __DATE__ );
vprint( 0, "--- Game Code Static Analysis ---\n" );
char *pSpecificFile = NULL;
bool bOutsideGamedir = false;
int i = 1;
for ( i ; i<argc ; i++)
{
if ( argv[ i ][ 0 ] == '-' )
{
switch( argv[ i ][ 1 ] )
{
case 'q':
processor->SetQuiet( true );
break;
case 'h':
processor->SetPrintHierarchy( true );
break;
case 'm':
processor->SetPrintMembers( false );
break;
case 't':
processor->SetPrintTDs( false );
break;
case 'p':
processor->SetPrintPredTDs( false );
break;
case 'c':
processor->SetPrintCreateMissingTDs( true );
break;
case 'x':
processor->SetPrintCreateMissingPredTDs( true );
break;
case 'i':
if (i < argc-1)
{
pSpecificFile = argv[i+1];
++i;
}
break;
case 'b':
if (i < argc-1)
{
pSpecificFile = argv[i+1];
bOutsideGamedir = true;
++i;
}
break;
case 'l':
processor->SetLogFile( true );
break;
case 'j':
processor->SetCheckHungarian( true );
break;
default:
printusage();
break;
}
}
}
if ( argc < 3 || ( i != argc ) )
{
printusage();
}
CheckLogFile();
vprint( 0, " Looking for obvious screwups and boneheaded mistakes...\n" );
char sourcetreebase[ 256 ];
strcpy( sourcetreebase, argv[i-2] );
Q_StripTrailingSlash( sourcetreebase );
if ( !pSpecificFile )
{
ProcessDirectory( argv[ i-1 ], sourcetreebase, "server", "CBaseEntity" );
ProcessDirectory( argv[ i-1 ], sourcetreebase, "client", "C_BaseEntity" );
}
else
{
if ( bOutsideGamedir )
{
ProcessFile( argv[ i-1 ], sourcetreebase, "", "", pSpecificFile );
}
else
{
ProcessFile( argv[ i-1 ], sourcetreebase, "server", "CBaseEntity", pSpecificFile );
ProcessFile( argv[ i-1 ], sourcetreebase, "client", "C_BaseEntity", pSpecificFile );
}
}
return 0;
}
|