Replaced updaterevision with a python script, more renames, clang fixes

Sat, 22 Aug 2015 19:37:01 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 22 Aug 2015 19:37:01 +0300
changeset 948
3a91828475fd
parent 947
edc8fc0f37f2
child 949
a9ba8ffd9534

Replaced updaterevision with a python script, more renames, clang fixes

CMakeLists.txt file | annotate | diff | comparison | revisions
src/colorSelector.h file | annotate | diff | comparison | revisions
src/dialogs.cc file | annotate | diff | comparison | revisions
src/editHistory.h file | annotate | diff | comparison | revisions
src/editmodes/drawMode.h file | annotate | diff | comparison | revisions
src/editmodes/selectMode.h file | annotate | diff | comparison | revisions
src/mainWindow.cc file | annotate | diff | comparison | revisions
src/mainWindow.h file | annotate | diff | comparison | revisions
src/version.cc file | annotate | diff | comparison | revisions
src/version.h file | annotate | diff | comparison | revisions
ui/colorsel.ui file | annotate | diff | comparison | revisions
updaterevision/CMakeLists.txt file | annotate | diff | comparison | revisions
updaterevision/updaterevision.c file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Sat Aug 22 18:14:53 2015 +0300
+++ b/CMakeLists.txt	Sat Aug 22 19:37:01 2015 +0300
@@ -6,7 +6,6 @@
 ######################################################################
 
 project (ldforge)
-add_subdirectory (updaterevision)
 add_subdirectory (codegen)
 cmake_minimum_required (VERSION 2.6)
 
@@ -25,13 +24,11 @@
 
 find_package (OpenGL REQUIRED)
 
