Changeset - r10310:bfae42dc59ac
[Not reviewed]
master
0 23 0
skidd13 - 16 years ago 2008-11-02 11:20:15
skidd13@openttd.org
(svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
23 files changed with 85 insertions and 85 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -247,14 +247,14 @@ DEF_CONSOLE_CMD(ConLoad)
 
	if (item != NULL) {
 
		switch (item->type) {
 
			case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: {
 
				_switch_mode = SM_LOAD;
 
				SetFiosType(item->type);
 

	
 
				ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name));
 
				ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title));
 
				strecpy(_file_to_saveload.name, FiosBrowseTo(item), lastof(_file_to_saveload.name));
 
				strecpy(_file_to_saveload.title, item->title, lastof(_file_to_saveload.title));
 
			} break;
 
			default: IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
 
		}
 
	} else {
 
		IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
 
	}
 
@@ -1227,13 +1227,13 @@ bool NetworkChangeCompanyPassword(byte a
 
	}
 

	
 
	if (argc != 1) return false;
 

	
 
	if (strcmp(argv[0], "*") == 0) argv[0][0] = '\0';
 

	
 
	ttd_strlcpy(_network_company_info[_local_company].password, argv[0], sizeof(_network_company_info[_local_company].password));
 
	strecpy(_network_company_info[_local_company].password, argv[0], lastof(_network_company_info[_local_company].password));
 

	
 
	if (!_network_server) {
 
		NetworkClientSetPassword();
 
	} else {
 
		HashCurrentCompanyPassword();
 
	}
src/debug.cpp
Show inline comments
 
@@ -160,13 +160,13 @@ const char *GetDebugString()
 
	memset(dbgstr, 0, sizeof(dbgstr));
 
	i = debug_level;
 
	snprintf(dbgstr, sizeof(dbgstr), "%s=%d", i->name, *i->level);
 

	
 
	for (i++; i != endof(debug_level); i++) {
 
		snprintf(dbgval, sizeof(dbgval), ", %s=%d", i->name, *i->level);
 
		ttd_strlcat(dbgstr, dbgval, sizeof(dbgstr));
 
		strecat(dbgstr, dbgval, lastof(dbgstr));
 
	}
 

	
 
	return dbgstr;
 
}
 

	
 
#ifdef DEBUG_DUMP_COMMANDS
src/fileio.cpp
Show inline comments
 
@@ -307,13 +307,13 @@ FILE *FioFOpenFileSp(const char *filenam
 
	MultiByteToWideChar(CP_ACP, 0, mode, -1, Lmode, lengthof(Lmode));
 
#endif
 
	FILE *f = NULL;
 
	char buf[MAX_PATH];
 

	
 
	if (subdir == NO_DIRECTORY) {
 
		ttd_strlcpy(buf, filename, lengthof(buf));
 
		strecpy(buf, filename, lastof(buf));
 
	} else {
 
		snprintf(buf, lengthof(buf), "%s%s%s", _searchpaths[sp], _subdirs[subdir], filename);
 
	}
 

	
 
#if defined(WIN32)
 
	if (mode[0] == 'r' && GetFileAttributes(OTTD2FS(buf)) == INVALID_FILE_ATTRIBUTES) return NULL;
src/fios.cpp
Show inline comments
 
@@ -213,29 +213,29 @@ static FiosItem *FiosGetFileList(SaveLoa
 

	
 
	/* A parent directory link exists if we are not in the root directory */
 
	if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
 
		fios = _fios_items.Append();
 
		fios->type = FIOS_TYPE_PARENT;
 
		fios->mtime = 0;
 
		ttd_strlcpy(fios->name, "..", lengthof(fios->name));
 
		ttd_strlcpy(fios->title, ".. (Parent directory)", lengthof(fios->title));
 
		strecpy(fios->name, "..", lastof(fios->name));
 
		strecpy(fios->title, ".. (Parent directory)", lastof(fios->title));
 
	}
 

	
 
	/* Show subdirectories */
 
	if (mode != SLD_NEW_GAME && (dir = ttd_opendir(_fios_path)) != NULL) {
 
		while ((dirent = readdir(dir)) != NULL) {
 
			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
 
			strecpy(d_name, FS2OTTD(dirent->d_name), lastof(d_name));
 

	
 
			/* found file must be directory, but not '.' or '..' */
 
			if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
 
					(!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) &&
 
					strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
 
				fios = _fios_items.Append();
 
				fios->type = FIOS_TYPE_DIR;
 
				fios->mtime = 0;
 
				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
 
				strecpy(fios->name, d_name, lastof(fios->name));
 
				snprintf(fios->title, lengthof(fios->title), "%s" PATHSEP " (Directory)", d_name);
 
				str_validate(fios->title);
 
			}
 
		}
 
		closedir(dir);
 
	}
 
