Some renaming

Wed, 17 Apr 2013 14:09:38 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 17 Apr 2013 14:09:38 +0300
changeset 116
4fde8fdf258a
parent 115
611417d3e6d2
child 117
7eb7a43a511b

Some renaming

file.cpp file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
misc.cpp file | annotate | diff | comparison | revisions
misc.h file | annotate | diff | comparison | revisions
str.cpp file | annotate | diff | comparison | revisions
str.h file | annotate | diff | comparison | revisions
types.cpp file | annotate | diff | comparison | revisions
zz_addObjectDialog.cpp file | annotate | diff | comparison | revisions
zz_colorSelectDialog.cpp file | annotate | diff | comparison | revisions
zz_configDialog.cpp file | annotate | diff | comparison | revisions
zz_historyDialog.cpp file | annotate | diff | comparison | revisions
zz_newPartDialog.cpp file | annotate | diff | comparison | revisions
zz_setContentsDialog.cpp file | annotate | diff | comparison | revisions
--- a/file.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/file.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -57,7 +57,7 @@
 	
 	if (~io_ldpath.value) {
 		// Try with just the LDraw path first
-		zFilePath = str::mkfmt ("%s" DIRSLASH "%s",
+		zFilePath = format ("%s" DIRSLASH "%s",
 			io_ldpath.value.chars(), zTruePath.chars());
 		printf ("try %s\n", zFilePath.chars());
 		
@@ -72,7 +72,7 @@
 			};
 			
 			for (char const* sSubdir : saSubdirectories) {
-				zFilePath = str::mkfmt ("%s" DIRSLASH "%s" DIRSLASH "%s",
+				zFilePath = format ("%s" DIRSLASH "%s" DIRSLASH "%s",
 					io_ldpath.value.chars(), sSubdir, zTruePath.chars());
 				printf ("try %s\n", zFilePath.chars());
 				
@@ -265,7 +265,7 @@
 	// Write all entries now
 	for (LDObject* obj : objects) {
 		// LDraw requires lines to have DOS line endings
-		str zLine = str::mkfmt ("%s\r\n", obj->getContents ().chars ());
+		str zLine = format ("%s\r\n", obj->getContents ().chars ());
 		
 		fwrite (zLine.chars(), 1, ~zLine, fp);
 	}
@@ -281,7 +281,7 @@
 #define CHECK_TOKEN_NUMBERS(MIN,MAX) \
 	for (ushort i = MIN; i <= MAX; ++i) \
 		if (!isNumber (tokens[i])) \
-			return new LDGibberish (zLine, str::mkfmt ("Token #%u was `%s`, expected a number", \
+			return new LDGibberish (zLine, format ("Token #%u was `%s`, expected a number", \
 				(i + 1), tokens[i].chars()));
 
 // =============================================================================
@@ -331,7 +331,7 @@
 			// Handle BFC statements
 			if (tokens.size() > 2 && tokens[1] == "BFC") {
 				for (short i = 0; i < LDBFC::NumStatements; ++i)
-					if (zComment == str::mkfmt ("BFC %s", LDBFC::saStatements [i]))
+					if (zComment == format ("BFC %s", LDBFC::saStatements [i]))
 						return new LDBFC ((LDBFC::Type) i);
 				
 				// MLCAD is notorious for stuffing these statements in parts it
@@ -372,7 +372,7 @@
 					}
 					
 					if (eType == LDRadial::NumTypes)
-						return new LDGibberish (zLine, str::mkfmt ("Unknown radial type %s", tokens[3].chars ()));
+						return new LDGibberish (zLine, format ("Unknown radial type %s", tokens[3].chars ()));
 					
 					LDRadial* obj = new LDRadial;
 					
--- a/gui.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/gui.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -373,7 +373,7 @@
 		else {
 			QPushButton* qColorButton = new QPushButton;
 			qColorButton->setAutoFillBackground (true);
-			qColorButton->setStyleSheet (str::mkfmt ("background-color: %s", entry.col->zColorString.chars()));
+			qColorButton->setStyleSheet (format ("background-color: %s", entry.col->zColorString.chars()));
 			qColorButton->setToolTip (entry.col->zName);
 			
 			connect (qColorButton, SIGNAL (clicked ()), this, SLOT (slot_quickColor ()));
@@ -810,7 +810,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // ========================================================================= //
 QIcon getIcon (const char* sIconName) {
-	return (QIcon (str::mkfmt ("./icons/%s.png", sIconName)));
+	return (QIcon (format ("./icons/%s.png", sIconName)));
 }
 
 // ========================================================================= //
--- a/ldtypes.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/ldtypes.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -110,18 +110,18 @@
 
 // =============================================================================
 str LDComment::getContents () {
-	return str::mkfmt ("0 %s", zText.chars ());
+	return format ("0 %s", zText.chars ());
 }
 
 str LDSubfile::getContents () {
-	str val = str::mkfmt ("1 %d %s ", dColor, vPosition.getStringRep (false).chars ());
+	str val = format ("1 %d %s ", dColor, vPosition.getStringRep (false).chars ());
 	val += mMatrix.getStringRep ();
 	val += zFileName;
 	return val;
 }
 
 str LDLine::getContents () {
-	str val = str::mkfmt ("2 %d", dColor);
+	str val = format ("2 %d", dColor);
 	
 	for (ushort i = 0; i < 2; ++i)
 		val.appendformat (" %s", vaCoords[i].getStringRep (false).chars ());
@@ -130,7 +130,7 @@
 }
 
 str LDTriangle::getContents () {
-	str val = str::mkfmt ("3 %d", dColor);
+	str val = format ("3 %d", dColor);
 	
 	for (ushort i = 0; i < 3; ++i)
 		val.appendformat (" %s", vaCoords[i].getStringRep (false).chars ());
@@ -139,7 +139,7 @@
 }
 
 str LDQuad::getContents () {
-	str val = str::mkfmt ("4 %d", dColor);
+	str val = format ("4 %d", dColor);
 	
 	for (ushort i = 0; i < 4; ++i)
 		val.appendformat (" %s", vaCoords[i].getStringRep (false).chars ());
@@ -148,7 +148,7 @@
 }
 
 str LDCondLine::getContents () {
-	str val = str::mkfmt ("5 %d", dColor);
+	str val = format ("5 %d", dColor);
 	
 	// Add the coordinates
 	for (ushort i = 0; i < 4; ++i)
@@ -162,7 +162,7 @@
 }
 
 str LDVertex::getContents () {
-	return str::mkfmt ("0 !LDFORGE VERTEX %d %s", dColor, vPosition.getStringRep (false).chars());
+	return format ("0 !LDFORGE VERTEX %d %s", dColor, vPosition.getStringRep (false).chars());
 }
 
 str LDEmpty::getContents () {
@@ -182,7 +182,7 @@
 };
 
 str LDBFC::getContents () {
-	return str::mkfmt ("0 BFC %s", LDBFC::saStatements[eStatement]);
+	return format ("0 BFC %s", LDBFC::saStatements[eStatement]);
 }
 
 // =============================================================================
@@ -448,7 +448,7 @@
 			if (!bFirstDetails)
 				zText += ", ";
 			
-			str zNoun = str::mkfmt ("%s%s", g_saObjTypeNames[eType], PLURAL (ulCount));
+			str zNoun = format ("%s%s", g_saObjTypeNames[eType], PLURAL (ulCount));
 			
 			// Plural of "vertex" is "vertices". Stupid English.
 			if (eType == OBJ_Vertex && ulCount != 1)
@@ -678,7 +678,7 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 str LDRadial::getContents () {
-	return str::mkfmt ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s",
+	return format ("0 !LDFORGE RADIAL %s %d %d %d %d %s %s",
 		str (radialTypeName()).toupper ().strip (' ').chars (),
 		dColor, dSegments, dDivisions, dRingNum,
 		vPosition.getStringRep (false).chars(), mMatrix.getStringRep().chars());
@@ -712,10 +712,10 @@
 	}
 	
 	// Compose some general information: prefix, fraction, root, ring number
-	str zPrefix = (dDivisions == 16) ? "" : str::mkfmt ("%d/", dDivisions);
-	str zFrac = str::mkfmt ("%d-%d", dNumerator, dDenominator);
+	str zPrefix = (dDivisions == 16) ? "" : format ("%d/", dDivisions);
+	str zFrac = format ("%d-%d", dNumerator, dDenominator);
 	str zRoot = g_saRadialNameRoots[eRadialType];
-	str zRingNum = (eRadialType == Ring || eRadialType == Cone) ? str::mkfmt ("%d", dRingNum) : "";
+	str zRingNum = (eRadialType == Ring || eRadialType == Cone) ? format ("%d", dRingNum) : "";
 	
 	// Truncate the root if necessary (7-16rin4.dat for instance).
 	// However, always keep the root at least 2 characters.
@@ -723,5 +723,5 @@
 	zRoot -= min<short> (max<short> (dExtra, 0), 2);
 	
 	// Stick them all together and return the result.
-	return str::mkfmt ("%s%s%s%s", zPrefix.chars(), zFrac.chars (), zRoot.chars (), zRingNum.chars ());
+	return format ("%s%s%s%s", zPrefix.chars(), zFrac.chars (), zRoot.chars (), zRingNum.chars ());
 }
\ No newline at end of file
--- a/misc.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/misc.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -94,7 +94,7 @@
 	// turn into anything weird (like commas)
 	setlocale (LC_NUMERIC, "C");
 	
-	str zRep = str::mkfmt ("%f", fCoord);
+	str zRep = format ("%f", fCoord);
 	
 	// Remove trailing zeroes
 	while (zRep[~zRep - 1] == '0')
@@ -143,27 +143,27 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
-void simplify (short& a, short& b) {
-	bool repeat;
+void simplify (short& dNumerator, short& dDenominator) {
+	bool bRepeat;
 	
 	do {
-		repeat = false;
+		bRepeat = false;
 		
 		for (ulong x = 0; x < NUM_PRIMES; x++) {
 			ulong i = NUM_PRIMES - x - 1;
 			
-			ushort prime = g_uaPrimes[i];
-			if (a <= prime || b <= prime)
+			ushort uPrime = g_uaPrimes[i];
+			if (dNumerator <= uPrime || dDenominator <= uPrime)
 				continue;
 			
-			if (a % prime == 0 && b % prime == 0) {
-				a /= prime;
-				b /= prime;
-				repeat = true;
+			if (dNumerator % uPrime == 0 && dDenominator % uPrime == 0) {
+				dNumerator /= uPrime;
+				dDenominator /= uPrime;
+				bRepeat = true;
 				break;
 			}
 		}
-	} while (repeat);
+	} while (bRepeat);
 }
 
 // =============================================================================
--- a/misc.h	Tue Apr 16 20:32:42 2013 +0300
+++ b/misc.h	Wed Apr 17 14:09:38 2013 +0300
@@ -57,7 +57,7 @@
 	return out;
 }
 
-void simplify (short& a, short& b);
+void simplify (short& dNumerator, short& dDenominator);
 
 // =============================================================================
 // stringparser
--- a/str.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/str.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -500,4 +500,17 @@
 str& str::operator+= (vertex vrt) {
 	appendformat ("%s", vrt.getStringRep (false).chars());
 	return *this;
+}
+
+str format (const char* fmt, ...) {
+	va_list va;
+	char* buf;
+	
+	va_start (va, fmt);
+	buf = vdynformat (fmt, va, 256);
+	va_end (va);
+	
+	str val = buf;
+	delete[] buf;
+	return val;
 }
\ No newline at end of file
--- a/str.h	Tue Apr 16 20:32:42 2013 +0300
+++ b/str.h	Wed Apr 17 14:09:38 2013 +0300
@@ -54,19 +54,6 @@
 	str (QString c);
 	~str ();
 	
-	static str mkfmt (const char* fmt, ...) {
-		va_list va;
-		char* buf;
-		
-		va_start (va, fmt);
-		buf = vdynformat (fmt, va, 256);
-		va_end (va);
-		
-		str val = buf;
-		delete[] buf;
-		return val;
-	}
-	
 	// ======================================================================
 	// METHODS
 	
@@ -281,4 +268,6 @@
 	}
 };
 
+str format (const char* fmt, ...);
+
 #endif // __STR_H__
--- a/types.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/types.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -20,7 +20,7 @@
 str vertex::getStringRep (const bool bMangled) {
 	const char* sFormat = (bMangled) ? "(%s, %s, %s)" : "%s %s %s";
 	
-	return str::mkfmt (sFormat,
+	return format (sFormat,
 		ftoa (x).chars(),
 		ftoa (y).chars(),
 		ftoa (z).chars());
--- a/zz_addObjectDialog.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/zz_addObjectDialog.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -38,7 +38,7 @@
 	QDialog (parent)
 {
 	short dCoordCount = 0;
-	str zIconName = str::mkfmt ("icons/add-%s.png", g_saObjTypeIcons[type]);
+	str zIconName = format ("icons/add-%s.png", g_saObjTypeIcons[type]);
 	
 	qTypeIcon = new QLabel;
 	qTypeIcon->setPixmap (QPixmap (zIconName.chars ()));
@@ -163,7 +163,7 @@
 	
 	qLayout->addWidget (qButtons, 5, 1);
 	setLayout (qLayout);
-	setWindowTitle (str::mkfmt (APPNAME_DISPLAY " - new %s",
+	setWindowTitle (format (APPNAME_DISPLAY " - new %s",
 		g_saObjTypeNames[type]).chars());
 	
 	setWindowIcon (QIcon (zIconName.chars ()));
@@ -176,7 +176,7 @@
 	qButton->setIcon (QIcon ("icons/palette.png"));
 	qButton->setAutoFillBackground (true);
 	qButton->setStyleSheet (
-		str::mkfmt ("background-color: %s", getColor (dColor)->zColorString.chars()).chars()
+		format ("background-color: %s", getColor (dColor)->zColorString.chars()).chars()
 	);
 }
 
--- a/zz_colorSelectDialog.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/zz_colorSelectDialog.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -120,7 +120,7 @@
 		bool bDark = (ucLuma < 80);
 		
 		qScene->addRect (x, y, w, w, qPen, qColor);
-		QGraphicsTextItem* qText = qScene->addText (str::mkfmt ("%lu", i).chars());
+		QGraphicsTextItem* qText = qScene->addText (format ("%lu", i).chars());
 		qText->setDefaultTextColor ((bDark) ? Qt::white : Qt::black);
 		qText->setPos (x, y);
 		
@@ -143,7 +143,7 @@
 		return;
 	}
 	
-	qColorInfo->setText (str::mkfmt ("%d - %s",
+	qColorInfo->setText (format ("%d - %s",
 		dSelColor, col->zName.chars()));
 }
 
--- a/zz_configDialog.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/zz_configDialog.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -434,7 +434,7 @@
 	qButton->setIcon (QIcon ("icons/colorselect.png"));
 	qButton->setAutoFillBackground (true);
 	qButton->setStyleSheet (
-		str::mkfmt ("background-color: %s", zValue.chars()).chars()
+		format ("background-color: %s", zValue.chars()).chars()
 	);
 }
 
@@ -517,7 +517,7 @@
 	str zLabel = qAct->iconText ();
 	str zKeybind = qAct->shortcut ().toString ();
 	
-	qItem->setText (str::mkfmt ("%s (%s)", zLabel.chars () ,zKeybind.chars ()).chars());
+	qItem->setText (format ("%s (%s)", zLabel.chars () ,zKeybind.chars ()).chars());
 }
 
 // =============================================================================
@@ -617,7 +617,7 @@
 void KeySequenceDialog::updateOutput () {
 	str zShortcut = seq.toString ();
 	
-	str zText = str::mkfmt ("<center><b>%s</b></center>", zShortcut.chars ());
+	str zText = format ("<center><b>%s</b></center>", zShortcut.chars ());
 	
 	qOutput->setText (zText);
 }
--- a/zz_historyDialog.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/zz_historyDialog.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -115,7 +115,7 @@
 						if (eCommonType == OBJ_Unidentified)
 							qEntryIcon = getIcon ("add-subfile");
 						else
-							qEntryIcon = getIcon (str::mkfmt ("add-%s", g_saObjTypeIcons[eCommonType]));
+							qEntryIcon = getIcon (format ("add-%s", g_saObjTypeIcons[eCommonType]));
 					}
 					break;
 				}
--- a/zz_newPartDialog.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/zz_newPartDialog.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -109,11 +109,11 @@
 		
 		objs.push_back (new LDComment (dlg.qLE_Name->text ()));
 		objs.push_back (new LDComment ("Name: <untitled>.dat"));
-		objs.push_back (new LDComment (str::mkfmt ("Author: %s", zAuthor.chars())));
-		objs.push_back (new LDComment (str::mkfmt ("!LDRAW_ORG Unofficial_Part")));
+		objs.push_back (new LDComment (format ("Author: %s", zAuthor.chars())));
+		objs.push_back (new LDComment (format ("!LDRAW_ORG Unofficial_Part")));
 		
 		if (sLicense != null)
-			objs.push_back (new LDComment (str::mkfmt ("!LICENSE %s", sLicense)));
+			objs.push_back (new LDComment (format ("!LICENSE %s", sLicense)));
 		
 		objs.push_back (new LDEmpty);
 		objs.push_back (new LDBFC (eBFCType));
--- a/zz_setContentsDialog.cpp	Tue Apr 16 20:32:42 2013 +0300
+++ b/zz_setContentsDialog.cpp	Wed Apr 17 14:09:38 2013 +0300
@@ -42,7 +42,7 @@
 	
 	if (obj->getType() == OBJ_Gibberish) {
 		qErrorLabel = new QLabel;
-		qErrorLabel->setText (str::mkfmt ("<span style=\"color: #900\">%s</span>",
+		qErrorLabel->setText (format ("<span style=\"color: #900\">%s</span>",
 			static_cast<LDGibberish*> (obj)->zReason.chars()));
 		
 		QPixmap qErrorPixmap = QPixmap ("icons/error.png").scaledToHeight (16);

mercurial