Changeset - r24090:430f85894420
[Not reviewed]
master
0 2 0
Johannes E. Krause - 5 years ago 2019-03-22 03:37:53
j.k@eclipso.de
Feature: SLF_HEX to print hexadecimal numbers in the config file
2 files changed with 12 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/saveload/saveload.h
Show inline comments
 
@@ -471,7 +471,8 @@ enum VarTypes {
 
	SLF_NO_NETWORK_SYNC = 1 << 10, ///< do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
 
	SLF_ALLOW_CONTROL   = 1 << 11, ///< allow control codes in the strings
 
	SLF_ALLOW_NEWLINE   = 1 << 12, ///< allow new lines in the strings
 
	/* 3 more possible flags */
 
	SLF_HEX             = 1 << 13, ///< print numbers as hex in the config file (only useful for unsigned)
 
	/* 2 more possible flags */
 
};
 

	
 
typedef uint32 VarType;
src/settings.cpp
Show inline comments
 
@@ -268,7 +268,7 @@ static void MakeIntList(char *buf, const
 
	const byte *p = (const byte *)array;
 

	
 
	for (i = 0; i != nelems; i++) {
 
		switch (type) {
 
		switch (GetVarMemType(type)) {
 
			case SLE_VAR_BL:
 
			case SLE_VAR_I8:  v = *(const   int8 *)p; p += 1; break;
 
			case SLE_VAR_U8:  v = *(const  uint8 *)p; p += 1; break;
 
@@ -278,7 +278,13 @@ static void MakeIntList(char *buf, const
 
			case SLE_VAR_U32: v = *(const uint32 *)p; p += 4; break;
 
			default: NOT_REACHED();
 
		}
 
		buf += seprintf(buf, last, IsSignedVarMemType(type) ? ((i == 0) ? "%d" : ",%d") : ((i == 0) ? "%u" : ",%u"), v);
 
		if (IsSignedVarMemType(type)) {
 
			buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
 
		} else if (type & SLF_HEX) {
 
			buf += seprintf(buf, last, (i == 0) ? "0x%X" : ",0x%X", v);
 
		} else {
 
			buf += seprintf(buf, last, (i == 0) ? "%u" : ",%u", v);
 
		}
 
	}
 
}
 

	
 
@@ -673,7 +679,7 @@ static void IniSaveSettings(IniFile *ini
 

	
 
				switch (sdb->cmd) {
 
					case SDT_BOOLX:      strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break;
 
					case SDT_NUMX:       seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break;
 
					case SDT_NUMX:       seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : (sld->conv & SLF_HEX) ? "%X" : "%u", i); break;
 
					case SDT_ONEOFMANY:  MakeOneOfMany(buf, lastof(buf), sdb->many, i); break;
 
					case SDT_MANYOFMANY: MakeManyOfMany(buf, lastof(buf), sdb->many, i); break;
 
					default: NOT_REACHED();
 
@@ -701,7 +707,7 @@ static void IniSaveSettings(IniFile *ini
 
				break;
 

	
 
			case SDT_INTLIST:
 
				MakeIntList(buf, lastof(buf), ptr, sld->length, GetVarMemType(sld->conv));
 
				MakeIntList(buf, lastof(buf), ptr, sld->length, sld->conv);
 
				break;
 

	
 
			default: NOT_REACHED();
0 comments (0 inline, 0 general)