git » fp-git.git » commit b5d5710

added return comments and the name %m option

author ecalot
2006-01-07 20:48:48 UTC
committer ecalot
2006-01-07 20:48:48 UTC
parent 9aa72a93d03426263fa19cd823ecfacb5075c27d

added return comments and the name %m option

PR/src/lib/layers/stringformat.c +20 -16

diff --git a/PR/src/lib/layers/stringformat.c b/PR/src/lib/layers/stringformat.c
index 67abb9e..48ba1dc 100644
--- a/PR/src/lib/layers/stringformat.c
+++ b/PR/src/lib/layers/stringformat.c
@@ -40,9 +40,9 @@ static int i;
 static char buffer[200];
 
 int emit(char c) {
-	if (i==200) return 0;
+	if (i==200) return 0; /* false */
 	buffer[i++]=c;
-	return 1;
+	return 1; /* true */
 }
 
 void emitString(const char* txt, int size, int zeroflag) {
@@ -53,7 +53,7 @@ void emitString(const char* txt, int size, int zeroflag) {
 	complete=(length>size)?0:size-length;
 
 	while (complete--) emit(zeroflag?'0':' ');
-	
+
 	for (complete=0;complete<length;complete++) emit(txt[complete]);
 }
 
@@ -78,23 +78,24 @@ void emitNumber(int n, int size, int zeroflag) {
 
 	while (complete--) emit(zeroflag?'0':' ');
 
-	recEmit(n);	
+	recEmit(n);
 }
 
 #define readk(k) (k=*(format++))
 
-const char* parseformat(const char* format,long value,const char* index, const char* type, const char* extension, long numberOfThisType, int order, const char* desc) {
+const char* parseformat(const char* format,long value,const char* index, const char* type, const char* extension, long numberOfThisType, int order, const char* desc,const char* name) {
 	/* This function parses format in this way:
-	 * %v - the value
-	 * %i - the 4-chars index name
+	 * %% - a % sign
 	 * %I - the human-like index name
-	 * %t - the item type (image, wave, etc)
+	 * %d - the description
 	 * %e - the extension (bmp, wav, etc)
+	 * %i - the 4-chars index name
+	 * %m - the name of the item
 	 * %n - the number of the item typed in %t
 	 * %o - the order number (in case the index and values are the same)
-	 * %d - the description
-	 * %% - a % sign
-	 * 
+	 * %t - the item type (image, wave, etc)
+	 * %v - the value
+	 *
 	 * Modifiers: (TODO: truncate flag)
 	 * %5i  - the index truncated to 5 bytes or the index size, whatever comes first
 	 * %05i - the same, but in case the index is sized less than 5 it's filled with spaces
@@ -104,7 +105,7 @@ const char* parseformat(const char* format,long value,const char* index, const c
 	 * Examples:
 	 * "%i%05v.%e" for shap25001.bmp
 	 * "%t%02n.%e" for image01.bmp
-	 * 
+	 *
 	 * Limitations:
 	 * The generated string size has a limit, in case it is reached, a NULL pointer will be returned
 	 */
@@ -112,17 +113,17 @@ const char* parseformat(const char* format,long value,const char* index, const c
 	char k;
 	int zeroflag;
 	int size;
-				
+
 	i=0; /* initialize buffer */
 
 	while (readk(k)) { /* for each byte in format as k */
 		if (k=='%') {
 			zeroflag=0;
 			size=0;
-			
+
 			readk(k); /* read next char */
 			if (!k) return NULL; /* just in case the string is finished in the wrong place */
-			
+
 			if (k=='0') { /* it's %0... */
 				zeroflag=1;
 				readk(k); /* read next char */
@@ -158,6 +159,9 @@ const char* parseformat(const char* format,long value,const char* index, const c
 			case 'd': /* description */
 				emitString(desc,size,zeroflag);
 				break;
+			case 'm': /* name */
+				emitString(name,size,zeroflag);
+				break;
 			case '%': /* the % symbol */
 				emit(k); /* emit it */
 				break;
@@ -168,7 +172,7 @@ const char* parseformat(const char* format,long value,const char* index, const c
 			emit(k);
 		}
 	}
-	
+
 	return emit(0)?buffer:NULL; /* close the string and return it (return NULL in case of error)*/
 }