@@ -254,31 +254,31 @@ static FiosItem *FiosGetFileList(SaveLoa
 
	/* Show files */
 
	dir = ttd_opendir(_fios_path);
 
	if (dir != NULL) {
 
		while ((dirent = readdir(dir)) != NULL) {
 
			char fios_title[64];
 
			char *t;
 
			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
 
			strecpy(d_name, FS2OTTD(dirent->d_name), lastof(d_name));
 

	
 
			if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG) || FiosIsHiddenFile(dirent)) continue;
 

	
 
			/* File has no extension, skip it */
 
			if ((t = strrchr(d_name, '.')) == NULL) continue;
 
			fios_title[0] = '\0'; // reset the title;
 

	
 
			FiosType type = callback_proc(mode, d_name, t, fios_title);
 
			if (type != FIOS_TYPE_INVALID) {
 
				fios = _fios_items.Append();
 
				fios->mtime = sb.st_mtime;
 
				fios->type = type;
 
				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
 
				strecpy(fios->name, d_name, lastof(fios->name));
 

	
 
				/* Some callbacks want to lookup the title of the file. Allow that.
 
				 * If we just copy the title from the filename, strip the extension */
 
				t = (fios_title[0] == '\0') ? *t = '\0', d_name : fios_title;
 
				ttd_strlcpy(fios->title, t, lengthof(fios->title));
 
				strecpy(fios->title, t, lastof(fios->title));
 
				str_validate(fios->title);
 
			}
 
		}
 
		closedir(dir);
 
	}
 

	
src/gfx.cpp
Show inline comments
 
@@ -983,13 +983,13 @@ skip_cont:;
 
 *
 
 * @return Right-most x position after drawing the (possibly truncated) string
 
 */
 
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw)
 
{
 
	char buffer[DRAW_STRING_BUFFER];
 
	ttd_strlcpy(buffer, str, sizeof(buffer));
 
	strecpy(buffer, str, lastof(buffer));
 
	TruncateString(buffer, maxw);
 
	return DoDrawString(buffer, x, y, color);
 
}
 

	
 
/**
 
 * Draw a sprite.
src/misc_gui.cpp
Show inline comments
 
@@ -1485,13 +1485,13 @@ struct SaveLoadWindow : public QueryStri
 

	
 
			case SLD_LOAD_HEIGHTMAP:
 
				FioGetDirectory(o_dir.name, lengthof(o_dir.name), HEIGHTMAP_DIR);
 
				break;
 

	
 
			default:
 
				ttd_strlcpy(o_dir.name, _personal_dir, lengthof(o_dir.name));
 
				strecpy(o_dir.name, _personal_dir, lastof(o_dir.name));
 
		}
 

	
 
		this->vscroll.cap = 10;
 
		this->resize.step_width = 2;
 
		this->resize.step_height = 10;
 

	
 
@@ -1571,20 +1571,20 @@ struct SaveLoadWindow : public QueryStri
 
				char *name = FiosBrowseTo(file);
 
				if (name != NULL) {
 
					if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
 
						_switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD;
 

	
 
						SetFiosType(file->type);
 
						ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
 
						ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
 
						strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
 
						strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title));
 

	
 
						delete this;
 
					} else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
 
						SetFiosType(file->type);
 
						ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
 
						ttd_strlcpy(_file_to_saveload.title, file->title, sizeof(_file_to_saveload.title));
 
						strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
 
						strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title));
 

	
 
						delete this;
 
						ShowHeightmapLoad();
 
					} else {
 
						/* SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox */
 
						ttd_strlcpy(this->text.buf, file->title, this->text.maxsize);
src/music/extmidi.cpp
Show inline comments
 
@@ -31,13 +31,13 @@ void MusicDriver_ExtMidi::Stop()
 
	this->song[0] = '\0';
 
	this->DoStop();
 
}
 

	
 
void MusicDriver_ExtMidi::PlaySong(const char* filename)
 
{
 
	ttd_strlcpy(this->song, filename, lengthof(this->song));
 
	strecpy(this->song, filename, lastof(this->song));
 
	this->DoStop();
 
}
 

	
 
void MusicDriver_ExtMidi::StopSong()
 
