From eed181245dffbc04a2e527e8e7cccf44ce4fda86 Mon Sep 17 00:00:00 2001 From: tron Date: Sun, 6 Feb 2005 22:25:27 +0000 Subject: [PATCH] (svn r1833) byte -> char transition: the rest --- console_cmds.c | 4 ++-- engine.c | 2 +- engine.h | 2 +- functions.h | 2 +- main_gui.c | 7 ++++--- misc_gui.c | 8 ++++---- network.c | 16 ++++++++-------- network.h | 6 +++--- network_udp.c | 2 +- network_udp.h | 2 +- newgrf.c | 19 +++++++++++-------- news_gui.c | 12 +++++++----- players.c | 5 +++-- settings.c | 2 +- spritecache.c | 2 +- station_gui.c | 8 ++++---- ttd.c | 4 ++-- variables.h | 2 +- 18 files changed, 56 insertions(+), 49 deletions(-) diff --git a/console_cmds.c b/console_cmds.c index 8cb03151a4..adf67f2025 100644 --- a/console_cmds.c +++ b/console_cmds.c @@ -554,8 +554,8 @@ DEF_CONSOLE_CMD(ConNetworkClients) DEF_CONSOLE_CMD(ConNetworkConnect) { char* ip; - const byte *port = NULL; - const byte *player = NULL; + const char *port = NULL; + const char *player = NULL; uint16 rport; if (argc<2) return NULL; diff --git a/engine.c b/engine.c index 8b5980bf75..803ff43b12 100644 --- a/engine.c +++ b/engine.c @@ -625,7 +625,7 @@ void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger) 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); } diff --git a/engine.h b/engine.h index 9976f57c46..022af0ac72 100644 --- a/engine.h +++ b/engine.h @@ -114,7 +114,7 @@ enum VehicleTrigger { }; void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger); -void SetCustomEngineName(int engine, char *name); +void SetCustomEngineName(int engine, const char *name); StringID GetCustomEngineName(int engine); diff --git a/functions.h b/functions.h index 44be4f8c45..2b59c11a50 100644 --- a/functions.h +++ b/functions.h @@ -147,7 +147,7 @@ void NetworkShutDown(void); void NetworkGameLoop(void); void NetworkUDPGameLoop(void); bool NetworkServerStart(void); -bool NetworkClientConnectGame(const byte* host, unsigned short port); +bool NetworkClientConnectGame(const char* host, unsigned short port); void NetworkReboot(void); void NetworkDisconnect(void); void NetworkSend_Command(uint32 tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); diff --git a/main_gui.c b/main_gui.c index 6089fc3d8a..ac298d620a 100644 --- a/main_gui.c +++ b/main_gui.c @@ -2102,10 +2102,11 @@ extern GetNewsStringCallbackProc * const _get_news_string_callback[]; static bool DrawScrollingStatusText(NewsItem *ni, int pos) { StringID str; - byte *s, *d; + const char *s; + char *d; DrawPixelInfo tmp_dpi, *old_dpi; int x; - byte buffer[256]; + char buffer[256]; if (ni->display_mode == 3) { str = _get_news_string_callback[ni->callback](ni); @@ -2127,7 +2128,7 @@ static bool DrawScrollingStatusText(NewsItem *ni, int pos) } else if (*s == 0x0D) { d[0] = d[1] = d[2] = d[3] = ' '; d+=4; - } else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { + } else if ((byte)*s >= ' ' && ((byte)*s < 0x88 || (byte)*s >= 0x99)) { *d++ = *s; } } diff --git a/misc_gui.c b/misc_gui.c index 6db7b61d7d..d6dacc4542 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -678,7 +678,7 @@ void GuiShowTooltips(StringID string_id) static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, uint mask) { int i; - byte *b; + char *b; b = _userstring; 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[1] = STR_00D0_NOTHING; b[2] = STR_00D0_NOTHING >> 8; @@ -779,7 +779,7 @@ void SetHScrollCount(Window *w, int num) * [IN]buf: string to be checked * [OUT]count: gets set to the count of characters * [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; *width = -1; @@ -788,7 +788,7 @@ static void GetCurrentStringSize(const byte *buf, int *count, int *width) if (*++buf == 0) break; (*count)++; - (*width) += _stringwidth_table[*buf - 32]; + (*width) += _stringwidth_table[(byte)*buf - 32]; } while (1); } diff --git a/network.c b/network.c index 48a46a3e03..5f8da96787 100644 --- a/network.c +++ b/network.c @@ -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 // be set to the player and port strings given by the user, inside the memory area originally // 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++) { if (*p == '#') { *player = p + 1; @@ -819,7 +819,7 @@ static void NetworkInitialize(void) // Query a server to fetch his game-info // If game_info is true, only the gameinfo 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; @@ -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 * the list. If you use this functions, the games will be marked * as manually added. */ -void NetworkAddServer(const byte *b) +void NetworkAddServer(const char *b) { if (*b != '\0') { NetworkGameList *item; - const byte *port = NULL; - const byte *player = NULL; - byte host[NETWORK_HOSTNAME_LENGTH]; + const char *port = NULL; + const char *player = NULL; + char host[NETWORK_HOSTNAME_LENGTH]; uint16 rport; ttd_strlcpy(host, b, lengthof(host)); @@ -896,7 +896,7 @@ void NetworkRebuildHostList(void) } // 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; diff --git a/network.h b/network.h index b75d265ae2..ae55d541ac 100644 --- a/network.h +++ b/network.h @@ -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 -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 */ @@ -211,9 +211,9 @@ VARDEF bool _network_server; // network-server is active VARDEF bool _network_dedicated; // are we a dedicated server? 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 NetworkAddServer(const byte *b); +void NetworkAddServer(const char *b); void NetworkRebuildHostList(void); void NetworkChangeCompanyPassword(const char *str); diff --git a/network_udp.c b/network_udp.c index 4fd033d41e..6d8d051b86 100644 --- a/network_udp.c +++ b/network_udp.c @@ -516,7 +516,7 @@ void NetworkUDPSearchGame(void) _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; Packet *p; diff --git a/network_udp.h b/network_udp.h index 1db6d97ab1..5b57cb8ca9 100644 --- a/network_udp.h +++ b/network_udp.h @@ -8,7 +8,7 @@ bool NetworkUDPListen(SOCKET *udp, uint32 host, uint16 port, bool broadcast); void NetworkUDPReceive(SOCKET udp); void NetworkUDPSearchGame(void); void NetworkUDPQueryMasterServer(void); -NetworkGameList *NetworkUDPQueryServer(const byte* host, unsigned short port); +NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port); void NetworkUDPAdvertise(void); void NetworkUDPRemoveAdvertise(void); diff --git a/newgrf.c b/newgrf.c index 03f622a2e0..f964597341 100644 --- a/newgrf.c +++ b/newgrf.c @@ -1509,6 +1509,7 @@ static void VehicleNewName(byte *buf, int len) uint8 lang; uint8 id; uint8 endid; + const char* name; check_length(len, 6, "VehicleNewName"); feature = buf[1]; @@ -1530,17 +1531,19 @@ static void VehicleNewName(byte *buf, int len) return; } - buf += 5, len -= 5; + name = (const char*)(buf + 5); + len -= 5; for (; id < endid && len > 0; id++) { - int ofs = strlen(buf) + 1; + int ofs = strlen(name) + 1; if (ofs < 128) { - DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, buf); - SetCustomEngineName(id, buf); + DEBUG(grf, 8) ("VehicleNewName: %d <- %s", id, name); + SetCustomEngineName(id, name); } else { 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.) */ uint8 version; uint32 grfid; - char *name; - char *info; + const char *name; + const char *info; check_length(len, 9, "GRFInfo"); version = buf[1]; /* this is de facto big endian - grf_load_dword() unsuitable */ 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; _cur_grffile->grfid = grfid; diff --git a/news_gui.c b/news_gui.c index b8931a36c3..81a811c958 100644 --- a/news_gui.c +++ b/news_gui.c @@ -503,10 +503,11 @@ static byte getNews(byte i) } // 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; - byte *s, *d; + const char *s; + char *d; uint len = 0; if (ni->display_mode == 3) { @@ -537,8 +538,8 @@ static void GetNewsString(NewsItem *ni, byte *buffer, uint max) } else if (*s == '\r') { d[0] = d[1] = d[2] = d[3] = ' '; d += 4; - } else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { - len += _stringwidth_table[*s - 32]; + } else if ((byte)*s >= ' ' && ((byte)*s < 0x88 || (byte)*s >= 0x99)) { + len += _stringwidth_table[(byte)*s - 32]; *d++ = *s; } } @@ -549,7 +550,6 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e) { switch (e->event) { case WE_PAINT: { - byte buffer[256]; int y = 19; byte p, show; NewsItem *ni; @@ -560,6 +560,8 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e) show = min(_total_news, w->vscroll.cap); for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) { + char buffer[256]; + // get news in correct order ni = &_news_items[getNews(p)]; diff --git a/players.c b/players.c index 040f52a028..8eb088af53 100644 --- a/players.c +++ b/players.c @@ -775,7 +775,7 @@ int8 SaveHighScoreValue(const Player *p) for (i = 0; i < lengthof(_highscore_table[0]); i++) { /* You are in the TOP5. Move all values one down and save us there */ 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 memmove(&hs[i + 1], &hs[i], sizeof(HighScore) * (lengthof(_highscore_table[0]) - i - 1)); @@ -820,7 +820,6 @@ int8 SaveHighScoreValueNetwork(void) { HighScore *hs; - byte buf[sizeof(_highscore_table[0]->company)]; Player* const *p_cur = &player_sort[0]; uint8 i; @@ -828,6 +827,8 @@ int8 SaveHighScoreValueNetwork(void) /* Copy over Top5 companies */ 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]; SetDParam(0, (*p_cur)->president_name_1); SetDParam(1, (*p_cur)->president_name_2); diff --git a/settings.c b/settings.c index 99d254c30f..8a9c4423a5 100644 --- a/settings.c +++ b/settings.c @@ -158,7 +158,7 @@ static IniFile *ini_load(const char *filename) IniGroup *group = NULL; IniItem *item; - byte *comment = NULL; + char *comment = NULL; uint comment_size = 0; uint comment_alloc = 0; diff --git a/spritecache.c b/spritecache.c index c580813f8b..e15af9ada4 100644 --- a/spritecache.c +++ b/spritecache.c @@ -786,7 +786,7 @@ static bool FileMD5(const MD5File file, bool warn) #if !defined(WIN32) if (f == NULL) { - byte *s; + char *s; // make lower case and check again for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++) *s = tolower(*s); diff --git a/station_gui.c b/station_gui.c index df1b419bab..14d93c21d6 100644 --- a/station_gui.c +++ b/station_gui.c @@ -317,8 +317,6 @@ static void DrawStationViewWindow(Window *w) int pos; StringID str; uint16 station_id; - byte *b; - station_id = (uint16)w->window_number; @@ -401,6 +399,8 @@ static void DrawStationViewWindow(Window *w) } while (pos > -5 && ++i != 12); if (IsWindowOfPrototype(w, _station_view_widgets)) { + char *b; + b = _userstring; b[0] = 0x81; b[1] = STR_000C_ACCEPTS; @@ -408,7 +408,7 @@ static void DrawStationViewWindow(Window *w) b += 3; for(i=0; i!=NUM_CARGO; i++) { - if ((b - (byte *) &_userstring) + 5 > USERSTRING_LEN - 1) + if ((b - _userstring) + 5 > USERSTRING_LEN - 1) break; if (st->goods[i].waiting_acceptance & 0x8000) { 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[1] = STR_00D0_NOTHING; b[2] = STR_00D0_NOTHING >> 8; diff --git a/ttd.c b/ttd.c index 86886c956f..c120f2f961 100644 --- a/ttd.c +++ b/ttd.c @@ -647,8 +647,8 @@ int ttd_main(int argc, char* argv[]) #ifdef ENABLE_NETWORK if ((network) && (_network_available)) { if (network_conn != NULL) { - const byte *port = NULL; - const byte *player = NULL; + const char *port = NULL; + const char *player = NULL; uint16 rport; rport = NETWORK_DEFAULT_PORT; diff --git a/variables.h b/variables.h index 99800f9050..19e96d4289 100644 --- a/variables.h +++ b/variables.h @@ -303,7 +303,7 @@ VARDEF uint _returned_refit_amount; // Deals with the type of the savegame, independent of extension typedef struct { int mode; // savegame/scenario type (old, new) - byte name[MAX_PATH]; // name + char name[MAX_PATH]; // name } SmallFiosItem; // Used when switching from the intro menu.