Changeset - r27404:8b233646def8
[Not reviewed]
master
0 9 0
Rubidium - 17 months ago 2023-05-21 06:04:33
rubidium@openttd.org
Codechange: replace printf with fmt::print
9 files changed with 49 insertions and 52 deletions:
0 comments (0 inline, 0 general)
src/crashlog.cpp
Show inline comments
 
@@ -469,63 +469,63 @@ void CrashLog::SendSurvey() const
 
 */
 
bool CrashLog::MakeCrashLog() const
 
{
 
	/* Don't keep looping logging crashes. */
 
	static bool crashlogged = false;
 
	if (crashlogged) return false;
 
	crashlogged = true;
 

	
 
	char filename[MAX_PATH];
 
	char buffer[65536];
 
	bool ret = true;
 

	
 
	printf("Crash encountered, generating crash log...\n");
 
	fmt::print("Crash encountered, generating crash log...\n");
 
	this->FillCrashLog(buffer, lastof(buffer));
 
	printf("%s\n", buffer);
 
	printf("Crash log generated.\n\n");
 
	fmt::print("{}\n", buffer);
 
	fmt::print("Crash log generated.\n\n");
 

	
 
	printf("Writing crash log to disk...\n");
 
	fmt::print("Writing crash log to disk...\n");
 
	bool bret = this->WriteCrashLog(buffer, filename, lastof(filename));
 
	if (bret) {
 
		printf("Crash log written to %s. Please add this file to any bug reports.\n\n", filename);
 
		fmt::print("Crash log written to {}. Please add this file to any bug reports.\n\n", filename);
 
	} else {
 
		printf("Writing crash log failed. Please attach the output above to any bug reports.\n\n");
 
		fmt::print("Writing crash log failed. Please attach the output above to any bug reports.\n\n");
 
		ret = false;
 
	}
 

	
 
	/* Don't mention writing crash dumps because not all platforms support it. */
 
	int dret = this->WriteCrashDump(filename, lastof(filename));
 
	if (dret < 0) {
 
		printf("Writing crash dump failed.\n\n");
 
		fmt::print("Writing crash dump failed.\n\n");
 
		ret = false;
 
	} else if (dret > 0) {
 
		printf("Crash dump written to %s. Please add this file to any bug reports.\n\n", filename);
 
		fmt::print("Crash dump written to {}. Please add this file to any bug reports.\n\n", filename);
 
	}
 

	
 
	printf("Writing crash savegame...\n");
 
	fmt::print("Writing crash savegame...\n");
 
	bret = this->WriteSavegame(filename, lastof(filename));
 
	if (bret) {
 
		printf("Crash savegame written to %s. Please add this file and the last (auto)save to any bug reports.\n\n", filename);
 
		fmt::print("Crash savegame written to {}. Please add this file and the last (auto)save to any bug reports.\n\n", filename);
 
	} else {
 
		ret = false;
 
		printf("Writing crash savegame failed. Please attach the last (auto)save to any bug reports.\n\n");
 
		fmt::print("Writing crash savegame failed. Please attach the last (auto)save to any bug reports.\n\n");
 
	}
 

	
 
	printf("Writing crash screenshot...\n");
 
	fmt::print("Writing crash screenshot...\n");
 
	bret = this->WriteScreenshot(filename, lastof(filename));
 
	if (bret) {
 
		printf("Crash screenshot written to %s. Please add this file to any bug reports.\n\n", filename);
 
		fmt::print("Crash screenshot written to {}. Please add this file to any bug reports.\n\n", filename);
 
	} else {
 
		ret = false;
 
		printf("Writing crash screenshot failed.\n\n");
 
		fmt::print("Writing crash screenshot failed.\n\n");
 
	}
 

	
 
	this->SendSurvey();
 

	
 
	return ret;
 
}
 

	
 
/**
 
 * Sets a message for the error message handler.
 
 * @param message The error message of the error.
 
 */
 