{
 
	this->song[0] = '\0';
src/network/network.cpp
Show inline comments
 
@@ -209,25 +209,25 @@ void CDECL NetworkTextMessage(NetworkAct
 
			snprintf(message, sizeof(message), "*** %s %s %s", name, temp, buf);
 
			break;
 
		case NETWORK_ACTION_CHAT_COMPANY:
 
			SetDParamStr(0, name);
 
			SetDParamStr(1, buf);
 
			GetString(temp, self_send ? STR_NETWORK_CHAT_TO_COMPANY : STR_NETWORK_CHAT_COMPANY, lastof(temp));
 
			ttd_strlcpy(message, temp, sizeof(message));
 
			strecpy(message, temp, lastof(message));
 
			break;
 
		case NETWORK_ACTION_CHAT_CLIENT:
 
			SetDParamStr(0, name);
 
			SetDParamStr(1, buf);
 
			GetString(temp, self_send ? STR_NETWORK_CHAT_TO_CLIENT : STR_NETWORK_CHAT_CLIENT, lastof(temp));
 
			ttd_strlcpy(message, temp, sizeof(message));
 
			strecpy(message, temp, lastof(message));
 
			break;
 
		default:
 
			SetDParamStr(0, name);
 
			SetDParamStr(1, buf);
 
			GetString(temp, STR_NETWORK_CHAT_ALL, lastof(temp));
 
			ttd_strlcpy(message, temp, sizeof(message));
 
			strecpy(message, temp, lastof(message));
 
			break;
 
	}
 

	
 
	DebugDumpCommands("ddc:cmsg:%d;%d;%s\n", _date, _date_fract, message);
 
	IConsolePrintF(color, "%s", message);
 
	NetworkAddChatMessage(color, duration, "%s", message);
 
@@ -731,15 +731,15 @@ void NetworkAddServer(const char *b)
 
	if (*b != '\0') {
 
		const char *port = NULL;
 
		const char *company = NULL;
 
		char host[NETWORK_HOSTNAME_LENGTH];
 
		uint16 rport;
 

	
 
		ttd_strlcpy(host, b, lengthof(host));
 
		strecpy(host, b, lastof(host));
 

	
 
		ttd_strlcpy(_settings_client.network.connect_to_ip, b, lengthof(_settings_client.network.connect_to_ip));
 
		strecpy(_settings_client.network.connect_to_ip, b, lastof(_settings_client.network.connect_to_ip));
 
		rport = NETWORK_DEFAULT_PORT;
 

	
 
		ParseConnectionString(&company, &port, host);
 
		if (port != NULL) rport = atoi(port);
 

	
 
		NetworkUDPQueryServer(host, rport, true);
 
@@ -771,13 +771,13 @@ void NetworkRebuildHostList()
 
bool NetworkClientConnectGame(const char *host, uint16 port)
 
{
 
	if (!_network_available) return false;
 

	
 
	if (port == 0) return false;
 

	
 
	ttd_strlcpy(_settings_client.network.last_host, host, sizeof(_settings_client.network.last_host));
 
	strecpy(_settings_client.network.last_host, host, lastof(_settings_client.network.last_host));
 
	_settings_client.network.last_port = port;
 

	
 
	NetworkDisconnect();
 
	NetworkInitialize();
 

	
 
	// Try to connect
 
@@ -812,14 +812,14 @@ static void NetworkInitGameInfo()
 
	ci = &_network_client_info[MAX_CLIENT_INFO - 1];
 
	memset(ci, 0, sizeof(*ci));
 

	
 
	ci->client_index = NETWORK_SERVER_INDEX;
 
	ci->client_playas = _network_dedicated ? COMPANY_SPECTATOR : _local_company;
 

	
 
	ttd_strlcpy(ci->client_name, _settings_client.network.client_name, sizeof(ci->client_name));
 
	ttd_strlcpy(ci->unique_id, _settings_client.network.network_id, sizeof(ci->unique_id));
 
	strecpy(ci->client_name, _settings_client.network.client_name, lastof(ci->client_name));
 
	strecpy(ci->unique_id, _settings_client.network.network_id, lastof(ci->unique_id));
 
}
 

	
 
bool NetworkServerStart()
 
{
 
	if (!_network_available) return false;
 

	
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -94,13 +94,13 @@ void CDECL NetworkAddChatMessage(uint16 
 
		memmove(&_chatmsg_list[0], &_chatmsg_list[i], sizeof(_chatmsg_list[0]) * (msg_count - i));
 
		msg_count = MAX_CHAT_MESSAGES - lines;
 
	}
 

	
 
	for (bufp = buf; lines != 0; lines--) {
 
		ChatMessage *cmsg = &_chatmsg_list[msg_count++];
 
		ttd_strlcpy(cmsg->message, bufp, sizeof(cmsg->message));
 
		strecpy(cmsg->message, bufp, lastof(cmsg->message));
 

	
 
		/* The default colour for a message is company colour. Replace this with
 
		 * white for any additional lines */
 
		cmsg->color = (bufp == buf && color & IS_PALETTE_COLOR) ? color : (0x1D - 15) | IS_PALETTE_COLOR;
 
		cmsg->end_date = _date + duration;
 

	
src/network/network_client.cpp
Show inline comments
 
@@ -81,16 +81,16 @@ static const char *GenerateCompanyPasswo
 
 */
 
void HashCurrentCompanyPassword()
 
{
 
	if (StrEmpty(_network_company_info[_local_company].password)) return;
 

	
 
	_password_game_seed = _settings_game.game_creation.generation_seed;
 
	ttd_strlcpy(_password_server_unique_id, _settings_client.network.network_id, sizeof(_password_server_unique_id));
 
	strecpy(_password_server_unique_id, _settings_client.network.network_id, lastof(_password_server_unique_id));
 

	
 
	const char *new_pw = GenerateCompanyPasswordHash(_network_company_info[_local_company].password);
 
	ttd_strlcpy(_network_company_info[_local_company].password, new_pw, sizeof(_network_company_info[_local_company].password));
 
	strecpy(_network_company_info[_local_company].password, new_pw, lastof(_network_company_info[_local_company].password));
 
}
 

	
 

	
 
// **********
 
// Sending functions
 
//   DEF_CLIENT_SEND_COMMAND has no parameters
 
@@ -416,26 +416,26 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
		} else if (playas != ci->client_playas) {
 
			// The client changed from client-player..
 
			// Do not display that for now
 
		}
 

	
 
		ci->client_playas = playas;
 
		ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
 
		strecpy(ci->client_name, name, lastof(ci->client_name));
 

	
 
		InvalidateWindow(WC_CLIENT_LIST, 0);
 

	
 
		return NETWORK_RECV_STATUS_OKAY;
 
	}
 

	
 
	// We don't have this index yet, find an empty index, and put the data there
 
	ci = NetworkFindClientInfoFromIndex(NETWORK_EMPTY_INDEX);
 
	if (ci != NULL) {
 
		ci->client_index = index;
 
		ci->client_playas = playas;
 

	
 
		ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
 
		strecpy(ci->client_name, name, lastof(ci->client_name));
 

	
 
		InvalidateWindow(WC_CLIENT_LIST, 0);
 

	
 
		return NETWORK_RECV_STATUS_OKAY;
 
	}
 

	
 
@@ -948,13 +948,13 @@ void NetworkUpdateClientName()
 
	if (strcmp(ci->client_name, _settings_client.network.client_name) != 0) {
 
		if (!_network_server) {
 
			SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.client_name);
 
		} else {
 
			if (NetworkFindName(_settings_client.network.client_name)) {
 
				NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.client_name);
 
				ttd_strlcpy(ci->client_name, _settings_client.network.client_name, sizeof(ci->client_name));
 
				strecpy(ci->client_name, _settings_client.network.client_name, lastof(ci->client_name));
 
				NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
 
			}
 
		}
 
	}
 
}
 

	
src/network/network_data.cpp
Show inline comments
 
