Skip to content

Commit

Permalink
Refactoring: Modernize libversion
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Nov 13, 2023
1 parent 91f3785 commit e29c4a5
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion addon/doxyapp/doxyapp.cpp
Expand Up @@ -238,7 +238,7 @@ int main(int argc,char **argv)
}
else if (!strcmp(argv[1],"--version"))
{
printf("%s version: %s\n",argv[0],getFullVersion());
printf("%s version: %s\n",argv[0],getFullVersion().c_str());
exit(0);
}
}
Expand Down
2 changes: 1 addition & 1 deletion addon/doxyparse/doxyparse.cpp
Expand Up @@ -430,7 +430,7 @@ int main(int argc,char **argv) {
}
else if (!strcmp(argv[1],"--version"))
{
printf("%s version: %s\n",argv[0],getFullVersion());
printf("%s version: %s\n",argv[0],getFullVersion().c_str());
exit(0);
}
}
Expand Down
6 changes: 3 additions & 3 deletions addon/doxywizard/doxywizard.cpp
Expand Up @@ -266,7 +266,7 @@ void MainWindow::about()
QString msg;
QTextStream t(&msg,QIODevice::WriteOnly);
t << QString::fromLatin1("<qt><center>A tool to configure and run doxygen version ")+
QString::fromLatin1(getDoxygenVersion())+
QString::fromLatin1(getDoxygenVersion().c_str())+
QString::fromLatin1(" on your source files.</center>")+
QString::fromLatin1("<center>(Created with Qt version ")+
QString::fromLatin1(QT_VERSION_STR);
Expand Down Expand Up @@ -811,11 +811,11 @@ int main(int argc,char **argv)
QMessageBox msgBox;
if (!qstrcmp(qVersion(),QT_VERSION_STR))
{
msgBox.setText(QString::fromLatin1("Doxywizard version: %1, Qt version: %2").arg(QString::fromLatin1(getFullVersion()),QString::fromLatin1(QT_VERSION_STR)));
msgBox.setText(QString::fromLatin1("Doxywizard version: %1, Qt version: %2").arg(QString::fromLatin1(getFullVersion().c_str()),QString::fromLatin1(QT_VERSION_STR)));
}
else
{
msgBox.setText(QString::fromLatin1("Doxywizard version: %1, Qt version: created with %2, running with %3").arg(QString::fromLatin1(getFullVersion()),QString::fromLatin1(QT_VERSION_STR),QString::fromLatin1(qVersion())));
msgBox.setText(QString::fromLatin1("Doxywizard version: %1, Qt version: created with %2, running with %3").arg(QString::fromLatin1(getFullVersion().c_str()),QString::fromLatin1(QT_VERSION_STR),QString::fromLatin1(qVersion())));
}
msgBox.exec();
exit(0);
Expand Down
2 changes: 1 addition & 1 deletion addon/doxywizard/expert.cpp
Expand Up @@ -846,7 +846,7 @@ void Expert::saveTopic(QTextStream &t,QDomElement &elem,TextCodecAdapter *codec,
bool Expert::writeConfig(QTextStream &t,bool brief, bool condensed)
{
// write global header
t << "# Doxyfile " << getDoxygenVersion() << "\n\n";
t << "# Doxyfile " << getDoxygenVersion().c_str() << "\n\n";
if (!brief && !condensed)
{
t << convertToComment(m_header);
Expand Down
5 changes: 2 additions & 3 deletions libversion/doxyversion.cpp.in
@@ -1,7 +1,6 @@
#include "version.h"

const char *getDoxygenVersion(void)
std::string getDoxygenVersion()
{
static char versionString[] = "@DOXYGEN_VERSION@";
return versionString;
return "@DOXYGEN_VERSION@";
}
18 changes: 6 additions & 12 deletions libversion/fullversion.cpp
@@ -1,22 +1,16 @@
#include <string.h>
#include <version.h>

const char *getFullVersion(void)
std::string getFullVersion()
{
#define BUF_SIZE 100
static char fullVersionString[BUF_SIZE];
static std::string fullVersion;
static bool init = false;
if (!init)
{
strncpy(fullVersionString,getDoxygenVersion(),BUF_SIZE-1);
if (strlen(getGitVersion())>0)
{
strncat(fullVersionString," (",BUF_SIZE-1);
strncat(fullVersionString,getGitVersion(),BUF_SIZE-1);
strncat(fullVersionString,")",BUF_SIZE-1);
}
fullVersionString[BUF_SIZE-1]='\0';
fullVersion = getDoxygenVersion();
std::string gitVersion = getGitVersion();
if (!gitVersion.empty()) fullVersion+=" ("+gitVersion+")";
init = true;
}
return fullVersionString;
return fullVersion;
}
20 changes: 12 additions & 8 deletions libversion/gitversion.cpp.in
Expand Up @@ -6,18 +6,22 @@
* - No git information is present (no .git directory)
* in those cases clear the gitVersionString (would have string GIT-NOTFOUND).
*/
const char *getGitVersion(void)
std::string getGitVersion()
{
#define BUF_SIZE 100
static char gitVersionString[BUF_SIZE];
static std::string gitVersion;
static bool init = false;
if (!init)
{
strncpy(gitVersionString,"@GIT_HEAD_SHA1@",BUF_SIZE-1);
strncat(gitVersionString,!strcmp("@GIT_IS_DIRTY@","true")?"*":"",BUF_SIZE-1);
if (!strcmp("@GIT_HEAD_SHA1@", "GIT-NOTFOUND")) gitVersionString[0] = '\0';
gitVersionString[BUF_SIZE-1]='\0';
gitVersion = "@GIT_HEAD_SHA1@";
if (std::string("@GIT_IS_DIRTY@")=="true")
{
gitVersion+="*";
}
if (gitVersion=="GIT_NOTFOUND")
{
gitVersion="";
}
init = true;
}
return gitVersionString;
return gitVersion;
}
10 changes: 7 additions & 3 deletions libversion/version.h
Expand Up @@ -15,7 +15,11 @@

#ifndef VERSION_H
#define VERSION_H
const char *getDoxygenVersion(void);
const char *getGitVersion(void);
const char *getFullVersion(void);

#include <string>

std::string getDoxygenVersion();
std::string getGitVersion();
std::string getFullVersion();

#endif
5 changes: 3 additions & 2 deletions src/doxygen.cpp
Expand Up @@ -11487,9 +11487,10 @@ static void writeTagFile()
TextStream tagFile(&f);
tagFile << "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
tagFile << "<tagfile doxygen_version=\"" << getDoxygenVersion() << "\"";
if (strlen(getGitVersion())>0)
std::string gitVersion = getGitVersion();
if (!gitVersion.empty())
{
tagFile << " doxygen_gitid=\"" << getGitVersion() << "\"";
tagFile << " doxygen_gitid=\"" << gitVersion << "\"";
}
tagFile << ">\n";

Expand Down

0 comments on commit e29c4a5

Please sign in to comment.