From 0c9856fbbba623fa4c925a5c0fb1397957648f9e Mon Sep 17 00:00:00 2001 From: Ramen2X Date: Tue, 19 Mar 2024 15:04:20 -0400 Subject: [PATCH] generate special header for forward declarations --- include/headergenerator.h | 2 + src/headergenerator.cpp | 77 ++++++++++++++++++++++++++++----------- src/main.cpp | 12 +++++- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/include/headergenerator.h b/include/headergenerator.h index a51730c..716c233 100644 --- a/include/headergenerator.h +++ b/include/headergenerator.h @@ -7,7 +7,9 @@ class HeaderGenerator { public: + bool CreateForwardDeclHeader(char *p_outputDir); bool GenerateHeader(char *p_interleafName, std::map *p_actionMap, char *p_outputDir); + std::ofstream m_declFout; private: bool CreateHeader(char *p_interleafName, char *p_outputDir); diff --git a/src/headergenerator.cpp b/src/headergenerator.cpp index d238d9f..3508d71 100644 --- a/src/headergenerator.cpp +++ b/src/headergenerator.cpp @@ -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 *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,35 +48,55 @@ bool HeaderGenerator::CreateHeader(char *p_interleafName, char *p_outputDir) { char headerName[1024]; char outputPath[2048]; + bool decl = false; - strcpy(m_normalizedInlfName, p_interleafName); + if (strcmp(p_interleafName, "") != 0) { + strcpy(m_normalizedInlfName, p_interleafName); - // format Interleaf name to mostly lowercase, - // to make acceptable by decomp styling guidelines - for (int i = 1; i < strlen(p_interleafName); i++) { - m_normalizedInlfName[i] = tolower(m_normalizedInlfName[i]); + // format Interleaf name to mostly lowercase, + // to make acceptable by decomp styling guidelines + for (int i = 1; i < strlen(p_interleafName); i++) { + m_normalizedInlfName[i] = tolower(m_normalizedInlfName[i]); + } + + // set the header name to the Interleaf name + strcpy(headerName, m_normalizedInlfName); + + // set first character to lowercase, which + // was skipped by the previous operation + headerName[0] = tolower(headerName[0]); + + // append the generic extension + strcat(headerName, g_headerExt); + } + else { + decl = true; + strcpy(headerName, "actionsfwd.h"); } - - // set the header name to the Interleaf name - strcpy(headerName, m_normalizedInlfName); - - // set first character to lowercase, which - // was skipped by the previous operation - headerName[0] = tolower(headerName[0]); - - // append the generic extension - strcat(headerName, g_headerExt); // generate the full path of the output file strcpy(outputPath, p_outputDir); strcat(outputPath, "/"); strcat(outputPath, headerName); - m_fout.open(outputPath); + if (!decl) { + m_fout.open(outputPath); - // make sure we can actually create this file - if (!m_fout.is_open()) { - return false; + // 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