@@ -50,13 +50,13 @@ void NetworkSend_Command(TileIndex tile,
 

	
 
	if (c.callback == _callback_table_count) {
 
		DEBUG(net, 0, "Unknown callback. (Pointer: %p) No callback sent", callback);
 
		c.callback = 0; // _callback_table[0] == NULL
 
	}
 

	
 
	ttd_strlcpy(c.text, (_cmd_text != NULL) ? _cmd_text : "", lengthof(c.text));
 
	strecpy(c.text, (_cmd_text != NULL) ? _cmd_text : "", lastof(c.text));
 

	
 
	if (_network_server) {
 
		/* If we are the server, we queue the command in our 'special' queue.
 
		 *   In theory, we could execute the command right away, but then the
 
		 *   client on the server can do everything 1 tick faster than others.
 
		 *   So to keep the game fair, we delay the command with 1 tick
src/network/network_gui.cpp
Show inline comments
 
@@ -669,15 +669,15 @@ public:
 
		}
 

	
 
		if (this->HandleEditBoxKey(NGWW_CLIENT, key, keycode, state) == HEBR_CONFIRM) return state;
 

	
 
		/* The name is only allowed when it starts with a letter! */
 
		if (!StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
 
			ttd_strlcpy(_settings_client.network.client_name, this->edit_str_buf, lengthof(_settings_client.network.client_name));
 
			strecpy(_settings_client.network.client_name, this->edit_str_buf, lastof(_settings_client.network.client_name));
 
		} else {
 
			ttd_strlcpy(_settings_client.network.client_name, "Player", lengthof(_settings_client.network.client_name));
 
			strecpy(_settings_client.network.client_name, "Player", lastof(_settings_client.network.client_name));
 
		}
 
		return state;
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
@@ -1000,14 +1000,14 @@ struct NetworkStartServerWindow : public
 
					ShowGenerateLandscape();
 
				} else { // load a scenario
 
					char *name = FiosBrowseTo(this->map);
 
					if (name != NULL) {
 
						SetFiosType(this->map->type);
 
						_file_to_saveload.filetype = FT_SCENARIO;
 
						ttd_strlcpy(_file_to_saveload.name, name, sizeof(_file_to_saveload.name));
 
						ttd_strlcpy(_file_to_saveload.title, this->map->title, sizeof(_file_to_saveload.title));
 
						strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
 
						strecpy(_file_to_saveload.title, this->map->title, lastof(_file_to_saveload.title));
 

	
 
						delete this;
 
						SwitchMode(SM_START_SCENARIO);
 
					}
 
				}
 
				break;
 
@@ -1046,24 +1046,24 @@ struct NetworkStartServerWindow : public
 
	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 
	{
 
		EventState state = ES_NOT_HANDLED;
 
		if (this->field == NSSW_GAMENAME) {
 
			if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == HEBR_CONFIRM) return state;
 

	
 
			ttd_strlcpy(_settings_client.network.server_name, this->text.buf, sizeof(_settings_client.network.server_name));
 
			strecpy(_settings_client.network.server_name, this->text.buf, lastof(_settings_client.network.server_name));
 
		}
 

	
 
		return state;
 
	}
 

	
 
	virtual void OnQueryTextFinished(char *str)
 
	{
 
		if (str == NULL) return;
 

	
 
		if (this->widget_id == NSSW_SETPWD) {
 
			ttd_strlcpy(_settings_client.network.server_password, str, lengthof(_settings_client.network.server_password));
 
			strecpy(_settings_client.network.server_password, str, lastof(_settings_client.network.server_password));
 
		} else {
 
			int32 value = atoi(str);
 
			this->InvalidateWidget(this->widget_id);
 
			switch (this->widget_id) {
 
				default: NOT_REACHED();
 
				case NSSW_CLIENTS_TXT:    _settings_client.network.max_clients    = Clamp(value, 2, MAX_CLIENTS); break;
src/network/network_server.cpp
Show inline comments
 
@@ -676,24 +676,24 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
				return;
 
			}
 
			break;
 
	}
 

	
 
	// We need a valid name.. make it Player
 
	if (StrEmpty(name)) ttd_strlcpy(name, "Player", sizeof(name));
 
	if (StrEmpty(name)) strecpy(name, "Player", lastof(name));
 

	
 
	if (!NetworkFindName(name)) { // Change name if duplicate
 
		// We could not create a name for this client
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NAME_IN_USE);
 
		return;
 
	}
 

	
 
	ci = DEREF_CLIENT_INFO(cs);
 

	
 
	ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
 
	ttd_strlcpy(ci->unique_id, unique_id, sizeof(ci->unique_id));
 
	strecpy(ci->client_name, name, lastof(ci->client_name));
 
	strecpy(ci->unique_id, unique_id, lastof(ci->unique_id));
 
	ci->client_playas = playas;
 
	ci->client_lang = client_lang;
 

	
 
	/* Make sure companies to which people try to join are not autocleaned */
 
	if (IsValidCompanyID(playas)) _network_company_info[playas].months_empty = 0;
 

	
 
