From 3bd383baf6a17e734329e1fc677c7e86283db772 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 26 Oct 2015 22:52:36 +0800 Subject: Added support for relative line numbers. Added instructions for, brk and cont. (They are still untested...) Parser code cleanup. Removed garbage output to stderr. Reorganize the repository structure. Updated BLR2 code move it into archive. Added BLR1 files. --- archive/hgehelp/hgestrings.cpp | 168 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 archive/hgehelp/hgestrings.cpp (limited to 'archive/hgehelp/hgestrings.cpp') diff --git a/archive/hgehelp/hgestrings.cpp b/archive/hgehelp/hgestrings.cpp new file mode 100644 index 0000000..6eda71c --- /dev/null +++ b/archive/hgehelp/hgestrings.cpp @@ -0,0 +1,168 @@ +/* +** Haaf's Game Engine 1.7 +** Copyright (C) 2003-2007, Relish Games +** hge.relishgames.com +** +** hgeStringTable helper class implementation +*/ + + +#include "hgestrings.h" +#include + +const char STRHEADERTAG[]="[HGESTRINGTABLE]"; +const char STRFORMATERROR[]="String table %s has incorrect format."; + + +HGE *hgeStringTable::hge=0; + + +hgeStringTable::hgeStringTable(const char *filename) +{ + int i; + void *data; + DWORD size; + char *desc, *pdesc; + NamedString *str; + char str_name[MAXSTRNAMELENGTH]; + char *str_value, *pvalue; + + hge=hgeCreate(HGE_VERSION); + strings=0; + + // load string table file + data=hge->Resource_Load(filename, &size); + if(!data) return; + + desc = new char[size+1]; + memcpy(desc,data,size); + desc[size]=0; + hge->Resource_Free(data); + + // check header + if(memcmp(desc, STRHEADERTAG, sizeof(STRHEADERTAG)-1)) + { + hge->System_Log(STRFORMATERROR, filename); + delete[] desc; + return; + } + + pdesc=desc+sizeof(STRHEADERTAG); + str_value=new char[8192]; + + for(;;) + { + // skip whitespaces + while(isspace(*pdesc)) pdesc++; + if(!*pdesc) break; + + // skip comments + if(*pdesc==';') + { + while(*pdesc && *pdesc != '\n') pdesc++; + pdesc++; + continue; + } + + // get string name -> str_name + i=0; + while(pdesc[i] && pdesc[i]!='=' && !isspace(pdesc[i]) && iSystem_Log(STRFORMATERROR, filename); break; } + pdesc++; + + // skip whitespaces to '"' + while(isspace(*pdesc)) pdesc++; + if(*pdesc!='"') { hge->System_Log(STRFORMATERROR, filename); break; } + pdesc++; + + // parse string value till the closing '"' -> str_value + // consider: \", \n, \\, LF, CR, whitespaces at line begin/end + pvalue=str_value; + + while(*pdesc && *pdesc!='"') + { + if(*pdesc=='\n' || *pdesc=='\r') + { + while(isspace(*pdesc)) pdesc++; + + pvalue--; + while(pvalue>=str_value && isspace(*pvalue)) pvalue--; + pvalue++; *pvalue=' '; pvalue++; + + continue; + } + + if(*pdesc=='\\') + { + pdesc++; + if(!*pdesc) continue; + if(*pdesc=='n') *pvalue='\n'; + else *pvalue=*pdesc; + pvalue++; + pdesc++; + continue; + } + + *pvalue=*pdesc; pvalue++; + pdesc++; + } + + *pvalue=0; + + // add the parsed string to the list + str=new NamedString; + strcpy(str->name, str_name); + str->string=new char[strlen(str_value)+1]; + strcpy(str->string, str_value); + str->next=strings; + strings=str; + + if(!*pdesc) break; + pdesc++; + } + + delete[] str_value; + delete[] desc; +} + +hgeStringTable::~hgeStringTable() +{ + NamedString *str, *strnext; + + str=strings; + while(str) + { + strnext=str->next; + delete[] str->string; + delete str; + str=strnext; + } + + hge->Release(); +} + +char *hgeStringTable::GetString(const char *name) +{ + NamedString *str=strings; + + while(str) + { + if(!strcmp(name, str->name)) return str->string; + str=str->next; + } + + return 0; +} -- cgit v1.2.3