src/settings.cpp
changeset 8969 6d1c74e0e2cd
parent 8937 9a4da442dd50
child 8990 0d5bb1c2a4a6
equal deleted inserted replaced
8968:c3206e3f051a 8969:6d1c74e0e2cd
    81 static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size);
    81 static void *pool_strdup(SettingsMemoryPool **pool, const char *mem, uint size);
    82 static void pool_free(SettingsMemoryPool **pool);
    82 static void pool_free(SettingsMemoryPool **pool);
    83 static bool IsSignedVarMemType(VarType vt);
    83 static bool IsSignedVarMemType(VarType vt);
    84 
    84 
    85 struct SettingsMemoryPool {
    85 struct SettingsMemoryPool {
    86 	uint pos,size;
    86 	uint pos, size;
    87 	SettingsMemoryPool *next;
    87 	SettingsMemoryPool *next;
    88 	byte mem[1];
    88 	byte mem[1];
    89 };
    89 };
    90 
    90 
    91 static SettingsMemoryPool *pool_new(uint minsize)
    91 static SettingsMemoryPool *pool_new(uint minsize)
   240 		/* trim whitespace from the left side */
   240 		/* trim whitespace from the left side */
   241 		for (s = buffer; *s == ' ' || *s == '\t'; s++) {}
   241 		for (s = buffer; *s == ' ' || *s == '\t'; s++) {}
   242 
   242 
   243 		/* trim whitespace from right side. */
   243 		/* trim whitespace from right side. */
   244 		e = s + strlen(s);
   244 		e = s + strlen(s);
   245 		while (e > s && ((c=e[-1]) == '\n' || c == '\r' || c == ' ' || c == '\t')) e--;
   245 		while (e > s && ((c = e[-1]) == '\n' || c == '\r' || c == ' ' || c == '\t')) e--;
   246 		*e = '\0';
   246 		*e = '\0';
   247 
   247 
   248 		/* skip comments and empty lines */
   248 		/* skip comments and empty lines */
   249 		if (*s == '#' || *s == ';' || *s == '\0') {
   249 		if (*s == '#' || *s == ';' || *s == '\0') {
   250 			uint ns = comment_size + (e - s + 1);
   250 			uint ns = comment_size + (e - s + 1);
   251 			uint a = comment_alloc;
   251 			uint a = comment_alloc;
   252 			uint pos;
   252 			uint pos;
   253 			/* add to comment */
   253 			/* add to comment */
   254 			if (ns > a) {
   254 			if (ns > a) {
   255 				a = max(a, 128U);
   255 				a = max(a, 128U);
   256 				do a*=2; while (a < ns);
   256 				do a *= 2; while (a < ns);
   257 				comment = ReallocT(comment, comment_alloc = a);
   257 				comment = ReallocT(comment, comment_alloc = a);
   258 			}
   258 			}
   259 			pos = comment_size;
   259 			pos = comment_size;
   260 			comment_size += (e - s + 1);
   260 			comment_size += (e - s + 1);
   261 			comment[pos + e - s] = '\n'; // comment newline
   261 			comment[pos + e - s] = '\n'; // comment newline