@@ -1191,13 +1191,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	const NetworkClientInfo *ci;
 

	
 
	p->Recv_string(password, sizeof(password));
 
	ci = DEREF_CLIENT_INFO(cs);
 

	
 
	if (IsValidCompanyID(ci->client_playas)) {
 
		ttd_strlcpy(_network_company_info[ci->client_playas].password, password, sizeof(_network_company_info[0].password));
 
		strecpy(_network_company_info[ci->client_playas].password, password, lastof(_network_company_info[0].password));
 
	}
 
}
 

	
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_NAME)
 
{
 
	if (cs->status != STATUS_ACTIVE) {
 
@@ -1215,13 +1215,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	if (cs->has_quit) return;
 

	
 
	if (ci != NULL) {
 
		// Display change
 
		if (NetworkFindName(client_name)) {
 
			NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", client_name);
 
			ttd_strlcpy(ci->client_name, client_name, sizeof(ci->client_name));
 
			strecpy(ci->client_name, client_name, lastof(ci->client_name));
 
			NetworkUpdateClientInfo(ci->client_index);
 
		}
 
	}
 
}
 

	
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_RCON)
 
@@ -1310,17 +1310,17 @@ void NetworkPopulateCompanyInfo()
 
	for (CompanyID cid = COMPANY_FIRST; cid < MAX_COMPANIES; cid++) {
 
		if (!IsValidCompanyID(cid)) memset(&_network_company_info[cid], 0, sizeof(NetworkCompanyInfo));
 
	}
 

	
 
	FOR_ALL_COMPANIES(c) {
 
		// Clean the info but not the password
 
		ttd_strlcpy(password, _network_company_info[c->index].password, sizeof(password));
 
		strecpy(password, _network_company_info[c->index].password, lastof(password));
 
		months_empty = _network_company_info[c->index].months_empty;
 
		memset(&_network_company_info[c->index], 0, sizeof(NetworkCompanyInfo));
 
		_network_company_info[c->index].months_empty = months_empty;
 
		ttd_strlcpy(_network_company_info[c->index].password, password, sizeof(_network_company_info[c->index].password));
 
		strecpy(_network_company_info[c->index].password, password, lastof(_network_company_info[c->index].password));
 

	
 
		// Grap the company name
 
		SetDParam(0, c->index);
 
		GetString(_network_company_info[c->index].company_name, STR_COMPANY_NAME, lastof(_network_company_info[c->index].company_name));
 

	
 
		// Check the income
 
@@ -1369,26 +1369,26 @@ void NetworkPopulateCompanyInfo()
 
		}
 
	}
 

	
 
	ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
 
	// Register local company (if not dedicated)
 
	if (ci != NULL && IsValidCompanyID(ci->client_playas))
 
		ttd_strlcpy(_network_company_info[ci->client_playas].clients, ci->client_name, sizeof(_network_company_info[0].clients));
 
		strecpy(_network_company_info[ci->client_playas].clients, ci->client_name, lastof(_network_company_info[0].clients));
 

	
 
	FOR_ALL_CLIENTS(cs) {
 
		char client_name[NETWORK_CLIENT_NAME_LENGTH];
 

	
 
		NetworkGetClientName(client_name, sizeof(client_name), cs);
 

	
 
		ci = DEREF_CLIENT_INFO(cs);
 
		if (ci != NULL && IsValidCompanyID(ci->client_playas)) {
 
			if (!StrEmpty(_network_company_info[ci->client_playas].clients)) {
 
				ttd_strlcat(_network_company_info[ci->client_playas].clients, ", ", lengthof(_network_company_info[0].clients));
 
				strecat(_network_company_info[ci->client_playas].clients, ", ", lastof(_network_company_info[0].clients));
 
			}
 

	
 
			ttd_strlcat(_network_company_info[ci->client_playas].clients, client_name, lengthof(_network_company_info[0].clients));
 
			strecat(_network_company_info[ci->client_playas].clients, client_name, lastof(_network_company_info[0].clients));
 
		}
 
	}
 
}
 

	
 
// Send a packet to all clients with updated info about this client_index
 
void NetworkUpdateClientInfo(uint16 client_index)
src/network/network_udp.cpp
Show inline comments
 
@@ -91,15 +91,15 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_U
 
	ngi.map_width      = MapSizeX();
 
	ngi.map_height     = MapSizeY();
 
	ngi.map_set        = _settings_game.game_creation.landscape;
 
	ngi.dedicated      = _network_dedicated;
 
	ngi.grfconfig      = _grfconfig;
 

	
 
	ttd_strlcpy(ngi.map_name, _network_game_info.map_name, lengthof(ngi.map_name));
 
	ttd_strlcpy(ngi.server_name, _settings_client.network.server_name, lengthof(ngi.server_name));
 
	ttd_strlcpy(ngi.server_revision, _openttd_revision, lengthof(ngi.server_revision));
 
	strecpy(ngi.map_name, _network_game_info.map_name, lastof(ngi.map_name));
 
	strecpy(ngi.server_name, _settings_client.network.server_name, lastof(ngi.server_name));
 
	strecpy(ngi.server_revision, _openttd_revision, lastof(ngi.server_revision));
 

	
 
	Packet packet(PACKET_UDP_SERVER_RESPONSE);
 
	this->Send_NetworkGameInfo(&packet, &ngi);
 

	
 
	// Let the client know that we are here
 
	this->SendPacket(&packet, client_addr);
 
