1
0
Fork 0

(svn r1833) byte -> char transition: the rest

release/0.4.5
tron 2005-02-06 22:25:27 +00:00
parent 27dc506a03
commit eed181245d
18 changed files with 56 additions and 49 deletions

View File

@ -554,8 +554,8 @@ DEF_CONSOLE_CMD(ConNetworkClients)
DEF_CONSOLE_CMD(ConNetworkConnect) DEF_CONSOLE_CMD(ConNetworkConnect)
{ {
char* ip; char* ip;
const byte *port = NULL; const char *port = NULL;
const byte *player = NULL; const char *player = NULL;
uint16 rport; uint16 rport;
if (argc<2) return NULL; if (argc<2) return NULL;

View File

@ -625,7 +625,7 @@ void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger)
static char *_engine_custom_names[256]; static char *_engine_custom_names[256];
void SetCustomEngineName(int engine, char *name) void SetCustomEngineName(int engine, const char *name)
{ {
_engine_custom_names[engine] = strdup(name); _engine_custom_names[engine] = strdup(name);
} }

View File

@ -114,7 +114,7 @@ enum VehicleTrigger {
}; };
void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger); void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger);
void SetCustomEngineName(int engine, char *name); void SetCustomEngineName(int engine, const char *name);
StringID GetCustomEngineName(int engine); StringID GetCustomEngineName(int engine);

View File

@ -147,7 +147,7 @@ void NetworkShutDown(void);
void NetworkGameLoop(void); void NetworkGameLoop(void);
void NetworkUDPGameLoop(void); void NetworkUDPGameLoop(void);
bool NetworkServerStart(void); bool NetworkServerStart(void);
bool NetworkClientConnectGame(const byte* host, unsigned short port); bool NetworkClientConnectGame(const char* host, unsigned short port);
void NetworkReboot(void); void NetworkReboot(void);
void NetworkDisconnect(void); void NetworkDisconnect(void);
void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);

View File

@ -2102,10 +2102,11 @@ extern GetNewsStringCallbackProc * const _get_news_string_callback[];
static bool DrawScrollingStatusText(NewsItem *ni, int pos) static bool DrawScrollingStatusText(NewsItem *ni, int pos)
{ {
StringID str; StringID str;
byte *s, *d; const char *s;
char *d;
DrawPixelInfo tmp_dpi, *old_dpi; DrawPixelInfo tmp_dpi, *old_dpi;
int x; int x;
byte buffer[256]; char buffer[256];
if (ni->display_mode == 3) { if (ni->display_mode == 3) {
str = _get_news_string_callback[ni->callback](ni); str = _get_news_string_callback[ni->callback](ni);
@ -2127,7 +2128,7 @@ static bool DrawScrollingStatusText(NewsItem *ni, int pos)
} else if (*s == 0x0D) { } else if (*s == 0x0D) {
d[0] = d[1] = d[2] = d[3] = ' '; d[0] = d[1] = d[2] = d[3] = ' ';
d+=4; d+=4;
} else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { } else if ((byte)*s >= ' ' && ((byte)*s < 0x88 || (byte)*s >= 0x99)) {
*d++ = *s; *d++ = *s;
} }
} }

View File

@ -678,7 +678,7 @@ void GuiShowTooltips(StringID string_id)
static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, uint mask) static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, uint mask)
{ {
int i; int i;
byte *b; char *b;
b = _userstring; b = _userstring;
b[0] = 0x81; b[0] = 0x81;
@ -698,7 +698,7 @@ static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, u
} }
} }
if (b == (byte*)&_userstring[3]) { if (b == &_userstring[3]) {
b[0] = 0x81; b[0] = 0x81;
b[1] = STR_00D0_NOTHING; b[1] = STR_00D0_NOTHING;
b[2] = STR_00D0_NOTHING >> 8; b[2] = STR_00D0_NOTHING >> 8;
@ -779,7 +779,7 @@ void SetHScrollCount(Window *w, int num)
* [IN]buf: string to be checked * [IN]buf: string to be checked
* [OUT]count: gets set to the count of characters * [OUT]count: gets set to the count of characters
* [OUT]width: gets set to the pixels width */ * [OUT]width: gets set to the pixels width */
static void GetCurrentStringSize(const byte *buf, int *count, int *width) static void GetCurrentStringSize(const char *buf, int *count, int *width)
{ {
*count = 0; *count = 0;
*width = -1; *width = -1;
@ -788,7 +788,7 @@ static void GetCurrentStringSize(const byte *buf, int *count, int *width)
if (*++buf == 0) if (*++buf == 0)
break; break;
(*count)++; (*count)++;
(*width) += _stringwidth_table[*buf - 32]; (*width) += _stringwidth_table[(byte)*buf - 32];
} while (1); } while (1);
} }

