Changeset - r7393:d9b5bcff3577
[Not reviewed]
master
0 5 0
peter1138 - 17 years ago 2007-08-03 09:08:49
peter1138@openttd.org
(svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
each STR_ entry. This avoids the need for a cast to StringID in some
places and thus better type-safety.
5 files changed with 13 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/command.h
Show inline comments
 
@@ -195,9 +195,9 @@ struct Command {
 
static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); }
 
static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); }
 

	
 
static const CommandCost CMD_ERROR = CommandCost((StringID)INVALID_STRING_ID);
 
static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
 

	
 
#define return_cmd_error(errcode) do { return CommandCost((StringID)(errcode)); } while (0)
 
#define return_cmd_error(errcode) do { return CommandCost(errcode); } while (0)
 

	
 
/* command.cpp */
 
typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
src/openttd.cpp
Show inline comments
 
@@ -5,7 +5,6 @@
 
#include "stdafx.h"
 
#define VARDEF
 
#include "string.h"
 
#include "table/strings.h"
 
#include "debug.h"
 
#include "driver.h"
 
#include "saveload.h"
 
@@ -15,6 +14,7 @@
 
#include "helpers.hpp"
 

	
 
#include "openttd.h"
 
#include "table/strings.h"
 
#include "strings.h"
 
#include "bridge_map.h"
 
#include "functions.h"
src/openttd.h
Show inline comments
 
@@ -51,7 +51,7 @@ struct PalSpriteID {
 
typedef uint16 EngineID;
 
typedef uint16 UnitID;
 
typedef uint16 StringID;
 
#define INVALID_STRING_ID 0xFFFF
 
static const StringID INVALID_STRING_ID = 0xFFFF;
 

	
 
typedef EngineID *EngineList; ///< engine list type placeholder acceptable for C code (see helpers.cpp)
 

	
src/strgen/strgen.cpp
Show inline comments
 
@@ -1019,19 +1019,20 @@ static void WriteStringsH(const char *fi
 
	out = fopen("tmp.xxx", "w");
 
	if (out == NULL) fatal("can't open tmp.xxx");
 

	
 
	fprintf(out, "enum StringIdEnum {");
 
	fprintf(out, "/* This file is automatically generated. Do not modify */\n\n");
 
	fprintf(out, "#ifndef TABLE_STRINGS_H\n");
 
	fprintf(out, "#define TABLE_STRINGS_H\n");
 

	
 
	lastgrp = 0;
 

	
 
	for (i = 0; i != lengthof(_strings); i++) {
 
		if (_strings[i] != NULL) {
 
			fprintf(out, next == i ? "\t%s,\n" : "\n\t%s = 0x%X,\n", _strings[i]->name, i);
 
			if (next != i) fprintf(out, "\n");
 
			fprintf(out, "static const StringID %s = 0x%X;\n", _strings[i]->name, i);
 
			next = i + 1;
 
		}
 
	}
 

	
 
	fprintf(out, "};\n");
 

	
 
	fprintf(out,
 
		"\nenum {\n"
 
		"\tLANGUAGE_PACK_IDENT = 0x474E414C, // Big Endian value for 'LANG' (LE is 0x 4C 41 4E 47)\n"
 
@@ -1039,6 +1040,8 @@ static void WriteStringsH(const char *fi
 
		"};\n", (uint)_hash
 
	);
 

	
 
	fprintf(out, "\n#endif /* TABLE_STRINGS_H */\n");
 

	
 
	fclose(out);
 

	
 
	if (CompareFiles("tmp.xxx", filename)) {
src/strings.cpp
Show inline comments
 
@@ -696,7 +696,7 @@ static char* FormatString(char* buff, co
 
				 *   8bit   - cargo type
 
				 *   16-bit - cargo count */
 
				CargoID cargo = GetInt32(&argv);
 
				StringID cargo_str = (cargo == CT_INVALID) ? (StringID)STR_8838_N_A : GetCargo(cargo)->quantifier;
 
				StringID cargo_str = (cargo == CT_INVALID) ? STR_8838_N_A : GetCargo(cargo)->quantifier;
 
				buff = GetStringWithArgs(buff, cargo_str, argv++, last);
 
				break;
 
			}
 
@@ -852,7 +852,7 @@ static char* FormatString(char* buff, co
 
				assert(g->IsValid());
 

	
 
				args[0] = g->index;
 
				buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : (StringID)STR_GROUP_NAME_FORMAT, args, last);
 
				buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : STR_GROUP_NAME_FORMAT, args, last);
 

	
 
				break;
 
			}
0 comments (0 inline, 0 general)