@@ -206,14 +206,14 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_U
 
	Packet packet(PACKET_UDP_SERVER_NEWGRFS);
 
	packet.Send_uint8(in_reply_count);
 
	for (i = 0; i < in_reply_count; i++) {
 
		char name[NETWORK_GRF_NAME_LENGTH];
 

	
 
		/* The name could be an empty string, if so take the filename */
 
		ttd_strlcpy(name, (in_reply[i]->name != NULL && !StrEmpty(in_reply[i]->name)) ?
 
				in_reply[i]->name : in_reply[i]->filename, sizeof(name));
 
		strecpy(name, (in_reply[i]->name != NULL && !StrEmpty(in_reply[i]->name)) ?
 
				in_reply[i]->name : in_reply[i]->filename, lastof(name));
 
		this->Send_GRFIdentifier(&packet, in_reply[i]);
 
		packet.Send_string(name);
 
	}
 

	
 
	this->SendPacket(&packet, client_addr);
 
}
 
@@ -462,14 +462,14 @@ void NetworkUDPQueryServer(const char* h
 
	// Clear item in gamelist
 
	item = NetworkGameListAddItem(inet_addr(inet_ntoa(out_addr.sin_addr)), ntohs(out_addr.sin_port));
 
	if (item == NULL) return;
 

	
 
	if (StrEmpty(item->info.server_name)) {
 
		memset(&item->info, 0, sizeof(item->info));
 
		ttd_strlcpy(item->info.server_name, host, lengthof(item->info.server_name));
 
		ttd_strlcpy(item->info.hostname, host, lengthof(item->info.hostname));
 
		strecpy(item->info.server_name, host, lastof(item->info.server_name));
 
		strecpy(item->info.hostname, host, lastof(item->info.hostname));
 
		item->online = false;
 
	}
 
	item->manually = manually;
 

	
 
	// Init the packet
 
	Packet p(PACKET_UDP_CLIENT_FIND_SERVER);
src/newgrf_config.cpp
Show inline comments
 
@@ -443,13 +443,13 @@ char *FindUnknownGRFName(uint32 grfid, u
 

	
 
	if (!create) return NULL;
 

	
 
	grf = CallocT<UnknownGRF>(1);
 
	grf->grfid = grfid;
 
	grf->next  = unknown_grfs;
 
	ttd_strlcpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, sizeof(grf->name));
 
	strecpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, lastof(grf->name));
 
	memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum));
 

	
 
	unknown_grfs = grf;
 
	return grf->name;
 
}
 

	
src/openttd.cpp
Show inline comments
 
