From 6ff942e98931b2cf2fe39ea0a8f4537dfa690400 Mon Sep 17 00:00:00 2001 From: albertzeyer Date: Wed, 22 Jul 2009 23:46:59 +0000 Subject: [PATCH] fixes for menu and game strings git-svn-id: https://clonekeenplus.svn.sourceforge.net/svnroot/clonekeenplus/cgenius/trunk@113 4df4b0f3-56ce-47cb-b001-ed939b7d65a6 --- src/CGraphics.cpp | 4 +-- src/fileio.cpp | 66 +++++++++++++++++++++++------------------------ src/fileio.h | 2 +- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/CGraphics.cpp b/src/CGraphics.cpp index adb85b9b8..843024784 100644 --- a/src/CGraphics.cpp +++ b/src/CGraphics.cpp @@ -300,6 +300,7 @@ unsigned int xstart,ystart; void CGraphics::drawCharacter(int x, int y, int f) { + assert(f >= 0 && f < 256); unsigned char xa,ya; for(ya=0;ya<8;ya++) @@ -596,12 +597,11 @@ int c; void CGraphics::drawFont(const std::string& text, int xoff, int yoff, int highlight) { unsigned int i,x=xoff,y; -int c; y = yoff; for(i=0;i #include #include "StringUtils.h" +#include "Debug.h" extern CPlayer *Player; @@ -751,15 +752,14 @@ unsigned int i; } // load strings from file *fname ("strings.dat") -char loadstrings(const char *fname) +char loadstrings(const std::string& fname) { FILE *fp; char state; -char stName[80]; -char stString[1024]; + std::string stName; + std::string stString; char stAttr[80]; int i,c; -int nameIndex, stringIndex; int attrIndex=0; int waitChar, gotoState; char highlight; @@ -769,8 +769,8 @@ char highlight; #define STSTATE_READSTRING 2 #define STSTATE_READATTR 3 -g_pLogFile->ftextOut("loadstrings(): Opening string file '%s'.
", fname); - fp = fopen(fname, "rb"); +g_pLogFile->ftextOut("loadstrings(): Opening string file '%s'.
", fname.c_str()); + fp = fopen(fname.c_str(), "rb"); if (!fp) { g_pLogFile->ftextOut("loadstrings(): String file unable to open.
"); @@ -786,8 +786,6 @@ g_pLogFile->ftextOut("loadstrings(): Opening string file '%s'.
", fname); strings[i].numAttributes = 0; } - nameIndex = 0; - stringIndex = 0; numStrings = 0; highlight = 0; @@ -844,13 +842,11 @@ g_pLogFile->ftextOut("loadstrings(): Opening string file '%s'.
", fname); // read in the string name until we get to ']' if (c != ']') { - stName[nameIndex] = c; - nameIndex++; + stName += (char)c; } else { - stName[nameIndex] = 0; //null-terminate - highlight = 0; + highlight = 0; // read any attributes until the CR state = STSTATE_READATTR; attrIndex = 0; @@ -864,63 +860,59 @@ g_pLogFile->ftextOut("loadstrings(): Opening string file '%s'.
", fname); // you can put [ and ] in the string by using \( and \). // set a highlight (change font color to the +128 font) with \H // stop highlighting with \h - if (stringIndex>0 && stString[stringIndex-1]=='\\'+(highlight*128)) + if (stString.size()>0 && stString[stString.size()-1]==char('\\'+(highlight*128))) { // delimiter detected if (c=='(') { - stString[stringIndex - 1] = '[' + (highlight*128); + stString[stString.size()-1] = '[' + (highlight*128); } else if (c==')') { - stString[stringIndex - 1] = ']' + (highlight*128); + stString[stString.size()-1] = ']' + (highlight*128); } else if (c=='H') { highlight = 1; - stringIndex--; + stString.erase(stString.size()-1); } else if (c=='h') { highlight = 0; - stringIndex--; + stString.erase(stString.size()-1); } else if (c=='\\') { - stString[stringIndex - 1] = '\\' + (highlight*128); + stString[stString.size() - 1] = '\\' + (highlight*128); } } else { // normal non-delimited char - stString[stringIndex] = c; - if (highlight && c!=0 && c!=13) - { - stString[stringIndex] += 128; - } - stringIndex++; + stString += (char)c + ((highlight && c!=0 && c!=13) ? 128 : 0); } } else { - stString[stringIndex-1] = 0; //null-terminate (cutting off final CR) - +// HexDump(GetConstIterator(stName), printOnLogger, 0); +// HexDump(GetConstIterator(stString), printOnLogger, 0); +// notes.flush(); /* save the string to the strings[] structure */ // copy the string info to the newly malloc()'d memory area strings[numStrings].name = stName; strings[numStrings].stringptr = stString; - + stName = ""; + stString = ""; + numStrings++; // read the name of the next string state = STSTATE_READNAME; - nameIndex = 0; - stringIndex = 0; } break; } } while(1); - g_pLogFile->ftextOut("loadstrings(): loaded %d strings from '%s'.
", numStrings, fname); + g_pLogFile->ftextOut("loadstrings(): loaded %d strings from '%s'.
", numStrings, fname.c_str()); fclose(fp); return 0; } @@ -949,13 +941,17 @@ int NumStringsFreed; return NumStringsFreed; } -const char *MissingString = "MISSING STRING!"; +static void dumpstrings() { + notes << "Available strings: "; + for(int i=0;i #include -char loadstrings(const char *fname); +char loadstrings(const std::string& fname); unsigned int fgeti(FILE *fp); unsigned long fgetl(FILE *fp); std::string formatPathString(const std::string& path);