doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CreateResourceIDs.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 
33 /*
34 ================
35 CreateResourceIDs_f
36 ================
37 */
38 void CreateResourceIDs_f( const idCmdArgs &args ) {
39  int i, j;
40  idStr path, fileName;
41  idStrList resourceFiles;
42  idLexer src;
43  idToken token;
44  idStrList dialogs;
45  idStrList resources;
46  idStrList bitmaps;
47  idStrList icons;
48  idStrList strings;
49  idStrList controls;
50  idStrList commands;
51 
52  if ( args.Argc() > 1 ) {
53  path = args.Argv(1);
54  } else {
55  path = SOURCE_CODE_BASE_FOLDER"/";
56  path.Append( __FILE__ );
57  path.StripFilename();
58  path.BackSlashesToSlashes();
59  }
60 
61  common->Printf( "%s\n", path.c_str() );
62  Sys_ListFiles( path, "_resource.h", resourceFiles );
63 
64  for ( i = 0; i < resourceFiles.Num(); i++ ) {
65 
66  fileName = path + "/" + resourceFiles[i];
67 
68  common->Printf( "creating IDs for %s...\n", fileName.c_str() );
69 
70  if ( !src.LoadFile( fileName, true ) ) {
71  common->Warning( "couldn't load %s", fileName.c_str() );
72  continue;
73  }
74 
75  dialogs.Clear();
76  resources.Clear();
77  bitmaps.Clear();
78  icons.Clear();
79  strings.Clear();
80  controls.Clear();
81  commands.Clear();
82 
83  while( src.ReadToken( &token ) ) {
84  if ( token == "#" ) {
85  src.ExpectAnyToken( &token );
86  if ( token == "ifdef" || token == "ifndef" ) {
87  src.SkipRestOfLine();
88  } else if ( token == "define" ) {
89  src.ExpectTokenType( TT_NAME, 0, &token );
90 
91  if ( token.Icmpn( "_APS_", 5 ) == 0 ) {
92  continue;
93  }
94 
95  if ( token.Icmpn( "IDD_", 4 ) == 0 ) {
96  dialogs.AddUnique( token );
97  } else if ( token.Icmpn( "IDR_", 4 ) == 0 ) {
98  resources.AddUnique( token );
99  } else if ( token.Icmpn( "IDB_", 4 ) == 0 ) {
100  bitmaps.AddUnique( token );
101  } else if ( token.Icmpn( "IDI_", 4 ) == 0 ) {
102  icons.AddUnique( token );
103  } else if ( token.Icmpn( "IDS_", 4 ) == 0 ||
104  token.Icmpn( "IDP_", 4 ) == 0 ) {
105  strings.AddUnique( token );
106  } else if ( token.Icmpn( "IDC_", 4 ) == 0 ) {
107  controls.AddUnique( token );
108  } else {
109  commands.AddUnique( token );
110  }
111  }
112  }
113  }
114 
115  src.FreeSource();
116 
117  idFile *f;
118  int curResource, curControl, curCommand;
119 
120  curResource = i ? i * 1000 : 100;
121  curCommand = 20000 + i * 1000;
122  curControl = i * 1000 + 200;
123 
124  f = fileSystem->OpenExplicitFileWrite( fileName );
125  if ( !f ) {
126  common->Warning( "couldn't write %s", fileName.c_str() );
127  continue;
128  }
129 
130  f->WriteFloatString( "//{{NO_DEPENDENCIES}}\n"
131  "// Microsoft Visual C++ generated include file.\n"
132  "// Used by .rc\n"
133  "//\n\n" );
134 
135  for ( j = 0; j < dialogs.Num(); j++ ) {
136  f->WriteFloatString( "#define %-40s %d\n", dialogs[j].c_str(), curResource++ );
137  }
138  for ( j = 0; j < resources.Num(); j++ ) {
139  f->WriteFloatString( "#define %-40s %d\n", resources[j].c_str(), curResource++ );
140  }
141  for ( j = 0; j < bitmaps.Num(); j++ ) {
142  f->WriteFloatString( "#define %-40s %d\n", bitmaps[j].c_str(), curResource++ );
143  }
144  for ( j = 0; j < icons.Num(); j++ ) {
145  f->WriteFloatString( "#define %-40s %d\n", icons[j].c_str(), curResource++ );
146  }
147  for ( j = 0; j < strings.Num(); j++ ) {
148  f->WriteFloatString( "#define %-40s %d\n", strings[j].c_str(), curResource++ );
149  }
150 
151  f->WriteFloatString( "\n" );
152 
153  for ( j = 0; j < controls.Num(); j++ ) {
154  f->WriteFloatString( "#define %-40s %d\n", controls[j].c_str(), curControl++ );
155  }
156 
157  f->WriteFloatString( "\n" );
158 
159  for ( j = 0; j < commands.Num(); j++ ) {
160 
161  // NOTE: special hack for Radiant
162  if ( commands[j].Cmp( "ID_ENTITY_START" ) == 0 ) {
163  f->WriteFloatString( "#define %-40s %d\n", commands[j].c_str(), 40000 );
164  continue;
165  }
166  if ( commands[j].Cmp( "ID_ENTITY_END" ) == 0 ) {
167  f->WriteFloatString( "#define %-40s %d\n", commands[j].c_str(), 45000 );
168  continue;
169  }
170 
171  f->WriteFloatString( "#define %-40s %d\n", commands[j].c_str(), curCommand++ );
172  }
173 
174 
175  f->WriteFloatString( "\n// Next default values for new objects\n"
176  "// \n"
177  "#ifdef APSTUDIO_INVOKED\n"
178  "#ifndef APSTUDIO_READONLY_SYMBOLS\n"
179  "#define _APS_3D_CONTROLS 1\n"
180  "#define _APS_NEXT_RESOURCE_VALUE %d\n"
181  "#define _APS_NEXT_COMMAND_VALUE %d\n"
182  "#define _APS_NEXT_CONTROL_VALUE %d\n"
183  "#define _APS_NEXT_SYMED_VALUE %d\n"
184  "#endif\n"
185  "#endif\n", curResource, curCommand, curControl, curResource );
186 
187  fileSystem->CloseFile( f );
188  }
189 }
#define SOURCE_CODE_BASE_FOLDER
Definition: Licensee.h:54
void FreeSource(void)
Definition: Lexer.cpp:1676
#define TT_NAME
Definition: Token.h:44
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
Definition: Token.h:71
GLuint src
Definition: glext.h:5390
int i
Definition: process.py:33
idStr & BackSlashesToSlashes(void)
Definition: Str.cpp:727
int ExpectAnyToken(idToken *token)
Definition: Lexer.cpp:992
int Icmpn(const char *text, int n) const
Definition: Str.h:672
Definition: File.h:50
Definition: Lexer.h:137
int Sys_ListFiles(const char *directory, const char *extension, idStrList &list)
Definition: posix_main.cpp:198
int ExpectTokenType(int type, int subtype, idToken *token)
Definition: Lexer.cpp:938
idCommon * common
Definition: Common.cpp:206
const char * path
Definition: sws.c:117
int Argc(void) const
Definition: CmdArgs.h:48
virtual int WriteFloatString(const char *fmt,...) id_attribute((format(printf
Definition: File.cpp:294
virtual void Printf(const char *fmt,...) id_attribute((format(printf
virtual idFile * OpenExplicitFileWrite(const char *OSPath)=0
int AddUnique(const type &obj)
Definition: List.h:742
tuple f
Definition: idal.py:89
void Append(const char a)
Definition: Str.h:729
int Num(void) const
Definition: List.h:265
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
const char * Argv(int arg) const
Definition: CmdArgs.h:50
GLint j
Definition: qgl.h:264
virtual void CloseFile(idFile *f)=0
int SkipRestOfLine(void)
Definition: Lexer.cpp:1113
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
int ReadToken(idToken *token)
Definition: Lexer.cpp:820
idStr & StripFilename(void)
Definition: Str.cpp:864
int LoadFile(const char *filename, bool OSPath=false)
Definition: Lexer.cpp:1591
void Clear(void)
Definition: List.h:184
void CreateResourceIDs_f(const idCmdArgs &args)