@@ -421,17 +421,17 @@ int ttd_main(int argc, char *argv[])
 
	;
 

	
 
	MyGetOptData mgo(argc - 1, argv + 1, optformat);
 

	
 
	while ((i = MyGetOpt(&mgo)) != -1) {
 
		switch (i) {
 
		case 'I': ttd_strlcpy(graphics_set, mgo.opt, sizeof(graphics_set)); break;
 
		case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
 
		case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break;
 
		case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
 
		case 'b': ttd_strlcpy(blitter, mgo.opt, sizeof(blitter)); break;
 
		case 'I': strecpy(graphics_set, mgo.opt, lastof(graphics_set)); break;
 
		case 'm': strecpy(musicdriver, mgo.opt, lastof(musicdriver)); break;
 
		case 's': strecpy(sounddriver, mgo.opt, lastof(sounddriver)); break;
 
		case 'v': strecpy(videodriver, mgo.opt, lastof(videodriver)); break;
 
		case 'b': strecpy(blitter, mgo.opt, lastof(blitter)); break;
 
#if defined(ENABLE_NETWORK)
 
		case 'D':
 
			strcpy(musicdriver, "null");
 
			strcpy(sounddriver, "null");
 
			strcpy(videodriver, "dedicated");
 
			strcpy(blitter, "null");
 
@@ -464,13 +464,13 @@ int ttd_main(int argc, char *argv[])
 
				if (mgo.opt != NULL) SetDebugString(mgo.opt);
 
			} break;
 
		case 'e': _switch_mode = SM_EDITOR; break;
 
		case 'i': _use_palette = (mgo.opt == NULL || atoi(mgo.opt) == 0) ? PAL_DOS : PAL_WINDOWS; break;
 
		case 'g':
 
			if (mgo.opt != NULL) {
 
				ttd_strlcpy(_file_to_saveload.name, mgo.opt, sizeof(_file_to_saveload.name));
 
				strecpy(_file_to_saveload.name, mgo.opt, lastof(_file_to_saveload.name));
 
				_switch_mode = SM_LOAD;
 
				_file_to_saveload.mode = SL_LOAD;
 

	
 
				/* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
 
				const char *t = strrchr(_file_to_saveload.name, '.');
 
				if (t != NULL) {
 
@@ -519,17 +519,17 @@ int ttd_main(int argc, char *argv[])
 
	LoadFromConfig();
 
	CheckConfig();
 
	LoadFromHighScore();
 

	
 

	
 
	/* override config? */
 
	if (!StrEmpty(graphics_set)) ttd_strlcpy(_ini_graphics_set, graphics_set, sizeof(_ini_graphics_set));
 
	if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
 
	if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
 
	if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
 
	if (!StrEmpty(blitter))     ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
 
	if (!StrEmpty(graphics_set)) strecpy(_ini_graphics_set, graphics_set, lastof(_ini_graphics_set));
 
	if (!StrEmpty(musicdriver)) strecpy(_ini_musicdriver, musicdriver, lastof(_ini_musicdriver));
 
	if (!StrEmpty(sounddriver)) strecpy(_ini_sounddriver, sounddriver, lastof(_ini_sounddriver));
 
	if (!StrEmpty(videodriver)) strecpy(_ini_videodriver, videodriver, lastof(_ini_videodriver));
 
	if (!StrEmpty(blitter))     strecpy(_ini_blitter, blitter, lastof(_ini_blitter));
 
	if (resolution.width != 0) { _cur_resolution = resolution; }
 
	if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
 
	if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
 

	
 
	/* The width and height must be at least 1 pixel, this
 
	 * way all internal drawing routines work correctly. */
 
@@ -1106,13 +1106,13 @@ static void DoAutosave()
 
#endif /* PSP */
 

	
 
	if (_settings_client.gui.keep_all_autosave && _local_company != COMPANY_SPECTATOR) {
 
		SetDParam(0, _local_company);
 
		SetDParam(1, _date);
 
		GetString(buf, STR_4004, lastof(buf));
 
		ttd_strlcat(buf, ".sav", lengthof(buf));
 
		strecat(buf, ".sav", lastof(buf));
 
	} else {
 
		/* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */
 
		snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
 

	
 
		if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0;
 
	}
src/os2.cpp
Show inline comments
 
@@ -72,13 +72,13 @@ void FiosGetDrives()
 
			fios->mtime = 0;
 
#ifndef __INNOTEK_LIBC__
 
			snprintf(fios->name, lengthof(fios->name),  "%c:", 'A' + disk - 1);
 
#else
 
			snprintf(fios->name, lengthof(fios->name),  "%c:", disk);
 
#endif
 
			ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
 
			strecpy(fios->title, fios->name, lastof(fios->title));
 
		}
 
	}
 

	
 
	/* Restore the original drive */
 
#ifndef __INNOTEK_LIBC__
 
	_dos_setdrive(save, &total);
src/screenshot.cpp
Show inline comments
 