-get_target_property (UPDATEREVISION_EXE updaterevision LOCATION)
 get_target_property (CODEGEN_EXE codegen LOCATION)
 
 add_custom_target (revision_check ALL
-	COMMAND ${UPDATEREVISION_EXE} ${CMAKE_SOURCE_DIR} hginfo.h
-	WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-	DEPENDS updaterevision)
+	COMMAND python "${CMAKE_SOURCE_DIR}/updaterevision.py" hginfo.h
+	WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 
 include_directories (${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
 
--- a/src/colorSelector.h	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/colorSelector.h	Sat Aug 22 19:37:01 2015 +0300
@@ -32,7 +32,7 @@
 	static bool selectColor (LDColor& val, LDColor defval = LDColor::nullColor(), QWidget* parent = null);
 
 private:
-	class Ui_ColorSelUI& ui;
+	class Ui_ColorSelUi& ui;
 	QMap<int, QPushButton*> m_buttons;
 	QMap<QPushButton*, int> m_buttonsReversed;
 	bool m_firstResize;
--- a/src/dialogs.cc	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/dialogs.cc	Sat Aug 22 19:37:01 2015 +0300
@@ -346,7 +346,7 @@
 {
 	Ui::AboutUI ui;
 	ui.setupUi (this);
-	ui.versionInfo->setText (APPNAME " " + QString (FullVersionString()));
+	ui.versionInfo->setText (APPNAME " " + QString (fullVersionString()));
 
 	QPushButton* mailButton = new QPushButton;
 	mailButton->setText (tr ("Contact"));
--- a/src/editHistory.h	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/editHistory.h	Sat Aug 22 19:37:01 2015 +0300
@@ -20,19 +20,19 @@
 #include "main.h"
 #include "ldObject.h"
 
-#define IMPLEMENT_HISTORY_TYPE(N)							\
-	virtual ~N##History() {}								\
-	virtual void undo() const override;						\
-	virtual void redo() const override;						\
-															\
-	virtual History::EHistoryType getType() const override	\
-	{														\
-		return History::E##N##History;						\
-	}														\
-															\
-	virtual QString getTypeName() const						\
-	{														\
-		return #N;											\
+#define IMPLEMENT_HISTORY_TYPE(N)					\
+	~N##History() {}								\
+	void undo() const override;						\
+	void redo() const override;						\
+													\
+	History::EHistoryType getType() const override	\
+	{												\
+		return History::E##N##History;				\
+	}												\
+													\
+	QString getTypeName() const override			\
+	{												\
+		return #N;									\
 	}
 
 class AbstractHistoryEntry;
--- a/src/editmodes/drawMode.h	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/editmodes/drawMode.h	Sat Aug 22 19:37:01 2015 +0300
@@ -31,6 +31,6 @@
 	EditModeType type() const override;
 	bool mouseReleased (MouseEventData const& data) override;
 	void endDraw();
-	bool preAddVertex (Vertex const&);
+	bool preAddVertex (Vertex const&) override;
 	Vertex getCursorVertex() const;
 };
--- a/src/editmodes/selectMode.h	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/editmodes/selectMode.h	Sat Aug 22 19:37:01 2015 +0300
@@ -30,10 +30,10 @@
 public:
 	SelectMode (GLRenderer* renderer);
 
-	virtual void render (QPainter& painter) const override;
-	virtual bool mousePressed (QMouseEvent* ev);
-	virtual bool mouseReleased (MouseEventData const& data) override;
-	virtual bool mouseDoubleClicked (QMouseEvent* ev);
-	virtual bool mouseMoved (QMouseEvent*) override;
-	virtual EditModeType type() const override;
+	void render (QPainter& painter) const override;
+	bool mousePressed (QMouseEvent* ev) override;
+	bool mouseReleased (MouseEventData const& data) override;
+	bool mouseDoubleClicked (QMouseEvent* ev) override;
+	bool mouseMoved (QMouseEvent*) override;
+	EditModeType type() const override;
 };
\ No newline at end of file
--- a/src/mainWindow.cc	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/mainWindow.cc	Sat Aug 22 19:37:01 2015 +0300
@@ -266,7 +266,7 @@
 //
 void MainWindow::updateTitle()
 {
-	QString title = format (APPNAME " %1", VersionString());
+	QString title = format (APPNAME " " VERSION_STRING);
 
 	// Append our current file if we have one
 	if (CurrentDocument())
@@ -292,8 +292,8 @@
 	title += " [pre-release build]";
 #endif // DEBUG
 
-	if (CommitTimeString()[0] != '\0')
-		title += format (" (%1)", QString::fromUtf8 (CommitTimeString()));
+	if (strlen (commitTimeString()))
+		title += format (" (%1)", QString::fromUtf8 (commitTimeString()));
 
 	setWindowTitle (title);
 }
--- a/src/mainWindow.h	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/mainWindow.h	Sat Aug 22 19:37:01 2015 +0300
@@ -35,7 +35,7 @@
 class QComboBox;
 class QProgressBar;
 class Ui_LDForgeUI;
-class Primitive;
+struct Primitive;
 
 // Stuff for dialogs
 #define IMPLEMENT_DIALOG_BUTTONS \
--- a/src/version.cc	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/version.cc	Sat Aug 22 19:37:01 2015 +0300
@@ -16,63 +16,33 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-// Note: only using stock C stuff in this file, keeping the STL/Qt stuff out
-// makes this simple file very fast to compile, which is nice since this file
-// must be compiled every time I commit something.
+// This file only uses stock C stuff. Keeping the STL/Qt stuff out  makes this simple file very fast to compile, which
+// is nice since this file must be compiled every time I commit something.
 
-#include <stdio.h>
-#include <string.h>
 #include <time.h>
 #include "version.h"
 #include "hginfo.h"
 
-char g_versionString[64] = {'\0'};
-char g_fullVersionString[256] = {'\0'};
-char g_buildTime[256] = {'\0'};
-
-// =============================================================================
-//
-const char* VersionString()
+const char* fullVersionString()
 {
-	if (g_versionString[0] == '\0')
-	{
-#if VERSION_PATCH == 0
-		sprintf (g_versionString, "%d.%d", VERSION_MAJOR, VERSION_MINOR);
+#if BUILD_ID != BUILD_RELEASE and defined (HG_DATE_VERSION)
+	return VERSION_STRING "-" HG_DATE_VERSION;
 #else
-		sprintf (g_versionString, "%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
-#endif // VERSION_PATCH
-	}
-
-	return g_versionString;
+	return HG_DATE_VERSION;
+#endif
 }
 
-// =============================================================================
-//
-const char* FullVersionString()
+const char* commitTimeString()
 {
-	if (g_fullVersionString[0] == '\0')
-	{
-#if BUILD_ID != BUILD_RELEASE and defined (SVN_REVISION_STRING)
-		sprintf (g_fullVersionString, "%s-" SVN_REVISION_STRING, VersionString());
-#else
-		sprintf (g_fullVersionString, "%s", versionString());
-#endif
-	}
+	static char buffer[256];
 
-	return g_fullVersionString;
-}
-
-// =============================================================================
-//
-const char* CommitTimeString()
-{
-#ifdef SVN_REVISION_NUMBER
-	if (g_buildTime[0] == '\0')
+#ifdef HG_COMMIT_TIME
+	if (buffer[0] == '\0')
 	{
-		time_t timestamp = SVN_REVISION_NUMBER;
-		strftime (g_buildTime, sizeof g_buildTime, "%d %b %Y", localtime (&timestamp));
+		time_t timestamp = HG_COMMIT_TIME;
+		strftime (buffer, sizeof buffer, "%d %b %Y", localtime (&timestamp));
 	}
 #endif
 
-	return g_buildTime;
+	return buffer;
 }
--- a/src/version.h	Sat Aug 22 18:14:53 2015 +0300
+++ b/src/version.h	Sat Aug 22 19:37:01 2015 +0300
@@ -18,19 +18,24 @@
 
 #pragma once
 
-//
-// Application name
-//
 #define APPNAME			"LDForge"
 #define UNIXNAME		"ldforge"
 
-//
-// Version number
-//
+#define MACRO_TO_STRING(X) MACRO_TO_STRING_2(X)
+#define MACRO_TO_STRING_2(X) #X
+
 #define VERSION_MAJOR	0
 #define VERSION_MINOR	4
 #define VERSION_PATCH	0
 
+#define VERSION_MAJOR_MINOR_STRING MACRO_TO_STRING (VERSION_MAJOR) "." MACRO_TO_STRING (VERSION_MINOR)
+
+#if VERSION_PATCH == 0
+# define VERSION_STRING VERSION_MAJOR_MINOR_STRING
+#else
+# define VERSION_STRING VERSION_MAJOR_MINOR_STRING "." MACRO_TO_STRING (VERSION_PATCH)
+#endif
+
 //
 // Build ID, this is BUILD_RELEASE for releases
 //
@@ -46,6 +51,5 @@
 # undef DEBUG
 #endif // RELEASE
 
-const char* VersionString();
-const char* FullVersionString();
-const char* CommitTimeString();
+const char* fullVersionString();
+const char* commitTimeString();
--- a/ui/colorsel.ui	Sat Aug 22 18:14:53 2015 +0300
+++ b/ui/colorsel.ui	Sat Aug 22 19:37:01 2015 +0300
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
- <class>ColorSelUI</class>
- <widget class="QDialog" name="ColorSelUI">
+ <class>ColorSelUi</class>
+ <widget class="QDialog" name="ColorSelUi">
   <property name="geometry">
    <rect>
     <x>0</x>
@@ -105,7 +105,7 @@
   <connection>
    <sender>buttonBox</sender>
    <signal>accepted()</signal>
-   <receiver>ColorSelUI</receiver>
+   <receiver>ColorSelUi</receiver>
    <slot>accept()</slot>
    <hints>
     <hint type="sourcelabel">
@@ -121,7 +121,7 @@
   <connection>
    <sender>buttonBox</sender>
    <signal>rejected()</signal>
-   <receiver>ColorSelUI</receiver>
+   <receiver>ColorSelUi</receiver>
    <slot>reject()</slot>
    <hints>
     <hint type="sourcelabel">
--- a/updaterevision/CMakeLists.txt	Sat Aug 22 18:14:53 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-cmake_minimum_required (VERSION 2.4)
-add_executable (updaterevision updaterevision.c)
\ No newline at end of file
--- a/updaterevision/updaterevision.c	Sat Aug 22 18:14:53 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,192 +0,0 @@
-/* updaterevision.c
- *
- * Public domain. This program uses the svnversion command to get the
- * repository revision for a particular directory and writes it into
- * a header file so that it can be used as a project's build number.
- */
-
-#define _CRT_SECURE_NO_DEPRECATE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-// [BB] New #includes.
-#include <sys/stat.h>
-#include <time.h>
-
-int main(int argc, char **argv)
-{
-    const char *name = "svnout";
-	char currev[64], lastrev[64], run[256], *rev;
-	unsigned long urev;
-	FILE *stream = NULL;
-	int gotrev = 0, needupdate = 1;
-	// [BB] Are we working with a SVN checkout?
-	int svnCheckout = 0;
-	char hgdateString[64];
-	time_t hgdate = 0;
-	char hgHash[13];
-	hgHash[0] = '\0';
-
-	if (argc != 3)
-	{
-		fprintf (stderr, "Usage: %s <repository directory> <path to svnrevision.h>\n", argv[0]);
-		return 1;
-	}
-
-	// [BB] Try to figure out whether this is a SVN or a Hg checkout.
-	{
-		struct stat st;
-		char filename[1024];
-		sprintf ( filename, "%s/.svn/entries", argv[1] );
-		if ( stat ( filename, &st ) == 0 )
-			svnCheckout = 1;
-		// [BB] If stat failed we have to manually clear errno, otherwise the code below doesn't work.
-		else
-			errno = 0;
-	}
-
-	// Use svnversion to get the revision number. If that fails, pretend it's
-	// revision 0. Note that this requires you have the command-line svn tools installed.
-	// [BB] Depending on whether this is a SVN or Hg checkout we have to use the appropriate tool.
-	if ( svnCheckout )
-		sprintf (run, "svnversion -cn %s", argv[1]);
-	else
-		sprintf (run, "hg identify -n"); 
-    // if ((name = tempnam(NULL, "svnout")) != NULL)
-	{
-#ifdef __APPLE__
-		// tempnam will return errno of 2 even though it is successful for our purposes.
-		errno = 0;
-#endif
-		if((stream = freopen(name, "w+b", stdout)) != NULL &&
-		   system(run) == 0 &&
-#ifndef __FreeBSD__
-		   errno == 0 &&
-#endif
-		   fseek(stream, 0, SEEK_SET) == 0 &&
-		   fgets(currev, sizeof currev, stream) == currev &&
-		   (isdigit(currev[0]) || (currev[0] == '-' && currev[1] == '1')))
-		{
-			gotrev = 1;
-			// [BB] Find the date the revision of the working copy was created.
-			if ( ( svnCheckout == 0 ) &&
-				( system("hg log -r. --template \"{date|hgdate} {node|short}\"") == 0 ) &&
-				( fseek(stream, strlen(currev), SEEK_SET) == 0 ) &&
-				( fgets(hgdateString, sizeof ( hgdateString ), stream) == hgdateString ) )
-			{
-				// [BB] Find the hash in the output and store it.
-				char *p = strrchr ( hgdateString, ' ' );
-				strncpy ( hgHash, p ? ( p+1 ) : "hashnotfound" , sizeof( hgHash ) - 1 );
-				hgHash[ sizeof ( hgHash ) - 1 ] = '\0';
-				// [BB] Extract the date from the output and store it.
-				hgdate = atoi ( hgdateString );
-			}
-		}
-	}
-	if (stream != NULL)
-	{
-		fclose (stream);
-		remove (name);
-	}
-    /*if (name != NULL)
-	{
-		free (name);
-    }*/
-
-	if (!gotrev)
-	{
-		fprintf (stderr, "Failed to get current revision: %s\n", strerror(errno));
-		strcpy (currev, "0");
-		rev = currev;
-	}
-	else
-	{
-		rev = strchr (currev, ':');
-		if (rev == NULL)
-		{
-			rev = currev;
-		}
-		else
-		{
-			rev += 1;
-		}
-	}
-
-	// [BB] Create date version string.
-	if ( gotrev && ( svnCheckout == 0 ) )
-	{
-		char *endptr;
-		unsigned long parsedRev = strtoul(rev, &endptr, 10);
-		unsigned int localChanges = ( *endptr == '+' );
-		struct tm	*lt = gmtime( &hgdate );
-		if ( localChanges )
-			sprintf ( rev, "%d%02d%02d-%02d%02dM", lt->tm_year - 100, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min);
-		else
-			sprintf ( rev, "%d%02d%02d-%02d%02d", lt->tm_year - 100, lt->tm_mon + 1, lt->tm_mday, lt->tm_hour, lt->tm_min);
-	}
-
-	stream = fopen (argv[2], "r");
-	if (stream != NULL)
-	{
-		if (!gotrev)
-		{ // If we didn't get a revision but the file does exist, leave it alone.
-			fprintf( stderr, "No revision found.\n" );
-			fclose (stream);
-			return 0;
-		}
-		// Read the revision that's in this file already. If it's the same as
-		// what we've got, then we don't need to modify it and can avoid rebuilding
-		// dependant files.
-		if (fgets(lastrev, sizeof lastrev, stream) == lastrev)
-		{
-			if (lastrev[0] != '\0')
-			{ // Strip trailing \n
-				lastrev[strlen(lastrev) - 1] = '\0';
-			}
-			if (strcmp(rev, lastrev + 3) == 0)
-			{
-				needupdate = 0;
-			}
-		}
-		fclose (stream);
-	}
-
-	if (needupdate)
-	{
-		stream = fopen (argv[2], "w");
-		if (stream == NULL)
-		{
-			return 1;
-		}
-		// [BB] Use hgdate as revision number.
-		if ( hgdate )
-			urev = hgdate;
-		else
-			urev = strtoul(rev, NULL, 10);
-		fprintf (stream,
-"// %s\n"
-"//\n"
-"// This file was automatically generated by the\n"
-"// updaterevision tool. Do not edit by hand.\n"
-"\n"
-"#define SVN_REVISION_STRING \"%s\"\n"
-"#define SVN_REVISION_NUMBER %lu\n",
-			rev, rev, urev);
-
-		// [BB] Also save the hg hash.
-		if ( svnCheckout == 0 )
-			fprintf (stream, "#define HG_REVISION_HASH_STRING \"%s\"\n", hgHash);
-
-		fclose (stream);
-		fprintf (stderr, "%s updated to revision %s.\n", argv[2], rev);
-	}
-	else
-	{
-		fprintf (stderr, "%s is up to date at revision %s.\n", argv[2], rev);
-	}
-
-	return 0;
-}

mercurial