/* static */ void CrashLog::SetErrorMessage(const std::string &message)
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -76,25 +76,25 @@ static inline bool HaveChatMessages(bool
 
	auto now = std::chrono::steady_clock::now();
 
	for (auto &cmsg : _chatmsg_list) {
 
		if (cmsg.remove_time >= now) return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
/**
 
 * Add a text message to the 'chat window' to be shown
 
 * @param colour The colour this message is to be shown in
 
 * @param duration The duration of the chat message in seconds
 
 * @param message message itself in printf() style
 
 * @param message message itself
 
 */
 
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const std::string &message)
 
{
 
	if (_chatmsg_list.size() == MAX_CHAT_MESSAGES) {
 
		_chatmsg_list.pop_back();
 
	}
 

	
 
	ChatMessage *cmsg = &_chatmsg_list.emplace_front();
 
	cmsg->message = message;
 
	cmsg->colour = colour;
 
	cmsg->remove_time = std::chrono::steady_clock::now() + std::chrono::seconds(duration);
 

	
src/openttd.cpp
Show inline comments
 
@@ -216,25 +216,25 @@ static void ShowHelp()
 
	AI::Initialize();
 
	AI::GetConsoleList(output_iterator, true);
 
	AI::Uninitialize(true);
 

	
 
	/* We need to initialize the GameScript, so it finds the GSs */
 
	Game::Initialize();
 
	Game::GetConsoleList(output_iterator, true);
 
	Game::Uninitialize(true);
 

	
 
	/* ShowInfo put output to stderr, but version information should go
 
	 * to stdout; this is the only exception */
 
#if !defined(_WIN32)
 
	printf("%s\n", str.c_str());
 
	fmt::print("{}\n", str);
 
#else
 
	ShowInfoI(str);
 
#endif
 
}
 

	
 
static void WriteSavegameInfo(const char *name)
 
{
 
	extern SaveLoadVersion _sl_version;
 
	uint32 last_ottd_rev = 0;
 
	byte ever_modified = 0;
 
	bool removed_newgrfs = false;
 

	
 
@@ -253,25 +253,25 @@ static void WriteSavegameInfo(const char
 

	
 
	message += "NewGRFs:\n";
 
	if (_load_check_data.HasNewGrfs()) {
 
		for (GRFConfig *c = _load_check_data.grfconfig; c != nullptr; c = c->next) {
 
			fmt::format_to(std::back_inserter(message), "{:08X} {} {}\n", c->ident.grfid,
 
				FormatArrayAsHex(HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum), c->filename);
 
		}
 
	}
 

	
 
	/* ShowInfo put output to stderr, but version information should go
 
	 * to stdout; this is the only exception */
 
#if !defined(_WIN32)
 
	printf("%s\n", message.c_str());
 
	fmt::print("%s\n", message);
 
#else
 
	ShowInfoI(message);
 
#endif
 
}
 

	
 

	
 
/**
 
 * Extract the resolution from the given string and store
 
 * it in the 'res' parameter.
 
 * @param res variable to store the resolution in.
 
 * @param s   the string to decompose.
 
 */
src/os/macosx/crashlog_osx.cpp
Show inline comments
 
@@ -160,42 +160,42 @@ public:
 
	{
 
		filename_log[0] = '\0';
 
		filename_save[0] = '\0';
 
		filename_screenshot[0] = '\0';
 
	}
 

	
 
	/** Generate the crash log. */
 
	bool MakeCrashLog()
 
	{
 
		char buffer[65536];
 
		bool ret = true;
 

	
 
		printf("Crash encountered, generating crash log...\n");
 
		fmt::print("Crash encountered, generating crash log...\n");
 
		this->FillCrashLog(buffer, lastof(buffer));
 
		printf("%s\n", buffer);
 
		printf("Crash log generated.\n\n");
 
		fmt::print("{}\n", buffer);
 
		fmt::print("Crash log generated.\n\n");
 

	
 
		printf("Writing crash log to disk...\n");
 
		fmt::print("Writing crash log to disk...\n");
 
		if (!this->WriteCrashLog(buffer, filename_log, lastof(filename_log))) {
 
			filename_log[0] = '\0';
 
			ret = false;
 
		}
 

	
 
		printf("Writing crash savegame...\n");
 
		fmt::print("Writing crash savegame...\n");
 
		if (!this->WriteSavegame(filename_save, lastof(filename_save))) {
 
			filename_save[0] = '\0';
 
			ret = false;
 
		}
 

	
 
		printf("Writing crash screenshot...\n");
 
		fmt::print("Writing crash screenshot...\n");
 
		if (!this->WriteScreenshot(filename_screenshot, lastof(filename_screenshot))) {
 
			filename_screenshot[0] = '\0';
 
			ret = false;
 
		}
 

	
 
		this->SendSurvey();
 

	
 
		return ret;
 
	}
 

	
 
	/** Show a dialog with the crash information. */
 
	void DisplayCrashDialog() const
src/os/unix/crashlog_unix.cpp
Show inline comments
 
@@ -147,33 +147,33 @@ static const int _signals_to_handle[] = 
 
 * Entry point for the crash handler.
 
 * @note Not static so it shows up in the backtrace.
 
 * @param signum the signal that caused us to crash.
 
 */
 
static void CDECL HandleCrash(int signum)
 
{
 
	/* Disable all handling of signals by us, so we don't go into infinite loops. */
 
	for (const int *i = _signals_to_handle; i != endof(_signals_to_handle); i++) {
 
		signal(*i, SIG_DFL);
 
	}
 

	
 
	if (_gamelog.TestEmergency()) {
 
		printf("A serious fault condition occurred in the game. The game will shut down.\n");
 
		printf("As you loaded an emergency savegame no crash information will be generated.\n");
 
		fmt::print("A serious fault condition occurred in the game. The game will shut down.\n");
 
		fmt::print("As you loaded an emergency savegame no crash information will be generated.\n");
 
		abort();
 
	}
 

	
 
	if (SaveloadCrashWithMissingNewGRFs()) {
 
		printf("A serious fault condition occurred in the game. The game will shut down.\n");
 
		printf("As you loaded an savegame for which you do not have the required NewGRFs\n");
 
		printf("no crash information will be generated.\n");
 
		fmt::print("A serious fault condition occurred in the game. The game will shut down.\n");
 
		fmt::print("As you loaded an savegame for which you do not have the required NewGRFs\n");
 
		fmt::print("no crash information will be generated.\n");
 
		abort();
 
	}
 

	
 
	CrashLogUnix log(signum);
 
	log.MakeCrashLog();
 

	
 
	CrashLog::AfterCrashLogCleanup();
 
	abort();
 
}
 

	
 
/* static */ void CrashLog::InitialiseCrashLog()
 
{
src/pathfinder/npf/aystar.cpp
Show inline comments
 
@@ -202,66 +202,66 @@ int AyStar::Loop()
 

	
 
/**
 
 * This function frees the memory it allocated
 
 */
 
void AyStar::Free()
 
{
 
	this->openlist_queue.Free(false);
 
	/* 2nd argument above is false, below is true, to free the values only
 
	 * once */
 
	this->openlist_hash.Delete(true);
 
	this->closedlist_hash.Delete(true);
 
#ifdef AYSTAR_DEBUG
 
	printf("[AyStar] Memory free'd\n");
 
	Debug(misc, 0, "[AyStar] Memory free'd");
 
#endif
 
}
 

	
 
/**
 
 * This function make the memory go back to zero.
 
 * This function should be called when you are using the same instance again.
 
 */
 
void AyStar::Clear()
 
{
 
	/* Clean the Queue, but not the elements within. That will be done by
 
	 * the hash. */
 
	this->openlist_queue.Clear(false);
 
	/* Clean the hashes */
 
	this->openlist_hash.Clear(true);
 
	this->closedlist_hash.Clear(true);
 

	
 
#ifdef AYSTAR_DEBUG
 
	printf("[AyStar] Cleared AyStar\n");
 
	Debug(misc, 0, "[AyStar] Cleared AyStar");
 
#endif
 
}
 

	
 
/**
 
 * This is the function you call to run AyStar.
 
 * @return Possible values:
 
 *  - #AYSTAR_FOUND_END_NODE : indicates we found an end node.
 
 *  - #AYSTAR_NO_PATH : indicates that there was no path found.
 
 *  - #AYSTAR_STILL_BUSY : indicates we have done some checked, that we did not found the path yet, and that we still have items left to try.
 
 * @note When the algorithm is done (when the return value is not #AYSTAR_STILL_BUSY) #Clear() is called automatically.
 
 *       When you stop the algorithm halfway, you should call #Clear() yourself!
 
 */
 
int AyStar::Main()
 
{
 
	int r, i = 0;
 
	/* Loop through the OpenList
 
	 *  Quit if result is no AYSTAR_STILL_BUSY or is more than loops_per_tick */
 
	while ((r = this->Loop()) == AYSTAR_STILL_BUSY && (this->loops_per_tick == 0 || ++i < this->loops_per_tick)) { }
 
#ifdef AYSTAR_DEBUG
 
	switch (r) {
 
		case AYSTAR_FOUND_END_NODE: printf("[AyStar] Found path!\n"); break;
 
		case AYSTAR_EMPTY_OPENLIST: printf("[AyStar] OpenList run dry, no path found\n"); break;
 
		case AYSTAR_LIMIT_REACHED:  printf("[AyStar] Exceeded search_nodes, no path found\n"); break;
 
		case AYSTAR_FOUND_END_NODE: Debug(misc, 0, "[AyStar] Found path!"); break;
 
		case AYSTAR_EMPTY_OPENLIST: Debug(misc, 0, "[AyStar] OpenList run dry, no path found"); break;
 
		case AYSTAR_LIMIT_REACHED:  Debug(misc, 0, "[AyStar] Exceeded search_nodes, no path found"); break;
 
		default: break;
 
	}
 
#endif
 
	if (r != AYSTAR_STILL_BUSY) {
 
		/* We're done, clean up */
 
		this->Clear();
 
	}
 

	
 
	switch (r) {
 
		case AYSTAR_FOUND_END_NODE: return AYSTAR_FOUND_END_NODE;
 
		case AYSTAR_EMPTY_OPENLIST:
 
		case AYSTAR_LIMIT_REACHED:  return AYSTAR_NO_PATH;
 
@@ -271,25 +271,25 @@ int AyStar::Main()
 

	
 
/**
 
 * Adds a node from where to start an algorithm. Multiple nodes can be added
 
 * if wanted. You should make sure that #Clear() is called before adding nodes
 
 * if the #AyStar has been used before (though the normal main loop calls
 
 * #Clear() automatically when the algorithm finishes.
 
 * @param start_node Node to start with.
 
 * @param g the cost for starting with this node.
 
 */
 
void AyStar::AddStartNode(AyStarNode *start_node, uint g)
 
{
 
#ifdef AYSTAR_DEBUG
 
	printf("[AyStar] Starting A* Algorithm from node (%d, %d, %d)\n",
 
	Debug(misc, 0, "[AyStar] Starting A* Algorithm from node ({}, {}, {})\n",
 
		TileX(start_node->tile), TileY(start_node->tile), start_node->direction);
 
#endif
 
	this->OpenListAdd(nullptr, start_node, 0, g);
 
}
 

	
 
/**
 
 * Initialize an #AyStar. You should fill all appropriate fields before
 
 * calling #Init (see the declaration of #AyStar for which fields are internal).
 
 */
 
void AyStar::Init(Hash_HashProc hash, uint num_buckets)
 
{
 
	/* Allocated the Hash for the OpenList and ClosedList */
src/pathfinder/npf/queue.cpp
Show inline comments
 
@@ -294,47 +294,44 @@ void Hash::PrintStatistics() const
 
			const HashNode *node;
 

	
 
			used_buckets++;
 
			for (node = &this->buckets[i]; node != nullptr; node = node->next) collision++;
 
			if (collision > max_collision) max_collision = collision;
 
		}
 
		if (collision >= lengthof(usage)) collision = lengthof(usage) - 1;
 
		usage[collision]++;
 
		if (collision > 0 && usage[collision] >= max_usage) {
 
			max_usage = usage[collision];
 
		}
 
	}
 
	printf(
 
		"---\n"
 
		"Hash size: %u\n"
 
		"Nodes used: %u\n"
 
		"Non empty buckets: %u\n"
 
		"Max collision: %u\n",
 
	Debug(misc, 0, "Hash size: {}, Nodes used: {}, Non empty buckets: {}, Max collision: {}",
 
		this->num_buckets, this->size, used_buckets, max_collision
 
	);
 
	printf("{ ");
 
	std::string line;
 
	line += "{ ";
 
	for (i = 0; i <= max_collision; i++) {
 
		if (usage[i] > 0) {
 
			printf("%u:%u ", i, usage[i]);
 
			fmt::format_to(std::back_inserter(line), "{}:{} ", i, usage[i]);
 
#if 0
 
			if (i > 0) {
 
				uint j;
 

	
 
				for (j = 0; j < usage[i] * 160 / 800; j++) putchar('#');
 
				for (j = 0; j < usage[i] * 160 / 800; j++) line += "#";
 
			}
 
			printf("\n");
 
			line += "\n";
 
#endif
 
		}
 
	}
 
	printf ("}\n");
 
	line += "}";
 
	Debug(misc, 0, "{}", line);
 
}
 
#endif
 

	
 
/**
 
 * Cleans the hash, but keeps the memory allocated
 
 */
 
void Hash::Clear(bool free_values)
 
{
 
	uint i;
 

	
 
#ifdef HASH_STATS
 
	if (this->size > 2000) this->PrintStatistics();
src/script/squirrel.cpp
Show inline comments
 
@@ -260,25 +260,25 @@ SQInteger Squirrel::_RunError(HSQUIRRELV
 
		}
 
	}
 

	
 
	Squirrel::RunError(vm, "unknown error");
 
	return 0;
 
}
 

	
 
void Squirrel::PrintFunc(HSQUIRRELVM vm, const std::string &s)
 
{
 
	/* Check if we have a custom print function */
 
	SQPrintFunc *func = ((Squirrel *)sq_getforeignptr(vm))->print_func;
 
	if (func == nullptr) {
 
		printf("%s", s.c_str());
 
		fmt::print("%s", s);
 
	} else {
 
		(*func)(false, s);
 
	}
 
}
 

	
 
void Squirrel::AddMethod(const char *method_name, SQFUNCTION proc, uint nparam, const char *params, void *userdata, int size)
 
{
 
	ScriptAllocatorScope alloc_scope(this);
 

	
 
	sq_pushstring(this->vm, method_name, -1);
 

	
 
	if (size != 0) {
src/strgen/strgen.cpp
Show inline comments
 
@@ -418,51 +418,51 @@ int CDECL main(int argc, char *argv[])
 

	
 
	GetOptData mgo(argc - 1, argv + 1, _opts);
 
	for (;;) {
 
		int i = mgo.GetOpt();
 
		if (i == -1) break;
 

	
 
		switch (i) {
 
			case 'v':
 
				puts("$Revision$");
 
				return 0;
 

	
 
			case 'C':
 
				printf("args\tflags\tcommand\treplacement\n");
 
				fmt::print("args\tflags\tcommand\treplacement\n");
 
				for (const CmdStruct *cs = _cmd_structs; cs < endof(_cmd_structs); cs++) {
 
					char flags;
 
					if (cs->proc == EmitGender) {
 
						flags = 'g'; // Command needs number of parameters defined by number of genders
 
					} else if (cs->proc == EmitPlural) {
 
						flags = 'p'; // Command needs number of parameters defined by plural value
 
					} else if (cs->flags & C_DONTCOUNT) {
 
						flags = 'i'; // Command may be in the translation when it is not in base
 
					} else {
 
						flags = '0'; // Command needs no parameters
 
					}
 
					printf("%i\t%c\t\"%s\"\t\"%s\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
 
					fmt::print("{}\t{:c}\t\"{}\"\t\"{}\"\n", cs->consumes, flags, cs->cmd, strstr(cs->cmd, "STRING") ? "STRING" : cs->cmd);
 
				}
 
				return 0;
 

	
 
			case 'L':
 
				printf("count\tdescription\tnames\n");
 
				fmt::print("count\tdescription\tnames\n");
 
				for (const PluralForm *pf = _plural_forms; pf < endof(_plural_forms); pf++) {
 
					printf("%i\t\"%s\"\t%s\n", pf->plural_count, pf->description, pf->names);
 
					fmt::print("{}\t\"{}\"\t{}\n", pf->plural_count, pf->description, pf->names);
 
				}
 
				return 0;
 

	
 
			case 'P':
 
				printf("name\tflags\tdefault\tdescription\n");
 
				fmt::print("name\tflags\tdefault\tdescription\n");
 
				for (size_t j = 0; j < lengthof(_pragmas); j++) {
 
					printf("\"%s\"\t%s\t\"%s\"\t\"%s\"\n",
 
					fmt::print("\"{}\"\t{}\t\"{}\"\t\"{}\"\n",
 
							_pragmas[j][0], _pragmas[j][1], _pragmas[j][2], _pragmas[j][3]);
 
				}
 
				return 0;
 

	
 
			case 't':
 
				_show_todo |= 1;
 
				break;
 

	
 
			case 'w':
 
				_show_todo |= 2;
 
				break;
 

	
0 comments (0 inline, 0 general)