View File

@ -425,9 +425,9 @@ unsigned long NetworkResolveHost(const char *hostname)
// connection_string will be re-terminated to seperate out the hostname, and player and port will // connection_string will be re-terminated to seperate out the hostname, and player and port will
// be set to the player and port strings given by the user, inside the memory area originally // be set to the player and port strings given by the user, inside the memory area originally
// occupied by connection_string. // occupied by connection_string.
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string) void ParseConnectionString(const char **player, const char **port, char *connection_string)
{ {
byte *p; char *p;
for (p = connection_string; *p != '\0'; p++) { for (p = connection_string; *p != '\0'; p++) {
if (*p == '#') { if (*p == '#') {
*player = p + 1; *player = p + 1;
@ -819,7 +819,7 @@ static void NetworkInitialize(void)
// Query a server to fetch his game-info // Query a server to fetch his game-info
// If game_info is true, only the gameinfo is fetched, // If game_info is true, only the gameinfo is fetched,
// else only the client_info is fetched // else only the client_info is fetched
NetworkGameList *NetworkQueryServer(const byte* host, unsigned short port, bool game_info) NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool game_info)
{ {
if (!_network_available) return NULL; if (!_network_available) return NULL;
@ -853,13 +853,13 @@ NetworkGameList *NetworkQueryServer(const byte* host, unsigned short port, bool
/* Validates an address entered as a string and adds the server to /* Validates an address entered as a string and adds the server to
* the list. If you use this functions, the games will be marked * the list. If you use this functions, the games will be marked
* as manually added. */ * as manually added. */
void NetworkAddServer(const byte *b) void NetworkAddServer(const char *b)
{ {
if (*b != '\0') { if (*b != '\0') {
NetworkGameList *item; NetworkGameList *item;
const byte *port = NULL; const char *port = NULL;
const byte *player = NULL; const char *player = NULL;
byte host[NETWORK_HOSTNAME_LENGTH]; char host[NETWORK_HOSTNAME_LENGTH];
uint16 rport; uint16 rport;
ttd_strlcpy(host, b, lengthof(host)); ttd_strlcpy(host, b, lengthof(host));
@ -896,7 +896,7 @@ void NetworkRebuildHostList(void)
} }
// Used by clients, to connect to a server // Used by clients, to connect to a server
bool NetworkClientConnectGame(const byte* host, unsigned short port) bool NetworkClientConnectGame(const char* host, unsigned short port)
{ {
if (!_network_available) return false; if (!_network_available) return false;

View File

@ -196,7 +196,7 @@ VARDEF uint8 _network_autoclean_protected; // Unprotect a company after X mont
VARDEF uint16 _network_restart_game_date; // If this year is reached, the server automaticly restarts VARDEF uint16 _network_restart_game_date; // If this year is reached, the server automaticly restarts
NetworkGameList *NetworkQueryServer(const byte* host, unsigned short port, bool game_info); NetworkGameList *NetworkQueryServer(const char* host, unsigned short port, bool game_info);
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
@ -211,9 +211,9 @@ VARDEF bool _network_server; // network-server is active
VARDEF bool _network_dedicated; // are we a dedicated server? VARDEF bool _network_dedicated; // are we a dedicated server?
VARDEF byte _network_playas; // an id to play as.. VARDEF byte _network_playas; // an id to play as..
void ParseConnectionString(const byte **player, const byte **port, byte *connection_string); void ParseConnectionString(const char **player, const char **port, char *connection_string);
void NetworkUpdateClientInfo(uint16 client_index); void NetworkUpdateClientInfo(uint16 client_index);
void NetworkAddServer(const byte *b); void NetworkAddServer(const char *b);
void NetworkRebuildHostList(void); void NetworkRebuildHostList(void);
void NetworkChangeCompanyPassword(const char *str); void NetworkChangeCompanyPassword(const char *str);

View File

@ -516,7 +516,7 @@ void NetworkUDPSearchGame(void)
_network_udp_broadcast = 300; // Stay searching for 300 ticks _network_udp_broadcast = 300; // Stay searching for 300 ticks
} }
NetworkGameList *NetworkUDPQueryServer(const byte* host, unsigned short port) NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port)
{ {
struct sockaddr_in out_addr; struct sockaddr_in out_addr;
Packet *p; Packet *p;

View File

@ -8,7 +8,7 @@ bool NetworkUDPListen(SOCKET *udp, uint32 host, uint16 port, bool broadcast);
void NetworkUDPReceive(SOCKET udp); void NetworkUDPReceive(SOCKET udp);
void NetworkUDPSearchGame(void); void NetworkUDPSearchGame(void);
void NetworkUDPQueryMasterServer(void); void NetworkUDPQueryMasterServer(void);
NetworkGameList *NetworkUDPQueryServer(const byte* host, unsigned short port); NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port);
void NetworkUDPAdvertise(void); void NetworkUDPAdvertise(void);
void NetworkUDPRemoveAdvertise(void); void NetworkUDPRemoveAdvertise(void);

View File

@ -1509,6 +1509,7 @@ static void VehicleNewName(byte *buf, int len)
uint8 lang; uint8 lang;
uint8 id; uint8 id;
uint8 endid; uint8 endid;
const char* name;
check_length(len, 6, "VehicleNewName"); check_length(len, 6, "VehicleNewName");
feature = buf[1]; feature = buf[1];
@ -1530,17 +1531,19 @@ static void VehicleNewName(byte *buf, int len)
return; return;
} }
buf += 5, len -= 5; name = (const char*)(buf + 5);
len -= 5;
for (; id < endid && len > 0; id++) { for (; id < endid && len > 0; id++) {
int ofs = strlen(buf) + 1; int ofs = strlen(name) + 1;
if (ofs < 128) { if (ofs < 128) {
DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, buf); DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, name);
SetCustomEngineName(id, buf); SetCustomEngineName(id, name);
} else { } else {
DEBUG(grf, 7) ("VehicleNewName: Too long a name (%d)", ofs); DEBUG(grf, 7) ("VehicleNewName: Too long a name (%d)", ofs);
} }
buf += ofs, len -= ofs; name += ofs;
len -= ofs;
} }
} }
@ -1712,14 +1715,14 @@ static void GRFInfo(byte *buf, int len)
/* TODO: Check version. (We should have own versioning done somehow.) */ /* TODO: Check version. (We should have own versioning done somehow.) */
uint8 version; uint8 version;
uint32 grfid; uint32 grfid;
char *name; const char *name;
char *info; const char *info;
check_length(len, 9, "GRFInfo"); check_length(len, 9, "GRFInfo");
version = buf[1]; version = buf[1];
/* this is de facto big endian - grf_load_dword() unsuitable */ /* this is de facto big endian - grf_load_dword() unsuitable */
grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5]; grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5];
name = buf + 6; name = (const char*)(buf + 6);
info = name + strlen(name) + 1; info = name + strlen(name) + 1;
_cur_grffile->grfid = grfid; _cur_grffile->grfid = grfid;

View File

@ -503,10 +503,11 @@ static byte getNews(byte i)
} }
// cut string after len pixels // cut string after len pixels
static void GetNewsString(NewsItem *ni, byte *buffer, uint max) static void GetNewsString(NewsItem *ni, char *buffer, uint max)
{ {
StringID str; StringID str;
byte *s, *d; const char *s;
char *d;
uint len = 0; uint len = 0;
if (ni->display_mode == 3) { if (ni->display_mode == 3) {
@ -537,8 +538,8 @@ static void GetNewsString(NewsItem *ni, byte *buffer, uint max)
} else if (*s == '\r') { } else if (*s == '\r') {
d[0] = d[1] = d[2] = d[3] = ' '; d[0] = d[1] = d[2] = d[3] = ' ';
d += 4; d += 4;
} else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { } else if ((byte)*s >= ' ' && ((byte)*s < 0x88 || (byte)*s >= 0x99)) {
len += _stringwidth_table[*s - 32]; len += _stringwidth_table[(byte)*s - 32];
*d++ = *s; *d++ = *s;
} }
} }
@ -549,7 +550,6 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
case WE_PAINT: { case WE_PAINT: {
byte buffer[256];
int y = 19; int y = 19;
byte p, show; byte p, show;
NewsItem *ni; NewsItem *ni;
@ -560,6 +560,8 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e)
show = min(_total_news, w->vscroll.cap); show = min(_total_news, w->vscroll.cap);
for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) { for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) {
char buffer[256];
// get news in correct order // get news in correct order
ni = &_news_items[getNews(p)]; ni = &_news_items[getNews(p)];

View File

@ -775,7 +775,7 @@ int8 SaveHighScoreValue(const Player *p)
for (i = 0; i < lengthof(_highscore_table[0]); i++) { for (i = 0; i < lengthof(_highscore_table[0]); i++) {
/* You are in the TOP5. Move all values one down and save us there */ /* You are in the TOP5. Move all values one down and save us there */
if (hs[i].score <= score) { if (hs[i].score <= score) {
byte buf[sizeof(hs[i].company)]; char buf[sizeof(hs[i].company)];
// move all elements one down starting from the replaced one // move all elements one down starting from the replaced one
memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1)); memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1));
@ -820,7 +820,6 @@ int8 SaveHighScoreValueNetwork(void)
{ {
HighScore *hs; HighScore *hs;
byte buf[sizeof(_highscore_table[0]->company)];
Player* const *p_cur = &player_sort[0]; Player* const *p_cur = &player_sort[0];
uint8 i; uint8 i;
@ -828,6 +827,8 @@ int8 SaveHighScoreValueNetwork(void)
/* Copy over Top5 companies */ /* Copy over Top5 companies */
for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < (uint8)count; i++) { for (i = 0; i < lengthof(_highscore_table[LAST_HS_ITEM]) && i < (uint8)count; i++) {
char buf[sizeof(_highscore_table[0]->company)];
hs = &_highscore_table[LAST_HS_ITEM][i]; hs = &_highscore_table[LAST_HS_ITEM][i];
SetDParam(0, (*p_cur)->president_name_1); SetDParam(0, (*p_cur)->president_name_1);
SetDParam(1, (*p_cur)->president_name_2); SetDParam(1, (*p_cur)->president_name_2);

View File

@ -158,7 +158,7 @@ static IniFile *ini_load(const char *filename)
IniGroup *group = NULL; IniGroup *group = NULL;
IniItem *item; IniItem *item;
byte *comment = NULL; char *comment = NULL;
uint comment_size = 0; uint comment_size = 0;
uint comment_alloc = 0; uint comment_alloc = 0;

View File

@ -786,7 +786,7 @@ static bool FileMD5(const MD5File file, bool warn)
#if !defined(WIN32) #if !defined(WIN32)
if (f == NULL) { if (f == NULL) {
byte *s; char *s;
// make lower case and check again // make lower case and check again
for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++) for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++)
*s = tolower(*s); *s = tolower(*s);

View File

@ -317,8 +317,6 @@ static void DrawStationViewWindow(Window *w)
int pos; int pos;
StringID str; StringID str;
uint16 station_id; uint16 station_id;
byte *b;
station_id = (uint16)w->window_number; station_id = (uint16)w->window_number;
@ -401,6 +399,8 @@ static void DrawStationViewWindow(Window *w)
} while (pos > -5 && ++i != 12); } while (pos > -5 && ++i != 12);
if (IsWindowOfPrototype(w, _station_view_widgets)) { if (IsWindowOfPrototype(w, _station_view_widgets)) {
char *b;
b = _userstring; b = _userstring;
b[0] = 0x81; b[0] = 0x81;
b[1] = STR_000C_ACCEPTS; b[1] = STR_000C_ACCEPTS;
@ -408,7 +408,7 @@ static void DrawStationViewWindow(Window *w)
b += 3; b += 3;
for(i=0; i!=NUM_CARGO; i++) { for(i=0; i!=NUM_CARGO; i++) {
if ((b - (byte *) &_userstring) + 5 > USERSTRING_LEN - 1) if ((b - _userstring) + 5 > USERSTRING_LEN - 1)
break; break;
if (st->goods[i].waiting_acceptance & 0x8000) { if (st->goods[i].waiting_acceptance & 0x8000) {
b[0] = 0x81; b[0] = 0x81;
@ -418,7 +418,7 @@ static void DrawStationViewWindow(Window *w)
} }
} }
if (b == (byte*)&_userstring[3]) { if (b == &_userstring[3]) {
b[0] = 0x81; b[0] = 0x81;
b[1] = STR_00D0_NOTHING; b[1] = STR_00D0_NOTHING;
b[2] = STR_00D0_NOTHING >> 8; b[2] = STR_00D0_NOTHING >> 8;

4
ttd.c
View File

@ -647,8 +647,8 @@ int ttd_main(int argc, char* argv[])
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
if ((network) && (_network_available)) { if ((network) && (_network_available)) {
if (network_conn != NULL) { if (network_conn != NULL) {
const byte *port = NULL; const char *port = NULL;
const byte *player = NULL; const char *player = NULL;
uint16 rport; uint16 rport;
rport = NETWORK_DEFAULT_PORT; rport = NETWORK_DEFAULT_PORT;

View File

@ -303,7 +303,7 @@ VARDEF uint _returned_refit_amount;
// Deals with the type of the savegame, independent of extension // Deals with the type of the savegame, independent of extension
typedef struct { typedef struct {
int mode; // savegame/scenario type (old, new) int mode; // savegame/scenario type (old, new)
byte name[MAX_PATH]; // name char name[MAX_PATH]; // name
} SmallFiosItem; } SmallFiosItem;
// Used when switching from the intro menu. // Used when switching from the intro menu.