mirror of
https://github.com/isledecomp/actionheadergen.git
synced 2024-11-23 07:47:58 -05:00
generate special header for forward declarations
This commit is contained in:
parent
ade9bd1d3f
commit
0c9856fbbb
3 changed files with 68 additions and 23 deletions
|
@ -7,7 +7,9 @@
|
|||
|
||||
class HeaderGenerator {
|
||||
public:
|
||||
bool CreateForwardDeclHeader(char *p_outputDir);
|
||||
bool GenerateHeader(char *p_interleafName, std::map<size_t, std::string> *p_actionMap, char *p_outputDir);
|
||||
std::ofstream m_declFout;
|
||||
|
||||
private:
|
||||
bool CreateHeader(char *p_interleafName, char *p_outputDir);
|
||||
|
|
|
@ -16,11 +16,21 @@ const char *g_enumEntryPrefix = "c_";
|
|||
// notice to not edit autogenerated headers
|
||||
const char *g_doNotEditNotice = "// This file was automatically generated by the actionheadergen tool.\n// Please do not manually edit this file.\n";
|
||||
|
||||
bool HeaderGenerator::CreateForwardDeclHeader(char *p_outputDir)
|
||||
{
|
||||
// attempt to create special forward decl header
|
||||
if (!CreateHeader("", p_outputDir)) {
|
||||
printf("Failed to create forward declaration header, check file permissions?\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HeaderGenerator::GenerateHeader(char *p_interleafName, std::map<size_t, std::string> *p_actionMap, char *p_outputDir)
|
||||
{
|
||||
// attempt to create header file
|
||||
if (!CreateHeader(p_interleafName, p_outputDir)) {
|
||||
printf("Failed to create header, check file permissions?\n");
|
||||
printf("Failed to create Interleaf header, check file permissions?\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -38,7 +48,9 @@ bool HeaderGenerator::CreateHeader(char *p_interleafName, char *p_outputDir)
|
|||
{
|
||||
char headerName[1024];
|
||||
char outputPath[2048];
|
||||
bool decl = false;
|
||||
|
||||
if (strcmp(p_interleafName, "") != 0) {
|
||||
strcpy(m_normalizedInlfName, p_interleafName);
|
||||
|
||||
// format Interleaf name to mostly lowercase,
|
||||
|
@ -56,18 +68,36 @@ bool HeaderGenerator::CreateHeader(char *p_interleafName, char *p_outputDir)
|
|||
|
||||
// append the generic extension
|
||||
strcat(headerName, g_headerExt);
|
||||
}
|
||||
else {
|
||||
decl = true;
|
||||
strcpy(headerName, "actionsfwd.h");
|
||||
}
|
||||
|
||||
// generate the full path of the output file
|
||||
strcpy(outputPath, p_outputDir);
|
||||
strcat(outputPath, "/");
|
||||
strcat(outputPath, headerName);
|
||||
|
||||
if (!decl) {
|
||||
m_fout.open(outputPath);
|
||||
|
||||
// make sure we can actually create this file
|
||||
if (!m_fout.is_open()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_declFout.open(outputPath);
|
||||
|
||||
// make sure we can actually create this file
|
||||
if (!m_declFout.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_declFout << g_doNotEditNotice;
|
||||
m_declFout << "#ifndef ACTIONSFWD_H\n#define ACTIONSFWD_H\n\n";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -96,12 +126,15 @@ bool HeaderGenerator::WriteHeader(char *p_interleafName, std::map<size_t, std::s
|
|||
|
||||
// we need to scope this enum to avoid conflicts
|
||||
m_fout << "namespace " << m_normalizedInlfName << "Script\n{\n";
|
||||
m_declFout << "namespace " << m_normalizedInlfName << "Script\n{\n";
|
||||
|
||||
// add ifdefs for conditional compilation (decomp requirement)
|
||||
m_fout << "#ifdef COMPAT_MODE\nenum Script : int {\n#else\n";
|
||||
m_declFout << "#ifdef COMPAT_MODE\nenum Script : int;\n#else\n";
|
||||
|
||||
// declare enum
|
||||
m_fout << "enum Script {\n#endif\n";
|
||||
m_declFout << "enum Script;\n#endif\n";
|
||||
|
||||
// add generic "none" state to the enum
|
||||
m_fout << "\tc_none" << m_normalizedInlfName << " = -1,\n\n";
|
||||
|
@ -122,6 +155,7 @@ bool HeaderGenerator::WriteHeader(char *p_interleafName, std::map<size_t, std::s
|
|||
// some compilers don't accept extremely large enums,
|
||||
// so we split them up here in case of 2000+ entries
|
||||
m_fout << "};\n\n#ifdef COMPAT_MODE\nenum Script2 : int {\n#else\nenum Script2 {\n#endif\n";
|
||||
m_declFout << "\n#ifdef COMPAT_MODE\nenum Script2 : int;\n#else\nenum Script2;\n#endif\n";
|
||||
}
|
||||
|
||||
// actually write the enum entry
|
||||
|
@ -137,6 +171,7 @@ bool HeaderGenerator::WriteHeader(char *p_interleafName, std::map<size_t, std::s
|
|||
|
||||
// all done with actions, so lets close the enum and namespace
|
||||
m_fout << "};\n} // namespace " << m_normalizedInlfName << "Script\n\n";
|
||||
m_declFout << "} // namespace " << m_normalizedInlfName << "\n\n";
|
||||
|
||||
// finally, close the include guard
|
||||
m_fout << "#endif // " << guardName << "\n";
|
||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -80,6 +80,13 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
else interleafFiles.push_back(filePath); // we were provided a single file, but we'll still use the vector
|
||||
|
||||
// generate special forward declaration header
|
||||
HeaderGenerator hgenerator;
|
||||
|
||||
if (!hgenerator.CreateForwardDeclHeader(outputDir)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// iterate through every Interleaf in the vector and perform our operations
|
||||
for (int i = 0; i < interleafFiles.size(); i++) {
|
||||
|
||||
|
@ -116,8 +123,6 @@ int main(int argc, char *argv[])
|
|||
filename = filename + 1;
|
||||
}
|
||||
|
||||
HeaderGenerator hgenerator;
|
||||
|
||||
// generate the actual header
|
||||
// we use the Interleaf name for the filename
|
||||
// and the vector previously generated to make the enum data
|
||||
|
@ -135,6 +140,9 @@ int main(int argc, char *argv[])
|
|||
printf("Successfully generated header for %s\n", filename);
|
||||
}
|
||||
|
||||
hgenerator.m_declFout << "#endif // ACTIONSFWD_H";
|
||||
hgenerator.m_declFout.close();
|
||||
|
||||
printf("Finished!\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue