Workaround for StringFromFormat-under-linux problem, random cleanup.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1491 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-12-10 22:36:26 +00:00
parent 61392ba692
commit 0ad52a4fee
8 changed files with 62 additions and 47 deletions

View File

@ -137,7 +137,7 @@ public:
template<class T>
void DoLinkedList(LinkedListItem<T> **list_start) {
// TODO
PanicAlert("Do(vector<>) does not yet work.");
PanicAlert("Do(linked list<>) does not yet work.");
}
};

View File

@ -38,10 +38,10 @@ void PanicAlert(const char* format, ...)
if (panic_handler)
{
std::string msg;
StringFromFormatV(&msg, format, args);
LOG(MASTER_LOG, "PANIC: %s", msg.c_str());
panic_handler(msg.c_str(), false);
char buffer[2048];
CharArrayFromFormatV(buffer, 2048, format, args);
LOG(MASTER_LOG, "PANIC: %s", buffer);
panic_handler(buffer, false);
}
else
{

View File

@ -85,19 +85,23 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
// Expensive!
void StringFromFormatV(std::string* out, const char* format, va_list args)
void ToStringFromFormat(std::string* out, const char* format, ...)
{
int writtenCount = -1;
size_t newSize = strlen(format) + 16;
char* buf = 0;
int newSize = (int)strlen(format) + 4;
char *buf = 0;
va_list args;
while (writtenCount < 0)
{
delete [] buf;
buf = new char[newSize + 1];
va_start(args, format);
writtenCount = vsnprintf(buf, newSize, format, args);
if (writtenCount > (int)newSize)
va_end(args);
if (writtenCount >= (int)newSize) {
writtenCount = -1;
}
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
@ -114,12 +118,32 @@ void StringFromFormatV(std::string* out, const char* format, va_list args)
std::string StringFromFormat(const char* format, ...)
{
std::string temp;
int writtenCount = -1;
int newSize = (int)strlen(format) + 4;
char *buf = 0;
va_list args;
va_start(args, format);
StringFromFormatV(&temp, format, args);
va_end(args);
return(temp);
while (writtenCount < 0)
{
delete [] buf;
buf = new char[newSize + 1];
va_start(args, format);
writtenCount = vsnprintf(buf, newSize, format, args);
va_end(args);
if (writtenCount >= (int)newSize) {
writtenCount = -1;
}
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
// if (writtenCount >= (int)newSize)
// writtenCount = -1;
newSize *= 2;
}
buf[writtenCount] = '\0';
std::string temp = buf;
return temp;
}
@ -142,15 +166,6 @@ std::string ArrayToString(const u8 *data, u32 size, u32 offset, int line_len)
// ================
void ToStringFromFormat(std::string* out, const char* format, ...)
{
va_list args;
va_start(args, format);
StringFromFormatV(out, format, args);
va_end(args);
}
// Turns " hej " into "hej". Also handles tabs.
std::string StripSpaces(const std::string &str)
{

View File

@ -28,10 +28,8 @@
std::string StringFromFormat(const char* format, ...);
void ToStringFromFormat(std::string* out, const char* format, ...);
// Expensive!
// WARNING - only call once with a set of args!
void StringFromFormatV(std::string* out, const char* format, va_list args);
// Cheap!
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args);

View File

@ -40,9 +40,9 @@ void CEXIMemoryCard::FlushCallback(u64 userdata, int cyclesLate)
}
CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rFilename, int _card_index) :
m_strFilename(_rFilename)
m_strFilename(_rFilename),
card_index(_card_index)
{
this->card_index = _card_index;
cards[_card_index] = this;
et_this_card = CoreTiming::RegisterEvent(_rName.c_str(), FlushCallback);
@ -71,10 +71,12 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
pFile = fopen(m_strFilename.c_str(), "rb");
if (pFile)
{
fseek( pFile, 0L, SEEK_END );
u64 MemFileSize = ftell( pFile );
switch ((MemFileSize / (8 * 1024))-5) // Convert the filesize in bytes to the "nintendo-size"
// Measure size of the memcard file.
fseek(pFile, 0L, SEEK_END);
u64 MemFileSize = ftell(pFile);
fseek(pFile, 0L, SEEK_SET);
switch ((MemFileSize / (8 * 1024)) - 5) // Convert the filesize in bytes to the "nintendo-size"
{
case 59:
nintendo_card_id = 0x00000004;
@ -103,9 +105,6 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
break;
}
// Return to start otherwise the mem card is "corrupt"
fseek( pFile,0L,SEEK_SET);
memory_card_content = new u8[memory_card_size];
memset(memory_card_content, 0xFF, memory_card_size);
@ -124,7 +123,7 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
LOG(EXPANSIONINTERFACE, "No memory card found. Will create new.");
Flush();
Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", m_strFilename.c_str()), 4000);
Core::DisplayMessage(StringFromFormat("Wrote memory card %i contents to %s.", card_index + 1, m_strFilename.c_str()), 4000);
}
}
@ -149,8 +148,9 @@ void CEXIMemoryCard::Flush(bool exiting)
}
fwrite(memory_card_content, memory_card_size, 1, pFile);
fclose(pFile);
if (!exiting)
Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", GetFileName().c_str()), 4000);
if (!exiting) {
Core::DisplayMessage(StringFromFormat("Wrote memory card %i contents to %s.", card_index, m_strFilename.c_str()).c_str(), 4000);
}
}

View File

@ -39,6 +39,14 @@ using namespace Common;
namespace PatchEngine
{
const char *PatchTypeStrings[] =
{
"byte",
"word",
"dword",
0
};
std::vector<Patch> onFrame;
std::map<u32, int> speedHacks;

View File

@ -30,13 +30,7 @@ enum PatchType
PATCH_32BIT,
};
static const char *PatchTypeStrings[] =
{
"byte",
"word",
"dword",
0
};
extern const char *PatchTypeStrings[];
struct PatchEntry
{

View File

@ -628,7 +628,7 @@ void CGameListCtrl::OnProperties(wxCommandEvent& WXUNUSED (event))
void CGameListCtrl::MultiCompressCB(const char* text, float percent, void* arg)
{
wxString textString(wxString::Format(wxT("%s (%i/%i) - %s"), m_currentFilename.c_str(), m_currentItem+1, m_numberItem, text));
wxString textString(wxString::Format(wxT("%s (%i/%i) - %s"), m_currentFilename.c_str(), (int)m_currentItem+1, (int)m_numberItem, text));
percent = (((float)m_currentItem) + percent) / (float)m_numberItem;
wxProgressDialog* pDialog = (wxProgressDialog*)arg;