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
 
@@ -475,51 +475,51 @@ bool CrashLog::MakeCrashLog() const
 
	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;
 
}
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -82,13 +82,13 @@ static inline bool HaveChatMessages(bool
 
}
 

	
 
/**
 
 * 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();
 
	}
src/openttd.cpp
Show inline comments
 
@@ -222,13 +222,13 @@ static void ShowHelp()
 
	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)
 
@@ -259,13 +259,13 @@ static void WriteSavegameInfo(const char
 
		}
 
	}
 

	
 
	/* 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
 
}
 

	
 

	
src/os/macosx/crashlog_osx.cpp
Show inline comments
 
@@ -166,30 +166,30 @@ public:
 
	/** 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();
src/os/unix/crashlog_unix.cpp
Show inline comments
 
@@ -153,21 +153,21 @@ 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();
 

	
src/pathfinder/npf/aystar.cpp
Show inline comments
 
@@ -208,13 +208,13 @@ 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.
 
@@ -226,13 +226,13 @@ void AyStar::Clear()
 
	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:
 
@@ -247,15 +247,15 @@ 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();
 
@@ -277,13 +277,13 @@ int AyStar::Main()
 
 * @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);
 
}
 

	
 
/**
src/pathfinder/npf/queue.cpp
Show inline comments
 
@@ -300,35 +300,32 @@ void Hash::PrintStatistics() const
 
		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
 
 */
src/script/squirrel.cpp
Show inline comments
 
@@ -266,13 +266,13 @@ SQInteger Squirrel::_RunError(HSQUIRRELV
 

	
 
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)
src/strgen/strgen.cpp
Show inline comments
 
@@ -424,39 +424,39 @@ int CDECL main(int argc, char *argv[])
 
		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;
0 comments (0 inline, 0 general)