@@ -545,13 +545,13 @@ static char *MakeScreenshotName(const ch
 
{
 
	static char filename[MAX_PATH];
 
	int serial;
 
	size_t len;
 

	
 
	if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
 
		ttd_strlcpy(_screenshot_name, "screenshot", lengthof(_screenshot_name));
 
		strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
 
	} else {
 
		SetDParam(0, _local_company);
 
		SetDParam(1, _date);
 
		GetString(_screenshot_name, STR_4004, lastof(_screenshot_name));
 
	}
 

	
src/settings_gui.cpp
Show inline comments
 
@@ -1187,21 +1187,21 @@ struct CustomCurrencyWindow : Window {
 
			case CUSTCURR_EXCHANGERATE:
 
				_custom_currency.rate = Clamp(atoi(str), 1, 5000);
 
				break;
 

	
 
			case CUSTCURR_SEPARATOR: /* Thousands seperator */
 
				_custom_currency.separator = StrEmpty(str) ? ' ' : str[0];
 
				ttd_strlcpy(this->separator, str, lengthof(this->separator));
 
				strecpy(this->separator, str, lastof(this->separator));
 
				break;
 

	
 
			case CUSTCURR_PREFIX:
 
				ttd_strlcpy(_custom_currency.prefix, str, lengthof(_custom_currency.prefix));
 
				strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
 
				break;
 

	
 
			case CUSTCURR_SUFFIX:
 
				ttd_strlcpy(_custom_currency.suffix, str, lengthof(_custom_currency.suffix));
 
				strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
 
				break;
 

	
 
			case CUSTCURR_TO_EURO: { /* Year to switch to euro */
 
				int val = atoi(str);
 

	
 
				_custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
src/strgen/strgen.cpp
Show inline comments
 
@@ -640,17 +640,17 @@ static const CmdStruct *ParseCommandStri
 

	
 
static void HandlePragma(char *str)
 
{
 
	if (!memcmp(str, "id ", 3)) {
 
		_next_string_id = strtoul(str + 3, NULL, 0);
 
	} else if (!memcmp(str, "name ", 5)) {
 
		ttd_strlcpy(_lang_name, str + 5, sizeof(_lang_name));
 
		strecpy(_lang_name, str + 5, lastof(_lang_name));
 
	} else if (!memcmp(str, "ownname ", 8)) {
 
		ttd_strlcpy(_lang_ownname, str + 8, sizeof(_lang_ownname));
 
		strecpy(_lang_ownname, str + 8, lastof(_lang_ownname));
 
	} else if (!memcmp(str, "isocode ", 8)) {
 
		ttd_strlcpy(_lang_isocode, str + 8, sizeof(_lang_isocode));
 
		strecpy(_lang_isocode, str + 8, lastof(_lang_isocode));
 
	} else if (!memcmp(str, "plural ", 7)) {
 
		_lang_pluralform = atoi(str + 7);
 
		if (_lang_pluralform >= lengthof(_plural_form_counts))
 
			error("Invalid pluralform %d", _lang_pluralform);
 
	} else if (!memcmp(str, "textdir ", 8)) {
 
		if (!memcmp(str + 8, "ltr", 3)) {
 
@@ -665,24 +665,24 @@ static void HandlePragma(char *str)
 

	
 
		for (;;) {
 
			const char* s = ParseWord(&buf);
 

	
 
			if (s == NULL) break;
 
			if (_numgenders >= MAX_NUM_GENDER) error("Too many genders, max %d", MAX_NUM_GENDER);
 
			ttd_strlcpy(_genders[_numgenders], s, sizeof(_genders[_numgenders]));
 
			strecpy(_genders[_numgenders], s, lastof(_genders[_numgenders]));
 
			_numgenders++;
 
		}
 
	} else if (!memcmp(str, "case ", 5)) {
 
		char* buf = str + 5;
 

	
 
		for (;;) {
 
			const char* s = ParseWord(&buf);
 

	
 
			if (s == NULL) break;
 
			if (_numcases >= MAX_NUM_CASES) error("Too many cases, max %d", MAX_NUM_CASES);
 
			ttd_strlcpy(_cases[_numcases], s, sizeof(_cases[_numcases]));
 
			strecpy(_cases[_numcases], s, lastof(_cases[_numcases]));
 
			_numcases++;
 
		}
 
	} else {
 
		error("unknown pragma '%s'", str);
 
	}
 
}
src/strings.cpp
Show inline comments
 
@@ -1268,13 +1268,13 @@ bool ReadLanguagePack(int lang_index)
 
	_langpack = lang_pack;
 

	
 
	free(_langpack_offs);
 
	_langpack_offs = langpack_offs;
 

	
 
	const char *c_file = strrchr(_dynlang.ent[lang_index].file, PATHSEPCHAR) + 1;
 
	ttd_strlcpy(_dynlang.curr_file, c_file, lengthof(_dynlang.curr_file));
 
	strecpy(_dynlang.curr_file, c_file, lastof(_dynlang.curr_file));
 

	
 
	_dynlang.curr = lang_index;
 
	_dynlang.text_dir = (TextDirection)lang_pack->text_dir;
 
	SetCurrentGrfLangID(_langpack->isocode);
 
	SortNetworkLanguages();
 
	return true;
src/unix.cpp
Show inline comments
 
@@ -151,13 +151,13 @@ static const char *convert_tofrom_fs(ico
 
#endif
 

	
 
	char *outbuf  = buf;
 
	size_t outlen = sizeof(buf) - 1;
 
	size_t inlen  = strlen(name);
 

	
 
	ttd_strlcpy(outbuf, name, sizeof(buf));
 
	strecpy(outbuf, name, lastof(buf));
 

	
 
	iconv(convd, NULL, NULL, NULL, NULL);
 
	if (iconv(convd, &inbuf, &inlen, &outbuf, &outlen) == (size_t)(-1)) {
 
		DEBUG(misc, 0, "[iconv] error converting '%s'. Errno %d", name, errno);
 
	}
 

	
src/win32.cpp
Show inline comments
 
@@ -800,24 +800,24 @@ void FiosGetDrives()
 
#if defined(WINCE)
 
	/* WinCE only knows one drive: / */
 
	FiosItem *fios = _fios_items.Append();
 
	fios->type = FIOS_TYPE_DRIVE;
 
	fios->mtime = 0;
 
	snprintf(fios->name, lengthof(fios->name), PATHSEP "");
 
	ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
 
	strecpy(fios->title, fios->name, lastof(fios->title));
 
#else
 
	TCHAR drives[256];
 
	const TCHAR *s;
 

	
 
	GetLogicalDriveStrings(lengthof(drives), drives);
 
	for (s = drives; *s != '\0';) {
 
		FiosItem *fios = _fios_items.Append();
 
		fios->type = FIOS_TYPE_DRIVE;
 
		fios->mtime = 0;
 
		snprintf(fios->name, lengthof(fios->name),  "%c:", s[0] & 0xFF);
 
		ttd_strlcpy(fios->title, fios->name, lengthof(fios->title));
 
		strecpy(fios->title, fios->name, lastof(fios->title));
 
		while (*s++ != '\0') { /* Nothing */ }
 
	}
 
#endif
 
}
 

	
 
bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb)
 
@@ -1124,13 +1124,13 @@ bool InsertTextBufferClipboard(Textbuf *
 
#if !defined(UNICODE)
 
	} else if (IsClipboardFormatAvailable(CF_TEXT)) {
 
		OpenClipboard(NULL);
 
		cbuf = GetClipboardData(CF_TEXT);
 

	
 
		ptr = (const char*)GlobalLock(cbuf);
 
		ttd_strlcpy(utf8_buf, FS2OTTD(ptr), lengthof(utf8_buf));
 
		strecpy(utf8_buf, FS2OTTD(ptr), lastof(utf8_buf));
 

	
 
		GlobalUnlock(cbuf);
 
		CloseClipboard();
 
#endif /* UNICODE */
 
	} else {
 
		return false;
0 comments (0 inline, 0 general)