Skip to content

Instantly share code, notes, and snippets.

@LordAro
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LordAro/9545939 to your computer and use it in GitHub Desktop.
Save LordAro/9545939 to your computer and use it in GitHub Desktop.
diff --git a/.clang-format b/.clang-format
new file mode 100644
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,46 @@
+---
+# BasedOnStyle: Google
+AccessModifierOffset: -1
+ConstructorInitializerIndentWidth: 4
+AlignEscapedNewlinesLeft: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakTemplateDeclarations: true
+AlwaysBreakBeforeMultilineStrings: true
+BreakBeforeBinaryOperators: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BinPackParameters: true
+ColumnLimit: 140
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+DerivePointerBinding: true
+ExperimentalAutoDetectBinPacking: false
+IndentCaseLabels: true
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 60
+PenaltyBreakString: 1000
+PenaltyBreakFirstLessLess: 120
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerBindsToType: true
+SpacesBeforeTrailingComments: 1
+Cpp11BracedListStyle: true
+Standard: Auto
+IndentWidth: 8
+TabWidth: 8
+UseTab: ForIndentation
+BreakBeforeBraces: Linux
+IndentFunctionDeclarationAfterType: true
+SpacesInParentheses: false
+SpacesInAngles: false
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpaceAfterControlStatementKeyword: true
+SpaceBeforeAssignmentOperators: true
+ContinuationIndentWidth: 4
+
diff --git a/src/ExpandingArray.h b/src/ExpandingArray.h
--- a/src/ExpandingArray.h
+++ b/src/ExpandingArray.h
@@ -25,56 +25,77 @@
#define _RENUM_EXPANDING_ARRAY_H_INCLUDED_
#ifdef _MSC_VER
-#pragma warning(disable:4702)//unreachable code
-#include<vector>
-#pragma warning(default:4702)
+#pragma warning(disable : 4702) // unreachable code
+#include <vector>
+#pragma warning(default : 4702)
#else
-#include<vector>
+#include <vector>
#endif
using namespace std;
-template<typename _Ty>class ExpandingArray:public vector<_Ty>{
+template <typename _Ty>
+class ExpandingArray : public vector<_Ty>
+{
typedef ExpandingArray<_Ty> _MyT;
typedef vector<_Ty> _Mybase;
-public:
- ExpandingArray(){}
- ExpandingArray(const _Ty&_fill):m_fill(_fill){}
- const _Ty&operator[](unsigned int x)const{
- if(x>=_MyT::size())return m_fill;
+
+ public:
+ ExpandingArray()
+ {
+ }
+ ExpandingArray(const _Ty& _fill) : m_fill(_fill)
+ {
+ }
+ const _Ty& operator[](unsigned int x) const
+ {
+ if (x >= _MyT::size()) return m_fill;
return vector<_Ty>::operator[](x);
}
- _Ty&operator[](unsigned int x){
- if(x>=_MyT::size())_MyT::resize(x+1);
+ _Ty& operator[](unsigned int x)
+ {
+ if (x >= _MyT::size()) _MyT::resize(x + 1);
return _Mybase::operator[](x);
}
- void ChangeFill(const _Ty&_fill){m_fill=_fill;}
-private:
+ void ChangeFill(const _Ty& _fill)
+ {
+ m_fill = _fill;
+ }
+
+ private:
_Ty m_fill;
};
-template<typename _Ty>class Expanding0Array:public vector<_Ty>{
+template <typename _Ty>
+class Expanding0Array : public vector<_Ty>
+{
typedef Expanding0Array<_Ty> _MyT;
-public:
- _Ty operator[](unsigned int x)const{
- if(x>=_MyT::size())return 0;
+
+ public:
+ _Ty operator[](unsigned int x) const
+ {
+ if (x >= _MyT::size()) return 0;
return vector<_Ty>::operator[](x);
}
- _Ty&operator[](unsigned int x){
- if(x>=_MyT::size())_MyT::resize(x+1,0);
+ _Ty& operator[](unsigned int x)
+ {
+ if (x >= _MyT::size()) _MyT::resize(x + 1, 0);
return vector<_Ty>::operator[](x);
}
};
-template<>class Expanding0Array<bool>:public vector<bool>{
-public:
- bool operator[](unsigned int x)const{
- if(x>=size())return false;
+template <>
+class Expanding0Array<bool> : public vector<bool>
+{
+ public:
+ bool operator[](unsigned int x) const
+ {
+ if (x >= size()) return false;
return vector<bool>::operator[](x);
}
- reference operator[](unsigned int x){
- if(x>=size())resize(x+1,false);
+ reference operator[](unsigned int x)
+ {
+ if (x >= size()) resize(x + 1, false);
return vector<bool>::operator[](x);
}
};
-
-#endif//_RENUM_EXPANDING_ARRAY_H_INCLUDED_
+#endif //_RENUM_EXPANDING_ARRAY_H_INCLUDED_
diff --git a/src/IDs.cpp b/src/IDs.cpp
--- a/src/IDs.cpp
+++ b/src/IDs.cpp
@@ -19,122 +19,132 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
-#include<string>
-#include<cassert>
-#include<fstream>
-#include<errno.h>
-#include<cstdlib>
+#include <string>
+#include <cassert>
+#include <fstream>
+#include <errno.h>
+#include <cstdlib>
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"messages.h"
-#include"sanity_defines.h"
-#include"data.h"
-#include"command.h"
-#include"ExpandingArray.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "messages.h"
+#include "sanity_defines.h"
+#include "data.h"
+#include "command.h"
+#include "ExpandingArray.h"
-class IDs:public Guintp{
-public:
+class IDs : public Guintp
+{
+ public:
SINGLETON(IDs);
};
-IDs::IDs(){
- FILE*pFile=myfopen(IDs);
- _p=new uint[MaxFeature()+1];
- for(uint i=0;i<=MaxFeature();i++)
- _p[i]=GetCheckWord(IDs);
+IDs::IDs()
+{
+ FILE* pFile = myfopen(IDs);
+ _p = new uint[MaxFeature() + 1];
+ for (uint i = 0; i <= MaxFeature(); i++) _p[i] = GetCheckWord(IDs);
fclose(pFile);
}
-class TextIDs{
-public:
- uint idClasses[0x20],numspecials;
- bool CheckID(uint,uint);
+class TextIDs
+{
+ public:
+ uint idClasses[0x20], numspecials;
+ bool CheckID(uint, uint);
void Define(uint);
bool IsDefined(uint);
static void Clear();
AUTO_ARRAY(uchar);
SINGLETON(TextIDs);
-private:
+
+ private:
static Expanding0Array<bool> _m;
};
Expanding0Array<bool> TextIDs::_m;
-TextIDs::TextIDs(){
- FILE*pFile=myfopen(TextIDs);
- uint i=0;
- for(;i<0x20;i++)
- idClasses[i]=GetCheckWord(TextIDs);
- _p=new uchar[numspecials=GetCheckByte(TextIDs)];
- myfread(_p,numspecials,TextIDs);
+TextIDs::TextIDs()
+{
+ FILE* pFile = myfopen(TextIDs);
+ uint i = 0;
+ for (; i < 0x20; i++) idClasses[i] = GetCheckWord(TextIDs);
+ _p = new uchar[numspecials = GetCheckByte(TextIDs)];
+ myfread(_p, numspecials, TextIDs);
fclose(pFile);
}
-bool TextIDs::CheckID(uint feature,uint ID){
- if((ID&0xF000)==0xD000){
- if(feature==0x48)return ID<0xD400||(ID>0xDBFF&&ID<0xDD00);
- return ID>0xD3FF&&ID<0xD800;
+bool TextIDs::CheckID(uint feature, uint ID)
+{
+ if ((ID & 0xF000) == 0xD000) {
+ if (feature == 0x48) return ID < 0xD400 || (ID > 0xDBFF && ID < 0xDD00);
+ return ID > 0xD3FF && ID < 0xD800;
}
- if(feature==0x49&&ID==0xC7FF)return true;
- if(idClasses[ID>>11]==0xFFFF){
- for(uint i=0;i<numspecials;i++)if(ID>>8==_p[i])return true;
+ if (feature == 0x49 && ID == 0xC7FF) return true;
+ if (idClasses[ID >> 11] == 0xFFFF) {
+ for (uint i = 0; i < numspecials; i++)
+ if (ID >> 8 == _p[i]) return true;
return false;
}
- return(ID&0x7FF)<idClasses[ID>>11];
+ return (ID & 0x7FF) < idClasses[ID >> 11];
}
-void TextIDs::Define(uint ID){
- if(idClasses[ID>>11]==0xFFFF){
- ID-=0xC000;
- _m[ID]=true;
+void TextIDs::Define(uint ID)
+{
+ if (idClasses[ID >> 11] == 0xFFFF) {
+ ID -= 0xC000;
+ _m[ID] = true;
}
}
-bool TextIDs::IsDefined(uint ID){
- if(idClasses[ID>>11]==0xFFFF)
- return const_cast<const Expanding0Array<bool>& >(_m)[ID-0xC000];
- return (ID&0x7FF)<idClasses[ID>>11];
+bool TextIDs::IsDefined(uint ID)
+{
+ if (idClasses[ID >> 11] == 0xFFFF) return const_cast<const Expanding0Array<bool>&>(_m)[ID - 0xC000];
+ return (ID & 0x7FF) < idClasses[ID >> 11];
}
-void TextIDs::Clear() {
+void TextIDs::Clear()
+{
_m.clear();
}
-void ClearTextIDs() {
+void ClearTextIDs()
+{
TextIDs::Clear();
}
-bool CheckTextID(uint feature,uint ID,uint offset){
- VERIFY(feature==0x48||feature==0x49,feature);
- VERIFY(ID<0x10000,ID);
- if(TextIDs::Instance().CheckID(feature,ID)){
- if (feature==0x48) TextIDs::Instance().Define(ID);
+bool CheckTextID(uint feature, uint ID, uint offset)
+{
+ VERIFY(feature == 0x48 || feature == 0x49, feature);
+ VERIFY(ID < 0x10000, ID);
+ if (TextIDs::Instance().CheckID(feature, ID)) {
+ if (feature == 0x48) TextIDs::Instance().Define(ID);
return true;
}
- IssueMessage(ERROR,INVALID_TEXTID,offset,ID);
+ IssueMessage(ERROR, INVALID_TEXTID, offset, ID);
return false;
}
-bool IsTextDefined(uint ID) {
+bool IsTextDefined(uint ID)
+{
return TextIDs::Instance().IsDefined(ID);
}
-bool CheckID(uint feature,uint ID){
- VERIFY(feature<=MaxFeature(),feature);
- VERIFY(ID<0x10000,ID);
+bool CheckID(uint feature, uint ID)
+{
+ VERIFY(feature <= MaxFeature(), feature);
+ VERIFY(ID < 0x10000, ID);
/* Since OpenTTD 0.7 higher vehicle IDs are allowed; GRF version 8
* is the first new GRF version after that, so use that as minimum
* threshold for allowing the higher IDs. Even though this is not
* actually tied to GRF version 8.*/
- uint maxID=_grfver>=8&&feature<=0x03?0xFFFF:IDs::Instance()[feature];
- if(ID>maxID){
- IssueMessage(ERROR,INVALID_ID,ID,feature==0x0C?0x49:0,maxID);
+ uint maxID = _grfver >= 8 && feature <= 0x03 ? 0xFFFF : IDs::Instance()[feature];
+ if (ID > maxID) {
+ IssueMessage(ERROR, INVALID_ID, ID, feature == 0x0C ? 0x49 : 0, maxID);
return false;
}
- if(feature==0x0C&&ID<0x49){
- IssueMessage(ERROR,INVALID_ID,ID,0x49,0xFFFF);
+ if (feature == 0x0C && ID < 0x49) {
+ IssueMessage(ERROR, INVALID_ID, ID, 0x49, 0xFFFF);
return false;
}
return true;
diff --git a/src/act0.cpp b/src/act0.cpp
--- a/src/act0.cpp
+++ b/src/act0.cpp
@@ -19,30 +19,30 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
+#include <string>
#ifdef _MSC_VER
-#pragma warning(disable:4702)//unreachable code
-#include<vector>
-#pragma warning(default:4702)
+#pragma warning(disable : 4702) // unreachable code
+#include <vector>
+#pragma warning(default : 4702)
#else
-#include<vector>
+#include <vector>
#endif
-#include<cassert>
-#include<errno.h>
-#include<cstdlib>
+#include <cassert>
+#include <errno.h>
+#include <cstdlib>
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"messages.h"
-#include"ExpandingArray.h"
-#include"sanity_defines.h"
-#include"data.h"
-#include"pseudo.h"
-#include"command.h"
-#include"rangedint.h"
-#include"act123.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "messages.h"
+#include "ExpandingArray.h"
+#include "sanity_defines.h"
+#include "data.h"
+#include "pseudo.h"
+#include "command.h"
+#include "rangedint.h"
+#include "act123.h"
/*Data Format:
bits indicate width:
@@ -61,7 +61,7 @@
- Check BE words against defined TTD and DCxx IDs
- Check BE doubles against remaining size of property (e.g. indu prop 0A)
- Check default words against defined IDs for feature that relates to this one
- (i.e. Check that tiles used in indu prop 0A are defined.)
+ (i.e. Check that tiles used in indu prop 0A are defined.)
Basic formatting:
0:default 1:quote 2:decimal 3:B-E hex
@@ -99,504 +99,542 @@
typedef basic_string<uchar> ustring;
typedef vector<int> int_str;
-class PropData:public auto_array<PropData>{
-public:
- PropData(){}
- void Init(FILE*,bool);
- uchar GetData(uint)const;
- uint GetLength()const{return(uint)length.length();}
- const PropData*GetVarLength(int)const;
- uint GetValue(uint&,const int_str&)const;
- uint maxfirst(int prop){return idRange[prop]&0xFF;}
- uint maxlast(int prop){return (idRange[prop]>>8)&0xFF;}
-private:
+class PropData : public auto_array<PropData>
+{
+ public:
+ PropData()
+ {
+ }
+ void Init(FILE*, bool);
+ uchar GetData(uint) const;
+ uint GetLength() const
+ {
+ return (uint)length.length();
+ }
+ const PropData* GetVarLength(int) const;
+ uint GetValue(uint&, const int_str&) const;
+ uint maxfirst(int prop)
+ {
+ return idRange[prop] & 0xFF;
+ }
+ uint maxlast(int prop)
+ {
+ return (idRange[prop] >> 8) & 0xFF;
+ }
+
+ private:
ustring length;
vector<uint> idRange;
- void readString(FILE*,bool);
+ void readString(FILE*, bool);
int CountFE();
void operator=(const PropData&);
PropData(const PropData&);
};
-class Check0:public auto_array<PropData>{
-public:
+class Check0 : public auto_array<PropData>
+{
+ public:
void Check(PseudoSprite&);
- static Check0&Instance(){static Check0 obj;return obj;}
- uint GetFeat8(){return _p[8].GetLength();}
-private:
+ static Check0& Instance()
+ {
+ static Check0 obj;
+ return obj;
+ }
+ uint GetFeat8()
+ {
+ return _p[8].GetLength();
+ }
+
+ private:
Check0();
- bool CheckVar(uint&,PseudoSprite&,const PropData&,bool addblank,bool,int_str =int_str())const;
+ bool CheckVar(uint&, PseudoSprite&, const PropData&, bool addblank, bool, int_str = int_str()) const;
void operator=(const Check0&);
Check0(const Check0&);
};
-void Check0(PseudoSprite&str){
+void Check0(PseudoSprite& str)
+{
Check0::Instance().Check(str);
}
-uchar PropData::GetData(unsigned int prop)const{
- return prop<length.length()?length[prop]:(uchar)0xFF;
+uchar PropData::GetData(unsigned int prop) const
+{
+ return prop < length.length() ? length[prop] : (uchar)0xFF;
}
-const PropData*PropData::GetVarLength(int prop)const{
- PropData*ret=_p;
- for(int i=0;i<prop;i++)
- if(length[i]==0xFE)ret++;
+const PropData* PropData::GetVarLength(int prop) const
+{
+ PropData* ret = _p;
+ for (int i = 0; i < prop; i++)
+ if (length[i] == 0xFE) ret++;
return ret;
}
-uint PropData::GetValue(uint&len_off,const int_str&decoded)const{
- uint value=GetData(len_off);
- if(value=='x'){
- value=GetValue(++len_off,decoded);
- return value*GetValue(++len_off,decoded);
+uint PropData::GetValue(uint& len_off, const int_str& decoded) const
+{
+ uint value = GetData(len_off);
+ if (value == 'x') {
+ value = GetValue(++len_off, decoded);
+ return value * GetValue(++len_off, decoded);
}
- if(value=='&'){
- value=GetValue(++len_off,decoded);
- return value&GetValue(++len_off,decoded);
+ if (value == '&') {
+ value = GetValue(++len_off, decoded);
+ return value & GetValue(++len_off, decoded);
}
- if(value=='l')
- return GetData(++len_off);
- if(value=='m'){
+ if (value == 'l') return GetData(++len_off);
+ if (value == 'm') {
uint len = GetData(++len_off);
- value=0;
- for(uint k=0;k<len;k++)
- value|=GetData(++len_off)<<(8*k);
+ value = 0;
+ for (uint k = 0; k < len; k++) value |= GetData(++len_off) << (8 * k);
return value;
}
- if(value&0x80)
- return decoded[value&0x7F];
+ if (value & 0x80) return decoded[value & 0x7F];
return value;
}
-void PropData::Init(FILE*pFile, bool withIDs){
+void PropData::Init(FILE* pFile, bool withIDs)
+{
readString(pFile, withIDs);
- int j=CountFE();
- if(j){
- _p=new PropData[j];
- for(int k=0;k<j;k++)
- _p[k].Init(pFile, false);
+ int j = CountFE();
+ if (j) {
+ _p = new PropData[j];
+ for (int k = 0; k < j; k++) _p[k].Init(pFile, false);
}
}
-void PropData::readString(FILE*pFile, bool withIDs){
+void PropData::readString(FILE* pFile, bool withIDs)
+{
int ch;
- bool escape=false;
- do{
- if((ch=fgetc(pFile))==EOF)
- throw 0;
- if(!escape){
- if(!ch)break;
- if(ch=='\\'){
- escape=true;
+ bool escape = false;
+ do {
+ if ((ch = fgetc(pFile)) == EOF) throw 0;
+ if (!escape) {
+ if (!ch) break;
+ if (ch == '\\') {
+ escape = true;
continue;
}
}
- escape=false;
- if(withIDs){
- if(ch!=0xFF)
+ escape = false;
+ if (withIDs) {
+ if (ch != 0xFF)
idRange.push_back(GetCheckWord(0));
else
idRange.push_back(0);
}
- length.append(1,(char)ch);
- }while(true);
+ length.append(1, (char)ch);
+ } while (true);
}
-int PropData::CountFE(){
- int ret=0;
- size_t start=0;
- while((start=length.find_first_of((unsigned char)0xFE,start)+1)!=0)ret++;
+int PropData::CountFE()
+{
+ int ret = 0;
+ size_t start = 0;
+ while ((start = length.find_first_of((unsigned char)0xFE, start) + 1) != 0) ret++;
return ret;
}
-class Prop08Tracking{
+class Prop08Tracking
+{
STATIC(Prop08Tracking)
-public:
- static void Set(uint feat,uint id){
- _m[feat][id]=true;
+ public:
+ static void Set(uint feat, uint id)
+ {
+ _m[feat][id] = true;
}
- static void Reset(){
+ static void Reset()
+ {
_m.clear();
}
- static bool Check(uint feat,uint id){
+ static bool Check(uint feat, uint id)
+ {
return ((const ExpandingArray<Expanding0Array<bool> >)_m)[feat][id];
}
-private:
+
+ private:
static ExpandingArray<Expanding0Array<bool> > _m;
};
ExpandingArray<Expanding0Array<bool> > Prop08Tracking::_m;
-bool IsProp08Set(uint feature,uint id){
- return Prop08Tracking::Check(feature,id);
+bool IsProp08Set(uint feature, uint id)
+{
+ return Prop08Tracking::Check(feature, id);
}
-uint CargoTransTable(int newlimit=0){
- static int limit=0;
+uint CargoTransTable(int newlimit = 0)
+{
+ static int limit = 0;
static uint prevtable;
- if(newlimit<0)
- limit=0;
- else if(newlimit){
- if(limit)
- IssueMessage(WARNING1,DUPLICATE_TRANS_TABLE,prevtable);
+ if (newlimit < 0)
+ limit = 0;
+ else if (newlimit) {
+ if (limit) IssueMessage(WARNING1, DUPLICATE_TRANS_TABLE, prevtable);
limit = newlimit;
- prevtable=_spritenum;
+ prevtable = _spritenum;
}
- if(limit) return (uint)limit;
+ if (limit) return (uint)limit;
return 0x1B;
}
-void Init0(){
+void Init0()
+{
Prop08Tracking::Reset();
CargoTransTable(-1);
}
-#define GetWidth(x) ((x)&7)
-#define IsSpecial(x) ((x)&8)
-#define GetFormat(x) ((x>>4)&3)
-#define GetLinebreak(x) ((x>>6)&3)
+#define GetWidth(x) ((x) & 7)
+#define IsSpecial(x) ((x) & 8)
+#define GetFormat(x) ((x >> 4) & 3)
+#define GetLinebreak(x) ((x >> 6) & 3)
bool IsTextDefined(uint);
static vector<uint> lengthlist;
-static void FormatSprite(PseudoSprite&str, uint&ofs, const uint format, const uint IDs = 1) {
+static void FormatSprite(PseudoSprite& str, uint& ofs, const uint format, const uint IDs = 1)
+{
uint feature = str.ExtractByte(1);
- for(uint j=0;j<IDs;j++){
- switch(GetFormat(format)){
- case 0: // default
- if (GetWidth(format)==2 && IsSpecial(format)) { // Check word against defined IDs.
- uint k=UINT_MAX;
- for (uint i=0;i<=MaxFeature();i++)
- if (Check2v::GetEffFeature(i,0x82)==feature && (k==UINT_MAX||k==feature)) k=i;
+ for (uint j = 0; j < IDs; j++) {
+ switch (GetFormat(format)) {
+ case 0: // default
+ if (GetWidth(format) == 2 && IsSpecial(format)) { // Check word against defined IDs.
+ uint k = UINT_MAX;
+ for (uint i = 0; i <= MaxFeature(); i++)
+ if (Check2v::GetEffFeature(i, 0x82) == feature && (k == UINT_MAX || k == feature)) k = i;
- static Expanding0Array<bool> warned;
- if (k>MaxFeature()) {
- if (!warned[feature]) IssueMessage(WARNING1,COULD_NOT_VERIFY);
- warned[feature]=true;
- break;
+ static Expanding0Array<bool> warned;
+ if (k > MaxFeature()) {
+ if (!warned[feature]) IssueMessage(WARNING1, COULD_NOT_VERIFY);
+ warned[feature] = true;
+ break;
+ }
+
+ if (!IsProp08Set(k, str.ExtractWord(ofs)))
+ IssueMessage(ERROR, ACT3_PRECEDES_PROP08, ofs, str.ExtractWord(ofs));
}
-
- if (!IsProp08Set(k,str.ExtractWord(ofs)))
- IssueMessage(ERROR,ACT3_PRECEDES_PROP08,ofs,str.ExtractWord(ofs));
- }
- break;
- case 1:
- if(IsSpecial(format)) {
- str.SetText(ofs);
- } else {
- str.SetText(ofs,GetWidth(format));
- }
- break;
- case 2: // Decimal (or date)
- if (IsSpecial(format))
- str.SetDate(ofs,GetWidth(format));
- else
- str.SetDec(ofs,GetWidth(format));
- break;
- case 3: // BE hex
- if (IsSpecial(format)) {
- if (GetWidth(format)==2) { // Check word against defined TextIDs.
- if(!IsTextDefined(str.ExtractWord(ofs)))
- IssueMessage(ERROR,UNDEFINED_TEXTID,ofs,str.ExtractWord(ofs));
- } else if (GetWidth(format)==4) // Check dword against prop length
- lengthlist.push_back(ofs);
- }
- str.SetBE(ofs,GetWidth(format));
- break;
+ break;
+ case 1:
+ if (IsSpecial(format)) {
+ str.SetText(ofs);
+ } else {
+ str.SetText(ofs, GetWidth(format));
+ }
+ break;
+ case 2: // Decimal (or date)
+ if (IsSpecial(format))
+ str.SetDate(ofs, GetWidth(format));
+ else
+ str.SetDec(ofs, GetWidth(format));
+ break;
+ case 3: // BE hex
+ if (IsSpecial(format)) {
+ if (GetWidth(format) == 2) { // Check word against defined TextIDs.
+ if (!IsTextDefined(str.ExtractWord(ofs)))
+ IssueMessage(ERROR, UNDEFINED_TEXTID, ofs, str.ExtractWord(ofs));
+ } else if (GetWidth(format) == 4) // Check dword against prop length
+ lengthlist.push_back(ofs);
+ }
+ str.SetBE(ofs, GetWidth(format));
+ break;
}
- if(GetWidth(format)==3)
- ofs+=str.ExtendedLen(ofs);
+ if (GetWidth(format) == 3)
+ ofs += str.ExtendedLen(ofs);
else
- ofs+=GetWidth(format);
+ ofs += GetWidth(format);
}
}
-void Check0::Check(PseudoSprite&str){
- assert(str.ExtractByte(0)==0);
- int feature=str.ExtractByte(1);
- //IssueMessage(-2,V_ACTION_FOR,1,0,ACTION_STRINGS,0,FEATURE_STRINGS,feature);
- if(!IsValidFeature(ACT0,feature)){
- IssueMessage(FATAL,INVALID_FEATURE);
+void Check0::Check(PseudoSprite& str)
+{
+ assert(str.ExtractByte(0) == 0);
+ int feature = str.ExtractByte(1);
+ // IssueMessage(-2,V_ACTION_FOR,1,0,ACTION_STRINGS,0,FEATURE_STRINGS,feature);
+ if (!IsValidFeature(ACT0, feature)) {
+ IssueMessage(FATAL, INVALID_FEATURE);
return;
}
- int propsRemain=str.ExtractByte(2),prop=-1,len;
- //IssueMessage(-1,V_PROPS,2,
- unsigned int i=4+str.ExtendedLen(4),firstID=str.ExtractExtended(4),IDs=str.ExtractByte(3),j;
- //IssueMessage(-1,V_IDS,3,firstID,firstID+IDs-1,IDs);
- uint maxID=firstID+IDs-1;
- if(propsRemain==0)
- IssueMessage(WARNING1,NO_PROPS);
- if(IDs==0&&(propsRemain!=1||feature||str.ExtractByte(i)!=0x1A)){
- IssueMessage(WARNING1,NO_IDS);
+ int propsRemain = str.ExtractByte(2), prop = -1, len;
+ // IssueMessage(-1,V_PROPS,2,
+ unsigned int i = 4 + str.ExtendedLen(4), firstID = str.ExtractExtended(4), IDs = str.ExtractByte(3), j;
+ // IssueMessage(-1,V_IDS,3,firstID,firstID+IDs-1,IDs);
+ uint maxID = firstID + IDs - 1;
+ if (propsRemain == 0) IssueMessage(WARNING1, NO_PROPS);
+ if (IDs == 0 && (propsRemain != 1 || feature || str.ExtractByte(i) != 0x1A)) {
+ IssueMessage(WARNING1, NO_IDS);
return;
}
- feature!=8&&IDs&&CheckID(feature,firstID)&&CheckID(feature,maxID);
- Expanding0Array<uint>propLoc, idWidth;
- try{
- while(propsRemain||_autocorrect){
- try{
- prop=str.ExtractByte(i);
- }catch(unsigned int){
- if(propsRemain>0)IssueMessage(ERROR,INSUFFICIENT_PROPS,propsRemain);
- if(_autocorrect>=2||(_autocorrect&&propsRemain<3&&str.ExtractByte(2)-propsRemain>1)){
- if(i>str.Length()){
- i=propLoc[prop];
+ feature != 8 && IDs&& CheckID(feature, firstID) && CheckID(feature, maxID);
+ Expanding0Array<uint> propLoc, idWidth;
+ try
+ {
+ while (propsRemain || _autocorrect) {
+ try
+ {
+ prop = str.ExtractByte(i);
+ }
+ catch (unsigned int)
+ {
+ if (propsRemain > 0) IssueMessage(ERROR, INSUFFICIENT_PROPS, propsRemain);
+ if (_autocorrect >= 2 || (_autocorrect && propsRemain < 3 && str.ExtractByte(2) - propsRemain > 1)) {
+ if (i > str.Length()) {
+ i = propLoc[prop];
propsRemain++;
}
- if(propsRemain){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,2,NUMINFO,str.ExtractByte(2),str.ExtractByte(2)-propsRemain);
- str.SetByteAt(2,str.ExtractByte(2)-propsRemain);
+ if (propsRemain) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 2, NUMINFO, str.ExtractByte(2),
+ str.ExtractByte(2) - propsRemain);
+ str.SetByteAt(2, str.ExtractByte(2) - propsRemain);
}
break;
}
return;
}
- if(feature==8 && prop==9)
- CargoTransTable(IDs-1);
- len=_p[feature].GetData(prop);
- if(prop==8)// Mark prop 08 as set, if necessary.
- for(uint i=firstID;i<=maxID;i++)
- Prop08Tracking::Set(feature,i);
+ if (feature == 8 && prop == 9) CargoTransTable(IDs - 1);
+ len = _p[feature].GetData(prop);
+ if (prop == 8) // Mark prop 08 as set, if necessary.
+ for (uint i = firstID; i <= maxID; i++) Prop08Tracking::Set(feature, i);
- if(len==0xFF){
- IssueMessage(FATAL,INVALID_PROP,i,prop);
- if(_autocorrect){
- if(propsRemain){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,2,NUMINFO,str.ExtractByte(2),str.ExtractByte(2)-propsRemain);
- str.SetByteAt(2,str.ExtractByte(2)-propsRemain);
+ if (len == 0xFF) {
+ IssueMessage(FATAL, INVALID_PROP, i, prop);
+ if (_autocorrect) {
+ if (propsRemain) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 2, NUMINFO, str.ExtractByte(2),
+ str.ExtractByte(2) - propsRemain);
+ str.SetByteAt(2, str.ExtractByte(2) - propsRemain);
}
break;
}
return;
}
- if(feature==8){
- if(firstID>_p[feature].maxfirst(prop))
- IssueMessage(ERROR,INVALID_ID,firstID,0,_p[feature].maxfirst(prop));
- if(IDs&&maxID>_p[feature].maxlast(prop))
- IssueMessage(ERROR,INVALID_ID,maxID,0,_p[feature].maxlast(prop));
+ if (feature == 8) {
+ if (firstID > _p[feature].maxfirst(prop))
+ IssueMessage(ERROR, INVALID_ID, firstID, 0, _p[feature].maxfirst(prop));
+ if (IDs && maxID > _p[feature].maxlast(prop))
+ IssueMessage(ERROR, INVALID_ID, maxID, 0, _p[feature].maxlast(prop));
}
- if(propLoc[prop]&&!(len&0x80))
- IssueMessage(WARNING2,REPEATED_PROP,i,prop,propLoc[prop]);
- propLoc[prop]=i++;
- if(len==0xFE){
- const PropData*data=_p[feature].GetVarLength(prop);
- for(j=0;j<IDs;j++){
- if(!CheckVar(i,str,*data,j+1<IDs,true))return;
+ if (propLoc[prop] && !(len & 0x80)) IssueMessage(WARNING2, REPEATED_PROP, i, prop, propLoc[prop]);
+ propLoc[prop] = i++;
+ if (len == 0xFE) {
+ const PropData* data = _p[feature].GetVarLength(prop);
+ for (j = 0; j < IDs; j++) {
+ if (!CheckVar(i, str, *data, j + 1 < IDs, true)) return;
while (lengthlist.size()) {
- const uint loc = lengthlist.back(),
- val = str.ExtractDword(loc),
- dist = i-(loc+4);
+ const uint loc = lengthlist.back(), val = str.ExtractDword(loc), dist = i - (loc + 4);
if (val != dist) {
- IssueMessage(ERROR,LENGTH_MISMATCH,loc,val,dist);
+ IssueMessage(ERROR, LENGTH_MISMATCH, loc, val, dist);
if (_autocorrect) {
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,loc,PROPLENGTH,val,dist);
- str.SetDwordAt(loc,dist);
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, loc, PROPLENGTH, val, dist);
+ str.SetDwordAt(loc, dist);
}
}
lengthlist.pop_back();
}
}
- }else
- FormatSprite(str,i,len,IDs);
+ } else
+ FormatSprite(str, i, len, IDs);
propsRemain--;
}
- if(i>str.Length())
- IssueMessage(ERROR,INSUFFICIENT_DATA2,i-str.Length(),prop);
- else{
- if(i<str.Length()){
- len=_p[feature].GetData(str.ExtractByte(4+str.ExtendedLen(4)));
- if(_autocorrect&&str.ExtractByte(2)==1&&GetWidth(len)<5){
+ if (i > str.Length())
+ IssueMessage(ERROR, INSUFFICIENT_DATA2, i - str.Length(), prop);
+ else {
+ if (i < str.Length()) {
+ len = _p[feature].GetData(str.ExtractByte(4 + str.ExtendedLen(4)));
+ if (_autocorrect && str.ExtractByte(2) == 1 && GetWidth(len) < 5) {
// If setting one property, assume setting same prop for more IDs
- while(i+(GetWidth(len)==3?str.ExtendedLen(i):GetWidth(len))<=str.Length()&&IDs<0xFF){
- FormatSprite(str,i,len);
+ while (i + (GetWidth(len) == 3 ? str.ExtendedLen(i) : GetWidth(len)) <= str.Length() &&
+ IDs < 0xFF) {
+ FormatSprite(str, i, len);
IDs++;
}
- if(IDs!=str.ExtractByte(3)){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,3,NUMIDS,str.ExtractByte(3),IDs);
- str.SetByteAt(3,IDs);
+ if (IDs != str.ExtractByte(3)) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 3, NUMIDS, str.ExtractByte(3), IDs);
+ str.SetByteAt(3, IDs);
}
}
- if(i<str.Length())
- IssueMessage(WARNING2,EXTRA_DATA,str.Length(),i);
+ if (i < str.Length()) IssueMessage(WARNING2, EXTRA_DATA, str.Length(), i);
}
- if(!GetState(LINEBREAKS))return;
- bool linebreaks=(IDs>1||GetState(LINEBREAKS)==3)&&str.ExtractByte(2)>1;
+ if (!GetState(LINEBREAKS)) return;
+ bool linebreaks = (IDs > 1 || GetState(LINEBREAKS) == 3) && str.ExtractByte(2) > 1;
uint data;
- for(i=0;i<propLoc.size();i++)
- linebreaks |= propLoc[i] && _p[feature].GetData(i)==0xFE;
- if(!linebreaks)return;
- for(i=0;i<propLoc.size();i++){
- if(!propLoc[i])continue;
- str.SetEol(propLoc[i]-1,1);
- if((data=_p[feature].GetData(i))==0xFE)continue;
- for(uint j=IDs;j;j--)
- str.ColumnAfter(propLoc[i]+GetWidth(data)*j);
+ for (i = 0; i < propLoc.size(); i++) linebreaks |= propLoc[i] && _p[feature].GetData(i) == 0xFE;
+ if (!linebreaks) return;
+ for (i = 0; i < propLoc.size(); i++) {
+ if (!propLoc[i]) continue;
+ str.SetEol(propLoc[i] - 1, 1);
+ if ((data = _p[feature].GetData(i)) == 0xFE) continue;
+ for (uint j = IDs; j; j--) str.ColumnAfter(propLoc[i] + GetWidth(data) * j);
}
}
- }catch(uint off){
- IssueMessage(FATAL,INSUFFICIENT_DATA,prop,EXPECTED_BYTES(off),EXPECTED_LOC(off));
+ }
+ catch (uint off)
+ {
+ IssueMessage(FATAL, INSUFFICIENT_DATA, prop, EXPECTED_BYTES(off), EXPECTED_LOC(off));
}
}
-bool Check0::CheckVar(uint&str_loc,PseudoSprite&str,const PropData&vdata,bool canaddblank,bool appendeol,int_str decoded)const{
- bool findPipe=false;
+bool Check0::CheckVar(uint& str_loc, PseudoSprite& str, const PropData& vdata, bool canaddblank, bool appendeol, int_str decoded) const
+{
+ bool findPipe = false;
uchar ch;
int_str pass;
- uint orig_loc=str_loc,vdatalen=vdata.GetLength();
- bool addblank=false;
- for(uint i=0;i<vdatalen;i++){
- ch=vdata.GetData(i);
- if(findPipe&&ch!='|')continue;
- else if(findPipe){
- findPipe=false;
+ uint orig_loc = str_loc, vdatalen = vdata.GetLength();
+ bool addblank = false;
+ for (uint i = 0; i < vdatalen; i++) {
+ ch = vdata.GetData(i);
+ if (findPipe && ch != '|')
+ continue;
+ else if (findPipe) {
+ findPipe = false;
continue;
}
- switch(ch){
- case'|':return true;
- case'l':
- case'm':{
- uint len=(ch=='m'?vdata.GetData(++i):1);
- for(uint k=0;k<len;k++){
- /* Check for a specific raw data value.
- * As this is used to check for certain formats, we do not want stuff like warning 209,
- * so use LinkSafeExtractByte().
- * Though the correct way of doing this would be to change the behaviour of '|' to dismiss
- * all warnings and errors of the branch that was declined, this still works reasonable well. */
- if(vdata.GetData(++i)!=str.LinkSafeExtractByte(str_loc++)){
- str_loc=orig_loc;
- findPipe=true;
+ switch (ch) {
+ case '|':
+ return true;
+ case 'l':
+ case 'm': {
+ uint len = (ch == 'm' ? vdata.GetData(++i) : 1);
+ for (uint k = 0; k < len; k++) {
+ /* Check for a specific raw data value.
+ * As this is used to check for certain formats, we do not want stuff like warning 209,
+ * so use LinkSafeExtractByte().
+ * Though the correct way of doing this would be to change the behaviour of '|' to dismiss
+ * all warnings and errors of the branch that was declined, this still works reasonable well. */
+ if (vdata.GetData(++i) != str.LinkSafeExtractByte(str_loc++)) {
+ str_loc = orig_loc;
+ findPipe = true;
+ break;
+ }
+ }
+ break;
+ }
+ case 'e':
+ case 'n': {
+ uint lhs = vdata.GetValue(++i, decoded);
+ uint rhs = vdata.GetValue(++i, decoded);
+ const PropData* vdata2 = vdata.GetVarLength(i);
+ uchar data = vdata.GetData(++i);
+ if ((lhs == rhs) == (ch == 'n')) break;
+ if (data == 'a') {
+ IssueMessage(ERROR, UNKNOWN_ACT0_DATA, str_loc);
+ return false;
+ } else if (data == 's') {
+ str_loc = orig_loc;
+ findPipe = true;
+ } else if (data == 0xFE) {
+ if (!CheckVar(str_loc, str, *vdata2, false, false, pass)) return false;
+ } else if (GetWidth(data) < 5) {
+ FormatSprite(str, str_loc, data, 1);
+ } else {
+ IssueMessage(0, INVALID_DATAFILE, "0.dat", DAT2, ch, data);
+ exit(EDATA);
+ }
+ break;
+ }
+ case 'r': {
+ const PropData* vdata2 = vdata.GetVarLength(i);
+ uchar repeat_data = vdata.GetData(++i);
+ uint times = vdata.GetValue(++i, decoded);
+ if (repeat_data == 0xFE) {
+ for (uint j = 0; j < times; j++)
+ if (!CheckVar(str_loc, str, *vdata2, false, false, pass)) return false;
+ } else if (GetWidth(repeat_data) < 5) {
+ FormatSprite(str, str_loc, repeat_data, times);
+ } else {
+ IssueMessage(0, INVALID_DATAFILE, "0.dat", DAT2, 'r', repeat_data);
+ exit(EDATA);
+ }
+ break;
+ }
+ case '*': {
+ const PropData* vdata2 = vdata.GetVarLength(i);
+ uchar repeat_data = vdata.GetData(++i);
+ int term_len = vdata.GetData(++i);
+ uint term;
+ uint (PseudoSprite::*ExtractTerm)(uint) const;
+ switch (term_len) {
+ case 1:
+ term = vdata.GetData(++i);
+ ExtractTerm = &PseudoSprite::ExtractByte;
+ break;
+ case 2:
+ term = vdata.GetData(++i);
+ term |= vdata.GetData(++i) << 8;
+ ExtractTerm = &PseudoSprite::ExtractWord;
+ break;
+ case 4:
+ term = vdata.GetData(++i);
+ term |= vdata.GetData(++i) << 8;
+ term |= vdata.GetData(++i) << 16;
+ term |= vdata.GetData(++i) << 24;
+ ExtractTerm = &PseudoSprite::ExtractDword;
+ break;
+ default:
+ IssueMessage(0, INVALID_DATAFILE, "0.dat", DAT3, '*', repeat_data, term_len);
+ exit(EDATA);
+ }
+ try
+ {
+ if (repeat_data == 0xFE) {
+ while ((str.*ExtractTerm)(str_loc) != term)
+ if (!CheckVar(str_loc, str, *vdata2, false, false, pass)) return false;
+ } else if (GetWidth(repeat_data) < 5) {
+ while ((str.*ExtractTerm)(str_loc) != term) FormatSprite(str, str_loc, repeat_data);
+ } else {
+ IssueMessage(0, INVALID_DATAFILE, "0.dat", DAT2, '*', repeat_data);
+ exit(EDATA);
+ }
+ str_loc += term_len;
break;
}
+ catch (uint)
+ {
+ IssueMessage(ERROR, MISSING_TERMINATOR);
+ return false;
+ }
+ break;
}
- break;
- }
- case'e':
- case'n':{
- uint lhs=vdata.GetValue(++i,decoded);
- uint rhs=vdata.GetValue(++i,decoded);
- const PropData*vdata2=vdata.GetVarLength(i);
- uchar data=vdata.GetData(++i);
- if ((lhs == rhs) == (ch == 'n')) break;
- if(data=='a'){
- IssueMessage(ERROR,UNKNOWN_ACT0_DATA,str_loc);
- return false;
- }else if(data=='s'){
- str_loc=orig_loc;
- findPipe=true;
- }else if(data==0xFE){
- if(!CheckVar(str_loc,str,*vdata2,false,false,pass))return false;
- }else if(GetWidth(data)<5){
- FormatSprite(str,str_loc,data,1);
- }else{
- IssueMessage(0,INVALID_DATAFILE,"0.dat",DAT2,ch,data);
- exit(EDATA);
- }
- break;
- }
- case'r':{
- const PropData*vdata2=vdata.GetVarLength(i);
- uchar repeat_data=vdata.GetData(++i);
- uint times=vdata.GetValue(++i,decoded);
- if(repeat_data==0xFE){
- for(uint j=0;j<times;j++)
- if(!CheckVar(str_loc,str,*vdata2,false,false,pass))return false;
- }else if(GetWidth(repeat_data)<5){
- FormatSprite(str,str_loc,repeat_data,times);
- }else{
- IssueMessage(0,INVALID_DATAFILE,"0.dat",DAT2,'r',repeat_data);
- exit(EDATA);
- }
- break;
- }case'*':{
- const PropData*vdata2=vdata.GetVarLength(i);
- uchar repeat_data=vdata.GetData(++i);
- int term_len=vdata.GetData(++i);
- uint term;
- uint(PseudoSprite::*ExtractTerm)(uint)const;
- switch(term_len){
- case 1:
- term=vdata.GetData(++i);
- ExtractTerm=&PseudoSprite::ExtractByte;
+ case 0xFD:
+ pass.push_back(vdata.GetValue(++i, decoded));
break;
- case 2:
- term=vdata.GetData(++i);
- term|=vdata.GetData(++i)<<8;
- ExtractTerm=&PseudoSprite::ExtractWord;
- break;
- case 4:
- term=vdata.GetData(++i);
- term|=vdata.GetData(++i)<<8;
- term|=vdata.GetData(++i)<<16;
- term|=vdata.GetData(++i)<<24;
- ExtractTerm=&PseudoSprite::ExtractDword;
+ case 0xFE:
+ CheckVar(str_loc, str, *vdata.GetVarLength(i), false, false, pass);
break;
default:
- IssueMessage(0,INVALID_DATAFILE,"0.dat",DAT3,'*',repeat_data,term_len);
- exit(EDATA);
- }
- try{
- if(repeat_data==0xFE){
- while((str.*ExtractTerm)(str_loc)!=term)
- if(!CheckVar(str_loc,str,*vdata2,false,false,pass))return false;
- }else if(GetWidth(repeat_data)<5){
- while((str.*ExtractTerm)(str_loc)!=term)
- FormatSprite(str,str_loc,repeat_data);
- }else{
- IssueMessage(0,INVALID_DATAFILE,"0.dat",DAT2,'*',repeat_data);
- exit(EDATA);
+ switch (GetWidth(ch)) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ decoded.push_back(str.ExtractVariable(str_loc, GetWidth(ch)));
+ FormatSprite(str, str_loc, ch);
+ case 0:
+ break;
+ DEFAULT(ch)
}
- str_loc+=term_len;
- break;
- }catch(uint){
- IssueMessage(ERROR,MISSING_TERMINATOR);
- return false;
- }
- break;
- }case 0xFD:
- pass.push_back(vdata.GetValue(++i,decoded));
- break;
- case 0xFE:
- CheckVar(str_loc,str,*vdata.GetVarLength(i),false,false,pass);
- break;
- default:
- switch(GetWidth(ch)){
- case 1:
- case 2:
- case 3:
- case 4:
- decoded.push_back(str.ExtractVariable(str_loc,GetWidth(ch)));
- FormatSprite(str,str_loc,ch);
- case 0:
- break;
- DEFAULT(ch)
- }
- if(GetLinebreak(ch)==3){
- str.SetEol(str_loc-1,2);
- addblank|=canaddblank;
- }
+ if (GetLinebreak(ch) == 3) {
+ str.SetEol(str_loc - 1, 2);
+ addblank |= canaddblank;
+ }
}
}
- if(findPipe){
- IssueMessage(ERROR,MISSING_TERMINATOR);
+ if (findPipe) {
+ IssueMessage(ERROR, MISSING_TERMINATOR);
return false;
}
- if(appendeol)
- str.SetEol(str_loc-1,1,canaddblank?1:0);
- if(addblank && GetState(LINEBREAKS)>1)
- str.AddBlank(str_loc-1);
+ if (appendeol) str.SetEol(str_loc - 1, 1, canaddblank ? 1 : 0);
+ if (addblank && GetState(LINEBREAKS) > 1) str.AddBlank(str_loc - 1);
return true;
}
-Check0::Check0(){
- FILE*pFile=myfopen(0);
- _p=new PropData[MaxFeature()+1];
- for(uint i=0;i<=MaxFeature();i++)
- _p[i].Init(pFile,i==8);
+Check0::Check0()
+{
+ FILE* pFile = myfopen(0);
+ _p = new PropData[MaxFeature() + 1];
+ for (uint i = 0; i <= MaxFeature(); i++) _p[i].Init(pFile, i == 8);
fclose(pFile);
}
diff --git a/src/act123.cpp b/src/act123.cpp
--- a/src/act123.cpp
+++ b/src/act123.cpp
@@ -19,525 +19,570 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
-#include<fstream>
-#include<cassert>
-#include<errno.h>
-#include<cstdlib>
+#include <string>
+#include <fstream>
+#include <cassert>
+#include <errno.h>
+#include <cstdlib>
using namespace std;
-#include"inlines.h"
-#include"ExpandingArray.h"
-#include"sanity_defines.h"
-#include"data.h"
-#include"rangedint.h"
-#include"pseudo.h"
-#include"act123.h"
-#include"command.h"
-#include"messages.h"
+#include "inlines.h"
+#include "ExpandingArray.h"
+#include "sanity_defines.h"
+#include "data.h"
+#include "rangedint.h"
+#include "pseudo.h"
+#include "act123.h"
+#include "command.h"
+#include "messages.h"
#define MAX_TTD_SPRITE 4894
-uint CargoTransTable(int=0);
+uint CargoTransTable(int = 0);
-#define CHANGED_FEATURE(type)\
- {\
- int loop;\
- loop=0;\
-type##ChangedFeature:\
- if(loop++>10){\
- IssueMessage(FATAL,AUTOCORRECT_LOOP);\
- return;\
- }\
+#define CHANGED_FEATURE(type) \
+ { \
+ int loop; \
+ loop = 0; \
+ type##ChangedFeature : if (loop++ > 10) \
+ { \
+ IssueMessage(FATAL, AUTOCORRECT_LOOP); \
+ return; \
+ } \
}
/*int parity(uint x){
- int ret=0;
- while(x){
- ret+=x%2;
- x/=2;
- }
- return ret;
+ int ret=0;
+ while(x){
+ ret+=x%2;
+ x/=2;
+ }
+ return ret;
}*/
-
-bool CheckSpriteNum(uint num,uint offset,act123::Act1&act1,uint feature,bool&mismatch,bool&hasGround){
- uint sprite=num&0x3FFF;
- if(num&1<<31){
- if(feature!=act1.feature&&!mismatch){
- IssueMessage(ERROR,FEATURE_MISMATCH,1,act1.spritenum);
- mismatch=true;
+bool CheckSpriteNum(uint num, uint offset, act123::Act1& act1, uint feature, bool& mismatch, bool& hasGround)
+{
+ uint sprite = num & 0x3FFF;
+ if (num & 1 << 31) {
+ if (feature != act1.feature && !mismatch) {
+ IssueMessage(ERROR, FEATURE_MISMATCH, 1, act1.spritenum);
+ mismatch = true;
return false;
}
- if(sprite>=act1.numsets)
- IssueMessage(ERROR,UNDEFINED_SPRITE_SET,offset,sprite,act1.spritenum);
- else act1.use(sprite);
- }else if(sprite>MAX_TTD_SPRITE)
- IssueMessage(ERROR,SPRITENUM_TOO_HIGH,offset);
- hasGround|=((num&1<<30)!=0);
- int translate=num>>14&3,color=num>>16&0x3FFF;
- if(translate==3)IssueMessage(ERROR,INVALID_COLOR_TRANS,offset);
- else if((translate==1||(translate==2&&color))&&(color<775||color>790)&&(color<795||color>803))
- IssueMessage(WARNING1,INVALID_COLOR_SPRITE,offset+2,color);
+ if (sprite >= act1.numsets)
+ IssueMessage(ERROR, UNDEFINED_SPRITE_SET, offset, sprite, act1.spritenum);
+ else
+ act1.use(sprite);
+ } else if (sprite > MAX_TTD_SPRITE)
+ IssueMessage(ERROR, SPRITENUM_TOO_HIGH, offset);
+ hasGround |= ((num & 1 << 30) != 0);
+ int translate = num >> 14 & 3, color = num >> 16 & 0x3FFF;
+ if (translate == 3)
+ IssueMessage(ERROR, INVALID_COLOR_TRANS, offset);
+ else if ((translate == 1 || (translate == 2 && color)) && (color < 775 || color > 790) && (color < 795 || color > 803))
+ IssueMessage(WARNING1, INVALID_COLOR_SPRITE, offset + 2, color);
return true;
}
-bool CheckCargoID(uint offset,unsigned int id,uint feature,uint&newfeature){
- act123::IDarray&IDs=act123::Instance().defined2IDs;
- if(id&0x8000)return false;//callback
- else if(id>>8){
- IssueMessage(ERROR,NEITHER_ID_CALLBACK,id,CID);
+bool CheckCargoID(uint offset, unsigned int id, uint feature, uint& newfeature)
+{
+ act123::IDarray& IDs = act123::Instance().defined2IDs;
+ if (id & 0x8000)
+ return false; // callback
+ else if (id >> 8) {
+ IssueMessage(ERROR, NEITHER_ID_CALLBACK, id, CID);
return true;
}
- if(IDs.test(offset,id)){
- if(IDs.GetFeature(id)!=feature){
- IssueMessage(ERROR,FEATURE_LINK_MISMATCH,offset,id,IDs.GetFeature(id));
- if(newfeature==(uint)-1)newfeature=IDs.GetFeature(id);
- else if(newfeature!=IDs.GetFeature(id))newfeature=feature;
- }else newfeature=feature;
+ if (IDs.test(offset, id)) {
+ if (IDs.GetFeature(id) != feature) {
+ IssueMessage(ERROR, FEATURE_LINK_MISMATCH, offset, id, IDs.GetFeature(id));
+ if (newfeature == (uint) - 1)
+ newfeature = IDs.GetFeature(id);
+ else if (newfeature != IDs.GetFeature(id))
+ newfeature = feature;
+ } else
+ newfeature = feature;
IDs.use(id);
return IDs.checks1C(id);
- }else
+ } else
return true;
}
-void invalidate_act3(){
- act123::Instance().act3spritenum=0;
+void invalidate_act3()
+{
+ act123::Instance().act3spritenum = 0;
}
-void CheckCallback(uint offs,uint feature,uint cb){
- Callbacks&cbs=Callbacks::Instance();
- if(cb&&(cb>=cbs.numcallbacks||cb<0x10||(cbs[cb]&0x80000000?!(cbs[cb]&(1<<feature)):feature!=cbs[cb])))
- IssueMessage(ERROR,INVALID_CALLBACK,offs,cb);
+void CheckCallback(uint offs, uint feature, uint cb)
+{
+ Callbacks& cbs = Callbacks::Instance();
+ if (cb && (cb >= cbs.numcallbacks || cb < 0x10 || (cbs[cb] & 0x80000000 ? !(cbs[cb] & (1 << feature)) : feature != cbs[cb])))
+ IssueMessage(ERROR, INVALID_CALLBACK, offs, cb);
}
-int Check1(PseudoSprite&data){
- act123::Act1&act1=act123::Instance().act1;
- const uint length=data.Length();
- if(act1.spritenum)
- for(unsigned int i=0;i<act1.numsets;i++)
- if(!act1.is_used(i))IssueMessage(WARNING1,UNUSED_SET,i,act1.spritenum);
+int Check1(PseudoSprite& data)
+{
+ act123::Act1& act1 = act123::Instance().act1;
+ const uint length = data.Length();
+ if (act1.spritenum)
+ for (unsigned int i = 0; i < act1.numsets; i++)
+ if (!act1.is_used(i)) IssueMessage(WARNING1, UNUSED_SET, i, act1.spritenum);
act1.init();
- if(CheckLength(length,(data.ExtractByte(3)==0xFF)?6:4,INVALID_LENGTH,ACTION,1,ONE_OF,4,6))return 0;
- if(!IsValidFeature(ACT1|EMPTY1,act1.feature=data.ExtractByte(1)))IssueMessage(ERROR,INVALID_FEATURE);
- act1.numsets=data.ExtractByte(2);
- if(!act1.numsets)IssueMessage(WARNING1,NO_SETS,1);
- int numsprites=data.ExtractExtended(3);
- if(!numsprites&&!IsValidFeature(EMPTY1,act1.feature))IssueMessage(WARNING1,NO_SPRITES,1);
- if(numsprites&&!IsValidFeature(ACT1,act1.feature)&&IsValidFeature(EMPTY1,act1.feature))IssueMessage(ERROR,INVALID_FEATURE);
- if((numsprites>4&&(act1.feature==7||act1.feature==9))||(numsprites>8&&act1.feature<4)||
- (numsprites>1&&act1.feature==0x0B))IssueMessage(WARNING1,SET_TOO_LARGE);
- else if(numsprites>4&&numsprites<8&&act1.feature<4)IssueMessage(WARNING1,STRANGE_SET_SIZE);
- act1.spritenum=_spritenum;
- return numsprites*act1.numsets;
+ if (CheckLength(length, (data.ExtractByte(3) == 0xFF) ? 6 : 4, INVALID_LENGTH, ACTION, 1, ONE_OF, 4, 6)) return 0;
+ if (!IsValidFeature(ACT1 | EMPTY1, act1.feature = data.ExtractByte(1))) IssueMessage(ERROR, INVALID_FEATURE);
+ act1.numsets = data.ExtractByte(2);
+ if (!act1.numsets) IssueMessage(WARNING1, NO_SETS, 1);
+ int numsprites = data.ExtractExtended(3);
+ if (!numsprites && !IsValidFeature(EMPTY1, act1.feature)) IssueMessage(WARNING1, NO_SPRITES, 1);
+ if (numsprites && !IsValidFeature(ACT1, act1.feature) && IsValidFeature(EMPTY1, act1.feature)) IssueMessage(ERROR, INVALID_FEATURE);
+ if ((numsprites > 4 && (act1.feature == 7 || act1.feature == 9)) || (numsprites > 8 && act1.feature < 4) ||
+ (numsprites > 1 && act1.feature == 0x0B))
+ IssueMessage(WARNING1, SET_TOO_LARGE);
+ else if (numsprites > 4 && numsprites < 8 && act1.feature < 4)
+ IssueMessage(WARNING1, STRANGE_SET_SIZE);
+ act1.spritenum = _spritenum;
+ return numsprites * act1.numsets;
}
-void Check2(PseudoSprite&data){
+void Check2(PseudoSprite& data)
+{
data.SetAllHex();
- act123::Act1&act1=act123::Instance().act1;
- uint feature=data.ExtractByte(1),id=data.ExtractByte(2);
- uint nument1=data.ExtractByte(3),length=data.Length(),i,j;
- Define2 defineID(feature,id);
- if(!IsValid2Feature(feature)){
- IssueMessage((nument1&0x80)?ERROR:FATAL,INVALID_FEATURE);
- if(_autocorrect==2&&act1.spritenum&&!(nument1&0x80)){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,FEATURE,feature,act1.feature);
- data.SetByteAt(1,feature=act1.feature);
- }else if(!(nument1&0x80)) return;
+ act123::Act1& act1 = act123::Instance().act1;
+ uint feature = data.ExtractByte(1), id = data.ExtractByte(2);
+ uint nument1 = data.ExtractByte(3), length = data.Length(), i, j;
+ Define2 defineID(feature, id);
+ if (!IsValid2Feature(feature)) {
+ IssueMessage((nument1 & 0x80) ? ERROR : FATAL, INVALID_FEATURE);
+ if (_autocorrect == 2 && act1.spritenum && !(nument1 & 0x80)) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, FEATURE, feature, act1.feature);
+ data.SetByteAt(1, feature = act1.feature);
+ } else if (!(nument1 & 0x80))
+ return;
}
- switch(nument1){
- case 0x80:
- case 0x83:
- case 0x84:
- {
-CHANGED_FEATURE(rand)
- bool isRand=false;
- unsigned int prevID=(unsigned)-1,rID,newfeature=(uint)-1;
- uint base = 7; // offset of first randID
- if(nument1==0x84){
- base = 8;
- if(data.ExtractByte(4)&0x30)
- IssueMessage(ERROR,BAD_RANDSUBTYPE);
+ switch (nument1) {
+ case 0x80:
+ case 0x83:
+ case 0x84: {
+ CHANGED_FEATURE(rand)
+ bool isRand = false;
+ unsigned int prevID = (unsigned)-1, rID, newfeature = (uint) - 1;
+ uint base = 7; // offset of first randID
+ if (nument1 == 0x84) {
+ base = 8;
+ if (data.ExtractByte(4) & 0x30) IssueMessage(ERROR, BAD_RANDSUBTYPE);
+ }
+ uint nument2 = data.ExtractByte(base - 1);
+ if ((nument2 - 1) & nument2 /*tests for only one bit set*/ || !nument2)
+ IssueMessage(ERROR, RAND_2_NUMSETS);
+ else if (nument2 == 1)
+ IssueMessage(WARNING3, ONLY_ONE_CHOICE);
+ rand2::Instance().CheckRand(feature, nument1, data.ExtractByte(base - 3), data.ExtractByte(base - 2), nument2);
+ if (_autocorrect && !((length - base) % 2)) {
+ uint realcount = (length - base) / 2;
+ if (nument2 != realcount && realcount < 256 && !((realcount - 1) & realcount)) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, base - 1, NRAND, nument2, realcount);
+ data.SetByteAt(base - 1, nument2 = realcount);
+ }
+ }
+ if (CheckLength(length, base + 2 * nument2, BAD_LENGTH, NRAND, VAL, nument2, base + 2 * nument2)) return;
+ for (i = 0; i < nument2; i++) {
+ rID = data.SetNoEol(base + 2 * i).ExtractWord(base + 2 * i);
+ CheckCargoID(base + i * 2, rID, feature, newfeature);
+ if (prevID != (unsigned)-1) isRand |= (prevID != rID);
+ prevID = rID;
+ }
+ if (!isRand && nument2 != 1) IssueMessage(WARNING3, NOT_RANDOM);
+ if (_autocorrect && newfeature != (uint) - 1 && newfeature != feature) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, FEATURE, feature, newfeature);
+ data.SetByteAt(1, feature = newfeature);
+ defineID.ChangeFeature(feature);
+ goto randChangedFeature;
+ }
+ return;
}
- uint nument2=data.ExtractByte(base-1);
- if((nument2-1)&nument2/*tests for only one bit set*/||!nument2)IssueMessage(ERROR,RAND_2_NUMSETS);
- else if(nument2==1)IssueMessage(WARNING3,ONLY_ONE_CHOICE);
- rand2::Instance().CheckRand(feature,nument1,data.ExtractByte(base-3),data.ExtractByte(base-2),nument2);
- if(_autocorrect&&!((length-base)%2)){
- uint realcount=(length-base)/2;
- if(nument2!=realcount && realcount<256 && !((realcount-1)&realcount)){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,base-1,NRAND,nument2,realcount);
- data.SetByteAt(base-1,nument2=realcount);
+ case 0x81:
+ case 0x82:
+ case 0x85:
+ case 0x86:
+ case 0x89:
+ case 0x8A: {
+#define Is60x(var) (((var) & 0xE0) == 0x60)
+ CHANGED_FEATURE(var)
+ uint extract = 1 << ((nument1 >> 2) & 3), off = 4, var, param = 0, shift, op = (uint) - 1, newfeature = (uint) - 1,
+ effFeature = Check2v::GetEffFeature(feature, nument1);
+ bool isvar = false, isadv = false;
+ uint oldop = 0;
+ varRange ranges(extract);
+ while (true) { // read <var> [<param>] <varadjust> [<op> ...]. off reports byte to be read.
+ var = data.ExtractByte(off++);
+ if (op == 0xF && oldop != 0xE && oldop != 0x10 && var != 0x7B)
+ IssueMessage(WARNING1, DISCARD_UNSTORED, off - 2);
+ else if (op == 0x10 && !Check2v::Instance().IsValid(effFeature, 0x7C))
+ IssueMessage(ERROR, NO_PERS_REGS, off - 2);
+ oldop = op;
+ if (Is60x(var)) param = data.ExtractByte(off++);
+ shift = data.ExtractByte(off++);
+ if (!isadv && var == 0x7B) IssueMessage(WARNING1, INDIRECT_VAR_START, off - 3);
+ Check2v::Instance().Check(effFeature, var, off - 2 - (Is60x(var) ? 1 : 0), param, shift & 0x1F);
+ if ((shift & 0xC0) == 0xC0) {
+ IssueMessage(FATAL, INVALID_SHIFT, off - 1);
+ return;
+ }
+ if (isadv || (shift & 0x20)) data.SetEol(off - (Is60x(var) ? 4 : 3), 2);
+ ranges.UpdateRange(var, op, shift, data, off);
+ defineID.Check(var);
+ isvar |= (var != 0x1A && var != 0x1C);
+ if (!(shift & 0x20)) break;
+ isadv = true;
+ if ((op = data.ExtractByte(off++)) > Check2v::GetMaxOp())
+ IssueMessage(ERROR, INVALID_OP, off - 1, op);
+ else
+ data.SetOpByte(off - 1, '2');
}
+ uint nument2 = data.ExtractByte(off); // off switches to byte-just-read.
+ if (isadv)
+ data.SetEol(off - 1, 1);
+ else if (nument2 > 1)
+ data.SetEol(off, 1);
+ if (!isvar) IssueMessage(WARNING4, NOT_VARIATIONAL);
+ uint width = 2 + extract * 2, end = ++off + width * nument2;
+ int change = int(length - end - 2) / int(width);
+ if (change && _autocorrect && !((length - end - 2) % width) && nument2 + change < 256) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, off - 1, NVAR, nument2, nument2 + change);
+ data.SetByteAt(off - 1, nument2 += change);
+ end = length - 2;
+ }
+ if (CheckLength(length, end + 2, BAD_LENGTH, NVAR, VAL, nument2, end + 2)) return;
+ uint def = data.ExtractWord(end), vID;
+ for (i = off; i < end; i += width) { // read <ID> <min> <max> [...]
+ vID = data.ExtractWord(i);
+ isvar = CheckCargoID(i, vID, feature, newfeature);
+ uint min = data.ExtractVariable(i + 2, extract), max = data.ExtractVariable(i + 2 + extract, extract);
+ if (nument2 > 1) data.SetEol(i + 1 + extract * 2, isadv ? 2 : 1);
+ if (min > max)
+ IssueMessage((i == off) ? WARNING4 : WARNING1, UNREACHABLE_VAR, (i - off) / width);
+ else {
+ ranges.AddRange(min, max);
+ if (def == vID && (nument2 != 1 || !isvar)) IssueMessage(WARNING3, REUSED_DEFAULT);
+ }
+ if (var == 0x0C && !isadv) {
+ if (min != max &&
+ !((feature == 7 && min == 0x1B && max == 0x1C) ||
+ (feature == 0 && min == 0x10 && max == 0x11 && (vID == 0x8000 || vID == 0xFF00))))
+ IssueMessage(WARNING1, CHECK_0C_RANGE, i + 2, min, max);
+ else {
+ CheckCallback(i + 2, feature, min);
+ }
+ }
+ }
+ ranges.CheckDefault();
+ CheckCargoID(end, def, feature, newfeature);
+ if (_autocorrect && newfeature != (uint) - 1 && newfeature != feature) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, FEATURE, feature, newfeature);
+ data.SetByteAt(1, feature = newfeature);
+ defineID.ChangeFeature(feature);
+ goto varChangedFeature;
+ }
+ return;
}
- if(CheckLength(length,base+2*nument2,BAD_LENGTH,NRAND,VAL,nument2,base+2*nument2))return;
- for(i=0;i<nument2;i++){
- rID=data.SetNoEol(base+2*i).ExtractWord(base+2*i);
- CheckCargoID(base+i*2,rID,feature,newfeature);
- if(prevID!=(unsigned)-1)
- isRand|=(prevID!=rID);
- prevID=rID;
- }
- if(!isRand&&nument2!=1)
- IssueMessage(WARNING3,NOT_RANDOM);
- if(_autocorrect&&newfeature!=(uint)-1&&newfeature!=feature){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,FEATURE,feature,newfeature);
- data.SetByteAt(1,feature=newfeature);
- defineID.ChangeFeature(feature);
- goto randChangedFeature;
- }
- return;
- }
- case 0x81:case 0x82:
- case 0x85:case 0x86:
- case 0x89:case 0x8A:
- {
-#define Is60x(var) (((var)&0xE0)==0x60)
-CHANGED_FEATURE(var)
- uint extract=1<<((nument1>>2)&3),off=4,var,param=0,shift,op=(uint)-1,newfeature=(uint)-1,
- effFeature = Check2v::GetEffFeature(feature,nument1);
- bool isvar=false,isadv=false;
- uint oldop = 0;
- varRange ranges(extract);
- while(true){//read <var> [<param>] <varadjust> [<op> ...]. off reports byte to be read.
- var=data.ExtractByte(off++);
- if(op==0xF && oldop!=0xE && oldop!=0x10 && var!=0x7B)
- IssueMessage(WARNING1,DISCARD_UNSTORED,off-2);
- else if(op==0x10 && !Check2v::Instance().IsValid(effFeature, 0x7C))
- IssueMessage(ERROR,NO_PERS_REGS,off-2);
- oldop = op;
- if(Is60x(var))param=data.ExtractByte(off++);
- shift=data.ExtractByte(off++);
- if(!isadv&&var==0x7B) IssueMessage(WARNING1,INDIRECT_VAR_START,off-3);
- Check2v::Instance().Check(effFeature,var,off-2-(Is60x(var)?1:0),param,shift&0x1F);
- if((shift&0xC0)==0xC0){
- IssueMessage(FATAL,INVALID_SHIFT,off-1);
+ default:
+ CHANGED_FEATURE(std)
+ if (nument1 & 0x80) {
+ IssueMessage(FATAL, INVALID_TYPE);
return;
}
- if(isadv||(shift&0x20))data.SetEol(off-(Is60x(var)?4:3),2);
- ranges.UpdateRange(var,op,shift,data,off);
- defineID.Check(var);
- isvar|=(var!=0x1A&&var!=0x1C);
- if(!(shift&0x20))break;
- isadv=true;
- if((op=data.ExtractByte(off++))>Check2v::GetMaxOp())
- IssueMessage(ERROR,INVALID_OP,off-1,op);
- else
- data.SetOpByte(off-1, '2');
- }
- uint nument2=data.ExtractByte(off);//off switches to byte-just-read.
- if(isadv)data.SetEol(off-1,1);
- else if(nument2>1)data.SetEol(off,1);
- if(!isvar)IssueMessage(WARNING4,NOT_VARIATIONAL);
- uint width=2+extract*2,end=++off+width*nument2;
- int change=int(length-end-2)/int(width);
- if(change&&_autocorrect&&!((length-end-2)%width)&&nument2+change<256){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,off-1,NVAR,nument2,nument2+change);
- data.SetByteAt(off-1,nument2+=change);
- end=length-2;
- }
- if(CheckLength(length,end+2,BAD_LENGTH,NVAR,VAL,nument2,end+2))return;
- uint def=data.ExtractWord(end),vID;
- for(i=off;i<end;i+=width){//read <ID> <min> <max> [...]
- vID=data.ExtractWord(i);
- isvar=CheckCargoID(i,vID,feature,newfeature);
- uint min=data.ExtractVariable(i+2,extract),max=data.ExtractVariable(i+2+extract,extract);
- if(nument2>1)data.SetEol(i+1+extract*2,isadv?2:1);
- if(min>max)IssueMessage((i==off)?WARNING4:WARNING1,UNREACHABLE_VAR,(i-off)/width);
- else{
- ranges.AddRange(min,max);
- if(def==vID&&(nument2!=1||!isvar))IssueMessage(WARNING3,REUSED_DEFAULT);
- }
- if(var==0x0C&&!isadv){
- if(min!=max&&!(
- (feature==7&&min==0x1B&&max==0x1C)||
- (feature==0&&min==0x10&&max==0x11&&(vID==0x8000||vID==0xFF00))
- ))
- IssueMessage(WARNING1,CHECK_0C_RANGE,i+2,min,max);
- else{
- CheckCallback(i+2,feature,min);
+ switch (Get2Type(feature)) {
+ case 0:
+ case 1:
+ case 2: { // Standard format
+ bool mismatch = false, no1 = false;
+ uint nument2 = data.ExtractByte(4);
+ if (CheckLength(length, 2 * (nument1 + nument2) + 5, BAD_LENGTH, VARS, NUMENT1, NUMENT2, VALS,
+ nument1, nument2, 2 * (nument1 + nument2) + 5))
+ break;
+ if (Get2Type(feature) == 0) {
+ if (!nument1) IssueMessage(ERROR, NO_REQD_SETS, LOADED);
+ if (!nument2) IssueMessage(ERROR, NO_REQD_SETS, LOADING);
+ } else if (Get2Type(feature) == 1) {
+ if (!nument2) IssueMessage(ERROR, NO_REQD_SETS, LOTS);
+ } else {
+ if (nument1 != 1) IssueMessage(ERROR, INVALID_LITERAL, 3, nument1, 1);
+ if (nument2) IssueMessage(ERROR, INVALID_LITERAL, 4, nument2, 0);
+ }
+ for (i = 0; i < nument1 + nument2; i++) {
+ j = data.ExtractWord(2 * i + 5);
+ if (j & 0x8000)
+ ; // Callback
+ else if (j >> 8)
+ IssueMessage(ERROR, NEITHER_ID_CALLBACK, j, SET);
+ else if (act1.spritenum == 0 && !no1) {
+ IssueMessage(ERROR, NO_ACT1);
+ no1 = true;
+ } else if (feature != act1.feature && !mismatch && !no1) {
+ mismatch = true;
+ IssueMessage(ERROR, FEATURE_MISMATCH, 1, act1.spritenum);
+ if (_autocorrect == 2 || (_autocorrect && Get2Type(act1.feature) < 3)) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, FEATURE, feature, act1.feature);
+ data.SetByteAt(1, feature = act1.feature);
+ defineID.ChangeFeature(feature);
+ goto stdChangedFeature;
+ }
+ } else if (j >= act1.numsets)
+ IssueMessage(ERROR, UNDEFINED_SPRITE_SET, 2 * i + 5, j, act1.spritenum);
+ else
+ act1.use(j);
+ }
+ break;
}
- }
- }
- ranges.CheckDefault();
- CheckCargoID(end,def,feature,newfeature);
- if(_autocorrect&&newfeature!=(uint)-1&&newfeature!=feature){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,FEATURE,feature,newfeature);
- data.SetByteAt(1,feature=newfeature);
- defineID.ChangeFeature(feature);
- goto varChangedFeature;
- }
- return;
- }
- default:
-CHANGED_FEATURE(std)
- if(nument1&0x80){
- IssueMessage(FATAL,INVALID_TYPE);
- return;
- }
- switch(Get2Type(feature)){
- case 0:
- case 1:
- case 2:{ // Standard format
- bool mismatch=false,no1=false;
- uint nument2=data.ExtractByte(4);
- if(CheckLength(length,2*(nument1+nument2)+5,BAD_LENGTH,VARS,NUMENT1,NUMENT2,VALS,nument1,nument2,
- 2*(nument1+nument2)+5))
- break;
- if (Get2Type(feature) == 0) {
- if(!nument1)IssueMessage(ERROR,NO_REQD_SETS,LOADED);
- if(!nument2)IssueMessage(ERROR,NO_REQD_SETS,LOADING);
- } else if (Get2Type(feature) == 1) {
- if(!nument2)IssueMessage(ERROR,NO_REQD_SETS,LOTS);
- } else {
- if(nument1!=1)IssueMessage(ERROR,INVALID_LITERAL,3,nument1,1);
- if(nument2)IssueMessage(ERROR,INVALID_LITERAL,4,nument2,0);
- }
- for(i=0;i<nument1+nument2;i++){
- j=data.ExtractWord(2*i+5);
- if(j&0x8000);//Callback
- else if(j>>8)IssueMessage(ERROR,NEITHER_ID_CALLBACK,j,SET);
- else if(act1.spritenum==0&&!no1){
- IssueMessage(ERROR,NO_ACT1);
- no1=true;
- }else if(feature!=act1.feature&&!mismatch&&!no1){
- mismatch=true;
- IssueMessage(ERROR,FEATURE_MISMATCH,1,act1.spritenum);
- if(_autocorrect==2||(_autocorrect&&Get2Type(act1.feature)<3)){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,FEATURE,feature,act1.feature);
- data.SetByteAt(1,feature=act1.feature);
- defineID.ChangeFeature(feature);
- goto stdChangedFeature;
+ case 3: { // House/Industry tile format
+ uint ground = data.ExtractDword(4);
+ uint ground_flags = 0;
+ uint off = 8;
+ if (nument1 & 0x40) {
+ ground_flags = data.ExtractWord(off);
+ off += 2;
+ if (ground_flags & 0x01) off += 1;
+ if (ground_flags & 0x02) off += 1;
+ if (ground_flags & 0x04) off += 1;
+ /*(flags&0x08) is valid but doesn't eat an extra byte*/
+ if (ground_flags & 0xFFF0) IssueMessage(ERROR, INVALID_ACT2_FLAGS, 8);
}
- }else if(j>=act1.numsets)
- IssueMessage(ERROR,UNDEFINED_SPRITE_SET,2*i+5,j,act1.spritenum);
- else act1.use(j);
- }
- break;
- }case 3:{ // House/Industry tile format
- uint ground=data.ExtractDword(4);
- uint ground_flags=0;
- uint off=8;
- if(nument1&0x40) {
- ground_flags=data.ExtractWord(off);off+=2;
- if(ground_flags&0x01)off+=1;
- if(ground_flags&0x02)off+=1;
- if(ground_flags&0x04)off+=1;
- /*(flags&0x08) is valid but doesn't eat an extra byte*/
- if(ground_flags&0xFFF0)IssueMessage(ERROR,INVALID_ACT2_FLAGS,8);
- }
- bool mismatch=false,hasGround=(ground!=0)||(ground_flags&0x06);
- if(ground&&!(ground_flags&0x06))CheckSpriteNum(ground,4,act1,feature,mismatch,hasGround);
- if(nument1){//Extended format
- bool has_flags = nument1&0x40;
- nument1&=0x3F;
- data.SetEol(3,3);//EOL before ground sprite
- data.SetEol(off-1,1);//EOL after ground sprite
- for(i=0;i<nument1||_autocorrect;/*increment in last statement in try block*/){
- try{
- uint curoff=off;
- uint building=data.ExtractDword(curoff);
- curoff+=4;
- uint flags=0;
- if(has_flags){
- flags=data.ExtractWord(curoff);
- curoff+=2;
+ bool mismatch = false, hasGround = (ground != 0) || (ground_flags & 0x06);
+ if (ground && !(ground_flags & 0x06)) CheckSpriteNum(ground, 4, act1, feature, mismatch, hasGround);
+ if (nument1) { // Extended format
+ bool has_flags = nument1 & 0x40;
+ nument1 &= 0x3F;
+ data.SetEol(3, 3); // EOL before ground sprite
+ data.SetEol(off - 1, 1); // EOL after ground sprite
+ for (i = 0; i < nument1 || _autocorrect; /*increment in last statement in try block*/) {
+ try
+ {
+ uint curoff = off;
+ uint building = data.ExtractDword(curoff);
+ curoff += 4;
+ uint flags = 0;
+ if (has_flags) {
+ flags = data.ExtractWord(curoff);
+ curoff += 2;
+ }
+ uint xoff = data.ExtractByte(curoff++);
+ uint yoff = data.ExtractByte(curoff++);
+ uint zoff = data.ExtractByte(curoff++);
+
+ if (!CheckSpriteNum(building, off, act123::Instance().act1, feature,
+ mismatch, hasGround) &&
+ (_autocorrect == 2 || (_autocorrect && Get2Type(act1.feature) == 3))) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, FEATURE, feature, act1.feature);
+ data.SetByteAt(1, feature = act1.feature);
+ goto stdChangedFeature;
+ }
+ if (!building && !(flags & 0x06))
+ IssueMessage(ERROR, NO_BUILDING_SPRITE, off);
+ if (zoff != 0x80) {
+ uint x = data.ExtractByte(curoff++);
+ uint y = data.ExtractByte(curoff++);
+ data.ExtractByte(curoff++);
+ if (xoff > 16)
+ IssueMessage(WARNING3, TOO_LARGE, curoff - 6, XOFF, 16);
+ else if (xoff + x > 16)
+ IssueMessage(WARNING3, TOO_LARGE, curoff - 6, XOFF_EXT, 16);
+ if (yoff > 16)
+ IssueMessage(WARNING3, TOO_LARGE, curoff - 5, YOFF, 16);
+ else if (yoff + y > 16)
+ IssueMessage(WARNING3, TOO_LARGE, curoff - 5, YOFF_EXT, 16);
+ }
+ if (flags & 0x01) curoff += 1;
+ if (flags & 0x02) curoff += 1;
+ if (flags & 0x04) curoff += 1;
+ /*(flags&0x08) is valid but doesn't eat an extra byte*/
+ if (flags & 0x10) curoff += 2;
+ if (flags & 0x20) curoff += 1;
+ if (flags & 0xFFC0) IssueMessage(ERROR, INVALID_ACT2_FLAGS, 8);
+ off = curoff;
+ if (++i != nument1) data.SetEol(off - 1, 1);
+ if (i == 0x3F && _autocorrect) throw 0;
+ }
+ catch (...)
+ {
+ if (_autocorrect && i) {
+ if (i != nument1) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 3, NUMSPRITES, nument1, i);
+ data.SetByteAt(3, i | (has_flags ? 0x40 : 0));
+ }
+ break;
+ } else {
+ IssueMessage(FATAL, OVERRAN_SPRITE, i);
+ return;
+ }
+ }
}
- uint xoff=data.ExtractByte(curoff++);
- uint yoff=data.ExtractByte(curoff++);
- uint zoff=data.ExtractByte(curoff++);
-
- if(!CheckSpriteNum(building,off,act123::Instance().act1,feature,mismatch,hasGround)&&
- (_autocorrect==2||(_autocorrect&&Get2Type(act1.feature)==3))){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,FEATURE,feature,act1.feature);
- data.SetByteAt(1,feature=act1.feature);
- goto stdChangedFeature;
- }
- if(!building&&!(flags&0x06))IssueMessage(ERROR,NO_BUILDING_SPRITE,off);
- if(zoff!=0x80){
- uint x=data.ExtractByte(curoff++);
- uint y=data.ExtractByte(curoff++);
- data.ExtractByte(curoff++);
- if(xoff>16)IssueMessage(WARNING3,TOO_LARGE,curoff-6,XOFF,16);
- else if(xoff+x>16)IssueMessage(WARNING3,TOO_LARGE,curoff-6,XOFF_EXT,16);
- if(yoff>16)IssueMessage(WARNING3,TOO_LARGE,curoff-5,YOFF,16);
- else if(yoff+y>16)IssueMessage(WARNING3,TOO_LARGE,curoff-5,YOFF_EXT,16);
- }
- if(flags&0x01)curoff+=1;
- if(flags&0x02)curoff+=1;
- if(flags&0x04)curoff+=1;
- /*(flags&0x08) is valid but doesn't eat an extra byte*/
- if(flags&0x10)curoff+=2;
- if(flags&0x20)curoff+=1;
- if(flags&0xFFC0)IssueMessage(ERROR,INVALID_ACT2_FLAGS,8);
- off=curoff;
- if(++i!=nument1)data.SetEol(off-1,1);
- if(i==0x3F&&_autocorrect)throw 0;
- }catch(...){
- if(_autocorrect&&i){
- if(i!=nument1){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,3,NUMSPRITES,nument1,i);
- data.SetByteAt(3,i|(has_flags?0x40:0));
+ if (off != length) IssueMessage(WARNING2, EXTRA_DATA, length, off);
+ if (!hasGround) IssueMessage(WARNING2, NO_GROUNDSPRITE, NONTRANS);
+ } else { // Basic format
+ if (!ground) IssueMessage(ERROR, NO_GROUNDSPRITE, GROUND);
+ if (CheckLength(length, 17, INVALID_LENGTH, TYPE, BASICSTD2, HOUSE_INSTYTILE, EXACTLY, 17))
+ break;
+ uint building = data.ExtractDword(8), xoff = data.ExtractByte(12),
+ yoff = data.ExtractByte(13), x = data.ExtractByte(14),
+ y = data.ExtractByte(15); //,z=data.ExtractByte(16);
+ if (building) {
+ if (!CheckSpriteNum(building, 8, act1, feature, mismatch, hasGround) &&
+ (_autocorrect == 2 || (_autocorrect && Get2Type(act1.feature) == 3))) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, FEATURE, feature, act1.feature);
+ data.SetByteAt(1, feature = act1.feature);
+ goto stdChangedFeature;
}
- break;
- }else{
- IssueMessage(FATAL,OVERRAN_SPRITE,i);
- return;
+ if (xoff > 16)
+ IssueMessage(WARNING3, TOO_LARGE, 12, XOFF, 16);
+ else if (xoff + x > 16)
+ IssueMessage(WARNING3, TOO_LARGE, 12, XOFF_EXT, 16);
+ if (yoff > 16)
+ IssueMessage(WARNING3, TOO_LARGE, 13, YOFF, 16);
+ else if (yoff + y > 16)
+ IssueMessage(WARNING3, TOO_LARGE, 13, YOFF_EXT, 16);
+ // if(z>0x87)IssueMessage(WARNING1,TOO_LARGE,16,ZEXT,0x87);
}
}
+ break;
}
- if(off!=length)IssueMessage(WARNING2,EXTRA_DATA,length,off);
- if(!hasGround)IssueMessage(WARNING2,NO_GROUNDSPRITE,NONTRANS);
- }else{//Basic format
- if(!ground)IssueMessage(ERROR,NO_GROUNDSPRITE,GROUND);
- if(CheckLength(length,17,INVALID_LENGTH,TYPE,BASICSTD2,HOUSE_INSTYTILE,EXACTLY,17))break;
- uint building=data.ExtractDword(8),xoff=data.ExtractByte(12),yoff=data.ExtractByte(13),
- x=data.ExtractByte(14),y=data.ExtractByte(15);//,z=data.ExtractByte(16);
- if(building){
- if(!CheckSpriteNum(building,8,act1,feature,mismatch,hasGround)&&
- (_autocorrect==2||(_autocorrect&&Get2Type(act1.feature)==3))){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,FEATURE,feature,act1.feature);
- data.SetByteAt(1,feature=act1.feature);
- goto stdChangedFeature;
+ case 4: // Industry format
+ switch (data.ExtractByte(3)) { // Callback version
+ case 0:
+ if (CheckLength(length, 15, INVALID_LENGTH, TYPE, PROD2S, INDUSTRIES, ONE_OF, 10,
+ 15))
+ break;
+ if (data.ExtractWord(10) > 32768) IssueMessage(WARNING1, EXCESSIVE_ADD, 1);
+ if (data.ExtractWord(12) > 32768) IssueMessage(WARNING1, EXCESSIVE_ADD, 2);
+ break;
+ case 1:
+ CheckLength(length, 10, INVALID_LENGTH, TYPE, PROD2S, INDUSTRIES, ONE_OF, 10, 15);
+ break;
+ default:
+ IssueMessage(ERROR, INVALID_VERSION, PROD2);
}
- if(xoff>16)IssueMessage(WARNING3,TOO_LARGE,12,XOFF,16);
- else if(xoff+x>16)IssueMessage(WARNING3,TOO_LARGE,12,XOFF_EXT,16);
- if(yoff>16)IssueMessage(WARNING3,TOO_LARGE,13,YOFF,16);
- else if(yoff+y>16)IssueMessage(WARNING3,TOO_LARGE,13,YOFF_EXT,16);
- //if(z>0x87)IssueMessage(WARNING1,TOO_LARGE,16,ZEXT,0x87);
- }
+ break;
+ DEFAULT(feature)
}
- break;
- }case 4: // Industry format
- switch(data.ExtractByte(3)){ // Callback version
- case 0:
- if(CheckLength(length,15,INVALID_LENGTH,TYPE,PROD2S,INDUSTRIES,ONE_OF,10,15))break;
- if(data.ExtractWord(10)>32768)IssueMessage(WARNING1,EXCESSIVE_ADD,1);
- if(data.ExtractWord(12)>32768)IssueMessage(WARNING1,EXCESSIVE_ADD,2);
- break;
- case 1:
- CheckLength(length,10,INVALID_LENGTH,TYPE,PROD2S,INDUSTRIES,ONE_OF,10,15);
- break;
- default:
- IssueMessage(ERROR,INVALID_VERSION,PROD2);
- }
- break;
- DEFAULT(feature)
- }
}
}
-void Check3(PseudoSprite&data){
+void Check3(PseudoSprite& data)
+{
PseudoSprite::Byte feature, numIDs;
-CHANGED_FEATURE(act3)
- data.seek(1)>>feature>>numIDs;
- uint newfeature=(uint)-1, i;
- bool isOverride=((numIDs&0x80)!=0),isGeneric=((numIDs&0x7F)==0);
- if(isOverride&&isGeneric)IssueMessage(ERROR,GENERIC_AND_OVERRIDE);
- if(!isGeneric&&!IsValidFeature(ACT3,feature)){IssueMessage(FATAL,INVALID_FEATURE);return;}
- else if(isOverride&&!IsValidFeature(OVERRIDE3,feature))IssueMessage(ERROR,INVALID_FEATURE);
- else if(isGeneric&&!IsValidFeature(GENERIC3,feature))IssueMessage(ERROR,INVALID_FEATURE);
+ CHANGED_FEATURE(act3)
+ data.seek(1) >> feature >> numIDs;
+ uint newfeature = (uint) - 1, i;
+ bool isOverride = ((numIDs & 0x80) != 0), isGeneric = ((numIDs & 0x7F) == 0);
+ if (isOverride && isGeneric) IssueMessage(ERROR, GENERIC_AND_OVERRIDE);
+ if (!isGeneric && !IsValidFeature(ACT3, feature)) {
+ IssueMessage(FATAL, INVALID_FEATURE);
+ return;
+ } else if (isOverride && !IsValidFeature(OVERRIDE3, feature))
+ IssueMessage(ERROR, INVALID_FEATURE);
+ else if (isGeneric && !IsValidFeature(GENERIC3, feature))
+ IssueMessage(ERROR, INVALID_FEATURE);
Expanding0Array<int> ids;
PseudoSprite::ExtByte id;
- for(i=0;i<(numIDs&0x7F);i++){
- data>>id;
- if(ids[id])
- IssueMessage(WARNING1,DUPLICATE,id.loc(),ID,id.val(),ids[id]);
- ids[id]=id.loc();
- CheckID(feature,id);
- if(!IsValidFeature(ACT3_BEFORE_PROP08,feature) && !IsProp08Set(feature,id))
- IssueMessage(ERROR,ACT3_PRECEDES_PROP08,id.loc(),id.val());
+ for (i = 0; i < (numIDs & 0x7F); i++) {
+ data >> id;
+ if (ids[id]) IssueMessage(WARNING1, DUPLICATE, id.loc(), ID, id.val(), ids[id]);
+ ids[id] = id.loc();
+ CheckID(feature, id);
+ if (!IsValidFeature(ACT3_BEFORE_PROP08, feature) && !IsProp08Set(feature, id))
+ IssueMessage(ERROR, ACT3_PRECEDES_PROP08, id.loc(), id.val());
}
PseudoSprite::Byte numCIDs;
- data>>numCIDs;
- uint newCIDs=data.BytesRemaining()/3;
- if(_autocorrect>=2&&(data.BytesRemaining()%3)==2&&newCIDs!=numCIDs&&newCIDs<256){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,numCIDs.loc(),NUMCID,numCIDs.val(),newCIDs);
+ data >> numCIDs;
+ uint newCIDs = data.BytesRemaining() / 3;
+ if (_autocorrect >= 2 && (data.BytesRemaining() % 3) == 2 && newCIDs != numCIDs && newCIDs < 256) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, numCIDs.loc(), NUMCID, numCIDs.val(), newCIDs);
numCIDs.set(newCIDs);
}
- if(numCIDs&&feature>4&&feature!=0xF&&feature!=0x10)IssueMessage(WARNING1,NO_CARGOTYPES);
+ if (numCIDs && feature > 4 && feature != 0xF && feature != 0x10) IssueMessage(WARNING1, NO_CARGOTYPES);
PseudoSprite::Byte cargo;
- PseudoSprite::Word cid,def;
- data.Extract(def,numCIDs.loc()+1+numCIDs*3);
+ PseudoSprite::Word cid, def;
+ data.Extract(def, numCIDs.loc() + 1 + numCIDs * 3);
- ids.clear(); // Reuse as cargos
+ ids.clear(); // Reuse as cargos
ids.reserve(256);
- for (i=0; i<numCIDs; i++) {
- data>>cargo>>cid;
- if ((feature == 0x0F && cargo != 0x00 && cargo != 0xFF) ||
- (feature == 0x10 && cargo > 0x0A) ||
- (feature <= 0x04 && cargo>CargoTransTable() && cargo != 0xFF && (cargo != 0xFE || feature != 4)))
- IssueMessage(ERROR,INVALID_CARGO_TYPE,cargo.loc(),cargo.val());
- if(ids[cargo])
- IssueMessage(WARNING1,DUPLICATE,cargo.loc(),CARGO,cargo.val(),ids[cargo]);
+ for (i = 0; i < numCIDs; i++) {
+ data >> cargo >> cid;
+ if ((feature == 0x0F && cargo != 0x00 && cargo != 0xFF) || (feature == 0x10 && cargo > 0x0A) ||
+ (feature <= 0x04 && cargo > CargoTransTable() && cargo != 0xFF && (cargo != 0xFE || feature != 4)))
+ IssueMessage(ERROR, INVALID_CARGO_TYPE, cargo.loc(), cargo.val());
+ if (ids[cargo]) IssueMessage(WARNING1, DUPLICATE, cargo.loc(), CARGO, cargo.val(), ids[cargo]);
ids[cargo] = cargo.loc();
- CheckCargoID(cid.loc(),cid,feature,newfeature);
- if(def==cid)
- IssueMessage(WARNING1,REUSED_DEFAULT);
+ CheckCargoID(cid.loc(), cid, feature, newfeature);
+ if (def == cid) IssueMessage(WARNING1, REUSED_DEFAULT);
}
- CheckCargoID(def.loc(),def,feature,newfeature);
+ CheckCargoID(def.loc(), def, feature, newfeature);
if (isOverride && act123::Instance().act3spritenum && feature != act123::Instance().act3feature) {
- IssueMessage(ERROR,FEATURE_MISMATCH, 3, act123::Instance().act3spritenum);
+ IssueMessage(ERROR, FEATURE_MISMATCH, 3, act123::Instance().act3spritenum);
newfeature = act123::Instance().act3feature;
}
- if(_autocorrect&&newfeature!=(uint)-1&&newfeature!=feature){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,FEATURE,feature.val(),newfeature);
+ if (_autocorrect && newfeature != (uint) - 1 && newfeature != feature) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, FEATURE, feature.val(), newfeature);
feature.set(newfeature);
goto act3ChangedFeature;
}
- if(isGeneric)// Generic 3s cannot be followed by an override
- act123::Instance().act3spritenum=0;
- else if(!isOverride){
- act123::Instance().act3feature=feature;
- act123::Instance().act3spritenum=_spritenum;
- }else if(!act123::Instance().act3spritenum) IssueMessage(ERROR,NO_STD_3);
+ if (isGeneric) // Generic 3s cannot be followed by an override
+ act123::Instance().act3spritenum = 0;
+ else if (!isOverride) {
+ act123::Instance().act3feature = feature;
+ act123::Instance().act3spritenum = _spritenum;
+ } else if (!act123::Instance().act3spritenum)
+ IssueMessage(ERROR, NO_STD_3);
}
-void Init123(){act123::Instance().init();}
+void Init123()
+{
+ act123::Instance().init();
+}
-void final123(){
- const act123::IDarray& IDs=act123::CInstance().defined2IDs;
+void final123()
+{
+ const act123::IDarray& IDs = act123::CInstance().defined2IDs;
ManualConsoleMessages();
- bool header=false;
- if(act123::Instance().act1.spritenum)
- for(unsigned int i=0;i<act123::Instance().act1.numsets;i++)
- if(!act123::CInstance().act1.is_used(i)){
- IssueMessage(WARNING1,UNUSED_SET,i,act123::Instance().act1.spritenum);
- if(!header){
- IssueMessage(WARNING1,UNEXP_EOF_STD2);
- header=true;
+ bool header = false;
+ if (act123::Instance().act1.spritenum)
+ for (unsigned int i = 0; i < act123::Instance().act1.numsets; i++)
+ if (!act123::CInstance().act1.is_used(i)) {
+ IssueMessage(WARNING1, UNUSED_SET, i, act123::Instance().act1.spritenum);
+ if (!header) {
+ IssueMessage(WARNING1, UNEXP_EOF_STD2);
+ header = true;
}
}
int j;
- for(uint i=0;i<=act123::Instance().MaxFoundFeat();i++){
- header=false;
- for(j=0;j<256;j++)
- if(IDs.GetFeature(j)==i&&IDs.is_defined(j)&&!IDs.is_used(j)){
- if(!header){
- IssueMessage(WARNING1,UNUSED2IDLEAD,i);
- IssueMessage(WARNING1,UNEXP_EOF_CARGOID,i);
- header=true;
+ for (uint i = 0; i <= act123::Instance().MaxFoundFeat(); i++) {
+ header = false;
+ for (j = 0; j < 256; j++)
+ if (IDs.GetFeature(j) == i && IDs.is_defined(j) && !IDs.is_used(j)) {
+ if (!header) {
+ IssueMessage(WARNING1, UNUSED2IDLEAD, i);
+ IssueMessage(WARNING1, UNEXP_EOF_CARGOID, i);
+ header = true;
}
- IssueMessage(WARNING1,UNUSEDIDFINAL,j,IDs.defined_at(j));
+ IssueMessage(WARNING1, UNUSEDIDFINAL, j, IDs.defined_at(j));
}
}
}
diff --git a/src/act123.h b/src/act123.h
--- a/src/act123.h
+++ b/src/act123.h
@@ -24,121 +24,196 @@
class PseudoSprite;
-struct act123{
+struct act123
+{
void init();
- uint MaxFoundFeat()const;
+ uint MaxFoundFeat() const;
- class Act1{
- public:
- Act1(){init();}
- void init(){spritenum=0;used.resize(0);}
- bool is_used(int set)const{return used[set];}
- void use(int set){used[set]=true;}
- unsigned int feature,numsets,spritenum;
- private:
- Expanding0Array<bool>used;
- }act1;
- class IDarray{
- public:
- void init(){_m.resize(0);}
- bool is_defined(int id)const{return _m[id].sprite!=0;}
- bool is_used(int id)const{return _m[id].used;}
- unsigned int defined_at(int id)const{return _m[id].sprite;}
- void define(uint feature,unsigned int id,bool checks1C);
- bool checks1C(int id)const{return _m[id].v1C;}
- void use(int id){_m[id].used=true;}
- bool test(uint,uint)const;
- unsigned short GetFeature(uint id)const{return _m[id].feature;}
- friend uint act123::MaxFoundFeat()const;
- private:
- struct info{
- info():used(false),v1C(false),feature((unsigned short)-1),sprite(0){}
- bool used,v1C;
+ class Act1
+ {
+ public:
+ Act1()
+ {
+ init();
+ }
+ void init()
+ {
+ spritenum = 0;
+ used.resize(0);
+ }
+ bool is_used(int set) const
+ {
+ return used[set];
+ }
+ void use(int set)
+ {
+ used[set] = true;
+ }
+ unsigned int feature, numsets, spritenum;
+
+ private:
+ Expanding0Array<bool> used;
+ } act1;
+ class IDarray
+ {
+ public:
+ void init()
+ {
+ _m.resize(0);
+ }
+ bool is_defined(int id) const
+ {
+ return _m[id].sprite != 0;
+ }
+ bool is_used(int id) const
+ {
+ return _m[id].used;
+ }
+ unsigned int defined_at(int id) const
+ {
+ return _m[id].sprite;
+ }
+ void define(uint feature, unsigned int id, bool checks1C);
+ bool checks1C(int id) const
+ {
+ return _m[id].v1C;
+ }
+ void use(int id)
+ {
+ _m[id].used = true;
+ }
+ bool test(uint, uint) const;
+ unsigned short GetFeature(uint id) const
+ {
+ return _m[id].feature;
+ }
+ friend uint act123::MaxFoundFeat() const;
+
+ private:
+ struct info
+ {
+ info() : used(false), v1C(false), feature((unsigned short)-1), sprite(0)
+ {
+ }
+ bool used, v1C;
unsigned short feature;
unsigned int sprite;
};
- ExpandingArray<info>_m;
- }defined2IDs;
+ ExpandingArray<info> _m;
+ } defined2IDs;
- uint act3feature,act3spritenum;
+ uint act3feature, act3spritenum;
SINGLETON(act123)
};
-class Check2v{
- struct VarData{
- VarData():width(0){}
- VarData(int x):width(x){}
+class Check2v
+{
+ struct VarData
+ {
+ VarData() : width(0)
+ {
+ }
+ VarData(int x) : width(x)
+ {
+ }
int Load(FILE*);
- uint min,max,width,maxparam;
+ uint min, max, width, maxparam;
};
- struct FeatData{
- FeatData():var80(VarData(1)){}
- ExpandingArray<VarData>vars;
- ExpandingArray<VarData>var80;
- uint last80,featfor82;
+ struct FeatData
+ {
+ FeatData() : var80(VarData(1))
+ {
+ }
+ ExpandingArray<VarData> vars;
+ ExpandingArray<VarData> var80;
+ uint last80, featfor82;
};
-public:
- void Check(uint,uint,uint,uint,uint)const;
- static uint GetMaxOp(){return Instance().maxop;}
+
+ public:
+ void Check(uint, uint, uint, uint, uint) const;
+ static uint GetMaxOp()
+ {
+ return Instance().maxop;
+ }
static uint Prohibit0Mask(uint);
- static uint GetEffFeature(uint,uint);
- bool IsValid(uint feature, uint var)const;
+ static uint GetEffFeature(uint, uint);
+ bool IsValid(uint feature, uint var) const;
SINGLETON(Check2v)
-private:
- ExpandingArray<VarData>globvars;
- auto_array<FeatData>_p;
+ private:
+ ExpandingArray<VarData> globvars;
+ auto_array<FeatData> _p;
uint maxop;
- uint MaxParam(uint feature, uint var)const;
- uint GetWidth(uint feature, uint var)const;
+ uint MaxParam(uint feature, uint var) const;
+ uint GetWidth(uint feature, uint var) const;
};
-class varRange{
-private:
- struct range{
- explicit range(uint max):min(0,max),max(max,max){}
- range(const range&right):min(right.min),max(right.max){}
- range(uint rangemax,uint minval,uint maxval):min(minval,rangemax),max(maxval,rangemax){}
- RangedUint min,max;
- }dflt;
-public:
+class varRange
+{
+ private:
+ struct range
+ {
+ explicit range(uint max) : min(0, max), max(max, max)
+ {
+ }
+ range(const range& right) : min(right.min), max(right.max)
+ {
+ }
+ range(uint rangemax, uint minval, uint maxval) : min(minval, rangemax), max(maxval, rangemax)
+ {
+ }
+ RangedUint min, max;
+ } dflt;
+
+ public:
static const uint rangemax[];
explicit varRange(uint);
- void UpdateRange(uint var,uint op,uint shift,const PseudoSprite&data,uint&offs);
- void AddRange(uint min,uint max);
+ void UpdateRange(uint var, uint op, uint shift, const PseudoSprite& data, uint& offs);
+ void AddRange(uint min, uint max);
void CheckDefault();
-private:
+
+ private:
int num;
uint width;
- vector<range>ranges;
- void AddRangeInternal(uint min,uint max,RenumMessageId unreachable);
+ vector<range> ranges;
+ void AddRangeInternal(uint min, uint max, RenumMessageId unreachable);
};
-class rand2{
-private:
- struct rand2info{
- uint bits[2],numtriggers;
+class rand2
+{
+ private:
+ struct rand2info
+ {
+ uint bits[2], numtriggers;
};
- auto_array<rand2info>_p;
-public:
- void CheckRand(uint feat,uint type,uint triggers,uint first,uint nrand);
+ auto_array<rand2info> _p;
+
+ public:
+ void CheckRand(uint feat, uint type, uint triggers, uint first, uint nrand);
SINGLETON(rand2);
};
-//An object of this class will check and define the given ID when it is destroyed.
-class Define2{
-public:
- Define2(uint feat,uint id):feature(feat),id(id),checks1C(false){}
+// An object of this class will check and define the given ID when it is destroyed.
+class Define2
+{
+ public:
+ Define2(uint feat, uint id) : feature(feat), id(id), checks1C(false)
+ {
+ }
~Define2();
- void Check(uint var){checks1C|=(var==0x1C);}
+ void Check(uint var)
+ {
+ checks1C |= (var == 0x1C);
+ }
void ChangeFeature(uint);
-private:
- uint feature,id;
+
+ private:
+ uint feature, id;
bool checks1C;
};
-class Callbacks:public auto_array<uint>{
-public:
+class Callbacks : public auto_array<uint>
+{
+ public:
uint numcallbacks;
SINGLETON(Callbacks);
};
-
diff --git a/src/act123_classes.cpp b/src/act123_classes.cpp
--- a/src/act123_classes.cpp
+++ b/src/act123_classes.cpp
@@ -19,22 +19,22 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
-#include<iostream>
-#include<cstdlib>
+#include <string>
+#include <iostream>
+#include <cstdlib>
using namespace std;
-#include"inlines.h"
-#include"ExpandingArray.h"
-#include"sanity_defines.h"
-#include"data.h"
-#include"rangedint.h"
-#include"pseudo.h"
-#include"messages.h"
-#include"command.h"
+#include "inlines.h"
+#include "ExpandingArray.h"
+#include "sanity_defines.h"
+#include "data.h"
+#include "rangedint.h"
+#include "pseudo.h"
+#include "messages.h"
+#include "command.h"
-#if defined(min)||defined(max)
+#if defined(min) || defined(max)
#error min and max must be implemented as functions
#endif
@@ -44,32 +44,38 @@
// act123
//****************************************
-act123::act123(){init();}
+act123::act123()
+{
+ init();
+}
-void act123::init(){
+void act123::init()
+{
act1.init();
defined2IDs.init();
- act3spritenum=0;
+ act3spritenum = 0;
}
-uint act123::MaxFoundFeat()const{
- const vector<IDarray::info>&m=defined2IDs._m;
- short ret=0;
- for(uint i=0;i<(uint)m.size();i++)
- ret=max<short>(ret,m[i].feature);
+uint act123::MaxFoundFeat() const
+{
+ const vector<IDarray::info>& m = defined2IDs._m;
+ short ret = 0;
+ for (uint i = 0; i < (uint)m.size(); i++) ret = max<short>(ret, m[i].feature);
return ret;
}
-void act123::IDarray::define(uint feature,unsigned int id,bool checks1C){
- _m[id].used=false;
- _m[id].sprite=_spritenum;
- _m[id].v1C=checks1C;
- _m[id].feature=(ushort)feature;
+void act123::IDarray::define(uint feature, unsigned int id, bool checks1C)
+{
+ _m[id].used = false;
+ _m[id].sprite = _spritenum;
+ _m[id].v1C = checks1C;
+ _m[id].feature = (ushort)feature;
}
-bool act123::IDarray::test(uint offset,uint id)const{
- if(!is_defined(id)){
- IssueMessage(ERROR,UNDEFINED_ID,offset,id);
+bool act123::IDarray::test(uint offset, uint id) const
+{
+ if (!is_defined(id)) {
+ IssueMessage(ERROR, UNDEFINED_ID, offset, id);
return false;
}
return true;
@@ -79,97 +85,110 @@
// Check2v
//****************************************
-Check2v::Check2v(){
- FILE*pFile=myfopen(2v);
+Check2v::Check2v()
+{
+ FILE* pFile = myfopen(2v);
VarData tempvar;
int var;
- maxop=GetCheckByte(2v);
- while(true){
- var=tempvar.Load(pFile);
- if(var==-1)break;
- globvars[var]=tempvar;
+ maxop = GetCheckByte(2v);
+ while (true) {
+ var = tempvar.Load(pFile);
+ if (var == -1) break;
+ globvars[var] = tempvar;
}
- _p=new FeatData[MaxFeature()+1];
- for(uint i=0;i<=MaxFeature();i++){
- _p[i].last80=0xFF;
- _p[i].featfor82=GetCheckByte(2v);
- while(true){
- var=tempvar.Load(pFile);
- if(var==-1)break;
- if(tempvar.width==0x80){
- _p[i].last80=var-1;
+ _p = new FeatData[MaxFeature() + 1];
+ for (uint i = 0; i <= MaxFeature(); i++) {
+ _p[i].last80 = 0xFF;
+ _p[i].featfor82 = GetCheckByte(2v);
+ while (true) {
+ var = tempvar.Load(pFile);
+ if (var == -1) break;
+ if (tempvar.width == 0x80) {
+ _p[i].last80 = var - 1;
break;
}
- if(var==0xFF&&tempvar.width==0xF0)break;
- if(var&0x80)_p[i].var80[var&0x7F]=tempvar;
- else _p[i].vars[var]=tempvar;
+ if (var == 0xFF && tempvar.width == 0xF0) break;
+ if (var & 0x80)
+ _p[i].var80[var & 0x7F] = tempvar;
+ else
+ _p[i].vars[var] = tempvar;
}
}
fclose(pFile);
}
-bool Check2v::IsValid(uint feature, uint var)const{
- if(var>=0x80)
- return _p[feature].var80[var&0x7F].width != 0;
+bool Check2v::IsValid(uint feature, uint var) const
+{
+ if (var >= 0x80)
+ return _p[feature].var80[var & 0x7F].width != 0;
else
return _p[feature].vars[var].width || globvars[var].width;
}
-uint Check2v::MaxParam(uint feature, uint var)const{
- assert((var&0xE0)==0x60);
+uint Check2v::MaxParam(uint feature, uint var) const
+{
+ assert((var & 0xE0) == 0x60);
assert(IsValid(feature, var));
- if(_p[feature].vars[var].width)
+ if (_p[feature].vars[var].width)
return _p[feature].vars[var].maxparam;
else
return globvars[var].maxparam;
}
-uint Check2v::GetWidth(uint feature, uint var)const{
+uint Check2v::GetWidth(uint feature, uint var) const
+{
assert(IsValid(feature, var));
- if(_p[feature].vars[var].width)
+ if (_p[feature].vars[var].width)
return _p[feature].vars[var].width;
else
return globvars[var].width & ~0x40;
}
-uint Check2v::GetEffFeature(uint feature,uint type){
- if((type&3)==2)return Instance()._p[feature].featfor82;
+uint Check2v::GetEffFeature(uint feature, uint type)
+{
+ if ((type & 3) == 2) return Instance()._p[feature].featfor82;
return feature;
}
-void Check2v::Check(uint feature,uint var,uint offs,uint param,uint shift)const{
- if(feature>MaxFeature())return;
- uint real_var=var;
- if(real_var==0x7B){
- var=param;
- if(var<0x60 || var>=0x80) IssueMessage(WARNING1,INDIRECT_VAR_NOT_6X,offs);
+void Check2v::Check(uint feature, uint var, uint offs, uint param, uint shift) const
+{
+ if (feature > MaxFeature()) return;
+ uint real_var = var;
+ if (real_var == 0x7B) {
+ var = param;
+ if (var < 0x60 || var >= 0x80) IssueMessage(WARNING1, INDIRECT_VAR_NOT_6X, offs);
}
- if(var&0x80){
- if(var>_p[feature].last80) IssueMessage(ERROR,NONEXISTANT_VARIABLE,offs,var);
- else if(!IsValid(feature, var)) IssueMessage(WARNING1,NONEXISTANT_VARIABLE,offs,var);
- else if(shift>=_p[feature].var80[var&0x7F].width<<3)IssueMessage(WARNING4,SHIFT_TOO_FAR,offs+1,var);
- }else if(!IsValid(feature,var))
- IssueMessage(WARNING1,NONEXISTANT_VARIABLE,offs,var);
- else{
- if(var==0x7E){
- if(real_var==0x7B){
- IssueMessage(ERROR,INDIRECT_VAR_7E,offs);
+ if (var & 0x80) {
+ if (var > _p[feature].last80)
+ IssueMessage(ERROR, NONEXISTANT_VARIABLE, offs, var);
+ else if (!IsValid(feature, var))
+ IssueMessage(WARNING1, NONEXISTANT_VARIABLE, offs, var);
+ else if (shift >= _p[feature].var80[var & 0x7F].width << 3)
+ IssueMessage(WARNING4, SHIFT_TOO_FAR, offs + 1, var);
+ } else if (!IsValid(feature, var))
+ IssueMessage(WARNING1, NONEXISTANT_VARIABLE, offs, var);
+ else {
+ if (var == 0x7E) {
+ if (real_var == 0x7B) {
+ IssueMessage(ERROR, INDIRECT_VAR_7E, offs);
return;
}
- act123::IDarray&IDs=act123::Instance().defined2IDs;
- if(!IDs.is_defined(param)) IssueMessage(ERROR,UNDEFINED_ID,offs+1,param);
- else{
- if(IDs.GetFeature(param)!=feature)
- IssueMessage(WARNING1,FEATURE_CALL_MISMATCH,offs+1,param,IDs.GetFeature(param));
+ act123::IDarray& IDs = act123::Instance().defined2IDs;
+ if (!IDs.is_defined(param))
+ IssueMessage(ERROR, UNDEFINED_ID, offs + 1, param);
+ else {
+ if (IDs.GetFeature(param) != feature)
+ IssueMessage(WARNING1, FEATURE_CALL_MISMATCH, offs + 1, param, IDs.GetFeature(param));
IDs.use(param);
}
- }else if(var>=0x60 && real_var!=0x7B && param>MaxParam(feature,var))
- IssueMessage(WARNING1,PARAM_TOO_LARGE,offs+1,param,var);
- if(shift>=GetWidth(feature, var)<<3)IssueMessage(WARNING1,SHIFT_TOO_FAR,offs+2,var);
+ } else if (var >= 0x60 && real_var != 0x7B && param > MaxParam(feature, var))
+ IssueMessage(WARNING1, PARAM_TOO_LARGE, offs + 1, param, var);
+ if (shift >= GetWidth(feature, var) << 3) IssueMessage(WARNING1, SHIFT_TOO_FAR, offs + 2, var);
}
}
-uint Check2v::Prohibit0Mask(uint var){
+uint Check2v::Prohibit0Mask(uint var)
+{
return !(CInstance().globvars[var].width & 0x40);
}
@@ -177,43 +196,43 @@
// Check2v::VarData
//****************************************
-int Check2v::VarData::Load(FILE*pFile){
+int Check2v::VarData::Load(FILE* pFile)
+{
uint var;
- var=GetCheckByte(2v);
- if((width=GetCheckByte(2v))==0xF0&&var==0xFF)
- return-1;
- if(!(width&0x7F))return var;
- assert(width&0x80);
+ var = GetCheckByte(2v);
+ if ((width = GetCheckByte(2v)) == 0xF0 && var == 0xFF) return -1;
+ if (!(width & 0x7F)) return var;
+ assert(width & 0x80);
/* //Read lots of currently unused bytes.
- CHECK_EOF(min);
- if(min==0xFF){
- uint type;
- bool done=false;
- while(!done){
- CHECK_EOF(type);
- switch(type){
- case'-':
- fgetc(pFile);
- case '+':
- fgetc(pFile);
- break;
- case 'x':
- done=true;
- break;
- DEFAULT(Checkv2::VarData::Init,type);
- }
- }
- }else{
- for(;i>0;i--)
- min|=fgetc(pFile)<<(i*8);//ignore EOF--I'll catch that later
- CHECK_EOF(max);
- for(i=temp.width;i>0;i--)
- max|=fgetc(pFile)<<(i*8);//ignore EOF--I'll catch that later
- }
+ CHECK_EOF(min);
+ if(min==0xFF){
+ uint type;
+ bool done=false;
+ while(!done){
+ CHECK_EOF(type);
+ switch(type){
+ case'-':
+ fgetc(pFile);
+ case '+':
+ fgetc(pFile);
+ break;
+ case 'x':
+ done=true;
+ break;
+ DEFAULT(Checkv2::VarData::Init,type);
+ }
+ }
+ }else{
+ for(;i>0;i--)
+ min|=fgetc(pFile)<<(i*8);//ignore EOF--I'll catch that later
+ CHECK_EOF(max);
+ for(i=temp.width;i>0;i--)
+ max|=fgetc(pFile)<<(i*8);//ignore EOF--I'll catch that later
+ }
}
*/
- width&=0x7F;
- if((var&0xE0)==0x60)maxparam=GetCheckByte(2v);
+ width &= 0x7F;
+ if ((var & 0xE0) == 0x60) maxparam = GetCheckByte(2v);
return var;
}
@@ -221,207 +240,222 @@
// varRange
//****************************************
-const uint varRange::rangemax[]={0,0xFF,0xFFFF,0,0xFFFFFFFF};
+const uint varRange::rangemax[] = {0, 0xFF, 0xFFFF, 0, 0xFFFFFFFF};
-varRange::varRange(uint width):dflt(rangemax[width]),num(0),width(width){
- VERIFY(width&&width<5&&width!=3,width);
+varRange::varRange(uint width) : dflt(rangemax[width]), num(0), width(width)
+{
+ VERIFY(width && width < 5 && width != 3, width);
}
-void varRange::UpdateRange(uint Var,uint op,uint shift,const PseudoSprite&data,uint&offs){
- uint add,divmod,nAnd=data.ExtractVariable(offs,width);
- if(Check2v::Prohibit0Mask(Var) && !nAnd)IssueMessage(WARNING1,AND_00,offs);
- offs+=width;
- range var(rangemax[width],0,(0xFFFFFFFF>>shift)&nAnd);
- if(shift&0xC0){
- add=data.ExtractVariable(offs,width);
- divmod=data.ExtractVariable(offs+=width,width);
- if(divmod){
- if((var.min+=add).LastOpOverflow()||(var.max+=add).LastOpOverflow()){
- var.min=0;
- var.max=rangemax[width];
+void varRange::UpdateRange(uint Var, uint op, uint shift, const PseudoSprite& data, uint& offs)
+{
+ uint add, divmod, nAnd = data.ExtractVariable(offs, width);
+ if (Check2v::Prohibit0Mask(Var) && !nAnd) IssueMessage(WARNING1, AND_00, offs);
+ offs += width;
+ range var(rangemax[width], 0, (0xFFFFFFFF >> shift) & nAnd);
+ if (shift & 0xC0) {
+ add = data.ExtractVariable(offs, width);
+ divmod = data.ExtractVariable(offs += width, width);
+ if (divmod) {
+ if ((var.min += add).LastOpOverflow() || (var.max += add).LastOpOverflow()) {
+ var.min = 0;
+ var.max = rangemax[width];
}
- if(shift&0x80){// %
- var.min=0;
- var.max=min<uint>(var.max,divmod-1);
- add%=divmod;
- }else{// /
- var.min/=divmod;
- var.max/=divmod;
+ if (shift & 0x80) { // %
+ var.min = 0;
+ var.max = min<uint>(var.max, divmod - 1);
+ add %= divmod;
+ } else { // /
+ var.min /= divmod;
+ var.max /= divmod;
}
- if(!add&&!(divmod&(divmod-1)))
- IssueMessage(WARNING2,USE_SHIFT_AND,offs-3*width);
- }else{
- var.min=0;
- var.max=rangemax[width];
- IssueMessage(ERROR,DIVIDE_BY_ZERO,offs);
+ if (!add && !(divmod & (divmod - 1))) IssueMessage(WARNING2, USE_SHIFT_AND, offs - 3 * width);
+ } else {
+ var.min = 0;
+ var.max = rangemax[width];
+ IssueMessage(ERROR, DIVIDE_BY_ZERO, offs);
}
- offs+=width;
+ offs += width;
}
- assert(var.min<=var.max);
- assert(dflt.min<=dflt.max);
- switch(op){
- case(uint)-1://First run
- case 0xF:// Discard left
- dflt=var;
- case 0xE:// Store
- case 0x10://Persistent store
- break;
- case 0:// +
- case 0xC:// |
- case 0xD:// ^
- if((dflt.min+=var.min).LastOpOverflow()||(dflt.max+=var.max).LastOpOverflow()){
- dflt.min=0;
- dflt.max=rangemax[width];
- }
- break;
- case 1:// -
- if((dflt.min-=var.max).LastOpOverflow()||(dflt.max-=var.min).LastOpOverflow()){
- dflt.min=0;
- dflt.max=rangemax[width];
- }
- break;
- case 2:case 3:case 6:case 7://SIGNED min,max,/,%
- dflt.min=0;
- dflt.max=rangemax[width];
- //TODO: signed op support
- break;
- case 4:// min
- case 0xB:// &
- dflt.min=min(dflt.min,var.min);
- dflt.max=min(dflt.max,var.max);
- break;
- case 5:// max
- dflt.min=max(dflt.min,var.min);
- dflt.max=max(dflt.max,var.max);
- case 8:// /
- if(var.min==0){
- dflt.min=0;
- dflt.max=rangemax[width];
- }else{
- dflt.min/=var.max;
- dflt.max/=var.min;
- }
- break;
- case 9:// %
- dflt.min=0;
- dflt.max=var.max;
- break;
- case 0xA:// *
- if((dflt.min*=var.min).LastOpOverflow()||(dflt.max*=var.max).LastOpOverflow()){
- var.min=0;
- var.max=rangemax[width];
- }
- break;
- case 0x12:case 0x13: // <=>
- dflt.min=0;
- dflt.max=2;
- break;
- case 0x11: // ROR
- case 0x14: // SHL
- case 0x15: // SHR
- case 0x16: // SAR
- default:
- dflt.min=0;
- dflt.max=rangemax[width];
+ assert(var.min <= var.max);
+ assert(dflt.min <= dflt.max);
+ switch (op) {
+ case(uint) - 1: // First run
+ case 0xF: // Discard left
+ dflt = var;
+ case 0xE: // Store
+ case 0x10: // Persistent store
+ break;
+ case 0: // +
+ case 0xC: // |
+ case 0xD: // ^
+ if ((dflt.min += var.min).LastOpOverflow() || (dflt.max += var.max).LastOpOverflow()) {
+ dflt.min = 0;
+ dflt.max = rangemax[width];
+ }
+ break;
+ case 1: // -
+ if ((dflt.min -= var.max).LastOpOverflow() || (dflt.max -= var.min).LastOpOverflow()) {
+ dflt.min = 0;
+ dflt.max = rangemax[width];
+ }
+ break;
+ case 2:
+ case 3:
+ case 6:
+ case 7: // SIGNED min,max,/,%
+ dflt.min = 0;
+ dflt.max = rangemax[width];
+ // TODO: signed op support
+ break;
+ case 4: // min
+ case 0xB: // &
+ dflt.min = min(dflt.min, var.min);
+ dflt.max = min(dflt.max, var.max);
+ break;
+ case 5: // max
+ dflt.min = max(dflt.min, var.min);
+ dflt.max = max(dflt.max, var.max);
+ case 8: // /
+ if (var.min == 0) {
+ dflt.min = 0;
+ dflt.max = rangemax[width];
+ } else {
+ dflt.min /= var.max;
+ dflt.max /= var.min;
+ }
+ break;
+ case 9: // %
+ dflt.min = 0;
+ dflt.max = var.max;
+ break;
+ case 0xA: // *
+ if ((dflt.min *= var.min).LastOpOverflow() || (dflt.max *= var.max).LastOpOverflow()) {
+ var.min = 0;
+ var.max = rangemax[width];
+ }
+ break;
+ case 0x12:
+ case 0x13: // <=>
+ dflt.min = 0;
+ dflt.max = 2;
+ break;
+ case 0x11: // ROR
+ case 0x14: // SHL
+ case 0x15: // SHR
+ case 0x16: // SAR
+ default:
+ dflt.min = 0;
+ dflt.max = rangemax[width];
}
}
-void varRange::AddRange(uint min,uint max){
- AddRangeInternal(min,max,UNREACHABLE_VAR);
+void varRange::AddRange(uint min, uint max)
+{
+ AddRangeInternal(min, max, UNREACHABLE_VAR);
num++;
}
-void varRange::CheckDefault(){
- num=-1;
- AddRangeInternal(dflt.min,dflt.max,UNREACHABLE_DEFAULT);
+void varRange::CheckDefault()
+{
+ num = -1;
+ AddRangeInternal(dflt.min, dflt.max, UNREACHABLE_DEFAULT);
}
-void varRange::AddRangeInternal(uint min,uint max,RenumMessageId unreachable){
- bool obscured=false,repeat;
- do{
- repeat=false;
- for(int i=0;i<(int)ranges.size();i++){
- if(min>=ranges[i].min&&min<=ranges[i].max){
- if(ranges[i].max>=dflt.max){
- IssueMessage(WARNING1,unreachable,num);
+void varRange::AddRangeInternal(uint min, uint max, RenumMessageId unreachable)
+{
+ bool obscured = false, repeat;
+ do {
+ repeat = false;
+ for (int i = 0; i < (int)ranges.size(); i++) {
+ if (min >= ranges[i].min && min <= ranges[i].max) {
+ if (ranges[i].max >= dflt.max) {
+ IssueMessage(WARNING1, unreachable, num);
return;
}
- repeat=obscured=true;
- min=ranges[i].max+1;
+ repeat = obscured = true;
+ min = ranges[i].max + 1;
}
- if(max>=ranges[i].min&&max<=ranges[i].max){
- if(ranges[i].min<=dflt.min){
- IssueMessage(WARNING1,unreachable,num);
+ if (max >= ranges[i].min && max <= ranges[i].max) {
+ if (ranges[i].min <= dflt.min) {
+ IssueMessage(WARNING1, unreachable, num);
return;
}
- repeat=obscured=true;
- max=ranges[i].min-1;
+ repeat = obscured = true;
+ max = ranges[i].min - 1;
}
- if(min>max){
- IssueMessage(WARNING1,unreachable,num);
+ if (min > max) {
+ IssueMessage(WARNING1, unreachable, num);
return;
}
}
- }while(repeat);
- if(obscured&&num!=-1)
- IssueMessage(WARNING2,OBSCURED_VARIATION,num);
- ranges.push_back(range((uint)-1,min,max));
+ } while (repeat);
+ if (obscured && num != -1) IssueMessage(WARNING2, OBSCURED_VARIATION, num);
+ ranges.push_back(range((uint) - 1, min, max));
}
//****************************************
// rand2
//****************************************
-rand2::rand2(){
- FILE*pFile=myfopen(2r);
- _p=new rand2info[MaxFeature()+1];
- for(uint i=0;i<=MaxFeature();i++){
- _p[i].bits[0]=fgetc(pFile);
- _p[i].bits[1]=fgetc(pFile);
- _p[i].numtriggers=fgetc(pFile);
+rand2::rand2()
+{
+ FILE* pFile = myfopen(2r);
+ _p = new rand2info[MaxFeature() + 1];
+ for (uint i = 0; i <= MaxFeature(); i++) {
+ _p[i].bits[0] = fgetc(pFile);
+ _p[i].bits[1] = fgetc(pFile);
+ _p[i].numtriggers = fgetc(pFile);
}
- CheckEOF(_p[MaxFeature()].numtriggers,2r);
+ CheckEOF(_p[MaxFeature()].numtriggers, 2r);
fclose(pFile);
}
-void rand2::CheckRand(uint feat,uint type,uint triggers,uint first,uint nrand){
- if(feat>MaxFeature())return;
- type&=1;
- uint bits=0;
- while(nrand>>=1)bits++;
- if(first>_p[feat].bits[type])IssueMessage(ERROR,OUT_OF_RANGE_BITS,5,_p[feat].bits[type]);
- else if(first+bits>_p[feat].bits[type])IssueMessage(ERROR,OUT_OF_RANGE_BITS,6,_p[feat].bits[type]);
- triggers&=0x7F;
- if(triggers>>_p[feat].numtriggers)IssueMessage(WARNING1,UNDEFINED_TRIGGER);
+void rand2::CheckRand(uint feat, uint type, uint triggers, uint first, uint nrand)
+{
+ if (feat > MaxFeature()) return;
+ type &= 1;
+ uint bits = 0;
+ while (nrand >>= 1) bits++;
+ if (first > _p[feat].bits[type])
+ IssueMessage(ERROR, OUT_OF_RANGE_BITS, 5, _p[feat].bits[type]);
+ else if (first + bits > _p[feat].bits[type])
+ IssueMessage(ERROR, OUT_OF_RANGE_BITS, 6, _p[feat].bits[type]);
+ triggers &= 0x7F;
+ if (triggers >> _p[feat].numtriggers) IssueMessage(WARNING1, UNDEFINED_TRIGGER);
}
//****************************************
// Define2
//****************************************
-Define2::~Define2(){
- if(act123::CInstance().defined2IDs.is_defined(id)&&!act123::CInstance().defined2IDs.is_used(id))
- IssueMessage(WARNING1,UNUSED_ID,id,act123::CInstance().defined2IDs.defined_at(id));
- act123::Instance().defined2IDs.define(feature,id,checks1C);
+Define2::~Define2()
+{
+ if (act123::CInstance().defined2IDs.is_defined(id) && !act123::CInstance().defined2IDs.is_used(id))
+ IssueMessage(WARNING1, UNUSED_ID, id, act123::CInstance().defined2IDs.defined_at(id));
+ act123::Instance().defined2IDs.define(feature, id, checks1C);
}
-void Define2::ChangeFeature(uint feat){
- feature=feat;
+void Define2::ChangeFeature(uint feat)
+{
+ feature = feat;
}
//****************************************
// Callbacks
//****************************************
-Callbacks::Callbacks(){
- FILE*pFile=myfopen(callbacks);
- _p=new uint[numcallbacks=GetCheckWord(callbacks)];
- for(uint i=0;i<numcallbacks;i++){
- uint temp=GetCheckByte(callbacks);
- if(temp==0x7F)
- temp = GetCheckWord(callbacks) | (1<<31);
- else if(temp&0x80)temp ^= (1<<31 | 0x80);
- _p[i]=temp;
+Callbacks::Callbacks()
+{
+ FILE* pFile = myfopen(callbacks);
+ _p = new uint[numcallbacks = GetCheckWord(callbacks)];
+ for (uint i = 0; i < numcallbacks; i++) {
+ uint temp = GetCheckByte(callbacks);
+ if (temp == 0x7F)
+ temp = GetCheckWord(callbacks) | (1 << 31);
+ else if (temp & 0x80)
+ temp ^= (1 << 31 | 0x80);
+ _p[i] = temp;
}
fclose(pFile);
}
@@ -430,26 +464,32 @@
// GLOBAL FUNCTIONS
//****************************************
-void sanity_use_id(int id){
+void sanity_use_id(int id)
+{
act123::Instance().defined2IDs.use(id);
}
-void sanity_use_set(int set){
+void sanity_use_set(int set)
+{
act123::Instance().act1.use(set);
}
-void sanity_test_id(int id){
- act123::Instance().defined2IDs.test(0,id&0xFF);
+void sanity_test_id(int id)
+{
+ act123::Instance().defined2IDs.test(0, id & 0xFF);
}
-int sanity_locate_id(int id){
- return act123::Instance().defined2IDs.defined_at(id&0xFF);
+int sanity_locate_id(int id)
+{
+ return act123::Instance().defined2IDs.defined_at(id & 0xFF);
}
-void sanity_define_id(int feature,int id){
- act123::Instance().defined2IDs.define(feature,id&0xFF,true);
+void sanity_define_id(int feature, int id)
+{
+ act123::Instance().defined2IDs.define(feature, id & 0xFF, true);
}
-int sanity_get_feature(int id){
+int sanity_get_feature(int id)
+{
return act123::Instance().defined2IDs.GetFeature(id);
}
diff --git a/src/act14.cpp b/src/act14.cpp
--- a/src/act14.cpp
+++ b/src/act14.cpp
@@ -19,25 +19,25 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
-#include<cassert>
-#include<sstream>
+#include <string>
+#include <cassert>
+#include <sstream>
using namespace std;
-#include"nforenum.h"
-#include"pseudo.h"
-#include"messages.h"
-#include"strings.h"
-#include"command.h"
+#include "nforenum.h"
+#include "pseudo.h"
+#include "messages.h"
+#include "strings.h"
+#include "command.h"
-static bool Check14(PseudoSprite&data, uint&offset, vector<uint>&idstack)
+static bool Check14(PseudoSprite& data, uint& offset, vector<uint>& idstack)
{
/* NFORenum reads the NFO, which is a text file. As per definition the
* NFO is LE ordered. If characters are interpreted as bytes they will
* therefore be read in LE order. ExtractDword does interpret the
- * characters as bytes and construct a host endian ordered integer.
- * Consequently, there is no need to swap endian for the read data; it
+ * characters as bytes and construct a host endian ordered integer.
+ * Consequently, there is no need to swap endian for the read data; it
* will always be in the host order, or the constant below as long as
* they have the expected integer value, thus reverse due to LE. */
static const uint ID_INFO = 0x4F464E49; // INFO in reverse order (LE)
@@ -72,11 +72,12 @@
extern uint _act14_pal;
uint size = data.ExtractWord(offset);
offset += 2;
- if (idstack.size()==2 && idstack[0]==ID_INFO && idstack[1]==ID_PALS) {
- uint pal=data.ExtractByte(offset);
- if (size==1 && (pal=='D' || pal=='W' || pal=='A')) {
- _act14_pal=pal;
- } else IssueMessage(ERROR, INVALID_PALETTE_INFO, offset);
+ if (idstack.size() == 2 && idstack[0] == ID_INFO && idstack[1] == ID_PALS) {
+ uint pal = data.ExtractByte(offset);
+ if (size == 1 && (pal == 'D' || pal == 'W' || pal == 'A')) {
+ _act14_pal = pal;
+ } else
+ IssueMessage(ERROR, INVALID_PALETTE_INFO, offset);
}
offset += size;
break;
@@ -92,9 +93,9 @@
return true;
}
-void Check14(PseudoSprite&data)
+void Check14(PseudoSprite& data)
{
- vector<uint>idstack;
+ vector<uint> idstack;
uint offset = 1;
Check14(data, offset, idstack);
}
diff --git a/src/act5.cpp b/src/act5.cpp
--- a/src/act5.cpp
+++ b/src/act5.cpp
@@ -19,52 +19,62 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
-#include<fstream>
-#include<cassert>
-#include<errno.h>
+#include <string>
+#include <fstream>
+#include <cassert>
+#include <errno.h>
using namespace std;
-#include"nforenum.h"
-#include"sanity.h"
-#include"inlines.h"
-#include"ExpandingArray.h"
-#include"sanity_defines.h"
-#include"data.h"
-#include"pseudo.h"
-#include"messages.h"
-#include"command.h"
+#include "nforenum.h"
+#include "sanity.h"
+#include "inlines.h"
+#include "ExpandingArray.h"
+#include "sanity_defines.h"
+#include "data.h"
+#include "pseudo.h"
+#include "messages.h"
+#include "command.h"
extern bool _base_grf;
-class c5{
-public:
- int maxFeature(){return (int)sizes.size()+3;}
- const vector<int>&operator[](int x)const {return sizes[x-4];}
+class c5
+{
+ public:
+ int maxFeature()
+ {
+ return (int)sizes.size() + 3;
+ }
+ const vector<int>& operator[](int x) const
+ {
+ return sizes[x - 4];
+ }
SINGLETON(c5)
-private:
- vector<vector<int> >sizes;
+ private:
+ vector<vector<int> > sizes;
};
-c5::c5(){
- FILE*pFile=myfopen(5);
+c5::c5()
+{
+ FILE* pFile = myfopen(5);
vector<int> temp;
int ch, count, opts, flags;
- while((ch=GetCheckByte(5))!=0){
+ while ((ch = GetCheckByte(5)) != 0) {
flags = 0;
- if(ch&0x80){
- flags = ch&0x7F;
- ch=GetCheckByte(5);
+ if (ch & 0x80) {
+ flags = ch & 0x7F;
+ ch = GetCheckByte(5);
}
- count = ch>>4;
- opts = ch&0xF;
- for(int i=count;i;i--){
+ count = ch >> 4;
+ opts = ch & 0xF;
+ for (int i = count; i; i--) {
temp.clear();
temp.push_back(flags);
- for(int j=opts;j;j--)
- if(flags&4) temp.push_back(GetCheckWord(5));
- else temp.push_back(GetCheckByte(5));
+ for (int j = opts; j; j--)
+ if (flags & 4)
+ temp.push_back(GetCheckWord(5));
+ else
+ temp.push_back(GetCheckByte(5));
sizes.push_back(temp);
}
}
@@ -73,56 +83,58 @@
// I finally want to do runtime-generated varargs calls.
// But I can't, so I have to manually generate the string instead.
-void Act5CountWarn(const vector<int>&sizes){
- string str = mysprintf("%S",ACT5_SIZE, sizes[1], sizes[1]);
- int count=(int)sizes.size()-1;
- switch(count){
- case 1:
- break;
- default:
- for(int i=2;i<count;i++)
- str += ", "+mysprintf("%S",ACT5_SIZE, sizes[i], sizes[i]);
- str+=",";
- //fallthrough
- case 2:
- str += mysprintf("%S",ACT5_ORSIZE, sizes[count], sizes[count]);
+void Act5CountWarn(const vector<int>& sizes)
+{
+ string str = mysprintf("%S", ACT5_SIZE, sizes[1], sizes[1]);
+ int count = (int)sizes.size() - 1;
+ switch (count) {
+ case 1:
+ break;
+ default:
+ for (int i = 2; i < count; i++) str += ", " + mysprintf("%S", ACT5_SIZE, sizes[i], sizes[i]);
+ str += ",";
+ // fallthrough
+ case 2:
+ str += mysprintf("%S", ACT5_ORSIZE, sizes[count], sizes[count]);
}
IssueMessage(WARNING1, ACTION_5, str.c_str());
}
-int Check5(PseudoSprite&data,sanstate&state){
- int feature=data.ExtractByte(1);
- bool hasoffset = (feature&0x80)!=0;
- feature&=0x7F;
- int sprites=data.ExtractExtended(2);
- uint off=2+data.ExtendedLen(2);
- state=FIND_REAL_OR_RECOLOR;
- if(feature<4||feature>c5::Instance().maxFeature()){
- IssueMessage(FATAL,INVALID_FEATURE);
+int Check5(PseudoSprite& data, sanstate& state)
+{
+ int feature = data.ExtractByte(1);
+ bool hasoffset = (feature & 0x80) != 0;
+ feature &= 0x7F;
+ int sprites = data.ExtractExtended(2);
+ uint off = 2 + data.ExtendedLen(2);
+ state = FIND_REAL_OR_RECOLOR;
+ if (feature < 4 || feature > c5::Instance().maxFeature()) {
+ IssueMessage(FATAL, INVALID_FEATURE);
return sprites;
}
- const vector<int>&expSprites=c5::Instance()[feature];
- if(!hasoffset){
- for(int i=(int)expSprites.size();--i;){ // Test [1] ... [.size()-1]
- if(expSprites[i] == 0)goto countok;
- if(expSprites[i] == sprites)goto countok;
+ const vector<int>& expSprites = c5::Instance()[feature];
+ if (!hasoffset) {
+ for (int i = (int)expSprites.size(); --i;) { // Test [1] ... [.size()-1]
+ if (expSprites[i] == 0) goto countok;
+ if (expSprites[i] == sprites) goto countok;
}
/* A base GRF may provide 10 sprites for shores. */
- if(_base_grf && feature == 0x0D && sprites == 0x0A)goto countok;
+ if (_base_grf && feature == 0x0D && sprites == 0x0A) goto countok;
/* Having more sprites is generally okay for base GRFs as they are then more up-to-date than NFORenum. */
- if(_base_grf && feature == 0x15 && sprites > expSprites[0])goto countok;
+ if (_base_grf && feature == 0x15 && sprites > expSprites[0]) goto countok;
Act5CountWarn(expSprites);
- }else{
- if(!(expSprites[0]&8))
- IssueMessage(ERROR,CANNOT_EXTEND);
- int pastend=sprites + data.ExtractExtended(off);
- off+=data.ExtendedLen(off);
- if(expSprites[1] != 0 && expSprites[1] < pastend)
- IssueMessage(WARNING1, ACTION_5_LIMIT, sprites, pastend-1, expSprites[1]);
+ } else {
+ if (!(expSprites[0] & 8)) IssueMessage(ERROR, CANNOT_EXTEND);
+ int pastend = sprites + data.ExtractExtended(off);
+ off += data.ExtendedLen(off);
+ if (expSprites[1] != 0 && expSprites[1] < pastend)
+ IssueMessage(WARNING1, ACTION_5_LIMIT, sprites, pastend - 1, expSprites[1]);
}
countok:
- if(off<data.Length())IssueMessage(WARNING2,EXTRA_DATA,data.Length(),off);
- if(expSprites[0]&1)state=FIND_RECOLOR;
- else if(!(expSprites[0]&2))state=FIND_REAL;
+ if (off < data.Length()) IssueMessage(WARNING2, EXTRA_DATA, data.Length(), off);
+ if (expSprites[0] & 1)
+ state = FIND_RECOLOR;
+ else if (!(expSprites[0] & 2))
+ state = FIND_REAL;
return sprites;
}
diff --git a/src/act6.cpp b/src/act6.cpp
--- a/src/act6.cpp
+++ b/src/act6.cpp
@@ -19,42 +19,46 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
-#include<cassert>
+#include <string>
+#include <cassert>
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"sanity.h"
-#include"messages.h"
-#include"pseudo.h"
-#include"command.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "sanity.h"
+#include "messages.h"
+#include "pseudo.h"
+#include "command.h"
-uint Check6(PseudoSprite&data){
- assert(data.ExtractByte(0)==0x06);
- uint ofs=1,minlen=0;
- bool canCorrect=true;
- try{
- while(data.ExtractByte(ofs++)!=0xFF){
- canCorrect=false;
- int num=data.ExtractByte(ofs++)&0x7F;
- if(num)minlen=std::max(minlen,num+data.ExtractExtended(ofs));
- else IssueMessage(WARNING1,DOES_NOT_MODIFY,ofs-1);
- ofs+=data.ExtendedLen(ofs);
- canCorrect=true;
+uint Check6(PseudoSprite& data)
+{
+ assert(data.ExtractByte(0) == 0x06);
+ uint ofs = 1, minlen = 0;
+ bool canCorrect = true;
+ try
+ {
+ while (data.ExtractByte(ofs++) != 0xFF) {
+ canCorrect = false;
+ int num = data.ExtractByte(ofs++) & 0x7F;
+ if (num)
+ minlen = std::max(minlen, num + data.ExtractExtended(ofs));
+ else
+ IssueMessage(WARNING1, DOES_NOT_MODIFY, ofs - 1);
+ ofs += data.ExtendedLen(ofs);
+ canCorrect = true;
}
- if(ofs==2)
- IssueMessage(WARNING1,NO_MODIFICATIONS);
- if(ofs!=data.Length())
- IssueMessage(WARNING2,EXTRA_DATA,data.Length(),ofs);
- }catch(...){
- if(_autocorrect&&canCorrect){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECT_ADD,0xFF);
+ if (ofs == 2) IssueMessage(WARNING1, NO_MODIFICATIONS);
+ if (ofs != data.Length()) IssueMessage(WARNING2, EXTRA_DATA, data.Length(), ofs);
+ }
+ catch (...)
+ {
+ if (_autocorrect && canCorrect) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECT_ADD, 0xFF);
data.Append(0xFF);
- }else{
- IssueMessage(FATAL,UNTERM_ACT6);
+ } else {
+ IssueMessage(FATAL, UNTERM_ACT6);
}
}
return minlen;
diff --git a/src/act79D.cpp b/src/act79D.cpp
--- a/src/act79D.cpp
+++ b/src/act79D.cpp
@@ -19,183 +19,216 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
-#include<cassert>
-#include<fstream>
-#include<errno.h>
+#include <string>
+#include <cassert>
+#include <fstream>
+#include <errno.h>
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"messages.h"
-#include"sanity_defines.h"
-#include"data.h"
-#include"pseudo.h"
-#include"command.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "messages.h"
+#include "sanity_defines.h"
+#include "data.h"
+#include "pseudo.h"
+#include "command.h"
uint numvars;
-class Vars{
-public:
- bool canRead7(uint v){return(v<0x80||(v<numvars&&_p[v&0x7F]&0x80));}
- bool canReadD(uint v){return(v<0x80||v==0xFF||(v<numvars&&_p[v&0x7F]&0x40));}
- bool canWriteD(uint v){return(v<0x80||(v<numvars&&_p[v&0x7F]&0x20));}
- bool isBitmask(uint v){return(v<numvars&&_p[v&0x7F]&7)==0;}
- bool lenOK(uint v,uint len){
- if(len==4)len--;
- return(_p[v&0x7F]&(1<<(len-1)))!=0;
+class Vars
+{
+ public:
+ bool canRead7(uint v)
+ {
+ return (v < 0x80 || (v < numvars && _p[v & 0x7F] & 0x80));
+ }
+ bool canReadD(uint v)
+ {
+ return (v < 0x80 || v == 0xFF || (v < numvars && _p[v & 0x7F] & 0x40));
+ }
+ bool canWriteD(uint v)
+ {
+ return (v < 0x80 || (v < numvars && _p[v & 0x7F] & 0x20));
+ }
+ bool isBitmask(uint v)
+ {
+ return (v < numvars && _p[v & 0x7F] & 7) == 0;
+ }
+ bool lenOK(uint v, uint len)
+ {
+ if (len == 4) len--;
+ return (_p[v & 0x7F] & (1 << (len - 1))) != 0;
}
AUTO_ARRAY(uchar)
SINGLETON(Vars)
};
-class D:public Guintp{
-public:
- uint maxpatchvar,maxop;
+class D : public Guintp
+{
+ public:
+ uint maxpatchvar, maxop;
SINGLETON(D)
};
-Vars::Vars(){
- FILE*pFile=myfopen(79Dv);
- _p=new uchar[numvars=GetCheckByte(79Dv)];
- myfread(_p,numvars,79Dv);
+Vars::Vars()
+{
+ FILE* pFile = myfopen(79Dv);
+ _p = new uchar[numvars = GetCheckByte(79Dv)];
+ myfread(_p, numvars, 79Dv);
fclose(pFile);
- numvars|=0x80;
+ numvars |= 0x80;
}
-D::D(){
- FILE*pFile=myfopen(D);
- maxpatchvar=GetCheckByte(D);
- maxop=GetCheckByte(D);
- _p=new uint[MaxFeature()+1];
- for(uint i=0;i<=MaxFeature();i++)
- _p[i]=GetCheckWord(D);
+D::D()
+{
+ FILE* pFile = myfopen(D);
+ maxpatchvar = GetCheckByte(D);
+ maxop = GetCheckByte(D);
+ _p = new uint[MaxFeature() + 1];
+ for (uint i = 0; i <= MaxFeature(); i++) _p[i] = GetCheckWord(D);
fclose(pFile);
}
-#define SetSize(x)\
- if(desiredSize!=x)desiredSize=0;\
- else(void(0))
+#define SetSize(x) \
+ if (desiredSize != x) \
+ desiredSize = 0; \
+ else \
+ (void(0))
-#define CheckSize(var)\
- if(!Vars::Instance().lenOK(var,desiredSize)) desiredSize=0;\
- else(void(0))
+#define CheckSize(var) \
+ if (!Vars::Instance().lenOK(var, desiredSize)) \
+ desiredSize = 0; \
+ else \
+ (void(0))
-struct act7{
+struct act7
+{
act7();
- act7(uint act,uint skips):act(act),spriteno(_spritenum),skips(skips){}
- uint act,spriteno,skips;
+ act7(uint act, uint skips) : act(act), spriteno(_spritenum), skips(skips)
+ {
+ }
+ uint act, spriteno, skips;
};
-static vector<act7>jumps;
+static vector<act7> jumps;
-int Check7(PseudoSprite&data){
- uint desiredSize=data.Length()-5;
+int Check7(PseudoSprite& data)
+{
+ uint desiredSize = data.Length() - 5;
data.SetAllHex();
- uint var=data.ExtractByte(1),var_size=data.ExtractByte(2),cond=data.ExtractByte(3);
+ uint var = data.ExtractByte(1), var_size = data.ExtractByte(2), cond = data.ExtractByte(3);
data.SetOpByte(3, '7');
- if(cond>0xE)IssueMessage(ERROR,BAD_CONDITION,cond);
- else if(cond>5&&cond<0xB){
- if(var!=0x88){
- IssueMessage(ERROR,GRFCOND_NEEDS_GRFVAR,cond);
- desiredSize=0;
+ if (cond > 0xE)
+ IssueMessage(ERROR, BAD_CONDITION, cond);
+ else if (cond > 5 && cond < 0xB) {
+ if (var != 0x88) {
+ IssueMessage(ERROR, GRFCOND_NEEDS_GRFVAR, cond);
+ desiredSize = 0;
}
data.SetGRFID(4);
- }else if(cond>0xA){
- data.SetText(4,4);
+ } else if (cond > 0xA) {
+ data.SetText(4, 4);
SetSize(4);
}
- if(cond<6&&var==0x88){
- IssueMessage(ERROR,GRFVAR_NEEDS_GRFCOND);
- desiredSize=0;
+ if (cond < 6 && var == 0x88) {
+ IssueMessage(ERROR, GRFVAR_NEEDS_GRFCOND);
+ desiredSize = 0;
}
- if(cond<2){
+ if (cond < 2) {
SetSize(1);
- var_size=1;
+ var_size = 1;
}
- if(!Vars::Instance().canRead7(var))IssueMessage(ERROR,NONEXISTANT_VARIABLE,1,var);
- else if(var>0x7F&&cond>1&&Vars::Instance().isBitmask(var)){
- IssueMessage(ERROR,BITTEST_VARIABLE,var);
- desiredSize=0;
+ if (!Vars::Instance().canRead7(var))
+ IssueMessage(ERROR, NONEXISTANT_VARIABLE, 1, var);
+ else if (var > 0x7F && cond > 1 && Vars::Instance().isBitmask(var)) {
+ IssueMessage(ERROR, BITTEST_VARIABLE, var);
+ desiredSize = 0;
}
- if(var_size==8&&var==0x88){
- if(desiredSize>=8){
+ if (var_size == 8 && var == 0x88) {
+ if (desiredSize >= 8) {
uint grfid = data.ExtractDword(4), mask = data.ExtractDword(8);
- if((~mask&grfid)!=0)
- IssueMessage(WARNING1,MASKED_BIT_SET);
+ if ((~mask & grfid) != 0) IssueMessage(WARNING1, MASKED_BIT_SET);
}
- }else if(var_size==0||var_size==3||var_size>4){
- IssueMessage(FATAL,BAD_VARSIZE,var_size);
+ } else if (var_size == 0 || var_size == 3 || var_size > 4) {
+ IssueMessage(FATAL, BAD_VARSIZE, var_size);
return 0;
- }else if((cond==0xB||cond==0xC)&&var_size!=4)
- IssueMessage(WARNING2,COND_SIZE_MISMATCH,cond,4);
- else if(var>0x7F&&cond>1){
+ } else if ((cond == 0xB || cond == 0xC) && var_size != 4)
+ IssueMessage(WARNING2, COND_SIZE_MISMATCH, cond, 4);
+ else if (var > 0x7F && cond > 1) {
CheckSize(var);
- if(!Vars::Instance().lenOK(var,var_size))
- IssueMessage(WARNING2,VARIABLE_SIZE_MISMATCH,var_size,var);
+ if (!Vars::Instance().lenOK(var, var_size)) IssueMessage(WARNING2, VARIABLE_SIZE_MISMATCH, var_size, var);
}
- if(_autocorrect&&desiredSize&&desiredSize!=data.ExtractByte(2)){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,2,VARSIZE,data.ExtractByte(2),desiredSize);
- data.SetByteAt(2,var_size=desiredSize);
+ if (_autocorrect && desiredSize && desiredSize != data.ExtractByte(2)) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 2, VARSIZE, data.ExtractByte(2), desiredSize);
+ data.SetByteAt(2, var_size = desiredSize);
}
- if(cond<2?
- CheckLength(data.Length(),6,BAD_LENGTH,COND,VAL,cond,6):
- CheckLength(data.Length(),5+var_size,BAD_LENGTH,VARSIZE,VAL,data.ExtractByte(2),var_size+5))return 0;
- jumps.push_back(act7(data.ExtractByte(0),data.ExtractByte(4+var_size)));
- return data.ExtractByte(4+var_size);
+ if (cond < 2 ? CheckLength(data.Length(), 6, BAD_LENGTH, COND, VAL, cond, 6)
+ : CheckLength(data.Length(), 5 + var_size, BAD_LENGTH, VARSIZE, VAL, data.ExtractByte(2), var_size + 5))
+ return 0;
+ jumps.push_back(act7(data.ExtractByte(0), data.ExtractByte(4 + var_size)));
+ return data.ExtractByte(4 + var_size);
}
#undef SetSize
-void Init7(){
+void Init7()
+{
jumps.clear();
}
-void final7(){
- bool header=false;
- for(uint i=0;i<jumps.size();i++)
- if(!IsLabel(jumps[i].skips)&&jumps[i].skips+jumps[i].spriteno>_spritenum){
- if(!header){
- header=true;
- IssueMessage(WARNING2,LONG_JUMPLEAD);
- IssueMessage(WARNING2,UNEXP_EOF_LONGJUMP);
+void final7()
+{
+ bool header = false;
+ for (uint i = 0; i < jumps.size(); i++)
+ if (!IsLabel(jumps[i].skips) && jumps[i].skips + jumps[i].spriteno > _spritenum) {
+ if (!header) {
+ header = true;
+ IssueMessage(WARNING2, LONG_JUMPLEAD);
+ IssueMessage(WARNING2, UNEXP_EOF_LONGJUMP);
}
- IssueMessage(WARNING2,LONG_JUMP,jumps[i].act,jumps[i].spriteno);
+ IssueMessage(WARNING2, LONG_JUMP, jumps[i].act, jumps[i].spriteno);
}
}
-bool CheckD(PseudoSprite&data,uint length){
- if(length<5){IssueMessage(FATAL,INVALID_LENGTH,ACTION,0xD,ONE_OF,5,9);return false;}
+bool CheckD(PseudoSprite& data, uint length)
+{
+ if (length < 5) {
+ IssueMessage(FATAL, INVALID_LENGTH, ACTION, 0xD, ONE_OF, 5, 9);
+ return false;
+ }
data.SetAllHex();
- uint target=data.ExtractByte(1),op=data.ExtractByte(2),src1=data.ExtractByte(3),src2=data.ExtractByte(4);
+ uint target = data.ExtractByte(1), op = data.ExtractByte(2), src1 = data.ExtractByte(3), src2 = data.ExtractByte(4);
data.SetPositionalOpByte(2, 'D');
- if(!Vars::Instance().canWriteD(target))IssueMessage(ERROR,INVALID_TARGET);
- if((op&0x7F)>D::Instance().maxop)IssueMessage(ERROR,INVALID_OP,2,op);
- if((src1!=0xFE||src2!=0xFE)&&!Vars::Instance().canReadD(src1))IssueMessage(ERROR,INVALID_SRC,1);
- if(op&&src2!=0xFE&&!Vars::Instance().canReadD(src2))IssueMessage(ERROR,INVALID_SRC,2);
- if((op&0x7F)&&src1==0xFF&&src2==0xFF)IssueMessage(ERROR,ONLY_ONE_DATA);
- if(src1==0xFF||src2==0xFF||src2==0xFE){
- if(CheckLength(length,9,INVALID_LENGTH,ACTION,0xD,ONE_OF,5,9))return false;
- if(src2==0xFE){
- uint info=data.ExtractDword(5);
- if((info&0xFF)!=0xFF){
- if(op&0x7F)IssueMessage(ERROR,INVALID_OP,2,op);
- if(src1!=0xFE&&src1&0x80)IssueMessage(ERROR,INVALID_SRC,1);
+ if (!Vars::Instance().canWriteD(target)) IssueMessage(ERROR, INVALID_TARGET);
+ if ((op & 0x7F) > D::Instance().maxop) IssueMessage(ERROR, INVALID_OP, 2, op);
+ if ((src1 != 0xFE || src2 != 0xFE) && !Vars::Instance().canReadD(src1)) IssueMessage(ERROR, INVALID_SRC, 1);
+ if (op && src2 != 0xFE && !Vars::Instance().canReadD(src2)) IssueMessage(ERROR, INVALID_SRC, 2);
+ if ((op & 0x7F) && src1 == 0xFF && src2 == 0xFF) IssueMessage(ERROR, ONLY_ONE_DATA);
+ if (src1 == 0xFF || src2 == 0xFF || src2 == 0xFE) {
+ if (CheckLength(length, 9, INVALID_LENGTH, ACTION, 0xD, ONE_OF, 5, 9)) return false;
+ if (src2 == 0xFE) {
+ uint info = data.ExtractDword(5);
+ if ((info & 0xFF) != 0xFF) {
+ if (op & 0x7F) IssueMessage(ERROR, INVALID_OP, 2, op);
+ if (src1 != 0xFE && src1 & 0x80) IssueMessage(ERROR, INVALID_SRC, 1);
data.SetGRFID(5);
- }else if(info==0xFFFF){
- if(op&0x7F)IssueMessage(ERROR,INVALID_OP,2,op);
- if(src1>D::Instance().maxpatchvar)IssueMessage(ERROR,INVALID_SRC,1);
- }else{
- if(op)IssueMessage(ERROR,INVALID_OP,2,op);
+ } else if (info == 0xFFFF) {
+ if (op & 0x7F) IssueMessage(ERROR, INVALID_OP, 2, op);
+ if (src1 > D::Instance().maxpatchvar) IssueMessage(ERROR, INVALID_SRC, 1);
+ } else {
+ if (op) IssueMessage(ERROR, INVALID_OP, 2, op);
data.SetPositionalOpByte(3, 'D');
- uint feat=(info>>8)&0xFF,count=info>>16;
- if(src1>6)IssueMessage(ERROR,INVALID_SRC,1);
- if(feat>MaxFeature()||!D::Instance()[feat])IssueMessage(ERROR,INVALID_FEATURE);
- else if(count>D::Instance()[feat])IssueMessage(WARNING1,OOR_COUNT);
+ uint feat = (info >> 8) & 0xFF, count = info >> 16;
+ if (src1 > 6) IssueMessage(ERROR, INVALID_SRC, 1);
+ if (feat > MaxFeature() || !D::Instance()[feat])
+ IssueMessage(ERROR, INVALID_FEATURE);
+ else if (count > D::Instance()[feat])
+ IssueMessage(WARNING1, OOR_COUNT);
return true;
}
}
- }else if(length>5)IssueMessage(WARNING2,INVALID_LENGTH,ACTION,0xD,ONE_OF,5,9);
+ } else if (length > 5)
+ IssueMessage(WARNING2, INVALID_LENGTH, ACTION, 0xD, ONE_OF, 5, 9);
return false;
}
diff --git a/src/actB.cpp b/src/actB.cpp
--- a/src/actB.cpp
+++ b/src/actB.cpp
@@ -19,74 +19,82 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<fstream>
-#include<string>
+#include <fstream>
+#include <string>
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"sanity_defines.h"
-#include"messages.h"
-#include"data.h"
-#include"strings.h"
-#include"pseudo.h"
-#include"command.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "sanity_defines.h"
+#include "messages.h"
+#include "data.h"
+#include "strings.h"
+#include "pseudo.h"
+#include "command.h"
-class B{
-public:
- uint maxSeverity,numMessages;
+class B
+{
+ public:
+ uint maxSeverity, numMessages;
AUTO_ARRAY(uchar);
SINGLETON(B);
};
-B::B(){
- FILE*pFile=myfopen(B);
- maxSeverity=GetCheckByte(B);
- _p=new uchar[numMessages=GetCheckByte(B)];
- myfread(_p,numMessages,B);
+B::B()
+{
+ FILE* pFile = myfopen(B);
+ maxSeverity = GetCheckByte(B);
+ _p = new uchar[numMessages = GetCheckByte(B)];
+ myfread(_p, numMessages, B);
fclose(pFile);
}
-void CheckB(PseudoSprite&data){
- uint sev=data.ExtractByte(1),lang=data.ExtractByte(2),messageid=data.ExtractByte(3);
- uint offset=4;
+void CheckB(PseudoSprite& data)
+{
+ uint sev = data.ExtractByte(1), lang = data.ExtractByte(2), messageid = data.ExtractByte(3);
+ uint offset = 4;
int specials;
- if((sev&0x7F)>B::Instance().maxSeverity)IssueMessage(ERROR,INVALID_SEVERITY);
- if(_grfver){
- if(lang&0x80||(_grfver<7&&lang&0x60&&(lang&0x7F)!=0x7F))IssueMessage(WARNING2,UNKNOWN_LANG_BIT,2,lang);
- lang&=0x7F;
- if(_grfver>6)CheckLangID(lang,2);
- }else if((lang&=0x7F)>0x1F){
- _grfver=7;
- CheckLangID(lang,2);
- _grfver=0;
+ if ((sev & 0x7F) > B::Instance().maxSeverity) IssueMessage(ERROR, INVALID_SEVERITY);
+ if (_grfver) {
+ if (lang & 0x80 || (_grfver < 7 && lang & 0x60 && (lang & 0x7F) != 0x7F)) IssueMessage(WARNING2, UNKNOWN_LANG_BIT, 2, lang);
+ lang &= 0x7F;
+ if (_grfver > 6) CheckLangID(lang, 2);
+ } else if ((lang &= 0x7F) > 0x1F) {
+ _grfver = 7;
+ CheckLangID(lang, 2);
+ _grfver = 0;
}
- if(messageid!=0xFF&&messageid>=B::Instance().numMessages){
- IssueMessage(FATAL,INVALID_MESSAGEID);
+ if (messageid != 0xFF && messageid >= B::Instance().numMessages) {
+ IssueMessage(FATAL, INVALID_MESSAGEID);
return;
}
- if(messageid==0xFF)
- specials=CheckString(data,offset,CTRL_NEWLINE,false,MakeStack(4,STACK_TEXT,STACK_TEXT,STACK_DWORD,STACK_DWORD),RETURN_STACK);
+ if (messageid == 0xFF)
+ specials = CheckString(data, offset, CTRL_NEWLINE, false, MakeStack(4, STACK_TEXT, STACK_TEXT, STACK_DWORD, STACK_DWORD),
+ RETURN_STACK);
else
- specials=B::Instance()[messageid];
- if(specials==-1)return;
- if(specials>1){
- try{
- if(messageid==0xFF&&data.ExtractByte(offset))data.SetEol(offset-1,1);
- else data.SetNoEol(offset-1);
- }catch(uint){}
- CheckString(data,offset,CTRL_NEWLINE);
+ specials = B::Instance()[messageid];
+ if (specials == -1) return;
+ if (specials > 1) {
+ try
+ {
+ if (messageid == 0xFF && data.ExtractByte(offset))
+ data.SetEol(offset - 1, 1);
+ else
+ data.SetNoEol(offset - 1);
+ }
+ catch (uint)
+ {
+ }
+ CheckString(data, offset, CTRL_NEWLINE);
}
- if(specials>2){
- if(data.ExtractByte(offset)>0x7F)
- IssueMessage(ERROR,INVALID_PARAM,offset,data.ExtractByte(offset));
+ if (specials > 2) {
+ if (data.ExtractByte(offset) > 0x7F) IssueMessage(ERROR, INVALID_PARAM, offset, data.ExtractByte(offset));
offset++;
}
- if(specials>3){
- if(data.ExtractByte(offset)>0x7F)
- IssueMessage(ERROR,INVALID_PARAM,offset,data.ExtractByte(offset));
+ if (specials > 3) {
+ if (data.ExtractByte(offset) > 0x7F) IssueMessage(ERROR, INVALID_PARAM, offset, data.ExtractByte(offset));
offset++;
}
- if(offset!=data.Length())IssueMessage(WARNING2,EXTRA_DATA,data.Length(),offset);
+ if (offset != data.Length()) IssueMessage(WARNING2, EXTRA_DATA, data.Length(), offset);
}
diff --git a/src/actF.cpp b/src/actF.cpp
--- a/src/actF.cpp
+++ b/src/actF.cpp
@@ -19,156 +19,201 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<string>
-#include<cassert>
-#include<sstream>
+#include <string>
+#include <cassert>
+#include <sstream>
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"pseudo.h"
-#include"messages.h"
-#include"ExpandingArray.h"
-#include"strings.h"
-#include"command.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "pseudo.h"
+#include "messages.h"
+#include "ExpandingArray.h"
+#include "strings.h"
+#include "command.h"
-class IDarray{
-public:
- void init(){used.resize(0);sprite.resize(0);}
- bool is_defined(int id)const{return sprite[id]!=0;}
- bool is_used(int id)const{return used[id];}
- uint defined_at(int id)const{return sprite[id];}
- void define(unsigned int id){
- used[id]=false;
- sprite[id]=_spritenum;
+class IDarray
+{
+ public:
+ void init()
+ {
+ used.resize(0);
+ sprite.resize(0);
}
- void use(int id){used[id]=true;}
-protected:
- Expanding0Array<uint>sprite;
- Expanding0Array<bool>used;
-}status;
-static const IDarray&crStatus=status;
+ bool is_defined(int id) const
+ {
+ return sprite[id] != 0;
+ }
+ bool is_used(int id) const
+ {
+ return used[id];
+ }
+ uint defined_at(int id) const
+ {
+ return sprite[id];
+ }
+ void define(unsigned int id)
+ {
+ used[id] = false;
+ sprite[id] = _spritenum;
+ }
+ void use(int id)
+ {
+ used[id] = true;
+ }
-void InitF(){status.init();}
+ protected:
+ Expanding0Array<uint> sprite;
+ Expanding0Array<bool> used;
+} status;
+static const IDarray& crStatus = status;
+
+void InitF()
+{
+ status.init();
+}
#define BITS(first, num) (((1U << (num)) - 1) << (first))
-void CheckF(PseudoSprite&data){
+void CheckF(PseudoSprite& data)
+{
data.SetAllHex();
- uint id=data.ExtractByte(1),offset=2,langs,oldoff=0;
- bool isFinal=(id>=0x80);
- id&=0x7F;
- if(crStatus.is_defined(id)&&!status.is_used(id))IssueMessage(WARNING1,UNUSED_ID,id,status.defined_at(id));
+ uint id = data.ExtractByte(1), offset = 2, langs, oldoff = 0;
+ bool isFinal = (id >= 0x80);
+ id &= 0x7F;
+ if (crStatus.is_defined(id) && !status.is_used(id)) IssueMessage(WARNING1, UNUSED_ID, id, status.defined_at(id));
status.define(id);
- if(isFinal){
+ if (isFinal) {
status.use(id);
- ExpandingArray<uint>nameLocs;
- const ExpandingArray<uint>&cNameLocs=nameLocs;
- uint names=0;
- langs=data.ExtractByte(offset);
- do{
- if(langs&0x80)IssueMessage(WARNING2,UNKNOWN_LANG_BIT,offset,langs);
- langs&=0x7F;
+ ExpandingArray<uint> nameLocs;
+ const ExpandingArray<uint>& cNameLocs = nameLocs;
+ uint names = 0;
+ langs = data.ExtractByte(offset);
+ do {
+ if (langs & 0x80) IssueMessage(WARNING2, UNKNOWN_LANG_BIT, offset, langs);
+ langs &= 0x7F;
names++;
- if(names>1)data.SetEol(oldoff-1,1);
- oldoff=offset;
- if(_grfver<7){
- if(langs!=0x7F&&langs&0x60)IssueMessage(WARNING3,UNKNOWN_LANG_BIT,offset,langs);
- if(langs&0x10){if(nameLocs[4])IssueMessage(WARNING2,DUPLICATE_LANG_NAME,offset,4,nameLocs[4]);nameLocs[4]=offset;}
- if(langs&0x08){if(nameLocs[3])IssueMessage(WARNING2,DUPLICATE_LANG_NAME,offset,3,nameLocs[3]);nameLocs[3]=offset;}
- if(langs&0x04){if(nameLocs[2])IssueMessage(WARNING2,DUPLICATE_LANG_NAME,offset,2,nameLocs[2]);nameLocs[2]=offset;}
- if(langs&0x02){if(nameLocs[1])IssueMessage(WARNING2,DUPLICATE_LANG_NAME,offset,1,nameLocs[1]);nameLocs[1]=offset;}
- if(langs&0x01){if(nameLocs[0])IssueMessage(WARNING2,DUPLICATE_LANG_NAME,offset,0,nameLocs[0]);nameLocs[0]=offset;}
- }else{
- CheckLangID(langs,offset);
- if(nameLocs[langs])
- IssueMessage(WARNING2,DUPLICATE_LANG_NAME,offset,langs,nameLocs[langs]);
- nameLocs[langs]=offset;
+ if (names > 1) data.SetEol(oldoff - 1, 1);
+ oldoff = offset;
+ if (_grfver < 7) {
+ if (langs != 0x7F && langs & 0x60) IssueMessage(WARNING3, UNKNOWN_LANG_BIT, offset, langs);
+ if (langs & 0x10) {
+ if (nameLocs[4]) IssueMessage(WARNING2, DUPLICATE_LANG_NAME, offset, 4, nameLocs[4]);
+ nameLocs[4] = offset;
+ }
+ if (langs & 0x08) {
+ if (nameLocs[3]) IssueMessage(WARNING2, DUPLICATE_LANG_NAME, offset, 3, nameLocs[3]);
+ nameLocs[3] = offset;
+ }
+ if (langs & 0x04) {
+ if (nameLocs[2]) IssueMessage(WARNING2, DUPLICATE_LANG_NAME, offset, 2, nameLocs[2]);
+ nameLocs[2] = offset;
+ }
+ if (langs & 0x02) {
+ if (nameLocs[1]) IssueMessage(WARNING2, DUPLICATE_LANG_NAME, offset, 1, nameLocs[1]);
+ nameLocs[1] = offset;
+ }
+ if (langs & 0x01) {
+ if (nameLocs[0]) IssueMessage(WARNING2, DUPLICATE_LANG_NAME, offset, 0, nameLocs[0]);
+ nameLocs[0] = offset;
+ }
+ } else {
+ CheckLangID(langs, offset);
+ if (nameLocs[langs]) IssueMessage(WARNING2, DUPLICATE_LANG_NAME, offset, langs, nameLocs[langs]);
+ nameLocs[langs] = offset;
}
- if(CheckString(data,++offset,0)){
- IssueMessage(FATAL,OVERRAN_F_NAME,oldoff+1,langs);
+ if (CheckString(data, ++offset, 0)) {
+ IssueMessage(FATAL, OVERRAN_F_NAME, oldoff + 1, langs);
return;
}
- }while((langs=data.ExtractByte(offset))!=0);
- if(names>1)data.SetEol(oldoff-1,1);
- if(_grfver<7){
- if(!nameLocs[4])IssueMessage(WARNING1,MISSING_LANG_NAME,4);
- if(!nameLocs[3])IssueMessage(WARNING1,MISSING_LANG_NAME,3);
- if(!nameLocs[2])IssueMessage(WARNING1,MISSING_LANG_NAME,2);
- if(!nameLocs[1])IssueMessage(WARNING1,MISSING_LANG_NAME,1);
- if(!nameLocs[0])IssueMessage(WARNING1,MISSING_LANG_NAME,0);
- }else if(!cNameLocs[0x7F])IssueMessage(WARNING1,MISSING_FALLBACK);
+ } while ((langs = data.ExtractByte(offset)) != 0);
+ if (names > 1) data.SetEol(oldoff - 1, 1);
+ if (_grfver < 7) {
+ if (!nameLocs[4]) IssueMessage(WARNING1, MISSING_LANG_NAME, 4);
+ if (!nameLocs[3]) IssueMessage(WARNING1, MISSING_LANG_NAME, 3);
+ if (!nameLocs[2]) IssueMessage(WARNING1, MISSING_LANG_NAME, 2);
+ if (!nameLocs[1]) IssueMessage(WARNING1, MISSING_LANG_NAME, 1);
+ if (!nameLocs[0]) IssueMessage(WARNING1, MISSING_LANG_NAME, 0);
+ } else if (!cNameLocs[0x7F])
+ IssueMessage(WARNING1, MISSING_FALLBACK);
offset++;
}
- uint num_parts=data.SetEol(offset,1).ExtractByte(offset);
- if(isFinal)data.SetEol(offset-1,1);
- if(!num_parts)IssueMessage(ERROR,NO_PARTS,offset);
- uint bitsused=0;
- for(uint i=0;i<num_parts;i++){
- uint textcount=data.ExtractByte(++offset);
- if(!textcount)IssueMessage(ERROR,NO_PARTS,offset);
- uint total_prob=0,firstbit=data.ExtractByte(++offset),fb_offs=offset,numbits=data.ExtractByte(++offset);
- if(textcount>1){
- if(bitsused&BITS(firstbit,numbits)){
+ uint num_parts = data.SetEol(offset, 1).ExtractByte(offset);
+ if (isFinal) data.SetEol(offset - 1, 1);
+ if (!num_parts) IssueMessage(ERROR, NO_PARTS, offset);
+ uint bitsused = 0;
+ for (uint i = 0; i < num_parts; i++) {
+ uint textcount = data.ExtractByte(++offset);
+ if (!textcount) IssueMessage(ERROR, NO_PARTS, offset);
+ uint total_prob = 0, firstbit = data.ExtractByte(++offset), fb_offs = offset, numbits = data.ExtractByte(++offset);
+ if (textcount > 1) {
+ if (bitsused & BITS(firstbit, numbits)) {
ostringstream s;
- int first=-1,bits=bitsused&BITS(firstbit,numbits);
- for(int j=0;j<32;j++){
- if(bits&(1<<j)){
- if(first==-1)first=j;
+ int first = -1, bits = bitsused & BITS(firstbit, numbits);
+ for (int j = 0; j < 32; j++) {
+ if (bits & (1 << j)) {
+ if (first == -1) first = j;
continue;
}
- if(first==-1)continue;
- if(first==j-1)s<<first<<", ";
- else if(first==j-2)s<<first<<", "<<j-1<<", ";
- else s<<first<<".."<<j-1<<", ";
- first=-1;
+ if (first == -1) continue;
+ if (first == j - 1)
+ s << first << ", ";
+ else if (first == j - 2)
+ s << first << ", " << j - 1 << ", ";
+ else
+ s << first << ".." << j - 1 << ", ";
+ first = -1;
}
- string str=s.str();
- str[str.length()-2]='\0';
- IssueMessage(WARNING1,BITS_OVERLAP,fb_offs,i,str.c_str());
+ string str = s.str();
+ str[str.length() - 2] = '\0';
+ IssueMessage(WARNING1, BITS_OVERLAP, fb_offs, i, str.c_str());
}
- bitsused|=BITS(firstbit,numbits);
+ bitsused |= BITS(firstbit, numbits);
}
- data.SetEol(offset,2);
- if(firstbit+numbits>32)IssueMessage(ERROR,OUT_OF_RANGE_BITS,fb_offs,32);
- for(uint j=0;j<textcount;/*Increment in SetEol call*/){
- uint prob=data.ExtractByte(++offset);
- total_prob+=prob&0x7F;
- if(!(prob&0x7F))IssueMessage(WARNING1,NO_PROBABILITY,offset);
- if(prob&0x80){
- uint newid=data.ExtractByte(++offset)&0x7F;
- if(!status.is_defined(newid))IssueMessage(ERROR,UNDEFINED_ID,offset,newid);
- else if(newid==id)IssueMessage(ERROR,RECURSIVE_F,offset);
- else status.use(newid);
- }else{
- oldoff=++offset;
- if(CheckString(data,offset,0)){
- IssueMessage(FATAL,OVERRAN_F_PART,oldoff);
+ data.SetEol(offset, 2);
+ if (firstbit + numbits > 32) IssueMessage(ERROR, OUT_OF_RANGE_BITS, fb_offs, 32);
+ for (uint j = 0; j < textcount; /*Increment in SetEol call*/) {
+ uint prob = data.ExtractByte(++offset);
+ total_prob += prob & 0x7F;
+ if (!(prob & 0x7F)) IssueMessage(WARNING1, NO_PROBABILITY, offset);
+ if (prob & 0x80) {
+ uint newid = data.ExtractByte(++offset) & 0x7F;
+ if (!status.is_defined(newid))
+ IssueMessage(ERROR, UNDEFINED_ID, offset, newid);
+ else if (newid == id)
+ IssueMessage(ERROR, RECURSIVE_F, offset);
+ else
+ status.use(newid);
+ } else {
+ oldoff = ++offset;
+ if (CheckString(data, offset, 0)) {
+ IssueMessage(FATAL, OVERRAN_F_PART, oldoff);
return;
}
offset--;
}
- data.SetEol(offset,(++j==textcount)?1:2);
+ data.SetEol(offset, (++j == textcount) ? 1 : 2);
}
- total_prob--;//beause 2^n has n+1 bits but only needs n bits of randomness.
- uint minbits=1;
- while(total_prob>>=1)minbits++;
- if(numbits<minbits)IssueMessage(WARNING1,INSUFFICIENT_BITS,fb_offs+1,minbits,numbits);
+ total_prob--; // beause 2^n has n+1 bits but only needs n bits of randomness.
+ uint minbits = 1;
+ while (total_prob >>= 1) minbits++;
+ if (numbits < minbits) IssueMessage(WARNING1, INSUFFICIENT_BITS, fb_offs + 1, minbits, numbits);
}
- if(++offset!=data.Length())IssueMessage(WARNING2,EXTRA_DATA,data.Length(), offset);
+ if (++offset != data.Length()) IssueMessage(WARNING2, EXTRA_DATA, data.Length(), offset);
}
-void finalF(){
+void finalF()
+{
ManualConsoleMessages();
- bool header=false;
- for(uint i=0;i<128;i++)
- if(crStatus.is_defined(i)&&!crStatus.is_used(i)){
- if(!header){
- IssueMessage(WARNING1,UNUSEDFIDLEAD,i);
- IssueMessage(WARNING1,UNEXP_EOF_TOWNNAMES,i);
- header=true;
+ bool header = false;
+ for (uint i = 0; i < 128; i++)
+ if (crStatus.is_defined(i) && !crStatus.is_used(i)) {
+ if (!header) {
+ IssueMessage(WARNING1, UNUSEDFIDLEAD, i);
+ IssueMessage(WARNING1, UNEXP_EOF_TOWNNAMES, i);
+ header = true;
}
- IssueMessage(WARNING1,UNUSEDIDFINAL,i,crStatus.defined_at(i));
+ IssueMessage(WARNING1, UNUSEDIDFINAL, i, crStatus.defined_at(i));
}
}
diff --git a/src/allocarray.h b/src/allocarray.h
--- a/src/allocarray.h
+++ b/src/allocarray.h
@@ -25,53 +25,67 @@
#define _ALLOC_ARRAY_H
#ifdef _MSC_VER
-#pragma warning(disable:4702)//Unreachable code
-//Yes. I have a C++ library in which <vector> contains unreachable code.
-#include<vector>
-#pragma warning(default:4702)
+#pragma warning(disable : 4702) // Unreachable code
+// Yes. I have a C++ library in which <vector> contains unreachable code.
+#include <vector>
+#pragma warning(default : 4702)
#else
#include <vector>
#endif
-template<typename _Ty>class AllocArray:private std::vector<_Ty*>{
+template <typename _Ty>
+class AllocArray : private std::vector<_Ty*>
+{
typedef AllocArray<_Ty> _Myt;
typedef std::vector<_Ty*> _Mybase;
typedef typename _Mybase::size_type size_type;
typedef typename _Mybase::iterator iterator;
typedef typename _Mybase::reference reference;
typedef typename _Mybase::const_reference const_reference;
-public:
- AllocArray(){}
- ~AllocArray(){
- for(size_type i=_Mybase::size();i;)
- delete operator[](--i);
+
+ public:
+ AllocArray()
+ {
}
- template<typename _Cty>void push_back(const _Cty&val){
+ ~AllocArray()
+ {
+ for (size_type i = _Mybase::size(); i;) delete operator[](--i);
+ }
+ template <typename _Cty>
+ void push_back(const _Cty& val)
+ {
_Mybase::push_back(new _Cty(val));
}
- template<typename _Cty>void push_back(const _Cty*val){
+ template <typename _Cty>
+ void push_back(const _Cty* val)
+ {
_Mybase::push_back(new _Cty(*val));
}
- size_type size()const{
+ size_type size() const
+ {
return _Mybase::size();
}
- reference last(){
- return operator[](size()-1);
+ reference last()
+ {
+ return operator[](size() - 1);
}
- reference operator[](size_type x){
- return _Mybase::operator [](x);
+ reference operator[](size_type x)
+ {
+ return _Mybase::operator[](x);
}
- const_reference operator[](size_type x)const{
- return _Mybase::operator [](x);
+ const_reference operator[](size_type x) const
+ {
+ return _Mybase::operator[](x);
}
- void clear(){
- for(size_type i=_Mybase::size();i;)
- delete operator[](--i);
+ void clear()
+ {
+ for (size_type i = _Mybase::size(); i;) delete operator[](--i);
_Mybase::clear();
}
-private:
- AllocArray(const _Myt&right);
- void operator=(const _Myt&right);
+
+ private:
+ AllocArray(const _Myt& right);
+ void operator=(const _Myt& right);
};
#endif /* _ALLOC_ARRAY_H */
diff --git a/src/command.cpp b/src/command.cpp
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -19,41 +19,43 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<iostream>
-#include<iomanip>
-#include<sstream>
-#include<string>
-#include<cassert>
-#include<stack>
+#include <iostream>
+#include <iomanip>
+#include <sstream>
+#include <string>
+#include <cassert>
+#include <stack>
#ifdef _MSC_VER
-# pragma warning(disable:4702)//unreachable code
-# include<map>
-# pragma warning(default:4702)
+#pragma warning(disable : 4702) // unreachable code
+#include <map>
+#pragma warning(default : 4702)
#else
-# include<map>
+#include <map>
#endif
-#include<cstdlib>
-#include<getopt.h>
+#include <cstdlib>
+#include <getopt.h>
using namespace std;
-#include"globals.h"
-#include"nforenum.h"
-#include"command.h"
-#include"inlines.h"
-#include"sanity.h"
-#include"messages.h"
-#include"inject.h"
-#include"sanity_defines.h"
-#include"data.h"
+#include "globals.h"
+#include "nforenum.h"
+#include "command.h"
+#include "inlines.h"
+#include "sanity.h"
+#include "messages.h"
+#include "inject.h"
+#include "sanity_defines.h"
+#include "data.h"
-#include"ExpandingArray.h"
+#include "ExpandingArray.h"
-#define CASE(_case,_return)\
- case _case:return _commandState._return;
+#define CASE(_case, _return) \
+ case _case: \
+ return _commandState._return;
-struct commandData{
- const char*name;
+struct commandData
+{
+ const char* name;
int value;
};
@@ -62,440 +64,523 @@
#undef COMMAND_DATA
#undef COMMAND_DATA_EX
#undef COMMAND_DATA_END
-#define COMMAND_DATA_START(x) const commandData x[]={
-#define COMMAND_DATA(x) {#x,x},
-#define COMMAND_DATA_EX(val,name) {#name,val},
-#define COMMAND_DATA_END() {NULL,-1}};
+#define COMMAND_DATA_START(x) const commandData x[] = {
+#define COMMAND_DATA(x) \
+ { \
+ #x, x \
+ } \
+ ,
+#define COMMAND_DATA_EX(val, name) \
+ { \
+ #name, val \
+ } \
+ ,
+#define COMMAND_DATA_END() \
+ { \
+ NULL, -1 \
+ } \
+ } \
+ ;
#include "command.h"
-struct command{
+struct command
+{
command();
- uint sanity_messages;//,verbose;
- int real:2;
- bool remove_messages,beautifier,diff,locked,useoldnums;
- //7..0: MAXLEN
- //8: QuoteHighAscii
- //9: QuoteUTF8
- //10: HexGRFID
- //12..11: Linebreaks
- //13: UseEscape
- //14: Unused
- //15: Unused
- //20..16, 25..21, 30..26: Leading space 1,2,3
- //31: CONVERTONLY
+ uint sanity_messages; //,verbose;
+ int real : 2;
+ bool remove_messages, beautifier, diff, locked, useoldnums;
+ // 7..0: MAXLEN
+ // 8: QuoteHighAscii
+ // 9: QuoteUTF8
+ // 10: HexGRFID
+ // 12..11: Linebreaks
+ // 13: UseEscape
+ // 14: Unused
+ // 15: Unused
+ // 20..16, 25..21, 30..26: Leading space 1,2,3
+ // 31: CONVERTONLY
uint beauty;
- Expanding0Array<int>warnstate;
-}_commandState,_CLstate;
+ Expanding0Array<int> warnstate;
+} _commandState, _CLstate;
-static map<string,int>_varmap,_CLvar;
+static map<string, int> _varmap, _CLvar;
-const command&crCommandState=_commandState;
+const command& crCommandState = _commandState;
-command::command(){
- remove_messages=true;
- beautifier=diff=locked=false;
- sanity_messages=WARNING3;
- real=0;
- beauty=686039958;
-// verbose=0;
+command::command()
+{
+ remove_messages = true;
+ beautifier = diff = locked = false;
+ sanity_messages = WARNING3;
+ real = 0;
+ beauty = 686039958;
+ // verbose=0;
}
-int find_command(const string&command,const commandData type[]){
- for(int i=0;;i++){
- if(type[i].name==NULL)return -1;
- if(UCase(command)==type[i].name)return type[i].value;
+int find_command(const string& command, const commandData type[])
+{
+ for (int i = 0;; i++) {
+ if (type[i].name == NULL) return -1;
+ if (UCase(command) == type[i].name) return type[i].value;
}
}
-bool is_command(const string&line){
+bool is_command(const string& line)
+{
assert(is_comment(line));
- string::size_type x=line.find_first_not_of(COMMENT+WHITESPACE);
- return x!=string::npos&&x<(line.length()-1)&&line[x]=='@'&&line[x+1]=='@';
+ string::size_type x = line.find_first_not_of(COMMENT + WHITESPACE);
+ return x != string::npos && x < (line.length() - 1) && line[x] == '@' && line[x + 1] == '@';
}
-bool is_message(const string&line){
+bool is_message(const string& line)
+{
assert(is_comment(line));
- string::size_type x=line.find_first_not_of(COMMENT+WHITESPACE);
- return x!=string::npos&&x<(line.length()-1)&&line[x]=='!'&&line[x+1]=='!';
+ string::size_type x = line.find_first_not_of(COMMENT + WHITESPACE);
+ return x != string::npos && x < (line.length() - 1) && line[x] == '!' && line[x + 1] == '!';
}
-void reset_commands(){
- _commandState=_CLstate;
- _varmap=_CLvar;
+void reset_commands()
+{
+ _commandState = _CLstate;
+ _varmap = _CLvar;
}
-string GetOnOffString(string str){
- if(str[str.length()-1]=='+'){
- str[str.length()-1]=' ';
- str+="ON";
- }else if(str[str.length()-1]=='-'){
- str[str.length()-1]=' ';
- str+="OFF";
+string GetOnOffString(string str)
+{
+ if (str[str.length() - 1] == '+') {
+ str[str.length() - 1] = ' ';
+ str += "ON";
+ } else if (str[str.length() - 1] == '-') {
+ str[str.length() - 1] = ' ';
+ str += "OFF";
}
return str;
}
-bool CLCommand(int command){
- bool locked=_commandState.locked;
- _commandState.locked=false;
- switch(command){
- case'd':parse_comment("//@@DIFF");break;
- case'L':parse_comment("//@@LET "+string(optarg));break;
- case'l':parse_comment("//@@LINT "+GetOnOffString(optarg));break;
- case'r':parse_comment("//@@REALSPRITES "+string(optarg));break;
- case'b':parse_comment("//@@BEAUTIFY "+GetOnOffString(optarg));break;
- case'p':_commandState.remove_messages=false;break;
- case'e':parse_comment("//@@EXTENTIONS "+GetOnOffString(optarg));break;
- case'o':parse_comment("//@@USEOLDSPRITENUMS "+GetOnOffString(optarg));break;
- case 256:locked=true;break;
- case'w':case'W':{
- string s(optarg);
- if (s.find_first_not_of("0123456789,") != NPOS) return false;
- string::size_type loc;
- while ( (loc=s.find_first_of(',')) != NPOS)
- s[loc]='+';
- istringstream arg(s);
- uint opt;
- while(arg>>opt){
- parse_comment((command=='w'?"//@@WARNING DISABLE ":"//@@WARNING ENABLE ")+itoa(opt));
- arg.ignore();
+bool CLCommand(int command)
+{
+ bool locked = _commandState.locked;
+ _commandState.locked = false;
+ switch (command) {
+ case 'd':
+ parse_comment("//@@DIFF");
+ break;
+ case 'L':
+ parse_comment("//@@LET " + string(optarg));
+ break;
+ case 'l':
+ parse_comment("//@@LINT " + GetOnOffString(optarg));
+ break;
+ case 'r':
+ parse_comment("//@@REALSPRITES " + string(optarg));
+ break;
+ case 'b':
+ parse_comment("//@@BEAUTIFY " + GetOnOffString(optarg));
+ break;
+ case 'p':
+ _commandState.remove_messages = false;
+ break;
+ case 'e':
+ parse_comment("//@@EXTENTIONS " + GetOnOffString(optarg));
+ break;
+ case 'o':
+ parse_comment("//@@USEOLDSPRITENUMS " + GetOnOffString(optarg));
+ break;
+ case 256:
+ locked = true;
+ break;
+ case 'w':
+ case 'W': {
+ string s(optarg);
+ if (s.find_first_not_of("0123456789,") != NPOS) return false;
+ string::size_type loc;
+ while ((loc = s.find_first_of(',')) != NPOS) s[loc] = '+';
+ istringstream arg(s);
+ uint opt;
+ while (arg >> opt) {
+ parse_comment((command == 'w' ? "//@@WARNING DISABLE " : "//@@WARNING ENABLE ") + itoa(opt));
+ arg.ignore();
+ }
+ break;
}
- break;
- }DEFAULT(command)
+ DEFAULT(command)
}
- _commandState.locked=locked;
- _CLstate=_commandState;
- _CLvar=_varmap;
+ _commandState.locked = locked;
+ _CLstate = _commandState;
+ _CLvar = _varmap;
return true;
}
-void SetVar(const string&,const string&);
+void SetVar(const string&, const string&);
string ReadVar(istream&);
-bool parse_comment(const string&line){
+bool parse_comment(const string& line)
+{
assert(is_comment(line));
- if(is_message(line))
- return!GetState(REMOVEMESSAGES);
- if(!is_command(line))
- return true;
- string command=line.c_str()+line.find_first_not_of(COMMENT+WHITESPACE+'@'),command_part;
- while(command.find('=')!=NPOS)command[command.find('=')]=' ';
+ if (is_message(line)) return !GetState(REMOVEMESSAGES);
+ if (!is_command(line)) return true;
+ string command = line.c_str() + line.find_first_not_of(COMMENT + WHITESPACE + '@'), command_part;
+ while (command.find('=') != NPOS) command[command.find('=')] = ' ';
istringstream commandstream(command);
- commandstream>>command_part;
+ commandstream >> command_part;
int id;
- switch(find_command(command_part,gen)){
- case REMOVEMESSAGES:
- _commandState.remove_messages=true;
- break;
- case PRESERVEMESSAGES:
- _commandState.remove_messages=false;
- break;
- case LINT:
- if(commandstream>>command_part){
- if(GetState(LINT)!=OFF){
- int x=find_command(command_part,san);
- _commandState.sanity_messages=(x==-1?WARNING3:x);
+ switch (find_command(command_part, gen)) {
+ case REMOVEMESSAGES:
+ _commandState.remove_messages = true;
+ break;
+ case PRESERVEMESSAGES:
+ _commandState.remove_messages = false;
+ break;
+ case LINT:
+ if (commandstream >> command_part) {
+ if (GetState(LINT) != OFF) {
+ int x = find_command(command_part, san);
+ _commandState.sanity_messages = (x == -1 ? WARNING3 : x);
+ }
+ break;
+ }
+ return true;
+ case USEID2: {
+ int feature;
+ commandstream >> setbase(16) >> feature >> id;
+ if (!commandstream)
+ id = feature;
+ else if (!IsValid2Feature(feature)) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[USEID2].name);
+ return true;
+ } else {
+ inject(mysprintf("%t@@USEID2 %2x", COMMENT_PREFIX, id));
+ return false;
+ }
+ sanity_use_id(id);
+ return true;
+ }
+ case USESET:
+ commandstream >> setbase(16) >> id;
+ sanity_use_set(id);
+ return true;
+ case DIFF:
+ _commandState.diff = _commandState.remove_messages = true;
+ _commandState.sanity_messages = OFF;
+ if (_commandState.locked) _commandState = _CLstate;
+ return false;
+ case WARNING: {
+ commandstream >> command_part;
+ int num = 0, state = find_command(command_part, warn);
+ commandstream >> num;
+ if (state == -1) {
+ IssueMessage(0, COMMAND_UNKNOWN, command_part.c_str());
+ IssueMessage(0, COMMAND_REVERT_DEFAULT);
+ }
+ _commandState.warnstate[num] = state;
+ break;
+ }
+ case VERSIONCHECK: {
+ commandstream >> command_part;
+ int ver;
+ if (command_part.length() == 8 && command_part.find_first_not_of(VALID_PSEUDO) == NPOS)
+ ver = ctoi(command_part[0]) << 28 | ctoi(command_part[1]) << 24 | ctoi(command_part[2]) << 20 |
+ ctoi(command_part[3]) << 16 | ctoi(command_part[4]) << 12 | ctoi(command_part[5]) << 8 |
+ ctoi(command_part[6]) << 4 | ctoi(command_part[7]);
+ else {
+ uint M, m, r, b;
+ if (sscanf(command_part.c_str(), "%u.%u.%u.%u", &M, &m, &r, &b) == 4 && M < 256 && m < 16 && r < 16 &&
+ b < 65536)
+ ver = M << 24 | m << 20 | r << 16 | b;
+ else if ((sscanf(command_part.c_str(), "201a%u", &b) == 1 ||
+ sscanf(command_part.c_str(), "2.0.1a%u", &b) == 1) &&
+ b < 6553)
+ ver = 0x020A0000 | (b * 10);
+ else if ((sscanf(command_part.c_str(), "25b%u", &b) == 1 ||
+ sscanf(command_part.c_str(), "2.5b%u", &b) == 1)) {
+ if (b < 6)
+ ver = 0x02500000 | (b * 10);
+ else {
+ FILE* pFile = myfopen(versions);
+ uint maxVer = fgetc(pFile);
+ if (b <= maxVer) {
+ int r = 0;
+ for (b -= 5; b; b--) r = GetCheckWord(versions);
+ ver = 0x02500000 | r;
+ } else {
+ IssueMessage(0, COMMAND_UNKNOWN_VERSION, gen[VERSIONCHECK].name);
+ fclose(pFile);
+ return true;
+ }
+ fclose(pFile);
+ }
+ } else if ((sscanf(command_part.c_str(), "2%ur%x", &m, &b) == 2 ||
+ sscanf(command_part.c_str(), "2.%ur%x", &m, &b) == 2) &&
+ m < 16 && b > 417 && b < 0x10000)
+ ver = 0x02000000 | (m << 20) | b;
+ else {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[VERSIONCHECK].name);
+ return true;
+ }
+ }
+ if (!getline(commandstream, command_part)) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[VERSIONCHECK].name);
+ return true;
+ }
+ inject(mysprintf("0*0 09 8B 04 05 %8x 01", ver - 1));
+ inject(mysprintf("0*0 0B 03 1F 00%t 00", command_part.c_str()));
+ // inject("//@@PRESERVEMESSAGES NOPRESERVE");
+ inject(mysprintf("0*0 09 8B 04 04 %8x 00" /* %t!! MOVE ME AFTER THE ACTION 8 !!"*/, ver, COMMENT_PREFIX));
+ // if(GetState(REMOVEMESSAGES))inject("//@@REMOVEMESSAGES NOPRESERVE");
+ return false;
+ }
+ case LET: {
+ string var = ReadVar(commandstream);
+ if (var == "") return true;
+ if (eat_white(commandstream).peek() == '=') commandstream.ignore();
+ getline(eat_white(commandstream), command_part);
+ if (!_commandState.locked) SetVar(var, command_part);
+ return true;
+ }
+ case REALSPRITES:
+ commandstream >> command_part;
+ switch (find_command(command_part, real)) {
+ case RPNON:
+ _commandState.real &= ~1;
+ break;
+ case RPNOFF:
+ _commandState.real |= 3;
+ break; // Yes, 3. RPNOFF also sets COMMENTOFF.
+ case COMMENTON:
+ _commandState.real &= ~2;
+ break;
+ case COMMENTOFF:
+ _commandState.real |= 2;
+ break;
+ case -1:
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[REAL].name);
+ return true;
+ default:
+ INTERNAL_ERROR(command, find_command(command_part, real));
}
break;
- }
- return true;
- case USEID2:{
- int feature;
- commandstream>>setbase(16)>>feature>>id;
- if(!commandstream)
- id=feature;
- else if(!IsValid2Feature(feature)){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[USEID2].name);
- return true;
- }else{
- inject(mysprintf("%t@@USEID2 %2x",COMMENT_PREFIX,id));
- return false;
- }
- sanity_use_id(id);
- return true;
- }case USESET:
- commandstream>>setbase(16)>>id;
- sanity_use_set(id);
- return true;
- case DIFF:
- _commandState.diff=_commandState.remove_messages=true;
- _commandState.sanity_messages=OFF;
- if(_commandState.locked)_commandState=_CLstate;
- return false;
- case WARNING:{
- commandstream>>command_part;
- int num=0,state=find_command(command_part,warn);
- commandstream>>num;
- if(state==-1){
- IssueMessage(0,COMMAND_UNKNOWN,command_part.c_str());
- IssueMessage(0,COMMAND_REVERT_DEFAULT);
- }
- _commandState.warnstate[num]=state;
- break;
- }case VERSIONCHECK:{
- commandstream>>command_part;
- int ver;
- if(command_part.length()==8&&command_part.find_first_not_of(VALID_PSEUDO)==NPOS)
- ver=ctoi(command_part[0])<<28|ctoi(command_part[1])<<24|ctoi(command_part[2])<<20|ctoi(command_part[3])<<16|
- ctoi(command_part[4])<<12|ctoi(command_part[5])<<8|ctoi(command_part[6])<<4|ctoi(command_part[7]);
- else{
- uint M,m,r,b;
- if(sscanf(command_part.c_str(),"%u.%u.%u.%u",&M,&m,&r,&b)==4&&M<256&&m<16&&r<16&&b<65536)
- ver=M<<24|m<<20|r<<16|b;
- else if((sscanf(command_part.c_str(),"201a%u",&b)==1||sscanf(command_part.c_str(),"2.0.1a%u",&b)==1)&&b<6553)
- ver=0x020A0000|(b*10);
- else if((sscanf(command_part.c_str(),"25b%u",&b)==1||sscanf(command_part.c_str(),"2.5b%u",&b)==1)){
- if(b<6)ver=0x02500000|(b*10);
- else{
- FILE*pFile=myfopen(versions);
- uint maxVer=fgetc(pFile);
- if(b<=maxVer){
- int r=0;
- for(b-=5;b;b--)
- r=GetCheckWord(versions);
- ver=0x02500000|r;
- }else{
- IssueMessage(0,COMMAND_UNKNOWN_VERSION,gen[VERSIONCHECK].name);
- fclose(pFile);
+ case BEAUTIFY: {
+ commandstream >> command_part;
+ uint val = find_command(command_part, beaut), togglebit;
+ if (val != (uint) - 1 && val != OFF) _commandState.beautifier = true;
+ switch (val) {
+ case -1:
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[BEAUTIFY].name);
+ return true;
+ case OFF:
+ _commandState.beautifier = false;
+ break;
+ case ON:
+ break;
+ case MAXLEN:
+ if (!(commandstream >> val) || val > 255) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[BEAUTIFY].name);
+ commandstream.ignore(INT_MAX);
return true;
}
- fclose(pFile);
+ _commandState.beauty = (_commandState.beauty & ~0xFF) | val;
+ break;
+ case QUOTEHIGHASCII:
+ togglebit = 0x100;
+ goto dotoggle;
+ case QUOTEUTF8:
+ togglebit = 0x200;
+ goto dotoggle;
+ case HEXGRFID:
+ togglebit = 0x400;
+ goto dotoggle;
+ case LEADINGSPACE: {
+ commandstream >> command_part;
+ uint lead[3] = {0, 0, 0};
+ int count = sscanf(command_part.c_str(), "%u,%u,%u", lead, lead + 1, lead + 2);
+ if (lead[0] == 0) lead[0] = GetState(LEADINGSPACE);
+ if (lead[1] == 0) lead[1] = GetState(LEADINGSPACE, 1);
+ if (lead[2] == 0) lead[2] = GetState(LEADINGSPACE, 2);
+ while (count && count != 3) {
+ lead[count] = lead[count - 1] + 3;
+ count++;
+ }
+ if (lead[0] > 32 || lead[1] > 32 || lead[2] > 32) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[BEAUTIFY].name);
+ return true;
+ }
+ _commandState.beauty = (_commandState.beauty & ~0x7FFF0000) | ((lead[0] - 1) << 16) |
+ ((lead[1] - 1) << 21) | ((lead[2] - 1) << 26);
+ break;
}
- }else if((sscanf(command_part.c_str(),"2%ur%x",&m,&b)==2||sscanf(command_part.c_str(),"2.%ur%x",&m,&b)==2)&&m<16&&b>417&&b<0x10000)
- ver=0x02000000|(m<<20)|b;
- else{
- IssueMessage(0,COMMAND_INVALID_ARG,gen[VERSIONCHECK].name);
+ case LINEBREAKS: {
+ uint breaks = 4;
+ commandstream >> breaks;
+ if (breaks > 3) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[BEAUTIFY].name);
+ return true;
+ }
+ _commandState.beauty &= ~0x1800;
+ _commandState.beauty |= ((breaks + 2) & 3) << 11;
+ break;
+ }
+ case CONVERTONLY: {
+ togglebit = 0x80000000;
+ goto dotoggle;
+ }
+ case GETCOOKIE:
+ inject(mysprintf("%t@@BEAUTIFY SETCOOKIE %d", COMMENT_PREFIX, _commandState.beauty));
+ return false;
+ case SETCOOKIE:
+ if (!(commandstream >> _commandState.beauty)) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[BEAUTIFY].name);
+ return true;
+ }
+ break;
+ case USEESCAPES:
+ togglebit = 0x2000;
+ goto dotoggle;
+ default:
+ INTERNAL_ERROR(command, find_command(command_part, beaut));
+ dotoggle:
+ commandstream >> command_part;
+ val = find_command(command_part, beaut);
+ if (!commandstream || val == (uint) - 1) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[BEAUTIFY].name);
+ return true;
+ }
+ if (val == OFF)
+ _commandState.beauty &= ~togglebit;
+ else
+ _commandState.beauty |= togglebit;
+ }
+ commandstream >> command_part;
+ if (_commandState.locked) _commandState = _CLstate;
+ return find_command(command_part, preserve) != NOPRESERVE;
+ }
+ case CLEARACTION2:
+ final123();
+ Init123();
+ AutoConsoleMessages(); // final123 calls ManualConsoleMessages();
+ break;
+ case CLEARACTIONF:
+ finalF();
+ InitF();
+ AutoConsoleMessages(); // finalF calls ManualConsoleMessages();
+ break;
+ case TESTID2: {
+ int feature;
+ commandstream >> setbase(16) >> feature >> id;
+ if (!commandstream)
+ id = feature;
+ else if (!IsValid2Feature(feature)) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[TESTID2].name);
+ return true;
+ } else {
+ inject(mysprintf("%t@@TESTID2 %2x", COMMENT_PREFIX, id));
+ return false;
+ }
+ sanity_test_id(id);
+ return true;
+ }
+ case DEFINEID2: {
+ int feature;
+ commandstream >> setbase(16) >> feature >> id;
+ if (!commandstream)
+ id = feature;
+ else if (!IsValid2Feature(feature)) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[DEFINEID2].name);
return true;
}
- }
- if(!getline(commandstream,command_part)){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[VERSIONCHECK].name);
+ sanity_define_id(feature, id);
return true;
}
- inject(mysprintf("0*0 09 8B 04 05 %8x 01",ver-1));
- inject(mysprintf("0*0 0B 03 1F 00%t 00",command_part.c_str()));
- //inject("//@@PRESERVEMESSAGES NOPRESERVE");
- inject(mysprintf("0*0 09 8B 04 04 %8x 00"/* %t!! MOVE ME AFTER THE ACTION 8 !!"*/,ver,COMMENT_PREFIX));
- //if(GetState(REMOVEMESSAGES))inject("//@@REMOVEMESSAGES NOPRESERVE");
- return false;
- }case LET:{
- string var=ReadVar(commandstream);
- if(var=="")return true;
- if(eat_white(commandstream).peek()=='=')commandstream.ignore();
- getline(eat_white(commandstream),command_part);
- if(!_commandState.locked)SetVar(var,command_part);
- return true;
- }case REALSPRITES:
- commandstream>>command_part;
- switch(find_command(command_part,real)){
- case RPNON:_commandState.real&=~1;break;
- case RPNOFF:_commandState.real|=3;break;//Yes, 3. RPNOFF also sets COMMENTOFF.
- case COMMENTON:_commandState.real&=~2;break;
- case COMMENTOFF:_commandState.real|=2;break;
- case-1:IssueMessage(0,COMMAND_INVALID_ARG,gen[REAL].name);return true;
- default:
- INTERNAL_ERROR(command,find_command(command_part,real));
+ case LOCATEID2: {
+ int feature;
+ commandstream >> setbase(16) >> feature >> id;
+ if (!commandstream)
+ id = feature;
+ else if (!IsValid2Feature(feature)) {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[LOCATEID2].name);
+ return true;
+ } else {
+ inject(mysprintf("%t@@LOCATEID2 %2x", COMMENT_PREFIX, id));
+ return false;
+ }
+ inject("//@@PRESERVEMESSAGES NOPRESERVE");
+ inject(mysprintf("//!!LOCATEID2 %2x %2x: %d", sanity_get_feature(id), id, sanity_locate_id(id)));
+ if (GetState(REMOVEMESSAGES)) inject("//@@REMOVEMESSAGES NOPRESERVE");
+ break;
}
- break;
- case BEAUTIFY:{
- commandstream>>command_part;
- uint val=find_command(command_part,beaut),togglebit;
- if(val!=(uint)-1&&val!=OFF)_commandState.beautifier=true;
- switch(val){
- case -1:
- IssueMessage(0,COMMAND_INVALID_ARG,gen[BEAUTIFY].name);
- return true;
- case OFF:_commandState.beautifier=false;break;
- case ON:break;
- case MAXLEN:
- if(!(commandstream>>val)||val>255){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[BEAUTIFY].name);
- commandstream.ignore(INT_MAX);
- return true;
- }
- _commandState.beauty=(_commandState.beauty&~0xFF)|val;
- break;
- case QUOTEHIGHASCII:
- togglebit = 0x100;
- goto dotoggle;
- case QUOTEUTF8:
- togglebit = 0x200;
- goto dotoggle;
- case HEXGRFID:
- togglebit = 0x400;
- goto dotoggle;
- case LEADINGSPACE:{
- commandstream>>command_part;
- uint lead[3]={0,0,0};
- int count=sscanf(command_part.c_str(),"%u,%u,%u",lead,lead+1,lead+2);
- if(lead[0]==0)lead[0]=GetState(LEADINGSPACE);
- if(lead[1]==0)lead[1]=GetState(LEADINGSPACE,1);
- if(lead[2]==0)lead[2]=GetState(LEADINGSPACE,2);
- while(count&&count!=3){
- lead[count]=lead[count-1]+3;
- count++;
- }
- if(lead[0]>32||lead[1]>32||lead[2]>32){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[BEAUTIFY].name);
- return true;
- }
- _commandState.beauty=(_commandState.beauty&~0x7FFF0000)|((lead[0]-1)<<16)|((lead[1]-1)<<21)|((lead[2]-1)<<26);
- break;
- }case LINEBREAKS:{
- uint breaks=4;
- commandstream>>breaks;
- if(breaks>3){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[BEAUTIFY].name);
- return true;
- }
- _commandState.beauty&=~0x1800;
- _commandState.beauty|=((breaks+2)&3)<<11;
- break;
- }case CONVERTONLY:{
- togglebit = 0x80000000;
- goto dotoggle;
- }case GETCOOKIE:
- inject(mysprintf("%t@@BEAUTIFY SETCOOKIE %d",COMMENT_PREFIX,_commandState.beauty));
- return false;
- case SETCOOKIE:
- if(!(commandstream>>_commandState.beauty)){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[BEAUTIFY].name);
+ case USEOLDSPRITENUMS:
+ commandstream >> command_part;
+ if (!commandstream) return true;
+ id = find_command(command_part, ext);
+ if (id == ON)
+ _commandState.useoldnums = true;
+ else if (id == OFF)
+ _commandState.useoldnums = false;
+ else {
+ IssueMessage(0, COMMAND_INVALID_ARG, gen[USEOLDSPRITENUMS].name);
return true;
}
break;
- case USEESCAPES:
- togglebit = 0x2000;
- goto dotoggle;
+ /*case VERBOSE:{
+ uint level;
+ if(!(commandstream>>level)||level>2){
+ IssueMessage(0,COMMAND_INVALID_ARG,gen[VERBOSE].name);
+ return true;
+ }
+ _commandState.verbose=level;
+ break;
+ }*/
+ /* Add case condition for new comment commands here.
+ * The order in this function should be the same as the order in command.h.
+ */
+ case -1:
+ IssueMessage(0, COMMAND_UNKNOWN, command_part.c_str());
+ return true;
default:
- INTERNAL_ERROR(command,find_command(command_part,beaut));
-dotoggle:
- commandstream>>command_part;
- val=find_command(command_part,beaut);
- if(!commandstream||val==(uint)-1){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[BEAUTIFY].name);
- return true;
- }
- if(val==OFF)_commandState.beauty&=~togglebit;
- else _commandState.beauty|=togglebit;
- }
- commandstream>>command_part;
- if(_commandState.locked)_commandState=_CLstate;
- return find_command(command_part,preserve)!=NOPRESERVE;
- }case CLEARACTION2:
- final123();
- Init123();
- AutoConsoleMessages();//final123 calls ManualConsoleMessages();
- break;
- case CLEARACTIONF:
- finalF();
- InitF();
- AutoConsoleMessages();//finalF calls ManualConsoleMessages();
- break;
- case TESTID2:{
- int feature;
- commandstream>>setbase(16)>>feature>>id;
- if(!commandstream)
- id=feature;
- else if(!IsValid2Feature(feature)){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[TESTID2].name);
- return true;
- }else{
- inject(mysprintf("%t@@TESTID2 %2x",COMMENT_PREFIX,id));
- return false;
- }
- sanity_test_id(id);
- return true;
- }case DEFINEID2:{
- int feature;
- commandstream>>setbase(16)>>feature>>id;
- if(!commandstream)
- id=feature;
- else if(!IsValid2Feature(feature)){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[DEFINEID2].name);
- return true;
- }
- sanity_define_id(feature,id);
- return true;
- }case LOCATEID2:{
- int feature;
- commandstream>>setbase(16)>>feature>>id;
- if(!commandstream)
- id=feature;
- else if(!IsValid2Feature(feature)){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[LOCATEID2].name);
- return true;
- }else{
- inject(mysprintf("%t@@LOCATEID2 %2x",COMMENT_PREFIX,id));
- return false;
- }
- inject("//@@PRESERVEMESSAGES NOPRESERVE");
- inject(mysprintf("//!!LOCATEID2 %2x %2x: %d",sanity_get_feature(id),id,sanity_locate_id(id)));
- if(GetState(REMOVEMESSAGES))inject("//@@REMOVEMESSAGES NOPRESERVE");
- break;
- }case USEOLDSPRITENUMS:
- commandstream>>command_part;
- if(!commandstream)return true;
- id=find_command(command_part,ext);
- if(id==ON)_commandState.useoldnums=true;
- else if(id==OFF)_commandState.useoldnums=false;
- else{
- IssueMessage(0,COMMAND_INVALID_ARG,gen[USEOLDSPRITENUMS].name);
- return true;
- }
- break;
- /*case VERBOSE:{
- uint level;
- if(!(commandstream>>level)||level>2){
- IssueMessage(0,COMMAND_INVALID_ARG,gen[VERBOSE].name);
- return true;
- }
- _commandState.verbose=level;
- break;
- }*/
-/* Add case condition for new comment commands here.
- * The order in this function should be the same as the order in command.h.
- */
- case -1:
- IssueMessage(0,COMMAND_UNKNOWN,command_part.c_str());
- return true;
- default:
- INTERNAL_ERROR(find_command(command_part,gen),find_command(command_part,gen));
+ INTERNAL_ERROR(find_command(command_part, gen), find_command(command_part, gen));
}
- commandstream>>command_part;
- if(_commandState.locked)_commandState=_CLstate;
- return find_command(command_part,preserve)!=NOPRESERVE;
+ commandstream >> command_part;
+ if (_commandState.locked) _commandState = _CLstate;
+ return find_command(command_part, preserve) != NOPRESERVE;
}
-int GetState(enum gen type){
- switch(type){
- CASE(REMOVEMESSAGES,remove_messages);
- CASE(LINT,sanity_messages);
- CASE(DIFF,diff);
- CASE(REALSPRITES,real);
- CASE(BEAUTIFY,beautifier);
- CASE(USEOLDSPRITENUMS,useoldnums);
-// CASE(VERBOSE,verbose);
-/* Add CASE(COMMAND,variable) macros for new comment commands here.
- * The order in this function should be the same as the order in command.h.*/
+int GetState(enum gen type)
+{
+ switch (type) {
+ CASE(REMOVEMESSAGES, remove_messages);
+ CASE(LINT, sanity_messages);
+ CASE(DIFF, diff);
+ CASE(REALSPRITES, real);
+ CASE(BEAUTIFY, beautifier);
+ CASE(USEOLDSPRITENUMS, useoldnums);
+ // CASE(VERBOSE,verbose);
+ /* Add CASE(COMMAND,variable) macros for new comment commands here.
+ * The order in this function should be the same as the order in command.h.*/
DEFAULT(type);
}
}
-
-uint GetState(enum beaut type,int arg){
- const uint&beaut=_commandState.beauty;
- switch(type){
- case MAXLEN:return beaut&0xFF;
+uint GetState(enum beaut type, int arg)
+{
+ const uint& beaut = _commandState.beauty;
+ switch (type) {
+ case MAXLEN:
+ return beaut & 0xFF;
case LEADINGSPACE:
- return(beaut>>(16+5*arg))&0x1F;
- case QUOTEHIGHASCII:return beaut&0x100;
- case QUOTEUTF8:return beaut&0x200;
- case HEXGRFID:return beaut&0x400;
- case LINEBREAKS:return(((beaut&0x1800)>>11)+2)&3;
- case USEESCAPES:return beaut&0x2000;
- case CONVERTONLY:return beaut&0x80000000;
- DEFAULT(type);
+ return (beaut >> (16 + 5 * arg)) & 0x1F;
+ case QUOTEHIGHASCII:
+ return beaut & 0x100;
+ case QUOTEUTF8:
+ return beaut & 0x200;
+ case HEXGRFID:
+ return beaut & 0x400;
+ case LINEBREAKS:
+ return (((beaut & 0x1800) >> 11) + 2) & 3;
+ case USEESCAPES:
+ return beaut & 0x2000;
+ case CONVERTONLY:
+ return beaut & 0x80000000;
+ DEFAULT(type);
}
}
@@ -504,211 +589,243 @@
#undef END_MESSAGES
#undef MESSAGE_EX
-#define MESSAGE(name,message,props)name,
-#define START_MESSAGES(lang) int msg_type[]={
-#define END_MESSAGES() };
-#define MESSAGE_EX(name,msg,props,loc,base) base,
+#define MESSAGE(name, message, props) name,
+#define START_MESSAGES(lang) int msg_type[] = {
+#define END_MESSAGES() \
+ } \
+ ;
+#define MESSAGE_EX(name, msg, props, loc, base) base,
#include "lang/message_english.h"
-bool GetWarn(int message,int minSan){
- message=msg_type[message];
- switch(crCommandState.warnstate[message]){
- case ENABLE:return true;
- case DISABLE:if(minSan>=ERROR)return false;
+bool GetWarn(int message, int minSan)
+{
+ message = msg_type[message];
+ switch (crCommandState.warnstate[message]) {
+ case ENABLE:
+ return true;
+ case DISABLE:
+ if (minSan >= ERROR) return false;
}
- return GetState(LINT)>=minSan;
+ return GetState(LINT) >= minSan;
}
-void SetVar(const string&var,const string&value){
+void SetVar(const string& var, const string& value)
+{
int val;
string::size_type offs;
- if((offs=value.find('('))==NPOS){
- const char*pch=value.c_str();
- while(isspace(*pch))pch++;
- val=atoi(pch);
- }else{
- val=DoCalc(value,offs);
- if(offs==NPOS)return;
+ if ((offs = value.find('(')) == NPOS) {
+ const char* pch = value.c_str();
+ while (isspace(*pch)) pch++;
+ val = atoi(pch);
+ } else {
+ val = DoCalc(value, offs);
+ if (offs == NPOS) return;
}
_varmap[var] = val;
}
-int GetVar(const string&var,int&err){
- map<string,int>::const_iterator it;
- if((it=_varmap.find(var))!=_varmap.end())return it->second;
- IssueMessage(0,(RenumMessageId)(err=UNDEF_VAR),var.c_str());
+int GetVar(const string& var, int& err)
+{
+ map<string, int>::const_iterator it;
+ if ((it = _varmap.find(var)) != _varmap.end()) return it->second;
+ IssueMessage(0, (RenumMessageId)(err = UNDEF_VAR), var.c_str());
SetCode(EPARSE);
return 0;
}
-string ReadVar(istream&in){
+string ReadVar(istream& in)
+{
eat_white(in);
int ch;
- string delim="=()+/-*",var;
- while(!isspace(ch=in.get())&&delim.find((char)ch)==NPOS&&ch!=EOF)var+=(char)ch;
- if(ch==EOF)var="";
- else in.unget();
+ string delim = "=()+/-*", var;
+ while (!isspace(ch = in.get()) && delim.find((char)ch) == NPOS && ch != EOF) var += (char)ch;
+ if (ch == EOF)
+ var = "";
+ else
+ in.unget();
return var;
}
-int ReadNum(istream&in){
- if (in.get()=='0') {
- if (in.get()=='x') in>>setbase(16);
- else{
- in.unget()>>setbase(8);
- if (!isdigit(in.peek()))
- return 0;
+int ReadNum(istream& in)
+{
+ if (in.get() == '0') {
+ if (in.get() == 'x')
+ in >> setbase(16);
+ else {
+ in.unget() >> setbase(8);
+ if (!isdigit(in.peek())) return 0;
}
- } else in.unget()>>setbase(10);
+ } else
+ in.unget() >> setbase(10);
int ret;
- in>>ret;
+ in >> ret;
return ret;
}
-int DoCalc(istream&data,int&err){
- stack<int>nums;
+int DoCalc(istream& data, int& err)
+{
+ stack<int> nums;
// the unary and binary op charcters.
- string unyops="-~)",
- binops="+-*/%|&^<>";
- int ch,l;
- while(true){
- ch=eat_white(data).get();
- if(isdigit(ch)){
+ string unyops = "-~)", binops = "+-*/%|&^<>";
+ int ch, l;
+ while (true) {
+ ch = eat_white(data).get();
+ if (isdigit(ch)) {
data.unget();
nums.push(ReadNum(data));
continue;
}
- if(ch == '-'){ // a minus followed immediately by digits is a negative number
- if(isdigit(data.peek())){
+ if (ch == '-') { // a minus followed immediately by digits is a negative number
+ if (isdigit(data.peek())) {
nums.push(-ReadNum(data));
continue;
}
}
- if(unyops.find((char)ch)!=NPOS){
- if(nums.size()<1){
- IssueMessage(0,(RenumMessageId)(err=BAD_RPN),ch);
+ if (unyops.find((char)ch) != NPOS) {
+ if (nums.size() < 1) {
+ IssueMessage(0, (RenumMessageId)(err = BAD_RPN), ch);
return 0;
}
l = nums.top();
- switch(ch){
- case '~': nums.top() = ~l; continue;
- case ')': return l;
- case '-':
- if (data.peek() == '-'){
- data.ignore();
- nums.top() = -l;
+ switch (ch) {
+ case '~':
+ nums.top() = ~l;
continue;
- }
- break;
- DEFAULT(ch);
+ case ')':
+ return l;
+ case '-':
+ if (data.peek() == '-') {
+ data.ignore();
+ nums.top() = -l;
+ continue;
+ }
+ break;
+ DEFAULT(ch);
}
}
- if(binops.find((char)ch)!=NPOS){
- if(nums.size()<2){
- IssueMessage(0,(RenumMessageId)(err=BAD_RPN),ch);
+ if (binops.find((char)ch) != NPOS) {
+ if (nums.size() < 2) {
+ IssueMessage(0, (RenumMessageId)(err = BAD_RPN), ch);
return 0;
}
int r;
- r=nums.top();
+ r = nums.top();
nums.pop();
- l=nums.top();
- switch(ch){
- case'+':nums.top()=l+r;break;
- case'-':nums.top()=l-r;break;
- case'*':nums.top()=l*r;break;
- case'/':nums.top()=l/r;break;
- case'%':nums.top()=l%r;break;
- case'^':nums.top()=l^r;break;
- case'&':nums.top()=l&r;break;
- case'|':nums.top()=l|r;break;
- case'<':
- if(data.get()=='<'){
- nums.top()=l<<r;
+ l = nums.top();
+ switch (ch) {
+ case '+':
+ nums.top() = l + r;
break;
- }else{
- IssueMessage(0,(RenumMessageId)(err=BAD_RPN),ch);
- return 0;
- }
- case'>':
- if(data.get()=='>'){
- nums.top()=l>>r;
+ case '-':
+ nums.top() = l - r;
break;
- }else{
- IssueMessage(0,(RenumMessageId)(err=BAD_RPN),ch);
- return 0;
- }
- DEFAULT(ch);
+ case '*':
+ nums.top() = l * r;
+ break;
+ case '/':
+ nums.top() = l / r;
+ break;
+ case '%':
+ nums.top() = l % r;
+ break;
+ case '^':
+ nums.top() = l ^ r;
+ break;
+ case '&':
+ nums.top() = l & r;
+ break;
+ case '|':
+ nums.top() = l | r;
+ break;
+ case '<':
+ if (data.get() == '<') {
+ nums.top() = l << r;
+ break;
+ } else {
+ IssueMessage(0, (RenumMessageId)(err = BAD_RPN), ch);
+ return 0;
+ }
+ case '>':
+ if (data.get() == '>') {
+ nums.top() = l >> r;
+ break;
+ } else {
+ IssueMessage(0, (RenumMessageId)(err = BAD_RPN), ch);
+ return 0;
+ }
+ DEFAULT(ch);
}
- }else if(ch==EOF){
- IssueMessage(0,(RenumMessageId)(err=BAD_RPN_EOF));
+ } else if (ch == EOF) {
+ IssueMessage(0, (RenumMessageId)(err = BAD_RPN_EOF));
return 0;
- }else{
- data.unget(); // And now, restore first character of the var name.
- string var=ReadVar(data);
- nums.push(GetVar(var,err));
- if(err)return 0;
+ } else {
+ data.unget(); // And now, restore first character of the var name.
+ string var = ReadVar(data);
+ nums.push(GetVar(var, err));
+ if (err) return 0;
}
}
}
-int DoCalc(const string&data,string::size_type&offs){
+int DoCalc(const string& data, string::size_type& offs)
+{
istringstream in(data);
- in.ignore((int)offs+1);
- int err=0,ret=DoCalc(in,err);
- offs=err?NPOS:data.find(')',offs)+1;
+ in.ignore((int)offs + 1);
+ int err = 0, ret = DoCalc(in, err);
+ offs = err ? NPOS : data.find(')', offs) + 1;
return ret;
}
/*int DoCalc(istringstream&data,int&err){
- char ch=eat_white(data).peek();
- int l,r,op;
- if(isdigit(ch))data>>l;
- else if(ch=='('){
- l=DoCalc(data.ignore(),err);
- if(err)return l;
- }else{
- string var;
- data>>var;
- l=GetVar(var,err);
- if(err)return l;
- }
- eat_white(data).get(ch);
- if(ch==')')return l;
- string ops="+-*" "/";
- int op=(int)ops.find(ch);
- if(op==NPOS){
- err=NOT_OP;
- return ch;
- }
- if(isdigit(ch))data>>r;
- else if(ch=='('){
- r=DoCalc(data.ignore(),err);
- if(err)return r;
- }else{
- string var;
- data>>var;
- r=GetVar(var,err);
- if(err)return r;
- }
- switch(op){
- case 0:return l+r;
- case 1:return l-r;
- case 2:return l*r;
- case 3:return l/r;
- DEFAULT(DoCalc,op);
- }
+ char ch=eat_white(data).peek();
+ int l,r,op;
+ if(isdigit(ch))data>>l;
+ else if(ch=='('){
+ l=DoCalc(data.ignore(),err);
+ if(err)return l;
+ }else{
+ string var;
+ data>>var;
+ l=GetVar(var,err);
+ if(err)return l;
+ }
+ eat_white(data).get(ch);
+ if(ch==')')return l;
+ string ops="+-*" "/";
+ int op=(int)ops.find(ch);
+ if(op==NPOS){
+ err=NOT_OP;
+ return ch;
+ }
+ if(isdigit(ch))data>>r;
+ else if(ch=='('){
+ r=DoCalc(data.ignore(),err);
+ if(err)return r;
+ }else{
+ string var;
+ data>>var;
+ r=GetVar(var,err);
+ if(err)return r;
+ }
+ switch(op){
+ case 0:return l+r;
+ case 1:return l-r;
+ case 2:return l*r;
+ case 3:return l/r;
+ DEFAULT(DoCalc,op);
+ }
}
int DoCalc(const string&data,size_t&offs){
- char ch;
- int l=0,r=0,op=0;
- while(true){
- if(isspace(ch=data[offs++]))continue;
- if(ch=='(')(op?r:l)=DoCalc(data,offs);
- else if(ops.find(ch)!=NPOS)op=ops.find(ch)+1;
- else if(ch>='0'&&ch<='9'){
- (op?r:l)*=10;
- (op?r:l)+=ch-'0';
- }else if(ch==')')
+ char ch;
+ int l=0,r=0,op=0;
+ while(true){
+ if(isspace(ch=data[offs++]))continue;
+ if(ch=='(')(op?r:l)=DoCalc(data,offs);
+ else if(ops.find(ch)!=NPOS)op=ops.find(ch)+1;
+ else if(ch>='0'&&ch<='9'){
+ (op?r:l)*=10;
+ (op?r:l)+=ch-'0';
+ }else if(ch==')')
}*/
diff --git a/src/command.h b/src/command.h
--- a/src/command.h
+++ b/src/command.h
@@ -25,17 +25,19 @@
#ifndef COMMAND_DATA
/* Be careful when changing these defs; they have to remain compatible
* with the ones in command.cpp.*/
-#define COMMAND_DATA_START(name) enum name{
+#define COMMAND_DATA_START(name) enum name {
#define COMMAND_DATA(command) command,
-#define COMMAND_DATA_EX(placeholder,command) placeholder,
-#define COMMAND_DATA_END() };
-#endif//COMMAND_DATA
+#define COMMAND_DATA_EX(placeholder, command) placeholder,
+#define COMMAND_DATA_END() \
+ } \
+ ;
+#endif // COMMAND_DATA
#ifndef RPNOFF
-#define RPNON() ((GetState(REALSPRITES)&1)==0)
-#define RPNOFF() ((GetState(REALSPRITES)&1)!=0)
-#define COMMENTON() ((GetState(REALSPRITES)&2)==0)
-#define COMMENTOFF() ((GetState(REALSPRITES)&2)!=0)
+#define RPNON() ((GetState(REALSPRITES) & 1) == 0)
+#define RPNOFF() ((GetState(REALSPRITES) & 1) != 0)
+#define COMMENTON() ((GetState(REALSPRITES) & 2) == 0)
+#define COMMENTOFF() ((GetState(REALSPRITES) & 2) != 0)
#endif
COMMAND_DATA_START(gen)
@@ -56,7 +58,7 @@
COMMAND_DATA(DEFINEID2)
COMMAND_DATA(LOCATEID2)
COMMAND_DATA(USEOLDSPRITENUMS)
-//COMMAND_DATA(VERBOSE)
+// COMMAND_DATA(VERBOSE)
/* Add new comment commands here; if they need arguments, create a new
* COMMENT_DATA_START/.../COMMENT_DATA_END block.
* Also add code to parse_comment in command.cpp and, if necessary, one or
@@ -94,8 +96,8 @@
COMMAND_DATA(COMMENTON)
COMMAND_DATA_END()
-COMMAND_DATA_START(beaut)//Be sure to update GetState(enum beaut) if necessary
-COMMAND_DATA_EX(__NOUSE,OFF)//OFF is already defined in enum san. Same numeric value is vital for this trick.
+COMMAND_DATA_START(beaut) // Be sure to update GetState(enum beaut) if necessary
+COMMAND_DATA_EX(__NOUSE, OFF) // OFF is already defined in enum san. Same numeric value is vital for this trick.
COMMAND_DATA(ON)
COMMAND_DATA(MAXLEN)
COMMAND_DATA(QUOTEHIGHASCII)
@@ -110,24 +112,24 @@
COMMAND_DATA_END()
COMMAND_DATA_START(ext)
-COMMAND_DATA_EX(__NOUSE2,OFF)
-COMMAND_DATA_EX(__NOUSE3,ON)
-//COMMAND_DATA(INOUTPUT)
+COMMAND_DATA_EX(__NOUSE2, OFF)
+COMMAND_DATA_EX(__NOUSE3, ON)
+// COMMAND_DATA(INOUTPUT)
COMMAND_DATA_END()
#ifndef _RENUM_COMMAND_H_FUNCTIONS_INCLUDED_
#define _RENUM_COMMAND_H_FUNCTIONS_INCLUDED_
int GetState(enum gen);
-uint GetState(enum beaut,int =0);
-bool GetWarn(int,int);
+uint GetState(enum beaut, int = 0);
+bool GetWarn(int, int);
bool is_command(const string&);
bool parse_comment(const string&);
void reset_commands();
-int DoCalc(const string&,size_t&);
-int DoCalc(istream&,int&);
+int DoCalc(const string&, size_t&);
+int DoCalc(istream&, int&);
bool CLCommand(int);
-#endif//_RENUM_COMMAND_H_FUNCTIONS_INCLUDED_
+#endif //_RENUM_COMMAND_H_FUNCTIONS_INCLUDED_
-#endif//_RENUM_COMMAND_H_INCLUDED_
+#endif //_RENUM_COMMAND_H_INCLUDED_
diff --git a/src/conv.h b/src/conv.h
--- a/src/conv.h
+++ b/src/conv.h
@@ -2,73 +2,71 @@
// convert between DOS and Windows GRF files
// map DOS to Windows
-int palmap0[] = {
- 0, 215, 216, 136, 88, 106, 32, 33, // 0..7
- 40, 245, 10, 11, 12, 13, 14, 15, // 8..15
- 16, 17, 18, 19, 20, 21, 22, 23, // 16..23
- 24, 25, 26, 27, 28, 29, 30, 31, // 24..31
- 53, 107, 34, 35, 36, 37, 38, 39, // 32..39
- 178, 41, 42, 43, 44, 45, 46, 47, // 40..47
- 48, 49, 50, 51, 52, 53, 54, 55, // 48..55
- 56, 57, 58, 59, 60, 61, 62, 63, // 56..63
- 64, 65, 66, 67, 68, 69, 70, 71, // 64..71
- 72, 73, 74, 75, 76, 77, 78, 79, // 72..79
- 80, 81, 82, 83, 84, 85, 86, 87, // 80..87
- 96, 89, 90, 91, 92, 93, 94, 95, // 88..95
- 96, 97, 98, 99, 100, 101, 102, 103, // 96..103
- 104, 105, 53, 107, 108, 109, 110, 111, // 104..111
- 112, 113, 114, 115, 116, 117, 118, 119, // 112..119
- 120, 121, 122, 123, 124, 125, 126, 127, // 120..127
- 128, 129, 130, 131, 132, 133, 134, 135, // 128..135
- 170, 137, 138, 139, 140, 141, 142, 143, // 136..143
- 144, 145, 146, 147, 148, 149, 150, 151, // 144..151
- 152, 153, 154, 155, 156, 157, 158, 159, // 152..159
- 160, 161, 162, 163, 164, 165, 166, 167, // 160..167
- 168, 169, 170, 171, 172, 173, 174, 175, // 168..175
- 176, 177, 178, 179, 180, 181, 182, 183, // 176..183
- 184, 185, 186, 187, 188, 189, 190, 191, // 184..191
- 192, 193, 194, 195, 196, 197, 198, 199, // 192..199
- 200, 201, 202, 203, 204, 205, 206, 207, // 200..207
- 208, 209, 210, 211, 212, 213, 214, 7, // 208..215
- 8, 9, 246, 247, 248, 249, 250, 251, // 216..223
- 252, 253, 254, 230, 231, 227, 228, 229, // 224..231
- 236, 237, 238, 232, 233, 234, 235, 184, // 232..239
- 70, 241, 242, 244, 243, 220, 221, 217, // 240..247
- 218, 219, 226, 222, 223, 224, 225, 15, // 248..255
+int palmap0[] = {0, 215, 216, 136, 88, 106, 32, 33, // 0..7
+ 40, 245, 10, 11, 12, 13, 14, 15, // 8..15
+ 16, 17, 18, 19, 20, 21, 22, 23, // 16..23
+ 24, 25, 26, 27, 28, 29, 30, 31, // 24..31
+ 53, 107, 34, 35, 36, 37, 38, 39, // 32..39
+ 178, 41, 42, 43, 44, 45, 46, 47, // 40..47
+ 48, 49, 50, 51, 52, 53, 54, 55, // 48..55
+ 56, 57, 58, 59, 60, 61, 62, 63, // 56..63
+ 64, 65, 66, 67, 68, 69, 70, 71, // 64..71
+ 72, 73, 74, 75, 76, 77, 78, 79, // 72..79
+ 80, 81, 82, 83, 84, 85, 86, 87, // 80..87
+ 96, 89, 90, 91, 92, 93, 94, 95, // 88..95
+ 96, 97, 98, 99, 100, 101, 102, 103, // 96..103
+ 104, 105, 53, 107, 108, 109, 110, 111, // 104..111
+ 112, 113, 114, 115, 116, 117, 118, 119, // 112..119
+ 120, 121, 122, 123, 124, 125, 126, 127, // 120..127
+ 128, 129, 130, 131, 132, 133, 134, 135, // 128..135
+ 170, 137, 138, 139, 140, 141, 142, 143, // 136..143
+ 144, 145, 146, 147, 148, 149, 150, 151, // 144..151
+ 152, 153, 154, 155, 156, 157, 158, 159, // 152..159
+ 160, 161, 162, 163, 164, 165, 166, 167, // 160..167
+ 168, 169, 170, 171, 172, 173, 174, 175, // 168..175
+ 176, 177, 178, 179, 180, 181, 182, 183, // 176..183
+ 184, 185, 186, 187, 188, 189, 190, 191, // 184..191
+ 192, 193, 194, 195, 196, 197, 198, 199, // 192..199
+ 200, 201, 202, 203, 204, 205, 206, 207, // 200..207
+ 208, 209, 210, 211, 212, 213, 214, 7, // 208..215
+ 8, 9, 246, 247, 248, 249, 250, 251, // 216..223
+ 252, 253, 254, 230, 231, 227, 228, 229, // 224..231
+ 236, 237, 238, 232, 233, 234, 235, 184, // 232..239
+ 70, 241, 242, 244, 243, 220, 221, 217, // 240..247
+ 218, 219, 226, 222, 223, 224, 225, 15, // 248..255
};
// map Windows to DOS
-int palmap1[] = {
- 0, 180, 2, 3, 4, 5, 6, 215, // 0..7
- 216, 219, 10, 11, 12, 13, 14, 15, // 8..15
- 16, 17, 18, 19, 20, 21, 22, 23, // 16..23
- 24, 25, 26, 27, 28, 29, 30, 31, // 24..31
- 6, 7, 34, 35, 36, 37, 38, 39, // 32..39
- 8, 41, 42, 43, 44, 45, 46, 47, // 40..47
- 48, 49, 50, 51, 52, 53, 54, 55, // 48..55
- 56, 57, 58, 59, 60, 61, 62, 63, // 56..63
- 64, 65, 66, 67, 68, 69, 70, 71, // 64..71
- 72, 73, 74, 75, 76, 77, 78, 79, // 72..79
- 80, 81, 82, 83, 84, 85, 86, 87, // 80..87
- 4, 89, 90, 91, 92, 93, 94, 95, // 88..95
- 96, 97, 98, 99, 100, 101, 102, 103, // 96..103
- 104, 105, 5, 107, 108, 109, 110, 111, // 104..111
- 112, 113, 114, 115, 116, 117, 118, 119, // 112..119
- 120, 121, 122, 123, 124, 125, 126, 127, // 120..127
- 128, 129, 130, 131, 132, 133, 134, 135, // 128..135
- 3, 137, 138, 139, 140, 141, 142, 143, // 136..143
- 144, 145, 146, 147, 148, 149, 150, 151, // 144..151
- 152, 153, 154, 155, 156, 157, 158, 159, // 152..159
- 160, 161, 162, 163, 164, 165, 166, 167, // 160..167
- 168, 169, 170, 171, 172, 173, 174, 175, // 168..175
- 176, 177, 178, 179, 180, 181, 182, 183, // 176..183
- 184, 185, 186, 187, 188, 189, 190, 191, // 184..191
- 192, 193, 194, 195, 196, 197, 198, 199, // 192..199
- 200, 201, 202, 203, 204, 205, 206, 207, // 200..207
- 208, 209, 210, 211, 212, 213, 214, 1, // 208..215
- 2, 247, 248, 249, 245, 246, 251, 252, // 216..223
- 253, 254, 250, 229, 230, 231, 227, 228, // 224..231
- 235, 236, 237, 238, 232, 233, 234, 239, // 232..239
- 240, 241, 242, 244, 243, 9, 218, 219, // 240..247
- 220, 221, 222, 223, 224, 225, 226, 255, // 248..255
+int palmap1[] = {0, 180, 2, 3, 4, 5, 6, 215, // 0..7
+ 216, 219, 10, 11, 12, 13, 14, 15, // 8..15
+ 16, 17, 18, 19, 20, 21, 22, 23, // 16..23
+ 24, 25, 26, 27, 28, 29, 30, 31, // 24..31
+ 6, 7, 34, 35, 36, 37, 38, 39, // 32..39
+ 8, 41, 42, 43, 44, 45, 46, 47, // 40..47
+ 48, 49, 50, 51, 52, 53, 54, 55, // 48..55
+ 56, 57, 58, 59, 60, 61, 62, 63, // 56..63
+ 64, 65, 66, 67, 68, 69, 70, 71, // 64..71
+ 72, 73, 74, 75, 76, 77, 78, 79, // 72..79
+ 80, 81, 82, 83, 84, 85, 86, 87, // 80..87
+ 4, 89, 90, 91, 92, 93, 94, 95, // 88..95
+ 96, 97, 98, 99, 100, 101, 102, 103, // 96..103
+ 104, 105, 5, 107, 108, 109, 110, 111, // 104..111
+ 112, 113, 114, 115, 116, 117, 118, 119, // 112..119
+ 120, 121, 122, 123, 124, 125, 126, 127, // 120..127
+ 128, 129, 130, 131, 132, 133, 134, 135, // 128..135
+ 3, 137, 138, 139, 140, 141, 142, 143, // 136..143
+ 144, 145, 146, 147, 148, 149, 150, 151, // 144..151
+ 152, 153, 154, 155, 156, 157, 158, 159, // 152..159
+ 160, 161, 162, 163, 164, 165, 166, 167, // 160..167
+ 168, 169, 170, 171, 172, 173, 174, 175, // 168..175
+ 176, 177, 178, 179, 180, 181, 182, 183, // 176..183
+ 184, 185, 186, 187, 188, 189, 190, 191, // 184..191
+ 192, 193, 194, 195, 196, 197, 198, 199, // 192..199
+ 200, 201, 202, 203, 204, 205, 206, 207, // 200..207
+ 208, 209, 210, 211, 212, 213, 214, 1, // 208..215
+ 2, 247, 248, 249, 245, 246, 251, 252, // 216..223
+ 253, 254, 250, 229, 230, 231, 227, 228, // 224..231
+ 235, 236, 237, 238, 232, 233, 234, 239, // 232..239
+ 240, 241, 242, 244, 243, 9, 218, 219, // 240..247
+ 220, 221, 222, 223, 224, 225, 226, 255, // 248..255
};
diff --git a/src/data.cpp b/src/data.cpp
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -20,118 +20,113 @@
*/
#ifdef _WIN32
-#include"win32.h"
+#include "win32.h"
#endif
-#include<cstdio>
-#include<cstdlib>
-#include<cassert>
-#include<string>
-#include<sys/stat.h>
-#include<cstdarg>
-#include<errno.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cassert>
+#include <string>
+#include <sys/stat.h>
+#include <cstdarg>
+#include <errno.h>
#ifndef _WIN32
-# include<unistd.h>
+#include <unistd.h>
#endif
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"globals.h"
-#include"data.h"
-#include"messages.h"
-#include"win32.h"
-#include"sanity_defines.h"
-#include"strings.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "globals.h"
+#include "data.h"
+#include "messages.h"
+#include "win32.h"
+#include "sanity_defines.h"
+#include "strings.h"
-//Let's dump the data files into the source code. That sounds like fun, right?
+// Let's dump the data files into the source code. That sounds like fun, right?
/* Data file format
- ================
+ ================
- Files that appear before the DATA_FILE(feat) line in data.h have two leading
- bytes that are checked and then eaten by myfopen.
+ Files that appear before the DATA_FILE(feat) line in data.h have two leading
+ bytes that are checked and then eaten by myfopen.
- The first byte is a format byte; start it at \x00. Each time the file format
- gets updated (ie the file reader changes), increment it and reset
- the version byte to \x00.
+ The first byte is a format byte; start it at \x00. Each time the file format
+ gets updated (ie the file reader changes), increment it and reset
+ the version byte to \x00.
- The second byte is a version byte; increment it every time the file
- gets updated.
+ The second byte is a version byte; increment it every time the file
+ gets updated.
- Files that depend on feat.dat (appear below it in data.h), have three
- leading bytes that are eaten by myfopen. The first two are as described
- above.
+ Files that depend on feat.dat (appear below it in data.h), have three
+ leading bytes that are eaten by myfopen. The first two are as described
+ above.
- The third byte is the maximum feature supported by this file.
- This should usually match the third byte of _datfeat, but under some
- circumstances, it is appropriate to increment the this byte without
- changing _datfeat.
+ The third byte is the maximum feature supported by this file.
+ This should usually match the third byte of _datfeat, but under some
+ circumstances, it is appropriate to increment the this byte without
+ changing _datfeat.
*/
-
#define NDF_HEADER(format, version) format, version
#define NDF_END 0
-
// ---------------------------------------------------------------------------
// ------------------------- Feature-independent data ------------------------
// ---------------------------------------------------------------------------
/* Action 7/9/D variables */
-#define NOTHING 0x00 /* Only VarAction2 access */
-#define BITMASK 0x00 /* Bitmask variable, use instead of B, W or D */
-#define B 0x01 /* Byte access allowed */
-#define W 0x02 /* Word access allowed */
-#define D 0x04 /* DWord access allowed */
-#define WD 0x20 /* Action D Write access allowed */
-#define RD 0x40 /* Action D Read access allowed */
-#define R7 0x80 /* Action 7 Read access allowed */
-static const unsigned char _dat79Dv[]={
-NDF_HEADER(0x20, 5),
-/* Number of variables: */ 0x25,
+#define NOTHING 0x00 /* Only VarAction2 access */
+#define BITMASK 0x00 /* Bitmask variable, use instead of B, W or D */
+#define B 0x01 /* Byte access allowed */
+#define W 0x02 /* Word access allowed */
+#define D 0x04 /* DWord access allowed */
+#define WD 0x20 /* Action D Write access allowed */
+#define RD 0x40 /* Action D Read access allowed */
+#define R7 0x80 /* Action 7 Read access allowed */
+static const unsigned char _dat79Dv[] = {NDF_HEADER(0x20, 5),
+ /* Number of variables: */ 0x25,
-/*80*/ NOTHING,
-/*81*/ B | RD | R7,
-/*82*/ NOTHING,
-/*83*/ B | RD | R7,
-/*84*/ B | D | RD | R7,
-/*85*/ BITMASK | R7,
-/*86*/ BITMASK | R7,
-/*87*/ NOTHING,
-/*88*/ D | R7,
-/*89*/ NOTHING,
-/*8A*/ NOTHING,
-/*8B*/ W | D | RD | R7,
-/*8C*/ NOTHING,
-/*8D*/ B | RD | R7,
-/*8E*/ B | WD | RD | R7,
-/*8F*/ D | WD | RD | R7,
-/*90*/ NOTHING,
-/*91*/ NOTHING,
-/*92*/ B | RD | R7,
-/*93*/ W | D | WD | RD | R7,
-/*94*/ W | D | WD | RD | R7,
-/*95*/ W | D | WD | RD | R7,
-/*96*/ W | D | WD | RD | R7,
-/*97*/ B | WD | RD | R7,
-/*98*/ NOTHING,
-/*99*/ D | WD,
-/*9A*/ B | W | D | R7,
-/*9B*/ NOTHING,
-/*9C*/ NOTHING,
-/*9D*/ D | RD | R7,
-/*9E*/ D | WD | RD | R7,
-/*9F*/ D | WD,
-/*A0*/ NOTHING,
-/*A1*/ D | RD | R7,
-/*A2*/ D | RD | R7,
-/*A3*/ D | RD | R7,
-/*A4*/ D | RD | R7,
-NDF_END
-};
+ /*80*/ NOTHING,
+ /*81*/ B | RD | R7,
+ /*82*/ NOTHING,
+ /*83*/ B | RD | R7,
+ /*84*/ B | D | RD | R7,
+ /*85*/ BITMASK | R7,
+ /*86*/ BITMASK | R7,
+ /*87*/ NOTHING,
+ /*88*/ D | R7,
+ /*89*/ NOTHING,
+ /*8A*/ NOTHING,
+ /*8B*/ W | D | RD | R7,
+ /*8C*/ NOTHING,
+ /*8D*/ B | RD | R7,
+ /*8E*/ B | WD | RD | R7,
+ /*8F*/ D | WD | RD | R7,
+ /*90*/ NOTHING,
+ /*91*/ NOTHING,
+ /*92*/ B | RD | R7,
+ /*93*/ W | D | WD | RD | R7,
+ /*94*/ W | D | WD | RD | R7,
+ /*95*/ W | D | WD | RD | R7,
+ /*96*/ W | D | WD | RD | R7,
+ /*97*/ B | WD | RD | R7,
+ /*98*/ NOTHING,
+ /*99*/ D | WD,
+ /*9A*/ B | W | D | R7,
+ /*9B*/ NOTHING,
+ /*9C*/ NOTHING,
+ /*9D*/ D | RD | R7,
+ /*9E*/ D | WD | RD | R7,
+ /*9F*/ D | WD,
+ /*A0*/ NOTHING,
+ /*A1*/ D | RD | R7,
+ /*A2*/ D | RD | R7,
+ /*A3*/ D | RD | R7,
+ /*A4*/ D | RD | R7, NDF_END};
#undef B
#undef W
#undef D
@@ -140,54 +135,49 @@
#undef R7
/* Action B
- ========
+ ========
*/
-static const char _datB[]="\x01\x02"
-// Maximum severity:
-"\x03"
-// Number of message types:
-"\x07"
-// Parameter counts for message types:
-"\x02\x02\x02\x03\x02\x02\x02"
-;
-
+static const char _datB[] =
+ "\x01\x02"
+ // Maximum severity:
+ "\x03"
+ // Number of message types:
+ "\x07"
+ // Parameter counts for message types:
+ "\x02\x02\x02\x03\x02\x02\x02";
/* Action 5
* Historical remark:
* The higher nibble in the OPTIONS byte can be used to define the type and alternatives for multiple entries.
* We do not use that anymore, as we want one line per entry.
*/
-#define OPTIONS(num) 0x10 | num /* Number of alternatives wrt. total sprite count */
-#define RECOLOUR 0x81 /* Only allow recolour sprites */
-#define MIXED 0x82 /* Allow both recolour and real sprites */
-#define WORD 0x84 /* Spritecount is larger than a byte and is defined using W() */
-#define OFFSET 0x88 /* Allow replacing sprite ranges with offsets */
-#define W(cnt) cnt & 0xFF, cnt >> 8 /* Construct word count */
-static const unsigned char _dat5[]={
-NDF_HEADER(0x04, 16),
-/*04*/ OFFSET, OPTIONS(3), 0x30, 0x70, 0xF0,
-/*05*/ OFFSET, OPTIONS(1), 0x30,
-/*06*/ OFFSET, OPTIONS(2), 0x4A, 0x5A,
-/*07*/ OPTIONS(1), 0x5D,
-/*08*/ OFFSET, OPTIONS(1), 0x41,
-/*09*/ OFFSET, OPTIONS(1), 0x06,
-/*0A*/ OFFSET | RECOLOUR | WORD, OPTIONS(1), W(0x100),
-/*0B*/ OFFSET, OPTIONS(1), 0x71,
-/*0C*/ OPTIONS(1), 0x85,
-/*0D*/ OPTIONS(2), 0x10, 0x12,
-/*0E*/ MIXED, OPTIONS(1), 0x00,
-/*0F*/ OFFSET, OPTIONS(1), 0x0C,
-/*10*/ OFFSET, OPTIONS(1), 0x0F,
-/*11*/ OFFSET, OPTIONS(1), 0x08,
-/*12*/ OFFSET, OPTIONS(1), 0x08,
-/*13*/ OFFSET, OPTIONS(1), 0x37,
-/*14*/ OFFSET, OPTIONS(1), 0x24,
-/*15*/ OFFSET, OPTIONS(1), 0xAF,
-/*16*/ OFFSET, OPTIONS(1), 0x09,
-/*17*/ OFFSET, OPTIONS(1), 0x10,
-00,
-NDF_END
-};
+#define OPTIONS(num) 0x10 | num /* Number of alternatives wrt. total sprite count */
+#define RECOLOUR 0x81 /* Only allow recolour sprites */
+#define MIXED 0x82 /* Allow both recolour and real sprites */
+#define WORD 0x84 /* Spritecount is larger than a byte and is defined using W() */
+#define OFFSET 0x88 /* Allow replacing sprite ranges with offsets */
+#define W(cnt) cnt & 0xFF, cnt >> 8 /* Construct word count */
+static const unsigned char _dat5[] = {NDF_HEADER(0x04, 16),
+ /*04*/ OFFSET, OPTIONS(3), 0x30, 0x70, 0xF0,
+ /*05*/ OFFSET, OPTIONS(1), 0x30,
+ /*06*/ OFFSET, OPTIONS(2), 0x4A, 0x5A,
+ /*07*/ OPTIONS(1), 0x5D,
+ /*08*/ OFFSET, OPTIONS(1), 0x41,
+ /*09*/ OFFSET, OPTIONS(1), 0x06,
+ /*0A*/ OFFSET | RECOLOUR | WORD, OPTIONS(1), W(0x100),
+ /*0B*/ OFFSET, OPTIONS(1), 0x71,
+ /*0C*/ OPTIONS(1), 0x85,
+ /*0D*/ OPTIONS(2), 0x10, 0x12,
+ /*0E*/ MIXED, OPTIONS(1), 0x00,
+ /*0F*/ OFFSET, OPTIONS(1), 0x0C,
+ /*10*/ OFFSET, OPTIONS(1), 0x0F,
+ /*11*/ OFFSET, OPTIONS(1), 0x08,
+ /*12*/ OFFSET, OPTIONS(1), 0x08,
+ /*13*/ OFFSET, OPTIONS(1), 0x37,
+ /*14*/ OFFSET, OPTIONS(1), 0x24,
+ /*15*/ OFFSET, OPTIONS(1), 0xAF,
+ /*16*/ OFFSET, OPTIONS(1), 0x09,
+ /*17*/ OFFSET, OPTIONS(1), 0x10, 00, NDF_END};
#undef OPTIONS
#undef RECOLOUR
#undef MIXED
@@ -196,25 +186,25 @@
#undef W
/* Text IDs
- ========
+ ========
*/
-static const char _datTextIDs[]="\x04\x09"
-//-0000- -1000- -2000- -3000-
-"\x35\x03\x11\x00\x25\x00\x19\x00\x5D\x00\x11\x00\x6D\x00\x08\x00"
-//-4000- -5000- -6000- -7000-
-"\x11\x00\x3C\x00\x2A\x00\x08\x00\x19\x00\x39\x00\x80\x00\x00\x00"
-//-8000- -9000- -A000- -B000-
-"\x08\x01\x6C\x00\x38\x00\x43\x00\x44\x00\x00\x00\x06\x00\x00\x00"
-//-C000- -D000- -E000- -F000-
-"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x4D\x00\x00\x00\x00\x00\x9B\x01"
-// Number of special string ID ranges:
-"\x03"
-// High bytes of special string IDs:
-"\xC4\xC5\xC9"
-;
+static const char _datTextIDs[] =
+ "\x04\x09"
+ //-0000- -1000- -2000- -3000-
+ "\x35\x03\x11\x00\x25\x00\x19\x00\x5D\x00\x11\x00\x6D\x00\x08\x00"
+ //-4000- -5000- -6000- -7000-
+ "\x11\x00\x3C\x00\x2A\x00\x08\x00\x19\x00\x39\x00\x80\x00\x00\x00"
+ //-8000- -9000- -A000- -B000-
+ "\x08\x01\x6C\x00\x38\x00\x43\x00\x44\x00\x00\x00\x06\x00\x00\x00"
+ //-C000- -D000- -E000- -F000-
+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x4D\x00\x00\x00\x00\x00\x9B\x01"
+ // Number of special string ID ranges:
+ "\x03"
+ // High bytes of special string IDs:
+ "\xC4\xC5\xC9";
/* Callbacks */
-#define W(cnt) cnt & 0xFF, cnt >> 8 /* Construct word count */
+#define W(cnt) cnt & 0xFF, cnt >> 8 /* Construct word count */
#define TRAIN 0x0
#define ROADVEH 0x1
#define SHIP 0x2
@@ -237,38 +227,54 @@
#define NONE 0x80
#define GROUNDVEHICLE MASK(TRAIN) | MASK(ROADVEH)
#define VEHICLE MASK(TRAIN) | MASK(ROADVEH) | MASK(SHIP) | MASK(AIRCRAFT)
-static const unsigned char _datcallbacks[]={
-NDF_HEADER(0x05, 23),
-/* Count: */ W(0x160),
-/* 00*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* 10*/ GROUNDVEHICLE | MASK(SHIP), GROUNDVEHICLE, VEHICLE, STATION, STATION, VEHICLE, GROUNDVEHICLE, HOUSE,
-/* 18*/ MASK(STATION) | VEHICLE, VEHICLE, HOUSE, HOUSE, HOUSE, TRAIN, HOUSE, HOUSE,
-/* 20*/ HOUSE, HOUSE, INDUSTRY, VEHICLE, STATION, INDTILE, INDTILE, INDTILE,
-/* 28*/ INDUSTRY, INDUSTRY, HOUSE, INDTILE, INDTILE, VEHICLE, HOUSE, INDTILE,
-/* 30*/ INDTILE, VEHICLE, VEHICLE, MASK(BRIDGE) | VEHICLE, VEHICLE, INDUSTRY, VEHICLE, INDUSTRY,
-/* 38*/ INDUSTRY, CARGO, INDUSTRY, INDUSTRY, INDTILE, INDUSTRY, NONE, NONE,
-/* 40*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* 50*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* 60*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* 70*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* 80*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* 90*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* A0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* B0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* C0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* D0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* E0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/* F0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/*100*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/*110*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/*120*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/*130*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
-/*140*/ STATION, STATION, STATION, HOUSE, SOUND, CARGO, SIGNAL, CANAL,
-/*148*/ HOUSE, STATION, INDUSTRY, INDUSTRY, INDUSTRY, HOUSE, HOUSE, HOUSE,
-/*150*/ AIRTILE, NONE, AIRTILE, AIRTILE, AIRTILE, AIRPORT, AIRPORT, OBJECT,
-/*158*/ OBJECT, OBJECT, OBJECT, OBJECT, OBJECT, OBJECT, VEHICLE, INDUSTRY,
-NDF_END
-};
+static const unsigned char _datcallbacks[] = {
+ NDF_HEADER(0x05, 23),
+ /* Count: */ W(0x160),
+ /* 00*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* 10*/ GROUNDVEHICLE | MASK(SHIP), GROUNDVEHICLE, VEHICLE, STATION, STATION, VEHICLE, GROUNDVEHICLE, HOUSE,
+ /* 18*/ MASK(STATION) | VEHICLE, VEHICLE, HOUSE, HOUSE, HOUSE, TRAIN, HOUSE, HOUSE,
+ /* 20*/ HOUSE, HOUSE, INDUSTRY, VEHICLE, STATION, INDTILE, INDTILE, INDTILE,
+ /* 28*/ INDUSTRY, INDUSTRY, HOUSE, INDTILE, INDTILE, VEHICLE, HOUSE, INDTILE,
+ /* 30*/ INDTILE, VEHICLE, VEHICLE, MASK(BRIDGE) | VEHICLE, VEHICLE, INDUSTRY, VEHICLE, INDUSTRY,
+ /* 38*/ INDUSTRY, CARGO, INDUSTRY, INDUSTRY, INDTILE, INDUSTRY, NONE, NONE,
+ /* 40*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* 50*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* 60*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* 70*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* 80*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* 90*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* A0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* B0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* C0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* D0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* E0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /* F0*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /*100*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /*110*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /*120*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /*130*/ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ NONE, NONE, NONE, NONE, NONE, NONE, NONE, NONE,
+ /*140*/ STATION, STATION, STATION, HOUSE, SOUND, CARGO, SIGNAL, CANAL,
+ /*148*/ HOUSE, STATION, INDUSTRY, INDUSTRY, INDUSTRY, HOUSE, HOUSE, HOUSE,
+ /*150*/ AIRTILE, NONE, AIRTILE, AIRTILE, AIRTILE, AIRPORT, AIRPORT, OBJECT,
+ /*158*/ OBJECT, OBJECT, OBJECT, OBJECT, OBJECT, OBJECT, VEHICLE, INDUSTRY,
+ NDF_END};
#undef W
#undef TRAIN
#undef ROADVEH
@@ -342,15 +348,17 @@
;
/* Version check data
- ==================
+ ==================
*/
-static const char _datversions[]="\x00\x04"
-// Maximum version (beta):
-"\x09"
-// Revisions (starting from beta 6)
-"\xD8\x01" "\x31\x06" "\x81\x07" "\x70\x11"
-;
-
+static const char _datversions[] =
+ "\x00\x04"
+ // Maximum version (beta):
+ "\x09"
+ // Revisions (starting from beta 6)
+ "\xD8\x01"
+ "\x31\x06"
+ "\x81\x07"
+ "\x70\x11";
/* Features */
#define ACT0 0x01
@@ -368,50 +376,46 @@
#define ACT2_HOUSE 0x03
#define ACT2_INDPROD 0x04
#define ACT2_NONE 0xFF
-static const unsigned char _datfeat[]={
-NDF_HEADER(0x12, 3),
-/* Max. feature: */ 0x11,
+static const unsigned char _datfeat[] = {NDF_HEADER(0x12, 3),
+ /* Max. feature: */ 0x11,
-/*00*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | OVERRIDE3 | GENERIC3 | ACT3_BEFORE_PROP08,
-/*01*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | GENERIC3 | ACT3_BEFORE_PROP08,
-/*02*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | GENERIC3 | ACT3_BEFORE_PROP08,
-/*03*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | OVERRIDE3 | GENERIC3 | ACT3_BEFORE_PROP08,
-/*04*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | GENERIC3,
-/*05*/ ACT0 | ACT1 | ACT3 | ACT4 | ACT3_BEFORE_PROP08,
-/*06*/ ACT0 | ACT4 | EMPTY1 | GENERIC3 | ACT3_BEFORE_PROP08,
-/*07*/ ACT0 | ACT1 | ACT3 | ACT4,
-/*08*/ ACT0,
-/*09*/ ACT0 | ACT1 | ACT3 | ACT4,
-/*0A*/ ACT0 | ACT3 | ACT4,
-/*0B*/ ACT0 | ACT1 | ACT3 | ACT4 | ACT3_BEFORE_PROP08,
-/*0C*/ ACT0,
-/*0D*/ ACT0 | ACT1 | ACT3 | ACT4,
-/*0E*/ EMPTY1 | GENERIC3,
-/*0F*/ ACT0 | ACT1 | ACT3 | ACT4,
-/*10*/ ACT0 | ACT1 | ACT3 | ACT4,
-/*11*/ ACT0 | ACT1 | ACT3 | ACT4,
+ /*00*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | OVERRIDE3 | GENERIC3 | ACT3_BEFORE_PROP08,
+ /*01*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | GENERIC3 | ACT3_BEFORE_PROP08,
+ /*02*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | GENERIC3 | ACT3_BEFORE_PROP08,
+ /*03*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | OVERRIDE3 | GENERIC3 | ACT3_BEFORE_PROP08,
+ /*04*/ ACT0 | ACT1 | ACT3 | ACT4 | EMPTY1 | GENERIC3,
+ /*05*/ ACT0 | ACT1 | ACT3 | ACT4 | ACT3_BEFORE_PROP08,
+ /*06*/ ACT0 | ACT4 | EMPTY1 | GENERIC3 | ACT3_BEFORE_PROP08,
+ /*07*/ ACT0 | ACT1 | ACT3 | ACT4,
+ /*08*/ ACT0,
+ /*09*/ ACT0 | ACT1 | ACT3 | ACT4,
+ /*0A*/ ACT0 | ACT3 | ACT4,
+ /*0B*/ ACT0 | ACT1 | ACT3 | ACT4 | ACT3_BEFORE_PROP08,
+ /*0C*/ ACT0,
+ /*0D*/ ACT0 | ACT1 | ACT3 | ACT4,
+ /*0E*/ EMPTY1 | GENERIC3,
+ /*0F*/ ACT0 | ACT1 | ACT3 | ACT4,
+ /*10*/ ACT0 | ACT1 | ACT3 | ACT4,
+ /*11*/ ACT0 | ACT1 | ACT3 | ACT4,
-/*00*/ ACT2_VEHICLE,
-/*01*/ ACT2_VEHICLE,
-/*02*/ ACT2_VEHICLE,
-/*03*/ ACT2_VEHICLE,
-/*04*/ ACT2_STATION,
-/*05*/ ACT2_CARGO,
-/*06*/ ACT2_CARGO,
-/*07*/ ACT2_HOUSE,
-/*08*/ ACT2_NONE,
-/*09*/ ACT2_HOUSE,
-/*0A*/ ACT2_INDPROD,
-/*0B*/ ACT2_CARGO,
-/*0C*/ ACT2_NONE,
-/*0D*/ ACT2_CARGO,
-/*0E*/ ACT2_VEHICLE,
-/*0F*/ ACT2_HOUSE,
-/*10*/ ACT2_CARGO,
-/*11*/ ACT2_HOUSE,
-
-NDF_END
-};
+ /*00*/ ACT2_VEHICLE,
+ /*01*/ ACT2_VEHICLE,
+ /*02*/ ACT2_VEHICLE,
+ /*03*/ ACT2_VEHICLE,
+ /*04*/ ACT2_STATION,
+ /*05*/ ACT2_CARGO,
+ /*06*/ ACT2_CARGO,
+ /*07*/ ACT2_HOUSE,
+ /*08*/ ACT2_NONE,
+ /*09*/ ACT2_HOUSE,
+ /*0A*/ ACT2_INDPROD,
+ /*0B*/ ACT2_CARGO,
+ /*0C*/ ACT2_NONE,
+ /*0D*/ ACT2_CARGO,
+ /*0E*/ ACT2_VEHICLE,
+ /*0F*/ ACT2_HOUSE,
+ /*10*/ ACT2_CARGO,
+ /*11*/ ACT2_HOUSE, NDF_END};
#undef ACT0
#undef ACT1
#undef ACT3
@@ -428,12 +432,10 @@
#undef ACT2_INDPROD
#undef ACT2_NONE
-
// ---------------------------------------------------------------------------
// ------------------------- Feature-dependent data --------------------------
// ---------------------------------------------------------------------------
-
/* Action 0 properties */
/* Invalid property */
@@ -452,14 +454,14 @@
#define DWORD 0x04
/* Formatting */
-#define QUOTED 0x10 /* Quoted string */
-#define DECIMAL 0x20 /* Escaped decimal */
-#define HEX 0x30 /* Escaped hex */
+#define QUOTED 0x10 /* Quoted string */
+#define DECIMAL 0x20 /* Escaped decimal */
+#define HEX 0x30 /* Escaped hex */
-#define MAGIC 0x08 /* Various meanings */
-#define DATE DECIMAL | MAGIC /* Date, that is days since 1920 if WORD, or since 0 if DWORD. For BYTE it means years since 1920. */
-#define TEXTID WORD | HEX | MAGIC /* Check for valid Text/String ID */
-#define TILEID WORD | MAGIC /* Check for valid tile ID, e.g. industrytile in industrylayout */
+#define MAGIC 0x08 /* Various meanings */
+#define DATE DECIMAL | MAGIC /* Date, that is days since 1920 if WORD, or since 0 if DWORD. For BYTE it means years since 1920. */
+#define TEXTID WORD | HEX | MAGIC /* Check for valid Text/String ID */
+#define TILEID WORD | MAGIC /* Check for valid tile ID, e.g. industrytile in industrylayout */
#define REMAININGSIZE DWORD | HEX | MAGIC /* Value is number of bytes for the property after this length information */
/* Allow multiple assignments to a property. (Only valid outside of SUBDATA) */
@@ -494,251 +496,819 @@
* You can also multiply multiple values using MUL() */
#define REPEAT_N(data, times) 'r', data, times
#define MUL(a, b) 'x', a, b
-#define DATAFROM(offset) offset | 0x80 /* Uses the value read with the token at position 'offset' within the current SUBDATA */
+#define DATAFROM(offset) offset | 0x80 /* Uses the value read with the token at position 'offset' within the current SUBDATA */
/* Repeat 'data' until a certain terminator with length 'length' is encountered */
#define REPEAT_UNTIL(data, length, ...) '*', data, length, __VA_ARGS__
-static const unsigned char _dat0[]={
-NDF_HEADER(0x0E, 1),
-/*Maximum feature:*/ 0x11,
-// Feature 00:
-/*00*/ WORD | DATE, INVALID, BYTE, BYTE | DECIMAL, BYTE | DECIMAL, BYTE, BYTE, BYTE | DECIMAL,
-/*08*/ BYTE, WORD | DECIMAL, INVALID, WORD | DECIMAL, INVALID, BYTE, DWORD, INVALID,
-/*10*/ INVALID, INVALID, BYTE, BYTE, BYTE | DECIMAL, BYTE, BYTE, BYTE,
-/*18*/ BYTE, BYTE, EXTBYTE, WORD | DECIMAL, BYTE, DWORD | HEX, BYTE, BYTE,
-/*20*/ BYTE, BYTE, BYTE, BYTE | DECIMAL, BYTE, BYTE, BYTE | DECIMAL, BYTE,
-/*28*/ WORD | HEX, WORD | HEX, DWORD | DATE, WORD, SUBDATA, SUBDATA,
-END,
-// Subdata - prop 2C:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
-// Subdata - prop 2D:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
+static const unsigned char _dat0[] = {NDF_HEADER(0x0E, 1),
+ /*Maximum feature:*/ 0x11,
+ // Feature 00:
+ /*00*/ WORD | DATE,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ /*08*/ BYTE,
+ WORD | DECIMAL,
+ INVALID,
+ WORD | DECIMAL,
+ INVALID,
+ BYTE,
+ DWORD,
+ INVALID,
+ /*10*/ INVALID,
+ INVALID,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ BYTE,
+ BYTE,
+ /*18*/ BYTE,
+ BYTE,
+ EXTBYTE,
+ WORD | DECIMAL,
+ BYTE,
+ DWORD | HEX,
+ BYTE,
+ BYTE,
+ /*20*/ BYTE,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ /*28*/ WORD | HEX,
+ WORD | HEX,
+ DWORD | DATE,
+ WORD,
+ SUBDATA,
+ SUBDATA,
+ END,
+ // Subdata - prop 2C:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
+ // Subdata - prop 2D:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
-// Feature 01:
-/*00*/ WORD | DATE, INVALID, BYTE, BYTE | DECIMAL, BYTE | DECIMAL, INVALID, BYTE, BYTE | DECIMAL,
-/*08*/ BYTE | DECIMAL, BYTE, DWORD, INVALID, INVALID, INVALID, BYTE, BYTE | DECIMAL,
-/*10*/ BYTE, BYTE, BYTE, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, DWORD | HEX, BYTE,
-/*18*/ BYTE, BYTE, BYTE, BYTE | DECIMAL, BYTE, WORD | HEX, WORD | HEX, DWORD | DATE,
-/*20*/ EXTBYTE, BYTE, WORD, BYTE, SUBDATA, SUBDATA,
-END,
-// Subdata - prop 24:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
-// Subdata - prop 25:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
+ // Feature 01:
+ /*00*/ WORD | DATE,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ /*08*/ BYTE | DECIMAL,
+ BYTE,
+ DWORD,
+ INVALID,
+ INVALID,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ /*10*/ BYTE,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ DWORD | HEX,
+ BYTE,
+ /*18*/ BYTE,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ WORD | HEX,
+ WORD | HEX,
+ DWORD | DATE,
+ /*20*/ EXTBYTE,
+ BYTE,
+ WORD,
+ BYTE,
+ SUBDATA,
+ SUBDATA,
+ END,
+ // Subdata - prop 24:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
+ // Subdata - prop 25:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
-// Feature 02:
-/*00*/ WORD | DATE, INVALID, BYTE, BYTE | DECIMAL, BYTE | DECIMAL, INVALID, BYTE, BYTE | DECIMAL,
-/*08*/ BYTE, BYTE, BYTE, BYTE | DECIMAL, BYTE, WORD | DECIMAL, INVALID, BYTE,
-/*10*/ BYTE, DWORD | HEX, BYTE, BYTE, BYTE, BYTE, BYTE | DECIMAL, BYTE,
-/*18*/ WORD | HEX, WORD | HEX, DWORD | DATE, EXTBYTE, BYTE, WORD, SUBDATA, SUBDATA,
-END,
-// Subdata - prop 1E:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
-// Subdata - prop 1F:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
+ // Feature 02:
+ /*00*/ WORD | DATE,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ /*08*/ BYTE,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ WORD | DECIMAL,
+ INVALID,
+ BYTE,
+ /*10*/ BYTE,
+ DWORD | HEX,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ /*18*/ WORD | HEX,
+ WORD | HEX,
+ DWORD | DATE,
+ EXTBYTE,
+ BYTE,
+ WORD,
+ SUBDATA,
+ SUBDATA,
+ END,
+ // Subdata - prop 1E:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
+ // Subdata - prop 1F:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
-// Feature 03:
-/*00*/ WORD | DATE, INVALID, BYTE, BYTE | DECIMAL, BYTE | DECIMAL, INVALID, BYTE, BYTE | DECIMAL,
-/*08*/ BYTE, BYTE, BYTE, BYTE, BYTE | DECIMAL, BYTE, BYTE, WORD | DECIMAL,
-/*10*/ INVALID, BYTE | DECIMAL, BYTE, DWORD | HEX, BYTE, BYTE, BYTE | DECIMAL, BYTE,
-/*18*/ WORD | HEX, WORD | HEX, DWORD | DATE, EXTBYTE, WORD, SUBDATA, SUBDATA, WORD,
-END,
-// Subdata - prop 1D:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
-// Subdata - prop 1E:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
+ // Feature 03:
+ /*00*/ WORD | DATE,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ INVALID,
+ BYTE,
+ BYTE | DECIMAL,
+ /*08*/ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ BYTE,
+ WORD | DECIMAL,
+ /*10*/ INVALID,
+ BYTE | DECIMAL,
+ BYTE,
+ DWORD | HEX,
+ BYTE,
+ BYTE,
+ BYTE | DECIMAL,
+ BYTE,
+ /*18*/ WORD | HEX,
+ WORD | HEX,
+ DWORD | DATE,
+ EXTBYTE,
+ WORD,
+ SUBDATA,
+ SUBDATA,
+ WORD,
+ END,
+ // Subdata - prop 1D:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
+ // Subdata - prop 1E:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
-// Feature 04:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ DWORD | QUOTED, SUBDATA, BYTE, BYTE, BYTE, BYTE, SUBDATA, BYTE,
-/*10*/ WORD | DECIMAL, BYTE, DWORD | HEX, BYTE, BYTE, BYTE, WORD | HEX, BYTE | DECIMAL,
-/*18*/ WORD, INVALID, SUBDATA,
-END,
-// Subdata - prop 09:
-EXTBYTE, REPEAT_N(SUBDATA, DATAFROM(0)), END,
- LINEBREAK, RAW(ZERO), RAW(ZERO), RAW(ZERO), RAW(ZERO), '|', LINEBREAK, DWORD | HEX, LINEBREAK, REPEAT_UNTIL(SUBDATA, 1, 0x80), END,
- BYTE, BYTE, BYTE, BYTE, BYTE, BYTE, DWORD | HEX, LINEBREAK, END,
-// Subdata - prop 0E:
-REPEAT_UNTIL(SUBDATA, 2, ZERO, ZERO), END,
- BYTE, BYTE, REPEAT_N(BYTE, MUL(DATAFROM(0), DATAFROM(1))), LINEBREAK, END,
-// Subdata - prop 20:
-EXTBYTE, REPEAT_N(SUBDATA, DATAFROM(0)), END,
- // spritelayout without flags
- BYTE, IFNOT(AND(DATAFROM(0), RAW(0x40)), ZERO, SKIPNEXT), DWORD, LINEBREAK, REPEAT_N(SUBDATA, AND(DATAFROM(0), RAW(0x3F))),
- // spritelayout with flags
- '|', BYTE, LINEBREAK, SUBDATA, REPEAT_N(SUBDATA, AND(DATAFROM(0), RAW(0x3F))), END,
- // building sprite without flags
- DWORD, BYTE | DECIMAL, BYTE | DECIMAL, RAW(0x80), LINEBREAK,
- '|', DWORD, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, LINEBREAK, END,
- // groundsprite with flags
- DWORD, WORD | HEX,
- IFNOT(AND(DATAFROM(1), RAWBYTES(2, 0x30, 0xFF)), ZERO, ASSERT), // assert on unknown flags
- IFNOT(AND(DATAFROM(1), RAW(0x01)), ZERO, BYTE), // skip sprite
- IFNOT(AND(DATAFROM(1), RAW(0x02)), ZERO, BYTE), // sprite offset
- IFNOT(AND(DATAFROM(1), RAW(0x04)), ZERO, BYTE), // palette offset
- IFNOT(AND(DATAFROM(1), RAW(0x40)), ZERO, BYTE), // sprite var10
- IFNOT(AND(DATAFROM(1), RAW(0x80)), ZERO, BYTE), // palette var10
- LINEBREAK,
- END,
- // buildingsprite with flags
- DWORD, WORD | HEX, BYTE | DECIMAL, BYTE | DECIMAL, RAW(0x80),
- IFNOT(AND(DATAFROM(1), RAWBYTES(2, ZERO, 0xFF)), ZERO, ASSERT), // assert on unknown flags
- IFNOT(AND(DATAFROM(1), RAW(0x01)), ZERO, BYTE), // skip sprite
- IFNOT(AND(DATAFROM(1), RAW(0x02)), ZERO, BYTE), // sprite offset
- IFNOT(AND(DATAFROM(1), RAW(0x04)), ZERO, BYTE), // palette offset
- IFNOT(AND(DATAFROM(1), RAW(0x10)), ZERO, BYTE), // X offset
- IFNOT(AND(DATAFROM(1), RAW(0x20)), ZERO, BYTE), // Y offset
- IFNOT(AND(DATAFROM(1), RAW(0x40)), ZERO, BYTE), // sprite var10
- IFNOT(AND(DATAFROM(1), RAW(0x80)), ZERO, BYTE), // palette var10
- LINEBREAK,
- '|', DWORD, WORD | HEX, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL, BYTE | DECIMAL,
- IFNOT(AND(DATAFROM(1), RAWBYTES(2, ZERO, 0xFF)), ZERO, ASSERT), // assert on unknown flags
- IFNOT(AND(DATAFROM(1), RAW(0x01)), ZERO, BYTE), // skip sprite
- IFNOT(AND(DATAFROM(1), RAW(0x02)), ZERO, BYTE), // sprite offset
- IFNOT(AND(DATAFROM(1), RAW(0x04)), ZERO, BYTE), // palette offset
- IFNOT(AND(DATAFROM(1), RAW(0x10)), ZERO, SUBDATA), // X/Y offset
- IFNOT(AND(DATAFROM(1), RAW(0x20)), ZERO, BYTE), // Z offset
- IFNOT(AND(DATAFROM(1), RAW(0x40)), ZERO, BYTE), // sprite var10
- IFNOT(AND(DATAFROM(1), RAW(0x80)), ZERO, BYTE), // palette var10
- LINEBREAK,
- END,
- BYTE, BYTE, END, // X/Y offset
+ // Feature 04:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ DWORD | QUOTED,
+ SUBDATA,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ SUBDATA,
+ BYTE,
+ /*10*/ WORD | DECIMAL,
+ BYTE,
+ DWORD | HEX,
+ BYTE,
+ BYTE,
+ BYTE,
+ WORD | HEX,
+ BYTE | DECIMAL,
+ /*18*/ WORD,
+ INVALID,
+ SUBDATA,
+ END,
+ // Subdata - prop 09:
+ EXTBYTE,
+ REPEAT_N(SUBDATA, DATAFROM(0)),
+ END,
+ LINEBREAK,
+ RAW(ZERO),
+ RAW(ZERO),
+ RAW(ZERO),
+ RAW(ZERO),
+ '|',
+ LINEBREAK,
+ DWORD | HEX,
+ LINEBREAK,
+ REPEAT_UNTIL(SUBDATA, 1, 0x80),
+ END,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ DWORD | HEX,
+ LINEBREAK,
+ END,
+ // Subdata - prop 0E:
+ REPEAT_UNTIL(SUBDATA, 2, ZERO, ZERO),
+ END,
+ BYTE,
+ BYTE,
+ REPEAT_N(BYTE, MUL(DATAFROM(0), DATAFROM(1))),
+ LINEBREAK,
+ END,
+ // Subdata - prop 20:
+ EXTBYTE,
+ REPEAT_N(SUBDATA, DATAFROM(0)),
+ END,
+ // spritelayout without flags
+ BYTE,
+ IFNOT(AND(DATAFROM(0), RAW(0x40)), ZERO, SKIPNEXT),
+ DWORD,
+ LINEBREAK,
+ REPEAT_N(SUBDATA, AND(DATAFROM(0), RAW(0x3F))),
+ // spritelayout with flags
+ '|',
+ BYTE,
+ LINEBREAK,
+ SUBDATA,
+ REPEAT_N(SUBDATA, AND(DATAFROM(0), RAW(0x3F))),
+ END,
+ // building sprite without flags
+ DWORD,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ RAW(0x80),
+ LINEBREAK,
+ '|',
+ DWORD,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ LINEBREAK,
+ END,
+ // groundsprite with flags
+ DWORD,
+ WORD | HEX,
+ IFNOT(AND(DATAFROM(1), RAWBYTES(2, 0x30, 0xFF)), ZERO, ASSERT), // assert on unknown flags
+ IFNOT(AND(DATAFROM(1), RAW(0x01)), ZERO, BYTE), // skip sprite
+ IFNOT(AND(DATAFROM(1), RAW(0x02)), ZERO, BYTE), // sprite offset
+ IFNOT(AND(DATAFROM(1), RAW(0x04)), ZERO, BYTE), // palette offset
+ IFNOT(AND(DATAFROM(1), RAW(0x40)), ZERO, BYTE), // sprite var10
+ IFNOT(AND(DATAFROM(1), RAW(0x80)), ZERO, BYTE), // palette var10
+ LINEBREAK,
+ END,
+ // buildingsprite with flags
+ DWORD,
+ WORD | HEX,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ RAW(0x80),
+ IFNOT(AND(DATAFROM(1), RAWBYTES(2, ZERO, 0xFF)), ZERO, ASSERT), // assert on unknown flags
+ IFNOT(AND(DATAFROM(1), RAW(0x01)), ZERO, BYTE), // skip sprite
+ IFNOT(AND(DATAFROM(1), RAW(0x02)), ZERO, BYTE), // sprite offset
+ IFNOT(AND(DATAFROM(1), RAW(0x04)), ZERO, BYTE), // palette offset
+ IFNOT(AND(DATAFROM(1), RAW(0x10)), ZERO, BYTE), // X offset
+ IFNOT(AND(DATAFROM(1), RAW(0x20)), ZERO, BYTE), // Y offset
+ IFNOT(AND(DATAFROM(1), RAW(0x40)), ZERO, BYTE), // sprite var10
+ IFNOT(AND(DATAFROM(1), RAW(0x80)), ZERO, BYTE), // palette var10
+ LINEBREAK,
+ '|',
+ DWORD,
+ WORD | HEX,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ IFNOT(AND(DATAFROM(1), RAWBYTES(2, ZERO, 0xFF)), ZERO, ASSERT), // assert on unknown flags
+ IFNOT(AND(DATAFROM(1), RAW(0x01)), ZERO, BYTE), // skip sprite
+ IFNOT(AND(DATAFROM(1), RAW(0x02)), ZERO, BYTE), // sprite offset
+ IFNOT(AND(DATAFROM(1), RAW(0x04)), ZERO, BYTE), // palette offset
+ IFNOT(AND(DATAFROM(1), RAW(0x10)), ZERO, SUBDATA), // X/Y offset
+ IFNOT(AND(DATAFROM(1), RAW(0x20)), ZERO, BYTE), // Z offset
+ IFNOT(AND(DATAFROM(1), RAW(0x40)), ZERO, BYTE), // sprite var10
+ IFNOT(AND(DATAFROM(1), RAW(0x80)), ZERO, BYTE), // palette var10
+ LINEBREAK,
+ END,
+ BYTE,
+ BYTE,
+ END, // X/Y offset
-// Feature 05:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, BYTE,
-END,
+ // Feature 05:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ BYTE,
+ END,
-// Feature 06:
-/*00*/ BYTE, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE | DATE, BYTE | DECIMAL, BYTE | DECIMAL, BYTE, WORD | DECIMAL, SUBDATA, BYTE, DWORD | DECIMAL,
-/*10*/ TEXTID, TEXTID, TEXTID, WORD | DECIMAL,
-END,
-// Subdata - prop 0D:
-BYTE, BYTE, REPEAT_N(DWORD | HEX, MUL(DATAFROM(1), 32)), LINEBREAK, END,
+ // Feature 06:
+ /*00*/ BYTE,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE | DATE,
+ BYTE | DECIMAL,
+ BYTE | DECIMAL,
+ BYTE,
+ WORD | DECIMAL,
+ SUBDATA,
+ BYTE,
+ DWORD | DECIMAL,
+ /*10*/ TEXTID,
+ TEXTID,
+ TEXTID,
+ WORD | DECIMAL,
+ END,
+ // Subdata - prop 0D:
+ BYTE,
+ BYTE,
+ REPEAT_N(DWORD | HEX, MUL(DATAFROM(1), 32)),
+ LINEBREAK,
+ END,
-// Feature 07:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, BYTE, SUBDATA, BYTE, BYTE, BYTE, BYTE, BYTE,
-/*10*/ WORD | DECIMAL, BYTE, TEXTID, WORD, BYTE, BYTE | REASSIGNABLE, BYTE, DWORD,
-/*18*/ BYTE, BYTE, BYTE, BYTE, BYTE, BYTE, DWORD, BYTE,
-/*20*/ SUBDATA, WORD | DECIMAL, WORD | DECIMAL,
-END,
-// Subdata - prop 0A:
-BYTE | DATE, BYTE | DATE, END,
-// Subdata - prop 20:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
+ // Feature 07:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ BYTE,
+ SUBDATA,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ /*10*/ WORD | DECIMAL,
+ BYTE,
+ TEXTID,
+ WORD,
+ BYTE,
+ BYTE | REASSIGNABLE,
+ BYTE,
+ DWORD,
+ /*18*/ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ BYTE,
+ DWORD,
+ BYTE,
+ /*20*/ SUBDATA,
+ WORD | DECIMAL,
+ WORD | DECIMAL,
+ END,
+ // Subdata - prop 0A:
+ BYTE | DATE,
+ BYTE | DATE,
+ END,
+ // Subdata - prop 20:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
-// Feature 08:
-// Different format this feature only:
-// Non-INVALID properties are followed by two bytes:
-// The max value for the action 0's <ID> entity
-// The max ID that can be set
-// (0f8.dat was merged into here to prevent it from getting out of sync.)
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, 0x46, 0x46, DWORD | QUOTED, 0x00, 0xFC, TEXTID, 0x12, 0x12, DWORD | DECIMAL, 0x12, 0x12,
-/*0C*/ WORD | QUOTED, 0x12, 0x12, DWORD | QUOTED, 0x12, 0x12, DWORD | QUOTED, 0x12, 0x12, WORD | DECIMAL, 0x12, 0x12,
-/*10*/ SUBDATA, 0x00, 0x00, SUBDATA, 0x00, 0xFF, DWORD | QUOTED, 0x00, 0xFC, SUBDATA, 0x7E, 0x7E,
-/*14*/ SUBDATA, 0x7E, 0x7E, BYTE, 0x7E, 0x7E,
-END,
-// Subdata - prop 10:
-REPEAT_N(SUBDATA, 11), SUBDATA, END,
- REPEAT_N(BYTE, 32), LINEBREAK, END,
- REPEAT_N(BYTE, 32), END,
-// Subdata - prop 11:
-DWORD | QUOTED, DWORD | QUOTED, END,
-// Subdata - prop 13:
-REPEAT_UNTIL(SUBDATA, 1, ZERO), END, BYTE, REPEAT_UNTIL(SUBDATA, 1, ZERO), LINEBREAK, END, BYTE | MAGIC | QUOTED, END,
-// Subdata - prop 14:
-REPEAT_UNTIL(SUBDATA, 1, ZERO), END, BYTE, REPEAT_UNTIL(SUBDATA, 1, ZERO), LINEBREAK, END, BYTE | MAGIC | QUOTED, END,
+ // Feature 08:
+ // Different format this feature only:
+ // Non-INVALID properties are followed by two bytes:
+ // The max value for the action 0's <ID> entity
+ // The max ID that can be set
+ // (0f8.dat was merged into here to prevent it from getting out of sync.)
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ 0x46,
+ 0x46,
+ DWORD | QUOTED,
+ 0x00,
+ 0xFC,
+ TEXTID,
+ 0x12,
+ 0x12,
+ DWORD | DECIMAL,
+ 0x12,
+ 0x12,
+ /*0C*/ WORD | QUOTED,
+ 0x12,
+ 0x12,
+ DWORD | QUOTED,
+ 0x12,
+ 0x12,
+ DWORD | QUOTED,
+ 0x12,
+ 0x12,
+ WORD | DECIMAL,
+ 0x12,
+ 0x12,
+ /*10*/ SUBDATA,
+ 0x00,
+ 0x00,
+ SUBDATA,
+ 0x00,
+ 0xFF,
+ DWORD | QUOTED,
+ 0x00,
+ 0xFC,
+ SUBDATA,
+ 0x7E,
+ 0x7E,
+ /*14*/ SUBDATA,
+ 0x7E,
+ 0x7E,
+ BYTE,
+ 0x7E,
+ 0x7E,
+ END,
+ // Subdata - prop 10:
+ REPEAT_N(SUBDATA, 11),
+ SUBDATA,
+ END,
+ REPEAT_N(BYTE, 32),
+ LINEBREAK,
+ END,
+ REPEAT_N(BYTE, 32),
+ END,
+ // Subdata - prop 11:
+ DWORD | QUOTED,
+ DWORD | QUOTED,
+ END,
+ // Subdata - prop 13:
+ REPEAT_UNTIL(SUBDATA, 1, ZERO),
+ END,
+ BYTE,
+ REPEAT_UNTIL(SUBDATA, 1, ZERO),
+ LINEBREAK,
+ END,
+ BYTE | MAGIC | QUOTED,
+ END,
+ // Subdata - prop 14:
+ REPEAT_UNTIL(SUBDATA, 1, ZERO),
+ END,
+ BYTE,
+ REPEAT_UNTIL(SUBDATA, 1, ZERO),
+ LINEBREAK,
+ END,
+ BYTE | MAGIC | QUOTED,
+ END,
-// Feature 09:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, BYTE | REASSIGNABLE, WORD, WORD, WORD, BYTE, BYTE, WORD,
-/*10*/ BYTE, BYTE, BYTE,
-END,
+ // Feature 09:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ BYTE | REASSIGNABLE,
+ WORD,
+ WORD,
+ WORD,
+ BYTE,
+ BYTE,
+ WORD,
+ /*10*/ BYTE,
+ BYTE,
+ BYTE,
+ END,
-// Feature 0A:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, BYTE, SUBDATA, BYTE, TEXTID, TEXTID, TEXTID, BYTE,
-/*10*/ WORD, DWORD, BYTE, BYTE, BYTE, SUBDATA, SUBDATA, BYTE,
-/*18*/ BYTE, BYTE, DWORD, TEXTID, DWORD, DWORD, DWORD, TEXTID,
-/*20*/ DWORD, BYTE, BYTE, DWORD | DECIMAL, TEXTID,
-END,
-// Subdata - prop 0A:
-BYTE, REMAININGSIZE | LINEBREAK, REPEAT_N(SUBDATA, DATAFROM(0)), END,
- RAW(0xFE), BYTE, BYTE | LINEBREAK, '|', REPEAT_UNTIL(SUBDATA, 2, ZERO, 0x80), END,
- END, // bogus end for RAW(0xFE)
- BYTE, BYTE, SUBDATA, LINEBREAK, END,
- RAW(0xFE), TILEID, '|', BYTE, END,
- END, // bogus end for RAW(0xFE)
-// Subdata - prop 15:
-BYTE, REPEAT_N(BYTE, DATAFROM(0)), END,
-// Subdata - prop 16:
-REPEAT_N(BYTE, 3), END,
+ // Feature 0A:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ BYTE,
+ SUBDATA,
+ BYTE,
+ TEXTID,
+ TEXTID,
+ TEXTID,
+ BYTE,
+ /*10*/ WORD,
+ DWORD,
+ BYTE,
+ BYTE,
+ BYTE,
+ SUBDATA,
+ SUBDATA,
+ BYTE,
+ /*18*/ BYTE,
+ BYTE,
+ DWORD,
+ TEXTID,
+ DWORD,
+ DWORD,
+ DWORD,
+ TEXTID,
+ /*20*/ DWORD,
+ BYTE,
+ BYTE,
+ DWORD | DECIMAL,
+ TEXTID,
+ END,
+ // Subdata - prop 0A:
+ BYTE,
+ REMAININGSIZE | LINEBREAK,
+ REPEAT_N(SUBDATA, DATAFROM(0)),
+ END,
+ RAW(0xFE),
+ BYTE,
+ BYTE | LINEBREAK,
+ '|',
+ REPEAT_UNTIL(SUBDATA, 2, ZERO, 0x80),
+ END,
+ END, // bogus end for RAW(0xFE)
+ BYTE,
+ BYTE,
+ SUBDATA,
+ LINEBREAK,
+ END,
+ RAW(0xFE),
+ TILEID,
+ '|',
+ BYTE,
+ END,
+ END, // bogus end for RAW(0xFE)
+ // Subdata - prop 15:
+ BYTE,
+ REPEAT_N(BYTE, DATAFROM(0)),
+ END,
+ // Subdata - prop 16:
+ REPEAT_N(BYTE, 3),
+ END,
-// Feature 0B:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE | DECIMAL, TEXTID, TEXTID, TEXTID, TEXTID, TEXTID, WORD | HEX, BYTE,
-/*10*/ BYTE, BYTE, DWORD | HEX, BYTE, BYTE, BYTE, WORD | HEX, DWORD | QUOTED,
-/*18*/ BYTE, WORD | HEX, BYTE, TEXTID, TEXTID, WORD,
-END,
+ // Feature 0B:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE | DECIMAL,
+ TEXTID,
+ TEXTID,
+ TEXTID,
+ TEXTID,
+ TEXTID,
+ WORD | HEX,
+ BYTE,
+ /*10*/ BYTE,
+ BYTE,
+ DWORD | HEX,
+ BYTE,
+ BYTE,
+ BYTE,
+ WORD | HEX,
+ DWORD | QUOTED,
+ /*18*/ BYTE,
+ WORD | HEX,
+ BYTE,
+ TEXTID,
+ TEXTID,
+ WORD,
+ END,
-// Feature 0C:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, BYTE, BYTE,
-END,
+ // Feature 0C:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ BYTE,
+ BYTE,
+ END,
-// Feature 0D:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, DWORD, SUBDATA, INVALID, SUBDATA, BYTE, BYTE, BYTE,
-/*10*/ WORD, WORD,
-END,
-// Subdata - prop 0A:
-BYTE, REMAININGSIZE | LINEBREAK, REPEAT_N(SUBDATA, DATAFROM(0)), END,
- BYTE, RAW(0xFE), BYTE, BYTE | LINEBREAK, '|', BYTE, REPEAT_UNTIL(SUBDATA, 2, ZERO, 0x80), END,
- END, // bogus end for RAW(0xFE)
- BYTE, BYTE, SUBDATA, LINEBREAK, END,
- RAW(0xFE), TILEID, '|', BYTE, END,
- END, // bogus end for RAW(0xFE)
-// Subdata - prop 0C:
-WORD, WORD, END,
+ // Feature 0D:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ DWORD,
+ SUBDATA,
+ INVALID,
+ SUBDATA,
+ BYTE,
+ BYTE,
+ BYTE,
+ /*10*/ WORD,
+ WORD,
+ END,
+ // Subdata - prop 0A:
+ BYTE,
+ REMAININGSIZE | LINEBREAK,
+ REPEAT_N(SUBDATA, DATAFROM(0)),
+ END,
+ BYTE,
+ RAW(0xFE),
+ BYTE,
+ BYTE | LINEBREAK,
+ '|',
+ BYTE,
+ REPEAT_UNTIL(SUBDATA, 2, ZERO, 0x80),
+ END,
+ END, // bogus end for RAW(0xFE)
+ BYTE,
+ BYTE,
+ SUBDATA,
+ LINEBREAK,
+ END,
+ RAW(0xFE),
+ TILEID,
+ '|',
+ BYTE,
+ END,
+ END, // bogus end for RAW(0xFE)
+ // Subdata - prop 0C:
+ WORD,
+ WORD,
+ END,
-// Feature 0E:
-END,
+ // Feature 0E:
+ END,
-// Feature 0F:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ DWORD | QUOTED, WORD, WORD, BYTE, BYTE, BYTE, DWORD | DATE, DWORD | DATE,
-/*10*/ WORD | HEX, WORD | HEX, BYTE | DECIMAL, WORD, BYTE, WORD | HEX, BYTE, BYTE, BYTE,
-END,
+ // Feature 0F:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ DWORD | QUOTED,
+ WORD,
+ WORD,
+ BYTE,
+ BYTE,
+ BYTE,
+ DWORD | DATE,
+ DWORD | DATE,
+ /*10*/ WORD | HEX,
+ WORD | HEX,
+ BYTE | DECIMAL,
+ WORD,
+ BYTE,
+ WORD | HEX,
+ BYTE,
+ BYTE,
+ BYTE,
+ END,
-// Feature 10:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ DWORD | QUOTED, WORD, WORD, WORD, WORD, WORD, SUBDATA, SUBDATA,
-/*10*/ BYTE, BYTE, BYTE, WORD, WORD, BYTE, BYTE, DWORD | DATE,
-/*18*/ SUBDATA, SUBDATA, BYTE, WORD, WORD, SUBDATA,
-END,
-// Subdata - prop 0E:
-BYTE, REPEAT_N(DWORD | QUOTED, DATAFROM(0)), END,
-// Subdata - prop 0F:
-BYTE, REPEAT_N(DWORD | QUOTED, DATAFROM(0)), END,
-// Subdata - prop 18:
-BYTE, REPEAT_N(DWORD | QUOTED, DATAFROM(0)), END,
-// Subdata - prop 19:
-BYTE, REPEAT_N(DWORD | QUOTED, DATAFROM(0)), END,
-// Subdata - prop 1D:
-BYTE, REPEAT_N(DWORD | QUOTED, DATAFROM(0)), END,
+ // Feature 10:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ DWORD | QUOTED,
+ WORD,
+ WORD,
+ WORD,
+ WORD,
+ WORD,
+ SUBDATA,
+ SUBDATA,
+ /*10*/ BYTE,
+ BYTE,
+ BYTE,
+ WORD,
+ WORD,
+ BYTE,
+ BYTE,
+ DWORD | DATE,
+ /*18*/ SUBDATA,
+ SUBDATA,
+ BYTE,
+ WORD,
+ WORD,
+ SUBDATA,
+ END,
+ // Subdata - prop 0E:
+ BYTE,
+ REPEAT_N(DWORD | QUOTED, DATAFROM(0)),
+ END,
+ // Subdata - prop 0F:
+ BYTE,
+ REPEAT_N(DWORD | QUOTED, DATAFROM(0)),
+ END,
+ // Subdata - prop 18:
+ BYTE,
+ REPEAT_N(DWORD | QUOTED, DATAFROM(0)),
+ END,
+ // Subdata - prop 19:
+ BYTE,
+ REPEAT_N(DWORD | QUOTED, DATAFROM(0)),
+ END,
+ // Subdata - prop 1D:
+ BYTE,
+ REPEAT_N(DWORD | QUOTED, DATAFROM(0)),
+ END,
-// Feature 11:
-/*00*/ INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID, INVALID,
-/*08*/ BYTE, BYTE | REASSIGNABLE, INVALID, INVALID, INVALID, INVALID, BYTE, WORD,
-/*10*/ BYTE, BYTE,
-END,
-
-NDF_END
-};
+ // Feature 11:
+ /*00*/ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ /*08*/ BYTE,
+ BYTE | REASSIGNABLE,
+ INVALID,
+ INVALID,
+ INVALID,
+ INVALID,
+ BYTE,
+ WORD,
+ /*10*/ BYTE,
+ BYTE,
+ END,
+ NDF_END};
#undef INVALID
#undef END
#undef ZERO
@@ -781,119 +1351,93 @@
#define DWORD6x(var, max) VAR6x(var, 4, max)
#define LASTVAR80(var) (var == 0xFF ? 0xFF : (unsigned char)(var + 1)), (var == 0xFF ? 0xF0 : 0x80)
#define NOVAR80 LASTVAR80(0x7F)
-static const unsigned char _dat2v[]={
-NDF_HEADER(0x0D, 30),
-/*Maximum feature:*/ 0x11,
-/*Maximum operator:*/ 0x16,
-// Global variables:
-WORD(0x00), BYTE(0x01), BYTE(0x02), BYTE(0x03), BYTE(0x06), WORD(0x09), WORD(0x0A), DWORD(0x0B), WORD(0x0C), BYTE(0x0D), BYTE(0x0E), VAR(0x0F, 3),
-DWORD(0x10), /* var 11 in feature 04 */ BYTE(0x12), WORD(0x13), WORD(0x14), WORD(0x15), WORD(0x16), DWORD(0x18), VAR(0x1A, 4 | ALLOW0MASK), BYTE(0x1B), DWORD(0x1C), BYTE(0x1D), DWORD(0x1E),
-BYTE(0x20), DWORD(0x21), DWORD(0x22), DWORD(0x23), DWORD(0x24),
-DWORD6x(0x7D, 0xFF), VAR6x(0x7E, 2 | ALLOW0MASK, 0xFF), DWORD6x(0x7F, 0x7F),
-// Things like 25, 5F and 7C as feature specific, so there are put with features
-LASTVAR80(0xFF),
-// Feature 00:
-/*Related:*/ 0x00,
-DWORD(0x25),
-VAR(0x40, 3), VAR(0x41, 3), DWORD(0x42), DWORD(0x43), VAR(0x45, 3), DWORD(0x46), DWORD(0x47),
-BYTE(0x48), DWORD(0x49), DWORD(0x4A), DWORD(0x4B), DWORD(0x4C), WORD(0x4D),
-WORD(0x5F),
-BYTE6x(0x60, 0x73), DWORD6x(0x61, 0xFF), DWORD6x(0x62, 0xFF),
-LASTVAR80(0xFF),
-// Feature 01:
-/*Related:*/ 0x01,
-VAR(0x40, 3), VAR(0x41, 3), VAR(0x42, 3), DWORD(0x43), VAR(0x45, 3), DWORD(0x46), DWORD(0x47),
-BYTE(0x48), DWORD(0x49), DWORD(0x4B), DWORD(0x4C), WORD(0x4D),
-WORD(0x5F),
-DWORD6x(0x61, 0xFF), DWORD6x(0x62, 0xFF),
-LASTVAR80(0xFF),
-// Feature 02:
-/*Related:*/ 0x02,
-BYTE(0x42), DWORD(0x43), DWORD(0x46), DWORD(0x47), BYTE(0x48), DWORD(0x49), DWORD(0x4B), DWORD(0x4C),
-WORD(0x5F),
-LASTVAR80(0xFF),
-// Feature 03:
-/*Related:*/ 0x03,
-VAR(0x40, 3), BYTE(0x42), DWORD(0x43), WORD(0x44), DWORD(0x46), DWORD(0x47), BYTE(0x48), DWORD(0x49),
-DWORD(0x4B), DWORD(0x4C),
-WORD(0x5F),
-LASTVAR80(0xFF),
-// Feature 04:
-/*Related:*/ 0x08,
-BYTE(0x11),
-DWORD(0x40), DWORD(0x41), WORD(0x42), VAR(0x43, 3), BYTE(0x44), WORD(0x45), DWORD(0x46), DWORD(0x47),
-DWORD(0x48), DWORD(0x49), BYTE(0x4A),
-DWORD(0x5F),
-WORD6x(0x60, 0xFF), BYTE6x(0x61, 0xFF), DWORD6x(0x62, 0xFF), BYTE6x(0x63, 0xFF), WORD6x(0x64, 0xFF),
-BYTE6x(0x65, 0xFF), DWORD6x(0x66, 0xFF), DWORD6x(0x67, 0xFF), WORD6x(0x68, 0xFF), BYTE6x(0x69, 0xFF),
-LASTVAR80(0xFF),
-// Feature 05:
-/*Related:*/ 0x05,
-WORD(0x5F),
-LASTVAR80(0x83),
-// Feature 06:
-/*Related:*/ 0x08,
-BYTE(0x40), BYTE(0x41),
-NOVAR80,
-// Feature 07:
-/*Related:*/ 0x08,
-BYTE(0x40), BYTE(0x41), BYTE(0x42), BYTE(0x43), DWORD(0x44), BYTE(0x45), BYTE(0x46), WORD(0x47),
-WORD(0x5F),
-WORD6x(0x60, 0x6B), WORD6x(0x61, 0xFF), DWORD6x(0x62,0xFF), BYTE6x(0x63, 0xFF),
-BYTE6x(0x64, 0xFF), BYTE6x(0x65, 0xFF), DWORD6x(0x66, 0xFF), DWORD6x(0x67, 0xFF),
-NOVAR80,
-// Town variables ("Feature 08" *cough*cough*)
-/*Related:*/ 0x08,
-BYTE(0x40), BYTE(0x41),
-LASTVAR80(0xDD),
-// Feature 09:
-/*Related:*/ 0x0A,
-BYTE(0x40), BYTE(0x41), BYTE(0x42), VAR(0x43, 3), BYTE(0x44),
-WORD(0x5F),
-DWORD6x(0x60, 0xFF), DWORD6x(0x61, 0xFF), WORD6x(0x62, 0xFF),
-NOVAR80,
-// Feature 0A:
-/*Related:*/ 0x08,
-WORD(0x40), WORD(0x41), WORD(0x42), WORD(0x43), BYTE(0x44), DWORD(0x45), DWORD(0x46),
-VAR(0x5F, 3),
-WORD6x(0x60, 0xFF), BYTE6x(0x61, 0xFF), DWORD6x(0x62, 0xFF), DWORD6x(0x63, 0xFF),
-DWORD6x(0x64, 0xFF), VAR6x(0x65, 3, 0xFF), VAR6x(0x66, 3, 0xFF), DWORD6x(0x67, 0xFF),
-DWORD6x(0x68, 0xFF),
-DWORD6x(0x7C, 0x0F),
-LASTVAR80(0xB5),
-// Feature 0B:
-/*Related:*/ 0x0B,
-NOVAR80,
-// Feature 0C:
-/*Related:*/ 0x0C,
-NOVAR80,
-// Feature 0D:
-/*Related:*/ 0x0D,
-NOVAR80,
-// Feature 0E:
-/*Related:*/ 0x0E,
-DWORD6x(0x60, 0xFF),
-NOVAR80,
-// Feature 0F:
-/*Related:*/ 0x08,
-VAR(0x40, 3), WORD(0x41), DWORD(0x42), BYTE(0x43), BYTE(0x44), DWORD(0x45), DWORD(0x46), BYTE(0x47), BYTE(0x48),
-WORD(0x5F),
-DWORD6x(0x60, 0xFF), BYTE6x(0x61, 0xFF), DWORD6x(0x62, 0xFF), WORD6x(0x63, 0xFF),
-DWORD6x(0x64, 0xFF),
-NOVAR80,
-// Feature 10:
-/*Related:*/ 0x10,
-BYTE(0x40), BYTE(0x41), BYTE(0x42), DWORD(0x43), BYTE(0x44),
-WORD(0x5F),
-NOVAR80,
-// Feature 11:
-/*Related:*/ 0x0D,
-BYTE(0x41), BYTE(0x42), VAR(0x43, 3), BYTE(0x44),
-DWORD(0x5F),
-DWORD6x(0x60, 0xFF), DWORD6x(0x61, 0xFF), WORD6x(0x62, 0xFF),
-NOVAR80,
-NDF_END
-};
+static const unsigned char _dat2v[] = {
+ NDF_HEADER(0x0D, 30),
+ /*Maximum feature:*/ 0x11,
+ /*Maximum operator:*/ 0x16,
+ // Global variables:
+ WORD(0x00), BYTE(0x01), BYTE(0x02), BYTE(0x03),
+ BYTE(0x06), WORD(0x09), WORD(0x0A), DWORD(0x0B),
+ WORD(0x0C), BYTE(0x0D), BYTE(0x0E), VAR(0x0F, 3),
+ DWORD(0x10), /* var 11 in feature 04 */ BYTE(0x12), WORD(0x13), WORD(0x14),
+ WORD(0x15), WORD(0x16), DWORD(0x18), VAR(0x1A, 4 | ALLOW0MASK),
+ BYTE(0x1B), DWORD(0x1C), BYTE(0x1D), DWORD(0x1E),
+ BYTE(0x20), DWORD(0x21), DWORD(0x22), DWORD(0x23),
+ DWORD(0x24), DWORD6x(0x7D, 0xFF), VAR6x(0x7E, 2 | ALLOW0MASK, 0xFF), DWORD6x(0x7F, 0x7F),
+ // Things like 25, 5F and 7C as feature specific, so there are put with features
+ LASTVAR80(0xFF),
+ // Feature 00:
+ /*Related:*/ 0x00, DWORD(0x25), VAR(0x40, 3), VAR(0x41, 3),
+ DWORD(0x42), DWORD(0x43), VAR(0x45, 3), DWORD(0x46),
+ DWORD(0x47), BYTE(0x48), DWORD(0x49), DWORD(0x4A),
+ DWORD(0x4B), DWORD(0x4C), WORD(0x4D), WORD(0x5F),
+ BYTE6x(0x60, 0x73), DWORD6x(0x61, 0xFF), DWORD6x(0x62, 0xFF), LASTVAR80(0xFF),
+ // Feature 01:
+ /*Related:*/ 0x01, VAR(0x40, 3), VAR(0x41, 3), VAR(0x42, 3),
+ DWORD(0x43), VAR(0x45, 3), DWORD(0x46), DWORD(0x47),
+ BYTE(0x48), DWORD(0x49), DWORD(0x4B), DWORD(0x4C),
+ WORD(0x4D), WORD(0x5F), DWORD6x(0x61, 0xFF), DWORD6x(0x62, 0xFF),
+ LASTVAR80(0xFF),
+ // Feature 02:
+ /*Related:*/ 0x02, BYTE(0x42), DWORD(0x43), DWORD(0x46),
+ DWORD(0x47), BYTE(0x48), DWORD(0x49), DWORD(0x4B),
+ DWORD(0x4C), WORD(0x5F), LASTVAR80(0xFF),
+ // Feature 03:
+ /*Related:*/ 0x03, VAR(0x40, 3), BYTE(0x42), DWORD(0x43),
+ WORD(0x44), DWORD(0x46), DWORD(0x47), BYTE(0x48),
+ DWORD(0x49), DWORD(0x4B), DWORD(0x4C), WORD(0x5F),
+ LASTVAR80(0xFF),
+ // Feature 04:
+ /*Related:*/ 0x08, BYTE(0x11), DWORD(0x40), DWORD(0x41),
+ WORD(0x42), VAR(0x43, 3), BYTE(0x44), WORD(0x45),
+ DWORD(0x46), DWORD(0x47), DWORD(0x48), DWORD(0x49),
+ BYTE(0x4A), DWORD(0x5F), WORD6x(0x60, 0xFF), BYTE6x(0x61, 0xFF),
+ DWORD6x(0x62, 0xFF), BYTE6x(0x63, 0xFF), WORD6x(0x64, 0xFF), BYTE6x(0x65, 0xFF),
+ DWORD6x(0x66, 0xFF), DWORD6x(0x67, 0xFF), WORD6x(0x68, 0xFF), BYTE6x(0x69, 0xFF),
+ LASTVAR80(0xFF),
+ // Feature 05:
+ /*Related:*/ 0x05, WORD(0x5F), LASTVAR80(0x83),
+ // Feature 06:
+ /*Related:*/ 0x08, BYTE(0x40), BYTE(0x41), NOVAR80,
+ // Feature 07:
+ /*Related:*/ 0x08, BYTE(0x40), BYTE(0x41), BYTE(0x42),
+ BYTE(0x43), DWORD(0x44), BYTE(0x45), BYTE(0x46),
+ WORD(0x47), WORD(0x5F), WORD6x(0x60, 0x6B), WORD6x(0x61, 0xFF),
+ DWORD6x(0x62, 0xFF), BYTE6x(0x63, 0xFF), BYTE6x(0x64, 0xFF), BYTE6x(0x65, 0xFF),
+ DWORD6x(0x66, 0xFF), DWORD6x(0x67, 0xFF), NOVAR80,
+ // Town variables ("Feature 08" *cough*cough*)
+ /*Related:*/ 0x08, BYTE(0x40), BYTE(0x41), LASTVAR80(0xDD),
+ // Feature 09:
+ /*Related:*/ 0x0A, BYTE(0x40), BYTE(0x41), BYTE(0x42),
+ VAR(0x43, 3), BYTE(0x44), WORD(0x5F), DWORD6x(0x60, 0xFF),
+ DWORD6x(0x61, 0xFF), WORD6x(0x62, 0xFF), NOVAR80,
+ // Feature 0A:
+ /*Related:*/ 0x08, WORD(0x40), WORD(0x41), WORD(0x42),
+ WORD(0x43), BYTE(0x44), DWORD(0x45), DWORD(0x46),
+ VAR(0x5F, 3), WORD6x(0x60, 0xFF), BYTE6x(0x61, 0xFF), DWORD6x(0x62, 0xFF),
+ DWORD6x(0x63, 0xFF), DWORD6x(0x64, 0xFF), VAR6x(0x65, 3, 0xFF), VAR6x(0x66, 3, 0xFF),
+ DWORD6x(0x67, 0xFF), DWORD6x(0x68, 0xFF), DWORD6x(0x7C, 0x0F), LASTVAR80(0xB5),
+ // Feature 0B:
+ /*Related:*/ 0x0B, NOVAR80,
+ // Feature 0C:
+ /*Related:*/ 0x0C, NOVAR80,
+ // Feature 0D:
+ /*Related:*/ 0x0D, NOVAR80,
+ // Feature 0E:
+ /*Related:*/ 0x0E, DWORD6x(0x60, 0xFF), NOVAR80,
+ // Feature 0F:
+ /*Related:*/ 0x08, VAR(0x40, 3), WORD(0x41), DWORD(0x42),
+ BYTE(0x43), BYTE(0x44), DWORD(0x45), DWORD(0x46),
+ BYTE(0x47), BYTE(0x48), WORD(0x5F), DWORD6x(0x60, 0xFF),
+ BYTE6x(0x61, 0xFF), DWORD6x(0x62, 0xFF), WORD6x(0x63, 0xFF), DWORD6x(0x64, 0xFF),
+ NOVAR80,
+ // Feature 10:
+ /*Related:*/ 0x10, BYTE(0x40), BYTE(0x41), BYTE(0x42),
+ DWORD(0x43), BYTE(0x44), WORD(0x5F), NOVAR80,
+ // Feature 11:
+ /*Related:*/ 0x0D, BYTE(0x41), BYTE(0x42), VAR(0x43, 3),
+ BYTE(0x44), DWORD(0x5F), DWORD6x(0x60, 0xFF), DWORD6x(0x61, 0xFF),
+ WORD6x(0x62, 0xFF), NOVAR80, NDF_END};
#undef ALLOW0MASK
#undef VAR
#undef VAR6x
@@ -906,137 +1450,124 @@
#undef LASTVAR80
#undef NOVAR80
-#define W(cnt) cnt & 0xFF, cnt >> 8 /* Construct word count */
-static const unsigned char _datD[]={
-NDF_HEADER(0x14, 7),
-/*Maximum feature:*/ 0x11,
-/*Max patch variable:*/ 0x16,
-/*Max operator:*/ 0x0C,
-// GRM count:
-/*00*/W(0x74),
-/*01*/W(0x58),
-/*02*/W(0x0B),
-/*03*/W(0x29),
-/*04*/W(0),
-/*05*/W(0),
-/*06*/W(0),
-/*07*/W(0),
-/*08*/W(0x131E),
-/*09*/W(0),
-/*0A*/W(0),
-/*0B*/W(0x40),
-/*0C*/W(0),
-/*0D*/W(0),
-/*0E*/W(0),
-/*0F*/W(0),
-/*10*/W(0),
-/*11*/W(0),
-NDF_END
-};
+#define W(cnt) cnt & 0xFF, cnt >> 8 /* Construct word count */
+static const unsigned char _datD[] = {NDF_HEADER(0x14, 7),
+ /*Maximum feature:*/ 0x11,
+ /*Max patch variable:*/ 0x16,
+ /*Max operator:*/ 0x0C,
+ // GRM count:
+ /*00*/ W(0x74),
+ /*01*/ W(0x58),
+ /*02*/ W(0x0B),
+ /*03*/ W(0x29),
+ /*04*/ W(0),
+ /*05*/ W(0),
+ /*06*/ W(0),
+ /*07*/ W(0),
+ /*08*/ W(0x131E),
+ /*09*/ W(0),
+ /*0A*/ W(0),
+ /*0B*/ W(0x40),
+ /*0C*/ W(0),
+ /*0D*/ W(0),
+ /*0E*/ W(0),
+ /*0F*/ W(0),
+ /*10*/ W(0),
+ /*11*/ W(0), NDF_END};
-static const unsigned char _datIDs[]={
-NDF_HEADER(0x77, 4),
-/*Maximum feature:*/ 0x11,
-/*00*/W(0x73),
-/*01*/W(0x57),
-/*02*/W(0x0A),
-/*03*/W(0x28),
-/*04*/W(0xFF),
-/*05*/W(0x08),
-/*06*/W(0x0C),
-/*07*/W(0xFF),
-/*08*/W(0x00),
-/*09*/W(0xFF),
-/*0A*/W(0x24),
-/*0B*/W(0x1F),
-/*0C*/W(0xFFFF),
-/*0D*/W(0x00),
-/*0E*/W(0x00),
-/*0F*/W(0xFF),
-/*10*/W(0xFF),
-/*11*/W(0xFF),
-NDF_END
-};
+static const unsigned char _datIDs[] = {NDF_HEADER(0x77, 4),
+ /*Maximum feature:*/ 0x11,
+ /*00*/ W(0x73),
+ /*01*/ W(0x57),
+ /*02*/ W(0x0A),
+ /*03*/ W(0x28),
+ /*04*/ W(0xFF),
+ /*05*/ W(0x08),
+ /*06*/ W(0x0C),
+ /*07*/ W(0xFF),
+ /*08*/ W(0x00),
+ /*09*/ W(0xFF),
+ /*0A*/ W(0x24),
+ /*0B*/ W(0x1F),
+ /*0C*/ W(0xFFFF),
+ /*0D*/ W(0x00),
+ /*0E*/ W(0x00),
+ /*0F*/ W(0xFF),
+ /*10*/ W(0xFF),
+ /*11*/ W(0xFF), NDF_END};
#undef W
/* Action 4 strings */
-static const unsigned char _dat4[]={
-NDF_HEADER(0x03, 5),
-/*Maximum feature:*/ 0x11,
-// Rules for one-byte IDs:
-/*00*/CTRL_SPACE,
-/*01*/CTRL_SPACE,
-/*02*/CTRL_SPACE,
-/*03*/CTRL_SPACE,
-/*04*/0,
-/*05*/0,
-/*06*/0,
-/*07*/0,
-/*08*/0,
-/*09*/0,
-/*0A*/0,
-/*0B*/0,
-/*0C*/0,
-/*0D*/0,
-/*0E*/0,
-/*0F*/0,
-/*10*/0,
-/*11*/ CTRL_COLOR,
-// Rules for two-byte IDs:
-/*00*/CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
-/*01*/CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
-/*02*/CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
-/*03*/CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
-/*04*/CTRL_SPACE,
-/*05*/CTRL_SPACE,
-/*06*/0,
-/*07*/CTRL_SPACE,
-/*08*/0,
-/*09*/CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
-/*0A*/CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR | CTRL_FONT_LARGE | CTRL_NO_STACK_CHECK,
-/*0B*/CTRL_SPACE | CTRL_FONT_SMALL,
-/*0C*/0,
-/*0D*/0,
-/*0E*/0,
-/*0F*/0,
-/*10*/CTRL_SPACE,
-/*11*/CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
-NDF_END
-};
-
+static const unsigned char _dat4[] = {NDF_HEADER(0x03, 5),
+ /*Maximum feature:*/ 0x11,
+ // Rules for one-byte IDs:
+ /*00*/ CTRL_SPACE,
+ /*01*/ CTRL_SPACE,
+ /*02*/ CTRL_SPACE,
+ /*03*/ CTRL_SPACE,
+ /*04*/ 0,
+ /*05*/ 0,
+ /*06*/ 0,
+ /*07*/ 0,
+ /*08*/ 0,
+ /*09*/ 0,
+ /*0A*/ 0,
+ /*0B*/ 0,
+ /*0C*/ 0,
+ /*0D*/ 0,
+ /*0E*/ 0,
+ /*0F*/ 0,
+ /*10*/ 0,
+ /*11*/ CTRL_COLOR,
+ // Rules for two-byte IDs:
+ /*00*/ CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
+ /*01*/ CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
+ /*02*/ CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
+ /*03*/ CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
+ /*04*/ CTRL_SPACE,
+ /*05*/ CTRL_SPACE,
+ /*06*/ 0,
+ /*07*/ CTRL_SPACE,
+ /*08*/ 0,
+ /*09*/ CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR,
+ /*0A*/ CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR | CTRL_FONT_LARGE | CTRL_NO_STACK_CHECK,
+ /*0B*/ CTRL_SPACE | CTRL_FONT_SMALL,
+ /*0C*/ 0,
+ /*0D*/ 0,
+ /*0E*/ 0,
+ /*0F*/ 0,
+ /*10*/ CTRL_SPACE,
+ /*11*/ CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR, NDF_END};
/* Randomized action 2 */
#define ACT2RANDOM(self_bits, related_bits, num_triggers) self_bits, related_bits, num_triggers
-static const unsigned char _dat2r[]={
-NDF_HEADER(0x02, 6),
-/*Maximum feature:*/ 0x11,
-/*00*/ACT2RANDOM( 8, 8, 5),
-/*01*/ACT2RANDOM( 8, 8, 5),
-/*02*/ACT2RANDOM( 8, 8, 5),
-/*03*/ACT2RANDOM( 8, 8, 5),
-/*04*/ACT2RANDOM(20, 0, 6),
-/*05*/ACT2RANDOM( 8, 0, 0),
-/*06*/ACT2RANDOM( 0, 0, 0),
-/*07*/ACT2RANDOM( 8, 0, 2),
-/*08*/ACT2RANDOM( 0, 0, 0),
-/*09*/ACT2RANDOM( 8, 16, 3),
-/*0A*/ACT2RANDOM(16, 0, 0),
-/*0B*/ACT2RANDOM( 0, 0, 0),
-/*0C*/ACT2RANDOM( 0, 0, 0),
-/*0D*/ACT2RANDOM( 0, 0, 0),
-/*0E*/ACT2RANDOM( 0, 0, 0),
-/*0F*/ACT2RANDOM( 8, 0, 0),
-/*10*/ACT2RANDOM( 2, 0, 0),
-/*11*/ACT2RANDOM( 4, 16, 0),
-NDF_END
-};
+static const unsigned char _dat2r[] = {NDF_HEADER(0x02, 6),
+ /*Maximum feature:*/ 0x11,
+ /*00*/ ACT2RANDOM(8, 8, 5),
+ /*01*/ ACT2RANDOM(8, 8, 5),
+ /*02*/ ACT2RANDOM(8, 8, 5),
+ /*03*/ ACT2RANDOM(8, 8, 5),
+ /*04*/ ACT2RANDOM(20, 0, 6),
+ /*05*/ ACT2RANDOM(8, 0, 0),
+ /*06*/ ACT2RANDOM(0, 0, 0),
+ /*07*/ ACT2RANDOM(8, 0, 2),
+ /*08*/ ACT2RANDOM(0, 0, 0),
+ /*09*/ ACT2RANDOM(8, 16, 3),
+ /*0A*/ ACT2RANDOM(16, 0, 0),
+ /*0B*/ ACT2RANDOM(0, 0, 0),
+ /*0C*/ ACT2RANDOM(0, 0, 0),
+ /*0D*/ ACT2RANDOM(0, 0, 0),
+ /*0E*/ ACT2RANDOM(0, 0, 0),
+ /*0F*/ ACT2RANDOM(8, 0, 0),
+ /*10*/ ACT2RANDOM(2, 0, 0),
+ /*11*/ ACT2RANDOM(4, 16, 0), NDF_END};
#undef ACT2RANDOM
// ---------------------------------------------------------------------------
-
-struct dat{
- const char*data,*name;
+struct dat
+{
+ const char *data, *name;
uint len;
};
@@ -1044,91 +1575,102 @@
#undef DATA
#undef DATA_FILE
#undef END_DATA
-#define DATA() static const dat data[]={
-#define DATA_FILE(name)\
- {(char*)_dat##name,"/.nforenum/" #name ".dat",sizeof(_dat##name)-1},\
+#define DATA() static const dat data[] = {
+#define DATA_FILE(name) \
+ { \
+ (char *) _dat##name, "/.nforenum/" #name ".dat", sizeof(_dat##name) - 1 \
+ } \
+ ,
-#define END_DATA() };
+#define END_DATA() \
+ } \
+ ;
#define NFORENUM_DIR_LEN (11)
#include "data.h"
-bool makedir(const string&dir,bool dieonfail=false){
- if(dir==""){
- if(dieonfail)exit(EDATA);
+bool makedir(const string &dir, bool dieonfail = false)
+{
+ if (dir == "") {
+ if (dieonfail) exit(EDATA);
return false;
}
- if(mkdir((dir+"/.nforenum").c_str(),0755)){
- IssueMessage(0,CREATE_FAILED,dir.c_str(),errno);
+ if (mkdir((dir + "/.nforenum").c_str(), 0755)) {
+ IssueMessage(0, CREATE_FAILED, dir.c_str(), errno);
perror(NULL);
- if(dosleep)sleep(5);
- if(dieonfail)exit(EDATA);
+ if (dosleep) sleep(5);
+ if (dieonfail) exit(EDATA);
return false;
- }else{
- IssueMessage(0,CREATED_DIR,dir.c_str());
- if(dosleep)sleep(5);
+ } else {
+ IssueMessage(0, CREATED_DIR, dir.c_str());
+ if (dosleep) sleep(5);
return true;
}
}
-bool finddir(string&dir){
- if(dir=="")return false;
+bool finddir(string &dir)
+{
+ if (dir == "") return false;
struct stat Stat;
- if(dir[dir.length()-1]=='\\'||dir[dir.length()-1]=='/')
- dir.resize(dir.length()-1);
- if(stat((dir+"/.nforenum").c_str(),&Stat))return false;
- else if(Stat.st_mode&S_IFREG)return false;
+ if (dir[dir.length() - 1] == '\\' || dir[dir.length() - 1] == '/') dir.resize(dir.length() - 1);
+ if (stat((dir + "/.nforenum").c_str(), &Stat))
+ return false;
+ else if (Stat.st_mode & S_IFREG)
+ return false;
return true;
}
-static string getdir(bool allow_mkdir){
+static string getdir(bool allow_mkdir)
+{
string *pret;
- string cwd,home,homedrpath;
- if(datadir!=""){
- verify(finddir(datadir)||makedir(datadir,true));
- pret=&datadir;
- }else{
+ string cwd, home, homedrpath;
+ if (datadir != "") {
+ verify(finddir(datadir) || makedir(datadir, true));
+ pret = &datadir;
+ } else {
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
-// getcwd is deprecated in MSVS 8.0+
- char*pcwd=_getcwd(NULL,0);
+ // getcwd is deprecated in MSVS 8.0+
+ char *pcwd = _getcwd(NULL, 0);
#else
- char*pcwd=getcwd(NULL,0);
+ char *pcwd = getcwd(NULL, 0);
#endif
- cwd=pcwd;
- home=safetostring(getenv("HOME"));
- homedrpath=safetostring(getenv("HOMEDRIVE"))+safetostring(getenv("HOMEPATH"));
+ cwd = pcwd;
+ home = safetostring(getenv("HOME"));
+ homedrpath = safetostring(getenv("HOMEDRIVE")) + safetostring(getenv("HOMEPATH"));
free(pcwd);
if (finddir(cwd)) {
- pret=&cwd;
+ pret = &cwd;
} else if (finddir(home) || (!home.empty() && (!allow_mkdir || makedir(home)))) {
- pret=&home;
+ pret = &home;
} else if (finddir(homedrpath) || (!allow_mkdir || makedir(homedrpath))) {
- pret=&homedrpath;
- } else{
+ pret = &homedrpath;
+ } else {
if (allow_mkdir) verify(makedir(cwd, true));
- pret=&cwd;
+ pret = &cwd;
}
}
- if(!dosleep)IssueMessage(0,DATA_FOUND_AT,pret->c_str());
+ if (!dosleep) IssueMessage(0, DATA_FOUND_AT, pret->c_str());
return *pret;
}
-FILE*tryopen(const char*name,const char*mode,bool allownull=false){
+FILE *tryopen(const char *name, const char *mode, bool allownull = false)
+{
string dir = getdir(mode[0] == 'w');
- FILE*pFile=fopen((dir+name).c_str(),mode);
- if(pFile||allownull)return pFile;
- IssueMessage(0,DATAFILE_ERROR,OPEN,name+1,ERRNO,errno);
+ FILE *pFile = fopen((dir + name).c_str(), mode);
+ if (pFile || allownull) return pFile;
+ IssueMessage(0, DATAFILE_ERROR, OPEN, name + 1, ERRNO, errno);
perror(NULL);
assert(false);
exit(EDATA);
}
-FILE*_myfopen(files file, bool write){
- FILE*pFile=tryopen(data[file].name,"rb",true);
- if(pFile){
- if(fgetc(pFile)==data[file].data[0]&&fgetc(pFile)>=data[file].data[1]){
- if(file>datfeat && (uint)fgetc(pFile)<MaxFeature()){
- IssueMessage(0,DATAFILE_MISMATCH,data[file].name+NFORENUM_DIR_LEN);
+FILE *_myfopen(files file, bool write)
+{
+ FILE *pFile = tryopen(data[file].name, "rb", true);
+ if (pFile) {
+ if (fgetc(pFile) == data[file].data[0] && fgetc(pFile) >= data[file].data[1]) {
+ if (file > datfeat && (uint)fgetc(pFile) < MaxFeature()) {
+ IssueMessage(0, DATAFILE_MISMATCH, data[file].name + NFORENUM_DIR_LEN);
assert(false);
exit(EDATA);
}
@@ -1148,42 +1690,45 @@
} else
#endif /* WITH_FMEMOPEN */
{
- pFile = tryopen(data[file].name,"wb");
+ pFile = tryopen(data[file].name, "wb");
if (fwrite(data[file].data, 1, data[file].len, pFile) != data[file].len) {
IssueMessage(0, DATAFILE_ERROR, WRITE, data[file].name + 1, -1);
assert(false);
exit(EDATA);
}
fclose(pFile);
- pFile = tryopen(data[file].name,"rb");
+ pFile = tryopen(data[file].name, "rb");
}
fgetc(pFile);
fgetc(pFile);
- if(file>datfeat && (uint)fgetc(pFile)<MaxFeature()){
- IssueMessage(0,DATAFILE_MISMATCH,data[file].name+NFORENUM_DIR_LEN);
+ if (file > datfeat && (uint)fgetc(pFile) < MaxFeature()) {
+ IssueMessage(0, DATAFILE_MISMATCH, data[file].name + NFORENUM_DIR_LEN);
assert(false);
exit(EDATA);
}
return pFile;
}
-int _CheckEOF(int dat,files file,const char*src,int line){
- if(dat==EOF){
- IssueMessage(0,DATAFILE_ERROR,LOAD,data[file].name+NFORENUM_DIR_LEN,FILELINE,src,line);
+int _CheckEOF(int dat, files file, const char *src, int line)
+{
+ if (dat == EOF) {
+ IssueMessage(0, DATAFILE_ERROR, LOAD, data[file].name + NFORENUM_DIR_LEN, FILELINE, src, line);
assert(false);
exit(EDATA);
}
return dat;
}
-int _GetCheckWord(FILE*pFile,files file,const char*src,int line){
- int ret=fgetc(pFile);
- return ret|(_CheckEOF(fgetc(pFile),file,src,line)<<8);
+int _GetCheckWord(FILE *pFile, files file, const char *src, int line)
+{
+ int ret = fgetc(pFile);
+ return ret | (_CheckEOF(fgetc(pFile), file, src, line) << 8);
}
-void _myfread(FILE*pFile,uchar*target,uint count,files file,const char*src,int line){
- if(fread(target,1,count,pFile)!=count){
- IssueMessage(0,DATAFILE_ERROR,LOAD,data[file].name+NFORENUM_DIR_LEN,FILELINE,src,line);
+void _myfread(FILE *pFile, uchar *target, uint count, files file, const char *src, int line)
+{
+ if (fread(target, 1, count, pFile) != count) {
+ IssueMessage(0, DATAFILE_ERROR, LOAD, data[file].name + NFORENUM_DIR_LEN, FILELINE, src, line);
assert(false);
exit(EDATA);
}
diff --git a/src/data.h b/src/data.h
--- a/src/data.h
+++ b/src/data.h
@@ -25,13 +25,16 @@
#include <cstdio>
#ifndef DATA
-#define DATA() enum files{
+#define DATA() enum files {
#endif
#ifndef DATA_FILE
#define DATA_FILE(name) dat##name,
#endif
#ifndef END_DATA
-#define END_DATA() FILES_MAX };
+#define END_DATA() \
+ FILES_MAX \
+ } \
+ ;
#endif
DATA()
@@ -78,14 +81,14 @@
END_DATA()
#define myfopen(file) _myfopen(dat##file, false)
-FILE*_myfopen(files, bool);
-int _CheckEOF(int,files,const char*,int);
-int _GetCheckWord(FILE*,files,const char*,int);
-void _myfread(FILE*,uchar*,uint,files,const char*,int);
+FILE* _myfopen(files, bool);
+int _CheckEOF(int, files, const char*, int);
+int _GetCheckWord(FILE*, files, const char*, int);
+void _myfread(FILE*, uchar*, uint, files, const char*, int);
-#define CheckEOF(ch,name) _CheckEOF(ch,dat##name,__FILE__,__LINE__)
-#define GetCheckByte(name) CheckEOF(fgetc(pFile),name)
-#define GetCheckWord(name) _GetCheckWord(pFile,dat##name,__FILE__,__LINE__)
-#define myfread(pch,count,name) _myfread(pFile,pch,count,dat##name,__FILE__,__LINE__)
+#define CheckEOF(ch, name) _CheckEOF(ch, dat##name, __FILE__, __LINE__)
+#define GetCheckByte(name) CheckEOF(fgetc(pFile), name)
+#define GetCheckWord(name) _GetCheckWord(pFile, dat##name, __FILE__, __LINE__)
+#define myfread(pch, count, name) _myfread(pFile, pch, count, dat##name, __FILE__, __LINE__)
-#endif//_RENUM_DATA_H_INCLUDED_
+#endif //_RENUM_DATA_H_INCLUDED_
diff --git a/src/endian_check.cpp b/src/endian_check.cpp
--- a/src/endian_check.cpp
+++ b/src/endian_check.cpp
@@ -15,9 +15,10 @@
* @param argv arguments themselves
* @return exit code
*/
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
{
- union {
+ union
+ {
unsigned int i;
char c[4];
} bint = {0x01020304};
@@ -29,12 +30,12 @@
const char *endian = little_endian ? "LITTLE" : "BIG";
printf(
- "#ifndef ENDIAN_H\n"
- "#define ENDIAN_H\n"
- "#define GRFCODEC_%s_ENDIAN 1\n"
- "#define ARCH_IS_%s_ENDIAN 1\n"
- "#endif /* ENDIAN_H */\n",
- endian, endian);
+ "#ifndef ENDIAN_H\n"
+ "#define ENDIAN_H\n"
+ "#define GRFCODEC_%s_ENDIAN 1\n"
+ "#define ARCH_IS_%s_ENDIAN 1\n"
+ "#endif /* ENDIAN_H */\n",
+ endian, endian);
return 0;
}
diff --git a/src/error.h b/src/error.h
--- a/src/error.h
+++ b/src/error.h
@@ -6,4 +6,3 @@
void fperror(const char *format, ...);
#endif /* _ERROR_H */
-
diff --git a/src/escapes.h b/src/escapes.h
--- a/src/escapes.h
+++ b/src/escapes.h
@@ -4,62 +4,79 @@
// This file is shared between GRFCodec and NFORenum.
// GRFCodec defines GRFCODEC. NFORenum does not.
-
#ifndef GRFCODEC
-#define START_ESCAPES()\
- const struct esc{\
- char byte;\
- char*str;\
- char action;\
- uint pos;\
- }escapes[]={
+#define START_ESCAPES() \
+ const struct esc \
+ { \
+ char byte; \
+ char* str; \
+ char action; \
+ uint pos; \
+ } escapes[] = {
-#define ESCAPE(byte,str,action,off)\
- {(char)0x##byte,(char*)("\\" str),(char)0x##action,off},
+#define ESCAPE(byte, str, action, off) \
+ { \
+ (char)0x##byte, (char*)("\\" str), (char)0x##action, off \
+ } \
+ ,
-#define ESCAPE_79(byte,str,off)\
- ESCAPE(byte,str,7,off)
+#define ESCAPE_79(byte, str, off) ESCAPE(byte, str, 7, off)
-#define ESCAPE_AD(byte,str,action,off,adtl)\
- {(char)0x##byte,(char*)("\\" str),(char)0x##action,off},
+#define ESCAPE_AD(byte, str, action, off, adtl) \
+ { \
+ (char)0x##byte, (char*)("\\" str), (char)0x##action, off \
+ } \
+ ,
-#define ESCAPE_OVR(byte,str,action,ovr)\
- {(char)0x##byte,(char*)("\\" str),(char)0x##action,0},
+#define ESCAPE_OVR(byte, str, action, ovr) \
+ { \
+ (char)0x##byte, (char*)("\\" str), (char)0x##action, 0 \
+ } \
+ ,
-#else /* GRFCODEC */
+#else /* GRFCODEC */
-#define START_ESCAPES()\
- const struct esc{\
- char byte;\
- char*str;\
- char action;\
- uint pos;\
- bool (*additional)(const U8*,uint);\
- bool (*override)(const U8*,uint);\
- }escapes[]={
+#define START_ESCAPES() \
+ const struct esc \
+ { \
+ char byte; \
+ char* str; \
+ char action; \
+ uint pos; \
+ bool (*additional)(const U8*, uint); \
+ bool (*override)(const U8*, uint); \
+ } escapes[] = {
-#define ESCAPE(byte,str,action,off)\
- {(char)0x##byte,(char*)("\\" str),(char)0x##action,off,NULL,NULL},
+#define ESCAPE(byte, str, action, off) \
+ { \
+ (char)0x##byte, (char*)("\\" str), (char)0x##action, off, NULL, NULL \
+ } \
+ ,
-#define ESCAPE_79(byte,str,off)\
- ESCAPE(byte,str,7,off) ESCAPE(byte,str,9,off)
+#define ESCAPE_79(byte, str, off) ESCAPE(byte, str, 7, off) ESCAPE(byte, str, 9, off)
-#define ESCAPE_AD(byte,str,action,off,adtl)\
- {(char)0x##byte,(char*)("\\" str),(char)0x##action,off,__ESC_AD__##adtl,NULL},
+#define ESCAPE_AD(byte, str, action, off, adtl) \
+ { \
+ (char)0x##byte, (char*)("\\" str), (char)0x##action, off, __ESC_AD__##adtl, NULL \
+ } \
+ ,
-#define ESCAPE_OVR(byte,str,action,ovr)\
- {(char)0x##byte,(char*)("\\" str),(char)0x##action,0,NULL,__ESC_OVR__##ovr},
+#define ESCAPE_OVR(byte, str, action, ovr) \
+ { \
+ (char)0x##byte, (char*)("\\" str), (char)0x##action, 0, NULL, __ESC_OVR__##ovr \
+ } \
+ ,
-#define CALLBACK_AD(name)\
- bool __ESC_AD__##name(const U8*data,uint len)
-#define CALLBACK_OVR(name)\
- bool __ESC_OVR__##name(const U8*data,uint pos)
+#define CALLBACK_AD(name) bool __ESC_AD__##name(const U8* data, uint len)
+#define CALLBACK_OVR(name) bool __ESC_OVR__##name(const U8* data, uint pos)
#endif /* GRFCODEC */
-#define END_ESCAPES() };\
- static const unsigned int num_esc=sizeof(escapes)/sizeof(escapes[0]);
+#define END_ESCAPES() \
+ } \
+ ; \
+ static const unsigned int num_esc = sizeof(escapes) / sizeof(escapes[0]);
#ifdef GRFCODEC
@@ -73,23 +90,24 @@
// bool func(const U8*data, uint pos)
// ***********************************************************************
-CALLBACK_AD(IsGRM){
- return len==9&&data[2]==0&&data[4]==0xFE&&data[5]==0xFF;
+CALLBACK_AD(IsGRM)
+{
+ return len == 9 && data[2] == 0 && data[4] == 0xFE && data[5] == 0xFF;
}
-CALLBACK_OVR(Is2Op){
- if(pos<7||!(data[3]&0x80)||data[3]==0x80||data[3]==0x83)return false;
- uint w = 1<<((data[3]>>2)&3);
- uint loc=4;//Start at first <var>
- while(true){//read <var> [<param>] <varadjust> [<op> ...]. loc reports byte to be checked.
- if((data[loc++/*<var>*/]&0xE0)==0x60)loc++;//<param>
- if(loc>=pos)return false;
- if(!(data[loc]&0x20))return false;//end of advanced
- if(data[loc++/*<shift>*/]&0xC0)
- loc+=2*w;//<add> and <div>/<mod>
- loc+=w;//<and>
- if(loc==pos)return true;//This is an operation byte
- if(loc++/*<op>*/>pos)return false;//past proposed op byte
+CALLBACK_OVR(Is2Op)
+{
+ if (pos < 7 || !(data[3] & 0x80) || data[3] == 0x80 || data[3] == 0x83) return false;
+ uint w = 1 << ((data[3] >> 2) & 3);
+ uint loc = 4; // Start at first <var>
+ while (true) { // read <var> [<param>] <varadjust> [<op> ...]. loc reports byte to be checked.
+ if ((data[loc++ /*<var>*/] & 0xE0) == 0x60) loc++; //<param>
+ if (loc >= pos) return false;
+ if (!(data[loc] & 0x20)) return false; // end of advanced
+ if (data[loc++ /*<shift>*/] & 0xC0) loc += 2 * w; //<add> and <div>/<mod>
+ loc += w; //<and>
+ if (loc == pos) return true; // This is an operation byte
+ if (loc++ /*<op>*/ > pos) return false; // past proposed op byte
}
}
@@ -112,67 +130,67 @@
// instead of running the off check.
// ***********************************************************************
-ESCAPE_OVR(00,"2+",2,Is2Op)
-ESCAPE_OVR(01,"2-",2,Is2Op)
-ESCAPE_OVR(02,"2<",2,Is2Op)
-ESCAPE_OVR(03,"2>",2,Is2Op)
-ESCAPE_OVR(04,"2u<",2,Is2Op)
-ESCAPE_OVR(05,"2u>",2,Is2Op)
-ESCAPE_OVR(06,"2/",2,Is2Op)
-ESCAPE_OVR(07,"2%",2,Is2Op)
-ESCAPE_OVR(08,"2u/",2,Is2Op)
-ESCAPE_OVR(09,"2u%",2,Is2Op)
-ESCAPE_OVR(0A,"2*",2,Is2Op)
-ESCAPE_OVR(0B,"2&",2,Is2Op)
-ESCAPE_OVR(0C,"2|",2,Is2Op)
-ESCAPE_OVR(0D,"2^",2,Is2Op)
-ESCAPE_OVR(0E,"2sto",2,Is2Op)
-ESCAPE_OVR(0E,"2s",2,Is2Op)
-ESCAPE_OVR(0F,"2rst",2,Is2Op)
-ESCAPE_OVR(0F,"2r",2,Is2Op)
-ESCAPE_OVR(10,"2psto",2,Is2Op)
-ESCAPE_OVR(11,"2ror",2,Is2Op)
-ESCAPE_OVR(11,"2rot",2,Is2Op)
-ESCAPE_OVR(12,"2cmp",2,Is2Op)
-ESCAPE_OVR(13,"2ucmp",2,Is2Op)
-ESCAPE_OVR(14,"2<<",2,Is2Op)
-ESCAPE_OVR(15,"2u>>",2,Is2Op)
-ESCAPE_OVR(16,"2>>",2,Is2Op)
+ESCAPE_OVR(00, "2+", 2, Is2Op)
+ESCAPE_OVR(01, "2-", 2, Is2Op)
+ESCAPE_OVR(02, "2<", 2, Is2Op)
+ESCAPE_OVR(03, "2>", 2, Is2Op)
+ESCAPE_OVR(04, "2u<", 2, Is2Op)
+ESCAPE_OVR(05, "2u>", 2, Is2Op)
+ESCAPE_OVR(06, "2/", 2, Is2Op)
+ESCAPE_OVR(07, "2%", 2, Is2Op)
+ESCAPE_OVR(08, "2u/", 2, Is2Op)
+ESCAPE_OVR(09, "2u%", 2, Is2Op)
+ESCAPE_OVR(0A, "2*", 2, Is2Op)
+ESCAPE_OVR(0B, "2&", 2, Is2Op)
+ESCAPE_OVR(0C, "2|", 2, Is2Op)
+ESCAPE_OVR(0D, "2^", 2, Is2Op)
+ESCAPE_OVR(0E, "2sto", 2, Is2Op)
+ESCAPE_OVR(0E, "2s", 2, Is2Op)
+ESCAPE_OVR(0F, "2rst", 2, Is2Op)
+ESCAPE_OVR(0F, "2r", 2, Is2Op)
+ESCAPE_OVR(10, "2psto", 2, Is2Op)
+ESCAPE_OVR(11, "2ror", 2, Is2Op)
+ESCAPE_OVR(11, "2rot", 2, Is2Op)
+ESCAPE_OVR(12, "2cmp", 2, Is2Op)
+ESCAPE_OVR(13, "2ucmp", 2, Is2Op)
+ESCAPE_OVR(14, "2<<", 2, Is2Op)
+ESCAPE_OVR(15, "2u>>", 2, Is2Op)
+ESCAPE_OVR(16, "2>>", 2, Is2Op)
-ESCAPE_79(00,"71",3)
-ESCAPE_79(01,"70",3)
-ESCAPE_79(02,"7=",3)
-ESCAPE_79(03,"7!",3)
-ESCAPE_79(04,"7<",3)
-ESCAPE_79(05,"7>",3)
-ESCAPE_79(06,"7G",3)
-ESCAPE_79(07,"7g",3)
-ESCAPE_79(08,"7gG",3)
-ESCAPE_79(09,"7GG",3)
-ESCAPE_79(0A,"7gg",3)
-ESCAPE_79(0B,"7c",3)
-ESCAPE_79(0C,"7C",3)
+ESCAPE_79(00, "71", 3)
+ESCAPE_79(01, "70", 3)
+ESCAPE_79(02, "7=", 3)
+ESCAPE_79(03, "7!", 3)
+ESCAPE_79(04, "7<", 3)
+ESCAPE_79(05, "7>", 3)
+ESCAPE_79(06, "7G", 3)
+ESCAPE_79(07, "7g", 3)
+ESCAPE_79(08, "7gG", 3)
+ESCAPE_79(09, "7GG", 3)
+ESCAPE_79(0A, "7gg", 3)
+ESCAPE_79(0B, "7c", 3)
+ESCAPE_79(0C, "7C", 3)
-ESCAPE(00,"D=",D,2)
-ESCAPE(01,"D+",D,2)
-ESCAPE(02,"D-",D,2)
-ESCAPE(03,"Du*",D,2)
-ESCAPE(04,"D*",D,2)
-ESCAPE(05,"Du<<",D,2)
-ESCAPE(06,"D<<",D,2)
-ESCAPE(07,"D&",D,2)
-ESCAPE(08,"D|",D,2)
-ESCAPE(09,"Du/",D,2)
-ESCAPE(0A,"D/",D,2)
-ESCAPE(0B,"Du%",D,2)
-ESCAPE(0C,"D%",D,2)
+ESCAPE(00, "D=", D, 2)
+ESCAPE(01, "D+", D, 2)
+ESCAPE(02, "D-", D, 2)
+ESCAPE(03, "Du*", D, 2)
+ESCAPE(04, "D*", D, 2)
+ESCAPE(05, "Du<<", D, 2)
+ESCAPE(06, "D<<", D, 2)
+ESCAPE(07, "D&", D, 2)
+ESCAPE(08, "D|", D, 2)
+ESCAPE(09, "Du/", D, 2)
+ESCAPE(0A, "D/", D, 2)
+ESCAPE(0B, "Du%", D, 2)
+ESCAPE(0C, "D%", D, 2)
-ESCAPE_AD(00,"DR",D,3,IsGRM)
-ESCAPE_AD(01,"DF",D,3,IsGRM)
-ESCAPE_AD(02,"DC",D,3,IsGRM)
-ESCAPE_AD(03,"DM",D,3,IsGRM)
-ESCAPE_AD(04,"DnF",D,3,IsGRM)
-ESCAPE_AD(05,"DnC",D,3,IsGRM)
-ESCAPE_AD(06,"DO",D,3,IsGRM)
+ESCAPE_AD(00, "DR", D, 3, IsGRM)
+ESCAPE_AD(01, "DF", D, 3, IsGRM)
+ESCAPE_AD(02, "DC", D, 3, IsGRM)
+ESCAPE_AD(03, "DM", D, 3, IsGRM)
+ESCAPE_AD(04, "DnF", D, 3, IsGRM)
+ESCAPE_AD(05, "DnC", D, 3, IsGRM)
+ESCAPE_AD(06, "DO", D, 3, IsGRM)
END_ESCAPES()
diff --git a/src/file.cpp b/src/file.cpp
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -45,8 +45,7 @@
singlefile::~singlefile()
{
- if (autoclose && thefile)
- fclose(thefile);
+ if (autoclose && thefile) fclose(thefile);
free(thefilename);
free(directory);
};
diff --git a/src/file.h b/src/file.h
--- a/src/file.h
+++ b/src/file.h
@@ -17,29 +17,51 @@
* *
\*****************************************/
-
-class multifile {
- public:
+class multifile
+{
+ public:
multifile() {};
virtual ~multifile() {};
- virtual FILE *curfile() { return NULL; };
- virtual FILE *nextfile() { return NULL; };
- virtual const char *filename() { return NULL; };
- virtual const char *getdirectory() { return NULL; };
+ virtual FILE *curfile()
+ {
+ return NULL;
+ };
+ virtual FILE *nextfile()
+ {
+ return NULL;
+ };
+ virtual const char *filename()
+ {
+ return NULL;
+ };
+ virtual const char *getdirectory()
+ {
+ return NULL;
+ };
};
-class singlefile : public multifile {
- public:
+class singlefile : public multifile
+{
+ public:
singlefile(const char *filename, const char *mode, const char *dir);
virtual ~singlefile();
void setfile(FILE *file);
- virtual FILE *curfile() { return thefile; };
- virtual const char *filename() { return thefilename; };
- virtual const char *getdirectory() { return directory; };
+ virtual FILE *curfile()
+ {
+ return thefile;
+ };
+ virtual const char *filename()
+ {
+ return thefilename;
+ };
+ virtual const char *getdirectory()
+ {
+ return directory;
+ };
- private:
+ private:
char *thefilename, *directory;
FILE *thefile;
int autoclose;
diff --git a/src/globals.cpp b/src/globals.cpp
--- a/src/globals.cpp
+++ b/src/globals.cpp
@@ -19,18 +19,18 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<iostream>
-#include<string>
+#include <iostream>
+#include <string>
using namespace std;
#include "globals.h"
-ostream*pNfo=&cout,*pOut,*pErr=&cerr;
+ostream* pNfo = &cout, *pOut, *pErr = &cerr;
-const char*const VALID_PSEUDO="0123456789ABCDEFabcdef \t\v\r\n",*const WHITESPACE=" \t\v\r\n";
-const string COMMENT="/;#";
+const char* const VALID_PSEUDO = "0123456789ABCDEFabcdef \t\v\r\n", *const WHITESPACE = " \t\v\r\n";
+const string COMMENT = "/;#";
string datadir;
-const char*COMMENT_PREFIX="//";
-bool dosleep=true;
-unsigned int _spritenum,_grfver,_autocorrect=0,_act14_pal;
+const char* COMMENT_PREFIX = "//";
+bool dosleep = true;
+unsigned int _spritenum, _grfver, _autocorrect = 0, _act14_pal;
diff --git a/src/globals.h b/src/globals.h
--- a/src/globals.h
+++ b/src/globals.h
@@ -22,38 +22,39 @@
#ifndef _RENUM_GLOBALS_H_INCLUDED_
#define _RENUM_GLOBALS_H_INCLUDED_
-#include<ostream>
-#include<string>
+#include <ostream>
+#include <string>
// NFO header string
-#define NFO_HEADER(ver)\
- ("// Automatically generated by GRFCODEC. Do not modify!\n"\
- "// (Info version "+itoa(ver)+")\n")
+#define NFO_HEADER(ver) \
+ ("// Automatically generated by GRFCODEC. Do not modify!\n" \
+ "// (Info version " + \
+ itoa(ver) + ")\n")
-#define NFO_FORMAT(ver)\
- (ver >= 32 ? "// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags\n"\
- : "// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel\n")
+#define NFO_FORMAT(ver) \
+ (ver >= 32 ? "// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags\n" \
+ : "// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel\n")
-extern const char*const VALID_PSEUDO; // List of valid pseudo-sprite characters
-extern const char*const WHITESPACE; // List of whitespace characters
-extern const std::string COMMENT; // List of comment prefix characters
+extern const char* const VALID_PSEUDO; // List of valid pseudo-sprite characters
+extern const char* const WHITESPACE; // List of whitespace characters
+extern const std::string COMMENT; // List of comment prefix characters
extern std::string datadir; // Current data directory path
-extern bool dosleep; // If true, program will wait after creating a new data directory
- // If false, program will report where it found its data files.
+extern bool dosleep; // If true, program will wait after creating a new data directory
+ // If false, program will report where it found its data files.
-extern const char*COMMENT_PREFIX; // Comment prefix string
+extern const char* COMMENT_PREFIX; // Comment prefix string
#define NPOS (std::basic_string<char>::npos)
-extern unsigned int _spritenum; // Current sprite number
-extern unsigned int _grfver; // GRF format version of current NFO
-extern unsigned int _act14_pal; // Palette info from action 14
+extern unsigned int _spritenum; // Current sprite number
+extern unsigned int _grfver; // GRF format version of current NFO
+extern unsigned int _act14_pal; // Palette info from action 14
extern unsigned int _autocorrect; // Auto-correction level
-//TODO: add command-line arguments to set these appropriately.
-extern std::ostream*pNfo; // NFO file output stream
-extern std::ostream*pOut; // Console output stream
-extern std::ostream*pErr; // Error output stream
+// TODO: add command-line arguments to set these appropriately.
+extern std::ostream* pNfo; // NFO file output stream
+extern std::ostream* pOut; // Console output stream
+extern std::ostream* pErr; // Error output stream
-#endif//_RENUM_GLOBALS_H_INCLUDED_
+#endif //_RENUM_GLOBALS_H_INCLUDED_
diff --git a/src/grfcodec.cpp b/src/grfcodec.cpp
--- a/src/grfcodec.cpp
+++ b/src/grfcodec.cpp
@@ -25,18 +25,18 @@
#include <getopt.h>
#ifdef MINGW
- #include <io.h>
- #define mkdir(a,b) mkdir(a)
- #define isatty _isatty
+#include <io.h>
+#define mkdir(a, b) mkdir(a)
+#define isatty _isatty
#elif defined(_MSC_VER)
- #include <io.h>
- #include <direct.h>
- #define mkdir(a,b) mkdir(a)
- #define F_OK 0
- #define isatty _isatty
+#include <io.h>
+#include <direct.h>
+#define mkdir(a, b) mkdir(a)
+#define F_OK 0
+#define isatty _isatty
#else
- #include <unistd.h>
-#endif//_MSC_VER
+#include <unistd.h>
+#endif //_MSC_VER
#define DOCHECK
#define DEFINE_PALS
@@ -59,50 +59,49 @@
static void usage(void)
{
printf(
- "%s\n"
- "Usage:\n"
- " GRFCODEC -d [<Options>] <GRF-File> [<Directory>]\n"
- " Decode all sprites in the GRF file and put them in the directory\n"
- " GRFCODEC -e [<Options>] <GRF-File> [<Directory>]\n"
- " Encode all sprites in the directory and combine them in the GRF file\n"
- "\n"
- "<GRF-File> denotes the .GRF file you want to work on, e.g. TRG1.GRF\n"
- "<Directory> is where the individual sprites should be saved. If omitted, they\n"
- "\twill default to a subdirectory called sprites/.\n"
- "\n"
- "Options for decoding:\n"
- " -w <num> Write spritesheets with the given width (default 800, minimum 16)\n"
- " -h <num> Split spritesheets when they reach this height (default no limit,\n"
- " minimum 16)\n"
- " -b <num> Organize sprites in boxes of this size (default 16)\n"
- " -o <ssf> Sets the format of generated spritesheets. See -o ? for a list.\n"
- " -p <pal> Use this palette instead of the default. See -p ? for a list.\n"
- " -t Disable decoding of plain text characters as strings.\n"
- " -x Disable production of unquoted escape sequences.\n"
- " -xx Disable production of both quoted and unquoted escape sequences.\n"
- " This has the side effect of producing a version 6 .nfo, instead\n"
- " of a version 32 .nfo.\n"
- " -X List sprite numbers in the PCX file in hex.\n"
- "\n"
- "Options for encoding:\n"
- " -c Crop extraneous transparent blue from real sprites\n"
- " -u Save uncompressed data (probably not a good idea)\n"
- " -q Suppress warning messages\n"
- " -s Suppress progress output\n"
- " -g <num> Version of the encoded container format (default 1, maximum 2)\n"
- " -n Try both compression algorithms and choose the most efficient\n"
- "\n"
- "Options for both encoding and decoding:\n"
- " -m <num> Apply colour translation to all sprites except character-glyphs.\n"
- " -M <num> Apply colour translation to all sprites.\n"
- " If both of these are specified, only the last is obeyed.\n"
- " (-m ? or -M ? for a list of colour translations.)\n"
- "\n"
- "GRFCODEC is Copyright (C) 2000-2005 by Josef Drexler\n"
- "You may copy and redistribute it under the terms of the GNU General Public\n"
- "License, as stated in the file 'COPYING'.\n",
- version
- );
+ "%s\n"
+ "Usage:\n"
+ " GRFCODEC -d [<Options>] <GRF-File> [<Directory>]\n"
+ " Decode all sprites in the GRF file and put them in the directory\n"
+ " GRFCODEC -e [<Options>] <GRF-File> [<Directory>]\n"
+ " Encode all sprites in the directory and combine them in the GRF file\n"
+ "\n"
+ "<GRF-File> denotes the .GRF file you want to work on, e.g. TRG1.GRF\n"
+ "<Directory> is where the individual sprites should be saved. If omitted, they\n"
+ "\twill default to a subdirectory called sprites/.\n"
+ "\n"
+ "Options for decoding:\n"
+ " -w <num> Write spritesheets with the given width (default 800, minimum 16)\n"
+ " -h <num> Split spritesheets when they reach this height (default no limit,\n"
+ " minimum 16)\n"
+ " -b <num> Organize sprites in boxes of this size (default 16)\n"
+ " -o <ssf> Sets the format of generated spritesheets. See -o ? for a list.\n"
+ " -p <pal> Use this palette instead of the default. See -p ? for a list.\n"
+ " -t Disable decoding of plain text characters as strings.\n"
+ " -x Disable production of unquoted escape sequences.\n"
+ " -xx Disable production of both quoted and unquoted escape sequences.\n"
+ " This has the side effect of producing a version 6 .nfo, instead\n"
+ " of a version 32 .nfo.\n"
+ " -X List sprite numbers in the PCX file in hex.\n"
+ "\n"
+ "Options for encoding:\n"
+ " -c Crop extraneous transparent blue from real sprites\n"
+ " -u Save uncompressed data (probably not a good idea)\n"
+ " -q Suppress warning messages\n"
+ " -s Suppress progress output\n"
+ " -g <num> Version of the encoded container format (default 1, maximum 2)\n"
+ " -n Try both compression algorithms and choose the most efficient\n"
+ "\n"
+ "Options for both encoding and decoding:\n"
+ " -m <num> Apply colour translation to all sprites except character-glyphs.\n"
+ " -M <num> Apply colour translation to all sprites.\n"
+ " If both of these are specified, only the last is obeyed.\n"
+ " (-m ? or -M ? for a list of colour translations.)\n"
+ "\n"
+ "GRFCODEC is Copyright (C) 2000-2005 by Josef Drexler\n"
+ "You may copy and redistribute it under the terms of the GNU General Public\n"
+ "License, as stated in the file 'COPYING'.\n",
+ version);
exit(1);
}
@@ -110,95 +109,90 @@
static void showpalettetext()
{
printf(
- "Options for the -p parameter:\n"
- "\n"
- "Built-in palettes: use -p <number>, where <number> is one of the following:\n"
- " %d DOS TTD\n"
- " %d Windows TTD\n"
- " %d DOS TTD, Candyland\n"
- " %d Windows TTD, Candyland\n"
- " %d TT Original\n"
- " %d TT Original, Mars landscape\n"
- "\n"
- "External palette files: use -p [type:]filename.\n"
- "[type:] can be bcp, psp, or gpl. (Other formats may become available later.)\n"
- "If the type is omitted, bcp is assumed.\n"
- "\n"
- "bcp binary coded palette with the same format as the palette in a PCX\n"
- " file: 256 triples of red, green and blue encoded in bytes.\n"
- "psp the palette format output by Paintshop Pro\n"
- "gpl the palette format output by The GIMP.\n"
- "\n",
+ "Options for the -p parameter:\n"
+ "\n"
+ "Built-in palettes: use -p <number>, where <number> is one of the following:\n"
+ " %d DOS TTD\n"
+ " %d Windows TTD\n"
+ " %d DOS TTD, Candyland\n"
+ " %d Windows TTD, Candyland\n"
+ " %d TT Original\n"
+ " %d TT Original, Mars landscape\n"
+ "\n"
+ "External palette files: use -p [type:]filename.\n"
+ "[type:] can be bcp, psp, or gpl. (Other formats may become available later.)\n"
+ "If the type is omitted, bcp is assumed.\n"
+ "\n"
+ "bcp binary coded palette with the same format as the palette in a PCX\n"
+ " file: 256 triples of red, green and blue encoded in bytes.\n"
+ "psp the palette format output by Paintshop Pro\n"
+ "gpl the palette format output by The GIMP.\n"
+ "\n",
- // note, -p values are the array index plus one (so that 0 is not
- // a valid number, which makes the atoi easier)
- PAL_ttd_norm+1, PAL_ttw_norm+1, PAL_ttd_cand+1, PAL_ttw_cand+1,
- PAL_tt1_norm+1, PAL_tt1_mars+1
- );
+ // note, -p values are the array index plus one (so that 0 is not
+ // a valid number, which makes the atoi easier)
+ PAL_ttd_norm + 1, PAL_ttw_norm + 1, PAL_ttd_cand + 1, PAL_ttw_cand + 1, PAL_tt1_norm + 1, PAL_tt1_mars + 1);
}
static void showcolourmaps()
{
printf(
- "Options for the -m parameter:\n"
- "\n"
- " 0 Convert a TTD-DOS file to TTD-Windows\n"
- " 1 Convert a TTD-Windows file to TTD-DOS\n"
- "\n"
- );
+ "Options for the -m parameter:\n"
+ "\n"
+ " 0 Convert a TTD-DOS file to TTD-Windows\n"
+ " 1 Convert a TTD-Windows file to TTD-DOS\n"
+ "\n");
}
static void showimageformats()
{
printf(
- "Options for the -o parameter:\n"
- "\n"
+ "Options for the -o parameter:\n"
+ "\n"
#ifdef WITH_PNG
- " pcx\n"
- " png (default)\n"
+ " pcx\n"
+ " png (default)\n"
#else
- " pcx (default)\n"
+ " pcx (default)\n"
#endif
- "\n"
- );
+ "\n");
}
-struct defpal {
- const char* grffile;
+struct defpal
+{
+ const char *grffile;
int defpalno;
};
-static const defpal defpals[] =
-{
- // DOS TTD
- { "TRG1", PAL_ttd_norm },
- { "TRGC", PAL_ttd_norm },
- { "TRGH", PAL_ttd_norm },
- { "TRGI", PAL_ttd_norm },
- { "TRGT", PAL_ttd_cand },
+static const defpal defpals[] = {
+ // DOS TTD
+ {"TRG1", PAL_ttd_norm},
+ {"TRGC", PAL_ttd_norm},
+ {"TRGH", PAL_ttd_norm},
+ {"TRGI", PAL_ttd_norm},
+ {"TRGT", PAL_ttd_cand},
- // Windows TTD
- { "TRG1R", PAL_ttw_norm },
- { "TRGCR", PAL_ttw_norm },
- { "TRGHR", PAL_ttw_norm },
- { "TRGIR", PAL_ttw_norm },
- { "TRGTR", PAL_ttw_cand },
+ // Windows TTD
+ {"TRG1R", PAL_ttw_norm},
+ {"TRGCR", PAL_ttw_norm},
+ {"TRGHR", PAL_ttw_norm},
+ {"TRGIR", PAL_ttw_norm},
+ {"TRGTR", PAL_ttw_cand},
- // DOS TTO or TT+WB
- { "TREDIT", PAL_tt1_norm },
- { "TREND", PAL_tt1_norm },
- { "TRTITLE", PAL_tt1_norm },
- { "TRHCOM", PAL_tt1_norm },
- { "TRHCOM2", PAL_tt1_mars },
+ // DOS TTO or TT+WB
+ {"TREDIT", PAL_tt1_norm},
+ {"TREND", PAL_tt1_norm},
+ {"TRTITLE", PAL_tt1_norm},
+ {"TRHCOM", PAL_tt1_norm},
+ {"TRHCOM2", PAL_tt1_mars},
- // TTDPatch
- { "TTDPATCH", PAL_ttd_norm },
- { "TTDPATCHW", PAL_ttw_norm },
- { "TTDPBASE", PAL_ttd_norm },
- { "TTDPBASEW", PAL_ttw_norm },
-};
+ // TTDPatch
+ {"TTDPATCH", PAL_ttd_norm},
+ {"TTDPATCHW", PAL_ttw_norm},
+ {"TTDPBASE", PAL_ttd_norm},
+ {"TTDPBASEW", PAL_ttw_norm}, };
-static int *colourmaps[] = { palmap0, palmap1 };
+static int *colourmaps[] = {palmap0, palmap1};
bool _interactive;
bool _best_compression = false;
@@ -214,9 +208,9 @@
// XXX: Shouldn't we rename orig to .bak even if .bak already exists? --pasky
if (_interactive) printf("\nRenaming %s to %s", realfile, bakfile);
if (rename(realfile, bakfile)) {
- errno = EEXIST; // go delete it
+ errno = EEXIST; // go delete it
} else {
- errno = ENOENT; // don't try to delete it
+ errno = ENOENT; // don't try to delete it
}
}
@@ -225,9 +219,8 @@
// delete grf if it exists
if (access(realfile, F_OK) == 0) {
- if (_interactive) printf("\nDeleting %s",realfile);
- if (remove(realfile))
- fperror("\nError deleting %s", realfile);
+ if (_interactive) printf("\nDeleting %s", realfile);
+ if (remove(realfile)) fperror("\nError deleting %s", realfile);
}
// rename tmp to grf
@@ -254,7 +247,7 @@
SpriteSheetFormat _outputformat = SSF_PCX;
#endif
-const char * getoutputext(bool rgba)
+const char *getoutputext(bool rgba)
{
switch (_outputformat) {
#ifdef WITH_PNG
@@ -267,28 +260,43 @@
}
}
-class spritefiles : public multifile {
-public:
- spritefiles() { init(); }
+class spritefiles : public multifile
+{
+ public:
+ spritefiles()
+ {
+ init();
+ }
spritefiles(const char *basename, const char *directory, bool rgba);
- virtual FILE *curfile() { return thecurfile; }
+ virtual FILE *curfile()
+ {
+ return thecurfile;
+ }
virtual FILE *nextfile();
- virtual const char *filename() { return thecurfilename; }
- virtual const char *getdirectory() { return directory; }
-private:
- void init () {
+ virtual const char *filename()
+ {
+ return thecurfilename;
+ }
+ virtual const char *getdirectory()
+ {
+ return directory;
+ }
+
+ private:
+ void init()
+ {
thecurfile = NULL;
basename = thecurfilename = NULL;
directory = NULL;
filenum = 0;
- rgba=false;
+ rgba = false;
}
- FILE *thecurfile;
- char *thecurfilename;
- const char *directory;
- const char *basename;
- unsigned int filenum;
- bool rgba;
+ FILE *thecurfile;
+ char *thecurfilename;
+ const char *directory;
+ const char *basename;
+ unsigned int filenum;
+ bool rgba;
};
spritefiles::spritefiles(const char *basename, const char *directory, bool rgba)
@@ -296,7 +304,7 @@
init();
spritefiles::basename = basename;
spritefiles::directory = directory;
- spritefiles::rgba=rgba;
+ spritefiles::rgba = rgba;
}
FILE *spritefiles::nextfile()
@@ -307,11 +315,10 @@
thecurfilename = strdup(spritefilename(basename, directory, getoutputext(rgba), filenum++, "wb", 1));
thecurfile = fopen(thecurfilename, "wb");
- if (thecurfile) { // new open succeeded, close old one
- if (oldfile)
- fclose(oldfile);
+ if (thecurfile) { // new open succeeded, close old one
+ if (oldfile) fclose(oldfile);
free(oldname);
- } else { // retain old one
+ } else { // retain old one
free(thecurfilename);
thecurfile = oldfile;
thecurfilename = oldname;
@@ -320,13 +327,12 @@
return thecurfile;
}
-int _crop=0;
-int _quiet=0;
+int _crop = 0;
+int _quiet = 0;
-static const char header[] = {
- '\x00', '\x00', // End-of-file marker for old OTTDp versions
- 'G', 'R', 'F', '\x82', // Container version 2
- '\x0D', '\x0A', '\x1A', '\x0A', // Detect garbled transmission
+static const char header[] = {'\x00', '\x00', // End-of-file marker for old OTTDp versions
+ 'G', 'R', 'F', '\x82', // Container version 2
+ '\x0D', '\x0A', '\x1A', '\x0A', // Detect garbled transmission
};
static int encode(const char *file, const char *dir, int compress, int *colourmap, int grfcontversion)
@@ -343,8 +349,7 @@
free(infofile);
- if (colourmap)
- info.installmap(colourmap);
+ if (colourmap) info.installmap(colourmap);
long totaluncomp = 1, totalcomp = 1;
long totaltransp = 1, totaluntransp = 1;
@@ -353,16 +358,16 @@
if (grfcontversion == 2) {
cfwrite("writing header", header, sizeof(header), 1, grf);
int size = 1 + 4; // The size of the zoom + end of data
- for(int i = 0; i < info.size(); i++) {
- switch(info[i].GetType()){
- case Sprite::ST_INCLUDE:
- case Sprite::ST_REAL:
- size += 4 + 1 + 4; // Size + type + ID
- break;
+ for (int i = 0; i < info.size(); i++) {
+ switch (info[i].GetType()) {
+ case Sprite::ST_INCLUDE:
+ case Sprite::ST_REAL:
+ size += 4 + 1 + 4; // Size + type + ID
+ break;
- case Sprite::ST_PSEUDO:
- size += 4 + 1 + ((const Pseudo&)info[i]).size();
- break;
+ case Sprite::ST_PSEUDO:
+ size += 4 + 1 + ((const Pseudo &)info[i]).size();
+ break;
}
}
writedword("writing header", size, grf);
@@ -370,123 +375,20 @@
}
for (int pass = 1; pass <= grfcontversion; pass++) {
- for(int i=0;i<info.size();i++){
+ for (int i = 0; i < info.size(); i++) {
if (_interactive && pass != grfcontversion) {
- int comp2 = (100L * totalcomp / totaluncomp);// % 100;
- int comp4 = (100L * totaltransp / totaluntransp);// % 100;
- int comp6 = (100L * totalreg / totalunreg);// % 100;
- printf("\rSprite%5d Done:%3d%% "
- "Compressed:%3d%% (Transparency:%3d%%, Redundancy:%3d%%)\r",
- i, (int) (i*100L/info.size()),
- comp2, comp4, comp6);
+ int comp2 = (100L * totalcomp / totaluncomp); // % 100;
+ int comp4 = (100L * totaltransp / totaluntransp); // % 100;
+ int comp6 = (100L * totalreg / totalunreg); // % 100;
+ printf(
+ "\rSprite%5d Done:%3d%% "
+ "Compressed:%3d%% (Transparency:%3d%%, Redundancy:%3d%%)\r",
+ i, (int)(i * 100L / info.size()), comp2, comp4, comp6);
}
- switch(info[i].GetType()){
- case Sprite::ST_INCLUDE:{
- static const char *action = "copying binary blob";
- if (pass != grfcontversion) {
- writespritesize(action, 4, grfcontversion, grf);
- fputc(0xfd, grf);
- writedword(action, i + 1, grf);
- break;
- }
-
- const char *bininclude=((const Include&)info[i]).GetName();
- FILE *bin = fopen(bininclude, "rb");
- if (!bin) {
- fperror("%s:%i: Error: Cannot include %s: Could not open.\n", file, i, bininclude);
- exit(2);
- }
-
- struct stat stat_buf;
- if ( fstat(fileno(bin), &stat_buf) ) {
- fperror("%s:%i: Error: Could not stat %s.\n", file, i, bininclude);
- exit(2);
- }
- if ( stat_buf.st_mode & S_IFDIR ) {
- fprintf(stderr, "%s:%i: Error: Cannot include %s: Is a directory.\n", file, i, bininclude);
- exit(2);
- }
- off_t fsize = stat_buf.st_size;
-
- const char *nameofs = bininclude + strlen(bininclude);
- while (nameofs > bininclude) {
- nameofs--;
- if (nameofs[0] == '\\' || nameofs[0] == '/') {
- nameofs++;
- break;
- }
- }
- int namelen = strlen(nameofs);
- if (namelen > 255) {
- fprintf(stderr, "%s:%i: Error: binary include has too long filename %s\n", file, i, nameofs);
- exit(2);
- }
-
- int spritesize = 3 + namelen + fsize;
- if (spritesize < 5) {
- fprintf(stderr, "%s:%i: Error: binary include %s is empty\n", file, i, nameofs);
- exit(2);
- }
- if (grfcontversion > 1) spritesize++; // We need the first 0xFF to be accounted for as well.
- /* GRF container version only allowed 64K, the rest prevents underflows. */
- if ((grfcontversion == 1 && spritesize > 65535) || spritesize < fsize || spritesize < 0) {
- fprintf(stderr, "%s:%i: Error: binary include %s is too large\n", file, i, nameofs);
- exit(2);
- }
-
- totalcomp += spritesize;
- totaluncomp += spritesize;
-
- if (grfcontversion == 2) writedword(action, i + 1, grf);
- writespritesize(action, spritesize, grfcontversion, grf);
- fputc(0xff, grf);
- fputc(0xff, grf);
- fputc(namelen, grf);
- cfwrite(action, nameofs, namelen+1, 1, grf);
-
- char *buffer = new char[16384];
- while (fsize > 0) {
- int chunk = 16384;
- if (chunk > fsize) chunk=fsize;
- cfread(action, buffer, chunk, 1, bin);
- cfwrite(action, buffer, chunk, 1, grf);
- fsize -= chunk;
- }
- delete[]buffer;
- fclose(bin);
- }
- break;
- case Sprite::ST_PSEUDO:{
- if (pass != 1) {
- break;
- }
-
- static const char *action = "writing pseudo sprite";
- const Pseudo&sprite=(const Pseudo&)info[i];
- uint size=sprite.size();
- totalcomp += size;
- totaluncomp += size;
-
- writespritesize(action, size, grfcontversion, grf);
- fputc(0xff, grf);
- cfwrite(action, sprite.GetData(),1,size,grf);
- if(i == 0 && sprite.size() == 4){
- int reported = *((S32*)sprite.GetData());
- reported = BE_SWAP32(reported) + 1;
- if(reported != info.size() && !_quiet)
- fprintf(stderr, "%s:1: Warning: Found %d %s sprites than sprite 0 reports.\n",
- file,
- abs(info.size() - reported),
- info.size()>reported?"more":"fewer");
- }
- }
- break;
- case Sprite::ST_REAL:{ // real sprite, encode it
- static const char *action = "writing real sprite";
-
- const Real&sprite=(Real&)info[i];
- for (size_t j = 0; j < (grfcontversion == 1 ? 1 : sprite.infs.size()); j++) {
+ switch (info[i].GetType()) {
+ case Sprite::ST_INCLUDE: {
+ static const char *action = "copying binary blob";
if (pass != grfcontversion) {
writespritesize(action, 4, grfcontversion, grf);
fputc(0xfd, grf);
@@ -494,144 +396,258 @@
break;
}
- info.PrepareReal(sprite.infs[j]);
- CommonPixel *image = (CommonPixel*) calloc(info.imgsize, sizeof(CommonPixel));
- if (!image) {
- fprintf(stderr, "%s:%d: Error: can't allocate sprite memory (%ld bytes)\n", file, i, info.imgsize);
+ const char *bininclude = ((const Include &)info[i]).GetName();
+ FILE *bin = fopen(bininclude, "rb");
+ if (!bin) {
+ fperror("%s:%i: Error: Cannot include %s: Could not open.\n", file, i, bininclude);
exit(2);
}
- bool has_mask=sprite.infs[j].depth==DEPTH_8BPP;
- bool rgba=sprite.infs[j].depth==DEPTH_32BPP;
- info.getsprite(image);
- if(j+1<sprite.infs.size()&&sprite.infs[j+1].depth==DEPTH_MASK){
- j++;
+ struct stat stat_buf;
+ if (fstat(fileno(bin), &stat_buf)) {
+ fperror("%s:%i: Error: Could not stat %s.\n", file, i, bininclude);
+ exit(2);
+ }
+ if (stat_buf.st_mode & S_IFDIR) {
+ fprintf(stderr, "%s:%i: Error: Cannot include %s: Is a directory.\n", file, i, bininclude);
+ exit(2);
+ }
+ off_t fsize = stat_buf.st_size;
+
+ const char *nameofs = bininclude + strlen(bininclude);
+ while (nameofs > bininclude) {
+ nameofs--;
+ if (nameofs[0] == '\\' || nameofs[0] == '/') {
+ nameofs++;
+ break;
+ }
+ }
+ int namelen = strlen(nameofs);
+ if (namelen > 255) {
+ fprintf(stderr, "%s:%i: Error: binary include has too long filename %s\n", file, i,
+ nameofs);
+ exit(2);
+ }
+
+ int spritesize = 3 + namelen + fsize;
+ if (spritesize < 5) {
+ fprintf(stderr, "%s:%i: Error: binary include %s is empty\n", file, i, nameofs);
+ exit(2);
+ }
+ if (grfcontversion > 1) spritesize++; // We need the first 0xFF to be accounted for as well.
+ /* GRF container version only allowed 64K, the rest prevents underflows. */
+ if ((grfcontversion == 1 && spritesize > 65535) || spritesize < fsize || spritesize < 0) {
+ fprintf(stderr, "%s:%i: Error: binary include %s is too large\n", file, i, nameofs);
+ exit(2);
+ }
+
+ totalcomp += spritesize;
+ totaluncomp += spritesize;
+
+ if (grfcontversion == 2) writedword(action, i + 1, grf);
+ writespritesize(action, spritesize, grfcontversion, grf);
+ fputc(0xff, grf);
+ fputc(0xff, grf);
+ fputc(namelen, grf);
+ cfwrite(action, nameofs, namelen + 1, 1, grf);
+
+ char *buffer = new char[16384];
+ while (fsize > 0) {
+ int chunk = 16384;
+ if (chunk > fsize) chunk = fsize;
+ cfread(action, buffer, chunk, 1, bin);
+ cfwrite(action, buffer, chunk, 1, grf);
+ fsize -= chunk;
+ }
+ delete[] buffer;
+ fclose(bin);
+ } break;
+ case Sprite::ST_PSEUDO: {
+ if (pass != 1) {
+ break;
+ }
+
+ static const char *action = "writing pseudo sprite";
+ const Pseudo &sprite = (const Pseudo &)info[i];
+ uint size = sprite.size();
+ totalcomp += size;
+ totaluncomp += size;
+
+ writespritesize(action, size, grfcontversion, grf);
+ fputc(0xff, grf);
+ cfwrite(action, sprite.GetData(), 1, size, grf);
+ if (i == 0 && sprite.size() == 4) {
+ int reported = *((S32 *)sprite.GetData());
+ reported = BE_SWAP32(reported) + 1;
+ if (reported != info.size() && !_quiet)
+ fprintf(stderr, "%s:1: Warning: Found %d %s sprites than sprite 0 reports.\n", file,
+ abs(info.size() - reported), info.size() > reported ? "more" : "fewer");
+ }
+ } break;
+ case Sprite::ST_REAL: { // real sprite, encode it
+ static const char *action = "writing real sprite";
+
+ const Real &sprite = (Real &)info[i];
+ for (size_t j = 0; j < (grfcontversion == 1 ? 1 : sprite.infs.size()); j++) {
+ if (pass != grfcontversion) {
+ writespritesize(action, 4, grfcontversion, grf);
+ fputc(0xfd, grf);
+ writedword(action, i + 1, grf);
+ break;
+ }
+
info.PrepareReal(sprite.infs[j]);
- CommonPixel *mask = (CommonPixel*) calloc(info.imgsize, sizeof(CommonPixel));
- if (!mask) {
- fprintf(stderr, "%s:%d: Error: can't allocate sprite memory (%ld bytes)\n", file, i, info.imgsize);
+ CommonPixel *image = (CommonPixel *)calloc(info.imgsize, sizeof(CommonPixel));
+ if (!image) {
+ fprintf(stderr, "%s:%d: Error: can't allocate sprite memory (%ld bytes)\n", file, i,
+ info.imgsize);
exit(2);
}
- info.getsprite(mask);
- for (int i = 0; i < info.imgsize; i++) image[i].m = mask[i].m;
- free(mask);
- has_mask=true;
- }
- int k=0;
- for (int j=info.imgsize-1; j >= 0; j--)
- if (has_mask && image[j].m == 0xFF) k++;
+ bool has_mask = sprite.infs[j].depth == DEPTH_8BPP;
+ bool rgba = sprite.infs[j].depth == DEPTH_32BPP;
+ info.getsprite(image);
+ if (j + 1 < sprite.infs.size() && sprite.infs[j + 1].depth == DEPTH_MASK) {
+ j++;
+ info.PrepareReal(sprite.infs[j]);
+ CommonPixel *mask = (CommonPixel *)calloc(info.imgsize, sizeof(CommonPixel));
+ if (!mask) {
+ fprintf(stderr, "%s:%d: Error: can't allocate sprite memory (%ld bytes)\n",
+ file, i, info.imgsize);
+ exit(2);
+ }
+ info.getsprite(mask);
+ for (int i = 0; i < info.imgsize; i++) image[i].m = mask[i].m;
+ free(mask);
+ has_mask = true;
+ }
- if (k && !_quiet)
- fprintf(stderr, "%s:%d: Warning: %d of %ld pixels (%ld%%) are pure white\n",
- file, i, k, info.imgsize, k*100/info.imgsize);
+ int k = 0;
+ for (int j = info.imgsize - 1; j >= 0; j--)
+ if (has_mask && image[j].m == 0xFF) k++;
- if(_crop && !DONOTCROP(info.inf.info)){
- int i=0,j=0;
- for(i=info.imgsize-1;i>=0;i--)if(!image[i].IsTransparent(rgba))break; // Find last non-blue pixel
- if(i<0)// We've got an all-blue sprite
- info.sx=info.sy=info.imgsize=1;
- else{
- i=info.imgsize-(i+info.sx-i%info.sx/*begining of next line*/);
- info.sy-=i/info.sx;
+ if (k && !_quiet)
+ fprintf(stderr, "%s:%d: Warning: %d of %ld pixels (%ld%%) are pure white\n", file,
+ i, k, info.imgsize, k * 100 / info.imgsize);
- for(i=0;i<info.imgsize;i++){
- if(!image[i].IsTransparent(rgba))
- break; // Find first non-blue pixel
- }
- i-=i%info.sx;// Move to beginning of line
+ if (_crop && !DONOTCROP(info.inf.info)) {
+ int i = 0, j = 0;
+ for (i = info.imgsize - 1; i >= 0; i--)
+ if (!image[i].IsTransparent(rgba)) break; // Find last non-blue pixel
+ if (i < 0) // We've got an all-blue sprite
+ info.sx = info.sy = info.imgsize = 1;
+ else {
+ i = info.imgsize - (i + info.sx - i % info.sx /*begining of next line*/);
+ info.sy -= i / info.sx;
- info.sy-=i/info.sx;
- info.inf.yrel+=i/info.sx;
- if(i)memmove(image,image+i,(info.imgsize-i)*sizeof(CommonPixel));
- for(i=0;i<info.sx;i++){
- for(j=0;j<info.sy;j++){
- if(!image[i+j*info.sx].IsTransparent(rgba))goto foundfirst;
+ for (i = 0; i < info.imgsize; i++) {
+ if (!image[i].IsTransparent(rgba))
+ break; // Find first non-blue pixel
+ }
+ i -= i % info.sx; // Move to beginning of line
+
+ info.sy -= i / info.sx;
+ info.inf.yrel += i / info.sx;
+ if (i) memmove(image, image + i, (info.imgsize - i) * sizeof(CommonPixel));
+ for (i = 0; i < info.sx; i++) {
+ for (j = 0; j < info.sy; j++) {
+ if (!image[i + j * info.sx].IsTransparent(rgba))
+ goto foundfirst;
+ }
+ }
+ foundfirst:
+ if (i) {
+ for (j = 0; j < info.sy; j++)
+ memmove(image + j * (info.sx - i), image + j * info.sx + i,
+ (info.sx - i) * sizeof(CommonPixel));
+ info.inf.xrel += i;
+ info.sx -= i;
+ }
+
+ for (i = info.sx - 1; i >= 0; i--) {
+ for (j = 0; j < info.sy; j++) {
+ if (!image[i + j * info.sx].IsTransparent(rgba))
+ goto foundlast;
+ }
+ }
+ foundlast:
+ i = info.sx - i - 1;
+ if (i) {
+ for (j = 1; j < info.sy; j++)
+ memmove(image + j * (info.sx - i), image + j * info.sx,
+ (info.sx - i) * sizeof(CommonPixel));
+ info.sx -= i;
}
}
-foundfirst:
- if(i){
- for(j=0;j<info.sy;j++)
- memmove(image+j*(info.sx-i),image+j*info.sx+i,(info.sx-i)*sizeof(CommonPixel));
- info.inf.xrel+=i;
- info.sx-=i;
+ info.inf.xdim = info.sx;
+ info.inf.ydim = info.sy;
+ info.imgsize = info.sx * info.sy;
+ }
+
+ U8 bytes_per_pixel = (has_mask ? 1 : 0) + (rgba ? 4 : 0);
+ U8 *compressed_chunked = NULL;
+ U8 *compressed_regular = NULL;
+ long compressed_size_chunked = 1 << 30;
+ long compressed_size_regular = 1 << 30;
+ long uncompressed_size_chunked = 0;
+
+ bool force_chunk = HASTRANSPARENCY(info.inf.info);
+ if (force_chunk || _best_compression) {
+ SpriteInfo inf = info.inf;
+ inf.info |= 8; // Set chunked status
+ compressed_size_chunked =
+ encodetile(&compressed_chunked, &uncompressed_size_chunked, image,
+ info.imgsize * bytes_per_pixel, info.sx, info.sy, inf, compress, i,
+ has_mask, rgba, grfcontversion);
+ }
+ if (!force_chunk || _best_compression) {
+ U8 *imgbuffer = (U8 *)malloc(info.imgsize * bytes_per_pixel);
+ if (!imgbuffer) {
+ fprintf(stderr, "%s:%d: Error: can't allocate sprite memory (%ld bytes)\n",
+ file, i, info.imgsize);
+ exit(2);
}
+ for (int j = 0; j < info.imgsize; j++) {
+ image[j].Encode(imgbuffer + (j * bytes_per_pixel), has_mask, rgba);
+ }
+ SpriteInfo inf = info.inf;
+ inf.info &= ~8; // Clear chunked status
+ compressed_size_regular =
+ encoderegular(&compressed_regular, imgbuffer, info.imgsize * bytes_per_pixel,
+ inf, compress, i, grfcontversion);
+ free(imgbuffer);
+ }
- for(i=info.sx-1;i>=0;i--){
- for(j=0;j<info.sy;j++){
- if(!image[i+j*info.sx].IsTransparent(rgba))goto foundlast;
- }
- }
-foundlast:
- i=info.sx-i-1;
- if(i){
- for(j=1;j<info.sy;j++)
- memmove(image+j*(info.sx-i),image+j*info.sx,(info.sx-i)*sizeof(CommonPixel));
- info.sx-=i;
- }
+ /* GRF container version 2 saves 4 extra bytes for the chunked data. */
+ bool use_chunk =
+ compressed_size_chunked + (grfcontversion == 2 ? 4 : 0) < compressed_size_regular;
+ long uncompressed_size =
+ use_chunk ? uncompressed_size_chunked : info.imgsize * bytes_per_pixel;
+ long compressed_size = use_chunk ? compressed_size_chunked : compressed_size_regular;
+ if (use_chunk) {
+ info.inf.info |= 8; // Set chunked status
+ } else {
+ info.inf.info &= ~8; // Clear chunked status
+ }
+ writesprite(grf, use_chunk ? compressed_chunked : compressed_regular, compressed_size,
+ uncompressed_size, info.inf, i, grfcontversion);
- }
- info.inf.xdim = info.sx;
- info.inf.ydim = info.sy;
- info.imgsize = info.sx * info.sy;
+ totaltransp += uncompressed_size; // how much after transparency removed
+ totaluntransp += info.imgsize; // how much with transparency
+
+ totalreg += compressed_size; // how much after transp&redund removed
+ totalunreg += uncompressed_size; // how much with redund
+
+ totalcomp += compressed_size;
+ totaluncomp += info.imgsize;
+ free(compressed_chunked);
+ free(compressed_regular);
+ free(image);
}
-
- U8 bytes_per_pixel=(has_mask?1:0)+(rgba?4:0);
- U8 *compressed_chunked = NULL;
- U8 *compressed_regular = NULL;
- long compressed_size_chunked = 1 << 30;
- long compressed_size_regular = 1 << 30;
- long uncompressed_size_chunked = 0;
-
- bool force_chunk = HASTRANSPARENCY(info.inf.info);
- if (force_chunk || _best_compression) {
- SpriteInfo inf = info.inf;
- inf.info |= 8; // Set chunked status
- compressed_size_chunked = encodetile(&compressed_chunked, &uncompressed_size_chunked, image, info.imgsize*bytes_per_pixel, info.sx, info.sy, inf, compress, i, has_mask, rgba, grfcontversion);
- }
- if (!force_chunk || _best_compression) {
- U8 *imgbuffer = (U8*)malloc(info.imgsize*bytes_per_pixel);
- if (!imgbuffer) {
- fprintf(stderr, "%s:%d: Error: can't allocate sprite memory (%ld bytes)\n", file, i, info.imgsize);
- exit(2);
- }
- for (int j = 0; j < info.imgsize; j++) {
- image[j].Encode(imgbuffer + (j * bytes_per_pixel), has_mask, rgba);
- }
- SpriteInfo inf = info.inf;
- inf.info &= ~8; // Clear chunked status
- compressed_size_regular = encoderegular(&compressed_regular, imgbuffer, info.imgsize*bytes_per_pixel, inf, compress, i, grfcontversion);
- free(imgbuffer);
- }
-
- /* GRF container version 2 saves 4 extra bytes for the chunked data. */
- bool use_chunk = compressed_size_chunked + (grfcontversion == 2 ? 4 : 0) < compressed_size_regular;
- long uncompressed_size = use_chunk ? uncompressed_size_chunked : info.imgsize*bytes_per_pixel;
- long compressed_size = use_chunk ? compressed_size_chunked : compressed_size_regular;
- if (use_chunk) {
- info.inf.info |= 8; // Set chunked status
- } else {
- info.inf.info &= ~8; // Clear chunked status
- }
- writesprite(grf, use_chunk ? compressed_chunked : compressed_regular, compressed_size, uncompressed_size, info.inf, i, grfcontversion);
-
- totaltransp += uncompressed_size; // how much after transparency removed
- totaluntransp += info.imgsize; // how much with transparency
-
- totalreg += compressed_size; // how much after transp&redund removed
- totalunreg += uncompressed_size; // how much with redund
-
- totalcomp += compressed_size;
- totaluncomp += info.imgsize;
- free(compressed_chunked);
- free(compressed_regular);
- free(image);
- }
- }
- break;
- default:
- fprintf(stderr, "%s:%d: Error: What type of sprite is that?", file, i);
- exit(2);
+ } break;
+ default:
+ fprintf(stderr, "%s:%d: Error: What type of sprite is that?", file, i);
+ exit(2);
}
}
@@ -667,8 +683,8 @@
}
// make sure the directory exists, or create it if not
- realdir = spritefilename(file, dir, "", -1, "rb", 0); // make fake filename
- *strrchr(realdir, '/') = 0; // cut off filename
+ realdir = spritefilename(file, dir, "", -1, "rb", 0); // make fake filename
+ *strrchr(realdir, '/') = 0; // cut off filename
if (stat(realdir, &statbuf)) {
// error during stat
@@ -699,7 +715,7 @@
fseek(grf, 0, SEEK_SET);
} else {
dataoffset = sizeof(header) + 4 + readdword(action, grf); // GRF data offset
- fgetc(grf); // Compression
+ fgetc(grf); // Compression
}
printf("Found grf container version %d\n", grfcontversion);
@@ -709,10 +725,10 @@
pcxwrite *pcx, *pcx32;
if (height == -1) {
- imgname = new singlefile(spritefilename(file, dir, getoutputext(false), -2, "wb", 1),"wb", dir);
- imgname32 = new singlefile(spritefilename(file, dir, getoutputext(true), -2, "wb", 1),"wb", dir);
+ imgname = new singlefile(spritefilename(file, dir, getoutputext(false), -2, "wb", 1), "wb", dir);
+ imgname32 = new singlefile(spritefilename(file, dir, getoutputext(true), -2, "wb", 1), "wb", dir);
} else {
- imgname = new spritefiles(file, dir, false);
+ imgname = new spritefiles(file, dir, false);
imgname32 = new spritefiles(file, dir, true);
}
@@ -720,13 +736,13 @@
switch (_outputformat) {
#ifdef WITH_PNG
case SSF_PNG:
- pcx = new pngwrite(imgname, false);
+ pcx = new pngwrite(imgname, false);
pcx32 = new pngwrite(imgname32, true);
break;
#endif
case SSF_PCX:
default:
- pcx = new pcxwrite(imgname);
+ pcx = new pcxwrite(imgname);
pcx32 = NULL;
break;
}
@@ -743,8 +759,7 @@
infowriter writer(info, (width + box - 1) / box, useplaintext, pcx->getdirectory());
- if (colourmap)
- pcx->installwritemap(colourmap);
+ if (colourmap) pcx->installwritemap(colourmap);
pcx->startimage(true, width, height, box, box);
if (pcx32 != NULL) pcx32->startimage(false, width, height, box, box);
@@ -754,7 +769,7 @@
if (_interactive) printf("Decoding:\n");
do {
- int newpct = 100L*ftell(grf)/fsize;
+ int newpct = 100L * ftell(grf) / fsize;
if (_interactive && newpct != lastpct) {
lastpct = newpct;
@@ -772,8 +787,8 @@
pcx->endimage();
if (pcx32 != NULL) pcx32->endimage();
- delete(pcx); // closes output file
- delete(pcx32);
+ delete (pcx); // closes output file
+ delete (pcx32);
if (pcx32 == NULL) delete imgname32;
writer.flush();
@@ -781,8 +796,7 @@
fclose(info);
- if (_interactive) printf("%s has %d sprites, maxx %d, maxy %d, maxs %d.\n",
- file, count, maxx, maxy, maxs);
+ if (_interactive) printf("%s has %d sprites, maxx %d, maxy %d, maxs %d.\n", file, count, maxx, maxy, maxs);
fclose(grf);
return 0;
@@ -790,9 +804,14 @@
static U8 *readpal(const char *filearg)
{
- enum paltype { UNK, BCP, PSP, GPL };
+ enum paltype {
+ UNK,
+ BCP,
+ PSP,
+ GPL
+ };
paltype type = UNK;
- static U8 pal[256*3];
+ static U8 pal[256 * 3];
if (!strnicmp(filearg, "bcp:", 4))
type = BCP;
@@ -801,8 +820,7 @@
else if (!strnicmp(filearg, "gpl:", 4))
type = GPL;
- if (type != UNK)
- filearg += 4; // remove type: from filename
+ if (type != UNK) filearg += 4; // remove type: from filename
FILE *f = fopen(filearg, "rb");
if (!f) {
@@ -811,55 +829,58 @@
}
switch (type) {
- case BCP:
- case UNK:
- if (fread(pal, 1, 256*3, f) != 256*3) {
- fprintf(stderr, "Error: %s is not a BCP file.\n", filearg);
- exit(1);
- }
- break;
- case PSP:
- char fmt[16];
- if (fgets(fmt, sizeof(fmt), f) == NULL || strcmp(fmt, "JASC-PAL\r\n")) {
-psp_error:
- fprintf(stderr, "Error: %s is not a PSP palette file.\n", filearg);
- exit(1);
- }
- int nument, nument2;
- if (fscanf(f, "%x\n", &nument) != 1) goto psp_error;
- if (fscanf(f, "%d\n", &nument2) != 1) goto psp_error;
- if ( (nument != nument2) || (nument != 256) ) {
- fprintf(stderr, "%s: Error: GRFCodec supports only 256 colour palette files.\n", filearg);
- exit(1);
- }
- for (int i=0; i<nument; i++) {
- if (!fscanf(f, "%cd %cd %cd\n", pal + i*3, pal+i*3+1, pal+i*3+2)) {
- fprintf(stderr, "Error reading palette.\n");
+ case BCP:
+ case UNK:
+ if (fread(pal, 1, 256 * 3, f) != 256 * 3) {
+ fprintf(stderr, "Error: %s is not a BCP file.\n", filearg);
exit(1);
}
- }
- break;
- case GPL:
- if (fgets(fmt, sizeof(fmt), f) == NULL || strcmp(fmt, "GIMP Palette\r\n")) {
-gpl_error:
- fprintf(stderr, "Error: %s is not a GIMP palette file.\n", filearg);
- exit(1);
- }
- while (fgets(fmt, sizeof(fmt), f) != NULL && fmt[strlen(fmt)-1] != '\n' ) {}// Name: ...
- while (fgets(fmt, sizeof(fmt), f) != NULL && fmt[strlen(fmt)-1] != '\n' ) {}// Columns: ...
- if (fgets(fmt, sizeof(fmt), f) == NULL) goto gpl_error; // #
- uint r, g, b;
- for (int i=0; i<256; i++) {
- if (!fscanf(f, "%d %d %d\n", &r, &g, &b) || r > 255 || g > 255 || b > 255) {
- fprintf(stderr, "%s: Error: reading palette.\n", filearg);
+ break;
+ case PSP:
+ char fmt[16];
+ if (fgets(fmt, sizeof(fmt), f) == NULL || strcmp(fmt, "JASC-PAL\r\n")) {
+ psp_error:
+ fprintf(stderr, "Error: %s is not a PSP palette file.\n", filearg);
exit(1);
}
- pal[3*i] = (U8) r;
- pal[3*i+1] = (U8) g;
- pal[3*i+2] = (U8) b;
- while (fgets(fmt, sizeof(fmt), f) != NULL && fmt[strlen(fmt)-1] != '\n' ) {}// color name
- }
- break;
+ int nument, nument2;
+ if (fscanf(f, "%x\n", &nument) != 1) goto psp_error;
+ if (fscanf(f, "%d\n", &nument2) != 1) goto psp_error;
+ if ((nument != nument2) || (nument != 256)) {
+ fprintf(stderr, "%s: Error: GRFCodec supports only 256 colour palette files.\n", filearg);
+ exit(1);
+ }
+ for (int i = 0; i < nument; i++) {
+ if (!fscanf(f, "%cd %cd %cd\n", pal + i * 3, pal + i * 3 + 1, pal + i * 3 + 2)) {
+ fprintf(stderr, "Error reading palette.\n");
+ exit(1);
+ }
+ }
+ break;
+ case GPL:
+ if (fgets(fmt, sizeof(fmt), f) == NULL || strcmp(fmt, "GIMP Palette\r\n")) {
+ gpl_error:
+ fprintf(stderr, "Error: %s is not a GIMP palette file.\n", filearg);
+ exit(1);
+ }
+ while (fgets(fmt, sizeof(fmt), f) != NULL && fmt[strlen(fmt) - 1] != '\n') {
+ } // Name: ...
+ while (fgets(fmt, sizeof(fmt), f) != NULL && fmt[strlen(fmt) - 1] != '\n') {
+ } // Columns: ...
+ if (fgets(fmt, sizeof(fmt), f) == NULL) goto gpl_error; // #
+ uint r, g, b;
+ for (int i = 0; i < 256; i++) {
+ if (!fscanf(f, "%d %d %d\n", &r, &g, &b) || r > 255 || g > 255 || b > 255) {
+ fprintf(stderr, "%s: Error: reading palette.\n", filearg);
+ exit(1);
+ }
+ pal[3 * i] = (U8)r;
+ pal[3 * i + 1] = (U8)g;
+ pal[3 * i + 2] = (U8)b;
+ while (fgets(fmt, sizeof(fmt), f) != NULL && fmt[strlen(fmt) - 1] != '\n') {
+ } // color name
+ }
+ break;
}
fclose(f);
@@ -868,19 +889,17 @@
static SpriteSheetFormat setoutputformat(const char *formatarg)
{
- if (!strnicmp(formatarg, "pcx", 3))
- return SSF_PCX;
+ if (!strnicmp(formatarg, "pcx", 3)) return SSF_PCX;
#ifdef WITH_PNG
- if (!strnicmp(formatarg, "png", 3))
- return SSF_PNG;
+ if (!strnicmp(formatarg, "png", 3)) return SSF_PNG;
#endif
return SSF_PCX;
}
// find default palette
-static U8* findpal(char *grffile)
+static U8 *findpal(char *grffile)
{
char base[MAXFILE];
char *bs;
@@ -895,18 +914,17 @@
bs = strchr(base, '.');
if (bs) *bs = 0;
- for (i=0; i<sizeof(defpals)/sizeof(defpals[0]); i++) {
- if (!stricmp(defpals[i].grffile, base))
- return defaultpalettes[defpals[i].defpalno];
+ for (i = 0; i < sizeof(defpals) / sizeof(defpals[0]); i++) {
+ if (!stricmp(defpals[i].grffile, base)) return defaultpalettes[defpals[i].defpalno];
}
return defaultpalettes[0];
}
-//extern "C" void debugint(void);
+// extern "C" void debugint(void);
-bool _force=false,_mapAll=false,_hexspritenums=false;
-int _useexts=2;
+bool _force = false, _mapAll = false, _hexspritenums = false;
+int _useexts = 2;
int main(int argc, char **argv)
{
@@ -924,127 +942,120 @@
checksizes();
#ifdef WIN32
- // debugint();
+// debugint();
#endif
// parse option arguments
while (1) {
char opt = getopt(argc, argv, "dev?w:h:b:up:m:M:o:tfxqcsXg:n");
- if (opt == (char) EOF)
- break;
+ if (opt == (char)EOF) break;
switch (opt) {
- case 'e':
- action = 1;
- break;
- case 'd':
- action = 2;
- break;
- case 'v':
- printf("%s\n", version);
- return 0;
- case 'w':
- width = min(max(atoi(optarg), 0), 65535);
- break;
- case 'h':
- height = min(max(atoi(optarg), 0), 65535);
- break;
- case 'b':
- box = atoi(optarg);
- break;
- case 'n':
- _best_compression = true;
- break;
- case 'p':
- unsigned int palnum;
- palnum = atoi(optarg);
- if ( (palnum > 0) &&
- (palnum <= sizeof(defaultpalettes)/sizeof(defaultpalettes[0])) ) {
- palette = defaultpalettes[palnum-1];
+ case 'e':
+ action = 1;
+ break;
+ case 'd':
+ action = 2;
+ break;
+ case 'v':
+ printf("%s\n", version);
+ return 0;
+ case 'w':
+ width = min(max(atoi(optarg), 0), 65535);
+ break;
+ case 'h':
+ height = min(max(atoi(optarg), 0), 65535);
+ break;
+ case 'b':
+ box = atoi(optarg);
+ break;
+ case 'n':
+ _best_compression = true;
+ break;
+ case 'p':
+ unsigned int palnum;
+ palnum = atoi(optarg);
+ if ((palnum > 0) && (palnum <= sizeof(defaultpalettes) / sizeof(defaultpalettes[0]))) {
+ palette = defaultpalettes[palnum - 1];
} else if (*optarg == '?') {
showpalettetext();
exit(1);
} else
palette = readpal(optarg);
break;
- case 'c':
- _crop++;
- break;
- case 'g':
- grfcontversion = atoi(optarg);
- if (grfcontversion < 1 || grfcontversion > 2) usage();
- break;
- case 'm':
- case 'M':
- _mapAll= opt=='M';
- unsigned int mapnum;
- mapnum = atoi(optarg);
- if (*optarg == '?') {
- printf("%s\n", version);
- showcolourmaps();
- exit(1);
- } else if (mapnum < sizeof(colourmaps)/sizeof(colourmaps[0]) ) {
+ case 'c':
+ _crop++;
+ break;
+ case 'g':
+ grfcontversion = atoi(optarg);
+ if (grfcontversion < 1 || grfcontversion > 2) usage();
+ break;
+ case 'm':
+ case 'M':
+ _mapAll = opt == 'M';
+ unsigned int mapnum;
+ mapnum = atoi(optarg);
+ if (*optarg == '?') {
+ printf("%s\n", version);
+ showcolourmaps();
+ exit(1);
+ } else if (mapnum < sizeof(colourmaps) / sizeof(colourmaps[0])) {
colourmap = colourmaps[mapnum];
} else {
usage();
}
break;
- case 'u':
- compress = 0;
- break;
- case 't':
- useplaintext = 0;
- break;
- case 'f':
- _force=true;
- break;
- case 'x':
- if(_useexts)_useexts--;
- break;
- case 'q':
- _quiet++;
- break;
- case 's':
- _interactive = false;
- case 'X':
- _hexspritenums=true;
- break;
- case 'o':
- if (*optarg == '?') {
- showimageformats();
- exit(1);
- }
- _outputformat = setoutputformat(optarg);
- break;
- default:
- usage();
+ case 'u':
+ compress = 0;
+ break;
+ case 't':
+ useplaintext = 0;
+ break;
+ case 'f':
+ _force = true;
+ break;
+ case 'x':
+ if (_useexts) _useexts--;
+ break;
+ case 'q':
+ _quiet++;
+ break;
+ case 's':
+ _interactive = false;
+ case 'X':
+ _hexspritenums = true;
+ break;
+ case 'o':
+ if (*optarg == '?') {
+ showimageformats();
+ exit(1);
+ }
+ _outputformat = setoutputformat(optarg);
+ break;
+ default:
+ usage();
}
}
// non-option arguments: filename and potentially directory
- if (optind < argc)
- grffile = argv[optind++];
+ if (optind < argc) grffile = argv[optind++];
safestrncpy(directory, optind < argc ? argv[optind++] : "sprites", MAXDIR);
int offset = strlen(directory);
- if (directory[offset - 1] != '/' ) {
+ if (directory[offset - 1] != '/') {
safestrncpy(directory + offset, "/", MAXDIR - offset);
}
- if (!action || !grffile || (width < 16) ||
- ( (height < 16) && (height != -1) ) ||
- (strlen(directory) < 1) ||
- (strlen(grffile) < 1) ||
- (box < 1))
+ if (!action || !grffile || (width < 16) || ((height < 16) && (height != -1)) || (strlen(directory) < 1) || (strlen(grffile) < 1) ||
+ (box < 1))
usage();
if (action == 1) {
return encode(grffile, directory, compress, colourmap, grfcontversion);
} else if (action == 2) {
- if (!palette)
- palette = findpal(grffile);
+ if (!palette) palette = findpal(grffile);
return decode(grffile, directory, palette, box, width, height, colourmap, useplaintext);
}
diff --git a/src/grfcomm.cpp b/src/grfcomm.cpp
--- a/src/grfcomm.cpp
+++ b/src/grfcomm.cpp
@@ -1,7 +1,7 @@
/*
- Functions and classes common to all GRF programs
- Copyright (C) 2000-2003 by Josef Drexler
- Distributed under the GNU General Public License
+ Functions and classes common to all GRF programs
+ Copyright (C) 2000-2003 by Josef Drexler
+ Distributed under the GNU General Public License
*/
#include <stdlib.h>
@@ -11,30 +11,26 @@
#include <errno.h>
#include <sys/stat.h>
#ifdef MINGW
-# include <io.h>
-# define mkdir(a,b) mkdir(a)
+#include <io.h>
+#define mkdir(a, b) mkdir(a)
#elif defined(_MSC_VER)
-# include <direct.h>
-# define mkdir(a,b) mkdir(a)
+#include <direct.h>
+#define mkdir(a, b) mkdir(a)
#endif
-
#include "error.h"
//#include "sprites.h"
#if defined(WIN32) || defined(GCC32) || defined(GCC64)
-# include "path.h"
+#include "path.h"
#endif
-
#include "grfcomm.h"
char *lastspritefilename;
const char *e_openfile = "Error opening %.228s";
-
-
static int getspritefilename(char *filename, const char *basefilename, char *subdirectory, const char *ext, long spriteno)
{
char bdrive[MAXDRIVE], bdirectory[MAXDIR], bname[MAXFILE], bext[MAXEXT];
@@ -43,7 +39,7 @@
fnsplit(subdirectory, sdrive, sdirectory, NULL, NULL);
fnsplit(basefilename, bdrive, bdirectory, bname, bext);
- if (strlen(sdrive)) { // drive given, go relative
+ if (strlen(sdrive)) { // drive given, go relative
char sfullpath[MAXPATH];
safestrncpy(sfullpath, subdirectory, MAXPATH);
fnsplit(sfullpath, sdrive, sdirectory, NULL, NULL);
@@ -114,19 +110,19 @@
getspritefilename(filename, basefilename, directory, ext, spriteno);
size_t dir_len = strlen(directory);
- if (dir_len != 0 && (directory[dir_len-1] == '\\' || directory[dir_len-1] == '/'))
- directory[dir_len-1] = 0; // cut off trailing backslash
+ if (dir_len != 0 && (directory[dir_len - 1] == '\\' || directory[dir_len - 1] == '/'))
+ directory[dir_len - 1] = 0; // cut off trailing backslash
- while (mustexist) { // actuall mustexist doesn't change, loop is terminated by explicit break
+ while (mustexist) { // actuall mustexist doesn't change, loop is terminated by explicit break
sprite = fopen(filename, mode);
if (!sprite) {
- if (errno == ENOENT) { // directory doesn't exist
- if (strchr(mode, 'w')) { // but we need to write to a file there
- if (mkdir(directory, 0755)) { // so try creating it
+ if (errno == ENOENT) { // directory doesn't exist
+ if (strchr(mode, 'w')) { // but we need to write to a file there
+ if (mkdir(directory, 0755)) { // so try creating it
fperror("Creating %.228s", directory);
exit(2);
}
- } else { // not writing, so report file missing
+ } else { // not writing, so report file missing
fperror("Cannot read %s", filename);
exit(2);
}
@@ -138,22 +134,20 @@
break;
}
- if (sprite)
- fclose(sprite);
+ if (sprite) fclose(sprite);
lastspritefilename = filename;
return filename;
}
-int doopen(const char *grffile, const char *dir, const char *ext, const char *mode,
- char **filename, FILE **file, int mustexist)
+int doopen(const char *grffile, const char *dir, const char *ext, const char *mode, char **filename, FILE **file, int mustexist)
{
char *fn;
FILE *f;
fn = spritefilename(grffile, dir, ext, -1, mode, mustexist);
- if (filename) *filename=strdup(fn);
+ if (filename) *filename = strdup(fn);
f = fopen(fn, mode);
@@ -162,8 +156,10 @@
exit(2);
}
- if (file) *file = f;
- else fclose(f);
+ if (file)
+ *file = f;
+ else
+ fclose(f);
return 1;
}
@@ -173,8 +169,7 @@
size_t read = fread(ptr, 1, size * n, stream);
if (read != size * n) {
- fperror("\nError while %s, got %d, wanted %d, at %ld", action, read, size * n,
- ftell(stream));
+ fperror("\nError while %s, got %d, wanted %d, at %ld", action, read, size * n, ftell(stream));
exit(2);
}
}
@@ -199,7 +194,7 @@
{
/* Length of filename + length of ".bak" + '\0' */
int len = strlen(filename) + 4 + 1;
- char *bakfile = (char*) malloc(len);
+ char *bakfile = (char *)malloc(len);
strcpy(bakfile, filename); // Safe use due to already checked buffer size
char *c = strrchr(bakfile, '.');
diff --git a/src/grfcomm.h b/src/grfcomm.h
--- a/src/grfcomm.h
+++ b/src/grfcomm.h
@@ -1,7 +1,6 @@
#ifndef _GRFCOMM_H
#define _GRFCOMM_H
-
/* header file for grfcomm.h */
extern char *lastspritefilename;
@@ -9,8 +8,7 @@
extern const char *e_openfile;
char *spritefilename(const char *basefilename, const char *reldirectory, const char *ext, int spriteno, const char *mode, int mustexist);
-int doopen(const char *grffile, const char *dir, const char *ext, const char *mode,
- char **filename, FILE **file, int mustexist);
+int doopen(const char *grffile, const char *dir, const char *ext, const char *mode, char **filename, FILE **file, int mustexist);
void cfread(const char *action, void *ptr, size_t size, size_t n, FILE *stream);
void cfwrite(const char *action, const void *ptr, size_t size, size_t n, FILE *stream);
diff --git a/src/grfid.cpp b/src/grfid.cpp
--- a/src/grfid.cpp
+++ b/src/grfid.cpp
@@ -1,8 +1,11 @@
/*
* This file is part of GRFCodec.
- * GRFCodec is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
- * GRFCodec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ * GRFCodec is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, version 2.
+ * GRFCodec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with
+ * OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
@@ -19,8 +22,9 @@
#define PROT_READ 0
#define MAP_PRIVATE 0
/* Lets fake mmap for Windows, please! */
-void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {
- char *mem = (char*)malloc(size + 1);
+void *mmap(void *ptr, long size, long prot, long type, long handle, long arg)
+{
+ char *mem = (char *)malloc(size + 1);
mem[size] = 0;
FILE *in = fdopen(handle, "rb");
if (fread(mem, size, 1, in) != 1) {
@@ -31,7 +35,8 @@
fclose(in);
return mem;
}
-long munmap (void *ptr, long size) {
+long munmap(void *ptr, long size)
+{
free(ptr);
return 0;
}
@@ -92,10 +97,9 @@
return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
}
-static const char header[] = {
- '\x00', '\x00', // End-of-file marker for old OTTDp versions
- 'G', 'R', 'F', '\x82', // Container version 2
- '\x0D', '\x0A', '\x1A', '\x0A', // Detect garbled transmission
+static const char header[] = {'\x00', '\x00', // End-of-file marker for old OTTDp versions
+ 'G', 'R', 'F', '\x82', // Container version 2
+ '\x0D', '\x0A', '\x1A', '\x0A', // Detect garbled transmission
};
inline uint32_t ReadSize(int grfcontversion)
@@ -103,7 +107,6 @@
return grfcontversion == 2 ? ReadDWord() : ReadWord();
}
-
const char *GetGrfID(const char *filename, uint32_t *grfid)
{
*grfid = 0;
@@ -117,7 +120,7 @@
fseek(f, 0, SEEK_SET);
/* Map the file into memory */
- _file_buffer = (uint8_t*)mmap(NULL, _file_length, PROT_READ, MAP_PRIVATE, fileno(f), 0);
+ _file_buffer = (uint8_t *)mmap(NULL, _file_length, PROT_READ, MAP_PRIVATE, fileno(f), 0);
_buffer = _file_buffer;
int grfcontversion = 1;
@@ -153,7 +156,7 @@
} else {
SkipBytes(num - 1);
}
- } else if (grfcontversion == 2 && type== 0xfd) {
+ } else if (grfcontversion == 2 && type == 0xfd) {
/* Skip sprite offset */
ReadDWord();
} else if (grfcontversion == 1) {
@@ -183,7 +186,7 @@
fseek(f, 0, SEEK_SET);
/* Map the file into memory */
- _file_buffer = (uint8_t*)mmap(NULL, _file_length, PROT_READ, MAP_PRIVATE, fileno(f), 0);
+ _file_buffer = (uint8_t *)mmap(NULL, _file_length, PROT_READ, MAP_PRIVATE, fileno(f), 0);
_buffer = _file_buffer;
size_t read_length = _file_length;
@@ -205,20 +208,20 @@
int main(int argc, char **argv)
{
if (argc < 2 || strcmp(argv[1], "-h") == 0 || (strcmp(argv[1], "-m") == 0 && argc < 3)) {
- printf(
- "GRFID " VERSION " - Copyright (C) 2009 by Peter Nelson\n"
- "\n"
- "Usage:\n"
- " GRFID <NewGRF-File>\n"
- " Get the GRF ID from the NewGRF file\n"
- " GRFID -m <NewGRF-File>\n"
- " Get the MD5 checksum of the NewGRF file\n"
- " GRFID -v\n"
- " Get the version of GRFID\n"
- "\n"
- "You may copy and redistribute it under the terms of the GNU General Public\n"
- "License, as stated in the file 'COPYING'.\n"
- "Uses MD5 implementation of L. Peter Deutsch.\n");
+ printf("GRFID " VERSION
+ " - Copyright (C) 2009 by Peter Nelson\n"
+ "\n"
+ "Usage:\n"
+ " GRFID <NewGRF-File>\n"
+ " Get the GRF ID from the NewGRF file\n"
+ " GRFID -m <NewGRF-File>\n"
+ " Get the MD5 checksum of the NewGRF file\n"
+ " GRFID -v\n"
+ " Get the version of GRFID\n"
+ "\n"
+ "You may copy and redistribute it under the terms of the GNU General Public\n"
+ "License, as stated in the file 'COPYING'.\n"
+ "Uses MD5 implementation of L. Peter Deutsch.\n");
return 1;
}
if (strcmp(argv[1], "-v") == 0) {
@@ -253,4 +256,3 @@
printf("Unable to get requested information: %s\n", err);
return 1;
}
-
diff --git a/src/grfstrip.cpp b/src/grfstrip.cpp
--- a/src/grfstrip.cpp
+++ b/src/grfstrip.cpp
@@ -1,8 +1,11 @@
/*
* This file is part of GRFCodec.
- * GRFCodec is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
- * GRFCodec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ * GRFCodec is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, version 2.
+ * GRFCodec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with
+ * OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
@@ -19,8 +22,9 @@
#define PROT_READ 0
#define MAP_PRIVATE 0
/* Lets fake mmap for Windows, please! */
-void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {
- char *mem = (char*)malloc(size + 1);
+void *mmap(void *ptr, long size, long prot, long type, long handle, long arg)
+{
+ char *mem = (char *)malloc(size + 1);
mem[size] = 0;
FILE *in = fdopen(handle, "rb");
if (fread(mem, size, 1, in) != 1) {
@@ -31,7 +35,8 @@
fclose(in);
return mem;
}
-long munmap (void *ptr, long size) {
+long munmap(void *ptr, long size)
+{
free(ptr);
return 0;
}
@@ -65,13 +70,11 @@
return v | (ReadWord() << 16);
}
-static const char header[] = {
- '\x00', '\x00', // End-of-file marker for old OTTDp versions
- 'G', 'R', 'F', '\x82', // Container version 2
- '\x0D', '\x0A', '\x1A', '\x0A', // Detect garbled transmission
+static const char header[] = {'\x00', '\x00', // End-of-file marker for old OTTDp versions
+ 'G', 'R', 'F', '\x82', // Container version 2
+ '\x0D', '\x0A', '\x1A', '\x0A', // Detect garbled transmission
};
-
const char *Strip(const char *origin, const char *dest, uint32_t allowed)
{
FILE *fin = fopen(origin, "rb");
@@ -86,7 +89,7 @@
fseek(fin, 0, SEEK_SET);
/* Map the file into memory */
- _file_buffer = (uint8_t*)mmap(NULL, _file_length, PROT_READ, MAP_PRIVATE, fileno(fin), 0);
+ _file_buffer = (uint8_t *)mmap(NULL, _file_length, PROT_READ, MAP_PRIVATE, fileno(fin), 0);
uint8_t *end = _file_buffer + _file_length;
if (_file_length <= sizeof(header) || memcmp(_file_buffer, header, sizeof(header)) != 0) {
@@ -131,7 +134,6 @@
if (_buffer >= end) return "Invalid GRF";
}
-
munmap(_file_buffer, _file_length);
fclose(fin);
@@ -141,18 +143,18 @@
int main(int argc, char **argv)
{
if (argc < 3 || strcmp(argv[1], "-h") == 0) {
- printf(
- "GRFSTRIP " VERSION " - Copyright (C) 2009 by Remko Bijker\n"
- "\n"
- "Usage:\n"
- " GRFSTRIP <origin> <dest> [<depth> <zoom>]\n"
- " Strip real sprites that are not in the set \"normal 8bpp and the ones\n"
- " specified at the command line\" from origin into dest.\n"
- " GRFSTRIP -v\n"
- " Get the version of GRFSTRIP\n"
- "\n"
- "You may copy and redistribute it under the terms of the GNU General Public\n"
- "License, as stated in the file 'COPYING'.\n");
+ printf("GRFSTRIP " VERSION
+ " - Copyright (C) 2009 by Remko Bijker\n"
+ "\n"
+ "Usage:\n"
+ " GRFSTRIP <origin> <dest> [<depth> <zoom>]\n"
+ " Strip real sprites that are not in the set \"normal 8bpp and the ones\n"
+ " specified at the command line\" from origin into dest.\n"
+ " GRFSTRIP -v\n"
+ " Get the version of GRFSTRIP\n"
+ "\n"
+ "You may copy and redistribute it under the terms of the GNU General Public\n"
+ "License, as stated in the file 'COPYING'.\n");
return 1;
}
if (strcmp(argv[1], "-v") == 0) {
@@ -172,7 +174,7 @@
return 1;
}
- static const char *zoom[] = { "normal", "zi4", "zi2", "zo2", "zo4", "zo8" };
+ static const char *zoom[] = {"normal", "zi4", "zi2", "zo2", "zo4", "zo8"};
int zoom_offset = 0xFF;
for (int j = 0; j < 6; j++) {
if (strcmp(argv[i + 1], zoom[j]) == 0) {
@@ -196,4 +198,3 @@
printf("Unable to get requested information: %s\n", err);
return 1;
}
-
diff --git a/src/help.cpp b/src/help.cpp
--- a/src/help.cpp
+++ b/src/help.cpp
@@ -20,8 +20,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<iostream>
-#include<string>
+#include <iostream>
+#include <string>
#include "language_mgr.h"
#include "help.h"
@@ -31,9 +31,13 @@
// --------
// Generate a ShowHelp function for each supported language.
-#define START_HELP_TEXT(lang) void ShowHelp_##lang(){ \
+#define START_HELP_TEXT(lang) \
+ void ShowHelp_##lang() \
+ { \
cout << ""
-#define END_HELP_TEXT() ; }
+#define END_HELP_TEXT() \
+ ; \
+ }
#include "lang/all_help.h"
// --------
@@ -43,8 +47,15 @@
#undef START_LANGUAGES
#undef RENUM_LANGUAGE
#undef END_LANGUAGES
-#define START_LANGUAGES() void ShowHelp() { \
- switch(LanguageMgr::Instance().GetCurrentLanguage()) {
-#define RENUM_LANGUAGE(name,code)case name: ShowHelp_##name(); break;
-#define END_LANGUAGES() } }
+#define START_LANGUAGES() \
+ void ShowHelp() \
+ { \
+ switch (LanguageMgr::Instance().GetCurrentLanguage()) {
+#define RENUM_LANGUAGE(name, code) \
+ case name: \
+ ShowHelp_##name(); \
+ break;
+#define END_LANGUAGES() \
+ } \
+ }
#include "lang/language_list.h"
diff --git a/src/info.cpp b/src/info.cpp
--- a/src/info.cpp
+++ b/src/info.cpp
@@ -25,7 +25,7 @@
return combined;
}
-void read_file(istream&in,int infover,int grfcontversion,AllocArray<Sprite>&sprites);
+void read_file(istream &in, int infover, int grfcontversion, AllocArray<Sprite> &sprites);
nfe_map nfo_escapes;
@@ -40,21 +40,20 @@
imgfile = NULL;
imgname = NULL;
- getline(f,buffer); // read first line, a comment
+ getline(f, buffer); // read first line, a comment
if (strncmp(buffer.c_str(), "// ", 3)) {
printf("NFO file missing header lines and version info\n");
exit(1);
}
- getline(f,buffer); // second line used to get info version
+ getline(f, buffer); // second line used to get info version
if (strncmp(buffer.c_str(), "// (Info version ", 17)) {
infover = 1;
f.seekg(0);
} else
infover = atoi(buffer.c_str() + 17);
- if (infover > 2)
- getline(f,buffer); // skip "format: " line
+ if (infover > 2) getline(f, buffer); // skip "format: " line
if (infover > 6) {
while (strncmp(buffer.c_str(), "// Format: ", 11)) {
@@ -63,22 +62,27 @@
string str;
int byte = 0;
esc.ignore(12);
- while (esc>>str){
- if(str == "=") byte--;
+ while (esc >> str) {
+ if (str == "=")
+ byte--;
else if (str[0] == '@')
- byte = strtol(str.c_str()+1, NULL, 16);
- else nfo_escapes.insert(nfe_pair(str, byte++));
+ byte = strtol(str.c_str() + 1, NULL, 16);
+ else
+ nfo_escapes.insert(nfe_pair(str, byte++));
}
}
- getline(f, buffer); // Try again to skip "format: " line
+ getline(f, buffer); // Try again to skip "format: " line
}
}
colourmap = NULL;
- try{
- read_file(f,infover,grfcontversion,nfofile);
- }catch(Sprite::unparseable e){
+ try
+ {
+ read_file(f, infover, grfcontversion, nfofile);
+ }
+ catch (Sprite::unparseable e)
+ {
printf("%s", e.reason.c_str());
exit(1);
}
@@ -89,10 +93,11 @@
delete imgfile;
}
-void inforeader::PrepareReal(const SpriteInfo&info){
- int oldy=inf.ypos;
- inf=info;
- if ( inf.forcereopen || !imgfile || !imgname || (stricmp(inf.name.c_str(), imgname) != 0) || oldy > inf.ypos) {
+void inforeader::PrepareReal(const SpriteInfo &info)
+{
+ int oldy = inf.ypos;
+ inf = info;
+ if (inf.forcereopen || !imgfile || !imgname || (stricmp(inf.name.c_str(), imgname) != 0) || oldy > inf.ypos) {
// new file
delete imgfile;
@@ -108,10 +113,9 @@
exit(2);
}
- if (colourmap)
- imgfile->installreadmap(colourmap);
+ if (colourmap) imgfile->installreadmap(colourmap);
- imgfile->startimage(inf.depth!=DEPTH_32BPP, 0, 0, 0, 0);
+ imgfile->startimage(inf.depth != DEPTH_32BPP, 0, 0, 0, 0);
}
sx = inf.xdim;
@@ -119,14 +123,15 @@
imgfile->startsubimage(inf.xpos, inf.ypos, sx, sy);
- imgsize = (long) sx * (long) sy;
+ imgsize = (long)sx * (long)sy;
}
-pcxread* inforeader::MakeReader()const{
+pcxread *inforeader::MakeReader() const
+{
#ifdef WITH_PNG
- if(toupper(imgname[strlen(imgname)-1])=='X')//pcx
- return new pcxread(new singlefile(imgname, "rb", NULL));
- else //png
+ if (toupper(imgname[strlen(imgname) - 1]) == 'X') // pcx
+ return new pcxread(new singlefile(imgname, "rb", NULL));
+ else // png
return new pngread(new singlefile(imgname, "rb", NULL));
#else
return new pcxread(new singlefile(imgname, "rb", NULL));
@@ -151,16 +156,17 @@
this->directory = directory;
infowriter::info = info;
fputs("// Automatically generated by GRFCODEC. Do not modify!\n", info);
- fprintf(info,"// (Info version %d)", _useexts ? 32 : 6);
- if(_useexts) {
+ fprintf(info, "// (Info version %d)", _useexts ? 32 : 6);
+ if (_useexts) {
// (re)insert default escapes
- foreach(const esc& e, escapes)
- nfo_escapes.insert(nfe_pair(e.str+1, e.byte));
+ foreach(const esc & e, escapes)
+ nfo_escapes.insert(nfe_pair(e.str + 1, e.byte));
fputs("\n// Escapes:", info);
int oldbyte = -1;
for (int act = 0; act < 255; act++) {
- foreach (const nfe_rpair& p, nfo_escapes.right) {
+ foreach(const nfe_rpair & p, nfo_escapes.right)
+ {
if (p.second[0] != act) continue;
if (p.first == oldbyte) {
@@ -170,25 +176,23 @@
fputs("\n// Escapes:", info);
oldbyte = -1;
}
- while (++oldbyte != p.first)
- fprintf(info," %s", nfo_escapes.right.begin()->second.c_str());
+ while (++oldbyte != p.first) fprintf(info, " %s", nfo_escapes.right.begin()->second.c_str());
fprintf(info, " %s", p.second.c_str());
}
}
}
if (_useexts) {
fputs("\n// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags\n", info);
- }else {
+ } else {
fputs("\n// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel\n", info);
}
infowriter::useplaintext = useplaintext;
infowriter::maxboxes = maxboxes;
- boxes = new Box*[maxboxes];
+ boxes = new Box *[maxboxes];
boxnum = 0;
spriteno = 0;
- for (int i=0; i<maxboxes; i++)
- boxes[i] = NULL;
+ for (int i = 0; i < maxboxes; i++) boxes[i] = NULL;
}
infowriter::~infowriter()
@@ -201,147 +205,147 @@
int i;
uint j;
- for (i=0; i<boxnum; i++) {
+ for (i = 0; i < boxnum; i++) {
switch (boxes[i]->type) {
- case Box::issprite:
- case Box::isspriteextension: {
- if (boxes[i]->type == Box::issprite) {
+ case Box::issprite:
+ case Box::isspriteextension: {
+ if (boxes[i]->type == Box::issprite) {
+ fprintf(info, "%5d ", spriteno++);
+ } else {
+ fprintf(info, " | ");
+ }
+ BoxSprite *s = (BoxSprite *)boxes[i];
+
+ if (_useexts) {
+ if (s->info.depth == 2) {
+ fprintf(info, "%s %5s %4d %4d", s->filename, depths[s->info.depth], s->x, s->y);
+ } else {
+ fprintf(info, "%s %5s %4d %4d %4d %4d %4d %4d %s", s->filename, depths[s->info.depth], s->x,
+ s->y, s->info.xdim, s->info.ydim, s->info.xrel, s->info.yrel,
+ zoom_levels[s->info.zoom]);
+ if (HASTRANSPARENCY(s->info.info)) fputs(" chunked", info);
+ if (DONOTCROP(s->info.info)) fputs(" nocrop", info);
+ }
+ } else {
+ fprintf(info, "%s %d %d %02X %d %d %d %d", s->filename, s->x, s->y, s->info.info, s->info.ydim,
+ s->info.xdim, s->info.xrel, s->info.yrel);
+ }
+ fputs("\n", info);
+ break;
+ }
+
+ case Box::isdata: {
fprintf(info, "%5d ", spriteno++);
- } else {
- fprintf(info, " | ");
- }
- BoxSprite *s = (BoxSprite*)boxes[i];
+ BoxData *d = (BoxData *)boxes[i];
+ int instr = 0;
+ int count = 0;
- if (_useexts) {
- if (s->info.depth == 2) {
- fprintf(info, "%s %5s %4d %4d",
- s->filename, depths[s->info.depth], s->x, s->y);
+ if (d->data[0] == 0xff && d->size > 4 && spriteno > 1) { // binary include file
+ int namelen = d->data[1];
+ int len = strlen(this->directory) + namelen + 1;
+ char *filename = new char[len];
+
+ snprintf(filename, len, "%s%s", this->directory, (char *)d->data + 2);
+ // Strip trailing whitespace
+ int last = 0;
+ for (int j = 0; j < len - 1; j++)
+ if (!isspace(filename[j])) last = j;
+ filename[last + 1] = '\0';
+ fprintf(info, "**\t %s\n", filename);
+
+ FILE *bin = fopen(filename, "wb");
+ if (!bin) {
+ fperror("Cannot write to %s", filename);
+ exit(2);
+ }
+ cfwrite("writing binary include", d->data + 3 + namelen, d->size - 3 - namelen, 1, bin);
+ delete[] filename;
+ fclose(bin);
} else {
- fprintf(info, "%s %5s %4d %4d %4d %4d %4d %4d %s",
- s->filename, depths[s->info.depth], s->x, s->y,
- s->info.xdim, s->info.ydim,
- s->info.xrel, s->info.yrel,
- zoom_levels[s->info.zoom]);
- if (HASTRANSPARENCY(s->info.info)) fputs(" chunked", info);
- if (DONOTCROP(s->info.info)) fputs(" nocrop", info);
- }
- } else {
- fprintf(info, "%s %d %d %02X %d %d %d %d",
- s->filename, s->x, s->y,
- s->info.info,
- s->info.ydim, s->info.xdim,
- s->info.xrel, s->info.yrel);
- }
- fputs("\n", info);
- break; }
+ fprintf(info, "* %d\t", d->size);
+ for (j = 0; j < d->size; j++) {
+// Readable characters are 32..126 and 158..255
+#define istxt(x) \
+ (j + (x) < \
+ d->size &&((d->data[j + (x)] >= 32 && (_useexts || d->data[j + (x)] != 34) && d->data[j + (x)] < 127) || d->data[j + (x)] > 158))
+ // int thistxt = (d->data[j] >= 32 && d->data[j] < 127) || d->data[j] > 158;
+ // int nexttxt = j+1<d->size && ((d->data[j+1]>=32 && d->data[j+1]<127) || d->data[j+1] >
+ // 158);
- case Box::isdata: {
- fprintf(info, "%5d ", spriteno++);
- BoxData *d = (BoxData*)boxes[i];
- int instr = 0;
- int count = 0;
-
- if (d->data[0] == 0xff && d->size>4 && spriteno>1) { // binary include file
- int namelen = d->data[1];
- int len = strlen(this->directory) + namelen + 1;
- char *filename = new char[len];
-
- snprintf(filename, len, "%s%s", this->directory, (char*) d->data + 2);
- // Strip trailing whitespace
- int last = 0;
- for (int j=0; j<len-1; j++)
- if (!isspace(filename[j])) last = j;
- filename[last+1] = '\0';
- fprintf(info, "**\t %s\n", filename);
-
- FILE *bin = fopen(filename, "wb");
- if (!bin) {
- fperror("Cannot write to %s", filename);
- exit(2);
- }
- cfwrite("writing binary include", d->data+3+namelen, d->size-3-namelen, 1, bin);
- delete[]filename;
- fclose(bin);
- } else {
- fprintf(info, "* %d\t", d->size);
- for (j=0; j<d->size; j++) {
- // Readable characters are 32..126 and 158..255
-#define istxt(x) (j+(x)<d->size && ((d->data[j+(x)]>=32 && (_useexts || d->data[j+(x)] != 34) && d->data[j+(x)]<127) || d->data[j+(x)] > 158))
- //int thistxt = (d->data[j] >= 32 && d->data[j] < 127) || d->data[j] > 158;
- //int nexttxt = j+1<d->size && ((d->data[j+1]>=32 && d->data[j+1]<127) || d->data[j+1] > 158);
-
- if (spriteno>1 &&
- istxt(0) && useplaintext && (instr ||
- //two in a row for 8 and E
- (istxt(1) && (d->data[0]==8 || d->data[0]==0xE ||
- //four in a row for everything else.
- (istxt(2) && istxt(3))
- ))
- )) {
- if (!instr) {
- fputs(" \"", info); instr = 1;
- }
- if(_useexts && d->data[j]=='\\')
- fputs("\\\\", info);
- else if(_useexts && d->data[j]=='"')
- fputs("\\\"", info);
- else
- fputc(d->data[j], info);
- } else {
- if (instr) {
- fputs("\"", info); instr = 0;
- }
- uint k=0;
- if (_useexts == 2 && spriteno>1) {
- for(;k<num_esc;k++)
- if(escapes[k].byte==d->data[j]&&
- escapes[k].action==d->data[0]&&
- (escapes[k].override?escapes[k].override(d->data,j):escapes[k].pos==j)&&
- (escapes[k].additional==NULL||escapes[k].additional(d->data,d->size))){
- fprintf(info," %s",escapes[k].str);
+ if (spriteno > 1 && istxt(0) && useplaintext &&
+ (instr ||
+ // two in a row for 8 and E
+ (istxt(1) && (d->data[0] == 8 || d->data[0] == 0xE ||
+ // four in a row for everything else.
+ (istxt(2) && istxt(3)))))) {
+ if (!instr) {
+ fputs(" \"", info);
+ instr = 1;
+ }
+ if (_useexts && d->data[j] == '\\')
+ fputs("\\\\", info);
+ else if (_useexts && d->data[j] == '"')
+ fputs("\\\"", info);
+ else
+ fputc(d->data[j], info);
+ } else {
+ if (instr) {
+ fputs("\"", info);
+ instr = 0;
+ }
+ uint k = 0;
+ if (_useexts == 2 && spriteno > 1) {
+ for (; k < num_esc; k++)
+ if (escapes[k].byte == d->data[j] &&
+ escapes[k].action == d->data[0] &&
+ (escapes[k].override ? escapes[k].override(d->data, j)
+ : escapes[k].pos == j) &&
+ (escapes[k].additional == NULL ||
+ escapes[k].additional(d->data, d->size))) {
+ fprintf(info, " %s", escapes[k].str);
break;
}
- }else
- k = num_esc;
- if(k==num_esc)
- fprintf(info, " %02X", d->data[j]);
+ } else
+ k = num_esc;
+ if (k == num_esc) fprintf(info, " %02X", d->data[j]);
+ }
+
+ // break lines after 32 non-text characters
+ // or at spaces after 32 text characters or
+ // after 60 text characters
+ count++;
+ if (((!instr && count >= 32) ||
+ (instr && ((count >= 32 && d->data[j] == ' ') || count >= 50))) &&
+ j < d->size - 1) {
+ if (instr) {
+ if (istxt(1)) {
+ fputs("\"\n\t \"", info);
+ } else {
+ fputs("\"\n\t", info);
+ instr = 0;
+ }
+ } else
+ fputs("\n\t", info);
+ count = 0;
+ }
}
- // break lines after 32 non-text characters
- // or at spaces after 32 text characters or
- // after 60 text characters
- count++;
- if ( ((!instr && count>=32) ||
- (instr && ((count>=32 && d->data[j]==' ')
- || count>=50)))
- && j<d->size-1) {
- if (instr) {
- if(istxt(1)){
- fputs("\"\n\t \"", info);
- }else{
- fputs("\"\n\t", info); instr = 0;
- }
- }else
- fputs("\n\t", info);
- count = 0;
- }
+ if (instr) fputs("\"", info);
+ fputs("\n", info);
}
+ free(d->data);
+ break;
+ }
- if (instr) fputs("\"", info);
- fputs("\n", info);
- }
- free(d->data);
- break; }
-
- default:
- printf("\nHuh? What kind of box is that?\n");
- exit(2);
+ default:
+ printf("\nHuh? What kind of box is that?\n");
+ exit(2);
}
}
boxnum = 0;
- for (i=0; i<maxboxes; i++) {
+ for (i = 0; i < maxboxes; i++) {
delete boxes[i];
boxes[i] = NULL;
}
@@ -351,28 +355,24 @@
{
printf("Reallocating memory for %d boxes\n", newmaxboxes);
infowriter::maxboxes = newmaxboxes;
- Box **newboxes = new Box*[newmaxboxes];
+ Box **newboxes = new Box *[newmaxboxes];
int i;
- for (i=0; i<maxboxes; i++)
- newboxes[i] = boxes[i];
- for (; i<newmaxboxes; i++)
- newboxes[i] = NULL;
+ for (i = 0; i < maxboxes; i++) newboxes[i] = boxes[i];
+ for (; i < newmaxboxes; i++) newboxes[i] = NULL;
delete[](boxes);
boxes = newboxes;
}
void infowriter::addsprite(bool first, const char *filename, int x, int y, SpriteInfo info)
{
- if (boxnum >= maxboxes)
- resize(maxboxes*2);
+ if (boxnum >= maxboxes) resize(maxboxes * 2);
boxes[boxnum++] = new BoxSprite(first, filename, x, y, info);
}
void infowriter::adddata(uint size, U8 *data)
{
- if (boxnum >= maxboxes)
- resize(maxboxes*2);
+ if (boxnum >= maxboxes) resize(maxboxes * 2);
boxes[boxnum++] = new BoxData(size, data);
}
diff --git a/src/info.h b/src/info.h
--- a/src/info.h
+++ b/src/info.h
@@ -1,7 +1,6 @@
#ifndef _INFO_H
#define _INFO_H
-
#include <stdio.h>
#include "pcxsprit.h"
@@ -10,56 +9,83 @@
#include "nfosprite.h"
#include "allocarray.h"
-class inforeader {
- public:
+class inforeader
+{
+ public:
inforeader(char *nf, int grfcontversion);
~inforeader();
- const Sprite&operator[](int x)const{return *(nfofile[x]);}
- int size()const{return nfofile.size();}
+ const Sprite &operator[](int x) const
+ {
+ return *(nfofile[x]);
+ }
+ int size() const
+ {
+ return nfofile.size();
+ }
void installmap(int *map);
long imgsize;
int sx, sy;
SpriteInfo inf;
- void PrepareReal(const SpriteInfo&info);
+ void PrepareReal(const SpriteInfo &info);
int getsprite(CommonPixel *sprite);
pcxread *imgfile;
- protected:
-
+ protected:
const char *imgname;
int *colourmap;
AllocArray<Sprite> nfofile;
-private:
- pcxread* MakeReader()const;
+
+ private:
+ pcxread *MakeReader() const;
};
-struct Box {
- enum boxtype {issprite, isspriteextension, isdata};
- Box(boxtype type) : type(type) {}
- virtual ~Box() {}
+struct Box
+{
+ enum boxtype {
+ issprite,
+ isspriteextension,
+ isdata
+ };
+ Box(boxtype type) : type(type)
+ {
+ }
+ virtual ~Box()
+ {
+ }
boxtype type;
};
-struct BoxData : Box {
- BoxData(uint size, U8 *data) : Box(isdata), size(size), data(data) {}
+struct BoxData : Box
+{
+ BoxData(uint size, U8 *data) : Box(isdata), size(size), data(data)
+ {
+ }
uint size;
U8 *data;
};
-struct BoxSprite : Box {
- BoxSprite(bool first, const char *filename, int x, int y, SpriteInfo info) : Box(first ? issprite : isspriteextension), filename(strdup(filename)), x(x), y(y), info(info) {}
- ~BoxSprite() { free(filename); }
+struct BoxSprite : Box
+{
+ BoxSprite(bool first, const char *filename, int x, int y, SpriteInfo info)
+ : Box(first ? issprite : isspriteextension), filename(strdup(filename)), x(x), y(y), info(info)
+ {
+ }
+ ~BoxSprite()
+ {
+ free(filename);
+ }
char *filename;
int x;
int y;
SpriteInfo info;
};
-class infowriter : public spriteinfowriter {
- public:
+class infowriter : public spriteinfowriter
+{
+ public:
infowriter(FILE *info, int maxboxes, int useplaintext, const char *directory);
virtual ~infowriter();
@@ -69,7 +95,7 @@
void done(int count);
- private:
+ private:
FILE *info;
const char *directory;
void resize(int newmaxboxes);
diff --git a/src/inject.cpp b/src/inject.cpp
--- a/src/inject.cpp
+++ b/src/inject.cpp
@@ -19,41 +19,47 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<queue>
-#include<istream>
-#include<string>
-#include<cassert>
+#include <queue>
+#include <istream>
+#include <string>
+#include <cassert>
using namespace std;
-#include"globals.h"
-#include"inject.h"
+#include "globals.h"
+#include "inject.h"
-static queue<string>_injected;
-static const istream*_into;
+static queue<string> _injected;
+static const istream* _into;
-istream&inj_getline(istream&in,string&str){
- assert(&in==_into);
- if(_injected.size()){
- str=_injected.front();
+istream& inj_getline(istream& in, string& str)
+{
+ assert(&in == _into);
+ if (_injected.size()) {
+ str = _injected.front();
_injected.pop();
return in;
}
- return getline(in,str);
+ return getline(in, str);
}
-int peek(istream&in){
- assert(&in==_into);
- if(&in==_into&&_injected.size())return _injected.front()[0];
+int peek(istream& in)
+{
+ assert(&in == _into);
+ if (&in == _into && _injected.size()) return _injected.front()[0];
return in.peek();
}
-void inject(const string&str){
- if(_into==NULL)(*pOut)<<str<<endl;
- else _injected.push(str);
+void inject(const string& str)
+{
+ if (_into == NULL)
+ (*pOut) << str << endl;
+ else
+ _injected.push(str);
}
-void inject_into(const istream&into){
- _into=&into;
- while(!_injected.empty())_injected.pop();
+void inject_into(const istream& into)
+{
+ _into = &into;
+ while (!_injected.empty()) _injected.pop();
}
diff --git a/src/inject.h b/src/inject.h
--- a/src/inject.h
+++ b/src/inject.h
@@ -22,9 +22,9 @@
#ifndef _RENUM_INJECT_H_INCLUDED_
#define _RENUM_INJECT_H_INCLUDED_
-istream&inj_getline(istream&,string&);
+istream& inj_getline(istream&, string&);
int peek(istream&);
void inject(const string&);
void inject_into(const istream&);
-#endif//_RENUM_INJECT_H_INCLUDED_
+#endif //_RENUM_INJECT_H_INCLUDED_
diff --git a/src/inlines.h b/src/inlines.h
--- a/src/inlines.h
+++ b/src/inlines.h
@@ -19,45 +19,51 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
#ifndef _RENUM_INLINES_H_INCLUDED_
#define _RENUM_INLINES_H_INCLUDED_
-#include<iostream>
-#include<cstdarg>
-#include<cassert>
-#include<cstring>
-#include<climits>
+#include <iostream>
+#include <cstdarg>
+#include <cassert>
+#include <cstring>
+#include <climits>
-#include"globals.h"
-#include"nforenum.h"
+#include "globals.h"
+#include "nforenum.h"
-inline string safetostring(const char*ptr){return ptr?ptr:"";}
+inline string safetostring(const char* ptr)
+{
+ return ptr ? ptr : "";
+}
-inline istream&eat_white(istream&in){
- while(isspace(in.peek()))in.ignore();
+inline istream& eat_white(istream& in)
+{
+ while (isspace(in.peek())) in.ignore();
return in;
}
-inline void strip_trailing_white(string&str){
+inline void strip_trailing_white(string& str)
+{
string::iterator last = str.end();
for (string::iterator i = str.begin(); i != str.end(); i++)
if (!isspace(*i)) last = i;
- if (last != str.end()) str.erase(last+1, str.end());
+ if (last != str.end()) str.erase(last + 1, str.end());
}
-inline int ctoi(char ch){
- if(ch>='0'&&ch<='9')return ch-'0';
- if(ch>='A'&&ch<='F')return ch-'A'+10;
- if(ch>='a'&&ch<='f')return ch-'a'+10;
+inline int ctoi(char ch)
+{
+ if (ch >= '0' && ch <= '9') return ch - '0';
+ if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10;
+ if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10;
return 0;
}
-inline bool is_comment(istream&in){
- if(strchr("#;",in.peek()))return true;
- if(in.peek()!='/')return false;
+inline bool is_comment(istream& in)
+{
+ if (strchr("#;", in.peek())) return true;
+ if (in.peek() != '/') return false;
in.ignore();
- if(in.peek()=='/'){
+ if (in.peek() == '/') {
in.unget();
return true;
}
@@ -65,68 +71,74 @@
return false;
}
-inline bool is_comment(const string&str,size_t off){
- if(strchr("#;",str[off]))return true;
- if(str[off]!='/'||str[off+1]!='/') return false;
+inline bool is_comment(const string& str, size_t off)
+{
+ if (strchr("#;", str[off])) return true;
+ if (str[off] != '/' || str[off + 1] != '/') return false;
return true;
}
-inline bool is_comment(const string&line){
- return line==""||is_comment(line,line.find_first_not_of(WHITESPACE));
+inline bool is_comment(const string& line)
+{
+ return line == "" || is_comment(line, line.find_first_not_of(WHITESPACE));
}
-inline string UCase(string str){
- size_t len=str.length();
- for(size_t i=0;i<len;i++)
- str[i]=(char)toupper(str[i]);
+inline string UCase(string str)
+{
+ size_t len = str.length();
+ for (size_t i = 0; i < len; i++) str[i] = (char)toupper(str[i]);
return str;
}
-inline string itoa(uint x,uint radix=10,uint minlen=1){
+inline string itoa(uint x, uint radix = 10, uint minlen = 1)
+{
string ret;
- if(radix==256){
- while(x||minlen--){
- ret+=char(x&0xFF);
- x>>=8;
+ if (radix == 256) {
+ while (x || minlen--) {
+ ret += char(x & 0xFF);
+ x >>= 8;
}
return ret;
}
- if(!x)ret="0";
- assert(radix<=16);
- while(x){
- ret="0123456789ABCDEF"[x%radix]+ret;
- x/=radix;
+ if (!x) ret = "0";
+ assert(radix <= 16);
+ while (x) {
+ ret = "0123456789ABCDEF"[x % radix] + ret;
+ x /= radix;
}
- while(ret.length()<minlen)
- ret=((radix==10)?' ':'0')+ret;
+ while (ret.length() < minlen) ret = ((radix == 10) ? ' ' : '0') + ret;
return ret;
}
-inline string itoa(int x,uint radix=10,uint minlen=1){
- if(x>=0)return itoa((uint)x,radix,minlen);
- if(x==INT_MIN)return '-'+itoa(uint(INT_MAX)+1,radix,minlen);
- else return '-'+itoa((uint)-x,radix,minlen);
+inline string itoa(int x, uint radix = 10, uint minlen = 1)
+{
+ if (x >= 0) return itoa((uint)x, radix, minlen);
+ if (x == INT_MIN)
+ return '-' + itoa(uint(INT_MAX) + 1, radix, minlen);
+ else
+ return '-' + itoa((uint) - x, radix, minlen);
}
-inline uint ReadHex(istream&in,uint digits){
+inline uint ReadHex(istream& in, uint digits)
+{
uint ret;
- while(isspace(in.peek()))in.ignore();
+ while (isspace(in.peek())) in.ignore();
char ch;
in.get(ch);
- if((ret=ctoi(ch))==0&&ch!='0'){
+ if ((ret = ctoi(ch)) == 0 && ch != '0') {
in.unget().clear(ios::badbit);
return ret;
}
- for(;--digits;){
+ for (; --digits;) {
in.get(ch);
- if(ctoi(ch)==0&&ch!='0'){
+ if (ctoi(ch) == 0 && ch != '0') {
in.unget();
return ret;
}
- ret<<=4;
- ret|=ctoi(ch);
+ ret <<= 4;
+ ret |= ctoi(ch);
}
return ret;
}
-#endif//_RENUM_INLINES_H_INCLUDED_
+#endif //_RENUM_INLINES_H_INCLUDED_
diff --git a/src/language_mgr.cpp b/src/language_mgr.cpp
--- a/src/language_mgr.cpp
+++ b/src/language_mgr.cpp
@@ -19,7 +19,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<cstdlib>
+#include <cstdlib>
#include "language_mgr.h"
@@ -27,20 +27,22 @@
#include "inlines.h"
-LanguageMgr::LanguageMgr() {
+LanguageMgr::LanguageMgr()
+{
InitLanguageMap();
currentId = DetectLanguage();
}
-RenumLanguageId LanguageMgr::DetectLanguage() const {
+RenumLanguageId LanguageMgr::DetectLanguage() const
+{
string langCode = safetostring(getenv("LANG"));
return DecodeLanguageCode(langCode);
}
-RenumLanguageId LanguageMgr::DecodeLanguageCode(const string& code) const {
+RenumLanguageId LanguageMgr::DecodeLanguageCode(const string& code) const
+{
str2lang_map::const_iterator pos = codeIdMap.find(code);
- if(pos != codeIdMap.end())
- return pos->second;
+ if (pos != codeIdMap.end()) return pos->second;
return RL_DEFAULT;
}
@@ -50,8 +52,9 @@
#undef START_LANGUAGES
#undef RENUM_LANGUAGE
#undef END_LANGUAGES
-#define START_LANGUAGES() void LanguageMgr::InitLanguageMap() {
-#define RENUM_LANGUAGE(name,code) \
- codeIdMap.insert(make_pair(code,name));
+#define START_LANGUAGES() \
+ void LanguageMgr::InitLanguageMap() \
+ {
+#define RENUM_LANGUAGE(name, code) codeIdMap.insert(make_pair(code, name));
#define END_LANGUAGES() }
#include "lang/language_list.h"
diff --git a/src/language_mgr.h b/src/language_mgr.h
--- a/src/language_mgr.h
+++ b/src/language_mgr.h
@@ -25,13 +25,13 @@
#include <string>
#ifdef _MSC_VER
-#pragma warning (disable : 4702) // warning C4702: unreachable code
+#pragma warning(disable : 4702) // warning C4702: unreachable code
#endif
#include <map>
#ifdef _MSC_VER
-#pragma warning (default : 4702)
+#pragma warning(default : 4702)
#endif
#include "singleton.h"
@@ -42,8 +42,10 @@
// all the supported language IDs.
#ifndef RENUM_LANGUAGE
#define START_LANGUAGES() typedef enum {
-#define RENUM_LANGUAGE(name,code)name,
-#define END_LANGUAGES() } RenumLanguageId;
+#define RENUM_LANGUAGE(name, code) name,
+#define END_LANGUAGES() \
+ } \
+ RenumLanguageId;
#endif // RENUM_LANGUAGE
#include "lang/language_list.h"
@@ -53,38 +55,46 @@
#define RL_DEFAULT RL_ENGLISH
/*! Collection mapping strings to language IDs. */
-typedef std::map<std::string,RenumLanguageId> str2lang_map;
+typedef std::map<std::string, RenumLanguageId> str2lang_map;
/*! Handles program language detection and selection. */
-class LanguageMgr {
+class LanguageMgr
+{
SINGLETON(LanguageMgr);
-public:
+
+ public:
/*! Gets the current language ID.
- \return ID of the current language.
+ \return ID of the current language.
*/
- RenumLanguageId GetCurrentLanguage() const { return currentId; };
+ RenumLanguageId GetCurrentLanguage() const
+ {
+ return currentId;
+ };
/*! Change the current language.
- \param id Language ID to set the current language to.
+ \param id Language ID to set the current language to.
*/
- void ChangeLanguage(RenumLanguageId id) { currentId = id; };
+ void ChangeLanguage(RenumLanguageId id)
+ {
+ currentId = id;
+ };
/*! Detects the current language based on environment variables. */
RenumLanguageId DetectLanguage() const;
/*! Decodes a language code into its identifier.
- \param code A string containing the language code.
- \return Corresponding language ID, if such a language is supported.
- Otherwise the function returns RL_DEFAULT.
+ \param code A string containing the language code.
+ \return Corresponding language ID, if such a language is supported.
+ Otherwise the function returns RL_DEFAULT.
*/
RenumLanguageId DecodeLanguageCode(const std::string& code) const;
-private:
+ private:
/*! Initializes the language map with data about supported languages. */
void InitLanguageMap();
RenumLanguageId currentId; /*!< Current language ID */
- str2lang_map codeIdMap; /*!< Maps language codes to identifiers */
+ str2lang_map codeIdMap; /*!< Maps language codes to identifiers */
};
#endif // _RENUM_LANGUAGE_MGR_H_INCLUDED_
diff --git a/src/mapescapes.cpp b/src/mapescapes.cpp
--- a/src/mapescapes.cpp
+++ b/src/mapescapes.cpp
@@ -28,37 +28,34 @@
#include "messages.h"
#include "mapescapes.h"
-string FindEscape(char action, int byte) {
+string FindEscape(char action, int byte)
+{
// Look for a custom escape
- foreach(const nfe_rpair& p, nfo_escapes.right.equal_range(byte))
- if (p.second[0] == action)
- return " \\" + p.second;
+ foreach(const nfe_rpair & p, nfo_escapes.right.equal_range(byte))
+ if (p.second[0] == action) return " \\" + p.second;
// Look for a built-in escape
- foreach(const esc& e, escapes)
- if (e.action==ctoi(action) && e.byte==byte)
- return ' ' + string(e.str);
+ foreach(const esc & e, escapes)
+ if (e.action == ctoi(action) && e.byte == byte) return ' ' + string(e.str);
return "";
}
-string FindEscape(char action, int byte, uint offset) {
+string FindEscape(char action, int byte, uint offset)
+{
// This time, look for a built-in escape first
- foreach(const esc& e, escapes)
- if (e.action==ctoi(action) && e.byte==byte && e.pos==offset)
- return ' ' + string(e.str);
+ foreach(const esc & e, escapes)
+ if (e.action == ctoi(action) && e.byte == byte && e.pos == offset) return ' ' + string(e.str);
// Look for a custom escape
- foreach(const nfe_rpair& p, nfo_escapes.right.equal_range(byte))
- if (p.second[0] == action)
- return " \\" + p.second;
+ foreach(const nfe_rpair & p, nfo_escapes.right.equal_range(byte))
+ if (p.second[0] == action) return " \\" + p.second;
return "";
}
-int FindEscape(string str) {
+int FindEscape(string str)
+{
foreach(esc e, escapes)
- if(str == e.str+1)
- return e.byte;
+ if (str == e.str + 1) return e.byte;
nfe_left_iter ret = nfo_escapes.left.find(str);
- if(ret == nfo_escapes.left.end())
- return -1;
+ if (ret == nfo_escapes.left.end()) return -1;
return ret->second;
}
diff --git a/src/md5.cpp b/src/md5.cpp
--- a/src/md5.cpp
+++ b/src/md5.cpp
@@ -27,7 +27,7 @@
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
- http://www.ietf.org/rfc/rfc1321.txt
+ http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
@@ -38,14 +38,14 @@
that follows (in reverse chronological order):
2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
- either statically or dynamically; added missing #include <string.h>
- in library.
+ either statically or dynamically; added missing #include <string.h>
+ in library.
2002-03-11 lpd Corrected argument list for main(), and added int return
- type, in test program and T value program.
+ type, in test program and T value program.
2002-02-21 lpd Added missing #include <stdio.h> in test program.
2000-07-03 lpd Patched to eliminate warnings about "constant is
- unsigned in ANSI C, signed in traditional"; made test program
- self-checking.
+ unsigned in ANSI C, signed in traditional"; made test program
+ self-checking.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
1999-05-03 lpd Original version.
@@ -54,328 +54,310 @@
#include "md5.h"
#include <string.h>
-#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
+#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#ifdef ARCH_IS_BIG_ENDIAN
-# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
+#define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
#else
-# define BYTE_ORDER 0
+#define BYTE_ORDER 0
#endif
-#define T_MASK ((md5_word_t)~0)
+#define T_MASK ((md5_word_t) ~0)
#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
-#define T3 0x242070db
+#define T3 0x242070db
#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
-#define T6 0x4787c62a
+#define T6 0x4787c62a
#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
-#define T9 0x698098d8
+#define T9 0x698098d8
#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
-#define T13 0x6b901122
+#define T13 0x6b901122
#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
-#define T16 0x49b40821
+#define T16 0x49b40821
#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
-#define T19 0x265e5a51
+#define T19 0x265e5a51
#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
-#define T22 0x02441453
+#define T22 0x02441453
#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
-#define T25 0x21e1cde6
+#define T25 0x21e1cde6
#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
-#define T28 0x455a14ed
+#define T28 0x455a14ed
#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
-#define T31 0x676f02d9
+#define T31 0x676f02d9
#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
-#define T35 0x6d9d6122
+#define T35 0x6d9d6122
#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
-#define T38 0x4bdecfa9
+#define T38 0x4bdecfa9
#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
-#define T41 0x289b7ec6
+#define T41 0x289b7ec6
#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
-#define T44 0x04881d05
+#define T44 0x04881d05
#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
-#define T47 0x1fa27cf8
+#define T47 0x1fa27cf8
#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
-#define T50 0x432aff97
+#define T50 0x432aff97
#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
-#define T53 0x655b59c3
+#define T53 0x655b59c3
#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
-#define T57 0x6fa87e4f
+#define T57 0x6fa87e4f
#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
-#define T60 0x4e0811a1
+#define T60 0x4e0811a1
#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
-#define T63 0x2ad7d2bb
+#define T63 0x2ad7d2bb
#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
-
-static void
-md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
+static void md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
{
- md5_word_t
- a = pms->abcd[0], b = pms->abcd[1],
- c = pms->abcd[2], d = pms->abcd[3];
- md5_word_t t;
+ md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2], d = pms->abcd[3];
+ md5_word_t t;
#if BYTE_ORDER > 0
- /* Define storage only for big-endian CPUs. */
- md5_word_t X[16];
+ /* Define storage only for big-endian CPUs. */
+ md5_word_t X[16];
#else
- /* Define storage for little-endian or both types of CPUs. */
- md5_word_t xbuf[16];
- const md5_word_t *X;
+ /* Define storage for little-endian or both types of CPUs. */
+ md5_word_t xbuf[16];
+ const md5_word_t *X;
#endif
- {
+ {
#if BYTE_ORDER == 0
- /*
- * Determine dynamically whether this is a big-endian or
- * little-endian machine, since we can use a more efficient
- * algorithm on the latter.
- */
- static const int w = 1;
+ /*
+ * Determine dynamically whether this is a big-endian or
+ * little-endian machine, since we can use a more efficient
+ * algorithm on the latter.
+ */
+ static const int w = 1;
- if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+ if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
#endif
-#if BYTE_ORDER <= 0 /* little-endian */
- {
- /*
- * On little-endian machines, we can process properly aligned
- * data without copying it.
- */
- if (!((data - (const md5_byte_t *)0) & 3)) {
- /* data are properly aligned */
- X = (const md5_word_t *)data;
- } else {
- /* not aligned */
- memcpy(xbuf, data, 64);
- X = xbuf;
- }
- }
+#if BYTE_ORDER <= 0 /* little-endian */
+ {
+ /*
+ * On little-endian machines, we can process properly aligned
+ * data without copying it.
+ */
+ if (!((data - (const md5_byte_t *)0) & 3)) {
+ /* data are properly aligned */
+ X = (const md5_word_t *)data;
+ } else {
+ /* not aligned */
+ memcpy(xbuf, data, 64);
+ X = xbuf;
+ }
+ }
#endif
#if BYTE_ORDER == 0
- else /* dynamic big-endian */
+ else /* dynamic big-endian */
#endif
-#if BYTE_ORDER >= 0 /* big-endian */
- {
- /*
- * On big-endian machines, we must arrange the bytes in the
- * right order.
- */
- const md5_byte_t *xp = data;
- int i;
+#if BYTE_ORDER >= 0 /* big-endian */
+ {
+ /*
+ * On big-endian machines, we must arrange the bytes in the
+ * right order.
+ */
+ const md5_byte_t *xp = data;
+ int i;
-# if BYTE_ORDER == 0
- X = xbuf; /* (dynamic only) */
-# else
-# define xbuf X /* (static only) */
-# endif
- for (i = 0; i < 16; ++i, xp += 4)
- xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
+#if BYTE_ORDER == 0
+ X = xbuf; /* (dynamic only) */
+#else
+#define xbuf X /* (static only) */
+#endif
+ for (i = 0; i < 16; ++i, xp += 4) xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
+ }
+#endif
}
-#endif
- }
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
- /* Round 1. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
+/* Round 1. */
+/* Let [abcd k s i] denote the operation
+ a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + F(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 0, 7, T1);
- SET(d, a, b, c, 1, 12, T2);
- SET(c, d, a, b, 2, 17, T3);
- SET(b, c, d, a, 3, 22, T4);
- SET(a, b, c, d, 4, 7, T5);
- SET(d, a, b, c, 5, 12, T6);
- SET(c, d, a, b, 6, 17, T7);
- SET(b, c, d, a, 7, 22, T8);
- SET(a, b, c, d, 8, 7, T9);
- SET(d, a, b, c, 9, 12, T10);
- SET(c, d, a, b, 10, 17, T11);
- SET(b, c, d, a, 11, 22, T12);
- SET(a, b, c, d, 12, 7, T13);
- SET(d, a, b, c, 13, 12, T14);
- SET(c, d, a, b, 14, 17, T15);
- SET(b, c, d, a, 15, 22, T16);
+#define SET(a, b, c, d, k, s, Ti) \
+ t = a + F(b, c, d) + X[k] + Ti; \
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 7, T1);
+ SET(d, a, b, c, 1, 12, T2);
+ SET(c, d, a, b, 2, 17, T3);
+ SET(b, c, d, a, 3, 22, T4);
+ SET(a, b, c, d, 4, 7, T5);
+ SET(d, a, b, c, 5, 12, T6);
+ SET(c, d, a, b, 6, 17, T7);
+ SET(b, c, d, a, 7, 22, T8);
+ SET(a, b, c, d, 8, 7, T9);
+ SET(d, a, b, c, 9, 12, T10);
+ SET(c, d, a, b, 10, 17, T11);
+ SET(b, c, d, a, 11, 22, T12);
+ SET(a, b, c, d, 12, 7, T13);
+ SET(d, a, b, c, 13, 12, T14);
+ SET(c, d, a, b, 14, 17, T15);
+ SET(b, c, d, a, 15, 22, T16);
#undef SET
- /* Round 2. */
- /* Let [abcd k s i] denote the operation
- a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
+/* Round 2. */
+/* Let [abcd k s i] denote the operation
+ a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + G(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 1, 5, T17);
- SET(d, a, b, c, 6, 9, T18);
- SET(c, d, a, b, 11, 14, T19);
- SET(b, c, d, a, 0, 20, T20);
- SET(a, b, c, d, 5, 5, T21);
- SET(d, a, b, c, 10, 9, T22);
- SET(c, d, a, b, 15, 14, T23);
- SET(b, c, d, a, 4, 20, T24);
- SET(a, b, c, d, 9, 5, T25);
- SET(d, a, b, c, 14, 9, T26);
- SET(c, d, a, b, 3, 14, T27);
- SET(b, c, d, a, 8, 20, T28);
- SET(a, b, c, d, 13, 5, T29);
- SET(d, a, b, c, 2, 9, T30);
- SET(c, d, a, b, 7, 14, T31);
- SET(b, c, d, a, 12, 20, T32);
+#define SET(a, b, c, d, k, s, Ti) \
+ t = a + G(b, c, d) + X[k] + Ti; \
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 1, 5, T17);
+ SET(d, a, b, c, 6, 9, T18);
+ SET(c, d, a, b, 11, 14, T19);
+ SET(b, c, d, a, 0, 20, T20);
+ SET(a, b, c, d, 5, 5, T21);
+ SET(d, a, b, c, 10, 9, T22);
+ SET(c, d, a, b, 15, 14, T23);
+ SET(b, c, d, a, 4, 20, T24);
+ SET(a, b, c, d, 9, 5, T25);
+ SET(d, a, b, c, 14, 9, T26);
+ SET(c, d, a, b, 3, 14, T27);
+ SET(b, c, d, a, 8, 20, T28);
+ SET(a, b, c, d, 13, 5, T29);
+ SET(d, a, b, c, 2, 9, T30);
+ SET(c, d, a, b, 7, 14, T31);
+ SET(b, c, d, a, 12, 20, T32);
#undef SET
- /* Round 3. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
+/* Round 3. */
+/* Let [abcd k s t] denote the operation
+ a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + H(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 5, 4, T33);
- SET(d, a, b, c, 8, 11, T34);
- SET(c, d, a, b, 11, 16, T35);
- SET(b, c, d, a, 14, 23, T36);
- SET(a, b, c, d, 1, 4, T37);
- SET(d, a, b, c, 4, 11, T38);
- SET(c, d, a, b, 7, 16, T39);
- SET(b, c, d, a, 10, 23, T40);
- SET(a, b, c, d, 13, 4, T41);
- SET(d, a, b, c, 0, 11, T42);
- SET(c, d, a, b, 3, 16, T43);
- SET(b, c, d, a, 6, 23, T44);
- SET(a, b, c, d, 9, 4, T45);
- SET(d, a, b, c, 12, 11, T46);
- SET(c, d, a, b, 15, 16, T47);
- SET(b, c, d, a, 2, 23, T48);
+#define SET(a, b, c, d, k, s, Ti) \
+ t = a + H(b, c, d) + X[k] + Ti; \
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 5, 4, T33);
+ SET(d, a, b, c, 8, 11, T34);
+ SET(c, d, a, b, 11, 16, T35);
+ SET(b, c, d, a, 14, 23, T36);
+ SET(a, b, c, d, 1, 4, T37);
+ SET(d, a, b, c, 4, 11, T38);
+ SET(c, d, a, b, 7, 16, T39);
+ SET(b, c, d, a, 10, 23, T40);
+ SET(a, b, c, d, 13, 4, T41);
+ SET(d, a, b, c, 0, 11, T42);
+ SET(c, d, a, b, 3, 16, T43);
+ SET(b, c, d, a, 6, 23, T44);
+ SET(a, b, c, d, 9, 4, T45);
+ SET(d, a, b, c, 12, 11, T46);
+ SET(c, d, a, b, 15, 16, T47);
+ SET(b, c, d, a, 2, 23, T48);
#undef SET
- /* Round 4. */
- /* Let [abcd k s t] denote the operation
- a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
+/* Round 4. */
+/* Let [abcd k s t] denote the operation
+ a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
-#define SET(a, b, c, d, k, s, Ti)\
- t = a + I(b,c,d) + X[k] + Ti;\
- a = ROTATE_LEFT(t, s) + b
- /* Do the following 16 operations. */
- SET(a, b, c, d, 0, 6, T49);
- SET(d, a, b, c, 7, 10, T50);
- SET(c, d, a, b, 14, 15, T51);
- SET(b, c, d, a, 5, 21, T52);
- SET(a, b, c, d, 12, 6, T53);
- SET(d, a, b, c, 3, 10, T54);
- SET(c, d, a, b, 10, 15, T55);
- SET(b, c, d, a, 1, 21, T56);
- SET(a, b, c, d, 8, 6, T57);
- SET(d, a, b, c, 15, 10, T58);
- SET(c, d, a, b, 6, 15, T59);
- SET(b, c, d, a, 13, 21, T60);
- SET(a, b, c, d, 4, 6, T61);
- SET(d, a, b, c, 11, 10, T62);
- SET(c, d, a, b, 2, 15, T63);
- SET(b, c, d, a, 9, 21, T64);
+#define SET(a, b, c, d, k, s, Ti) \
+ t = a + I(b, c, d) + X[k] + Ti; \
+ a = ROTATE_LEFT(t, s) + b
+ /* Do the following 16 operations. */
+ SET(a, b, c, d, 0, 6, T49);
+ SET(d, a, b, c, 7, 10, T50);
+ SET(c, d, a, b, 14, 15, T51);
+ SET(b, c, d, a, 5, 21, T52);
+ SET(a, b, c, d, 12, 6, T53);
+ SET(d, a, b, c, 3, 10, T54);
+ SET(c, d, a, b, 10, 15, T55);
+ SET(b, c, d, a, 1, 21, T56);
+ SET(a, b, c, d, 8, 6, T57);
+ SET(d, a, b, c, 15, 10, T58);
+ SET(c, d, a, b, 6, 15, T59);
+ SET(b, c, d, a, 13, 21, T60);
+ SET(a, b, c, d, 4, 6, T61);
+ SET(d, a, b, c, 11, 10, T62);
+ SET(c, d, a, b, 2, 15, T63);
+ SET(b, c, d, a, 9, 21, T64);
#undef SET
- /* Then perform the following additions. (That is increment each
- of the four registers by the value it had before this block
- was started.) */
- pms->abcd[0] += a;
- pms->abcd[1] += b;
- pms->abcd[2] += c;
- pms->abcd[3] += d;
+ /* Then perform the following additions. (That is increment each
+ of the four registers by the value it had before this block
+ was started.) */
+ pms->abcd[0] += a;
+ pms->abcd[1] += b;
+ pms->abcd[2] += c;
+ pms->abcd[3] += d;
}
-void
-md5_init(md5_state_t *pms)
+void md5_init(md5_state_t *pms)
{
- pms->count[0] = pms->count[1] = 0;
- pms->abcd[0] = 0x67452301;
- pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
- pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
- pms->abcd[3] = 0x10325476;
+ pms->count[0] = pms->count[1] = 0;
+ pms->abcd[0] = 0x67452301;
+ pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
+ pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
+ pms->abcd[3] = 0x10325476;
}
-void
-md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
+void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
{
- const md5_byte_t *p = data;
- int left = nbytes;
- int offset = (pms->count[0] >> 3) & 63;
- md5_word_t nbits = (md5_word_t)(nbytes << 3);
+ const md5_byte_t *p = data;
+ int left = nbytes;
+ int offset = (pms->count[0] >> 3) & 63;
+ md5_word_t nbits = (md5_word_t)(nbytes << 3);
- if (nbytes <= 0)
- return;
+ if (nbytes <= 0) return;
- /* Update the message length. */
- pms->count[1] += nbytes >> 29;
- pms->count[0] += nbits;
- if (pms->count[0] < nbits)
- pms->count[1]++;
+ /* Update the message length. */
+ pms->count[1] += nbytes >> 29;
+ pms->count[0] += nbits;
+ if (pms->count[0] < nbits) pms->count[1]++;
- /* Process an initial partial block. */
- if (offset) {
- int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
+ /* Process an initial partial block. */
+ if (offset) {
+ int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
- memcpy(pms->buf + offset, p, copy);
- if (offset + copy < 64)
- return;
- p += copy;
- left -= copy;
- md5_process(pms, pms->buf);
- }
+ memcpy(pms->buf + offset, p, copy);
+ if (offset + copy < 64) return;
+ p += copy;
+ left -= copy;
+ md5_process(pms, pms->buf);
+ }
- /* Process full blocks. */
- for (; left >= 64; p += 64, left -= 64)
- md5_process(pms, p);
+ /* Process full blocks. */
+ for (; left >= 64; p += 64, left -= 64) md5_process(pms, p);
- /* Process a final partial block. */
- if (left)
- memcpy(pms->buf, p, left);
+ /* Process a final partial block. */
+ if (left) memcpy(pms->buf, p, left);
}
-void
-md5_finish(md5_state_t *pms, md5_byte_t digest[16])
+void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
{
- static const md5_byte_t pad[64] = {
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
- };
- md5_byte_t data[8];
- int i;
+ static const md5_byte_t pad[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ md5_byte_t data[8];
+ int i;
- /* Save the length before padding. */
- for (i = 0; i < 8; ++i)
- data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
- /* Pad to 56 bytes mod 64. */
- md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
- /* Append the length. */
- md5_append(pms, data, 8);
- for (i = 0; i < 16; ++i)
- digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
+ /* Save the length before padding. */
+ for (i = 0; i < 8; ++i) data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
+ /* Pad to 56 bytes mod 64. */
+ md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
+ /* Append the length. */
+ md5_append(pms, data, 8);
+ for (i = 0; i < 16; ++i) digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
}
diff --git a/src/md5.h b/src/md5.h
--- a/src/md5.h
+++ b/src/md5.h
@@ -27,7 +27,7 @@
This code implements the MD5 Algorithm defined in RFC 1321, whose
text is available at
- http://www.ietf.org/rfc/rfc1321.txt
+ http://www.ietf.org/rfc/rfc1321.txt
The code is derived from the text of the RFC, including the test suite
(section A.5) but excluding the rest of Appendix A. It does not include
any code or documentation that is identified in the RFC as being
@@ -38,19 +38,19 @@
that follows (in reverse chronological order):
2002-04-13 lpd Removed support for non-ANSI compilers; removed
- references to Ghostscript; clarified derivation from RFC 1321;
- now handles byte order either statically or dynamically.
+ references to Ghostscript; clarified derivation from RFC 1321;
+ now handles byte order either statically or dynamically.
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
- added conditionalization for C++ compilation from Martin
- Purschke <purschke@bnl.gov>.
+ added conditionalization for C++ compilation from Martin
+ Purschke <purschke@bnl.gov>.
1999-05-03 lpd Original version.
*/
#include "endian.h"
#ifndef md5_INCLUDED
-# define md5_INCLUDED
+#define md5_INCLUDED
/*
* This package supports both compile-time and run-time determination of CPU
@@ -63,18 +63,18 @@
*/
typedef unsigned char md5_byte_t; /* 8-bit byte */
-typedef unsigned int md5_word_t; /* 32-bit word */
+typedef unsigned int md5_word_t; /* 32-bit word */
/* Define the state of the MD5 Algorithm. */
-typedef struct md5_state_s {
- md5_word_t count[2]; /* message length in bits, lsw first */
- md5_word_t abcd[4]; /* digest buffer */
- md5_byte_t buf[64]; /* accumulate block */
+typedef struct md5_state_s
+{
+ md5_word_t count[2]; /* message length in bits, lsw first */
+ md5_word_t abcd[4]; /* digest buffer */
+ md5_byte_t buf[64]; /* accumulate block */
} md5_state_t;
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
/* Initialize the algorithm. */
@@ -87,7 +87,7 @@
void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
#ifdef __cplusplus
-} /* end extern "C" */
+} /* end extern "C" */
#endif
#endif /* md5_INCLUDED */
diff --git a/src/message_mgr.cpp b/src/message_mgr.cpp
--- a/src/message_mgr.cpp
+++ b/src/message_mgr.cpp
@@ -31,103 +31,109 @@
const string MessageData::commentPrefix = "!!";
-MessageData::MessageData(char props_) : textMap() {
+MessageData::MessageData(char props_) : textMap()
+{
props = props_;
}
-MessageData::MessageData(char props_, const string& default_text) : textMap() {
+MessageData::MessageData(char props_, const string& default_text) : textMap()
+{
props = props_;
SetText(RL_DEFAULT, default_text);
}
-string MessageData::Display(const string& prefix, va_list& ap) const {
+string MessageData::Display(const string& prefix, va_list& ap) const
+{
string ret = myvsprintf(GetMessage(prefix).c_str(), ap);
ostream* const stream[] = {pErr, pOut, pNfo};
- if((props & TO_MASK) != TO_NULL)
- (*(stream[(props & TO_MASK) >> TO_SHIFT])) << ret;
+ if ((props & TO_MASK) != TO_NULL) (*(stream[(props & TO_MASK) >> TO_SHIFT])) << ret;
return ret;
}
-const string& MessageData::GetText() const {
- lang2str_map::const_iterator pos = textMap.find(
- LanguageMgr::Instance().GetCurrentLanguage());
- if(pos == textMap.end()) {
+const string& MessageData::GetText() const
+{
+ lang2str_map::const_iterator pos = textMap.find(LanguageMgr::Instance().GetCurrentLanguage());
+ if (pos == textMap.end()) {
pos = textMap.find(RL_DEFAULT);
- if(pos == textMap.end()) {
+ if (pos == textMap.end()) {
return MessageMgr::UNDEFINED_TEXT;
}
}
return pos->second;
}
-void MessageData::SetText(RenumLanguageId lang, const string& text) {
+void MessageData::SetText(RenumLanguageId lang, const string& text)
+{
textMap[lang] = text;
}
-string MessageData::GetMessage(const string& prefix) const {
+string MessageData::GetMessage(const string& prefix) const
+{
string ret = GetText();
- if(props & HAS_OFFSET)
- ret = MessageMgr::Instance().GetExtraText(OFFSET) + ret;
- if(props & USE_PREFIX)
- ret = prefix + ret;
- if(props & MAKE_COMMENT)
- ret = COMMENT_PREFIX + commentPrefix + ret;
+ if (props & HAS_OFFSET) ret = MessageMgr::Instance().GetExtraText(OFFSET) + ret;
+ if (props & USE_PREFIX) ret = prefix + ret;
+ if (props & MAKE_COMMENT) ret = COMMENT_PREFIX + commentPrefix + ret;
return ret;
}
// --------
const string MessageMgr::UNDEFINED_TEXT = "UNDEFINED_TEXT";
-const MessageData MessageMgr::UNKNOWN_MESSAGE = MessageData(0,"UNKNOWN_MESSAGE");
+const MessageData MessageMgr::UNKNOWN_MESSAGE = MessageData(0, "UNKNOWN_MESSAGE");
-MessageMgr::MessageMgr() {
+MessageMgr::MessageMgr()
+{
InitMessages();
InitMessageTexts();
InitExtraTexts();
}
-const MessageData& MessageMgr::GetMessageData(RenumMessageId i) const {
+const MessageData& MessageMgr::GetMessageData(RenumMessageId i) const
+{
msgid2data_map::const_iterator pos = msgDataMap.find(i);
- if(pos != msgDataMap.end()) {
+ if (pos != msgDataMap.end()) {
return pos->second;
}
return UNKNOWN_MESSAGE;
}
-const std::string& MessageMgr::GetExtraText(RenumExtraTextId i) const {
+const std::string& MessageMgr::GetExtraText(RenumExtraTextId i) const
+{
extid2data_map::const_iterator pos = extraTextMap.find(i);
- if(pos == extraTextMap.end()) {
+ if (pos == extraTextMap.end()) {
return UNDEFINED_TEXT;
}
const lang2str_map& textMap = pos->second;
- lang2str_map::const_iterator textPos = textMap.find(
- LanguageMgr::Instance().GetCurrentLanguage());
- if(textPos == textMap.end()) {
+ lang2str_map::const_iterator textPos = textMap.find(LanguageMgr::Instance().GetCurrentLanguage());
+ if (textPos == textMap.end()) {
textPos = textMap.find(RL_DEFAULT);
- if(textPos == textMap.end()) {
+ if (textPos == textMap.end()) {
return UNDEFINED_TEXT;
}
}
return textPos->second;
}
-bool MessageMgr::AddMessage(RenumMessageId i, char props) {
+bool MessageMgr::AddMessage(RenumMessageId i, char props)
+{
return msgDataMap.insert(make_pair(i, MessageData(props))).second;
}
-bool MessageMgr::SetMessageText(RenumMessageId i, RenumLanguageId lang, const std::string& text) {
+bool MessageMgr::SetMessageText(RenumMessageId i, RenumLanguageId lang, const std::string& text)
+{
msgid2data_map::iterator pos = msgDataMap.find(i);
- if(pos != msgDataMap.end()) {
+ if (pos != msgDataMap.end()) {
pos->second.SetText(lang, text);
return true;
}
return false;
}
-void MessageMgr::SetExtraText(RenumExtraTextId i, RenumLanguageId lang, const std::string& text) {
+void MessageMgr::SetExtraText(RenumExtraTextId i, RenumLanguageId lang, const std::string& text)
+{
extid2data_map::iterator pos = extraTextMap.find(i);
- if(pos == extraTextMap.end()) {
- pos = extraTextMap.insert(make_pair(i,lang2str_map())).first;
+ if (pos == extraTextMap.end()) {
+ pos = extraTextMap.insert(make_pair(i, lang2str_map())).first;
}
pos->second.insert(make_pair(lang, text));
}
@@ -139,8 +145,10 @@
#undef MESSAGE
#undef START_MESSAGES
#undef END_MESSAGES
-#define START_MESSAGES(lang) void MessageMgr::InitMessages() {
-#define MESSAGE(name,message,props) AddMessage(name, props);
+#define START_MESSAGES(lang) \
+ void MessageMgr::InitMessages() \
+ {
+#define MESSAGE(name, message, props) AddMessage(name, props);
#define END_MESSAGES() }
#include "lang/message_english.h"
@@ -151,9 +159,11 @@
#undef MESSAGE
#undef START_MESSAGES
#undef END_MESSAGES
-#define START_MESSAGES(lang) void InitMessageTexts_##lang(MessageMgr& msgmgr) { \
- RenumLanguageId langId = lang;
-#define MESSAGE(name,message,props) msgmgr.SetMessageText(name,langId, message);
+#define START_MESSAGES(lang) \
+ void InitMessageTexts_##lang(MessageMgr& msgmgr) \
+ { \
+ RenumLanguageId langId = lang;
+#define MESSAGE(name, message, props) msgmgr.SetMessageText(name, langId, message);
#define END_MESSAGES() }
#include "lang/all_messages.h"
@@ -164,8 +174,10 @@
#undef START_LANGUAGES
#undef RENUM_LANGUAGE
#undef END_LANGUAGES
-#define START_LANGUAGES() void MessageMgr::InitMessageTexts() {
-#define RENUM_LANGUAGE(name,code) InitMessageTexts_##name(*this);
+#define START_LANGUAGES() \
+ void MessageMgr::InitMessageTexts() \
+ {
+#define RENUM_LANGUAGE(name, code) InitMessageTexts_##name(*this);
#define END_LANGUAGES() }
#include "lang/language_list.h"
@@ -176,9 +188,11 @@
#undef EXTRA
#undef START_EXTRA_STRINGS
#undef END_EXTRA_STRINGS
-#define START_EXTRA_STRINGS(lang) void InitExtraTexts_##lang(MessageMgr& msgmgr) { \
- RenumLanguageId langId = lang;
-#define EXTRA(name,str) msgmgr.SetExtraText(name, langId, str);
+#define START_EXTRA_STRINGS(lang) \
+ void InitExtraTexts_##lang(MessageMgr& msgmgr) \
+ { \
+ RenumLanguageId langId = lang;
+#define EXTRA(name, str) msgmgr.SetExtraText(name, langId, str);
#define END_EXTRA_STRINGS() }
#include "lang/all_extra.h"
@@ -189,7 +203,9 @@
#undef START_LANGUAGES
#undef RENUM_LANGUAGE
#undef END_LANGUAGES
-#define START_LANGUAGES() void MessageMgr::InitExtraTexts() {
-#define RENUM_LANGUAGE(name,code) InitExtraTexts_##name(*this);
+#define START_LANGUAGES() \
+ void MessageMgr::InitExtraTexts() \
+ {
+#define RENUM_LANGUAGE(name, code) InitExtraTexts_##name(*this);
#define END_LANGUAGES() }
#include "lang/language_list.h"
diff --git a/src/message_mgr.h b/src/message_mgr.h
--- a/src/message_mgr.h
+++ b/src/message_mgr.h
@@ -27,139 +27,147 @@
#include <string>
#ifdef _MSC_VER
-#pragma warning (disable : 4702) // warning C4702: unreachable code
+#pragma warning(disable : 4702) // warning C4702: unreachable code
#endif
#include <map>
#ifdef _MSC_VER
-#pragma warning (default : 4702)
+#pragma warning(default : 4702)
#endif
#include "language_mgr.h"
#include "messages.h"
/*! Collection mapping language IDs to strings. */
-typedef std::map<RenumLanguageId,std::string> lang2str_map;
+typedef std::map<RenumLanguageId, std::string> lang2str_map;
/*! Encapsulates a NFORenum message. */
-class MessageData {
-public:
+class MessageData
+{
+ public:
/*! Creates a new instance of MessageData with the specified properties.
- \param props_ Initial properties of the message.
+ \param props_ Initial properties of the message.
*/
MessageData(char props_ = 0);
/*! Creates a new instance of MessageData with the specified properties
- and text in the default language.
- \param props_ Initial properties of the message.
- \param default_text Text of the message in the default language.
+ and text in the default language.
+ \param props_ Initial properties of the message.
+ \param default_text Text of the message in the default language.
*/
MessageData(char props_, const std::string& default_text);
/*! Check whether this message is meant for the console.
- \return true if the message is meant for the console.
+ \return true if the message is meant for the console.
*/
- bool IsConsoleMessage() const {
+ bool IsConsoleMessage() const
+ {
return !(props & NO_CONSOLE);
}
/*! Check whether this message is meant to make a comment.
- \return true if the message is supposed to make a comment.
+ \return true if the message is supposed to make a comment.
*/
- bool IsMakeComment() const {
+ bool IsMakeComment() const
+ {
return (props & MAKE_COMMENT);
}
/*! Output the message to the appropriate stream.
- \param prefix Message prefix
- \param ap Message parameter list
- \return The composed message
+ \param prefix Message prefix
+ \param ap Message parameter list
+ \return The composed message
*/
std::string Display(const std::string& prefix, std::va_list& ap) const;
/*! Get the text of this message in the current language.
- If the text is not available in the current language,
- get text in the default language. If even that fails
- return a fallback string.
- \return Text of the message, or MessageMgr::UNDEFINED_TEXT if not available.
+ If the text is not available in the current language,
+ get text in the default language. If even that fails
+ return a fallback string.
+ \return Text of the message, or MessageMgr::UNDEFINED_TEXT if not available.
*/
const std::string& GetText() const;
/*! Get the properties of this message.
- \return Message properties
+ \return Message properties
*/
- char GetProps() const { return props; }
+ char GetProps() const
+ {
+ return props;
+ }
/*! Set message text for the specified language.
- \param lang Language to set the text for
- \param text Text of the message
+ \param lang Language to set the text for
+ \param text Text of the message
*/
void SetText(RenumLanguageId lang, const std::string& text);
-private:
+ private:
/*! Renders the message in the current language with given optional prefix.
- \param prefix Optional message prefix
- \return Rendered message
+ \param prefix Optional message prefix
+ \return Rendered message
*/
std::string GetMessage(const std::string& prefix = "") const;
/*! A string inserted between comment delimiter and the beginning of a message. */
const static std::string commentPrefix;
lang2str_map textMap; /*!< Contains message texts for each language. */
- char props; /*!< Message properties */
+ char props; /*!< Message properties */
};
/*! Collection mapping message IDs to message data. */
-typedef std::map<RenumMessageId,MessageData> msgid2data_map;
+typedef std::map<RenumMessageId, MessageData> msgid2data_map;
/*! Collection mapping extra text IDs to extra text data. */
-typedef std::map<RenumExtraTextId,lang2str_map> extid2data_map;
+typedef std::map<RenumExtraTextId, lang2str_map> extid2data_map;
/*! Manages program messages and extra texts for various supported languages. */
-class MessageMgr {
+class MessageMgr
+{
SINGLETON(MessageMgr);
-public:
+
+ public:
const static MessageData UNKNOWN_MESSAGE; /*!< Fallback message data. */
- const static std::string UNDEFINED_TEXT; /*!< Fallback message text. */
+ const static std::string UNDEFINED_TEXT; /*!< Fallback message text. */
/*! Get the data for the specified message ID in the current language.
- \param i Message ID.
- \return Reference to message data for the given ID.
- If the ID is unknown, a reference to UNKNOWN_MESSAGE is returned.
+ \param i Message ID.
+ \return Reference to message data for the given ID.
+ If the ID is unknown, a reference to UNKNOWN_MESSAGE is returned.
*/
const MessageData& GetMessageData(RenumMessageId i) const;
/*! Get the data for the specified message ID in the current language.
- \param i Extra text ID.
- \return Extra text, or MessageMgr::UNDEFINED_TEXT if not available.
+ \param i Extra text ID.
+ \return Extra text, or MessageMgr::UNDEFINED_TEXT if not available.
*/
const std::string& GetExtraText(RenumExtraTextId i) const;
/*! Adds new message data for the specified message ID.
- \param i Message ID to add.
- \param props Properties of this message.
- \return true if successful.
- If message data for the speficied ID already exists,
- this function returns false.
+ \param i Message ID to add.
+ \param props Properties of this message.
+ \return true if successful.
+ If message data for the speficied ID already exists,
+ this function returns false.
*/
bool AddMessage(RenumMessageId i, char props);
/*! Sets the message text for the specified message ID and language.
- \param i Message ID
- \param lang Language this particular text is in
- \param text Text of the message
- \return true if successful. If no such message ID exists returns false.
+ \param i Message ID
+ \param lang Language this particular text is in
+ \param text Text of the message
+ \return true if successful. If no such message ID exists returns false.
*/
bool SetMessageText(RenumMessageId i, RenumLanguageId lang, const std::string& text);
/*! Set the extra text for the specifified extra text ID and language.
- \param i Extra text ID
- \param lang Language this particular text is in
- \param text The extra text
+ \param i Extra text ID
+ \param lang Language this particular text is in
+ \param text The extra text
*/
void SetExtraText(RenumExtraTextId i, RenumLanguageId lang, const std::string& text);
-private:
+ private:
/*! Initialize message data and properties. */
void InitMessages();
@@ -169,7 +177,7 @@
/*! Initialize extra text data for all supported languages. */
void InitExtraTexts();
- msgid2data_map msgDataMap; /*!< Message data for each message ID. */
+ msgid2data_map msgDataMap; /*!< Message data for each message ID. */
extid2data_map extraTextMap; /*!< Extra text data for each extra text ID. */
};
diff --git a/src/messages.cpp b/src/messages.cpp
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -20,10 +20,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<cstdarg>
-#include<string>
-#include<cassert>
-#include<cstdlib>
+#include <cstdarg>
+#include <string>
+#include <cassert>
+#include <cstdlib>
//#include<sstream>
using namespace std;
@@ -35,158 +35,179 @@
// #define YEARS "2004-2006"
// where <revision> is the current revision of the nforenum source
// Increment the 3.3.1 as necessary to agree with version.def
-#include"version.h"
-#include"nforenum.h"
-#include"inlines.h"
-#include"messages.h"
-#include"sanity_defines.h"
-#include"strings.h"
-#include"command.h"
+#include "version.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "messages.h"
+#include "sanity_defines.h"
+#include "strings.h"
+#include "command.h"
#include "message_mgr.h"
//#define MSG_ARRAYS_INCLUDE_TIMES 3
//#include"msg_arrays.h"
-static const char*STACK[]={NULL,"byte","word","textID","dword","date"};
+static const char* STACK[] = {NULL, "byte", "word", "textID", "dword", "date"};
static bool bAutoMessage;
-void AutoConsoleMessages(){
- bAutoMessage=true;
+void AutoConsoleMessages()
+{
+ bAutoMessage = true;
}
-void ManualConsoleMessages(){
- bAutoMessage=false;
+void ManualConsoleMessages()
+{
+ bAutoMessage = false;
}
-string mysprintf(const char*str,...){
+string mysprintf(const char* str, ...)
+{
WrapAp(str);
- return myvsprintf(str,ap);
+ return myvsprintf(str, ap);
}
#if defined DEBUG || defined _DEBUG
static RenumMessageId curMessage;
#endif
-string IssueMessage(int minSan,RenumMessageId id,...){
+string IssueMessage(int minSan, RenumMessageId id, ...)
+{
WrapAp(id);
- return vIssueMessage(minSan,id,ap);
+ return vIssueMessage(minSan, id, ap);
}
-string vIssueMessage(int minSan,RenumMessageId id,va_list& arg_ptr){
+string vIssueMessage(int minSan, RenumMessageId id, va_list& arg_ptr)
+{
#if defined DEBUG || defined _DEBUG
- curMessage=id;
+ curMessage = id;
#endif
/*if(minSan<0){
if(GetState(VERBOSE)<-minSan)return"";
- }else*/if(!GetWarn(id,minSan))return"";
- if(MessageMgr::Instance().GetMessageData(id).IsMakeComment() && GetState(DIFF)) return "";
+ }else*/ if (!GetWarn(id, minSan))
+ return "";
+ if (MessageMgr::Instance().GetMessageData(id).IsMakeComment() && GetState(DIFF)) return "";
RenumExtraTextId prefix = PREFIX_LINT_WARNING;
- switch(minSan){
- case-1:case-2:break;
+ switch (minSan) {
+ case -1:
+ case -2:
+ break;
case 0:
- prefix=PREFIX_UNPARSEABLE;
+ prefix = PREFIX_UNPARSEABLE;
break;
case FATAL:
case ERROR:
- prefix=minSan==FATAL?PREFIX_LINT_FATAL:PREFIX_LINT_ERROR;
+ prefix = minSan == FATAL ? PREFIX_LINT_FATAL : PREFIX_LINT_ERROR;
case WARNING1:
case WARNING2:
case WARNING3:
case WARNING4:
- if(MessageMgr::Instance().GetMessageData(id).IsConsoleMessage()&&bAutoMessage)
- IssueMessage(0,(RenumMessageId)(CONSOLE_LINT_WARNING-(minSan<WARNING1?WARNING1-minSan:0)),
- _spritenum,minSan-ERROR);
+ if (MessageMgr::Instance().GetMessageData(id).IsConsoleMessage() && bAutoMessage)
+ IssueMessage(0, (RenumMessageId)(CONSOLE_LINT_WARNING - (minSan < WARNING1 ? WARNING1 - minSan : 0)),
+ _spritenum, minSan - ERROR);
break;
- DEFAULT(minSan)
+ DEFAULT(minSan)
}
- if(MessageMgr::Instance().GetMessageData(id).IsMakeComment()){
- if(minSan==FATAL||minSan==ERROR)SetCode(EERROR);
- else if(minSan>=0)SetCode(EWARN);
+ if (MessageMgr::Instance().GetMessageData(id).IsMakeComment()) {
+ if (minSan == FATAL || minSan == ERROR)
+ SetCode(EERROR);
+ else if (minSan >= 0)
+ SetCode(EWARN);
}
- try{
- return MessageMgr::Instance().GetMessageData(id).Display(
- mysprintf(MessageMgr::Instance().GetExtraText(prefix).c_str(),id),arg_ptr);
- }catch(...){
- (*pErr)<<MessageMgr::Instance().GetMessageData(FATAL_MESSAGE_ERROR).GetText()<<id<<endl;
+ try
+ {
+ return MessageMgr::Instance().GetMessageData(id).Display(mysprintf(MessageMgr::Instance().GetExtraText(prefix).c_str(), id),
+ arg_ptr);
+ }
+ catch (...)
+ {
+ (*pErr) << MessageMgr::Instance().GetMessageData(FATAL_MESSAGE_ERROR).GetText() << id << endl;
assert(false);
exit(EFATAL);
}
}
-string myvsprintf(const char*fmt,va_list&arg_ptr){
+string myvsprintf(const char* fmt, va_list& arg_ptr)
+{
string ret;
- int i=-1,pad;
- while(fmt[++i]!='\0'){
- if(fmt[i]!='%')ret+=fmt[i];
- else{
- if(isdigit(fmt[++i]))i+=(int)itoa(pad=atoi(fmt+i)).length();
- else pad=0;
- switch(fmt[i]){
- case'c':
- ret+=(char)va_arg(arg_ptr,int);
- break;
- case'd':
- ret+=itoa(va_arg(arg_ptr,int),10,pad);
- break;
- case't': // If an EXTRA cannot be used (eg for __FILE__), use %t, not %s.
- ret+=(char*)va_arg(arg_ptr,char*);
- break;
- case's':{
- int x=(int)va_arg(arg_ptr,int);
- if(x>=__LAST_EXTRA){
+ int i = -1, pad;
+ while (fmt[++i] != '\0') {
+ if (fmt[i] != '%')
+ ret += fmt[i];
+ else {
+ if (isdigit(fmt[++i]))
+ i += (int)itoa(pad = atoi(fmt + i)).length();
+ else
+ pad = 0;
+ switch (fmt[i]) {
+ case 'c':
+ ret += (char)va_arg(arg_ptr, int);
+ break;
+ case 'd':
+ ret += itoa(va_arg(arg_ptr, int), 10, pad);
+ break;
+ case 't': // If an EXTRA cannot be used (eg for __FILE__), use %t, not %s.
+ ret += (char*)va_arg(arg_ptr, char*);
+ break;
+ case 's': {
+ int x = (int)va_arg(arg_ptr, int);
+ if (x >= __LAST_EXTRA) {
#if defined DEBUG || defined _DEBUG
- IssueMessage(0,BAD_STRING,x,curMessage,_spritenum);
+ IssueMessage(0, BAD_STRING, x, curMessage, _spritenum);
#else
- IssueMessage(0,BAD_STRING,x);
+ IssueMessage(0, BAD_STRING, x);
#endif
- assert(false);
- exit(EFATAL);
- }
- if(x!=-1)
- ret += MessageMgr::Instance().GetExtraText((RenumExtraTextId)x);
- break;
- }case'S':{
- int x=(int)va_arg(arg_ptr,int);
- if(x>=__LAST_EXTRA){
-#if defined DEBUG || defined _DEBUG
- IssueMessage(0,BAD_STRING,x,curMessage,_spritenum);
-#else
- IssueMessage(0,BAD_STRING,x);
-#endif
- assert(false);
- exit(EFATAL);
- }
- if(x!=-1)
- ret+=myvsprintf(MessageMgr::Instance().GetExtraText((RenumExtraTextId)x).c_str(),arg_ptr);
- break;
- }case'x':{
- uint val=va_arg(arg_ptr,int);
- if(pad&&!(pad&1)){
- while(pad||val){
- ret+=itoa(val&0xFF,16,2);
- val>>=8;
- if((pad?pad-=2:0)||val)ret+=' ';
+ assert(false);
+ exit(EFATAL);
}
+ if (x != -1) ret += MessageMgr::Instance().GetExtraText((RenumExtraTextId)x);
break;
}
- ret+=itoa(val,16);
- break;
- }case'L':{
- uint langID=va_arg(arg_ptr,int);
- ret+=mysprintf(GetLangName(langID).c_str(),langID);
- break;
- }case'K':
- ret+=STACK[va_arg(arg_ptr,int)];//_msgArrays[STACK].array[va_arg(arg_ptr,int)];
- break;
- /*case'Y':{
+ case 'S': {
+ int x = (int)va_arg(arg_ptr, int);
+ if (x >= __LAST_EXTRA) {
+#if defined DEBUG || defined _DEBUG
+ IssueMessage(0, BAD_STRING, x, curMessage, _spritenum);
+#else
+ IssueMessage(0, BAD_STRING, x);
+#endif
+ assert(false);
+ exit(EFATAL);
+ }
+ if (x != -1)
+ ret +=
+ myvsprintf(MessageMgr::Instance().GetExtraText((RenumExtraTextId)x).c_str(), arg_ptr);
+ break;
+ }
+ case 'x': {
+ uint val = va_arg(arg_ptr, int);
+ if (pad && !(pad & 1)) {
+ while (pad || val) {
+ ret += itoa(val & 0xFF, 16, 2);
+ val >>= 8;
+ if ((pad ? pad -= 2 : 0) || val) ret += ' ';
+ }
+ break;
+ }
+ ret += itoa(val, 16);
+ break;
+ }
+ case 'L': {
+ uint langID = va_arg(arg_ptr, int);
+ ret += mysprintf(GetLangName(langID).c_str(), langID);
+ break;
+ }
+ case 'K':
+ ret += STACK[va_arg(arg_ptr, int)]; //_msgArrays[STACK].array[va_arg(arg_ptr,int)];
+ break;
+ /*case'Y':{
uint array=va_arg(arg_ptr,uint),offset=va_arg(arg_ptr,uint);
VERIFY(array>=INVALID_MSG_ARRAY,vIssueMessage,array);
if(offset>=_msgArrays[array].length)offset=_msgArrays[array].length-1;
ret+=_msgArrays[array].array[offset];
break;
- }*/default:
- ret+=fmt[i];
+ }*/ default:
+ ret += fmt[i];
}
}
}
diff --git a/src/messages.h b/src/messages.h
--- a/src/messages.h
+++ b/src/messages.h
@@ -23,13 +23,13 @@
#ifndef _RENUM_MESSAGES_H_INCLUDED_
#define _RENUM_MESSAGES_H_INCLUDED_
-#include<cstdarg>
+#include <cstdarg>
// Message properties
-#define MAKE_COMMENT 1 //Indicates that the message should be prefixed with "//!!"
-#define USE_PREFIX 2 //Use the appropriate PREFIX_* string, as determined by the minSan argument to IssueMessage
-#define HAS_OFFSET 4 //Prefix "Offset %d"
-#define NO_CONSOLE 8 //Don't auto-send message to console
+#define MAKE_COMMENT 1 // Indicates that the message should be prefixed with "//!!"
+#define USE_PREFIX 2 // Use the appropriate PREFIX_* string, as determined by the minSan argument to IssueMessage
+#define HAS_OFFSET 4 // Prefix "Offset %d"
+#define NO_CONSOLE 8 // Don't auto-send message to console
// Message output stream
#define TO_ERROR 0
@@ -44,23 +44,25 @@
// Generate type RenumMessageId to be an enum of
// all the supported message IDs
#ifndef MESSAGE
-#define MESSAGE(name,message,props)name,
+#define MESSAGE(name, message, props) name,
#define START_MESSAGES(lang) typedef enum {
-#define END_MESSAGES() } RenumMessageId;
-#endif//MESSAGE
+#define END_MESSAGES() \
+ } \
+ RenumMessageId;
+#endif // MESSAGE
#ifndef ERR_MESSAGE
-#define ERR_MESSAGE(name,message,props) MESSAGE(name,message,NO_CONSOLE|props|TO_ERROR)
-#define OUT_MESSAGE(name,message,props) MESSAGE(name,message,NO_CONSOLE|props|TO_OUT)
-#define NFO_MESSAGE(name,message,props) MESSAGE(name,message,MAKE_COMMENT|props|TO_NFO)
+#define ERR_MESSAGE(name, message, props) MESSAGE(name, message, NO_CONSOLE | props | TO_ERROR)
+#define OUT_MESSAGE(name, message, props) MESSAGE(name, message, NO_CONSOLE | props | TO_OUT)
+#define NFO_MESSAGE(name, message, props) MESSAGE(name, message, MAKE_COMMENT | props | TO_NFO)
#endif
#ifndef MESSAGE_EX
-#define MESSAGE_EX(name,msg,props,loc,base) MESSAGE(name,msg,props|TO_##loc)
+#define MESSAGE_EX(name, msg, props, loc, base) MESSAGE(name, msg, props | TO_##loc)
#endif
#ifndef MESSAGE_UNUSED
-#define MESSAGE_UNUSED(name) MESSAGE(unused_##name,"",0)
+#define MESSAGE_UNUSED(name) MESSAGE(unused_##name, "", 0)
#endif
//#ifndef VMESSAGE // Verbose output messages
@@ -74,19 +76,22 @@
// Generate type RenumExtraTextId to be an enum of
// all the supported extra text IDs
#ifndef EXTRA
-#define EXTRA(name,str)name,
+#define EXTRA(name, str) name,
#define START_EXTRA_STRINGS(lang) typedef enum {
-#define END_EXTRA_STRINGS() __LAST_EXTRA} RenumExtraTextId;
-#endif //EXTRA
+#define END_EXTRA_STRINGS() \
+ __LAST_EXTRA \
+ } \
+ RenumExtraTextId;
+#endif // EXTRA
#include "lang/extra_english.h"
// -------
-std::string vIssueMessage(int,RenumMessageId,std::va_list&);
-std::string IssueMessage(int,RenumMessageId,...);
+std::string vIssueMessage(int, RenumMessageId, std::va_list&);
+std::string IssueMessage(int, RenumMessageId, ...);
void AutoConsoleMessages();
void ManualConsoleMessages();
-std::string mysprintf(const char*,...);
-std::string myvsprintf(const char*,std::va_list&);
+std::string mysprintf(const char*, ...);
+std::string myvsprintf(const char*, std::va_list&);
-#endif//_RENUM_MESSAGES_H_INCLUDED_
+#endif //_RENUM_MESSAGES_H_INCLUDED_
diff --git a/src/nforenum.cpp b/src/nforenum.cpp
--- a/src/nforenum.cpp
+++ b/src/nforenum.cpp
@@ -24,42 +24,42 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<iostream>
-#include<string>
-#include<sstream>
-#include<iomanip>
-#include<fstream>
-#include<cerrno>
-#include<cassert>
-#include<cstdlib>
-#include<getopt.h>
-#include<set>
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <fstream>
+#include <cerrno>
+#include <cassert>
+#include <cstdlib>
+#include <getopt.h>
+#include <set>
#ifdef MINGW
- #include <io.h>
- #define isatty _isatty
+#include <io.h>
+#define isatty _isatty
#elif defined(_MSC_VER)
- #include <io.h>
- #include <direct.h>
- #define F_OK 0
- #define isatty _isatty
+#include <io.h>
+#include <direct.h>
+#define F_OK 0
+#define isatty _isatty
#else
- #include <unistd.h>
-#endif//_MSC_VER
+#include <unistd.h>
+#endif //_MSC_VER
using namespace std;
-#include"getopt.h"
-#include"globals.h"
-#include"inlines.h"
-#include"sanity.h"
-#include"command.h"
-#include"messages.h"
-#include"inject.h"
-#include"pseudo.h"
-#include"help.h"
+#include "getopt.h"
+#include "globals.h"
+#include "inlines.h"
+#include "sanity.h"
+#include "command.h"
+#include "messages.h"
+#include "inject.h"
+#include "pseudo.h"
+#include "help.h"
#ifdef _WIN32
-# include "win32.h"
+#include "win32.h"
#endif
#include "mapescapes.h"
@@ -68,162 +68,186 @@
nfe_map nfo_escapes;
#ifndef _MSC_VER
-//Cygwin's GCC #defines __cdecl, but other GCCs do not
+// Cygwin's GCC #defines __cdecl, but other GCCs do not
//#undef it to prevent GCC from warning on the #define,
-//then #define it to prevent errors on main's definition.
+// then #define it to prevent errors on main's definition.
#undef __cdecl
#define __cdecl
#endif
-struct RealSpriteFormat{
+struct RealSpriteFormat
+{
bool bpp32;
int zoom;
- bool operator<(const RealSpriteFormat&other)const{
- return bpp32==other.bpp32?zoom<other.zoom:other.bpp32;
+ bool operator<(const RealSpriteFormat &other) const
+ {
+ return bpp32 == other.bpp32 ? zoom < other.zoom : other.bpp32;
}
};
-struct RealSpriteState {
+struct RealSpriteState
+{
std::set<RealSpriteFormat> present;
bool mask_allowed;
- void Reset(){
+ void Reset()
+ {
present.clear();
mask_allowed = false;
}
};
-int process_file(istream&);
-void output_buffer(const string&,bool,int);
-bool verify_real(string&,RealSpriteState&);
+int process_file(istream &);
+void output_buffer(const string &, bool, int);
+bool verify_real(string &, RealSpriteState &);
-static int _retval=EOK;
-static int _force=0;
+static int _retval = EOK;
+static int _force = 0;
bool _interactive;
-void SetCode(int x){_retval=max(_retval,x);}
-void doexit(){exit(_retval);}
+void SetCode(int x)
+{
+ _retval = max(_retval, x);
+}
+void doexit()
+{
+ exit(_retval);
+}
-//The VS project file specifies __stdcall as the default convention,
-//so main must be explicitly __cdecl'd
-int __cdecl main(const int argc,char**argv){
- string infilename,outfilename,bakfilename,basename;
- int result,longind,opt=0,replace=1;
- static const option optlist[]={
- /* Command-line only options */
- {"auto-correct",no_argument,NULL,'a'},
- {"comments",required_argument,NULL,'c'},
- {"data",optional_argument,NULL,'D'},
- {"force",no_argument,&_force,1},
- {"help",no_argument,NULL,'h'},
- {"keep-old",no_argument,&replace,0},
- {"lock",no_argument,NULL,256},
- {"no-replace",no_argument,&replace,0},
- {"silent",no_argument,NULL,'s'},
- {"version",no_argument,NULL,'v'},
- {"write-data",no_argument,NULL,257},
+// The VS project file specifies __stdcall as the default convention,
+// so main must be explicitly __cdecl'd
+int __cdecl main(const int argc, char **argv)
+{
+ string infilename, outfilename, bakfilename, basename;
+ int result, longind, opt = 0, replace = 1;
+ static const option optlist[] = {
+ /* Command-line only options */
+ {"auto-correct", no_argument, NULL, 'a'},
+ {"comments", required_argument, NULL, 'c'},
+ {"data", optional_argument, NULL, 'D'},
+ {"force", no_argument, &_force, 1},
+ {"help", no_argument, NULL, 'h'},
+ {"keep-old", no_argument, &replace, 0},
+ {"lock", no_argument, NULL, 256},
+ {"no-replace", no_argument, &replace, 0},
+ {"silent", no_argument, NULL, 's'},
+ {"version", no_argument, NULL, 'v'},
+ {"write-data", no_argument, NULL, 257},
- /* Switches also available via @@ in the .nfo */
- {"beautify",required_argument,NULL,'b'},
- {"diff",no_argument,NULL,'d'},
- {"extentions",required_argument,NULL,'e'}, // used to enable non-official nfo features. currently none.
- {"let",required_argument,NULL,'L'},
- {"lint",optional_argument,NULL,'l'},
- {"preserve-messages",no_argument,NULL,'P'},
- {"real-sprites",required_argument,NULL,'r'},
- {"use-old-nums",required_argument,NULL,'o'},
- {"warning-disable",required_argument,NULL,'w'},
- {"warning-enable",required_argument,NULL,'W'},
- {NULL,0,0,0}
- };
+ /* Switches also available via @@ in the .nfo */
+ {"beautify", required_argument, NULL, 'b'},
+ {"diff", no_argument, NULL, 'd'},
+ {"extentions", required_argument, NULL, 'e'}, // used to enable non-official nfo features. currently none.
+ {"let", required_argument, NULL, 'L'},
+ {"lint", optional_argument, NULL, 'l'},
+ {"preserve-messages", no_argument, NULL, 'P'},
+ {"real-sprites", required_argument, NULL, 'r'},
+ {"use-old-nums", required_argument, NULL, 'o'},
+ {"warning-disable", required_argument, NULL, 'w'},
+ {"warning-enable", required_argument, NULL, 'W'},
+ {NULL, 0, 0, 0}};
_interactive = (isatty(fileno(stdout)) != 0);
bool seen_startup_message = false;
- pOut=argc==1?&cerr:&cout;
+ pOut = argc == 1 ? &cerr : &cout;
ifstream fin;
ofstream fout;
- while(argc>1){
- if(opt!=EOF)opt=getopt_long(argc,argv,"ac:D::fhksv" "b:de:L:l:pr:o:w:W:",optlist,&longind);
- switch(opt){
- case 0:continue;
- case 257: /* --write-data */
- for (int i = 0; i < FILES_MAX; i++) {
- FILE *pFile = _myfopen((files)i, true);
- fclose(pFile);
- }
- continue;
- case 's':
- _interactive = false;
- continue;
- case 'v':
- IssueMessage(0,STARTUP);
- return 0;
- case'D':
- if(optarg)datadir=optarg;
- dosleep=false;
- continue;
- case'k':replace=0;continue;
- case'c':
- switch(*optarg){
- case'#':COMMENT_PREFIX="#";break;
- case';':COMMENT_PREFIX=";";break;
- case'/':COMMENT_PREFIX="//";
- }
- continue;
- case'h':
- IssueMessage(0,STARTUP);
- ShowHelp();
- return 0;
- case'f':_force=1;continue;
- case'a':
- _autocorrect++;
- if(!GetState(BEAUTIFY)){
- optarg=(char*)"convertonly+";
- CLCommand('b');
- }
- continue;
- case EOF:
- if(optind==argc)doexit();
- basename=argv[optind++];break;
- case '?':
- ShowHelp();
- exit(1);
- default:
- if(!CLCommand(opt))
- IssueMessage(0,BAD_CL_ARG,opt,optarg);
- continue;
+ while (argc > 1) {
+ if (opt != EOF)
+ opt = getopt_long(argc, argv,
+ "ac:D::fhksv"
+ "b:de:L:l:pr:o:w:W:",
+ optlist, &longind);
+ switch (opt) {
+ case 0:
+ continue;
+ case 257: /* --write-data */
+ for (int i = 0; i < FILES_MAX; i++) {
+ FILE *pFile = _myfopen((files)i, true);
+ fclose(pFile);
+ }
+ continue;
+ case 's':
+ _interactive = false;
+ continue;
+ case 'v':
+ IssueMessage(0, STARTUP);
+ return 0;
+ case 'D':
+ if (optarg) datadir = optarg;
+ dosleep = false;
+ continue;
+ case 'k':
+ replace = 0;
+ continue;
+ case 'c':
+ switch (*optarg) {
+ case '#':
+ COMMENT_PREFIX = "#";
+ break;
+ case ';':
+ COMMENT_PREFIX = ";";
+ break;
+ case '/':
+ COMMENT_PREFIX = "//";
+ }
+ continue;
+ case 'h':
+ IssueMessage(0, STARTUP);
+ ShowHelp();
+ return 0;
+ case 'f':
+ _force = 1;
+ continue;
+ case 'a':
+ _autocorrect++;
+ if (!GetState(BEAUTIFY)) {
+ optarg = (char *)"convertonly+";
+ CLCommand('b');
+ }
+ continue;
+ case EOF:
+ if (optind == argc) doexit();
+ basename = argv[optind++];
+ break;
+ case '?':
+ ShowHelp();
+ exit(1);
+ default:
+ if (!CLCommand(opt)) IssueMessage(0, BAD_CL_ARG, opt, optarg);
+ continue;
}
if (!seen_startup_message && _interactive) {
seen_startup_message = true;
- IssueMessage(0,STARTUP);
+ IssueMessage(0, STARTUP);
}
- pNfo=&fout;
- bakfilename=basename+bak_ext;
- fin.open((infilename=basename).c_str());
- if(!fin.is_open()){
- fin.open((infilename=basename+nfo_ext).c_str());
- bakfilename=basename+nfo_ext+bak_ext;
+ pNfo = &fout;
+ bakfilename = basename + bak_ext;
+ fin.open((infilename = basename).c_str());
+ if (!fin.is_open()) {
+ fin.open((infilename = basename + nfo_ext).c_str());
+ bakfilename = basename + nfo_ext + bak_ext;
}
- if(fin.is_open()){
- fout.open((outfilename=(replace?basename+new_ext:basename+new_ext+nfo_ext)).c_str());
- }else{
- bakfilename=dirname+(basename+bak_ext);
- fin.open((infilename=dirname+basename).c_str());
- if(!fin.is_open()){
- bakfilename=dirname+(basename+nfo_ext+bak_ext);
- fin.open((infilename=dirname+basename+nfo_ext).c_str());
+ if (fin.is_open()) {
+ fout.open((outfilename = (replace ? basename + new_ext : basename + new_ext + nfo_ext)).c_str());
+ } else {
+ bakfilename = dirname + (basename + bak_ext);
+ fin.open((infilename = dirname + basename).c_str());
+ if (!fin.is_open()) {
+ bakfilename = dirname + (basename + nfo_ext + bak_ext);
+ fin.open((infilename = dirname + basename + nfo_ext).c_str());
}
- if(fin.is_open()){
- fout.open((outfilename=dirname+(replace?basename+new_ext:basename+new_ext+nfo_ext)).c_str());
- }else{
- IssueMessage(0,NO_INPUT_FILE,basename.c_str());
+ if (fin.is_open()) {
+ fout.open((outfilename = dirname + (replace ? basename + new_ext : basename + new_ext + nfo_ext)).c_str());
+ } else {
+ IssueMessage(0, NO_INPUT_FILE, basename.c_str());
SetCode(EFILE);
continue;
}
}
- if(!fout.is_open()){
- IssueMessage(0,NO_OUTPUT_FILE,outfilename.c_str(),basename.c_str());
+ if (!fout.is_open()) {
+ IssueMessage(0, NO_OUTPUT_FILE, outfilename.c_str(), basename.c_str());
SetCode(EFILE);
fin.close();
fout.clear();
@@ -232,281 +256,279 @@
fin.clear();
reset_sanity();
reset_commands();
- _grfver=_act14_pal=0;
- if (_interactive) IssueMessage(0,PROCESSING_FILE,basename.c_str());
- result=process_file(fin);
+ _grfver = _act14_pal = 0;
+ if (_interactive) IssueMessage(0, PROCESSING_FILE, basename.c_str());
+ result = process_file(fin);
fin.close();
fout.close();
- if(result){
+ if (result) {
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
-// unlink is deprecated in MSVS 8.0+
+ // unlink is deprecated in MSVS 8.0+
_unlink(outfilename.c_str());
#else
unlink(outfilename.c_str());
#endif
- }else if(replace){
- if(rename(infilename.c_str(),bakfilename.c_str())&&errno==EEXIST){
+ } else if (replace) {
+ if (rename(infilename.c_str(), bakfilename.c_str()) && errno == EEXIST) {
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
-// unlink is deprecated in MSVS 8.0+
- if(_unlink(infilename.c_str()))
+ // unlink is deprecated in MSVS 8.0+
+ if (_unlink(infilename.c_str()))
#else
- if(unlink(infilename.c_str()))
+ if (unlink(infilename.c_str()))
#endif
{
- IssueMessage(0,DELETE_FAILED,infilename.c_str(),errno);
+ IssueMessage(0, DELETE_FAILED, infilename.c_str(), errno);
perror(NULL);
SetCode(EFILE);
}
}
- if(rename(outfilename.c_str(),infilename.c_str())){
- IssueMessage(0,REPLACE_FAILED,infilename.c_str(),outfilename.c_str(),errno);
+ if (rename(outfilename.c_str(), infilename.c_str())) {
+ IssueMessage(0, REPLACE_FAILED, infilename.c_str(), outfilename.c_str(), errno);
perror(NULL);
SetCode(EFILE);
}
}
- if (_interactive) IssueMessage(0,PROCESSING_COMPLETE);
+ if (_interactive) IssueMessage(0, PROCESSING_COMPLETE);
}
- pNfo=&cout;
- IssueMessage(0,PROCESSING);
+ pNfo = &cout;
+ IssueMessage(0, PROCESSING);
process_file(cin);
- IssueMessage(0,PROCESSING_COMPLETE);
+ IssueMessage(0, PROCESSING_COMPLETE);
return _retval;
}
-#define flush_buffer()\
- if(true) {\
- if(buffer!="") {\
- output_buffer(buffer,isPatch,oldspritenum);\
- buffer="";\
- }\
- oldspritenum=temp;\
- } else\
- (void(0))
+#define flush_buffer() \
+ if (true) { \
+ if (buffer != "") { \
+ output_buffer(buffer, isPatch, oldspritenum); \
+ buffer = ""; \
+ } \
+ oldspritenum = temp; \
+ } else \
+ (void(0))
-#define SetVersion(x)\
- (NFOversion=max((x),NFOversion))
+#define SetVersion(x) (NFOversion = max((x), NFOversion))
static bool hasHeader;
int NFOversion;
-bool TrySetVersion(int x){
- if(hasHeader&&NFOversion>=x)return true;
- if(hasHeader&&NFOversion<=6&&x>=7)return false;
+bool TrySetVersion(int x)
+{
+ if (hasHeader && NFOversion >= x) return true;
+ if (hasHeader && NFOversion <= 6 && x >= 7) return false;
SetVersion(x);
return true;
}
-string smash(const string&,int&);
+string smash(const string &, int &);
-int process_file(istream&in){
- NFOversion=4;
- string sprite,datapart,buffer;
+int process_file(istream &in)
+{
+ NFOversion = 4;
+ string sprite, datapart, buffer;
inject_into(in);
nfo_escapes.clear();
vector<string> extra_lines;
- if(string(" \t\n*0123456789/;#*").find((char)in.peek())==NPOS){
- IssueMessage(0,APPARENTLY_NOT_NFO);
- if(!_force){
- IssueMessage(0,SKIPPING_FILE);
+ if (string(" \t\n*0123456789/;#*").find((char)in.peek()) == NPOS) {
+ IssueMessage(0, APPARENTLY_NOT_NFO);
+ if (!_force) {
+ IssueMessage(0, SKIPPING_FILE);
SetCode(EPARSE);
- return-1;
+ return -1;
}
}
-//This section is a rewrite of lines 35-50 or thereabouts of info.cc
-//from grfcodec: http://www.ttdpatch.net/grfcodec
-//grfcodec is Copyright 2000-2003 Josef Drexler
- getline(in,sprite);//Info header or first sprite
- hasHeader=false;
- if (sprite.substr(0,3)=="// "){
- hasHeader=true;
- getline(in,sprite);//Info version (first sprite for ancient NFO versions)
- if(sscanf(sprite.c_str(),"// (Info version %d)",&NFOversion)){
- if((NFOversion<4||NFOversion>7)&&NFOversion!=32){
- IssueMessage(0,UNKNOWN_VERSION,NFOversion);
- if(NFOversion>7){
- IssueMessage(0,SKIPPING_FILE);
+ // This section is a rewrite of lines 35-50 or thereabouts of info.cc
+ // from grfcodec: http://www.ttdpatch.net/grfcodec
+ // grfcodec is Copyright 2000-2003 Josef Drexler
+ getline(in, sprite); // Info header or first sprite
+ hasHeader = false;
+ if (sprite.substr(0, 3) == "// ") {
+ hasHeader = true;
+ getline(in, sprite); // Info version (first sprite for ancient NFO versions)
+ if (sscanf(sprite.c_str(), "// (Info version %d)", &NFOversion)) {
+ if ((NFOversion < 4 || NFOversion > 7) && NFOversion != 32) {
+ IssueMessage(0, UNKNOWN_VERSION, NFOversion);
+ if (NFOversion > 7) {
+ IssueMessage(0, SKIPPING_FILE);
SetCode(EPARSE);
- return-1;
+ return -1;
}
- IssueMessage(0,PARSING_FILE);
+ IssueMessage(0, PARSING_FILE);
}
- if(NFOversion>2)
- getline(in,sprite);//Format line
- if (NFOversion>6) {
+ if (NFOversion > 2) getline(in, sprite); // Format line
+ if (NFOversion > 6) {
while (strncmp(sprite.c_str(), "// Format: ", 11)) {
- if (!strncmp(sprite.c_str(), "// Escapes: ", 12)) { // Actually, that was an escapes line. Read it.
+ if (!strncmp(sprite.c_str(), "// Escapes: ", 12)) { // Actually, that was an escapes line. Read it.
istringstream esc(sprite);
string str;
int byte = 0;
esc.ignore(12);
- while (esc>>str)
- if (str == "=") byte--;
+ while (esc >> str)
+ if (str == "=")
+ byte--;
else if (str[0] == '@')
- byte = strtol(str.c_str()+1,NULL,16);
- else nfo_escapes.insert(nfe_pair(str, byte++));
- } else if (strncmp(sprite.c_str(), "// ",3)) { // EEEP! No "Format:" line in this file!
+ byte = strtol(str.c_str() + 1, NULL, 16);
+ else
+ nfo_escapes.insert(nfe_pair(str, byte++));
+ } else if (strncmp(sprite.c_str(), "// ", 3)) { // EEEP! No "Format:" line in this file!
IssueMessage(0, APPARENTLY_NOT_NFO);
SetCode(EPARSE);
return -1;
- } else extra_lines.push_back(sprite); // store unknown lines
+ } else
+ extra_lines.push_back(sprite); // store unknown lines
- getline(in,sprite); // Try again to skip "Format: " line
+ getline(in, sprite); // Try again to skip "Format: " line
}
// Now remove all defaults. This serves two purposes:
// 1) Prevent incorrectly specified defaults from causing problems later.
// 2) Allow the beautifier to select custom escapes over built-ins.
- foreach(const esc& e, escapes)
- nfo_escapes.left.erase(e.str+1);
+ foreach(const esc & e, escapes)
+ nfo_escapes.left.erase(e.str + 1);
}
- }else{
- IssueMessage(0,UNKNOWN_VERSION,1);
- IssueMessage(0,PARSING_FILE);
+ } else {
+ IssueMessage(0, UNKNOWN_VERSION, 1);
+ IssueMessage(0, PARSING_FILE);
}
- getline(in,sprite);//first sprite
+ getline(in, sprite); // first sprite
}
-
- int temp=-1,size,oldspritenum=-1;
- _spritenum=(unsigned)-1;
+ int temp = -1, size, oldspritenum = -1;
+ _spritenum = (unsigned)-1;
RealSpriteState realsprite_state;
string::size_type firstnotpseudo;
- bool isPatch=false;
+ bool isPatch = false;
ostringstream outbuffer;
- ostream*real_out=pNfo;
- pNfo=&outbuffer;
+ ostream *real_out = pNfo;
+ pNfo = &outbuffer;
SetVersion(4);
AutoConsoleMessages();
- while(true){
- //IssueMessage(0,SPRITE,spritenum+1,sprite.c_str());
+ while (true) {
+ // IssueMessage(0,SPRITE,spritenum+1,sprite.c_str());
istringstream spritestream(sprite);
eat_white(spritestream);
- if(spritestream.peek()==EOF) {
- buffer+='\n';
- } else if(is_comment(spritestream)){
- if(is_command(sprite)) {
+ if (spritestream.peek() == EOF) {
+ buffer += '\n';
+ } else if (is_comment(spritestream)) {
+ if (is_command(sprite)) {
flush_buffer();
- }
- if(parse_comment(sprite)) {
- buffer+=sprite+'\n';
- }
- } else {//sprite
- if(!eat_white(spritestream>>temp)){
+ }
+ if (parse_comment(sprite)) {
+ buffer += sprite + '\n';
+ }
+ } else { // sprite
+ if (!eat_white(spritestream >> temp)) {
spritestream.clear();
- temp=-1;
+ temp = -1;
}
- if(spritestream.peek()=='*'){
+ if (spritestream.peek() == '*') {
realsprite_state.Reset();
- if(spritestream.ignore().peek()=='*'){
+ if (spritestream.ignore().peek() == '*') {
SetVersion(6);
- getline(eat_white(spritestream.ignore()),datapart);
+ getline(eat_white(spritestream.ignore()), datapart);
flush_buffer();
- if(isPatch) {
+ if (isPatch) {
check_sprite(INCLUDE);
} else {
- IssueMessage(ERROR,UNEXPECTED,BIN_INCLUDE);
+ IssueMessage(ERROR, UNEXPECTED, BIN_INCLUDE);
}
_spritenum++;
- (*pNfo)<<setw(5)<<spritenum()<<" **\t "<<datapart<<'\n';
- }else{
- (spritestream>>size).clear();
+ (*pNfo) << setw(5) << spritenum() << " **\t " << datapart << '\n';
+ } else {
+ (spritestream >> size).clear();
eat_white(spritestream);
flush_buffer();
- if(_spritenum==(uint)-1){
- isPatch=true;
- if(size!=4 && size!=0)
- outbuffer<<COMMENT_PREFIX<<sprite<<endl;
- _spritenum=0;
- }else{
- getline(spritestream,buffer);
- buffer+='\n';
+ if (_spritenum == (uint) - 1) {
+ isPatch = true;
+ if (size != 4 && size != 0) outbuffer << COMMENT_PREFIX << sprite << endl;
+ _spritenum = 0;
+ } else {
+ getline(spritestream, buffer);
+ buffer += '\n';
}
}
- }else if(NFOversion>=32&&spritestream.peek()=='|'){
+ } else if (NFOversion >= 32 && spritestream.peek() == '|') {
eat_white(spritestream.ignore());
- getline(spritestream,datapart);
- if(realsprite_state.present.empty()){
- IssueMessage(0,NOT_IN_REALSPRITE,_spritenum+1);
- buffer+="//"+sprite+'\n';
- }else{
- if(verify_real(datapart,realsprite_state)){
+ getline(spritestream, datapart);
+ if (realsprite_state.present.empty()) {
+ IssueMessage(0, NOT_IN_REALSPRITE, _spritenum + 1);
+ buffer += "//" + sprite + '\n';
+ } else {
+ if (verify_real(datapart, realsprite_state)) {
flush_buffer();
- (*pNfo)<<" | "<<datapart<<endl;
- }else{
- buffer+="//"+sprite+'\n';
+ (*pNfo) << " | " << datapart << endl;
+ } else {
+ buffer += "//" + sprite + '\n';
SetCode(EPARSE);
- IssueMessage(0,PARTIAL_PARSE_FAILURE,_spritenum);
+ IssueMessage(0, PARTIAL_PARSE_FAILURE, _spritenum);
}
}
- }else{
- getline(spritestream,datapart);
- firstnotpseudo=datapart.find_first_not_of(VALID_PSEUDO);
- if(!spritestream || firstnotpseudo==NPOS
- || datapart[firstnotpseudo]=='"'
- || (datapart[firstnotpseudo]=='\\'?TrySetVersion(7):false)
- || is_comment(datapart,firstnotpseudo)) {
- if(PseudoSprite::MayBeSprite(buffer)) {
- buffer+=sprite+'\n';
+ } else {
+ getline(spritestream, datapart);
+ firstnotpseudo = datapart.find_first_not_of(VALID_PSEUDO);
+ if (!spritestream || firstnotpseudo == NPOS || datapart[firstnotpseudo] == '"' ||
+ (datapart[firstnotpseudo] == '\\' ? TrySetVersion(7) : false) || is_comment(datapart, firstnotpseudo)) {
+ if (PseudoSprite::MayBeSprite(buffer)) {
+ buffer += sprite + '\n';
} else {
- IssueMessage(0,NOT_IN_SPRITE,_spritenum+1);
- buffer+="//"+sprite+'\n';
+ IssueMessage(0, NOT_IN_SPRITE, _spritenum + 1);
+ buffer += "//" + sprite + '\n';
}
- }else{
+ } else {
_spritenum++;
realsprite_state.Reset();
- if(verify_real(datapart,realsprite_state)){
+ if (verify_real(datapart, realsprite_state)) {
_spritenum--;
flush_buffer();
_spritenum++;
- if(isPatch)check_sprite(REAL);
- (*pNfo)<<setw(5)<<spritenum()<<' '<<datapart<<endl;
- }else{
- buffer+="//"+sprite+'\n';
+ if (isPatch) check_sprite(REAL);
+ (*pNfo) << setw(5) << spritenum() << ' ' << datapart << endl;
+ } else {
+ buffer += "//" + sprite + '\n';
SetCode(EPARSE);
- IssueMessage(0,PARTIAL_PARSE_FAILURE,_spritenum--);
+ IssueMessage(0, PARTIAL_PARSE_FAILURE, _spritenum--);
}
}
}
}
- if(peek(in)==EOF){
+ if (peek(in) == EOF) {
flush_buffer();
- (*real_out)<<NFO_HEADER(NFOversion);
+ (*real_out) << NFO_HEADER(NFOversion);
if (NFOversion > 6) {
- // (re)insert default escapes
- foreach(const esc& e, escapes)
- nfo_escapes.insert(nfe_pair(e.str+1, e.byte));
- (*real_out)<<"// Escapes:";
- int oldbyte = -1;
+ // (re)insert default escapes
+ foreach(const esc & e, escapes)
+ nfo_escapes.insert(nfe_pair(e.str + 1, e.byte));
+ (*real_out) << "// Escapes:";
+ int oldbyte = -1;
- for (int act = 0; act < 255; act++) {
- foreach (const nfe_rpair& p, nfo_escapes.right) {
- if (p.second[0] != act) continue;
+ for (int act = 0; act < 255; act++) {
+ foreach(const nfe_rpair & p, nfo_escapes.right)
+ {
+ if (p.second[0] != act) continue;
- if (p.first == oldbyte) {
- (*real_out)<<" =";
- --oldbyte;
- } else if (p.first < oldbyte) {
- (*real_out)<<"\n// Escapes:";
- oldbyte = -1;
- }
- while (++oldbyte != p.first)
- (*real_out)<<" "<<nfo_escapes.right.begin()->second;
- (*real_out)<<" "<<p.second;
+ if (p.first == oldbyte) {
+ (*real_out) << " =";
+ --oldbyte;
+ } else if (p.first < oldbyte) {
+ (*real_out) << "\n// Escapes:";
+ oldbyte = -1;
}
+ while (++oldbyte != p.first) (*real_out) << " " << nfo_escapes.right.begin()->second;
+ (*real_out) << " " << p.second;
}
- (*real_out)<<"\n";
- for (uint i=0; i<extra_lines.size(); i++)
- (*real_out)<<extra_lines[i]<<"\n";
+ }
+ (*real_out) << "\n";
+ for (uint i = 0; i < extra_lines.size(); i++) (*real_out) << extra_lines[i] << "\n";
}
- (*real_out)<<NFO_FORMAT(NFOversion);
- if(isPatch)(*real_out)<<" 0 * 4\t "<<mysprintf("%8x\n",GetState(DIFF)?0:_spritenum);
- (*real_out)<<outbuffer.str();
- pNfo=real_out;
+ (*real_out) << NFO_FORMAT(NFOversion);
+ if (isPatch) (*real_out) << " 0 * 4\t " << mysprintf("%8x\n", GetState(DIFF) ? 0 : _spritenum);
+ (*real_out) << outbuffer.str();
+ pNfo = real_out;
final_sanity();
return 0;
}
- inj_getline(in,sprite);
+ inj_getline(in, sprite);
}
}
@@ -520,7 +542,7 @@
* from \a input. E.g. because of parsing an RPN expression.
* @return true on error
*/
-static bool extract_string(string&input,string&token,string&processed,bool&)
+static bool extract_string(string &input, string &token, string &processed, bool &)
{
const char *start = input.c_str();
const char *pos = start;
@@ -553,18 +575,18 @@
* from \a input. E.g. because of parsing an RPN expression.
* @return true on error
*/
-static bool extract_int(string&input,int&token,string&processed,bool&anyprocessing)
+static bool extract_int(string &input, int &token, string &processed, bool &anyprocessing)
{
const char *start = input.c_str();
const char *pos = start;
while (isspace(*pos)) pos++;
const char *end = NULL;
- token = strtol(pos, const_cast<char**>(&end), 10);
+ token = strtol(pos, const_cast<char **>(&end), 10);
if (pos == end) {
- if(RPNOFF()||*pos!='(') return true;
+ if (RPNOFF() || *pos != '(') return true;
size_t offs = pos - start;
- token = DoCalc(input,offs);
- if(offs==NPOS) return true;
+ token = DoCalc(input, offs);
+ if (offs == NPOS) return true;
anyprocessing = true;
input.erase(0, offs);
processed.append(mysprintf(" %d", token));
@@ -586,13 +608,13 @@
* from \a input. E.g. because of parsing an RPN expression.
* @return true on error
*/
-static bool extract_hex(string&input,int&token,string&processed,bool&)
+static bool extract_hex(string &input, int &token, string &processed, bool &)
{
const char *start = input.c_str();
const char *pos = start;
while (isspace(*pos)) pos++;
const char *end = NULL;
- token = strtol(pos, const_cast<char**>(&end), 16);
+ token = strtol(pos, const_cast<char **>(&end), 16);
if (pos == end) return true;
size_t count = end - start;
processed.append(input, 0, count);
@@ -600,143 +622,233 @@
return false;
}
-bool verify_real(string&data,RealSpriteState&formats){
- string::size_type loc=NPOS;
- string udata=UCase(data);
- while(true){
- loc=udata.find(".PCX",loc+1);
- if(loc==NPOS)
- loc = udata.find(".PNG",loc+1);
- if(loc==NPOS){
- IssueMessage(0,REAL_NO_FILENAME);
+bool verify_real(string &data, RealSpriteState &formats)
+{
+ string::size_type loc = NPOS;
+ string udata = UCase(data);
+ while (true) {
+ loc = udata.find(".PCX", loc + 1);
+ if (loc == NPOS) loc = udata.find(".PNG", loc + 1);
+ if (loc == NPOS) {
+ IssueMessage(0, REAL_NO_FILENAME);
return false;
}
- if(isspace(data[loc+4]))break;
+ if (isspace(data[loc + 4])) break;
}
- string name=data.substr(0,loc+4);
+ string name = data.substr(0, loc + 4);
- if(NFOversion>=32){
+ if (NFOversion >= 32) {
string depth;
int xpos, ypos, xsize, ysize, xrel, yrel, zoom;
- string meta=data.substr(loc+5);
+ string meta = data.substr(loc + 5);
string processed;
bool anyprocessing = false;
- if (extract_string(meta,depth,processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"depth"); return COMMENTOFF(); }
- if (depth=="mask"){
+ if (extract_string(meta, depth, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "depth");
+ return COMMENTOFF();
+ }
+ if (depth == "mask") {
if (!formats.mask_allowed) {
- IssueMessage(0,REAL_32BPP_BEFORE_MASK); return COMMENTOFF();
+ IssueMessage(0, REAL_32BPP_BEFORE_MASK);
+ return COMMENTOFF();
}
formats.mask_allowed = false;
- if (extract_int(meta,xpos, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xpos"); return COMMENTOFF(); }
- if (extract_int(meta,ypos, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"ypos"); return COMMENTOFF(); }
+ if (extract_int(meta, xpos, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "xpos");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, ypos, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "ypos");
+ return COMMENTOFF();
+ }
- if(xpos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XPOS,0);
- if(ypos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YPOS,0);
+ if (xpos < 0) IssueMessage(ERROR, REAL_VAL_TOO_SMALL, XPOS, 0);
+ if (ypos < 0) IssueMessage(ERROR, REAL_VAL_TOO_SMALL, YPOS, 0);
string flag;
- while (!extract_string(meta,flag,processed,anyprocessing)) {
- { IssueMessage(0,REAL_UNKNOWN_FLAG,flag.c_str()); return COMMENTOFF(); }
+ while (!extract_string(meta, flag, processed, anyprocessing)) {
+ {
+ IssueMessage(0, REAL_UNKNOWN_FLAG, flag.c_str());
+ return COMMENTOFF();
+ }
}
- } else if (depth=="32bpp"||depth=="8bpp"){
- formats.mask_allowed = depth=="32bpp";
+ } else if (depth == "32bpp" || depth == "8bpp") {
+ formats.mask_allowed = depth == "32bpp";
string zoom_str;
- if (extract_int(meta,xpos, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xpos"); return COMMENTOFF(); }
- if (extract_int(meta,ypos, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"ypos"); return COMMENTOFF(); }
- if (extract_int(meta,xsize,processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xsize"); return COMMENTOFF(); }
- if (extract_int(meta,ysize,processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"ysize"); return COMMENTOFF(); }
- if (extract_int(meta,xrel, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xrel"); return COMMENTOFF(); }
- if (extract_int(meta,yrel, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"yrel"); return COMMENTOFF(); }
- if (extract_string(meta,zoom_str,processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"zoom"); return COMMENTOFF(); }
+ if (extract_int(meta, xpos, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "xpos");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, ypos, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "ypos");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, xsize, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "xsize");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, ysize, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "ysize");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, xrel, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "xrel");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, yrel, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "yrel");
+ return COMMENTOFF();
+ }
+ if (extract_string(meta, zoom_str, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "zoom");
+ return COMMENTOFF();
+ }
- if(xpos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XPOS,0);
- if(ypos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YPOS,0);
- if(xsize<1)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XSIZE,1);
- else if(xsize>0xFFFF)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,XSIZE,0xFFFF);
- if(ysize<1)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YSIZE,1);
- else if(ysize>0xFFFF)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,YSIZE,0xFFFF);
- if(xsize*ysize>0xFFFFFF)IssueMessage(ERROR,REAL_SPRITE_TOO_LARGE); // arbitrary but sane limit
- if(xrel<-32768)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XREL,-32768);
- else if(xrel>32767)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,XREL,32767);
- if(yrel<-32768)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YREL,-32768);
- else if(yrel>32767)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,YREL,32767);
+ if (xpos < 0) IssueMessage(ERROR, REAL_VAL_TOO_SMALL, XPOS, 0);
+ if (ypos < 0) IssueMessage(ERROR, REAL_VAL_TOO_SMALL, YPOS, 0);
+ if (xsize < 1)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, XSIZE, 1);
+ else if (xsize > 0xFFFF)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, XSIZE, 0xFFFF);
+ if (ysize < 1)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, YSIZE, 1);
+ else if (ysize > 0xFFFF)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, YSIZE, 0xFFFF);
+ if (xsize * ysize > 0xFFFFFF) IssueMessage(ERROR, REAL_SPRITE_TOO_LARGE); // arbitrary but sane limit
+ if (xrel < -32768)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, XREL, -32768);
+ else if (xrel > 32767)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, XREL, 32767);
+ if (yrel < -32768)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, YREL, -32768);
+ else if (yrel > 32767)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, YREL, 32767);
- if (zoom_str=="normal") zoom = 0;
- else if (zoom_str=="zi4") zoom = 1;
- else if (zoom_str=="zi2") zoom = 2;
- else if (zoom_str=="zo2") zoom = 3;
- else if (zoom_str=="zo4") zoom = 4;
- else if (zoom_str=="zo8") zoom = 5;
- else { IssueMessage(0,REAL_MISSING_DATA,"zoom"); return COMMENTOFF(); }
+ if (zoom_str == "normal")
+ zoom = 0;
+ else if (zoom_str == "zi4")
+ zoom = 1;
+ else if (zoom_str == "zi2")
+ zoom = 2;
+ else if (zoom_str == "zo2")
+ zoom = 3;
+ else if (zoom_str == "zo4")
+ zoom = 4;
+ else if (zoom_str == "zo8")
+ zoom = 5;
+ else {
+ IssueMessage(0, REAL_MISSING_DATA, "zoom");
+ return COMMENTOFF();
+ }
string flag;
- bool chunked = false, nocrop=false;
- while (!extract_string(meta,flag,processed,anyprocessing)) {
- if (!chunked&&flag=="chunked") chunked = true;
- else if (!nocrop&&flag=="nocrop") nocrop = true;
- else { IssueMessage(0,REAL_UNKNOWN_FLAG,flag.c_str()); return COMMENTOFF(); }
+ bool chunked = false, nocrop = false;
+ while (!extract_string(meta, flag, processed, anyprocessing)) {
+ if (!chunked && flag == "chunked")
+ chunked = true;
+ else if (!nocrop && flag == "nocrop")
+ nocrop = true;
+ else {
+ IssueMessage(0, REAL_UNKNOWN_FLAG, flag.c_str());
+ return COMMENTOFF();
+ }
}
RealSpriteFormat format;
- format.bpp32 = depth=="32bpp";
+ format.bpp32 = depth == "32bpp";
format.zoom = zoom;
- if (formats.present.empty()&&(format.bpp32||format.zoom!=0)) IssueMessage(0,REAL_8BPP_NORMAL_FIRST);
- if (formats.present.count(format) > 0) { IssueMessage(0,REAL_DUPLICATE_ZOOM); return COMMENTOFF(); }
+ if (formats.present.empty() && (format.bpp32 || format.zoom != 0)) IssueMessage(0, REAL_8BPP_NORMAL_FIRST);
+ if (formats.present.count(format) > 0) {
+ IssueMessage(0, REAL_DUPLICATE_ZOOM);
+ return COMMENTOFF();
+ }
formats.present.insert(format);
} else {
- IssueMessage(0,REAL_MISSING_DATA,"depth");
+ IssueMessage(0, REAL_MISSING_DATA, "depth");
return COMMENTOFF();
}
- if (anyprocessing) data=data.substr(0,loc+5)+processed+meta;
+ if (anyprocessing) data = data.substr(0, loc + 5) + processed + meta;
return true;
- }else{
+ } else {
int xpos, ypos, comp, ysize, xsize, xrel, yrel;
- string meta=data.substr(loc+5);
+ string meta = data.substr(loc + 5);
string processed;
bool anyprocessing = false;
- if (extract_int(meta,xpos, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xpos"); return COMMENTOFF(); }
- if (extract_int(meta,ypos, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"ypos"); return COMMENTOFF(); }
- if (extract_hex(meta,comp, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"comp"); return COMMENTOFF(); }
- if (extract_int(meta,ysize,processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"ysize"); return COMMENTOFF(); }
- if (extract_int(meta,xsize,processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xsize"); return COMMENTOFF(); }
- if (extract_int(meta,xrel, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xrel"); return COMMENTOFF(); }
- if (extract_int(meta,yrel, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"yrel"); return COMMENTOFF(); }
+ if (extract_int(meta, xpos, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "xpos");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, ypos, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "ypos");
+ return COMMENTOFF();
+ }
+ if (extract_hex(meta, comp, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "comp");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, ysize, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "ysize");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, xsize, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "xsize");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, xrel, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "xrel");
+ return COMMENTOFF();
+ }
+ if (extract_int(meta, yrel, processed, anyprocessing)) {
+ IssueMessage(0, REAL_MISSING_DATA, "yrel");
+ return COMMENTOFF();
+ }
- if (anyprocessing) data=data.substr(0,loc+5)+processed+meta;
+ if (anyprocessing) data = data.substr(0, loc + 5) + processed + meta;
- if(xpos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XPOS,0);
- if(ypos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YPOS,0);
- if(!(comp&1)||(comp&0x4B)!=comp)IssueMessage(comp==0xFF?ERROR:WARNING1,REAL_BAD_COMP,comp);
- if(xsize<1)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XSIZE,1);
- else if(xsize>0xFFFF)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,XSIZE,0xFFFF);
- if(ysize<1)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YSIZE,1);
- else if(ysize>0xFF)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,YSIZE,0xFF);
- if(xsize*ysize>0xFFFF)IssueMessage(ERROR,REAL_SPRITE_TOO_LARGE);
- if(xrel<-32768)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XREL,-32768);
- else if(xrel>32767)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,XREL,32767);
- if(yrel<-32768)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YREL,-32768);
- else if(yrel>32767)IssueMessage(ERROR,REAL_VAL_TOO_LARGE,YREL,32767);
+ if (xpos < 0) IssueMessage(ERROR, REAL_VAL_TOO_SMALL, XPOS, 0);
+ if (ypos < 0) IssueMessage(ERROR, REAL_VAL_TOO_SMALL, YPOS, 0);
+ if (!(comp & 1) || (comp & 0x4B) != comp) IssueMessage(comp == 0xFF ? ERROR : WARNING1, REAL_BAD_COMP, comp);
+ if (xsize < 1)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, XSIZE, 1);
+ else if (xsize > 0xFFFF)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, XSIZE, 0xFFFF);
+ if (ysize < 1)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, YSIZE, 1);
+ else if (ysize > 0xFF)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, YSIZE, 0xFF);
+ if (xsize * ysize > 0xFFFF) IssueMessage(ERROR, REAL_SPRITE_TOO_LARGE);
+ if (xrel < -32768)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, XREL, -32768);
+ else if (xrel > 32767)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, XREL, 32767);
+ if (yrel < -32768)
+ IssueMessage(ERROR, REAL_VAL_TOO_SMALL, YREL, -32768);
+ else if (yrel > 32767)
+ IssueMessage(ERROR, REAL_VAL_TOO_LARGE, YREL, 32767);
return true;
}
}
-void output_buffer(const string&sprite,bool isPatch,int spriteno){
- PseudoSprite data(sprite,spriteno);
- if(data.IsValid()){
+void output_buffer(const string &sprite, bool isPatch, int spriteno)
+{
+ PseudoSprite data(sprite, spriteno);
+ if (data.IsValid()) {
_spritenum++;
- if(isPatch)check_sprite(data);
- else{
+ if (isPatch)
+ check_sprite(data);
+ else {
data.SetAllHex();
- data.SetEol(32,1);
- data.SetEol(64,1);
- data.SetEol(96,1);
- data.SetEol(128,1);
- data.SetEol(160,1);
- data.SetEol(192,1);
- data.SetEol(224,1);
+ data.SetEol(32, 1);
+ data.SetEol(64, 1);
+ data.SetEol(96, 1);
+ data.SetEol(128, 1);
+ data.SetEol(160, 1);
+ data.SetEol(192, 1);
+ data.SetEol(224, 1);
}
}
- (*pNfo)<<data;
+ (*pNfo) << data;
}
diff --git a/src/nforenum.h b/src/nforenum.h
--- a/src/nforenum.h
+++ b/src/nforenum.h
@@ -46,37 +46,48 @@
typedef unsigned char uchar;
#if defined DEBUG || defined _DEBUG
-inline int _FORCE_INT_(int x){return x;}
+inline int _FORCE_INT_(int x)
+{
+ return x;
+}
#define verify assert
#else
#define verify(x) (void(x))
#define _FORCE_INT_(x) ((int)x)
#endif
-enum{EOK,EWARN=3,EERROR,EPARSE,EFILE,EDATA,EFATAL};
+enum {
+ EOK,
+ EWARN = 3,
+ EERROR,
+ EPARSE,
+ EFILE,
+ EDATA,
+ EFATAL
+};
void SetCode(int);
-#define INTERNAL_ERROR(var,val)\
- if(true){\
- IssueMessage(0,INTERNAL_ERROR_TEXT,__FILE__,__LINE__,_spritenum,#var,_FORCE_INT_(val),BOOST_CURRENT_FUNCTION);\
- assert(false);\
- exit(EFATAL);\
- }else\
- ((void)0)
+#define INTERNAL_ERROR(var, val) \
+ if (true) { \
+ IssueMessage(0, INTERNAL_ERROR_TEXT, __FILE__, __LINE__, _spritenum, #var, _FORCE_INT_(val), BOOST_CURRENT_FUNCTION); \
+ assert(false); \
+ exit(EFATAL); \
+ } else \
+ ((void)0)
-#define DEFAULT(var)\
- default:\
- INTERNAL_ERROR(var,var);
+#define DEFAULT(var) \
+ default: \
+ INTERNAL_ERROR(var, var);
-#define VERIFY(cond,var)\
- if(!(cond))INTERNAL_ERROR(var,var);\
- else\
- ((void)0)
+#define VERIFY(cond, var) \
+ if (!(cond)) \
+ INTERNAL_ERROR(var, var); \
+ else \
+ ((void)0)
-#define EXPECTED_BYTES(off) (off>>24)
-#define EXPECTED_LOC(off) (off&0xFFFFFF)
+#define EXPECTED_BYTES(off) (off >> 24)
+#define EXPECTED_LOC(off) (off & 0xFFFFFF)
-#define spritenum() (GetState(DIFF)?-1:\
- GetState(USEOLDSPRITENUMS)?oldspritenum:(int)_spritenum)
+#define spritenum() (GetState(DIFF) ? -1 : GetState(USEOLDSPRITENUMS) ? oldspritenum : (int)_spritenum)
-#endif//_RENUM_RENUM_H_INCLUDED_
+#endif //_RENUM_RENUM_H_INCLUDED_
diff --git a/src/nfosprite.h b/src/nfosprite.h
--- a/src/nfosprite.h
+++ b/src/nfosprite.h
@@ -26,62 +26,101 @@
#include <istream>
#include <vector>
-#include"typesize.h"
-#include"sprites.h"
+#include "typesize.h"
+#include "sprites.h"
typedef unsigned short ushort;
-class Sprite{
-protected:
- Sprite(){}
-public:
- virtual ~Sprite(){}
- enum SpriteType{ST_REAL,ST_PSEUDO,ST_INCLUDE};
- virtual SpriteType GetType()const =0;
- class unparseable{//thrown by the constructors
- public:
- unparseable(string reason,size_t sprite);
+class Sprite
+{
+ protected:
+ Sprite()
+ {
+ }
+
+ public:
+ virtual ~Sprite()
+ {
+ }
+ enum SpriteType {
+ ST_REAL,
+ ST_PSEUDO,
+ ST_INCLUDE
+ };
+ virtual SpriteType GetType() const = 0;
+ class unparseable
+ { // thrown by the constructors
+ public:
+ unparseable(string reason, size_t sprite);
string reason;
};
};
-class Real:public Sprite{
-public:
- void AddSprite(size_t,int,const string&);
- Sprite::SpriteType GetType()const{return ST_REAL;}
+class Real : public Sprite
+{
+ public:
+ void AddSprite(size_t, int, const string &);
+ Sprite::SpriteType GetType() const
+ {
+ return ST_REAL;
+ }
vector<SpriteInfo> infs;
-private:
- ostream&output(ostream&)const;
+
+ private:
+ ostream &output(ostream &) const;
static string prevname;
static int prevy;
};
-class Pseudo:public Sprite{
-public:
- Pseudo(size_t,int,int,const string&,int);
+class Pseudo : public Sprite
+{
+ public:
+ Pseudo(size_t, int, int, const string &, int);
- U8 operator[](int offs)const{return packed[offs];}
- uint size()const;
+ U8 operator[](int offs) const
+ {
+ return packed[offs];
+ }
+ uint size() const;
- Sprite::SpriteType GetType()const{return ST_PSEUDO;}
- const char*GetData()const{return packed.c_str();}
+ Sprite::SpriteType GetType() const
+ {
+ return ST_PSEUDO;
+ }
+ const char *GetData() const
+ {
+ return packed.c_str();
+ }
- //static bool CanQuote(uint);
- static bool MayBeSprite(const string&);
- enum width {_B_, _BX_, _W_, _D_};
+ // static bool CanQuote(uint);
+ static bool MayBeSprite(const string &);
+ enum width {
+ _B_,
+ _BX_,
+ _W_,
+ _D_
+ };
- static uint ReadValue(istream&, width);
+ static uint ReadValue(istream &, width);
-private:
+ private:
string packed;
};
-class Include:public Sprite{
-public:
- Include(const string&);
- Sprite::SpriteType GetType()const{return ST_INCLUDE;}
- const char *GetName()const{return name.c_str();}
-private:
+class Include : public Sprite
+{
+ public:
+ Include(const string &);
+ Sprite::SpriteType GetType() const
+ {
+ return ST_INCLUDE;
+ }
+ const char *GetName() const
+ {
+ return name.c_str();
+ }
+
+ private:
string name;
};
diff --git a/src/path.cpp b/src/path.cpp
--- a/src/path.cpp
+++ b/src/path.cpp
@@ -5,16 +5,14 @@
static int DotFound(const char *pB)
{
- if (*(pB-1) == '.')
- pB--;
+ if (*(pB - 1) == '.') pB--;
switch (*--pB) {
- case ':' :
- if (*(pB-2) != '\0')
- break;
- case '/' :
- case '\\' :
- case '\0' :
- return 1;
+ case ':':
+ if (*(pB - 2) != '\0') break;
+ case '/':
+ case '\\':
+ case '\0':
+ return 1;
}
return 0;
}
@@ -25,8 +23,7 @@
return dest + strlen(dest);
}
-void fnmerge(register char *pathP, const char *driveP,
- const char *dirP, const char *nameP, const char *extP)
+void fnmerge(register char *pathP, const char *driveP, const char *dirP, const char *nameP, const char *extP)
{
char *origpathP = pathP;
if (driveP && *driveP) {
@@ -36,7 +33,7 @@
if (dirP && *dirP) {
pathP = stpcopy(pathP, dirP, MAXPATH - (pathP - origpathP));
- if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = '/';
+ if (*(pathP - 1) != '\\' && *(pathP - 1) != '/') *pathP++ = '/';
}
if (nameP) {
@@ -50,36 +47,29 @@
*pathP = 0;
}
-int fnsplit(const char *pathP, char *driveP, char *dirP,
- char *nameP, char *extP)
+int fnsplit(const char *pathP, char *driveP, char *dirP, char *nameP, char *extP)
{
- register char *pB;
- register int Wrk;
- int Ret;
+ register char *pB;
+ register int Wrk;
+ int Ret;
- char buf[ MAXPATH+2 ];
+ char buf[MAXPATH + 2];
/*
Set all string to default value zero
*/
Ret = 0;
- if (driveP)
- *driveP = 0;
- if (dirP)
- *dirP = 0;
- if (nameP)
- *nameP = 0;
- if (extP)
- *extP = 0;
+ if (driveP) *driveP = 0;
+ if (dirP) *dirP = 0;
+ if (nameP) *nameP = 0;
+ if (extP) *extP = 0;
/*
- Copy filename into template up to MAXPATH characters
+ Copy filename into template up to MAXPATH characters
*/
pB = buf;
- while (*pathP == ' ')
- pathP++;
- if ((Wrk = strlen(pathP)) > MAXPATH)
- Wrk = MAXPATH - 1;
+ while (*pathP == ' ') pathP++;
+ if ((Wrk = strlen(pathP)) > MAXPATH) Wrk = MAXPATH - 1;
*pB++ = 0;
safestrncpy(pB, pathP, Wrk + 1);
pB += Wrk;
@@ -88,52 +78,45 @@
Split the filename and fill corresponding nonzero pointers
*/
Wrk = 0;
- for (; ; ) {
+ for (;;) {
switch (*--pB) {
- case '.' :
- if (!Wrk && (*(pB+1) == '\0'))
- Wrk = DotFound(pB);
- if ((!Wrk) && ((Ret & EXTENSION) == 0)) {
- Ret |= EXTENSION;
- safestrncpy(extP, pB, MAXEXT);
- *pB = 0;
- }
- continue;
- case ':' :
- if (pB != &buf[2])
+ case '.':
+ if (!Wrk && (*(pB + 1) == '\0')) Wrk = DotFound(pB);
+ if ((!Wrk) && ((Ret & EXTENSION) == 0)) {
+ Ret |= EXTENSION;
+ safestrncpy(extP, pB, MAXEXT);
+ *pB = 0;
+ }
continue;
- case '\0' :
- if (Wrk) {
- if (*++pB)
- Ret |= DIRECTORY;
- safestrncpy(dirP, pB, MAXDIR);
- *pB-- = 0;
- break;
- }
- case '/' :
- case '\\' :
- if (!Wrk) {
- Wrk++;
- if (*++pB)
- Ret |= FILENAME;
+ case ':':
+ if (pB != &buf[2]) continue;
+ case '\0':
+ if (Wrk) {
+ if (*++pB) Ret |= DIRECTORY;
+ safestrncpy(dirP, pB, MAXDIR);
+ *pB-- = 0;
+ break;
+ }
+ case '/':
+ case '\\':
+ if (!Wrk) {
+ Wrk++;
+ if (*++pB) Ret |= FILENAME;
safestrncpy(nameP, pB, MAXFILE);
*pB-- = 0;
- if (*pB == 0 || (*pB == ':' && pB == &buf[2]))
- break;
- }
- continue;
- case '*' :
- case '?' :
- if (!Wrk)
- Ret |= WILDCARDS;
- default :
- continue;
+ if (*pB == 0 || (*pB == ':' && pB == &buf[2])) break;
+ }
+ continue;
+ case '*':
+ case '?':
+ if (!Wrk) Ret |= WILDCARDS;
+ default:
+ continue;
}
break;
}
if (*pB == ':') {
- if (buf[1])
- Ret |= DRIVE;
+ if (buf[1]) Ret |= DRIVE;
safestrncpy(driveP, &buf[1], MAXDRIVE);
}
diff --git a/src/path.h b/src/path.h
--- a/src/path.h
+++ b/src/path.h
@@ -7,19 +7,17 @@
#define WILDCARDS 0x01
#define EXTENSION 0x02
-#define FILENAME 0x04
+#define FILENAME 0x04
#define DIRECTORY 0x08
-#define DRIVE 0x10
+#define DRIVE 0x10
-#define MAXPATH 1024
-#define MAXDRIVE 3
-#define MAXDIR 1024
-#define MAXFILE 1024
-#define MAXEXT 32
+#define MAXPATH 1024
+#define MAXDRIVE 3
+#define MAXDIR 1024
+#define MAXFILE 1024
+#define MAXEXT 32
-void fnmerge(register char *pathP, const char *driveP,
- const char *dirP, const char *nameP, const char *extP);
-int fnsplit(const char *pathP, char *driveP, char *dirP,
- char *nameP, char *extP);
+void fnmerge(register char *pathP, const char *driveP, const char *dirP, const char *nameP, const char *extP);
+int fnsplit(const char *pathP, char *driveP, char *dirP, char *nameP, char *extP);
#endif /* _PATH_H */
diff --git a/src/pcxfile.cpp b/src/pcxfile.cpp
--- a/src/pcxfile.cpp
+++ b/src/pcxfile.cpp
@@ -21,7 +21,6 @@
#include "pcxfile.h"
#include "error.h"
-
/***********************\
* *
* class pcxfile *
@@ -50,16 +49,14 @@
header.window[2] = 65535;
codecing = 0;
paletted = true;
-
}
pcxfile::~pcxfile()
{
- delete(mfile);
+ delete (mfile);
if (band) {
- for (int i=0; i<bandlines; i++)
- delete[](band[i]);
+ for (int i = 0; i < bandlines; i++) delete[](band[i]);
delete[](band);
}
}
@@ -72,7 +69,7 @@
void pcxfile::newfile(bool paletted, int sx)
{
- if (curfile) { // do we already have a file
+ if (curfile) { // do we already have a file
filedone(1);
}
@@ -92,14 +89,19 @@
void pcxfile::newheader(int sx)
{
- const static pcxheader baseheader =
- { 10, 5, 1, 8, // manuf, version, encoding, bpp
- {0, 0, 65535, 65535}, // window[4]
- {72, 72}, // dpi[2]
- {0}, // cmap[48]
- 0, 1, -1, 1, // reserved, nplanes, bpl, palinfo
- {-1, -1}, // screen[2]
- {0 }}; // filler[54]
+ const static pcxheader baseheader = {10,
+ 5,
+ 1,
+ 8, // manuf, version, encoding, bpp
+ {0, 0, 65535, 65535}, // window[4]
+ {72, 72}, // dpi[2]
+ {0}, // cmap[48]
+ 0,
+ 1,
+ -1,
+ 1, // reserved, nplanes, bpl, palinfo
+ {-1, -1}, // screen[2]
+ {0}}; // filler[54]
header = baseheader;
header.window[2] = sx - 1;
@@ -116,8 +118,7 @@
newfile(paletted, sx);
- if (bandy > bandlines)
- alloclines(bandy);
+ if (bandy > bandlines) alloclines(bandy);
thisbandy = bandy;
}
@@ -126,20 +127,18 @@
{
CommonPixel **newband, **oldband = band;
- if (newlines <= bandlines)
- return;
+ if (newlines <= bandlines) return;
- newband = new CommonPixel*[newlines];
+ newband = new CommonPixel *[newlines];
if (!newband) {
printf("%s: Error allocating band array\n", this->filename());
exit(2);
}
int i;
- for (i=0; i<bandlines; i++)
- newband[i] = oldband[i];
+ for (i = 0; i < bandlines; i++) newband[i] = oldband[i];
- for (i=bandlines; i<newlines; i++) {
+ for (i = bandlines; i < newlines; i++) {
newband[i] = new CommonPixel[sx];
if (!(newband[i])) {
printf("%s: Error allocating new band lines\n", this->filename());
@@ -153,20 +152,18 @@
i = bandlines;
bandlines = newlines;
- for (; i<newlines; i++)
- initline(i);
+ for (; i < newlines; i++) initline(i);
}
void pcxfile::expirelines(int oldlines)
{
- for (int i=0; i<oldlines; i++) {
+ for (int i = 0; i < oldlines; i++) {
CommonPixel *old = band[0];
- memmove( &(band[0]), &(band[1]), (bandlines-1)*sizeof(band[0]));
- band[bandlines-1] = old;
+ memmove(&(band[0]), &(band[1]), (bandlines - 1) * sizeof(band[0]));
+ band[bandlines - 1] = old;
// Attempt to prevent reading past the end of file
- if (i + totaly + bandlines < pcxfile::sy)
- initline(bandlines - 1);
+ if (i + totaly + bandlines < pcxfile::sy) initline(bandlines - 1);
}
}
@@ -179,19 +176,15 @@
setline(band[y]);
};
-
void pcxfile::endimage()
{
- if (px)
- newband();
+ if (px) newband();
- if (run)
- endencoding();
+ if (run) endencoding();
if (band) {
int i;
- for (i=0; i<bandlines; i++)
- delete[](band[i]);
+ for (i = 0; i < bandlines; i++) delete[](band[i]);
delete[](band);
band = NULL;
}
@@ -221,10 +214,9 @@
void pcxfile::streamputpixel(CommonPixel *buffer, unsigned long datasize)
{
- for (unsigned long i=0; i<datasize; i++) {
+ for (unsigned long i = 0; i < datasize; i++) {
streamputpixel(buffer[i]);
- if ( (i % (px-1)) == (unsigned long) px-2)
- newline();
+ if ((i % (px - 1)) == (unsigned long)px - 2) newline();
}
}
@@ -244,19 +236,17 @@
void pcxfile::streamgetpixel(CommonPixel *buffer, unsigned long datasize)
{
- unsigned long i=0;
+ unsigned long i = 0;
CommonPixel colour;
- bool maybeGlyph=!_mapAll;
- for (; i<datasize; i++) {
+ bool maybeGlyph = !_mapAll;
+ for (; i < datasize; i++) {
colour = streamgetpixel();
maybeGlyph &= (colour.m < 3);
buffer[i] = colour;
- if ( (i % px) == (unsigned long) px-1)
- newline();
+ if ((i % px) == (unsigned long)px - 1) newline();
}
if (!maybeGlyph)
- for(i=0; i<datasize; i++)
- buffer[i].m = getcolourmap[buffer[i].m];
+ for (i = 0; i < datasize; i++) buffer[i].m = getcolourmap[buffer[i].m];
}
void pcxfile::putpixel(int x, int y, CommonPixel colour)
@@ -272,19 +262,19 @@
/*U8 pcxfile::getpixel(int x, int y)
{
- int sx = subofsx(x, 0);
- int sy = subofsy(y, 0);
- int colour;
- if (sx < 0 || sy < 0)
- colour = 255;
- else
- colour = band[sy][sx];
- if (getcolourmap[colour] == -1) {
- printf("Agh! Getting colour %d but it has no map!\n", colour);
- exit(2);
- }
+ int sx = subofsx(x, 0);
+ int sy = subofsy(y, 0);
+ int colour;
+ if (sx < 0 || sy < 0)
+ colour = 255;
+ else
+ colour = band[sy][sx];
+ if (getcolourmap[colour] == -1) {
+ printf("Agh! Getting colour %d but it has no map!\n", colour);
+ exit(2);
+ }
- return getcolourmap[colour];
+ return getcolourmap[colour];
}*/
void pcxfile::endsubimage()
@@ -295,34 +285,32 @@
{
int i, y;
- if ( (totaly + thisbandy > sy) && (thisbandy <= sy) ) { // would be too large
+ if ((totaly + thisbandy > sy) && (thisbandy <= sy)) { // would be too large
newfile(this->paletted, sx);
}
totaly += thisbandy;
- for (y=0; y<thisbandy; y++) {
+ for (y = 0; y < thisbandy; y++) {
startencoding();
encodebytes(band[y], sx);
endencoding();
}
- for (i=0; i<bandlines; i++)
- initline(i);
+ for (i = 0; i < bandlines; i++) initline(i);
- subx=0;
- px=0;
+ subx = 0;
+ px = 0;
thisbandy = bandy;
// while testing only...
-// filedone(0);
+ // filedone(0);
}
void pcxfile::startencoding()
{
- if (codecing == 1)
- return;
+ if (codecing == 1) return;
run = 0;
codecing = 1;
@@ -330,8 +318,7 @@
void pcxfile::startdecoding()
{
- if (codecing == 2)
- return;
+ if (codecing == 2) return;
run = 0;
codecing = 2;
@@ -358,8 +345,7 @@
num--;
}
- if ((thisrun > 1) || ( (byte & 0xc0) == 0xc0) )
- fputc(thisrun | 0xc0, curfile);
+ if ((thisrun > 1) || ((byte & 0xc0) == 0xc0)) fputc(thisrun | 0xc0, curfile);
fputc(byte, curfile);
}
}
@@ -376,11 +362,9 @@
while (num) {
thisrun = num;
- if (thisrun > 0x3f)
- thisrun = 0x3f;
+ if (thisrun > 0x3f) thisrun = 0x3f;
- if ((thisrun > 1) || ( (byte & 0xc0) == 0xc0) )
- fputc(thisrun | 0xc0, curfile);
+ if ((thisrun > 1) || ((byte & 0xc0) == 0xc0)) fputc(thisrun | 0xc0, curfile);
fputc(byte, curfile);
num -= thisrun;
}
@@ -399,8 +383,7 @@
thisrun = run;
if (thisrun) {
used = run;
- if (used > num)
- used = num;
+ if (used > num) used = num;
for (int i = 0; i < used; i++) buffer[i].m = byte;
buffer += used;
num -= used;
@@ -409,13 +392,12 @@
while (num) {
byte = fgetc(curfile);
- if ( (byte & 0xc0) == 0xc0) { // it's a run of equal bytes
+ if ((byte & 0xc0) == 0xc0) { // it's a run of equal bytes
thisrun = byte & 0x3f;
byte = fgetc(curfile);
used = thisrun;
- if (used > num)
- used = num;
+ if (used > num) used = num;
for (int i = 0; i < used; i++) buffer[i].m = byte;
buffer += used;
num -= used;
@@ -477,7 +459,7 @@
}
#ifdef GRFCODEC_BIG_ENDIAN
-void pcxfile::be_swapheader(pcxheader& header)
+void pcxfile::be_swapheader(pcxheader &header)
{
header.window[0] = BE_SWAP16(header.window[0]);
header.window[1] = BE_SWAP16(header.window[1]);
@@ -491,5 +473,7 @@
header.screen[1] = BE_SWAP16(header.screen[1]);
}
#else
-void pcxfile::be_swapheader(pcxheader&){}
+void pcxfile::be_swapheader(pcxheader &)
+{
+}
#endif
diff --git a/src/pcxfile.h b/src/pcxfile.h
--- a/src/pcxfile.h
+++ b/src/pcxfile.h
@@ -26,14 +26,17 @@
#include "file.h"
/** Definition of a common pixel in GRFCodec's realm. */
-struct CommonPixel {
- U8 r; ///< Red-channel
- U8 g; ///< Green-channel
- U8 b; ///< Blue-channel
- U8 a; ///< Alpha-channel
- U8 m; ///< Remap-channel
+struct CommonPixel
+{
+ U8 r; ///< Red-channel
+ U8 g; ///< Green-channel
+ U8 b; ///< Blue-channel
+ U8 a; ///< Alpha-channel
+ U8 m; ///< Remap-channel
- explicit CommonPixel(U8 r = 0, U8 g = 0, U8 b = 0, U8 a = 0, U8 m = 0) : r(r), g(g), b(b), a(a), m(m) {}
+ explicit CommonPixel(U8 r = 0, U8 g = 0, U8 b = 0, U8 a = 0, U8 m = 0) : r(r), g(g), b(b), a(a), m(m)
+ {
+ }
bool IsTransparent(bool rgba) const
{
@@ -74,32 +77,45 @@
}
};
-struct pcxheader {
- U8 manuf; // 10
- U8 version; // 5
- U8 encoding; // 1
- U8 bpp; // 1, 2, 4 or 8 (per plane)
- U16 window[4]; // x1,y1,x2,x2
- U16 dpi[2]; // x,y
- U8 cmap[48]; // colormap
- U8 reserved; // 0
+struct pcxheader
+{
+ U8 manuf; // 10
+ U8 version; // 5
+ U8 encoding; // 1
+ U8 bpp; // 1, 2, 4 or 8 (per plane)
+ U16 window[4]; // x1,y1,x2,x2
+ U16 dpi[2]; // x,y
+ U8 cmap[48]; // colormap
+ U8 reserved; // 0
U8 nplanes;
- S16 bpl; // bytes per line (per plane)
- S16 palinfo; // 1=colour
- S16 screen[2]; // x,y
+ S16 bpl; // bytes per line (per plane)
+ S16 palinfo; // 1=colour
+ S16 screen[2]; // x,y
U8 filler[54];
};
-class pcxfile {
- public:
+class pcxfile
+{
+ public:
virtual ~pcxfile();
- virtual const char *filename() { return mfile->filename(); };
- virtual FILE *getnextfile() { return mfile->nextfile(); };
- virtual FILE *getcurfile() { return mfile->curfile(); };
- virtual void filedone(int /*final*/) { };
+ virtual const char *filename()
+ {
+ return mfile->filename();
+ };
+ virtual FILE *getnextfile()
+ {
+ return mfile->nextfile();
+ };
+ virtual FILE *getcurfile()
+ {
+ return mfile->curfile();
+ };
+ virtual void filedone(int /*final*/) {};
virtual void filestart(bool)
- { fseek(curfile, sizeof(header), SEEK_SET); };
+ {
+ fseek(curfile, sizeof(header), SEEK_SET);
+ };
void setfile(multifile *mfile);
@@ -109,34 +125,43 @@
void alloclines(int newlines);
void expirelines(int oldlines);
void initline(int y);
- virtual void setline(CommonPixel* /*band*/) { };
+ virtual void setline(CommonPixel * /*band*/) {};
void endimage();
- virtual void startsubimage(int /*x*/, int /*y*/, int /*sx*/, int /*sy*/) { };
+ virtual void startsubimage(int /*x*/, int /*y*/, int /*sx*/, int /*sy*/) {};
void newline();
void streamputpixel(CommonPixel colour);
void streamputpixel(CommonPixel *buffer, unsigned long datasize);
-private:
+
+ private:
CommonPixel streamgetpixel();
-public:
+
+ public:
void streamgetpixel(CommonPixel *buffer, unsigned long datasize);
void installreadmap(int *map);
void installwritemap(int *map);
void putpixel(int x, int y, CommonPixel colour);
- //U8 getpixel(int x, int y);
- int subimagex()
- { return subx + dx; }
- int subimagey()
- { return totaly + dy; }
+ // U8 getpixel(int x, int y);
+ int subimagex()
+ {
+ return subx + dx;
+ }
+ int subimagey()
+ {
+ return totaly + dy;
+ }
void endsubimage();
- const char *getdirectory() { return mfile->getdirectory(); };
+ const char *getdirectory()
+ {
+ return mfile->getdirectory();
+ };
- void be_swapheader(pcxheader& header);
+ void be_swapheader(pcxheader &header);
- protected:
+ protected:
pcxfile();
void newband();
@@ -153,48 +178,53 @@
FILE *curfile;
pcxheader header;
- int sx, sy, // size of the PCX image
- subx, // current subimage x offset
- px, py, // subimage size x, y
- cx, cy, // subimage stream ptr x, y
- dx, dy, // subimage pos x, y (rel to subx, 0)
- bandx, bandy, thisbandy, // default band x, y, current band y
- totaly; // total lines written so far
+ int sx, sy, // size of the PCX image
+ subx, // current subimage x offset
+ px, py, // subimage size x, y
+ cx, cy, // subimage stream ptr x, y
+ dx, dy, // subimage pos x, y (rel to subx, 0)
+ bandx, bandy, thisbandy, // default band x, y, current band y
+ totaly; // total lines written so far
int bandlines;
int codecing;
bool paletted;
- class colourmap{
- public:
- colourmap():map(new int[256]),deletemap(true){
- for(int i=0;i<256;i++)
- map[i]=i;
+ class colourmap
+ {
+ public:
+ colourmap() : map(new int[256]), deletemap(true)
+ {
+ for (int i = 0; i < 256; i++) map[i] = i;
}
- ~colourmap(){
- if(deletemap) delete[] map;
+ ~colourmap()
+ {
+ if (deletemap) delete[] map;
}
- const colourmap&operator=(int*p){
- if(deletemap) delete map;
- deletemap=false;
- map=p;
- return*this;
+ const colourmap &operator=(int *p)
+ {
+ if (deletemap) delete map;
+ deletemap = false;
+ map = p;
+ return *this;
}
- int operator[](int x){return map[x];}
- private:
- int*map;
+ int operator[](int x)
+ {
+ return map[x];
+ }
+
+ private:
+ int *map;
bool deletemap;
- void operator=(const colourmap&);// Not assignable
- colourmap(const colourmap&);// not copyable
+ void operator=(const colourmap &); // Not assignable
+ colourmap(const colourmap &); // not copyable
} getcolourmap, putcolourmap;
CommonPixel **band;
- private:
-
+ private:
multifile *mfile;
U8 last;
U8 run;
};
-
#endif /* _PCXFILE_H */
diff --git a/src/pcxsprit.cpp b/src/pcxsprit.cpp
--- a/src/pcxsprit.cpp
+++ b/src/pcxsprit.cpp
@@ -3,7 +3,7 @@
#include "ttdpal.h"
#include "grfcomm.h"
-extern bool _mapAll,_hexspritenums;
+extern bool _mapAll, _hexspritenums;
/***********************\
* *
@@ -29,30 +29,25 @@
#define bOOO_ 14
#define bOOOO 15
-
-#define _(o,t) ((b ## t << 4) + b ## o)
+#define _(o, t) ((b##t << 4) + b##o)
#define DIGITHEIGHT 5
#define DIGITWIDTH 4
// DIGITHEIGHT*DIGITWIDTH*16(digits)/8(bitsperbyte) = 40 bytes
-#define DIGITIND(digit,line) (digit/2+8*line)
-#define DIGITSHR(digit) (4*(digit&1))
+#define DIGITIND(digit, line) (digit / 2 + 8 * line)
+#define DIGITSHR(digit) (4 * (digit & 1))
static unsigned char digitlines[40] = {
-
-_( _OO_, __O_ ),_( OOO_, OOO_ ),_( __O_, OOOO),_( _OO_, OOOO),_( _OO_, _OO_ ), _( _OO_, OOO_ ), _( _OOO, OOO_ ), _( OOOO, OOOO ),
-_( O__O, _OO_ ),_( ___O, ___O ),_( _OO_, O___),_( O___, ___O),_( O__O, O__O ), _( O__O, O__O ), _( O___, O__O ), _( O___, O___ ),
-_( O__O, __O_ ),_( _OO_, _OO_ ),_( O_O_, OOO_),_( OOOO, __O_),_( _OO_, _OOO ), _( OOOO, OOO_ ), _( O___, O__O ), _( OOO_, OOO_ ),
-_( O__O, __O_ ),_( O___, ___O ),_( OOOO, ___O),_( O__O, _O__),_( O__O, ___O ), _( O__O, O__O ), _( O___, O__O ), _( O___, O___ ),
-_( _OO_, _OOO ),_( OOOO, OOO_ ),_( __O_, OOO_),_( _OO_, _O__),_( _OO_, _OO_ ), _( O__O, OOO_ ), _( _OOO, OOO_ ), _( OOOO, O___ ),
-
-};
+ _(_OO_, __O_), _(OOO_, OOO_), _(__O_, OOOO), _(_OO_, OOOO), _(_OO_, _OO_), _(_OO_, OOO_), _(_OOO, OOO_), _(OOOO, OOOO),
+ _(O__O, _OO_), _(___O, ___O), _(_OO_, O___), _(O___, ___O), _(O__O, O__O), _(O__O, O__O), _(O___, O__O), _(O___, O___),
+ _(O__O, __O_), _(_OO_, _OO_), _(O_O_, OOO_), _(OOOO, __O_), _(_OO_, _OOO), _(OOOO, OOO_), _(O___, O__O), _(OOO_, OOO_),
+ _(O__O, __O_), _(O___, ___O), _(OOOO, ___O), _(O__O, _O__), _(O__O, ___O), _(O__O, O__O), _(O___, O__O), _(O___, O___),
+ _(_OO_, _OOO), _(OOOO, OOO_), _(__O_, OOO_), _(_OO_, _O__), _(_OO_, _OO_), _(O__O, OOO_), _(_OOO, OOO_), _(OOOO, O___), };
#undef _
-
pcxwrite::pcxwrite(multifile *mfile)
{
setfile(mfile);
- spriteno=-1; // so the first one will be 0
+ spriteno = -1; // so the first one will be 0
lastdigitx = -50;
}
@@ -63,15 +58,13 @@
if (curfile) {
if (final) {
// fill with blank lines to the right height if necessary
- for (y=totaly; y<sy; y++) {
+ for (y = totaly; y < sy; y++) {
startencoding();
encodebytes(background, sx);
endencoding();
}
- if (sy != -1)
- totaly = sy;
-
+ if (sy != -1) totaly = sy;
}
writepal();
@@ -90,7 +83,7 @@
void pcxwrite::filestart(bool paletted)
{
- if (!paletted){
+ if (!paletted) {
fprintf(stderr, "GRFCodec supports only paletted PCX files.\n");
exit(2);
}
@@ -107,7 +100,7 @@
sx += bordersizex;
sy += bordersizey;
- subx += ( (int) (px + bandx) / bandx) * bandx;
+ subx += ((int)(px + bandx) / bandx) * bandx;
if (subx + sx >= pcxfile::sx) {
newband();
@@ -115,8 +108,8 @@
}
if (sy > thisbandy) {
- int needbandy = ( (int) (sy + bandy - 1) / bandy) * bandy;
- if ((totaly + needbandy > this->sy) && (needbandy <= this->sy)) { // would be too large
+ int needbandy = ((int)(sy + bandy - 1) / bandy) * bandy;
+ if ((totaly + needbandy > this->sy) && (needbandy <= this->sy)) { // would be too large
newband();
lastdigitx = -50;
/* Above call to newband might had already switched into a new file, have to recheck */
@@ -131,8 +124,8 @@
cx = 0;
cy = 0;
- px = sx;// - bordersizex;
- py = sy;// - bordersizey;
+ px = sx; // - bordersizex;
+ py = sy; // - bordersizey;
dx = 1;
dy = 1;
@@ -141,7 +134,7 @@
int i, bx, by;
bx = sx - 2;
by = sy - 2;
- for (i=0; i < 2*bx+2*by; i+=borderskip) {
+ for (i = 0; i < 2 * bx + 2 * by; i += borderskip) {
border.m = i & 8;
if (i < bx)
@@ -150,11 +143,11 @@
else if (i < bx + by)
putpixel(0, i - bx, border);
- else if (i < 2*bx + by)
- putpixel(i-bx-by, by, border);
+ else if (i < 2 * bx + by)
+ putpixel(i - bx - by, by, border);
else
- putpixel(bx, i-2*bx-by, border);
+ putpixel(bx, i - 2 * bx - by, border);
}
}
@@ -164,36 +157,32 @@
showspriteno();
dx++;
- dy+=1+DIGITHEIGHT+1;
+ dy += 1 + DIGITHEIGHT + 1;
}
void pcxwrite::showspriteno()
{
char spritenum[10];
int newlastx;
- if(_hexspritenums)
+ if (_hexspritenums)
sprintf(spritenum, "%X", spriteno);
else
sprintf(spritenum, "%d", spriteno);
- newlastx = subx+strlen(spritenum)*(DIGITWIDTH+1)+dx;
- if (newlastx >= pcxfile::sx)
- return;
+ newlastx = subx + strlen(spritenum) * (DIGITWIDTH + 1) + dx;
+ if (newlastx >= pcxfile::sx) return;
- if (subx+dx < lastdigitx + 2*(DIGITWIDTH+1))
- return;
+ if (subx + dx < lastdigitx + 2 * (DIGITWIDTH + 1)) return;
lastdigitx = newlastx;
- for (int i=0; spritenum[i]; i++) {
+ for (int i = 0; spritenum[i]; i++) {
int digit = spritenum[i] - '0';
- if (digit > 9)
- digit += '0' - 'A';
- for (int y=0; y<DIGITHEIGHT; y++) {
- int pixels = digitlines[DIGITIND(digit,y)] >> DIGITSHR(digit);
- for (int x=DIGITWIDTH-1; x>=0; x--) {
- if (pixels & 1)
- putpixel(x + i*(DIGITWIDTH+1),y,border);
+ if (digit > 9) digit += '0' - 'A';
+ for (int y = 0; y < DIGITHEIGHT; y++) {
+ int pixels = digitlines[DIGITIND(digit, y)] >> DIGITSHR(digit);
+ for (int x = DIGITWIDTH - 1; x >= 0; x--) {
+ if (pixels & 1) putpixel(x + i * (DIGITWIDTH + 1), y, border);
pixels >>= 1;
}
}
@@ -205,19 +194,18 @@
for (int i = 0; i < sx; i++) band[i] = background;
}
-void pcxwrite::spritedone(int sx, int sy){
+void pcxwrite::spritedone(int sx, int sy)
+{
spritedone();
- bool maybeGlyph=!_mapAll;
+ bool maybeGlyph = !_mapAll;
- for(int cx=0, x=subofsx(cx,0);cx<sx&&maybeGlyph;cx++,x++)
- for(int cy=0, y=subofsy(cy,0);cy<sy;cy++,y++)
- maybeGlyph &= (band[y][x].m < 3);
+ for (int cx = 0, x = subofsx(cx, 0); cx < sx && maybeGlyph; cx++, x++)
+ for (int cy = 0, y = subofsy(cy, 0); cy < sy; cy++, y++) maybeGlyph &= (band[y][x].m < 3);
if (!maybeGlyph)
- for(int cx=0, x=subofsx(cx,0);cx<sx;cx++,x++)
- for(int cy=0, y=subofsy(cy,0);cy<sy;cy++,y++)
- band[y][x].m = putcolourmap[band[y][x].m];
+ for (int cx = 0, x = subofsx(cx, 0); cx < sx; cx++, x++)
+ for (int cy = 0, y = subofsy(cy, 0); cy < sy; cy++, y++) band[y][x].m = putcolourmap[band[y][x].m];
}
void pcxwrite::writeheader()
@@ -228,12 +216,12 @@
header.window[3] = totaly - 1;
header.screen[1] = totaly - 1;
- #ifdef GRFCODEC_BIG_ENDIAN
- pcxheader le_header = header;
- be_swapheader(le_header);
- #else
- pcxheader& le_header = header;
- #endif
+#ifdef GRFCODEC_BIG_ENDIAN
+ pcxheader le_header = header;
+ be_swapheader(le_header);
+#else
+ pcxheader &le_header = header;
+#endif
cfwrite("writing pcx header", &le_header, sizeof(pcxheader), 1, curfile);
fseek(curfile, oldpos, SEEK_SET);
}
@@ -257,10 +245,9 @@
/*void pcxwrite::setpalette(FILE *palfile)
{
- cfread(palette, 1, 768, palfile);
+ cfread(palette, 1, 768, palfile);
}*/
-
/***********************\
* *
* class pcxread *
@@ -274,7 +261,7 @@
void pcxread::filestart(bool paletted)
{
- if (!paletted){
+ if (!paletted) {
fprintf(stderr, "GRFCodec supports only paletted PCX files.\n");
exit(2);
}
@@ -288,15 +275,15 @@
if (y + sy > pcxread::sy) {
printf("\n%s: Error: Sprite y extends beyond end of the spritesheet.\nSpritesheet has %d lines, sprite wants %d..%d\n.",
- this->filename(), pcxread::sy, y, y + sy - 1);
+ this->filename(), pcxread::sy, y, y + sy - 1);
exit(2);
}
- if (sy > bandlines) { // don't have enough lines in memory, read rest
+ if (sy > bandlines) { // don't have enough lines in memory, read rest
alloclines(sy);
}
- if (y > totaly) { // doesn't start right at the top -> delete extra lines
+ if (y > totaly) { // doesn't start right at the top -> delete extra lines
expirelines(y - totaly);
totaly = y;
}
@@ -333,29 +320,31 @@
fprintf(stderr, "%s: Cannot read truecolour PCX files!\n", this->filename());
exit(2);
}
- if ( (header.bpp != 8) || (header.nplanes != 1) ) {
+ if ((header.bpp != 8) || (header.nplanes != 1)) {
fprintf(stderr, "%s: PCX file is not a 256 colour file!\n", this->filename());
exit(2);
}
- fseek(curfile,-768,SEEK_END);
+ fseek(curfile, -768, SEEK_END);
U8 palette[768];
- if (fread(palette,1,768,curfile) != 768 ) {
+ if (fread(palette, 1, 768, curfile) != 768) {
fprintf(stderr, "%s: Could not read palette from PCX file!\n", this->filename());
exit(2);
}
- int i=0;
- for(;i<NUM_PALS;i++)
- if(!memcmp(palette,defaultpalettes[i],768)) break;
+ int i = 0;
+ for (; i < NUM_PALS; i++)
+ if (!memcmp(palette, defaultpalettes[i], 768)) break;
- if ( i == NUM_PALS ) {
- if ( _force ) {
+ if (i == NUM_PALS) {
+ if (_force) {
if (!_quiet) fprintf(stderr, "%s: Warning: Encoding despite unrecognized palette.\n", this->filename());
} else {
- fprintf(stderr, "%s: Error: Unrecognized palette, aborting.\n"
- "Specify -f on the command line to override this check.\n", this->filename());
+ fprintf(stderr,
+ "%s: Error: Unrecognized palette, aborting.\n"
+ "Specify -f on the command line to override this check.\n",
+ this->filename());
exit(2);
}
}
@@ -372,4 +361,3 @@
thisbandy = 0;
}
-
diff --git a/src/pcxsprit.h b/src/pcxsprit.h
--- a/src/pcxsprit.h
+++ b/src/pcxsprit.h
@@ -1,55 +1,78 @@
#ifndef _PCXSPRIT_H
#define _PCXSPRIT_H
-
#include "pcxfile.h"
#include "sprites.h"
-class pcxwrite : public pcxfile, public spritestorage {
- public:
+class pcxwrite : public pcxfile, public spritestorage
+{
+ public:
pcxwrite(multifile *mfile);
virtual void filedone(int final);
virtual void filestart(bool paletted);
- virtual void newsprite() {spriteno++; };
+ virtual void newsprite()
+ {
+ spriteno++;
+ };
virtual void startsubimage(int x, int y, int sx, int sy);
virtual void setline(CommonPixel *band);
virtual void setsize(int sx, int sy)
- { startsubimage(-1, -1, sx, sy); };
- virtual int curspritex() {return subimagex();};
- virtual int curspritey() {return subimagey();};
- virtual const char *filename(){return pcxfile::filename();};
- virtual void newrow() { newline(); };
- virtual void nextpixel(CommonPixel colour) { streamputpixel(colour); };
- virtual void spritedone() { endsubimage(); };
+ {
+ startsubimage(-1, -1, sx, sy);
+ };
+ virtual int curspritex()
+ {
+ return subimagex();
+ };
+ virtual int curspritey()
+ {
+ return subimagey();
+ };
+ virtual const char *filename()
+ {
+ return pcxfile::filename();
+ };
+ virtual void newrow()
+ {
+ newline();
+ };
+ virtual void nextpixel(CommonPixel colour)
+ {
+ streamputpixel(colour);
+ };
+ virtual void spritedone()
+ {
+ endsubimage();
+ };
virtual void spritedone(int sx, int sy);
-
void writeheader();
void writepal();
void setcolours(U8 bg, U8 bord, int skip);
void setpalette(const U8 *palette);
- //void setpalette(FILE *palfile);
+ // void setpalette(FILE *palfile);
- protected:
+ protected:
const U8 *palette;
- private:
+ private:
void showspriteno();
CommonPixel background;
CommonPixel border;
int borderskip, spriteno, lastdigitx;
- pcxwrite(const pcxwrite&);//not copyable: pcxfile::colormap
- void operator=(const pcxwrite&);//not assignable: pcxfile::colormap
+ pcxwrite(const pcxwrite &); // not copyable: pcxfile::colormap
+ void operator=(const pcxwrite &); // not assignable: pcxfile::colormap
};
-class pcxread : public pcxfile {
- public:
+class pcxread : public pcxfile
+{
+ public:
pcxread(singlefile *mfile);
virtual void filestart(bool paletted);
@@ -59,10 +82,10 @@
void readheader();
- private:
+ private:
multifile *mfile;
- pcxread(const pcxread&); //not copyable: pcxfile::colormap
- void operator=(const pcxread&); //not assignable: pcx::colormap
+ pcxread(const pcxread &); // not copyable: pcxfile::colormap
+ void operator=(const pcxread &); // not assignable: pcx::colormap
};
#endif /* _PCXSPRIT_H */
diff --git a/src/pngsprit.cpp b/src/pngsprit.cpp
--- a/src/pngsprit.cpp
+++ b/src/pngsprit.cpp
@@ -10,17 +10,16 @@
* *
\***********************/
-pngwrite::pngwrite(multifile *mfile, bool paletted): pcxwrite(mfile), png(NULL), info(NULL)
+pngwrite::pngwrite(multifile *mfile, bool paletted) : pcxwrite(mfile), png(NULL), info(NULL)
{
this->paletted = paletted;
// Hopefully 8MiB should suffice
- cache.reserve(8*1024*1024);
+ cache.reserve(8 * 1024 * 1024);
}
pngwrite::~pngwrite()
{
// Make sure we clean up if grfcodec terminates prematurely
- if (png)
- png_destroy_write_struct(&png, &info);
+ if (png) png_destroy_write_struct(&png, &info);
}
void pngwrite::filestart(bool)
@@ -30,34 +29,33 @@
info = png_create_info_struct(png);
if (!png || !info) {
printf("%s: Agh! Unable to initialize libpng!\n", this->filename());
- exit (254);
+ exit(254);
}
// Set the error out point
if (setjmp(png_jmpbuf(png))) {
- exit (252);
+ exit(252);
}
}
void pngwrite::filedone(int final)
{
// Do not save the png until the grf file has been processed
- if (final && png && cache.size() > 0)
- {
+ if (final && png && cache.size() > 0) {
// Initialise libpng io
png_init_io(png, curfile);
if (paletted) {
// Store the final image's size
- png_set_IHDR(png, info, sx, totaly, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+ png_set_IHDR(png, info, sx, totaly, 8, PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
// Set the palette data
- png_set_PLTE(png, info, (png_color*)pcxwrite::palette, 256);
+ png_set_PLTE(png, info, (png_color *)pcxwrite::palette, 256);
} else {
// Store the final image's size
- png_set_IHDR(png, info, sx, totaly, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
- PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+ png_set_IHDR(png, info, sx, totaly, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
+ PNG_FILTER_TYPE_DEFAULT);
}
// Write the the png header
@@ -68,8 +66,7 @@
png_set_flush(png, 64);
// Write the image data
- for (unsigned int i = 0, j = cache.size(); i < j; i += sx * (paletted ? 1 : 4))
- png_write_row(png, (png_byte*)&cache[i]);
+ for (unsigned int i = 0, j = cache.size(); i < j; i += sx * (paletted ? 1 : 4)) png_write_row(png, (png_byte *)&cache[i]);
// Finalise writing
png_write_end(png, info);
@@ -100,8 +97,7 @@
void pngwrite::encodebytes(const CommonPixel *buffer, int num)
{
- for (int i = 0; i < num; i++)
- this->encodebytes(buffer[i], 1);
+ for (int i = 0; i < num; i++) this->encodebytes(buffer[i], 1);
}
/***********************\
@@ -110,14 +106,13 @@
* *
\***********************/
-pngread::pngread(singlefile *mfile): pcxread(mfile), png(NULL), info(NULL), line_buffer(NULL), whole_image(NULL)
+pngread::pngread(singlefile *mfile) : pcxread(mfile), png(NULL), info(NULL), line_buffer(NULL), whole_image(NULL)
{
}
pngread::~pngread()
{
- if (png)
- png_destroy_read_struct(&png, &info, NULL);
+ if (png) png_destroy_read_struct(&png, &info, NULL);
delete[] line_buffer;
if (whole_image != NULL) {
@@ -157,7 +152,7 @@
void pngread::filestart(bool paletted)
{
- this->paletted=paletted;
+ this->paletted = paletted;
if (png) {
// Technically this should never be reached but as a safety net
png_read_end(png, info);
@@ -168,12 +163,12 @@
info = png_create_info_struct(png);
if (!png || !info) {
printf("%s: Agh! Unable to initialize libpng!\n", this->filename());
- exit (254);
+ exit(254);
}
// Set the error out point
if (setjmp(png_jmpbuf(png))) {
- exit (252);
+ exit(252);
}
// Reset the file back to the start
@@ -200,7 +195,8 @@
fprintf(stderr, "%s: Cannot read true colour PNG files!\n", this->filename());
exit(2);
}
- if (png_get_channels(png, info) != 1 || png_get_bit_depth(png, info) != 8 || png_get_color_type(png, info) != PNG_COLOR_TYPE_PALETTE) {
+ if (png_get_channels(png, info) != 1 || png_get_bit_depth(png, info) != 8 ||
+ png_get_color_type(png, info) != PNG_COLOR_TYPE_PALETTE) {
fprintf(stderr, "%s: Cannot read non-paletted PNG files!\n", this->filename());
exit(2);
}
@@ -209,23 +205,25 @@
int entries;
U8 *palette; // Compatible format RGB
- png_get_PLTE(png, info, (png_color**)&palette, &entries);
+ png_get_PLTE(png, info, (png_color **)&palette, &entries);
if (entries != 256) {
fprintf(stderr, "%s: PNG file is not a 256 colour file!\n", this->filename());
exit(2);
}
// Look for a matching palette
- int i=0;
- for( ; i<NUM_PALS; i++)
- if(!memcmp(palette, defaultpalettes[i], 768)) break;
+ int i = 0;
+ for (; i < NUM_PALS; i++)
+ if (!memcmp(palette, defaultpalettes[i], 768)) break;
if (i == NUM_PALS) {
- if ( _force ) {
+ if (_force) {
if (!_quiet) fprintf(stderr, "%s: Warning: Encoding despite unrecognized palette.\n", this->filename());
} else {
- fprintf(stderr, "%s: Error: Unrecognized palette, aborting.\n"
- "Specify -f on the command line to override this check.\n", this->filename());
+ fprintf(stderr,
+ "%s: Error: Unrecognized palette, aborting.\n"
+ "Specify -f on the command line to override this check.\n",
+ this->filename());
exit(2);
}
}
@@ -244,13 +242,13 @@
if (png_get_interlace_type(png, info) == PNG_INTERLACE_NONE) {
/* Read image row by row */
- line_buffer = new U8[sx * (paletted?1:4)];
+ line_buffer = new U8[sx * (paletted ? 1 : 4)];
} else {
/* Interlaced images can only be read as a whole */
read_row = 0;
- whole_image = new U8*[sy];
+ whole_image = new U8 *[sy];
for (int i = 0; i < sy; ++i) {
- whole_image[i] = new U8[sx * (paletted?1:4)];
+ whole_image[i] = new U8[sx * (paletted ? 1 : 4)];
}
png_read_image(png, whole_image);
}
diff --git a/src/pngsprit.h b/src/pngsprit.h
--- a/src/pngsprit.h
+++ b/src/pngsprit.h
@@ -6,41 +6,43 @@
#include <png.h>
#include <vector>
-class pngwrite: public pcxwrite {
- public:
+class pngwrite : public pcxwrite
+{
+ public:
pngwrite(multifile *mfile, bool paletted);
~pngwrite();
void filestart(bool);
void filedone(int final);
- protected:
+ protected:
void encodebytes(const CommonPixel &pixel, int num);
void encodebytes(const CommonPixel *buffer, int num);
- private:
- pngwrite(const pngwrite&);
- void operator=(const pngwrite&);
+ private:
+ pngwrite(const pngwrite &);
+ void operator=(const pngwrite &);
- private:
+ private:
png_struct *png;
png_info *info;
std::vector<U8> cache;
};
-class pngread: public pcxread {
- public:
- pngread(singlefile * mfile);
+class pngread : public pcxread
+{
+ public:
+ pngread(singlefile *mfile);
~pngread();
void filestart(bool paletted);
void setline(CommonPixel *band);
- private:
- pngread(const pngread&);
- void operator=(const pngread&);
+ private:
+ pngread(const pngread &);
+ void operator=(const pngread &);
- private:
+ private:
multifile *mfile;
png_struct *png;
png_info *info;
diff --git a/src/pseudo.cpp b/src/pseudo.cpp
--- a/src/pseudo.cpp
+++ b/src/pseudo.cpp
@@ -19,11 +19,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<sstream>
-#include<iostream>
-#include<iomanip>
-#include<cstdarg>
-#include<cstdio>
+#include <sstream>
+#include <iostream>
+#include <iomanip>
+#include <cstdarg>
+#include <cstdio>
/* If your compiler errors on the following lines, boost is not
* properly installed.
@@ -40,524 +40,599 @@
#define foreach BOOST_FOREACH
using namespace std;
-#include"nforenum.h"
-#include"pseudo.h"
-#include"globals.h"
-#include"messages.h"
-#include"inlines.h"
-#include"command.h"
-#include"utf8.h"
+#include "nforenum.h"
+#include "pseudo.h"
+#include "globals.h"
+#include "messages.h"
+#include "inlines.h"
+#include "command.h"
+#include "utf8.h"
extern int NFOversion;
bool TrySetVersion(int);
-//QESC: \n or \xx
+// QESC: \n or \xx
// \" and \\ are implicit in TEXT.
-//QEXT: \Uxxxx, usually.
-enum{HEX,TEXT,UTF8,ENDQUOTE,QESC,QEXT,NQEXT,NOBREAK=0x80};
+// QEXT: \Uxxxx, usually.
+enum {
+ HEX,
+ TEXT,
+ UTF8,
+ ENDQUOTE,
+ QESC,
+ QEXT,
+ NQEXT,
+ NOBREAK = 0x80
+};
-
-#define cur_pos() ((uint)out.str().length()-1)
+#define cur_pos() ((uint)out.str().length() - 1)
#define next_pos() ((uint)out.str().length())
#define cur_context() (context[cur_pos()])
-#define ProcessWhite()\
- if(white!=""){\
- if(white[white.length()-1]==' '&&!GetState(CONVERTONLY))white=white.substr(0,white.length()-1);\
- if((cur_context()!=""&&cur_context().find('\n')!=NPOS)||GetState(CONVERTONLY))cur_context()+=white;\
- white="";\
- }else ((void)0)
+#define ProcessWhite() \
+ if (white != "") { \
+ if (white[white.length() - 1] == ' ' && !GetState(CONVERTONLY)) white = white.substr(0, white.length() - 1); \
+ if ((cur_context() != "" && cur_context().find('\n') != NPOS) || GetState(CONVERTONLY)) cur_context() += white; \
+ white = ""; \
+ } else \
+ ((void)0)
int FindEscape(string str);
string FindEscape(char, int);
string FindEscape(char, int, uint);
-PseudoSprite::PseudoSprite(const string&sprite,int oldspritenum):
- orig(sprite),
- valid(true),
- useorig(false),
- oldspritenum(oldspritenum),
- extract_offs(0)
+PseudoSprite::PseudoSprite(const string& sprite, int oldspritenum)
+ : orig(sprite), valid(true), useorig(false), oldspritenum(oldspritenum), extract_offs(0)
{
istringstream in(sprite);
ostringstream out;
char ch;
- bool newline=true;
+ bool newline = true;
string white;
- while(in){
- switch(in.peek()){
- case EOF:continue;
- case'"':
- TrySetVersion(5);
- in.ignore();
- ProcessWhite();
- while(true){
- if(!in.get(ch)){
- IssueMessage(0,UNTERMINATED_STRING);
+ while (in) {
+ switch (in.peek()) {
+ case EOF:
+ continue;
+ case '"':
+ TrySetVersion(5);
+ in.ignore();
+ ProcessWhite();
+ while (true) {
+ if (!in.get(ch)) {
+ IssueMessage(0, UNTERMINATED_STRING);
+ Invalidate();
+ return;
+ }
+ if (ch == '"') break;
+ if (ch == '\\' && TrySetVersion(7)) {
+ switch (ch = (char)in.get()) {
+ case 'n':
+ ch = '\r'; // TTD uses Mac-style linefeeds (\r)
+ break;
+ case '"':
+ case '\\':
+ break;
+ case 'U': {
+ uint x = ReadHex(in, 4);
+ if (!in) {
+ IssueMessage(0, INVALID_EXTENSION);
+ Invalidate();
+ return;
+ }
+ if (x > 0x7FF) {
+ SetUTF8(next_pos(), 3);
+ out.write(GetUtf8Encode(x).c_str(), 3);
+ LinkBytes(3, out.str().length());
+ continue;
+ } else if (x > 0x7F) {
+ SetUTF8(next_pos(), 2);
+ out.write(GetUtf8Encode(x).c_str(), 2);
+ LinkBytes(2, out.str().length());
+ continue;
+ } else {
+ out.put(ch);
+ LinkBytes(1, out.str().length());
+ continue;
+ }
+ break;
+ }
+ default:
+ in.unget();
+ ch = (char)ReadHex(in, 2);
+ if (!in) {
+ IssueMessage(0, INVALID_EXTENSION);
+ Invalidate();
+ return;
+ }
+ break;
+ }
+ }
+ SetText(next_pos());
+ newline = false;
+ out.put(ch);
+ }
+ break;
+ case '\\':
+ if (TrySetVersion(7)) {
+ ProcessWhite();
+ newline = false;
+ in.ignore();
+ uint x;
+ switch (in.get()) {
+ case 'b':
+ if (in.peek() == '*') { // \b*
+ x = ReadValue(in.ignore(), _BX_);
+ if (!in || x > 0xFFFF) break; // invalid
+ if (x > 0xFE) {
+ out.put('\xFF').write(itoa(x, 256, 2).c_str(), 2);
+ LinkBytes(3, out.str().length());
+ } else {
+ out.put((char)x);
+ LinkBytes(1, out.str().length());
+ }
+ continue;
+ }
+ x = ReadValue(in, _B_);
+ if (!in || x > 0xFF) break; // invalid
+ out.put((char)x);
+ LinkBytes(1, out.str().length());
+ continue;
+ case 'w':
+ x = ReadValue(in, _W_);
+ if (!in || x > 0xFFFF) break; // invalid
+ out.write(itoa(x, 256, 2).c_str(), 2);
+ LinkBytes(2, out.str().length());
+ continue;
+ case 'd':
+ x = ReadValue(in, _D_);
+ if (!in) break;
+ out.write(itoa(x, 256, 4).c_str(), 4);
+ LinkBytes(4, out.str().length());
+ continue;
+ default: {
+ in.unget();
+ string esc;
+ in >> esc;
+ int byte = FindEscape(esc);
+ if (byte == -1) break;
+ out.put((char)byte);
+ LinkBytes(1, out.str().length());
+ continue;
+ }
+ }
+
+ IssueMessage(0, INVALID_EXTENSION);
Invalidate();
return;
}
- if(ch=='"')break;
- if(ch=='\\'&&TrySetVersion(7)){
- switch(ch=(char)in.get()){
- case'n':
- ch='\r';//TTD uses Mac-style linefeeds (\r)
- break;
- case'"':
- case'\\':
- break;
- case'U':{
- uint x=ReadHex(in,4);
- if(!in){
- IssueMessage(0,INVALID_EXTENSION);
- Invalidate();
- return;
+ // fall through to default when !GetState(EXTENSIONS)
+ default:
+ if (is_comment(in)) {
+ string comment;
+ getline(in, comment);
+ comment = white + comment;
+ white = "";
+ if (is_command(comment) || parse_comment(comment)) {
+ if (newline) {
+ AddComment(comment, cur_pos());
+ } else {
+ TrailComment(comment, cur_pos());
}
- if(x>0x7FF){
- SetUTF8(next_pos(),3);
- out.write(GetUtf8Encode(x).c_str(),3);
- LinkBytes(3,out.str().length());
- continue;
- }else if(x>0x7F){
- SetUTF8(next_pos(),2);
- out.write(GetUtf8Encode(x).c_str(),2);
- LinkBytes(2,out.str().length());
- continue;
- }else{
- out.put(ch);
- LinkBytes(1,out.str().length());
- continue;
- }
- break;
- }default:
- in.unget();
- ch=(char)ReadHex(in,2);
- if(!in){
- IssueMessage(0,INVALID_EXTENSION);
- Invalidate();
- return;
- }
- break;
}
+ newline = true;
+ } else if (isspace(in.peek()))
+ if (in.peek() == '\n' && !GetState(CONVERTONLY)) {
+ if (newline) AddBlank(cur_pos());
+ newline = true;
+ white = "";
+ in.ignore();
+ } else
+ white += (char)in.get();
+ else {
+ ch = (char)ReadHex(in, 2);
+ if (!in) {
+ in.clear();
+ IssueMessage(0, INVALID_CHARACTER, in.peek());
+ Invalidate();
+ return;
+ }
+ ProcessWhite();
+ newline = false;
+ out.put(ch);
}
- SetText(next_pos());
- newline=false;
- out.put(ch);
- }
- break;
- case'\\':
- if(TrySetVersion(7)){
- ProcessWhite();
- newline=false;
- in.ignore();
- uint x;
- switch(in.get()){
- case'b':
- if(in.peek()=='*'){// \b*
- x = ReadValue(in.ignore(), _BX_);
- if(!in||x>0xFFFF)break;//invalid
- if(x>0xFE){
- out.put('\xFF').write(itoa(x,256,2).c_str(),2);
- LinkBytes(3,out.str().length());
- }else{
- out.put((char)x);
- LinkBytes(1,out.str().length());
- }
- continue;
- }
- x = ReadValue(in, _B_);
- if(!in||x>0xFF)break;//invalid
- out.put((char)x);
- LinkBytes(1,out.str().length());
- continue;
- case'w':
- x = ReadValue(in, _W_);
- if(!in||x>0xFFFF)break;//invalid
- out.write(itoa(x,256,2).c_str(),2);
- LinkBytes(2,out.str().length());
- continue;
- case'd':
- x = ReadValue(in, _D_);
- if(!in)break;
- out.write(itoa(x,256,4).c_str(),4);
- LinkBytes(4,out.str().length());
- continue;
- default:{
- in.unget();
- string esc;
- in>>esc;
- int byte = FindEscape(esc);
- if(byte == -1)
- break;
- out.put((char)byte);
- LinkBytes(1,out.str().length());
- continue;
- }}
-
- IssueMessage(0,INVALID_EXTENSION);
- Invalidate();
- return;
- }
- //fall through to default when !GetState(EXTENSIONS)
- default:
- if (is_comment(in)) {
- string comment;
- getline(in,comment);
- comment=white+comment;
- white="";
- if(is_command(comment)||parse_comment(comment)) {
- if(newline) {
- AddComment(comment,cur_pos());
- } else {
- TrailComment(comment,cur_pos());
- }
- }
- newline=true;
- } else if(isspace(in.peek()))
- if(in.peek()=='\n'&&!GetState(CONVERTONLY)){
- if(newline)AddBlank(cur_pos());
- newline=true;
- white="";
- in.ignore();
- }else
- white+=(char)in.get();
- else{
- ch=(char)ReadHex(in,2);
- if(!in){
- in.clear();
- IssueMessage(0,INVALID_CHARACTER,in.peek());
- Invalidate();
- return;
- }
- ProcessWhite();
- newline=false;
- out.put(ch);
- }
}
}
- packed=out.str();
- if(white!=""&&Length()){
- if(white[white.length()-1]==' '&&!GetState(CONVERTONLY))white=white.substr(0,white.length()-1);
- if((cur_context()!=""&&cur_context().find('\n')!=NPOS)||GetState(CONVERTONLY))cur_context()+=white;
- white="";
+ packed = out.str();
+ if (white != "" && Length()) {
+ if (white[white.length() - 1] == ' ' && !GetState(CONVERTONLY)) white = white.substr(0, white.length() - 1);
+ if ((cur_context() != "" && cur_context().find('\n') != NPOS) || GetState(CONVERTONLY)) cur_context() += white;
+ white = "";
};
}
-void PseudoSprite::LinkBytes(int count, size_t e){
+void PseudoSprite::LinkBytes(int count, size_t e)
+{
int end = (int)e;
- for(int i=end-count,high=0; i<end; i++,high++)
- linkage[i]=high<<8|count;
+ for (int i = end - count, high = 0; i < end; i++, high++) linkage[i] = high << 8 | count;
}
-bool PseudoSprite::ignorelinkage=false;
+bool PseudoSprite::ignorelinkage = false;
-void PseudoSprite::CheckLinkage(int ofs, int count)const{
- if(!ignorelinkage) {
- for(int i=0;i<count;i++) {
- if(linkage[ofs+i] != 0 && linkage[ofs+i] != (i<<8 | count)) {
- IssueMessage(WARNING2,EXTENSION_MISMATCH,ofs+i,((linkage[ofs+i]>>8)&0xFF)+1,linkage[ofs+i]&0xFF,i+1,count);
+void PseudoSprite::CheckLinkage(int ofs, int count) const
+{
+ if (!ignorelinkage) {
+ for (int i = 0; i < count; i++) {
+ if (linkage[ofs + i] != 0 && linkage[ofs + i] != (i << 8 | count)) {
+ IssueMessage(WARNING2, EXTENSION_MISMATCH, ofs + i, ((linkage[ofs + i] >> 8) & 0xFF) + 1,
+ linkage[ofs + i] & 0xFF, i + 1, count);
return;
}
}
}
}
-bool PseudoSprite::MayBeSprite(const string&sprite){
+bool PseudoSprite::MayBeSprite(const string& sprite)
+{
istringstream in(sprite);
char ch;
- while(in.get(ch)){
- if(ch=='"')return true;
- if(COMMENT.find(ch)!=NPOS){
- in.ignore(INT_MAX,'\n');
+ while (in.get(ch)) {
+ if (ch == '"') return true;
+ if (COMMENT.find(ch) != NPOS) {
+ in.ignore(INT_MAX, '\n');
continue;
}
- if(isspace(ch)||string(VALID_PSEUDO).find(ch)==NPOS)continue;
+ if (isspace(ch) || string(VALID_PSEUDO).find(ch) == NPOS) continue;
return true;
}
return false;
}
-uint PseudoSprite::Length()const{return(uint)(valid?packed.length():0);}
+uint PseudoSprite::Length() const
+{
+ return (uint)(valid ? packed.length() : 0);
+}
-PseudoSprite&PseudoSprite::SetHex(uint i){beauty[i]=HEX;return*this;}
-PseudoSprite&PseudoSprite::SetHex(uint i,uint num){while(num--)beauty[i++]=HEX;return*this;}
-PseudoSprite&PseudoSprite::SetAllHex(){beauty.clear();return*this;}
-PseudoSprite&PseudoSprite::SetUTF8(uint i,uint len){
- while(--len)
- beauty[i++]=uchar(UTF8|NOBREAK);
- beauty[i++]=UTF8;
- return*this;
+PseudoSprite& PseudoSprite::SetHex(uint i)
+{
+ beauty[i] = HEX;
+ return *this;
}
-PseudoSprite&PseudoSprite::SetText(uint i){
- if(i&&GetState(CONVERTONLY)){
- if((beauty[i-1]&~NOBREAK)==ENDQUOTE&&context[i-1]=="")context[i-1]=" ";
+PseudoSprite& PseudoSprite::SetHex(uint i, uint num)
+{
+ while (num--) beauty[i++] = HEX;
+ return *this;
+}
+PseudoSprite& PseudoSprite::SetAllHex()
+{
+ beauty.clear();
+ return *this;
+}
+PseudoSprite& PseudoSprite::SetUTF8(uint i, uint len)
+{
+ while (--len) beauty[i++] = uchar(UTF8 | NOBREAK);
+ beauty[i++] = UTF8;
+ return *this;
+}
+PseudoSprite& PseudoSprite::SetText(uint i)
+{
+ if (i && GetState(CONVERTONLY)) {
+ if ((beauty[i - 1] & ~NOBREAK) == ENDQUOTE && context[i - 1] == "") context[i - 1] = " ";
}
- beauty[i]=TEXT;
- return*this;
+ beauty[i] = TEXT;
+ return *this;
}
-PseudoSprite&PseudoSprite::SetText(uint i,uint num){
- for(uint j=i+num-1;i<j;i++)SetText(i);
+PseudoSprite& PseudoSprite::SetText(uint i, uint num)
+{
+ for (uint j = i + num - 1; i < j; i++) SetText(i);
return SetEot(i);
}
-PseudoSprite&PseudoSprite::SetOpByte (uint i, char action) {
+PseudoSprite& PseudoSprite::SetOpByte(uint i, char action)
+{
string s = FindEscape(action, ExtractByte(i));
if (s != "") SetEscape(i, false, s, 1);
return *this;
}
-PseudoSprite&PseudoSprite::SetPositionalOpByte (uint i, char action) {
+PseudoSprite& PseudoSprite::SetPositionalOpByte(uint i, char action)
+{
string s = FindEscape(action, ExtractByte(i), i);
if (s != "") SetEscape(i, false, s, 1);
return *this;
}
-PseudoSprite&PseudoSprite::SetDate(uint i, uint num) {
- assert(num==1 || num==2 || num==4);
- switch(num){
- case 1:
- return SetEscape(i, false, mysprintf(" \\b%d", 1920+ExtractByte(i)), 1);
- case 2:{
- date::ymd_type ymd = (date(1920,1,1) + days(ExtractWord(i))).year_month_day();
- ushort y = ymd.year, m = ymd.month, d = ymd.day;
- return SetEscape(i, false, mysprintf(" \\w%d/%d/%d", y, m, d), 2);
- } case 4: {
- const int min = 511340, // == PseudoSprite("\\d1400-1-1", 0).ExtractDword(0)
- max = 3652424, // == PseudoSprite("\\d9999-12-31", 0).ExtractDword(0)
- base = 701265; // == PseudoSprite("\\d1920-1-1", 0).ExtractDword(0)
- int yearmod = 0;
- int val = ExtractDword(i);
- while (val < min) {
- val += 365*400 + 97;
- yearmod -= 400;
+PseudoSprite& PseudoSprite::SetDate(uint i, uint num)
+{
+ assert(num == 1 || num == 2 || num == 4);
+ switch (num) {
+ case 1:
+ return SetEscape(i, false, mysprintf(" \\b%d", 1920 + ExtractByte(i)), 1);
+ case 2: {
+ date::ymd_type ymd = (date(1920, 1, 1) + days(ExtractWord(i))).year_month_day();
+ ushort y = ymd.year, m = ymd.month, d = ymd.day;
+ return SetEscape(i, false, mysprintf(" \\w%d/%d/%d", y, m, d), 2);
}
- while (val > max) {
- val -= 365*400 + 97;
- yearmod += 400;
+ case 4: {
+ const int min = 511340, // == PseudoSprite("\\d1400-1-1", 0).ExtractDword(0)
+ max = 3652424, // == PseudoSprite("\\d9999-12-31", 0).ExtractDword(0)
+ base = 701265; // == PseudoSprite("\\d1920-1-1", 0).ExtractDword(0)
+ int yearmod = 0;
+ int val = ExtractDword(i);
+ while (val < min) {
+ val += 365 * 400 + 97;
+ yearmod -= 400;
+ }
+ while (val > max) {
+ val -= 365 * 400 + 97;
+ yearmod += 400;
+ }
+ date::ymd_type ymd = (date(1920, 1, 1) + days(val - base)).year_month_day();
+ uint y = ymd.year + yearmod, m = ymd.month, d = ymd.day;
+ return SetEscape(i, false, mysprintf(" \\d%d/%d/%d", y, m, d), 4);
}
- date::ymd_type ymd = (date(1920,1,1) + days(val-base)).year_month_day();
- uint y = ymd.year+yearmod, m = ymd.month, d = ymd.day;
- return SetEscape(i, false, mysprintf(" \\d%d/%d/%d", y, m, d), 4);
- }}
+ }
return SetDec(i, num);
}
-PseudoSprite&PseudoSprite::SetBE(uint i, uint num) {
- assert(num>0 && num<5);
+PseudoSprite& PseudoSprite::SetBE(uint i, uint num)
+{
+ assert(num > 0 && num < 5);
switch (num) {
- case 2:
- return SetEscape(i, false, mysprintf(" \\wx%x", ExtractWord(i)), 2);
- case 3:
- return SetEscape(i, false, mysprintf(" \\b*x%x", ExtractExtended(i)), ExtendedLen(i));
- case 4:
- return SetEscape(i, false, mysprintf(" \\dx%x", ExtractDword(i)), 4);
+ case 2:
+ return SetEscape(i, false, mysprintf(" \\wx%x", ExtractWord(i)), 2);
+ case 3:
+ return SetEscape(i, false, mysprintf(" \\b*x%x", ExtractExtended(i)), ExtendedLen(i));
+ case 4:
+ return SetEscape(i, false, mysprintf(" \\dx%x", ExtractDword(i)), 4);
}
return SetHex(i, num);
}
-PseudoSprite&PseudoSprite::SetDec(uint i, uint num) {
- assert(num>0 && num<5);
+PseudoSprite& PseudoSprite::SetDec(uint i, uint num)
+{
+ assert(num > 0 && num < 5);
switch (num) {
- case 1:
- return SetEscape(i, false, mysprintf(" \\b%d", ExtractByte(i)), 1);
- case 2:
- return SetEscape(i, false, mysprintf(" \\w%d", ExtractWord(i)), 2);
- case 3:
- return SetEscape(i, false, mysprintf(" \\b*%d", ExtractExtended(i)), ExtendedLen(i));
- case 4:
- return SetEscape(i, false, mysprintf(" \\d%d", ExtractDword(i)), 4);
+ case 1:
+ return SetEscape(i, false, mysprintf(" \\b%d", ExtractByte(i)), 1);
+ case 2:
+ return SetEscape(i, false, mysprintf(" \\w%d", ExtractWord(i)), 2);
+ case 3:
+ return SetEscape(i, false, mysprintf(" \\b*%d", ExtractExtended(i)), ExtendedLen(i));
+ case 4:
+ return SetEscape(i, false, mysprintf(" \\d%d", ExtractDword(i)), 4);
}
return SetHex(i, num);
}
-PseudoSprite&PseudoSprite::SetQEscape(uint i){
- if(GetState(USEESCAPES))
- beauty[i]=QESC;
+PseudoSprite& PseudoSprite::SetQEscape(uint i)
+{
+ if (GetState(USEESCAPES))
+ beauty[i] = QESC;
else
- SetHex(i);
- return*this;
+ SetHex(i);
+ return *this;
}
-PseudoSprite&PseudoSprite::SetQEscape(uint i,uint num){
- if(GetState(USEESCAPES)){
- while(num--)
- beauty[i++]=QESC;
+PseudoSprite& PseudoSprite::SetQEscape(uint i, uint num)
+{
+ if (GetState(USEESCAPES)) {
+ while (num--) beauty[i++] = QESC;
return *this;
}
- return SetHex(i,num);
+ return SetHex(i, num);
}
-PseudoSprite&PseudoSprite::SetEscape(uint i, bool quote, string ext, uint len){
- if(GetState(USEESCAPES)){
- while(len--){
- ext_print[i+len]="";
- beauty[i+len]=char(quote?QEXT:NQEXT);
+PseudoSprite& PseudoSprite::SetEscape(uint i, bool quote, string ext, uint len)
+{
+ if (GetState(USEESCAPES)) {
+ while (len--) {
+ ext_print[i + len] = "";
+ beauty[i + len] = char(quote ? QEXT : NQEXT);
}
- ext_print[i]=ext;
+ ext_print[i] = ext;
return *this;
}
- return SetHex(i,len);
+ return SetHex(i, len);
}
-PseudoSprite&PseudoSprite::SetEot(uint i){beauty[i]=ENDQUOTE;return*this;}
-PseudoSprite&PseudoSprite::SetEol(uint i,uint minbreaks,uint lead){
- if(GetState(CONVERTONLY)||GetState(LINEBREAKS)<minbreaks||i+1==Length())return*this;
- if(context[i].find_first_of('\n')==NPOS)context[i]+="\n";
- if(context[i][context[i].length()-1]=='\n')context[i]+=string(GetState(LEADINGSPACE,lead),' ');
- return*this;
+PseudoSprite& PseudoSprite::SetEot(uint i)
+{
+ beauty[i] = ENDQUOTE;
+ return *this;
}
-PseudoSprite&PseudoSprite::SetNoEol(uint i){
- if(GetState(LINEBREAKS))beauty[i]|=NOBREAK;return*this;
+PseudoSprite& PseudoSprite::SetEol(uint i, uint minbreaks, uint lead)
+{
+ if (GetState(CONVERTONLY) || GetState(LINEBREAKS) < minbreaks || i + 1 == Length()) return *this;
+ if (context[i].find_first_of('\n') == NPOS) context[i] += "\n";
+ if (context[i][context[i].length() - 1] == '\n') context[i] += string(GetState(LEADINGSPACE, lead), ' ');
+ return *this;
+}
+PseudoSprite& PseudoSprite::SetNoEol(uint i)
+{
+ if (GetState(LINEBREAKS)) beauty[i] |= NOBREAK;
+ return *this;
}
-PseudoSprite&PseudoSprite::SetGRFID(uint i){
- if(CanQuote((*this)[i])&&CanQuote((*this)[i+1])&&(*this)[i]!=0xFF&&(*this)[i+1]!=0xFF&&!GetState(HEXGRFID)){
+PseudoSprite& PseudoSprite::SetGRFID(uint i)
+{
+ if (CanQuote((*this)[i]) && CanQuote((*this)[i + 1]) && (*this)[i] != 0xFF && (*this)[i + 1] != 0xFF && !GetState(HEXGRFID)) {
SetText(i);
- SetText(i+1);
- }else{
+ SetText(i + 1);
+ } else {
SetHex(i);
- SetHex(i+1);
+ SetHex(i + 1);
}
- SetHex(i+2);
- SetHex(i+3);
+ SetHex(i + 2);
+ SetHex(i + 3);
SetNoEol(i);
- SetNoEol(i+1);
- SetNoEol(i+2);
- return*this;
+ SetNoEol(i + 1);
+ SetNoEol(i + 2);
+ return *this;
}
-PseudoSprite&PseudoSprite::SetByteAt(uint off,uint byte){
- VERIFY(off<packed.length(),off);
- assert(byte<0x100);
- packed[off]=(uchar)byte;
- SetHex(off); // Remove any escape the beautifier might have generated from the old value.
- return*this;
+PseudoSprite& PseudoSprite::SetByteAt(uint off, uint byte)
+{
+ VERIFY(off < packed.length(), off);
+ assert(byte < 0x100);
+ packed[off] = (uchar)byte;
+ SetHex(off); // Remove any escape the beautifier might have generated from the old value.
+ return *this;
}
-PseudoSprite&PseudoSprite::SetWordAt(uint off, uint word){
- VERIFY(off+1<packed.length(),off);
- assert(word<0x10000);
- packed[off]=(uchar)word;
- packed[off+1]=(uchar)(word>>8);
- SetHex(off,2); // Remove any escape the beautifier might have generated from the old value.
- return*this;
+PseudoSprite& PseudoSprite::SetWordAt(uint off, uint word)
+{
+ VERIFY(off + 1 < packed.length(), off);
+ assert(word < 0x10000);
+ packed[off] = (uchar)word;
+ packed[off + 1] = (uchar)(word >> 8);
+ SetHex(off, 2); // Remove any escape the beautifier might have generated from the old value.
+ return *this;
}
-PseudoSprite&PseudoSprite::SetDwordAt(uint off, uint dword){
- VERIFY(off+3<packed.length(),off);
- packed[off]=(uchar)dword;
- packed[off+1]=(uchar)(dword>>8);
- packed[off+2]=(uchar)(dword>>16);
- packed[off+3]=(uchar)(dword>>24);
- SetHex(off,4); // Remove any escape the beautifier might have generated from the old value.
- return*this;
+PseudoSprite& PseudoSprite::SetDwordAt(uint off, uint dword)
+{
+ VERIFY(off + 3 < packed.length(), off);
+ packed[off] = (uchar)dword;
+ packed[off + 1] = (uchar)(dword >> 8);
+ packed[off + 2] = (uchar)(dword >> 16);
+ packed[off + 3] = (uchar)(dword >> 24);
+ SetHex(off, 4); // Remove any escape the beautifier might have generated from the old value.
+ return *this;
}
-
-PseudoSprite&PseudoSprite::Append(uchar byte){
- context.resize(Length()+1);
- context[Length()]=context[Length()-1];
- context[Length()-1].clear();
- packed.append(1,byte);
- return*this;
+PseudoSprite& PseudoSprite::Append(uchar byte)
+{
+ context.resize(Length() + 1);
+ context[Length()] = context[Length() - 1];
+ context[Length() - 1].clear();
+ packed.append(1, byte);
+ return *this;
}
-PseudoSprite&PseudoSprite::ColumnAfter(uint i){
- context[i]+='\t';
- return*this;
+PseudoSprite& PseudoSprite::ColumnAfter(uint i)
+{
+ context[i] += '\t';
+ return *this;
}
-static uint(PseudoSprite::* const ExtractFuncs[])(uint)const=
- {NULL,&PseudoSprite::ExtractByte,&PseudoSprite::ExtractWord,&PseudoSprite::ExtractExtended,&PseudoSprite::ExtractDword};
+static uint (PseudoSprite::*const ExtractFuncs[])(uint) const = {
+ NULL, &PseudoSprite::ExtractByte, &PseudoSprite::ExtractWord, &PseudoSprite::ExtractExtended, &PseudoSprite::ExtractDword};
-uint PseudoSprite::ExtractVariable(uint offs,uint length)const{
- VERIFY((length&&length<5),length);
- return(this->*(ExtractFuncs[length]))(offs);
+uint PseudoSprite::ExtractVariable(uint offs, uint length) const
+{
+ VERIFY((length && length < 5), length);
+ return (this->*(ExtractFuncs[length]))(offs);
}
-uint PseudoSprite::ExtendedLen(uint offs)const{
- return ExtractByte(offs)!=0xFF?1:3;
+uint PseudoSprite::ExtendedLen(uint offs) const
+{
+ return ExtractByte(offs) != 0xFF ? 1 : 3;
}
-uint PseudoSprite::LinkSafeExtractByte(uint offs)const{
- VERIFY(IsValid(),IsValid());
- if(Length()<=offs)
- throw offs|1<<24;
- return(uchar)packed[offs];
+uint PseudoSprite::LinkSafeExtractByte(uint offs) const
+{
+ VERIFY(IsValid(), IsValid());
+ if (Length() <= offs) throw offs | 1 << 24;
+ return (uchar)packed[offs];
}
-uint PseudoSprite::ExtractByte(uint offs)const{
- CheckLinkage(offs,1);
+uint PseudoSprite::ExtractByte(uint offs) const
+{
+ CheckLinkage(offs, 1);
return LinkSafeExtractByte(offs);
}
-uint PseudoSprite::ExtractWord(uint offs)const{
- try{
- CheckLinkage(offs,2);
- return LinkSafeExtractByte(offs)|LinkSafeExtractByte(offs+1)<<8;
- }catch(unsigned int){
- throw offs|2<<24;
+uint PseudoSprite::ExtractWord(uint offs) const
+{
+ try
+ {
+ CheckLinkage(offs, 2);
+ return LinkSafeExtractByte(offs) | LinkSafeExtractByte(offs + 1) << 8;
+ }
+ catch (unsigned int)
+ {
+ throw offs | 2 << 24;
}
}
-uint PseudoSprite::ExtractExtended(uint offs)const{
- uint val=LinkSafeExtractByte(offs);
- if(val!=0xFF){
- CheckLinkage(offs,1);
+uint PseudoSprite::ExtractExtended(uint offs) const
+{
+ uint val = LinkSafeExtractByte(offs);
+ if (val != 0xFF) {
+ CheckLinkage(offs, 1);
return val;
}
- if(linkage[offs]!=0 && linkage[offs]!=1) {
- CheckLinkage(offs,3);
+ if (linkage[offs] != 0 && linkage[offs] != 1) {
+ CheckLinkage(offs, 3);
ignorelinkage = true;
}
- val = ExtractWord(offs+1);
+ val = ExtractWord(offs + 1);
ignorelinkage = false;
return val;
}
-uint PseudoSprite::ExtractDword(uint offs)const{
- try{
- CheckLinkage(offs,4);
- ignorelinkage=true;
- uint val = ExtractWord(offs)|ExtractWord(offs+2)<<16;
- ignorelinkage=false;
+uint PseudoSprite::ExtractDword(uint offs) const
+{
+ try
+ {
+ CheckLinkage(offs, 4);
+ ignorelinkage = true;
+ uint val = ExtractWord(offs) | ExtractWord(offs + 2) << 16;
+ ignorelinkage = false;
return val;
- }catch(unsigned int){
- throw offs|4<<24;
+ }
+ catch (unsigned int)
+ {
+ throw offs | 4 << 24;
}
}
-void PseudoSprite::AddComment(const string&str,uint i){
- if(i==(uint)-1)NoBeautify();
- else if(context[i]=="")context[i]+='\n'+str+'\n';
- else if(context[i][context[i].length()-1]=='\n')context[i]+=str+'\n';
- else{
- uint offs=(uint)context[i].find_last_of('\n')+1;
- context[i]=context[i].substr(0,offs)+str+context[i].substr(offs);
+void PseudoSprite::AddComment(const string& str, uint i)
+{
+ if (i == (uint) - 1)
+ NoBeautify();
+ else if (context[i] == "")
+ context[i] += '\n' + str + '\n';
+ else if (context[i][context[i].length() - 1] == '\n')
+ context[i] += str + '\n';
+ else {
+ uint offs = (uint)context[i].find_last_of('\n') + 1;
+ context[i] = context[i].substr(0, offs) + str + context[i].substr(offs);
}
}
-void PseudoSprite::TrailComment(const string&str,uint i){
- if(i==(uint)-1)NoBeautify();
- else if(context[i]=="")context[i]=str+'\n';
- else if(context[i][0]!='\n')return;
- else context[i]=str+'\n'+context[i];
+void PseudoSprite::TrailComment(const string& str, uint i)
+{
+ if (i == (uint) - 1)
+ NoBeautify();
+ else if (context[i] == "")
+ context[i] = str + '\n';
+ else if (context[i][0] != '\n')
+ return;
+ else
+ context[i] = str + '\n' + context[i];
}
-void PseudoSprite::AddBlank(uint i){
- if(i==(uint)-1)NoBeautify();
- else if(context[i]=="")context[i]="\n\n";
- else if(!Length())context[i]+='\n';
- else{
- string::size_type offs=context[i].find_first_of('\n');
- if(offs==NPOS||context[i].substr(offs,2)!="\n\n")
- context[i]=context[i].substr(0,offs)+'\n'+context[i].substr(offs);
+void PseudoSprite::AddBlank(uint i)
+{
+ if (i == (uint) - 1)
+ NoBeautify();
+ else if (context[i] == "")
+ context[i] = "\n\n";
+ else if (!Length())
+ context[i] += '\n';
+ else {
+ string::size_type offs = context[i].find_first_of('\n');
+ if (offs == NPOS || context[i].substr(offs, 2) != "\n\n")
+ context[i] = context[i].substr(0, offs) + '\n' + context[i].substr(offs);
}
}
-void PseudoSprite::NoBeautify(){
- useorig=true;
+void PseudoSprite::NoBeautify()
+{
+ useorig = true;
}
-ostream&operator<<(ostream&out,PseudoSprite&sprite){
+ostream& operator<<(ostream& out, PseudoSprite& sprite)
+{
sprite.output(out);
return out;
}
@@ -566,122 +641,124 @@
// http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html#ss7.3
// "Copyright policy is GNU/GPL as per LDP (Linux Documentation project)."
// http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-22.html
-vector<string> Tokenize(const string& str, char delimiter) {
+vector<string> Tokenize(const string& str, char delimiter)
+{
vector<string> tokens;
- // Skip delimiters at beginning.
+ // Skip delimiters at beginning.
string::size_type lastPos = str.find_first_not_of(delimiter);
- // Find first "non-delimiter".
- string::size_type pos = str.find_first_of(delimiter, lastPos);
+ // Find first "non-delimiter".
+ string::size_type pos = str.find_first_of(delimiter, lastPos);
- while (string::npos != pos || string::npos != lastPos) {
- // Found a token, add it to the vector.
- tokens.push_back(str.substr(lastPos, pos - lastPos));
- // Skip delimiters. Note the "not_of"
- lastPos = str.find_first_not_of(delimiter, pos);
- // Find next "non-delimiter"
- pos = str.find_first_of(delimiter, lastPos);
- }
+ while (string::npos != pos || string::npos != lastPos) {
+ // Found a token, add it to the vector.
+ tokens.push_back(str.substr(lastPos, pos - lastPos));
+ // Skip delimiters. Note the "not_of"
+ lastPos = str.find_first_not_of(delimiter, pos);
+ // Find next "non-delimiter"
+ pos = str.find_first_of(delimiter, lastPos);
+ }
return tokens;
}
-ostream&PseudoSprite::output(ostream&out){
- if(!valid){
+ostream& PseudoSprite::output(ostream& out)
+{
+ if (!valid) {
istringstream datastream(orig);
string line;
- getline(datastream,line);
- out<<COMMENT_PREFIX<<" 0 * 0\t "<<line<<endl;
- while(getline(datastream,line)){
- if(!is_comment(line))out<<COMMENT_PREFIX;
- out<<line<<endl;
+ getline(datastream, line);
+ out << COMMENT_PREFIX << " 0 * 0\t " << line << endl;
+ while (getline(datastream, line)) {
+ if (!is_comment(line)) out << COMMENT_PREFIX;
+ out << line << endl;
}
return out;
}
- if(UseOrig()){
- if(Length())
- out<<setw(5)<<spritenum()<<" * "<<(GetState(DIFF)?0:Length())<<"\t ";
- return out<<orig;
+ if (UseOrig()) {
+ if (Length()) out << setw(5) << spritenum() << " * " << (GetState(DIFF) ? 0 : Length()) << "\t ";
+ return out << orig;
}
- bool instr=false,noendl=false;
- uint count=16;
- out<<setw(5)<<spritenum()<<" * "<<(GetState(DIFF)?0:Length())<<"\t";
+ bool instr = false, noendl = false;
+ uint count = 16;
+ out << setw(5) << spritenum() << " * " << (GetState(DIFF) ? 0 : Length()) << "\t";
- ostringstream outbuf; // buffer output for potential tab expansion
+ ostringstream outbuf; // buffer output for potential tab expansion
-//This section contains a rewrite of lines 402-438 or thereabouts of info.cc
-//from grfcodec v0.9.7: http://www.ttdpatch.net/grfcodec
-//grfcodec is Copyright 2000-2005 Josef Drexler
+ // This section contains a rewrite of lines 402-438 or thereabouts of info.cc
+ // from grfcodec v0.9.7: http://www.ttdpatch.net/grfcodec
+ // grfcodec is Copyright 2000-2005 Josef Drexler
ignorelinkage = true;
- for(uint i=0;i<Length();i++) {
+ for (uint i = 0; i < Length(); i++) {
// Most output strings contain a leading space, but this should be omitted if CONVERTONLY.
// ... unless there was no space between the preceding byte and this one.
- const int skipspace = (GetState(CONVERTONLY)&&i&&context[i-1]!="")?1:0;
- if(DoQuote(i)){
- if (!instr){
- outbuf<< (skipspace ? "\"" : " \"");
- count+=3-skipspace;// count close-quote here.
- instr=true;
+ const int skipspace = (GetState(CONVERTONLY) && i && context[i - 1] != "") ? 1 : 0;
+ if (DoQuote(i)) {
+ if (!instr) {
+ outbuf << (skipspace ? "\"" : " \"");
+ count += 3 - skipspace; // count close-quote here.
+ instr = true;
}
- if(NFOversion>6){
- if((beauty[i]&~NOBREAK)==QESC){
- if((*this)[i]=='\r'){
- outbuf<<"\\n";
- count=+2;
- }else{
- outbuf<<mysprintf("\\%2x",(*this)[i]);
- count+=3;
+ if (NFOversion > 6) {
+ if ((beauty[i] & ~NOBREAK) == QESC) {
+ if ((*this)[i] == '\r') {
+ outbuf << "\\n";
+ count = +2;
+ } else {
+ outbuf << mysprintf("\\%2x", (*this)[i]);
+ count += 3;
}
- }else if((beauty[i]&~NOBREAK)==QEXT){
- outbuf<<ext_print[i];
- count+=(uint)ext_print[i].size();
- }else if((*this)[i]=='"'){
- outbuf<<"\\\"";
- count+=2;
- }else if((*this)[i]=='\\'){
- outbuf<<"\\\\";
- count+=2;
- }else{
- outbuf<<(char)(*this)[i];
+ } else if ((beauty[i] & ~NOBREAK) == QEXT) {
+ outbuf << ext_print[i];
+ count += (uint)ext_print[i].size();
+ } else if ((*this)[i] == '"') {
+ outbuf << "\\\"";
+ count += 2;
+ } else if ((*this)[i] == '\\') {
+ outbuf << "\\\\";
+ count += 2;
+ } else {
+ outbuf << (char)(*this)[i];
count++;
}
- }else{
- outbuf<<(char)(*this)[i];
+ } else {
+ outbuf << (char)(*this)[i];
count++;
}
- noendl=false;
+ noendl = false;
} else {
- if(instr){
- outbuf<<'"';
- instr=false;
+ if (instr) {
+ outbuf << '"';
+ instr = false;
}
string str;
- if(NFOversion>6 && (beauty[i]&~NOBREAK)==NQEXT)
- str = ext_print[i].c_str()+skipspace;
+ if (NFOversion > 6 && (beauty[i] & ~NOBREAK) == NQEXT)
+ str = ext_print[i].c_str() + skipspace;
else
- str = mysprintf(skipspace ? "%2x" : " %2x",(*this)[i]);
- outbuf<<str;
- count+=(uint)str.size();
- noendl=false;
+ str = mysprintf(skipspace ? "%2x" : " %2x", (*this)[i]);
+ outbuf << str;
+ count += (uint)str.size();
+ noendl = false;
}
- //Context control (comments, beautifier controlled newlines, &c.)
- if(IsEot(i)&&instr){
- outbuf<<'"';
- instr=false;
+ // Context control (comments, beautifier controlled newlines, &c.)
+ if (IsEot(i) && instr) {
+ outbuf << '"';
+ instr = false;
}
- if(context[i]==" " && ((instr && i+1<Length() && (IsText(i)||(IsUTF8(i)&&GetState(QUOTEUTF8)))) || (beauty[i]&~NOBREAK)==NQEXT)) {
- context[i]="";
- } else if(context[i]!="") {
- if(instr){
- outbuf<<'"';
- instr=false;
+ if (context[i] == " " &&
+ ((instr && i + 1 < Length() && (IsText(i) || (IsUTF8(i) && GetState(QUOTEUTF8)))) || (beauty[i] & ~NOBREAK) == NQEXT)) {
+ context[i] = "";
+ } else if (context[i] != "") {
+ if (instr) {
+ outbuf << '"';
+ instr = false;
}
- for(const char*ch=context[i].c_str();*ch;ch++){
+ for (const char* ch = context[i].c_str(); *ch; ch++) {
count++;
- if(*ch=='\n'){
- count=0;
- noendl=true;
+ if (*ch == '\n') {
+ count = 0;
+ noendl = true;
}
- outbuf<<*ch;
+ outbuf << *ch;
}
}
// Insert line-breaks after current charater:
@@ -691,113 +768,120 @@
// at spaces after GetState(MAXLEN)-15 text characters or
// after GetState(MAXLEN) characters
// and when not last character
- if(!GetState(CONVERTONLY)&&
- IsLinePermitted(i)&&GetState(MAXLEN)&&
- ((!instr && count>=GetState(MAXLEN)-15) ||
- (instr && ((count>=GetState(MAXLEN)-15 && (*this)[i]==' ') ||
- count>=GetState(MAXLEN))))
- && i<Length()-1) {
- if(instr){
- outbuf<<'"';
- instr=false;
+ if (!GetState(CONVERTONLY) && IsLinePermitted(i) && GetState(MAXLEN) &&
+ ((!instr && count >= GetState(MAXLEN) - 15) ||
+ (instr && ((count >= GetState(MAXLEN) - 15 && (*this)[i] == ' ') || count >= GetState(MAXLEN)))) &&
+ i < Length() - 1) {
+ if (instr) {
+ outbuf << '"';
+ instr = false;
}
- outbuf<<(noendl?"":"\n")<<string(count=GetState(LEADINGSPACE,2),' ');
+ outbuf << (noendl ? "" : "\n") << string(count = GetState(LEADINGSPACE, 2), ' ');
}
}
- ignorelinkage=false;
- if (instr)outbuf<<'"';
+ ignorelinkage = false;
+ if (instr) outbuf << '"';
// Collected all output; perform tab expansion
string buffer = outbuf.str();
- if(buffer.find('\t')!=NPOS){
+ if (buffer.find('\t') != NPOS) {
// Split into columns
vector<vector<string> > sections;
- foreach(const string &line, (Tokenize(buffer, '\n')))
- sections.push_back(Tokenize(line, '\t'));
+ foreach(const string & line, (Tokenize(buffer, '\n')))
+ sections.push_back(Tokenize(line, '\t'));
// Count the columns
- uint columns = (uint)max_element(sections.begin(),sections.end(), bind(&vector<string>::size,_1) < bind(&vector<string>::size,_2))->size();
+ uint columns = (uint)max_element(sections.begin(), sections.end(),
+ bind(&vector<string>::size, _1) < bind(&vector<string>::size, _2))->size();
// For each column,
- for(uint i=0;i<columns;i++){
+ for (uint i = 0; i < columns; i++) {
// determine how wide it must be,
string::size_type padWidth = 0;
- foreach(const vector<string> &section, sections)
- if(section.size()>i+1) padWidth = max(padWidth, section[i].length()+1);
+ foreach(const vector<string> & section, sections)
+ if (section.size() > i + 1) padWidth = max(padWidth, section[i].length() + 1);
// and make it that wide.
- foreach(vector<string> &section, sections)
- if(section.size()>i+1) section[i] += string(padWidth - section[i].length(), ' ');
+ foreach(vector<string> & section, sections)
+ if (section.size() > i + 1) section[i] += string(padWidth - section[i].length(), ' ');
}
// Tabs are expanded, write each line
- foreach(const vector<string>&line, sections)
- for_each(line.begin(),line.end(),out<<_1)('\n');
+ foreach(const vector<string> & line, sections)
+ for_each(line.begin(), line.end(), out << _1)('\n');
- }else out<<buffer;
+ } else
+ out << buffer;
- if(noendl)return out;
- return out<<endl;
+ if (noendl) return out;
+ return out << endl;
}
-bool PseudoSprite::CanQuote(uint byte){
- VERIFY(byte<0x100,byte);
- return(byte<0x80||GetState(QUOTEHIGHASCII))&&
- //non-printable ASCII are 00..1F, 22(sometimes), 7F..9F.
- //(String parser is responsible for marking others text/hex/UTF8 as appropriate)
- byte>0x1F&&(byte!='"'||NFOversion>6)&&(byte<0x7F||byte>0x9F);
+bool PseudoSprite::CanQuote(uint byte)
+{
+ VERIFY(byte < 0x100, byte);
+ return (byte < 0x80 || GetState(QUOTEHIGHASCII)) &&
+ // non-printable ASCII are 00..1F, 22(sometimes), 7F..9F.
+ //(String parser is responsible for marking others text/hex/UTF8 as appropriate)
+ byte > 0x1F && (byte != '"' || NFOversion > 6) && (byte < 0x7F || byte > 0x9F);
}
-bool PseudoSprite::DoQuote(uint i)const{
- if((beauty[i]&~NOBREAK)==QESC || (beauty[i]&~NOBREAK)==QEXT) return NFOversion>6; // Quote IFF we have escapes
- return (CanQuote((*this)[i])&&IsText(i))||(IsUTF8(i)&&GetState(QUOTEUTF8));
+bool PseudoSprite::DoQuote(uint i) const
+{
+ if ((beauty[i] & ~NOBREAK) == QESC || (beauty[i] & ~NOBREAK) == QEXT) return NFOversion > 6; // Quote IFF we have escapes
+ return (CanQuote((*this)[i]) && IsText(i)) || (IsUTF8(i) && GetState(QUOTEUTF8));
}
-void PseudoSprite::Invalidate(){
- IssueMessage(0,PARSE_FAILURE,_spritenum);
- valid=false;
+void PseudoSprite::Invalidate()
+{
+ IssueMessage(0, PARSE_FAILURE, _spritenum);
+ valid = false;
SetCode(EPARSE);
}
-bool PseudoSprite::IsText(uint i)const{
- int type = beauty[i]&~NOBREAK;
- if (NFOversion>6)
- return type==TEXT || type==ENDQUOTE || type==QESC || type==QEXT;
+bool PseudoSprite::IsText(uint i) const
+{
+ int type = beauty[i] & ~NOBREAK;
+ if (NFOversion > 6)
+ return type == TEXT || type == ENDQUOTE || type == QESC || type == QEXT;
else
- return type==TEXT || type==ENDQUOTE;
+ return type == TEXT || type == ENDQUOTE;
}
-bool PseudoSprite::IsUTF8(uint i)const{
- return (beauty[i]&~NOBREAK)==UTF8;
+bool PseudoSprite::IsUTF8(uint i) const
+{
+ return (beauty[i] & ~NOBREAK) == UTF8;
}
-bool PseudoSprite::IsEot(uint i)const{
- return (beauty[i]&~NOBREAK)==ENDQUOTE;
+bool PseudoSprite::IsEot(uint i) const
+{
+ return (beauty[i] & ~NOBREAK) == ENDQUOTE;
}
-bool PseudoSprite::IsLinePermitted(uint i)const{
- return!(beauty[i]&NOBREAK);
+bool PseudoSprite::IsLinePermitted(uint i) const
+{
+ return !(beauty[i] & NOBREAK);
}
-bool PseudoSprite::UseOrig()const{
- return useorig||!GetState(BEAUTIFY);
+bool PseudoSprite::UseOrig() const
+{
+ return useorig || !GetState(BEAUTIFY);
}
-uint PseudoSprite::ReadValue(istream& in, width w) {
- if (in.peek() == 'x') { // Read any hex value
+uint PseudoSprite::ReadValue(istream& in, width w)
+{
+ if (in.peek() == 'x') { // Read any hex value
uint ret;
- in.ignore()>>setbase(16)>>ret>>setbase(10);
+ in.ignore() >> setbase(16) >> ret >> setbase(10);
return ret;
}
- if (in.peek() == '(') { // Read any RPN value
- if(RPNOFF){
+ if (in.peek() == '(') { // Read any RPN value
+ if (RPNOFF) {
IssueMessage(0, INVALID_EXTENSION);
return 0;
}
int val, err = 0, s = in.tellg();
- val = DoCalc(in.ignore(),err);
- if (err>0)
- return 0;
+ val = DoCalc(in.ignore(), err);
+ if (err > 0) return 0;
// Replace the original RPN with value
- int e = in.tellg(),
- p = orig.find(((istringstream&)in).str().substr(s, e - s));
+ int e = in.tellg(), p = orig.find(((istringstream&)in).str().substr(s, e - s));
orig.erase(p, e - s);
ostringstream Val;
Val << val;
@@ -809,15 +893,14 @@
string str;
// can't use operator>> -- that will consume comments in cases like \w12000//comment
eat_white(in); // skip whitespace at front
- while(in && !is_comment(in) && !isspace(in.peek()) && in.peek() != EOF)
- str += (char)in.get();
+ while (in && !is_comment(in) && !isspace(in.peek()) && in.peek() != EOF) str += (char)in.get();
char c1, c2;
int y, m, d, count = sscanf(str.c_str(), "%d%c%d%c%d", &y, &c1, &m, &c2, &d);
- if (count==1) {
+ if (count == 1) {
// Got a decimal number
- if (w==_B_ && y>1920) y-=1920; // special case for byte-sized years
+ if (w == _B_ && y > 1920) y -= 1920; // special case for byte-sized years
return y;
}
@@ -827,32 +910,38 @@
if (w == _W_) {
// word date
- if (d==0 || (d>31 && d<100) || d>1919) swap(y, d); // Try DMY instead
- if (y==0) y = 2000;
- else if (y>31 && y<100) y+=1900;
+ if (d == 0 || (d > 31 && d < 100) || d > 1919) swap(y, d); // Try DMY instead
+ if (y == 0)
+ y = 2000;
+ else if (y > 31 && y < 100)
+ y += 1900;
} else if (w == _D_) {
// dword date
extra = 701265;
if (d >= 32) swap(y, d); // Try DMY instead
// Boost doesn't support years out of the range 1400..9999
- while (y>9999) {
+ while (y > 9999) {
y -= 400;
- extra += 365*400 + 97; // 97 leap years every 400 years.
+ extra += 365 * 400 + 97; // 97 leap years every 400 years.
}
- while (y<1400) {
+ while (y < 1400) {
y += 400;
- extra -= 365*400 + 97;
+ extra -= 365 * 400 + 97;
}
- } else goto fail; // I can't read a date of that width.
+ } else
+ goto fail; // I can't read a date of that width.
- try {
+ try
+ {
return (date((ushort)y, (ushort)m, (ushort)d) - date(1920, 1, 1)).days() + extra;
- } catch (std::out_of_range) {
+ }
+ catch (std::out_of_range)
+ {
// Fall through to fail
}
}
-fail: // Nothing worked
+fail: // Nothing worked
in.clear(ios::badbit);
- return (uint)-1;
+ return (uint) - 1;
}
diff --git a/src/pseudo.h b/src/pseudo.h
--- a/src/pseudo.h
+++ b/src/pseudo.h
@@ -22,135 +22,160 @@
#ifndef _RENUM_PSEUDO_H_INCLUDED_
#define _RENUM_PSEUDO_H_INCLUDED_
-#include<string>
-#include"ExpandingArray.h"
+#include <string>
+#include "ExpandingArray.h"
+class PseudoSprite
+{
+ public:
+ // PseudoSprite();
+ PseudoSprite(const string&, int);
-class PseudoSprite{
-public:
- //PseudoSprite();
- PseudoSprite(const string&,int);
-
- void CheckLinkage(int ofs,int count)const;
+ void CheckLinkage(int ofs, int count) const;
// Use to read a single byte if you don't know/care about its meaning.
// To read a field that happens to be one byte wide, use ExtractByte.
- uint LinkSafeExtractByte(uint)const;
-private:
- void LinkBytes(int,size_t);
+ uint LinkSafeExtractByte(uint) const;
+
+ private:
+ void LinkBytes(int, size_t);
Expanding0Array<int> linkage;
static bool ignorelinkage;
-public:
+ public:
// Use to read a single byte if you don't know/care about its meaning.
// To read a field that happens to be one byte wide, use ExtractByte.
- uint operator[](uint offs)const{return LinkSafeExtractByte(offs);}
- operator const char*()const{return packed.c_str();}
- uint Length()const;
- bool IsValid()const{return Length()!=0;}
+ uint operator[](uint offs) const
+ {
+ return LinkSafeExtractByte(offs);
+ }
+ operator const char*() const
+ {
+ return packed.c_str();
+ }
+ uint Length() const;
+ bool IsValid() const
+ {
+ return Length() != 0;
+ }
- PseudoSprite&SetText(uint);
- PseudoSprite&SetText(uint,uint);
- PseudoSprite&SetUTF8(uint,uint);
- PseudoSprite&SetOpByte(uint,char);
- PseudoSprite&SetPositionalOpByte(uint,char);
- PseudoSprite&SetDate(uint,uint);
+ PseudoSprite& SetText(uint);
+ PseudoSprite& SetText(uint, uint);
+ PseudoSprite& SetUTF8(uint, uint);
+ PseudoSprite& SetOpByte(uint, char);
+ PseudoSprite& SetPositionalOpByte(uint, char);
+ PseudoSprite& SetDate(uint, uint);
- PseudoSprite&SetQEscape(uint);
- PseudoSprite&SetQEscape(uint,uint);
-private:
- PseudoSprite&SetEscape(uint,bool,string,uint);
+ PseudoSprite& SetQEscape(uint);
+ PseudoSprite& SetQEscape(uint, uint);
-public:
- PseudoSprite&SetHex(uint);
- PseudoSprite&SetHex(uint,uint);
- PseudoSprite&SetAllHex();
- PseudoSprite&SetEot(uint);
- PseudoSprite&SetEol(uint,uint,uint);
- PseudoSprite&SetEol(uint loc,uint minbreaks){
- return SetEol(loc,minbreaks,(minbreaks>1)?1:0);
+ private:
+ PseudoSprite& SetEscape(uint, bool, string, uint);
+
+ public:
+ PseudoSprite& SetHex(uint);
+ PseudoSprite& SetHex(uint, uint);
+ PseudoSprite& SetAllHex();
+ PseudoSprite& SetEot(uint);
+ PseudoSprite& SetEol(uint, uint, uint);
+ PseudoSprite& SetEol(uint loc, uint minbreaks)
+ {
+ return SetEol(loc, minbreaks, (minbreaks > 1) ? 1 : 0);
}
- PseudoSprite&SetNoEol(uint);
- PseudoSprite&SetGRFID(uint);
+ PseudoSprite& SetNoEol(uint);
+ PseudoSprite& SetGRFID(uint);
- PseudoSprite&SetDec(uint,uint);
- PseudoSprite&SetBE(uint,uint);
+ PseudoSprite& SetDec(uint, uint);
+ PseudoSprite& SetBE(uint, uint);
- PseudoSprite&SetByteAt(uint,uint);
- PseudoSprite&SetWordAt(uint,uint);
- PseudoSprite&SetDwordAt(uint,uint);
- PseudoSprite&Append(uchar);
+ PseudoSprite& SetByteAt(uint, uint);
+ PseudoSprite& SetWordAt(uint, uint);
+ PseudoSprite& SetDwordAt(uint, uint);
+ PseudoSprite& Append(uchar);
- PseudoSprite&ColumnAfter(uint);
+ PseudoSprite& ColumnAfter(uint);
- uint ExtractByte(uint offs)const;
- uint ExtractWord(uint offs)const;
- uint ExtractExtended(uint offs)const;
- uint ExtractDword(uint offs)const;
- uint ExtendedLen(uint)const;
- uint ExtractVariable(uint,uint)const;
+ uint ExtractByte(uint offs) const;
+ uint ExtractWord(uint offs) const;
+ uint ExtractExtended(uint offs) const;
+ uint ExtractDword(uint offs) const;
+ uint ExtendedLen(uint) const;
+ uint ExtractVariable(uint, uint) const;
uint ExtractUtf8(uint&, bool&); // in utf8.cpp.
- uint ExtractQEscapeByte(uint offs){
+ uint ExtractQEscapeByte(uint offs)
+ {
SetQEscape(offs);
return ExtractByte(offs);
}
- uint ExtractEscapeWord(uint offs){
- SetBE(offs,2);
+ uint ExtractEscapeWord(uint offs)
+ {
+ SetBE(offs, 2);
return ExtractWord(offs);
}
- void AddComment(const string&,uint);
- void TrailComment(const string&,uint);
+ void AddComment(const string&, uint);
+ void TrailComment(const string&, uint);
void AddBlank(uint);
void NoBeautify();
- friend ostream&operator<<(ostream&,PseudoSprite&);
-private:
- ostream&output(ostream&);
+ friend ostream& operator<<(ostream&, PseudoSprite&);
-public:
+ private:
+ ostream& output(ostream&);
+
+ public:
static bool CanQuote(uint);
static bool MayBeSprite(const string&);
- enum width {_B_, _BX_, _W_, _D_};
+ enum width {
+ _B_,
+ _BX_,
+ _W_,
+ _D_
+ };
uint ReadValue(istream&, width);
-private:
- bool DoQuote(uint)const;
- bool IsText(uint)const;
- bool IsUTF8(uint)const;
- bool IsEot(uint)const;
- bool IsLinePermitted(uint)const;
- bool NoPrint(uint)const;
+ private:
+ bool DoQuote(uint) const;
+ bool IsText(uint) const;
+ bool IsUTF8(uint) const;
+ bool IsEot(uint) const;
+ bool IsLinePermitted(uint) const;
+ bool NoPrint(uint) const;
void Invalidate();
- bool UseOrig()const;
+ bool UseOrig() const;
- string orig,packed;
- Expanding0Array<uchar>beauty;
- ExpandingArray<string>context,ext_print;
- bool valid,useorig;
+ string orig, packed;
+ Expanding0Array<uchar> beauty;
+ ExpandingArray<string> context, ext_print;
+ bool valid, useorig;
const int oldspritenum;
-// Support for sequential access
-public:
-#define PS_LOC_REF(size) \
- class size; \
- PseudoSprite& operator >>(size&); \
- PseudoSprite& Extract(size&, uint); \
- class size { \
- public: \
- size(); \
- size& set(uint); \
- uint val() const; \
- uint loc() const; \
- operator uint() const {return val();} \
- friend PseudoSprite& PseudoSprite::operator >>(size&); \
+ // Support for sequential access
+ public:
+#define PS_LOC_REF(size) \
+ class size; \
+ PseudoSprite& operator>>(size&); \
+ PseudoSprite& Extract(size&, uint); \
+ class size \
+ { \
+ public: \
+ size(); \
+ size& set(uint); \
+ uint val() const; \
+ uint loc() const; \
+ operator uint() const \
+ { \
+ return val(); \
+ } \
+ friend PseudoSprite& PseudoSprite::operator>>(size&); \
friend PseudoSprite& PseudoSprite::Extract(size&, uint); \
- private: \
- PseudoSprite *p; \
- uint offs; \
- }; \
+ \
+ private: \
+ PseudoSprite* p; \
+ uint offs; \
+ };
PS_LOC_REF(Byte)
PS_LOC_REF(Word)
@@ -162,8 +187,8 @@
uint BytesRemaining() const;
PseudoSprite& seek(uint);
-private:
+ private:
uint extract_offs;
};
-#endif//_RENUM_PSEUDO_H_INCLUDED_
+#endif //_RENUM_PSEUDO_H_INCLUDED_
diff --git a/src/pseudo_seq.cpp b/src/pseudo_seq.cpp
--- a/src/pseudo_seq.cpp
+++ b/src/pseudo_seq.cpp
@@ -47,53 +47,60 @@
#undef INCLUDING
-uint PseudoSprite::BytesRemaining() const {
+uint PseudoSprite::BytesRemaining() const
+{
return (uint)packed.length() - extract_offs;
}
-PseudoSprite& PseudoSprite::seek(uint off) {
+PseudoSprite& PseudoSprite::seek(uint off)
+{
extract_offs = off;
return *this;
}
-PseudoSprite::Byte& PseudoSprite::Byte::set(uint u) {
+PseudoSprite::Byte& PseudoSprite::Byte::set(uint u)
+{
p->SetByteAt(offs, u);
return *this;
}
-PseudoSprite::Word& PseudoSprite::Word::set(uint u) {
- p->SetByteAt(offs, u&0xFF);
- p->SetByteAt(offs, u>>8);
+PseudoSprite::Word& PseudoSprite::Word::set(uint u)
+{
+ p->SetByteAt(offs, u & 0xFF);
+ p->SetByteAt(offs, u >> 8);
return *this;
}
#else // INCLUDING
#ifndef EXTRACT
-# define EXTRACT FOR_CLASS
+#define EXTRACT FOR_CLASS
#endif
-PseudoSprite::FOR_CLASS::FOR_CLASS() :
- p(NULL)
-{}
+PseudoSprite::FOR_CLASS::FOR_CLASS() : p(NULL)
+{
+}
-
-uint PseudoSprite::FOR_CLASS::val() const {
+uint PseudoSprite::FOR_CLASS::val() const
+{
return p->BOOST_PP_CAT(Extract, EXTRACT(offs));
}
-uint PseudoSprite::FOR_CLASS::loc() const {
+uint PseudoSprite::FOR_CLASS::loc() const
+{
return offs;
}
-PseudoSprite& PseudoSprite::operator >>(PseudoSprite::FOR_CLASS& b) {
+PseudoSprite& PseudoSprite::operator>>(PseudoSprite::FOR_CLASS& b)
+{
b.p = this;
b.offs = extract_offs;
extract_offs += WIDTH(extract_offs);
return *this;
}
-PseudoSprite& PseudoSprite::Extract(PseudoSprite::FOR_CLASS& b, uint off) {
+PseudoSprite& PseudoSprite::Extract(PseudoSprite::FOR_CLASS& b, uint off)
+{
b.p = this;
b.offs = off;
return *this;
@@ -103,5 +110,4 @@
#undef EXTRACT
#undef WIDTH
-
-#endif //INCLUDING
+#endif // INCLUDING
diff --git a/src/rangedint.cpp b/src/rangedint.cpp
--- a/src/rangedint.cpp
+++ b/src/rangedint.cpp
@@ -24,39 +24,53 @@
#include "rangedint.h"
-RangedUint::RangedUint(uint max):m_max(max){}
-RangedUint::RangedUint(uint val,uint max):m_max(max),m_val(val){}
-
-RangedUint::operator uint()const{return m_val;}
-
-const RangedUint&RangedUint::operator+=(uint right){
- if(m_val+right>=m_val)m_overflow=(m_val+=right)>m_max;
- else m_overflow=true;
- return*this;
+RangedUint::RangedUint(uint max) : m_max(max)
+{
+}
+RangedUint::RangedUint(uint val, uint max) : m_max(max), m_val(val)
+{
}
-const RangedUint&RangedUint::operator-=(uint right){
- m_overflow=(m_val-right<=m_val);
- m_val-=right;
- return*this;
+RangedUint::operator uint() const
+{
+ return m_val;
}
-const RangedUint&RangedUint::operator/=(uint right){
- m_overflow=false;
- m_val/=right;
- return*this;
+const RangedUint& RangedUint::operator+=(uint right)
+{
+ if (m_val + right >= m_val)
+ m_overflow = (m_val += right) > m_max;
+ else
+ m_overflow = true;
+ return *this;
}
-const RangedUint&RangedUint::operator*=(uint right){
- if(right&&(m_val*right)/right!=m_val)
- m_overflow=true;
- else
- m_overflow=(m_val*=right)>=m_max;
- return*this;
+const RangedUint& RangedUint::operator-=(uint right)
+{
+ m_overflow = (m_val - right <= m_val);
+ m_val -= right;
+ return *this;
}
-const RangedUint&RangedUint::operator=(uint right){
- m_overflow=(right>m_max);
- m_val=right;
- return*this;
+const RangedUint& RangedUint::operator/=(uint right)
+{
+ m_overflow = false;
+ m_val /= right;
+ return *this;
}
+
+const RangedUint& RangedUint::operator*=(uint right)
+{
+ if (right && (m_val * right) / right != m_val)
+ m_overflow = true;
+ else
+ m_overflow = (m_val *= right) >= m_max;
+ return *this;
+}
+
+const RangedUint& RangedUint::operator=(uint right)
+{
+ m_overflow = (right > m_max);
+ m_val = right;
+ return *this;
+}
diff --git a/src/rangedint.h b/src/rangedint.h
--- a/src/rangedint.h
+++ b/src/rangedint.h
@@ -23,50 +23,58 @@
#ifndef _RENUM_RANGEDINT_H_INCLUDED_
#define _RENUM_RANGEDINT_H_INCLUDED_
-class RangedUint{
-public:
- //RangedUint();
+class RangedUint
+{
+ public:
+ // RangedUint();
explicit RangedUint(uint max);
- RangedUint(uint val,uint max);
+ RangedUint(uint val, uint max);
- operator uint()const;
- const RangedUint&operator+=(uint);
- const RangedUint&operator-=(uint);
- const RangedUint&operator/=(uint);
- const RangedUint&operator*=(uint);
- const RangedUint&operator=(uint);
+ operator uint() const;
+ const RangedUint& operator+=(uint);
+ const RangedUint& operator-=(uint);
+ const RangedUint& operator/=(uint);
+ const RangedUint& operator*=(uint);
+ const RangedUint& operator=(uint);
- //SetRange(uint min,uint max);
+ // SetRange(uint min,uint max);
- bool LastOpOverflow()const{return m_overflow;}
+ bool LastOpOverflow() const
+ {
+ return m_overflow;
+ }
-private:
- uint m_max,m_val;
+ private:
+ uint m_max, m_val;
bool m_overflow;
};
-class RangedInt{
-public:
- //RangedUint();
+class RangedInt
+{
+ public:
+ // RangedUint();
explicit RangedInt(const RangedUint&);
explicit RangedInt(int max);
- RangedInt(int min,int max);
- RangedInt(int val,int min,int max);
+ RangedInt(int min, int max);
+ RangedInt(int val, int min, int max);
- operator int()const;
- const RangedInt&operator+=(int);
- const RangedInt&operator-=(int);
- const RangedInt&operator/=(int);
- const RangedInt&operator=(int);
+ operator int() const;
+ const RangedInt& operator+=(int);
+ const RangedInt& operator-=(int);
+ const RangedInt& operator/=(int);
+ const RangedInt& operator=(int);
- //SetRange(uint min,uint max);
+ // SetRange(uint min,uint max);
- bool LastOpOverflow()const{return m_overflow;}
+ bool LastOpOverflow() const
+ {
+ return m_overflow;
+ }
-private:
+ private:
RangedInt(const RangedInt&);
- int m_min,m_max,m_val;
+ int m_min, m_max, m_val;
bool m_overflow;
};
-#endif//_RENUM_RANGEDINT_H_INCLUDED_
+#endif //_RENUM_RANGEDINT_H_INCLUDED_
diff --git a/src/readinfo.cpp b/src/readinfo.cpp
--- a/src/readinfo.cpp
+++ b/src/readinfo.cpp
@@ -33,144 +33,142 @@
Version 7: Add backslash escapes
*/
-#include<cstring>
-#include<climits>
-#include<iostream>
-#include<string>
-#include<sstream>
-#include<iomanip>
-#include<cstdio>
+#include <cstring>
+#include <climits>
+#include <iostream>
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <cstdio>
using namespace std;
// grfcodec requires boost::date_time for its processing of the \wYMD and
// \wDMY formats. Get boost from www.boost.org
-#include<boost/date_time/gregorian/gregorian_types.hpp>
+#include <boost/date_time/gregorian/gregorian_types.hpp>
using namespace boost::gregorian;
-#include"nfosprite.h"
-#include"allocarray.h"
-#include"inlines.h"
+#include "nfosprite.h"
+#include "allocarray.h"
+#include "inlines.h"
extern int _quiet;
-const char *zoom_levels[ZOOM_LEVELS] = { "normal", "zi4", "zi2", "zo2", "zo4", "zo8" };
-const char *depths[DEPTHS] = { "8bpp", "32bpp", "mask" };
+const char *zoom_levels[ZOOM_LEVELS] = {"normal", "zi4", "zi2", "zo2", "zo4", "zo8"};
+const char *depths[DEPTHS] = {"8bpp", "32bpp", "mask"};
-#define checkspriteno()\
- if(spriteno!=-1&&spriteno!=(int)sprites.size() && !_quiet){\
- fprintf(stderr, "Warning: Found sprite %d looking for sprite %d.\n",spriteno,(int)sprites.size());\
- }else(void(0))
+#define checkspriteno() \
+ if (spriteno != -1 && spriteno != (int)sprites.size() && !_quiet) { \
+ fprintf(stderr, "Warning: Found sprite %d looking for sprite %d.\n", spriteno, (int)sprites.size()); \
+ } else \
+ (void(0))
+#define flush_buffer() \
+ if (true) { \
+ if (buffer != "") { \
+ checkspriteno(); \
+ sprites.push_back(Pseudo(sprites.size(), infover, grfcontversion, buffer, claimed_size)); \
+ buffer = ""; \
+ } \
+ spriteno = temp; \
+ } else \
+ (void(0))
-#define flush_buffer()\
- if(true){\
- if(buffer!=""){\
- checkspriteno();\
- sprites.push_back(Pseudo(sprites.size(),infover,grfcontversion,buffer,claimed_size));\
- buffer="";\
- }\
- spriteno=temp;\
- }else\
- (void(0))
+void read_file(istream &in, int infover, int grfcontversion, AllocArray<Sprite> &sprites)
+{
+ string sprite, datapart, buffer;
-void read_file(istream&in,int infover,int grfcontversion,AllocArray<Sprite>&sprites){
- string sprite,datapart,buffer;
-
- int temp=-1,spriteno=-1,claimed_size=1;
+ int temp = -1, spriteno = -1, claimed_size = 1;
string::size_type firstnotpseudo;
- while(true){
- getline(in,sprite);
+ while (true) {
+ getline(in, sprite);
istringstream spritestream(sprite);
eat_white(spritestream);
- if(spritestream.peek()==EOF || // blank
- is_comment(spritestream)){ // comment
- }else{//sprite
- if(!eat_white(spritestream>>temp)){
+ if (spritestream.peek() == EOF || // blank
+ is_comment(spritestream)) { // comment
+ } else { // sprite
+ if (!eat_white(spritestream >> temp)) {
spritestream.clear();
- temp=-1;
+ temp = -1;
}
- char peeked=spritestream.peek();
- if(peeked=='*'){
- if(spritestream.ignore().peek()=='*'){
+ char peeked = spritestream.peek();
+ if (peeked == '*') {
+ if (spritestream.ignore().peek() == '*') {
flush_buffer();
- getline(eat_white(spritestream.ignore()),datapart);
+ getline(eat_white(spritestream.ignore()), datapart);
strip_trailing_white(datapart);
checkspriteno();
sprites.push_back(Include(datapart));
- }else{
+ } else {
flush_buffer();
- eat_white(spritestream>>claimed_size);
- getline(spritestream,buffer);
- buffer+='\n';
+ eat_white(spritestream >> claimed_size);
+ getline(spritestream, buffer);
+ buffer += '\n';
}
- }else{
- getline(spritestream,datapart);
- firstnotpseudo=datapart.find_first_not_of(VALID_PSEUDO);
- if((!spritestream||firstnotpseudo==NPOS||
- (datapart[firstnotpseudo]=='"'&&infover>4)||
- (datapart[firstnotpseudo]=='\\'&&infover>6)||
- is_comment(datapart,firstnotpseudo))&&
- Pseudo::MayBeSprite(buffer)){
- buffer+=sprite+'\n';
- }else{
+ } else {
+ getline(spritestream, datapart);
+ firstnotpseudo = datapart.find_first_not_of(VALID_PSEUDO);
+ if ((!spritestream || firstnotpseudo == NPOS || (datapart[firstnotpseudo] == '"' && infover > 4) ||
+ (datapart[firstnotpseudo] == '\\' && infover > 6) || is_comment(datapart, firstnotpseudo)) &&
+ Pseudo::MayBeSprite(buffer)) {
+ buffer += sprite + '\n';
+ } else {
flush_buffer();
checkspriteno();
- if (peeked!='|') {
+ if (peeked != '|') {
sprites.push_back(Real());
} else {
do {
datapart.erase(0, 1);
} while (isspace(datapart[0]));
}
- ((Real*)sprites.last())->AddSprite(sprites.size()-1,infover,datapart);
+ ((Real *)sprites.last())->AddSprite(sprites.size() - 1, infover, datapart);
}
}
}
- if(in.peek()==EOF){
+ if (in.peek() == EOF) {
flush_buffer();
return;
}
}
}
-Sprite::unparseable::unparseable(string reason,size_t sprite){
- this->reason="Error: "+reason+".\n\tWhile reading sprite:"+itoa((int)sprite)+'\n';
+Sprite::unparseable::unparseable(string reason, size_t sprite)
+{
+ this->reason = "Error: " + reason + ".\n\tWhile reading sprite:" + itoa((int)sprite) + '\n';
}
-void Real::AddSprite(size_t sprite,int infover,const string&data){
- string::size_type loc=NPOS;
- string udata=UCase(data);
- while(true){
- loc=udata.find(".PCX",loc+1);
+void Real::AddSprite(size_t sprite, int infover, const string &data)
+{
+ string::size_type loc = NPOS;
+ string udata = UCase(data);
+ while (true) {
+ loc = udata.find(".PCX", loc + 1);
#ifdef WITH_PNG
- if(loc==NPOS)
- loc = udata.find(".PNG",loc+1);
+ if (loc == NPOS) loc = udata.find(".PNG", loc + 1);
#endif
- if(loc==NPOS) {
+ if (loc == NPOS) {
#ifndef WITH_PNG
- loc = udata.find(".PNG",loc+1);
- if(loc!=NPOS) throw Sprite::unparseable("Found PNG sprite, but GRFCodec is compiled without PNG support",sprite);
+ loc = udata.find(".PNG", loc + 1);
+ if (loc != NPOS)
+ throw Sprite::unparseable("Found PNG sprite, but GRFCodec is compiled without PNG support", sprite);
#endif
- throw Sprite::unparseable("Could not find filename",sprite);
+ throw Sprite::unparseable("Could not find filename", sprite);
}
- if(isspace(data[loc+4]))break;
+ if (isspace(data[loc + 4])) break;
}
SpriteInfo inf;
- if((inf.name=data.substr(0,loc+4))!=prevname){
- prevy=0;
- prevname=inf.name;
+ if ((inf.name = data.substr(0, loc + 4)) != prevname) {
+ prevy = 0;
+ prevname = inf.name;
}
- const char*meta=data.c_str()+loc+5;
- if(infover<3){
+ const char *meta = data.c_str() + loc + 5;
+ if (infover < 3) {
unsigned int intinf[8];
- if(sscanf(data.c_str(), "%d %d %x %x %x %x %x %x %x %x",
- &inf.xpos, &inf.ypos,
- &(intinf[0]), &(intinf[1]), &(intinf[2]), &(intinf[3]),
- &(intinf[4]), &(intinf[5]), &(intinf[6]), &(intinf[7]))!=10)
- throw Sprite::unparseable("Insufficient meta-data",sprite);
- for(int i=0;i<8;i++){
- if(intinf[i]>0xFF)
- throw Sprite::unparseable("\"Byte\" "+itoa(i)+" isn't.",sprite);
+ if (sscanf(data.c_str(), "%d %d %x %x %x %x %x %x %x %x", &inf.xpos, &inf.ypos, &(intinf[0]), &(intinf[1]), &(intinf[2]),
+ &(intinf[3]), &(intinf[4]), &(intinf[5]), &(intinf[6]), &(intinf[7])) != 10)
+ throw Sprite::unparseable("Insufficient meta-data", sprite);
+ for (int i = 0; i < 8; i++) {
+ if (intinf[i] > 0xFF) throw Sprite::unparseable("\"Byte\" " + itoa(i) + " isn't.", sprite);
}
inf.info = U8(intinf[0]);
inf.depth = DEPTH_8BPP;
@@ -179,19 +177,19 @@
inf.xdim = U16(intinf[2] | intinf[3] >> 8);
inf.xrel = S16(intinf[4] | intinf[5] >> 8);
inf.yrel = S16(intinf[6] | intinf[7] >> 8);
- }else if(infover<32){
- int sx,sy,rx,ry,comp;
- if(sscanf(meta,"%d %d %2x %d %d %d %d",&inf.xpos,&inf.ypos,&comp,&sy,&sx,&rx,&ry)!=7){
- throw Sprite::unparseable("Insufficient meta-data",sprite);
+ } else if (infover < 32) {
+ int sx, sy, rx, ry, comp;
+ if (sscanf(meta, "%d %d %2x %d %d %d %d", &inf.xpos, &inf.ypos, &comp, &sy, &sx, &rx, &ry) != 7) {
+ throw Sprite::unparseable("Insufficient meta-data", sprite);
}
- if(sx<1)throw Sprite::unparseable("xsize is too small",sprite);
- if(sx>0xFFFF)throw Sprite::unparseable("xsize is too large",sprite);
- if(sy<1)throw Sprite::unparseable("ysize is too small",sprite);
- if(sy>0xFF)throw Sprite::unparseable("ysize is too large",sprite);
- if(rx<-32768)throw Sprite::unparseable("xrel is too small",sprite);
- if(rx>32767)throw Sprite::unparseable("xrel is too large",sprite);
- if(ry<-32768)throw Sprite::unparseable("yrel is too small",sprite);
- if(ry>32767)throw Sprite::unparseable("yrel is too large",sprite);
+ if (sx < 1) throw Sprite::unparseable("xsize is too small", sprite);
+ if (sx > 0xFFFF) throw Sprite::unparseable("xsize is too large", sprite);
+ if (sy < 1) throw Sprite::unparseable("ysize is too small", sprite);
+ if (sy > 0xFF) throw Sprite::unparseable("ysize is too large", sprite);
+ if (rx < -32768) throw Sprite::unparseable("xrel is too small", sprite);
+ if (rx > 32767) throw Sprite::unparseable("xrel is too large", sprite);
+ if (ry < -32768) throw Sprite::unparseable("yrel is too small", sprite);
+ if (ry > 32767) throw Sprite::unparseable("yrel is too large", sprite);
inf.zoom = 0;
inf.depth = DEPTH_8BPP;
inf.info = U8(comp);
@@ -199,46 +197,50 @@
inf.xdim = U16(sx);
inf.xrel = S16(rx);
inf.yrel = S16(ry);
- }else{
- int sx,sy,rx,ry;
- char depth[8],zoom[8],flags[2][8];
- int read = sscanf(meta,"%7s %d %d %d %d %d %d %7s %7s %7s",depth,&inf.xpos,&inf.ypos,&sx,&sy,&rx,&ry,zoom,flags[0],flags[1]);
- if(strcmp(depth,"mask")==0?read!=3:read < 8){
- throw Sprite::unparseable("Insufficient meta-data",sprite);
+ } else {
+ int sx, sy, rx, ry;
+ char depth[8], zoom[8], flags[2][8];
+ int read = sscanf(meta, "%7s %d %d %d %d %d %d %7s %7s %7s", depth, &inf.xpos, &inf.ypos, &sx, &sy, &rx, &ry, zoom,
+ flags[0], flags[1]);
+ if (strcmp(depth, "mask") == 0 ? read != 3 : read < 8) {
+ throw Sprite::unparseable("Insufficient meta-data", sprite);
}
- inf.depth=0xFF;
+ inf.depth = 0xFF;
for (int i = 0; i < DEPTHS; i++) {
- if(strcmp(depth,depths[i])==0){
+ if (strcmp(depth, depths[i]) == 0) {
inf.depth = i;
break;
}
}
- if (inf.depth==0xFF)throw Sprite::unparseable("invalid depth",sprite);
+ if (inf.depth == 0xFF) throw Sprite::unparseable("invalid depth", sprite);
inf.info = 1; // Bit 1 has to be always set for container version 1
- if (inf.depth!=DEPTH_MASK){
- if(sx<1)throw Sprite::unparseable("xsize is too small",sprite);
- if(sx>0xFFFF)throw Sprite::unparseable("xsize is too large",sprite);
- if(sy<1)throw Sprite::unparseable("ysize is too small",sprite);
- if(sy>0xFFFF)throw Sprite::unparseable("ysize is too large",sprite);
- if(rx<-32768)throw Sprite::unparseable("xrel is too small",sprite);
- if(rx>32767)throw Sprite::unparseable("xrel is too large",sprite);
- if(ry<-32768)throw Sprite::unparseable("yrel is too small",sprite);
- if(ry>32767)throw Sprite::unparseable("yrel is too large",sprite);
- inf.zoom=0xFF;
+ if (inf.depth != DEPTH_MASK) {
+ if (sx < 1) throw Sprite::unparseable("xsize is too small", sprite);
+ if (sx > 0xFFFF) throw Sprite::unparseable("xsize is too large", sprite);
+ if (sy < 1) throw Sprite::unparseable("ysize is too small", sprite);
+ if (sy > 0xFFFF) throw Sprite::unparseable("ysize is too large", sprite);
+ if (rx < -32768) throw Sprite::unparseable("xrel is too small", sprite);
+ if (rx > 32767) throw Sprite::unparseable("xrel is too large", sprite);
+ if (ry < -32768) throw Sprite::unparseable("yrel is too small", sprite);
+ if (ry > 32767) throw Sprite::unparseable("yrel is too large", sprite);
+ inf.zoom = 0xFF;
for (int i = 0; i < ZOOM_LEVELS; i++) {
- if(strcmp(zoom,zoom_levels[i])==0){
+ if (strcmp(zoom, zoom_levels[i]) == 0) {
inf.zoom = i;
break;
}
}
- if (inf.zoom==0xFF)throw Sprite::unparseable("invalid zoom",sprite);
+ if (inf.zoom == 0xFF) throw Sprite::unparseable("invalid zoom", sprite);
for (int i = 8; i < read; i++) {
- const char *flag=flags[i - 8];
+ const char *flag = flags[i - 8];
/* Comment. */
if (*flag == '#' || *flag == '/' || *flag == ';') break;
- if (strcmp(flag,"chunked")==0)inf.info|=8;
- else if (strcmp(flag,"nocrop")==0)inf.info|=64;
- else throw Sprite::unparseable("invalid flag",sprite);
+ if (strcmp(flag, "chunked") == 0)
+ inf.info |= 8;
+ else if (strcmp(flag, "nocrop") == 0)
+ inf.info |= 64;
+ else
+ throw Sprite::unparseable("invalid flag", sprite);
}
inf.ydim = U16(sy);
inf.xdim = U16(sx);
@@ -246,17 +248,16 @@
inf.yrel = S16(ry);
}
}
- if (infover < 4)
- inf.ypos++; // bug, had an extra line at the top
- if(inf.xpos<0)throw Sprite::unparseable("xpos is too small",sprite);
- if(inf.ypos<0)throw Sprite::unparseable("ypos is too small",sprite);
- inf.forcereopen=(inf.ypos<prevy);
- prevy=inf.ypos;
+ if (infover < 4) inf.ypos++; // bug, had an extra line at the top
+ if (inf.xpos < 0) throw Sprite::unparseable("xpos is too small", sprite);
+ if (inf.ypos < 0) throw Sprite::unparseable("ypos is too small", sprite);
+ inf.forcereopen = (inf.ypos < prevy);
+ prevy = inf.ypos;
- if(infs.size()==0&&inf.zoom!=0)throw Sprite::unparseable("first sprite is not 8bpp normal zoom sprite",sprite);
- if(inf.depth==DEPTH_MASK){
- SpriteInfo parent=infs[infs.size()-1];
- if (parent.depth!=DEPTH_32BPP)throw Sprite::unparseable("mask sprite not preceded by 32bpp sprite",sprite);
+ if (infs.size() == 0 && inf.zoom != 0) throw Sprite::unparseable("first sprite is not 8bpp normal zoom sprite", sprite);
+ if (inf.depth == DEPTH_MASK) {
+ SpriteInfo parent = infs[infs.size() - 1];
+ if (parent.depth != DEPTH_32BPP) throw Sprite::unparseable("mask sprite not preceded by 32bpp sprite", sprite);
inf.info = parent.info;
inf.ydim = parent.ydim;
inf.xdim = parent.xdim;
@@ -268,176 +269,187 @@
}
string Real::prevname;
-int Real::prevy=0;
+int Real::prevy = 0;
-#define CHAR(x) (char(((ch>>((x)*6))&0x3F)|0x80))
+#define CHAR(x) (char(((ch >> ((x) * 6)) & 0x3F) | 0x80))
-string GetUtf8Encode(uint ch){
- if(ch<0x80)return string()+char(ch);
- if(ch<0x800)return string()+char(((ch>>6 )&0x1F)|0xC0)+CHAR(0);
- /*if(ch<0x10000)*/return string()+char(((ch>>12)&0x0F)|0xE0)+CHAR(1)+CHAR(0);
- //if(ch<0x200000)return string()+char(((ch>>18)&0x07)|0xF0)+CHAR(2)+CHAR(1)+CHAR(0);
- //if(ch<0x4000000)return string()+char(((ch>>24)&0x03)|0xF8)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0);
- //if(ch<0x80000000)return string()+char(((ch>>30)&0x01)|0xFC)+CHAR(4)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0);
- //INTERNAL_ERROR(ch,ch);
+string GetUtf8Encode(uint ch)
+{
+ if (ch < 0x80) return string() + char(ch);
+ if (ch < 0x800) return string() + char(((ch >> 6) & 0x1F) | 0xC0) + CHAR(0);
+ /*if(ch<0x10000)*/ return string() + char(((ch >> 12) & 0x0F) | 0xE0) + CHAR(1) + CHAR(0);
+ // if(ch<0x200000)return string()+char(((ch>>18)&0x07)|0xF0)+CHAR(2)+CHAR(1)+CHAR(0);
+ // if(ch<0x4000000)return string()+char(((ch>>24)&0x03)|0xF8)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0);
+ // if(ch<0x80000000)return string()+char(((ch>>30)&0x01)|0xFC)+CHAR(4)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0);
+ // INTERNAL_ERROR(ch,ch);
}
#undef CHAR
int FindEscape(string);
-Pseudo::Pseudo(size_t num,int infover,int grfcontversion,const string&sprite,int claimed_size){
+Pseudo::Pseudo(size_t num, int infover, int grfcontversion, const string &sprite, int claimed_size)
+{
istringstream in(sprite);
ostringstream out;
char ch;
- while(in){
+ while (in) {
eat_white(in);
- switch(in.peek()){
- case EOF:continue;
- case'"':
- in.ignore();
- while(true){
- if(!in.get(ch))
- throw Sprite::unparseable("Unterminated literal string",num);
- if(ch=='"')
- break;
- if(ch=='\\'&&infover>6){
- switch(ch=(char)in.get()){
- case'n':
- ch='\r';//TTD uses Mac-style linefeeds (\r)
- break;
- case'"':
- case'\\':
- break;
- case'U':{
- uint x=ReadHex(in,4);
- if(!in)
- throw Sprite::unparseable("Could not parse quoted escape sequence",num);
- if(x>0x7FF)
- out.write(GetUtf8Encode(x).c_str(),3);
- else if(x>0x7F)
- out.write(GetUtf8Encode(x).c_str(),2);
- else out.put(x);
- continue;
+ switch (in.peek()) {
+ case EOF:
+ continue;
+ case '"':
+ in.ignore();
+ while (true) {
+ if (!in.get(ch)) throw Sprite::unparseable("Unterminated literal string", num);
+ if (ch == '"') break;
+ if (ch == '\\' && infover > 6) {
+ switch (ch = (char)in.get()) {
+ case 'n':
+ ch = '\r'; // TTD uses Mac-style linefeeds (\r)
+ break;
+ case '"':
+ case '\\':
+ break;
+ case 'U': {
+ uint x = ReadHex(in, 4);
+ if (!in)
+ throw Sprite::unparseable("Could not parse quoted escape sequence",
+ num);
+ if (x > 0x7FF)
+ out.write(GetUtf8Encode(x).c_str(), 3);
+ else if (x > 0x7F)
+ out.write(GetUtf8Encode(x).c_str(), 2);
+ else
+ out.put(x);
+ continue;
+ }
+ default:
+ in.unget();
+ ch = (char)ReadHex(in, 2);
+ if (!in)
+ throw Sprite::unparseable("Could not parse quoted escape sequence",
+ num);
+ break;
}
- default:
- in.unget();
- ch=(char)ReadHex(in,2);
- if(!in)
- throw Sprite::unparseable("Could not parse quoted escape sequence",num);
- break;
}
+ out.put(ch);
}
+ break;
+ case '/':
+ case '#':
+ case ';': // comment
+ in.ignore(INT_MAX, '\n');
+ break;
+ case '\\':
+ if (infover > 6) {
+ in.ignore();
+ uint x;
+ switch (in.get()) {
+ case 'b':
+ if (in.peek() == '*') { // \b*
+ x = ReadValue(in.ignore(), _BX_);
+ if (!in || x > 0xFFFF) break; // invalid
+ if (x > 0xFE) {
+ out.put('\xFF');
+ out.put(x);
+ out.put(x >> 8);
+ } else
+ out.put((char)x);
+ continue;
+ }
+ x = ReadValue(in, _B_);
+ if (!in || x > 0xFF) break; // invalid
+ out.put((char)x);
+ continue;
+ case 'w':
+ x = ReadValue(in, _W_);
+ if (!in || x > 0xFFFF) break; // invalid
+ out.put(x);
+ out.put(x >> 8);
+ continue;
+ case 'd':
+ x = ReadValue(in, _D_);
+ if (!in) break;
+ out.put(x);
+ out.put(x >> 8);
+ out.put(x >> 16);
+ out.put(x >> 24);
+ continue;
+ default: {
+ in.unget();
+ string esc;
+ in >> esc;
+ int byte = FindEscape(esc);
+ if (byte == -1) break;
+ out.put(byte);
+ continue;
+ }
+ }
+ throw Sprite::unparseable("Could not parse unquoted escape sequence", num);
+ }
+ default:
+ ch = (char)ReadHex(in, 2);
+ if (!in) throw Sprite::unparseable("Encountered invalid character looking for literal byte", num);
out.put(ch);
- }
- break;
- case'/':case'#':case';'://comment
- in.ignore(INT_MAX,'\n');
- break;
- case'\\':
- if(infover>6){
- in.ignore();
- uint x;
- switch(in.get()){
- case'b':
- if(in.peek()=='*'){// \b*
- x = ReadValue(in.ignore(), _BX_);
- if(!in||x>0xFFFF)break;//invalid
- if(x>0xFE){
- out.put('\xFF');
- out.put(x);
- out.put(x>>8);
- }else out.put((char)x);
- continue;
- }
- x = ReadValue(in, _B_);
- if(!in||x>0xFF)break;//invalid
- out.put((char)x);
- continue;
- case'w':
- x = ReadValue(in, _W_);
- if(!in||x>0xFFFF)break;//invalid
- out.put(x);
- out.put(x>>8);
- continue;
- case'd':
- x = ReadValue(in, _D_);
- if(!in)break;
- out.put(x);
- out.put(x>>8);
- out.put(x>>16);
- out.put(x>>24);
- continue;
- default:{
- in.unget();
- string esc;
- in>>esc;
- int byte = FindEscape(esc);
- if(byte == -1) break;
- out.put(byte);
- continue;
- }}
- throw Sprite::unparseable("Could not parse unquoted escape sequence",num);
- }
- default:
- ch=(char)ReadHex(in,2);
- if(!in)
- throw Sprite::unparseable("Encountered invalid character looking for literal byte",num);
- out.put(ch);
}
}
- packed=out.str();
- if(!size())
- throw Sprite::unparseable("Found a zero-byte pseudo-sprite",num);
- if(grfcontversion==1&&size()>=65536)
- throw Sprite::unparseable("Found pseudo-sprite larger than 65535 bytes. This requires container version 2",num);
- if(size()!=(uint)claimed_size&&claimed_size!=0 && !_quiet)
- fprintf(stderr, "Warning: Sprite %d reports %d bytes, but I found %d.\n",(int)num,claimed_size,size());
+ packed = out.str();
+ if (!size()) throw Sprite::unparseable("Found a zero-byte pseudo-sprite", num);
+ if (grfcontversion == 1 && size() >= 65536)
+ throw Sprite::unparseable("Found pseudo-sprite larger than 65535 bytes. This requires container version 2", num);
+ if (size() != (uint)claimed_size && claimed_size != 0 && !_quiet)
+ fprintf(stderr, "Warning: Sprite %d reports %d bytes, but I found %d.\n", (int)num, claimed_size, size());
}
-uint Pseudo::size()const{return (uint)packed.size();}
+uint Pseudo::size() const
+{
+ return (uint)packed.size();
+}
-bool Pseudo::MayBeSprite(const string&sprite){
+bool Pseudo::MayBeSprite(const string &sprite)
+{
istringstream in(sprite);
char ch;
- while(in.get(ch)){
- if(ch=='"')return true;
- if(COMMENT.find(ch)!=NPOS){
- in.ignore(INT_MAX,'\n');
+ while (in.get(ch)) {
+ if (ch == '"') return true;
+ if (COMMENT.find(ch) != NPOS) {
+ in.ignore(INT_MAX, '\n');
continue;
}
- if(isspace(ch)||string(VALID_PSEUDO).find(ch)==NPOS)continue;
+ if (isspace(ch) || string(VALID_PSEUDO).find(ch) == NPOS) continue;
return true;
}
return false;
}
-Include::Include(const string&data):name(data){}
+Include::Include(const string &data) : name(data)
+{
+}
-uint Pseudo::ReadValue(istream& in, width w)
+uint Pseudo::ReadValue(istream &in, width w)
{
- if (in.peek() == 'x') { // Read any hex value
+ if (in.peek() == 'x') { // Read any hex value
uint ret;
- in.ignore()>>setbase(16)>>ret>>setbase(10);
+ in.ignore() >> setbase(16) >> ret >> setbase(10);
return ret;
}
/*if (in.peek() == '(') { // Read any RPN value
- //TODO: Magic goes here
+ //TODO: Magic goes here
}*/
// Read any other value
string str;
// can't use operator>> -- that will consume comments in cases like \w12000//comment
eat_white(in); // skip whitespace at front
- while(in && !is_comment(in) && !isspace(in.peek()) && in.peek() != EOF)
- str += (char)in.get();
+ while (in && !is_comment(in) && !isspace(in.peek()) && in.peek() != EOF) str += (char)in.get();
char c1, c2;
int y, m, d, count = sscanf(str.c_str(), "%d%c%d%c%d", &y, &c1, &m, &c2, &d);
- if (count==1) {
+ if (count == 1) {
// Got a decimal number
- if (w==_B_ && y>=1920) y-=1920; // special case for byte-sized years
+ if (w == _B_ && y >= 1920) y -= 1920; // special case for byte-sized years
return y;
}
@@ -447,27 +459,33 @@
if (w == _W_) {
// word date
- if (d==0 || (d>31 && d<100) || d>1919) swap(y, d); // Try DMY instead
- if (y==0) y = 2000;
- else if (y>31 && y<100) y+=1900;
+ if (d == 0 || (d > 31 && d < 100) || d > 1919) swap(y, d); // Try DMY instead
+ if (y == 0)
+ y = 2000;
+ else if (y > 31 && y < 100)
+ y += 1900;
} else if (w == _D_) {
// dword date
extra = 701265;
if (d >= 32) swap(y, d); // Try DMY instead
// Boost doesn't support years out of the range 1400..9999
- while (y>9999) {
+ while (y > 9999) {
y -= 400;
- extra += 365*400 + 97; // 97 leap years every 400 years.
+ extra += 365 * 400 + 97; // 97 leap years every 400 years.
}
- while (y<1400) {
+ while (y < 1400) {
y += 400;
- extra -= 365*400 + 97;
+ extra -= 365 * 400 + 97;
}
- } else goto fail; // I can't read a date of that width.
+ } else
+ goto fail; // I can't read a date of that width.
- try {
+ try
+ {
return (date((ushort)y, (ushort)m, (ushort)d) - date(1920, 1, 1)).days() + extra;
- } catch (std::out_of_range) {
+ }
+ catch (std::out_of_range)
+ {
// Fall through to fail
}
}
@@ -475,5 +493,5 @@
fail:
// Nothing worked
in.clear(ios::badbit);
- return (uint)-1;
+ return (uint) - 1;
}
diff --git a/src/sanity.cpp b/src/sanity.cpp
--- a/src/sanity.cpp
+++ b/src/sanity.cpp
@@ -19,32 +19,34 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<iostream>
-#include<string>
-#include<cassert>
-#include<cstdarg>
-#include<errno.h>
-#include<cstdlib>
+#include <iostream>
+#include <string>
+#include <cassert>
+#include <cstdarg>
+#include <errno.h>
+#include <cstdlib>
using namespace std;
-#include"nforenum.h"
-#include"globals.h"
-#include"inlines.h"
-#include"command.h"
-#include"messages.h"
-#include"sanity.h"
-#include"ExpandingArray.h"
-#include"sanity_defines.h"
-#include"data.h"
-#include"strings.h"
-#include"pseudo.h"
+#include "nforenum.h"
+#include "globals.h"
+#include "inlines.h"
+#include "command.h"
+#include "messages.h"
+#include "sanity.h"
+#include "ExpandingArray.h"
+#include "sanity_defines.h"
+#include "data.h"
+#include "strings.h"
+#include "pseudo.h"
bool _base_grf = false;
-class features{
-public:
+class features
+{
+ public:
uint maxFeat;
- struct featdat{
+ struct featdat
+ {
uchar validbits;
uchar act2type;
};
@@ -52,78 +54,116 @@
SINGLETON(features)
};
-features::features(){
- FILE*pFile=myfopen(feat);
- maxFeat=GetCheckByte(feat);
- _p=new features::featdat[maxFeat+1];
- uint i=0;
- for(;i<=maxFeat;i++) _p[i].validbits=(uchar)GetCheckByte(feat);
- for(i=0;i<=maxFeat;i++) _p[i].act2type=(uchar)GetCheckByte(feat);
+features::features()
+{
+ FILE* pFile = myfopen(feat);
+ maxFeat = GetCheckByte(feat);
+ _p = new features::featdat[maxFeat + 1];
+ uint i = 0;
+ for (; i <= maxFeat; i++) _p[i].validbits = (uchar)GetCheckByte(feat);
+ for (i = 0; i <= maxFeat; i++) _p[i].act2type = (uchar)GetCheckByte(feat);
fclose(pFile);
}
-bool IsValidFeature(int act,uint feat){
- if(feat>features::Instance().maxFeat)return false;
- return(features::Instance()[feat].validbits&act)!=0;
+bool IsValidFeature(int act, uint feat)
+{
+ if (feat > features::Instance().maxFeat) return false;
+ return (features::Instance()[feat].validbits & act) != 0;
}
-bool IsValid2Feature(uint feat){
- if(feat>features::Instance().maxFeat)return false;
- return features::Instance()[feat].act2type!=0xFF;
+bool IsValid2Feature(uint feat)
+{
+ if (feat > features::Instance().maxFeat) return false;
+ return features::Instance()[feat].act2type != 0xFF;
}
-uchar Get2Type(uint feat){
- if(feat>features::Instance().maxFeat)return 0xFF;
+uchar Get2Type(uint feat)
+{
+ if (feat > features::Instance().maxFeat) return 0xFF;
return features::Instance()[feat].act2type;
}
-uint MaxFeature(){return features::Instance().maxFeat;}
+uint MaxFeature()
+{
+ return features::Instance().maxFeat;
+}
#define MAX_TTD_SPRITE 4894
-static struct sanity{
- sanity(){init();}
- void init(){
- state=FIND_PSEUDO;
+static struct sanity
+{
+ sanity()
+ {
+ init();
+ }
+ void init()
+ {
+ state = FIND_PSEUDO;
defined10IDs.init();
- act8=act11=act14=0;
+ act8 = act11 = act14 = 0;
}
sanstate state;
- unsigned int expectedsprites,seensprites,spritenum,act8,act11,act14,minnextlen;
- class labelArray{
- public:
- labelArray(){init();}
- void init(){used.resize(0);sprite.resize(0);}
- bool is_defined(int id)const{return sprite[id]!=0;}
- bool is_used(int id)const{return used[id];}
- uint defined_at(int id)const{return sprite[id];}
- void define(uint id){sprite[id]=_spritenum;used[id]=false;}
- void use(int id){used[id]=true;}
- protected:
- Expanding0Array<bool>used;
- Expanding0Array<uint>sprite;
- }defined10IDs;
-}status;
-static const sanity&crStatus=status;
+ unsigned int expectedsprites, seensprites, spritenum, act8, act11, act14, minnextlen;
+ class labelArray
+ {
+ public:
+ labelArray()
+ {
+ init();
+ }
+ void init()
+ {
+ used.resize(0);
+ sprite.resize(0);
+ }
+ bool is_defined(int id) const
+ {
+ return sprite[id] != 0;
+ }
+ bool is_used(int id) const
+ {
+ return used[id];
+ }
+ uint defined_at(int id) const
+ {
+ return sprite[id];
+ }
+ void define(uint id)
+ {
+ sprite[id] = _spritenum;
+ used[id] = false;
+ }
+ void use(int id)
+ {
+ used[id] = true;
+ }
+
+ protected:
+ Expanding0Array<bool> used;
+ Expanding0Array<uint> sprite;
+ } defined10IDs;
+} status;
+static const sanity& crStatus = status;
void Init123();
void InitF();
void ClearTextIDs();
void Check0(PseudoSprite&);
-int Check1(PseudoSprite&);
+int Check1(PseudoSprite&);
void Check2(PseudoSprite&);
void Check3(PseudoSprite&);
-int Check5(PseudoSprite&,sanstate&);
+int Check5(PseudoSprite&, sanstate&);
uint Check6(PseudoSprite&);
-int Check7(PseudoSprite&);
+int Check7(PseudoSprite&);
void CheckB(PseudoSprite&);
-bool CheckD(PseudoSprite&,uint);
+bool CheckD(PseudoSprite&, uint);
void CheckF(PseudoSprite&);
void Check13(PseudoSprite&);
void Check14(PseudoSprite&);
void invalidate_act3();
-void reset_sanity(){
+void reset_sanity()
+{
status.init();
Init0();
Init123();
@@ -132,345 +172,377 @@
ClearTextIDs();
}
-bool IsLabel(uint x){
- VERIFY(x<0x100,x);
+bool IsLabel(uint x)
+{
+ VERIFY(x < 0x100, x);
return status.defined10IDs.is_defined(x);
}
-void Seen8(int action){
- if(status.act8==0){
- IssueMessage(ERROR,MISSING_8,action);
- status.act8=(unsigned)-1;
+void Seen8(int action)
+{
+ if (status.act8 == 0) {
+ IssueMessage(ERROR, MISSING_8, action);
+ status.act8 = (unsigned)-1;
}
}
-void Before8(int action){
- if(status.act8!=0){
- IssueMessage(ERROR,BEFORE_8,action);
+void Before8(int action)
+{
+ if (status.act8 != 0) {
+ IssueMessage(ERROR, BEFORE_8, action);
}
}
-bool CheckLength(int alen,int elen,RenumMessageId message,...){
+bool CheckLength(int alen, int elen, RenumMessageId message, ...)
+{
WrapAp(message);
- if(alen<elen){
- vIssueMessage(FATAL,message,ap);
+ if (alen < elen) {
+ vIssueMessage(FATAL, message, ap);
return true;
}
- if(alen>elen)
- vIssueMessage(WARNING2,message,ap);
+ if (alen > elen) vIssueMessage(WARNING2, message, ap);
return false;
}
-void SetState(sanstate x){
- if((signed)status.expectedsprites==-1)status.state=UNKNOWN;
- else if(status.expectedsprites==0)status.state=FIND_PSEUDO;
- else status.state=x;
+void SetState(sanstate x)
+{
+ if ((signed)status.expectedsprites == -1)
+ status.state = UNKNOWN;
+ else if (status.expectedsprites == 0)
+ status.state = FIND_PSEUDO;
+ else
+ status.state = x;
}
-void check_sprite(SpriteType type){
- if(GetState(LINT)==OFF)return;
- switch(status.state){
- case FIND_PSEUDO:
- if(type==REAL){
- IssueMessage(ERROR,UNEXPECTED,REAL_S);
- status.state=UNKNOWN;
- }else if(type==INCLUDE){
- IssueMessage(ERROR,UNEXPECTED,BIN_INCLUDE);
- status.state=UNKNOWN;
- }
- return;
- case FIND_REAL:
- case FIND_REAL_OR_RECOLOR:
- if(type==INCLUDE){
- IssueMessage(ERROR,UNEXPECTED,BIN_INCLUDE);
- status.state=UNKNOWN;
- }else if(++status.seensprites==status.expectedsprites)
- status.state=FIND_PSEUDO;
- else if(status.seensprites>status.expectedsprites){
- IssueMessage(ERROR,EXTRA,REAL_S,status.expectedsprites,status.spritenum);
- status.state=UNKNOWN;
- }
- return;
- case FIND_INCLUDE:
- if(type==REAL){
- IssueMessage(ERROR,UNEXPECTED,REAL_S);
- status.state=UNKNOWN;
- }else if(++status.seensprites==status.expectedsprites)
- status.state=FIND_PSEUDO;
- else if(status.seensprites>status.expectedsprites){
- IssueMessage(ERROR,EXTRA,BIN_INCLUDE,status.expectedsprites,status.spritenum);
- status.state=UNKNOWN;
- }
- return;
- case FIND_RECOLOR:
- if(type==REAL){
- IssueMessage(ERROR,UNEXPECTED,REAL_S);
- status.state=UNKNOWN;
- }else if(type==INCLUDE){
- IssueMessage(ERROR,UNEXPECTED,BIN_INCLUDE);
- status.state=UNKNOWN;
- }else if(++status.seensprites==status.expectedsprites)
- status.state=FIND_PSEUDO;
- return;
- case UNKNOWN:return;
- DEFAULT(status.state)
+void check_sprite(SpriteType type)
+{
+ if (GetState(LINT) == OFF) return;
+ switch (status.state) {
+ case FIND_PSEUDO:
+ if (type == REAL) {
+ IssueMessage(ERROR, UNEXPECTED, REAL_S);
+ status.state = UNKNOWN;
+ } else if (type == INCLUDE) {
+ IssueMessage(ERROR, UNEXPECTED, BIN_INCLUDE);
+ status.state = UNKNOWN;
+ }
+ return;
+ case FIND_REAL:
+ case FIND_REAL_OR_RECOLOR:
+ if (type == INCLUDE) {
+ IssueMessage(ERROR, UNEXPECTED, BIN_INCLUDE);
+ status.state = UNKNOWN;
+ } else if (++status.seensprites == status.expectedsprites)
+ status.state = FIND_PSEUDO;
+ else if (status.seensprites > status.expectedsprites) {
+ IssueMessage(ERROR, EXTRA, REAL_S, status.expectedsprites, status.spritenum);
+ status.state = UNKNOWN;
+ }
+ return;
+ case FIND_INCLUDE:
+ if (type == REAL) {
+ IssueMessage(ERROR, UNEXPECTED, REAL_S);
+ status.state = UNKNOWN;
+ } else if (++status.seensprites == status.expectedsprites)
+ status.state = FIND_PSEUDO;
+ else if (status.seensprites > status.expectedsprites) {
+ IssueMessage(ERROR, EXTRA, BIN_INCLUDE, status.expectedsprites, status.spritenum);
+ status.state = UNKNOWN;
+ }
+ return;
+ case FIND_RECOLOR:
+ if (type == REAL) {
+ IssueMessage(ERROR, UNEXPECTED, REAL_S);
+ status.state = UNKNOWN;
+ } else if (type == INCLUDE) {
+ IssueMessage(ERROR, UNEXPECTED, BIN_INCLUDE);
+ status.state = UNKNOWN;
+ } else if (++status.seensprites == status.expectedsprites)
+ status.state = FIND_PSEUDO;
+ return;
+ case UNKNOWN:
+ return;
+ DEFAULT(status.state)
}
}
-void check_sprite(PseudoSprite&data){
- if(GetState(LINT)==OFF)return;
- const uint length=data.Length();
- if(length==1&&data.ExtractByte(0)==0&&status.state==FIND_REAL){
+void check_sprite(PseudoSprite& data)
+{
+ if (GetState(LINT) == OFF) return;
+ const uint length = data.Length();
+ if (length == 1 && data.ExtractByte(0) == 0 && status.state == FIND_REAL) {
check_sprite(REAL);
return;
}
- if((status.state==FIND_RECOLOR||status.state==FIND_REAL_OR_RECOLOR)&&length==257&&data.ExtractByte(0)==0){
+ if ((status.state == FIND_RECOLOR || status.state == FIND_REAL_OR_RECOLOR) && length == 257 && data.ExtractByte(0) == 0) {
check_sprite(RECOLOR);
data.SetAllHex();
- data.SetEol(32,1);
- data.SetEol(64,1);
- data.SetEol(96,1);
- data.SetEol(128,1);
- data.SetEol(160,1);
- data.SetEol(192,1);
- data.SetEol(224,1);
+ data.SetEol(32, 1);
+ data.SetEol(64, 1);
+ data.SetEol(96, 1);
+ data.SetEol(128, 1);
+ data.SetEol(160, 1);
+ data.SetEol(192, 1);
+ data.SetEol(224, 1);
return;
}
- if(data.ExtractByte(0)==0xFF||data.ExtractByte(0)==0xFE)check_sprite(INCLUDE);
- else{
- switch(status.state){
- case FIND_REAL:
- case FIND_REAL_OR_RECOLOR:
- case FIND_INCLUDE:
- case FIND_RECOLOR:
- IssueMessage(ERROR,INSUFFICIENT,
- status.state==FIND_INCLUDE?BIN_INCLUDE:(status.state==FIND_RECOLOR?RECOLOR_TABLE:REAL_S),
- status.spritenum,status.expectedsprites,status.seensprites);
- status.state=UNKNOWN;
- case FIND_PSEUDO:
- case UNKNOWN:break;
- DEFAULT(status.state)
+ if (data.ExtractByte(0) == 0xFF || data.ExtractByte(0) == 0xFE)
+ check_sprite(INCLUDE);
+ else {
+ switch (status.state) {
+ case FIND_REAL:
+ case FIND_REAL_OR_RECOLOR:
+ case FIND_INCLUDE:
+ case FIND_RECOLOR:
+ IssueMessage(
+ ERROR, INSUFFICIENT,
+ status.state == FIND_INCLUDE ? BIN_INCLUDE : (status.state == FIND_RECOLOR ? RECOLOR_TABLE : REAL_S),
+ status.spritenum, status.expectedsprites, status.seensprites);
+ status.state = UNKNOWN;
+ case FIND_PSEUDO:
+ case UNKNOWN:
+ break;
+ DEFAULT(status.state)
}
}
- if(status.minnextlen>length)
- IssueMessage(ERROR,MODIFY_BEYOND_LENGTH);
- status.minnextlen=0;
- try{
- const int act=data.ExtractByte(0);
- if(act!=3&&act!=6&&act!=7&&act!=9&&act!=0xC)invalidate_act3();
- if(act == 0x14)
- Before8(act);
- else if(act<6 || act==0xA || act==0xF || act>0x11)
- Seen8(act);
- switch(act){
- case 0:
- data.SetAllHex();
- Check0(data);
- break;
- case 1:
- data.SetAllHex();
- status.expectedsprites=Check1(data);
- SetState(FIND_REAL);
- status.spritenum=_spritenum;
- status.seensprites=0;
- break;
- case 2:
- Check2(data);
- break;
- case 3:
- data.SetAllHex();
- Check3(data);
- break;
- case 4:
- Check4(data);
- break;
- case 5:
- data.SetAllHex();
- status.expectedsprites=Check5(data,status.state);
- SetState(status.state);
- status.spritenum=_spritenum;
- status.seensprites=0;
- break;
- case 6:
- data.SetAllHex();
- status.minnextlen=Check6(data);
- break;
- case 7:case 9:{
- status.defined10IDs.use(Check7(data));
- break;
- }case 8:{
- if(status.act8!=0&&status.act8!=(unsigned)-1)IssueMessage(ERROR,DUPLICATE_ACT,8,status.act8);
- status.act8=_spritenum;
- _grfver=data.ExtractByte(1);
- if(_grfver<2||_grfver>8)IssueMessage(ERROR,INVALID_VERSION,GRF);
- if(status.act14!=0&&_grfver<7)IssueMessage(ERROR,INVALID_VERSION_ACT14,_grfver);
- if(_act14_pal==0&&_grfver>=7)IssueMessage(WARNING1,MISSING_PALETTE_INFO);
- const uint GRFid=data.ExtractDword(2);
- data.SetGRFID(2);
- _base_grf=(GRFid&0xFFFFFF)==0x00544FFF;
- if(!_base_grf&&(GRFid&0xFF)==0xFF&&GRFid!=0xFFFFFFFF)IssueMessage(WARNING1,RESERVED_GRFID);
- if(length<8){
- IssueMessage(ERROR,INVALID_LENGTH,ACTION,8,AT_LEAST,8);
- break;
+ if (status.minnextlen > length) IssueMessage(ERROR, MODIFY_BEYOND_LENGTH);
+ status.minnextlen = 0;
+ try
+ {
+ const int act = data.ExtractByte(0);
+ if (act != 3 && act != 6 && act != 7 && act != 9 && act != 0xC) invalidate_act3();
+ if (act == 0x14)
+ Before8(act);
+ else if (act < 6 || act == 0xA || act == 0xF || act > 0x11)
+ Seen8(act);
+ switch (act) {
+ case 0:
+ data.SetAllHex();
+ Check0(data);
+ break;
+ case 1:
+ data.SetAllHex();
+ status.expectedsprites = Check1(data);
+ SetState(FIND_REAL);
+ status.spritenum = _spritenum;
+ status.seensprites = 0;
+ break;
+ case 2:
+ Check2(data);
+ break;
+ case 3:
+ data.SetAllHex();
+ Check3(data);
+ break;
+ case 4:
+ Check4(data);
+ break;
+ case 5:
+ data.SetAllHex();
+ status.expectedsprites = Check5(data, status.state);
+ SetState(status.state);
+ status.spritenum = _spritenum;
+ status.seensprites = 0;
+ break;
+ case 6:
+ data.SetAllHex();
+ status.minnextlen = Check6(data);
+ break;
+ case 7:
+ case 9: {
+ status.defined10IDs.use(Check7(data));
+ break;
+ }
+ case 8: {
+ if (status.act8 != 0 && status.act8 != (unsigned)-1) IssueMessage(ERROR, DUPLICATE_ACT, 8, status.act8);
+ status.act8 = _spritenum;
+ _grfver = data.ExtractByte(1);
+ if (_grfver < 2 || _grfver > 8) IssueMessage(ERROR, INVALID_VERSION, GRF);
+ if (status.act14 != 0 && _grfver < 7) IssueMessage(ERROR, INVALID_VERSION_ACT14, _grfver);
+ if (_act14_pal == 0 && _grfver >= 7) IssueMessage(WARNING1, MISSING_PALETTE_INFO);
+ const uint GRFid = data.ExtractDword(2);
+ data.SetGRFID(2);
+ _base_grf = (GRFid & 0xFFFFFF) == 0x00544FFF;
+ if (!_base_grf && (GRFid & 0xFF) == 0xFF && GRFid != 0xFFFFFFFF) IssueMessage(WARNING1, RESERVED_GRFID);
+ if (length < 8) {
+ IssueMessage(ERROR, INVALID_LENGTH, ACTION, 8, AT_LEAST, 8);
+ break;
+ }
+ uint offs = 6;
+ CheckString(data, offs, CTRL_COLOR);
+ try
+ {
+ if (data[offs]) data.SetEol(offs - 1, 1);
+ }
+ catch (uint)
+ {
+ IssueMessage(WARNING1, NO_NULL_FOUND);
+ }
+ CheckString(data, offs, CTRL_COLOR | CTRL_NEWLINE);
+ if (offs < length) IssueMessage(WARNING2, EXTRA_DATA, length, offs);
+ break;
+ }
+ case 0xA:
+ data.SetAllHex();
+ status.state = UNKNOWN;
+ status.seensprites = data.ExtractByte(1);
+ if (_autocorrect && length % 3 == 2 && length / 3 != status.seensprites && length / 3 < 256) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, NUMSETS, data.ExtractByte(1), length / 3);
+ data.SetByteAt(1, status.seensprites = length / 3);
+ }
+ if (!status.seensprites) IssueMessage(WARNING1, NO_SETS, 0x0A);
+ if (CheckLength(length, 2 + 3 * status.seensprites, BAD_LENGTH, BYTE1, VAL, status.seensprites,
+ 2 + 3 * status.seensprites))
+ return;
+ status.expectedsprites = 0;
+ for (uint i = 0; i < status.seensprites; i++) {
+ int sprites = data.ExtractByte(2 + 3 * i);
+ if (!sprites)
+ IssueMessage(WARNING1, SET_WITH_NO_SPRITES, 2 + 3 * i, i);
+ else if (data.ExtractWord(3 + 3 * i) + sprites - 1 > MAX_TTD_SPRITE)
+ IssueMessage(ERROR, SPRITENUM_TOO_HIGH, 2 + 3 * i);
+ status.expectedsprites += sprites;
+ }
+ status.spritenum = _spritenum;
+ status.seensprites = 0;
+ SetState(FIND_REAL_OR_RECOLOR);
+ break;
+ case 0xB:
+ data.SetAllHex();
+ CheckB(data);
+ case 0xC:
+ break;
+ case 0xD:
+ if (CheckD(data, length)) Seen8(0xD);
+ break;
+ case 0xE: {
+ uint numids = data.SetHex(1).ExtractByte(1);
+ if (_autocorrect && length % 4 == 2 && length / 4 != numids && length / 4 < 256) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, NUM, numids, length / 4);
+ data.SetByteAt(1, numids = length / 4);
+ }
+ if (CheckLength(length, 2 + 4 * numids, BAD_LENGTH, NUM, VAL, numids, 2 + 4 * numids)) return;
+ if (!numids) IssueMessage(WARNING1, NO_GRFIDS);
+ if (numids < 2) return;
+ uint* id = new uint[numids];
+ for (uint i = 0; i < numids; i++) {
+ if (((id[i] = data.SetGRFID(2 + i * 4).ExtractDword(2 + i * 4)) & 0xFF) == 0xFF)
+ IssueMessage(WARNING1, INVALID_GRFID, 2 + i * 4, 0xE);
+ for (uint j = 0; j < i; j++)
+ if (id[i] == id[j]) IssueMessage(WARNING1, DUPLICATE_GRFID, 2 + i * 4, 2 + j * 4, id[i]);
+ }
+ delete[] id;
+ break;
+ }
+ case 0xF:
+ CheckF(data);
+ break;
+ case 0x10: {
+ if (length < 2) {
+ IssueMessage(FATAL, INVALID_LENGTH, ACTION, 0x10, AT_LEAST, 2);
+ break;
+ }
+ int label = data.SetHex(1).ExtractByte(1);
+ if (!crStatus.defined10IDs.is_used(label)) {
+ if (crStatus.defined10IDs.is_defined(label))
+ IssueMessage(WARNING1, UNUSED_LABEL_PREV_DEF, label,
+ crStatus.defined10IDs.defined_at(label));
+ else
+ IssueMessage(WARNING2, UNUSED_LABEL_NO_PREV_DEF, label);
+ }
+ status.defined10IDs.define(label);
+ break;
+ }
+ case 0x11:
+ status.state = UNKNOWN;
+ data.SetAllHex();
+ if (CheckLength(length, 3, INVALID_LENGTH, ACTION, 0x11, EXACTLY, 3)) return;
+ if (status.act11) IssueMessage(ERROR, DUPLICATE_ACT, 0x11, status.act11);
+ status.expectedsprites = data.ExtractWord(1);
+ status.act11 = status.spritenum = _spritenum;
+ SetState(FIND_INCLUDE);
+ status.seensprites = 0;
+ break;
+ case 0x12:
+ data.SetAllHex();
+ status.state = UNKNOWN;
+ status.seensprites = data.ExtractByte(1);
+ if (_autocorrect && length % 4 == 2 && length / 4 != status.seensprites && length / 4 < 256) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 1, NUMDEFS, status.seensprites, length / 4);
+ data.SetByteAt(1, status.seensprites = length / 4);
+ }
+ if (!status.seensprites) IssueMessage(WARNING1, NO_SETS, 0x12);
+ if (CheckLength(length, 2 + 4 * status.seensprites, BAD_LENGTH, BYTE1, VAL, status.seensprites,
+ 2 + 4 * status.seensprites))
+ return;
+ status.expectedsprites = 0;
+ for (uint i = 0; i < status.seensprites; i++) {
+ uint sprites = data.ExtractByte(2 + 4 * i);
+ if (sprites > 3) IssueMessage(ERROR, INVALID_FONT, 2 + 4 * i, sprites);
+ sprites = data.ExtractByte(3 + 4 * i);
+ if (!sprites)
+ IssueMessage(WARNING1, SET_WITH_NO_SPRITES, 3 + 4 * i, i);
+ else if ((data.ExtractWord(4 + 4 * i) & ~0x7F) !=
+ ((data.ExtractWord(4 + 4 * i) + sprites - 1) & ~0x7F))
+ IssueMessage(ERROR, SPANS_BLOCKS, 3 + 4 * i, i);
+ status.expectedsprites += sprites;
+ }
+ status.spritenum = _spritenum;
+ status.seensprites = 0;
+ SetState(FIND_REAL);
+ break;
+ case 0x13:
+ Check13(data);
+ break;
+ case 0x14:
+ if (status.act14 == 0) status.act14 = _spritenum;
+ Check14(data);
+ break;
+ case 0xFE: {
+ if (CheckLength(length, 8, INVALID_LENGTH, IMPORTS, EXACTLY, 8)) return;
+ uint feat = data.SetAllHex().ExtractByte(1);
+ if (feat) IssueMessage(ERROR, INVALID_LITERAL, 1, feat, 0);
+ if (data.ExtractByte(2) == 0xFF) IssueMessage(WARNING1, INVALID_GRFID, 2, 0x11);
+ data.SetGRFID(2);
+ break;
+ }
+ case 0xFF:
+ // if(data.ExtractByte(data.ExtractByte(1)+2))
+ break;
+ default:
+ IssueMessage(FATAL, INVALID_ACTION);
}
- uint offs=6;
- CheckString(data,offs,CTRL_COLOR);
- try{
- if(data[offs])data.SetEol(offs-1,1);
- }catch(uint){
- IssueMessage(WARNING1,NO_NULL_FOUND);
- }
- CheckString(data,offs,CTRL_COLOR|CTRL_NEWLINE);
- if(offs<length)IssueMessage(WARNING2,EXTRA_DATA,length,offs);
- break;
- }case 0xA:
- data.SetAllHex();
- status.state=UNKNOWN;
- status.seensprites=data.ExtractByte(1);
- if(_autocorrect&&length%3==2&&length/3!=status.seensprites&&length/3<256){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,NUMSETS,data.ExtractByte(1),length/3);
- data.SetByteAt(1,status.seensprites=length/3);
- }
- if(!status.seensprites)IssueMessage(WARNING1,NO_SETS,0x0A);
- if(CheckLength(length,2+3*status.seensprites,BAD_LENGTH,BYTE1,VAL,status.seensprites,2+3*status.seensprites))
- return;
- status.expectedsprites=0;
- for(uint i=0;i<status.seensprites;i++){
- int sprites=data.ExtractByte(2+3*i);
- if(!sprites)
- IssueMessage(WARNING1,SET_WITH_NO_SPRITES,2+3*i,i);
- else if(data.ExtractWord(3+3*i)+sprites-1>MAX_TTD_SPRITE)
- IssueMessage(ERROR,SPRITENUM_TOO_HIGH,2+3*i);
- status.expectedsprites+=sprites;
- }
- status.spritenum=_spritenum;
- status.seensprites=0;
- SetState(FIND_REAL_OR_RECOLOR);
- break;
- case 0xB:
- data.SetAllHex();
- CheckB(data);
- case 0xC:break;
- case 0xD:
- if(CheckD(data,length))Seen8(0xD);
- break;
- case 0xE:{
- uint numids=data.SetHex(1).ExtractByte(1);
- if(_autocorrect&&length%4==2&&length/4!=numids&&length/4<256){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,NUM,numids,length/4);
- data.SetByteAt(1,numids=length/4);
- }
- if(CheckLength(length,2+4*numids,BAD_LENGTH,NUM,VAL,numids,2+4*numids))return;
- if(!numids)IssueMessage(WARNING1,NO_GRFIDS);
- if(numids<2)return;
- uint*id=new uint[numids];
- for(uint i=0;i<numids;i++){
- if(((id[i]=data.SetGRFID(2+i*4).ExtractDword(2+i*4))&0xFF)==0xFF)IssueMessage(WARNING1,INVALID_GRFID,2+i*4,0xE);
- for(uint j=0;j<i;j++)
- if(id[i]==id[j])IssueMessage(WARNING1,DUPLICATE_GRFID,2+i*4,2+j*4,id[i]);
- }
- delete[]id;
- break;
- }case 0xF:
- CheckF(data);
- break;
- case 0x10:{
- if(length<2){
- IssueMessage(FATAL,INVALID_LENGTH,ACTION,0x10,AT_LEAST,2);
- break;
- }
- int label=data.SetHex(1).ExtractByte(1);
- if(!crStatus.defined10IDs.is_used(label)){
- if(crStatus.defined10IDs.is_defined(label))
- IssueMessage(WARNING1,UNUSED_LABEL_PREV_DEF,label,crStatus.defined10IDs.defined_at(label));
- else
- IssueMessage(WARNING2,UNUSED_LABEL_NO_PREV_DEF,label);
- }
- status.defined10IDs.define(label);
- break;
- }case 0x11:
- status.state=UNKNOWN;
- data.SetAllHex();
- if(CheckLength(length,3,INVALID_LENGTH,ACTION,0x11,EXACTLY,3))return;
- if(status.act11)IssueMessage(ERROR,DUPLICATE_ACT,0x11,status.act11);
- status.expectedsprites=data.ExtractWord(1);
- status.act11=status.spritenum=_spritenum;
- SetState(FIND_INCLUDE);
- status.seensprites=0;
- break;
- case 0x12:
- data.SetAllHex();
- status.state=UNKNOWN;
- status.seensprites=data.ExtractByte(1);
- if(_autocorrect&&length%4==2&&length/4!=status.seensprites&&length/4<256){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,1,NUMDEFS,status.seensprites,length/4);
- data.SetByteAt(1,status.seensprites=length/4);
- }
- if(!status.seensprites)IssueMessage(WARNING1,NO_SETS,0x12);
- if(CheckLength(length,2+4*status.seensprites,BAD_LENGTH,BYTE1,VAL,status.seensprites,2+4*status.seensprites))
- return;
- status.expectedsprites=0;
- for(uint i=0;i<status.seensprites;i++){
- uint sprites=data.ExtractByte(2+4*i);
- if(sprites>3)IssueMessage(ERROR,INVALID_FONT,2+4*i,sprites);
- sprites=data.ExtractByte(3+4*i);
- if(!sprites)
- IssueMessage(WARNING1,SET_WITH_NO_SPRITES,3+4*i,i);
- else if((data.ExtractWord(4+4*i)&~0x7F)!=((data.ExtractWord(4+4*i)+sprites-1)&~0x7F))
- IssueMessage(ERROR,SPANS_BLOCKS,3+4*i,i);
- status.expectedsprites+=sprites;
- }
- status.spritenum=_spritenum;
- status.seensprites=0;
- SetState(FIND_REAL);
- break;
- case 0x13:
- Check13(data);
- break;
- case 0x14:
- if (status.act14==0) status.act14=_spritenum;
- Check14(data);
- break;
- case 0xFE:{
- if(CheckLength(length,8,INVALID_LENGTH,IMPORTS,EXACTLY,8))return;
- uint feat=data.SetAllHex().ExtractByte(1);
- if(feat)IssueMessage(ERROR,INVALID_LITERAL,1,feat,0);
- if(data.ExtractByte(2)==0xFF)IssueMessage(WARNING1,INVALID_GRFID,2,0x11);
- data.SetGRFID(2);
- break;
- }case 0xFF:
- //if(data.ExtractByte(data.ExtractByte(1)+2))
- break;
- default:
- IssueMessage(FATAL,INVALID_ACTION);
}
- }catch(unsigned int off){
- IssueMessage(FATAL,TOO_SHORT,EXPECTED_LOC(off),EXPECTED_BYTES(off));
+ catch (unsigned int off)
+ {
+ IssueMessage(FATAL, TOO_SHORT, EXPECTED_LOC(off), EXPECTED_BYTES(off));
}
-
}
-void final_sanity(){
- if(GetState(LINT)==OFF)return;
- if(status.seensprites<status.expectedsprites){
- switch(status.state){
- case FIND_REAL:
- case FIND_REAL_OR_RECOLOR:
- IssueMessage(ERROR,INSUFFICIENT,REAL_S,status.spritenum,status.expectedsprites,status.seensprites);
- break;
- case FIND_INCLUDE:
- IssueMessage(ERROR,INSUFFICIENT,BIN_INCLUDE,status.spritenum,status.expectedsprites,status.seensprites);
- break;
- case FIND_RECOLOR:
- IssueMessage(ERROR,INSUFFICIENT,RECOLOR_TABLE,status.spritenum,status.expectedsprites,status.seensprites);
- default:;//Intentionally ignoring FIND_PSEUDO and UNKNOWN
+void final_sanity()
+{
+ if (GetState(LINT) == OFF) return;
+ if (status.seensprites < status.expectedsprites) {
+ switch (status.state) {
+ case FIND_REAL:
+ case FIND_REAL_OR_RECOLOR:
+ IssueMessage(ERROR, INSUFFICIENT, REAL_S, status.spritenum, status.expectedsprites, status.seensprites);
+ break;
+ case FIND_INCLUDE:
+ IssueMessage(ERROR, INSUFFICIENT, BIN_INCLUDE, status.spritenum, status.expectedsprites,
+ status.seensprites);
+ break;
+ case FIND_RECOLOR:
+ IssueMessage(ERROR, INSUFFICIENT, RECOLOR_TABLE, status.spritenum, status.expectedsprites,
+ status.seensprites);
+ default:
+ ; // Intentionally ignoring FIND_PSEUDO and UNKNOWN
}
}
- if(status.minnextlen)
- IssueMessage(ERROR,NO_FOLLOWING_SPRITE);
+ if (status.minnextlen) IssueMessage(ERROR, NO_FOLLOWING_SPRITE);
final123();
final7();
finalF();
diff --git a/src/sanity.h b/src/sanity.h
--- a/src/sanity.h
+++ b/src/sanity.h
@@ -24,17 +24,22 @@
class PseudoSprite;
-enum SpriteType{REAL,PSEUDO,INCLUDE,RECOLOR};
+enum SpriteType {
+ REAL,
+ PSEUDO,
+ INCLUDE,
+ RECOLOR
+};
void reset_sanity();
-void check_sprite(SpriteType);//real/include
-void check_sprite(PseudoSprite&);//Pseudo
+void check_sprite(SpriteType); // real/include
+void check_sprite(PseudoSprite&); // Pseudo
void final_sanity();
void sanity_use_id(int);
void sanity_use_set(int);
void sanity_test_id(int);
int sanity_locate_id(int);
-void sanity_define_id(int,int);
+void sanity_define_id(int, int);
int sanity_get_feature(int);
-#endif//_RENUM_SANITY_H_DEFINED
+#endif //_RENUM_SANITY_H_DEFINED
diff --git a/src/sanity_defines.h b/src/sanity_defines.h
--- a/src/sanity_defines.h
+++ b/src/sanity_defines.h
@@ -25,9 +25,9 @@
#include <cstdarg>
#include "message_mgr.h"
-bool CheckLength(int,int,RenumMessageId,...);
-bool CheckTextID(uint,uint,uint);
-bool CheckID(uint,uint);
+bool CheckLength(int, int, RenumMessageId, ...);
+bool CheckTextID(uint, uint, uint);
+bool CheckID(uint, uint);
void Init0();
void Init123();
@@ -38,58 +38,111 @@
void finalF();
bool IsLabel(uint);
-//int GetBit(const string&);
+// int GetBit(const string&);
-enum ActBit{ACT0=1,ACT1=2,ACT3=4,ACT4=8,EMPTY1=0x10,OVERRIDE3=0x20,GENERIC3=0x40,ACT3_BEFORE_PROP08=0x80};
-enum sanstate{UNKNOWN,FIND_PSEUDO,FIND_REAL,FIND_INCLUDE,FIND_RECOLOR,FIND_REAL_OR_RECOLOR};
+enum ActBit {
+ ACT0 = 1,
+ ACT1 = 2,
+ ACT3 = 4,
+ ACT4 = 8,
+ EMPTY1 = 0x10,
+ OVERRIDE3 = 0x20,
+ GENERIC3 = 0x40,
+ ACT3_BEFORE_PROP08 = 0x80
+};
+enum sanstate {
+ UNKNOWN,
+ FIND_PSEUDO,
+ FIND_REAL,
+ FIND_INCLUDE,
+ FIND_RECOLOR,
+ FIND_REAL_OR_RECOLOR
+};
-bool IsValidFeature(int actbits,uint feat);
+bool IsValidFeature(int actbits, uint feat);
bool IsValid2Feature(uint feat);
-bool IsProp08Set(uint feat,uint id);
+bool IsProp08Set(uint feat, uint id);
uchar Get2Type(uint feat);
uint MaxFeature();
-template<typename _Ty>class auto_array{//can't use auto_ptr because I use new[]/delete[]
-public:
- auto_array():_p(NULL){}
- ~auto_array(){delete[]_p;}
- operator _Ty*&(){return _p;}
- operator const _Ty*()const{return _p;}
- const _Ty* operator=(_Ty*p){return _p=p;}
-protected:
- _Ty*_p;
-private:
+template <typename _Ty>
+class auto_array
+{ // can't use auto_ptr because I use new[]/delete[]
+ public:
+ auto_array() : _p(NULL)
+ {
+ }
+ ~auto_array()
+ {
+ delete[] _p;
+ }
+ operator _Ty*&()
+ {
+ return _p;
+ }
+ operator const _Ty*() const
+ {
+ return _p;
+ }
+ const _Ty* operator=(_Ty* p)
+ {
+ return _p = p;
+ }
+
+ protected:
+ _Ty* _p;
+
+ private:
void operator=(const auto_array<_Ty>&);
auto_array(const auto_array&);
};
typedef auto_array<uint> Guintp;
-#define AUTO_ARRAY(type)\
- auto_array<type>_p;\
- type&operator[](uint x){return _p[x];}\
- type operator[](uint x)const{return _p[x];}\
+#define AUTO_ARRAY(type) \
+ auto_array<type> _p; \
+ type& operator[](uint x) \
+ { \
+ return _p[x]; \
+ } \
+ type operator[](uint x) const \
+ { \
+ return _p[x]; \
+ }
-class apWrapper{
-private:
+class apWrapper
+{
+ private:
va_list _ap;
-public:
- ~apWrapper(){va_end(_ap);}
- operator va_list&(){return _ap;}
- operator const va_list&()const{return _ap;}
+
+ public:
+ ~apWrapper()
+ {
+ va_end(_ap);
+ }
+ operator va_list&()
+ {
+ return _ap;
+ }
+ operator const va_list&() const
+ {
+ return _ap;
+ }
#ifdef __va_copy
- va_list&operator=(va_list&ap){
- __va_copy(_ap,ap);
+ va_list& operator=(va_list& ap)
+ {
+ __va_copy(_ap, ap);
return _ap;
}
#else
- va_list const&operator=(va_list const&ap){
- return _ap=ap;
+ va_list const& operator=(va_list const& ap)
+ {
+ return _ap = ap;
}
#endif
};
-#define WrapAp(v)\
- apWrapper ap;\
- va_start(ap,v);
+#define WrapAp(v) \
+ apWrapper ap; \
+ va_start(ap, v);
-#endif//_RENUM_SANITY_DEFS_H_INCLUDED_
+#endif //_RENUM_SANITY_DEFS_H_INCLUDED_
diff --git a/src/singleton.h b/src/singleton.h
--- a/src/singleton.h
+++ b/src/singleton.h
@@ -23,30 +23,43 @@
#ifndef _RENUM_SINGLETON_H_INCLUDED_
#define _RENUM_SINGLETON_H_INCLUDED_
-//Mutable singleton
-#define SINGLETON(class)\
-public:\
- static class&Instance(){static class obj;return obj;}\
- static const class&CInstance(){return Instance();}\
-private:\
- class();\
- class(const class&);\
+// Mutable singleton
+#define SINGLETON(class) \
+ public: \
+ static class& Instance() \
+ { \
+ static class obj; \
+ return obj; \
+ } \
+ static const class& CInstance() \
+ { \
+ return Instance(); \
+ } \
+ \
+ private: \
+ class(); \
+ class(const class&); \
void operator=(const class&);
-//Immutable singleton
-#define C_SINGLETON(class)\
-public:\
- static const class&Instance(){static const class obj;return obj;}\
-private:\
- class();\
- class(const class&);\
+// Immutable singleton
+#define C_SINGLETON(class) \
+ public: \
+ static const class& Instance() \
+ { \
+ static const class obj; \
+ return obj; \
+ } \
+ \
+ private: \
+ class(); \
+ class(const class&); \
void operator=(const class&);
-//Non-object class
-#define STATIC(class)\
-private:\
- class();\
- class(const class&);\
+// Non-object class
+#define STATIC(class) \
+ private: \
+ class(); \
+ class(const class&); \
void operator=(const class&);
#endif // _RENUM_SINGLETON_H_INCLUDED_
diff --git a/src/sprites.cpp b/src/sprites.cpp
--- a/src/sprites.cpp
+++ b/src/sprites.cpp
@@ -27,22 +27,22 @@
static int decodetile(U8 *buffer, int sx, int sy, CommonPixel *imgbuffer, long tilesize, bool has_mask, bool rgba, int grfcontversion)
{
bool long_format = tilesize > 65535;
- bool long_chunk = grfcontversion == 2 && sx > 256;
+ bool long_chunk = grfcontversion == 2 && sx > 256;
buffer += SpriteInfo::Size(grfcontversion);
if (grfcontversion == 2 && tilesize <= sy * (long_format ? 4 : 2)) return -1;
- for (int y=0; y<sy; y++) {
+ for (int y = 0; y < sy; y++) {
long offset;
if (long_format) {
- U32 *ibuffer = (U32*)buffer;
+ U32 *ibuffer = (U32 *)buffer;
offset = BE_SWAP32(ibuffer[y]);
} else {
- U16 *ibuffer = (U16*)buffer;
+ U16 *ibuffer = (U16 *)buffer;
offset = BE_SWAP16(ibuffer[y]);
}
- long x, islast, chunkstart=0, len, ofs;
+ long x, islast, chunkstart = 0, len, ofs;
do {
if (long_chunk) {
if (grfcontversion == 2 && offset + 3 >= tilesize) return -1;
@@ -59,7 +59,7 @@
// fill from beginning of last chunk to start
// of this one, with "background" colour
- for (x=chunkstart; x<ofs; x++) {
+ for (x = chunkstart; x < ofs; x++) {
imgbuffer->MakeTransparent();
imgbuffer++;
}
@@ -67,7 +67,7 @@
// then copy the number of actual bytes
const U8 *obuffer = buffer + offset;
if (grfcontversion == 2 && offset + len > tilesize) return -1;
- for (x=0; x<len; x++) {
+ for (x = 0; x < len; x++) {
obuffer = imgbuffer->Decode(obuffer, has_mask, rgba);
imgbuffer++;
}
@@ -78,7 +78,7 @@
// and fill from the end of the last chunk to the
// end of the line
- for (x=chunkstart; x<sx; x++) {
+ for (x = chunkstart; x < sx; x++) {
imgbuffer->MakeTransparent();
imgbuffer++;
}
@@ -90,8 +90,8 @@
static int decoderegular(const U8 *buffer, int sx, int sy, CommonPixel *imgbuffer, bool has_mask, bool rgba, int grfcontversion)
{
buffer += SpriteInfo::Size(grfcontversion);
- for (int y=0; y<sy; y++) {
- for (int x=0; x<sx; x++) {
+ for (int y = 0; y < sy; y++) {
+ for (int x = 0; x < sx; x++) {
buffer = imgbuffer->Decode(buffer, has_mask, rgba);
imgbuffer++;
}
@@ -100,7 +100,7 @@
return 1;
}
-static long uncompress(unsigned long size, U8* in, unsigned long *insize, U8* out, unsigned long outsize, int spriteno, int grfcontversion)
+static long uncompress(unsigned long size, U8 *in, unsigned long *insize, U8 *out, unsigned long outsize, int spriteno, int grfcontversion)
{
unsigned long inused, datasize, compsize, *testsize;
@@ -108,18 +108,17 @@
memcpy(out, in, infobytes);
testsize = &datasize;
- if (grfcontversion == 2 || SIZEISCOMPRESSED(in[0])) // size is the compressed size
+ if (grfcontversion == 2 || SIZEISCOMPRESSED(in[0])) // size is the compressed size
testsize = &compsize;
- compsize = infobytes; // initially we only have the info data
+ compsize = infobytes; // initially we only have the info data
datasize = infobytes;
in += infobytes;
inused = infobytes;
while (*testsize < size) {
- S8 code = * ( (S8*) in++);
- if (++inused > *insize)
- break;
+ S8 code = *((S8 *)in++);
+ if (++inused > *insize) break;
compsize++;
@@ -130,32 +129,31 @@
compsize++;
unsigned long count = -(code >> 3);
- unsigned long offset = ( (code & 7) << 8) | ofs;
+ unsigned long offset = ((code & 7) << 8) | ofs;
if (datasize < offset) {
printf("\nOffset too large in sprite %d!\n", spriteno);
exit(2);
}
- if (datasize + count > outsize)
- return -2*(datasize + count);
+ if (datasize + count > outsize) return -2 * (datasize + count);
- U8* copy_src = out + datasize - offset;
- U8* copy_dest = out + datasize;
- for(unsigned long i = 0; i < count; i++) {
- *copy_dest = *copy_src; copy_dest++; copy_src++;
+ U8 *copy_src = out + datasize - offset;
+ U8 *copy_dest = out + datasize;
+ for (unsigned long i = 0; i < count; i++) {
+ *copy_dest = *copy_src;
+ copy_dest++;
+ copy_src++;
}
datasize += count;
} else {
unsigned long skip = code;
- if (code == 0)
- skip = 128;
+ if (code == 0) skip = 128;
- if (datasize + skip > outsize)
- return -2*(datasize + skip);
+ if (datasize + skip > outsize) return -2 * (datasize + skip);
- memmove(out+datasize, in, skip);
+ memmove(out + datasize, in, skip);
in += skip;
inused += skip;
@@ -178,11 +176,17 @@
int i = 0;
if (grfcontversion == 2) {
/* Copy bits 3 and 6 of the nfo and make it, for now, an 8bpp normal GRF. */
- U8 img=0;
- switch(this->depth){
- case DEPTH_8BPP: img=0x04; break;
- case DEPTH_32BPP: img=0x03; break;
- case DEPTH_MASK: img=0x07; break;
+ U8 img = 0;
+ switch (this->depth) {
+ case DEPTH_8BPP:
+ img = 0x04;
+ break;
+ case DEPTH_32BPP:
+ img = 0x03;
+ break;
+ case DEPTH_MASK:
+ img = 0x07;
+ break;
}
buffer[i++] = img | (this->info & (1 << 3 | 1 << 6));
buffer[i++] = this->zoom;
@@ -207,12 +211,21 @@
U8 data = fgetc(grf);
/* According to the documentation bit 0 must always be set, and bits 3 and 6 are the same as in the nfo. */
this->info = (1 << 0) | (data & (1 << 3 | 1 << 6));
- switch(data&0x7){
- case 0x03: this->depth=DEPTH_32BPP; break;
- case 0x04: this->depth=DEPTH_8BPP; break;
- case 0x07: this->depth=DEPTH_MASK; break;
+ switch (data & 0x7) {
+ case 0x03:
+ this->depth = DEPTH_32BPP;
+ break;
+ case 0x04:
+ this->depth = DEPTH_8BPP;
+ break;
+ case 0x07:
+ this->depth = DEPTH_MASK;
+ break;
default: {
- printf("\nUnknown colour depth %02x for sprite %d. GRFCodec currently only supports M, RGBA and RGBAM formats.\n", data&0x7, spriteno);
+ printf(
+ "\nUnknown colour depth %02x for sprite %d. GRFCodec currently only supports M, RGBA and RGBAM "
+ "formats.\n",
+ data & 0x7, spriteno);
exit(2);
}
}
@@ -234,15 +247,15 @@
{
image_writer->setsize(info.xdim, info.ydim);
info_writer->addsprite(first, image_writer->filename(), image_writer->curspritex(), image_writer->curspritey(), info);
- for (int y=0; y<info.ydim; y++) {
- for (int x=0; x<info.xdim; x++)
- image_writer->nextpixel(*image++);
+ for (int y = 0; y < info.ydim; y++) {
+ for (int x = 0; x < info.xdim; x++) image_writer->nextpixel(*image++);
image_writer->newrow();
}
image_writer->spritedone(info.xdim, info.ydim);
}
-int decodesprite(FILE *grf, spritestorage *imgpal, spritestorage *imgrgba, spriteinfowriter *writer, int spriteno, U32 *dataoffset, int grfcontversion)
+int decodesprite(FILE *grf, spritestorage *imgpal, spritestorage *imgrgba, spriteinfowriter *writer, int spriteno, U32 *dataoffset,
+ int grfcontversion)
{
static const char *action = "decoding sprite";
unsigned long size, datasize, inbufsize, outbufsize, startpos, returnpos = 0;
@@ -295,10 +308,10 @@
if (returnpos != 0) size--;
imgpal->setsize(1, 0);
- outbuffer = (U8*) malloc(size);
- //outbuffer[0] = 0xff;
+ outbuffer = (U8 *)malloc(size);
+ // outbuffer[0] = 0xff;
cfread(action, outbuffer, 1, size, grf);
- writer->adddata(size, outbuffer/*+1*/);
+ writer->adddata(size, outbuffer /*+1*/);
imgpal->spritedone();
result = 1;
@@ -310,7 +323,7 @@
fseek(grf, startpos, SEEK_SET);
info.readfromfile(action, grfcontversion, grf, spriteno);
- if(info.zoom >= ZOOM_LEVELS){
+ if (info.zoom >= ZOOM_LEVELS) {
printf("\nUnknown zoom level %02x for sprite %d\n", info.zoom, spriteno);
exit(2);
}
@@ -322,7 +335,7 @@
if (grfcontversion == 2 && HASTRANSPARENCY(info.info)) size -= 4;
- if (grfcontversion == 2 || SIZEISCOMPRESSED(info.info)) { // compressed size stated
+ if (grfcontversion == 2 || SIZEISCOMPRESSED(info.info)) { // compressed size stated
inbufsize = size;
// assume uncompressed is max. twice the compressed
outbufsize <<= 1;
@@ -335,9 +348,9 @@
outbufsize += 0L + info.ydim * 4;
}
- inbuffer = (U8*) malloc(inbufsize);
- outbuffer = (U8*) malloc(outbufsize);
- imgbuffer = (CommonPixel*) calloc(sx * sy, sizeof(CommonPixel));
+ inbuffer = (U8 *)malloc(inbufsize);
+ outbuffer = (U8 *)malloc(outbufsize);
+ imgbuffer = (CommonPixel *)calloc(sx * sy, sizeof(CommonPixel));
if (!inbuffer || !outbuffer || !imgbuffer) {
printf("\nError allocating sprite buffer, want %ld for sprite %d\n", inbufsize + outbufsize + sx * sy, spriteno);
exit(2);
@@ -360,7 +373,7 @@
result = uncompress(size, inbuffer, &inbufsize, outbuffer, outbufsize, spriteno, grfcontversion);
if (result < 0) {
outbufsize = -result;
- outbuffer = (U8*) realloc(outbuffer, outbufsize);
+ outbuffer = (U8 *)realloc(outbuffer, outbufsize);
if (!outbuffer) {
printf("\nError increasing sprite buffer size for sprite %d\n", spriteno);
exit(2);
@@ -369,8 +382,8 @@
} while (result < 0);
datasize = result;
- bool has_mask=info.depth==DEPTH_MASK||info.depth==DEPTH_8BPP;
- bool rgba=info.depth==DEPTH_MASK||info.depth==DEPTH_32BPP;
+ bool has_mask = info.depth == DEPTH_MASK || info.depth == DEPTH_8BPP;
+ bool rgba = info.depth == DEPTH_MASK || info.depth == DEPTH_32BPP;
if (HASTRANSPARENCY(info.info)) { // it's a tile
if (grfcontversion == 2 && datasize != tilesize + SpriteInfo::Size(grfcontversion)) {
printf("\nError: not enough data to perform tile decoding for sprite %d\n", spriteno);
@@ -382,42 +395,40 @@
exit(2);
}
} else {
- U8 bytes_per_pixel=(has_mask?1:0)+(rgba?4:0);
- if (grfcontversion == 2 && datasize != (unsigned long)(sx * sy * bytes_per_pixel) + SpriteInfo::Size(grfcontversion)) {
+ U8 bytes_per_pixel = (has_mask ? 1 : 0) + (rgba ? 4 : 0);
+ if (grfcontversion == 2 &&
+ datasize != (unsigned long)(sx * sy * bytes_per_pixel) + SpriteInfo::Size(grfcontversion)) {
printf("\nError: not enough data to perform regular decoding for sprite %d\n", spriteno);
exit(2);
}
result = decoderegular(outbuffer, sx, sy, imgbuffer, has_mask, rgba, grfcontversion);
}
- if (info.depth==DEPTH_32BPP) {
+ if (info.depth == DEPTH_32BPP) {
if (imgrgba == NULL) {
printf("\nError: cannot decode 32bpp sprites to pcx\n");
exit(2);
}
writesprite(false, imgrgba, writer, imgbuffer, info);
- } else if (info.depth==DEPTH_MASK) {
+ } else if (info.depth == DEPTH_MASK) {
if (imgrgba == NULL) {
printf("\nError: cannot decode 32bpp sprites to pcx\n");
exit(2);
}
- info.depth=DEPTH_32BPP;
+ info.depth = DEPTH_32BPP;
writesprite(false, imgrgba, writer, imgbuffer, info);
- info.depth=DEPTH_MASK;
+ info.depth = DEPTH_MASK;
writesprite(false, imgpal, writer, imgbuffer, info);
- } else if (info.depth==DEPTH_8BPP) {
+ } else if (info.depth == DEPTH_8BPP) {
writesprite(i == 0, imgpal, writer, imgbuffer, info);
} else {
printf("\nError unknown sprite depth %d\n", spriteno);
exit(2);
}
- if (sy > maxy)
- maxy = sy;
- if (sx > maxx)
- maxx = sx;
- if (datasize > (unsigned long) maxs)
- maxs = datasize;
+ if (sy > maxy) maxy = sy;
+ if (sx > maxx) maxx = sx;
+ if (datasize > (unsigned long)maxs) maxs = datasize;
free(inbuffer);
free(outbuffer);
@@ -446,8 +457,7 @@
long inpos = 0, outpos = 0;
while (inpos < insize) {
long rest = insize - inpos;
- if (rest > 0x7f)
- rest = 0x7f;
+ if (rest > 0x7f) rest = 0x7f;
out[outpos++] = rest;
memmove(&(out[outpos]), &(in[inpos]), rest);
@@ -465,7 +475,7 @@
#ifdef OLDSTRATEGY
// different compression strategies for identifying repetition
-static multitype strategy1(const U8* data, unsigned int datasize, unsigned int datamax)
+static multitype strategy1(const U8 *data, unsigned int datasize, unsigned int datamax)
{
int overlap;
multitype ret;
@@ -474,29 +484,27 @@
// can only find up to 11 bits back
if (datasize >= (1 << 11)) {
ofs = datasize - (1 << 11) + 1;
- data+=ofs;
- datasize-=ofs;
+ data += ofs;
+ datasize -= ofs;
}
- for (overlap=MAXOVERLAP;overlap >= MINOVERLAP;overlap--) {
- // see if we can find a repetition of length overlap
+ for (overlap = MAXOVERLAP; overlap >= MINOVERLAP; overlap--) {
+// see if we can find a repetition of length overlap
- // allow overlapping memory blocks?
+// allow overlapping memory blocks?
#if 0
foundofs = grepmem(data, datasize+overlap-1, data+datasize, overlap, 0);
#else
- foundofs = grepmem(data, datasize, data+datasize, overlap, 0);
+ foundofs = grepmem(data, datasize, data + datasize, overlap, 0);
#endif
- if (foundofs != GREP_NOMATCH) { // found one
+ if (foundofs != GREP_NOMATCH) { // found one
if (foundofs > datasize) {
- foundofs = GREP_NOMATCH; // not really
+ foundofs = GREP_NOMATCH; // not really
continue;
}
ofs = datasize - foundofs;
- if (ofs + overlap > datasize)
- overlap = datasize - ofs;
- if (datasize + overlap > datamax)
- overlap = datamax - datasize;
+ if (ofs + overlap > datasize) overlap = datasize - ofs;
+ if (datasize + overlap > datamax) overlap = datamax - datasize;
break;
}
}
@@ -514,7 +522,7 @@
// datasize is how much has been processed so far, and can be used for
// the repetition finding
// datamax is the entire size of the sprite data
-static multitype strategy2(const U8* data, unsigned int datasize, unsigned int datamax)
+static multitype strategy2(const U8 *data, unsigned int datasize, unsigned int datamax)
{
unsigned int overlap = 0, newoverlap, remain, minoverlap, maxoverlap;
multitype ret;
@@ -524,50 +532,42 @@
// can only find up to 11 bits back
if (datasize >= (1 << 11)) {
unsigned int ofs = datasize - (1 << 11) + 1;
- data+=ofs;
- datasize-=ofs;
- datamax-=ofs;
+ data += ofs;
+ datasize -= ofs;
+ datamax -= ofs;
}
remain = datasize;
- found = data-1;
+ found = data - 1;
maxoverlap = MAXOVERLAP;
while (overlap < maxoverlap) {
// minoverlap is minimum overlap we need to find minus one
minoverlap = overlap;
- if (minoverlap < MINOVERLAP-1)
- minoverlap = MINOVERLAP-1;
+ if (minoverlap < MINOVERLAP - 1) minoverlap = MINOVERLAP - 1;
- if (remain <= minoverlap)
- break; // don't have more data to find longer overlap
+ if (remain <= minoverlap) break; // don't have more data to find longer overlap
int i;
- for (i=remain-minoverlap; i; i--)
- if ( *(++found) == data[datasize])
- break;
+ for (i = remain - minoverlap; i; i--)
+ if (*(++found) == data[datasize]) break;
- if (!i)
- break;
+ if (!i) break;
- foundofs = (int) (found - data);
+ foundofs = (int)(found - data);
remain = datasize - foundofs - 1;
maxoverlap = datasize - foundofs;
- if (maxoverlap > MAXOVERLAP)
- maxoverlap = MAXOVERLAP; // can't store more anyway
- if (maxoverlap > datamax - datasize)
- maxoverlap = datamax - datasize; // can't use more
+ if (maxoverlap > MAXOVERLAP) maxoverlap = MAXOVERLAP; // can't store more anyway
+ if (maxoverlap > datamax - datasize) maxoverlap = datamax - datasize; // can't use more
newoverlap = 1;
- while ( (newoverlap < maxoverlap) && (found[newoverlap] == data[datasize+newoverlap]) )
- newoverlap++;
+ while ((newoverlap < maxoverlap) && (found[newoverlap] == data[datasize + newoverlap])) newoverlap++;
- if (newoverlap < MINOVERLAP)
- continue;
+ if (newoverlap < MINOVERLAP) continue;
- if (newoverlap > overlap) { // a longer chunk
+ if (newoverlap > overlap) { // a longer chunk
ret.u16[0] = datasize - foundofs;
overlap = newoverlap;
}
@@ -590,13 +590,13 @@
while (inpos < insize) {
// search for where the first repetition of >= 3 chars occurs
int overlap;
- int ofsh,ofsl;
+ int ofsh, ofsl;
// chunk = strategy1(in, inpos, insize);
chunk = strategy2(in, inpos, insize);
- if (chunk.u8[3]) { // Yay! Found one!
- if (!*lastcodepos) // there's a zero length verbatim chunk -> delete it
+ if (chunk.u8[3]) { // Yay! Found one!
+ if (!*lastcodepos) // there's a zero length verbatim chunk -> delete it
outpos--;
ofsl = chunk.u8[BYTE_OFSL];
@@ -606,19 +606,17 @@
out[outpos++] = (-overlap << 3) | ofsh;
out[outpos++] = ofsl;
- out[outpos] = 0; // start new interim verbatim chunk
- if (*lastcodepos == 0x80)
- *lastcodepos = 0;
+ out[outpos] = 0; // start new interim verbatim chunk
+ if (*lastcodepos == 0x80) *lastcodepos = 0;
lastcodepos = &(out[outpos++]);
inpos += overlap;
- } else { // no we didn't. Increase length of verbatim chunk
- /* In container version 2, verbatim data of length 128 can be encoded using 0.
- * While various GRF format specs list this already for container version 1, it is not true.
- * See http://www.tt-forums.net/viewtopic.php?p=1051455#p1051455 for details. */
- if (*lastcodepos == (grfcontversion >= 2 ? 0x80 : 0x7f)) { // check for maximum verbatim length
- if (*lastcodepos == 0x80)
- *lastcodepos = 0;
- lastcodepos = &(out[outpos++]); // start new one
+ } else { // no we didn't. Increase length of verbatim chunk
+ /* In container version 2, verbatim data of length 128 can be encoded using 0.
+ * While various GRF format specs list this already for container version 1, it is not true.
+ * See http://www.tt-forums.net/viewtopic.php?p=1051455#p1051455 for details. */
+ if (*lastcodepos == (grfcontversion >= 2 ? 0x80 : 0x7f)) { // check for maximum verbatim length
+ if (*lastcodepos == 0x80) *lastcodepos = 0;
+ lastcodepos = &(out[outpos++]); // start new one
*lastcodepos = 0;
}
(*lastcodepos)++;
@@ -626,24 +624,20 @@
}
if (outpos + 2 >= outsize) {
// buffer too small, estimate expected size
- long needed = (long) outpos * (long) insize / (long) inpos;
- needed += needed >> 3; // add 12% extra
+ long needed = (long)outpos * (long)insize / (long)inpos;
+ needed += needed >> 3; // add 12% extra
return -needed;
}
}
if (inpos != insize) {
- printf("\nError: compressed %ld bytes too much: %ld not %ld!",
- inpos - insize, inpos, insize);
- printf("\nLast chunk was repetition=%d, len=%d, ofs=%d\n",
- chunk.u8[3], chunk.u8[2], chunk.u16[0]);
+ printf("\nError: compressed %ld bytes too much: %ld not %ld!", inpos - insize, inpos, insize);
+ printf("\nLast chunk was repetition=%d, len=%d, ofs=%d\n", chunk.u8[3], chunk.u8[2], chunk.u16[0]);
exit(2);
}
- if (!*lastcodepos)
- outpos--;
- if (*lastcodepos == 0x80)
- *lastcodepos = 0;
+ if (!*lastcodepos) outpos--;
+ if (*lastcodepos == 0x80) *lastcodepos = 0;
*compsize = outpos;
@@ -651,7 +645,7 @@
}
#ifdef _MSC_VER
-#pragma warning(default:4701)
+#pragma warning(default : 4701)
#endif
static long lasttilesize;
@@ -661,7 +655,8 @@
return lasttilesize;
}
-long encodetile(U8 **compressed_data, long *uncompressed_size, const CommonPixel *image, long imgsize, int sx, int sy, SpriteInfo inf, int docompress, int spriteno, bool has_mask, bool rgba, int grfcontversion)
+long encodetile(U8 **compressed_data, long *uncompressed_size, const CommonPixel *image, long imgsize, int sx, int sy, SpriteInfo inf,
+ int docompress, int spriteno, bool has_mask, bool rgba, int grfcontversion)
{
long tilesize = imgsize + 16L * sy;
bool long_format = false;
@@ -669,54 +664,51 @@
const int chunk_len = long_chunk ? 0x7FFF : 0x7F;
const int trans_len = long_chunk ? 0xFFFF : 0xFF;
- while (1) { // repeat in case we didn't allocate enough memory
- U8 *tile = (U8*) malloc(tilesize);
+ while (1) { // repeat in case we didn't allocate enough memory
+ U8 *tile = (U8 *)malloc(tilesize);
if (!tile) {
- printf("\nError: can't allocate %ld bytes for tile memory of sprite %d\n",
- tilesize, spriteno);
+ printf("\nError: can't allocate %ld bytes for tile memory of sprite %d\n", tilesize, spriteno);
exit(2);
}
long offset_size = long_format ? 4 : 2;
- long tileofs = offset_size * sy; // first sy (int) offsets, then data
+ long tileofs = offset_size * sy; // first sy (int) offsets, then data
int y;
- for (y=0; y<sy; y++) {
+ for (y = 0; y < sy; y++) {
int x1 = 0, x2 = 0;
if (long_format) {
- U32 *lineofs = (U32*)tile;
+ U32 *lineofs = (U32 *)tile;
lineofs[y] = BE_SWAP32(tileofs);
} else {
- U16 *lineofs = (U16*)tile;
+ U16 *lineofs = (U16 *)tile;
lineofs[y] = BE_SWAP16(tileofs);
}
long lastlenofs = tileofs;
- while ( (x1 < sx) && (tileofs + offset_size + sx < tilesize) ) {
+ while ((x1 < sx) && (tileofs + offset_size + sx < tilesize)) {
// find where next non-transparent part starts
- while ( (x1 < sx) && (image[y*sx+x1].IsTransparent(rgba)) )
- x1++;
+ while ((x1 < sx) && (image[y * sx + x1].IsTransparent(rgba))) x1++;
if (x1 < sx) {
int len = 1;
// ...and where it ends
x2 = x1 + 1;
- while ( (x2 < sx) && (len < chunk_len) && (!image[y*sx+x2].IsTransparent(rgba)) ) {
+ while ((x2 < sx) && (len < chunk_len) && (!image[y * sx + x2].IsTransparent(rgba))) {
len++;
x2++;
}
- if (x2 > trans_len) { // chunk extends past the 255-wall; encode the remainder of the line
+ if (x2 > trans_len) { // chunk extends past the 255-wall; encode the remainder of the line
if (x1 > trans_len) // chunk cannot start after 255; move it back
x1 = trans_len;
x2 = sx;
- while ( (image[y*sx+x2-1].IsTransparent(rgba)) )
- x2--;
+ while ((image[y * sx + x2 - 1].IsTransparent(rgba))) x2--;
len = x2 - x1;
- if (len > chunk_len) { // chunk is too long
- if (x1 < trans_len) { // first encode the part before the wall
+ if (len > chunk_len) { // chunk is too long
+ if (x1 < trans_len) { // first encode the part before the wall
len = trans_len - x1;
x2 = trans_len;
} else { // chunk starts at wall, abort
@@ -738,11 +730,11 @@
}
U8 *buffer = tile + tileofs;
for (int i = 0; i < len; i++) {
- buffer = image[y*sx+x1+i].Encode(buffer, has_mask, rgba);
+ buffer = image[y * sx + x1 + i].Encode(buffer, has_mask, rgba);
}
tileofs += buffer - (tile + tileofs);
- } else { // transparent to end of line
- if (x2 == 0) { // totally empty line
+ } else { // transparent to end of line
+ if (x2 == 0) { // totally empty line
tile[tileofs++] = 0;
tile[tileofs++] = 0;
if (long_chunk) {
@@ -755,15 +747,14 @@
x1 = x2;
}
tile[lastlenofs + (long_chunk ? 1 : 0)] |= 0x80;
- if (tileofs + offset_size + sx >= tilesize)
- break;
+ if (tileofs + offset_size + sx >= tilesize) break;
}
if (tileofs + offset_size + sx >= tilesize) {
// tile didn't hold all data, estimate real size
// and enlarge it
free(tile);
- long imgofs = y*sx + 1L;
+ long imgofs = y * sx + 1L;
tilesize = tilesize * imgsize / imgofs;
tilesize += (tilesize >> 3) + 16L;
continue;
@@ -794,11 +785,11 @@
long compsize = imgsize + 24 + infobytes, uncompsize = compsize + infobytes;
unsigned int size;
- U8 *compr = (U8*) malloc(compsize);
- U8 *uncomp = (U8*) malloc(uncompsize);
+ U8 *compr = (U8 *)malloc(compsize);
+ U8 *uncomp = (U8 *)malloc(uncompsize);
if (!compr || !uncomp) {
- printf("\nError: can't allocate %ld bytes for compressed buffer while encoding sprite %d\n",
- compsize + uncompsize, spriteno);
+ printf("\nError: can't allocate %ld bytes for compressed buffer while encoding sprite %d\n", compsize + uncompsize,
+ spriteno);
exit(2);
}
@@ -807,37 +798,38 @@
while (1) {
inf.writetobuffer(compr, grfcontversion);
if (docompress)
- result = realcompress(image, imgsize, compr+infobytes, compsize-infobytes, &realcompsize, grfcontversion);
+ result = realcompress(image, imgsize, compr + infobytes, compsize - infobytes, &realcompsize, grfcontversion);
else
- result = fakecompress(image, imgsize, compr+infobytes, compsize-infobytes, &realcompsize, grfcontversion);
+ result = fakecompress(image, imgsize, compr + infobytes, compsize - infobytes, &realcompsize, grfcontversion);
- if (grfcontversion == 2 || SIZEISCOMPRESSED(inf.info)) // write compressed size
+ if (grfcontversion == 2 || SIZEISCOMPRESSED(inf.info)) // write compressed size
size = realcompsize + infobytes;
else
size = imgsize + infobytes;
if (result > 0) {
- do { // everything was good
+ do { // everything was good
// check that the compression is correct, by uncompressing again
unsigned long insize = realcompsize + infobytes;
result = uncompress(size, compr, &insize, uncomp, uncompsize, spriteno, grfcontversion);
if (result < 0) {
uncompsize = -result;
- uncomp = (U8*) realloc(uncomp, uncompsize);
+ uncomp = (U8 *)realloc(uncomp, uncompsize);
if (!uncomp) {
printf("\nError increasing sprite buffer size for sprite %d\n", spriteno);
exit(2);
}
}
// and verifying
- if ((result-imgsize-infobytes) || memcmp(uncomp+infobytes, image, imgsize)) {
+ if ((result - imgsize - infobytes) || memcmp(uncomp + infobytes, image, imgsize)) {
printf("\nError: invalid compression of sprite %d, ", spriteno);
- if (result-imgsize-infobytes)
- printf("length diff %ld, ", result-imgsize-infobytes);
+ if (result - imgsize - infobytes)
+ printf("length diff %ld, ", result - imgsize - infobytes);
else {
int i;
- for (i=0; uncomp[i+infobytes]==image[i]; i++) {}
+ for (i = 0; uncomp[i + infobytes] == image[i]; i++) {
+ }
printf("data diff at %d of %ld bytes, ", i, imgsize);
}
if (docompress) {
@@ -850,14 +842,12 @@
result = 0;
}
} while (result < 0);
- if (result)
- break;
- } else if (result < 0) { // buffer was too small
+ if (result) break;
+ } else if (result < 0) { // buffer was too small
compsize = -result;
- compr = (U8*) realloc(compr, compsize);
+ compr = (U8 *)realloc(compr, compsize);
if (!compr) {
- printf("\nError: can't allocate %ld bytes for compressed buffer of sprite %d\n",
- compsize, spriteno);
+ printf("\nError: can't allocate %ld bytes for compressed buffer of sprite %d\n", compsize, spriteno);
exit(2);
}
} else {
@@ -872,12 +862,13 @@
return realcompsize;
}
-void writesprite(FILE *grf, const U8 *compressed_data, int compressed_size, int uncompressed_size, SpriteInfo inf, int spriteno, int grfcontversion)
+void writesprite(FILE *grf, const U8 *compressed_data, int compressed_size, int uncompressed_size, SpriteInfo inf, int spriteno,
+ int grfcontversion)
{
const int infobytes = SpriteInfo::Size(grfcontversion);
static const char *action = "writing real sprite";
int size;
- if (grfcontversion == 2 || SIZEISCOMPRESSED(inf.info)) // write compressed size
+ if (grfcontversion == 2 || SIZEISCOMPRESSED(inf.info)) // write compressed size
size = compressed_size + infobytes;
else
size = uncompressed_size + infobytes;
diff --git a/src/sprites.h b/src/sprites.h
--- a/src/sprites.h
+++ b/src/sprites.h
@@ -31,9 +31,9 @@
#define DEPTHS (3)
extern const char *depths[DEPTHS];
-static const int DEPTH_8BPP = 0;
+static const int DEPTH_8BPP = 0;
static const int DEPTH_32BPP = 1;
-static const int DEPTH_MASK = 2;
+static const int DEPTH_MASK = 2;
#include "pcxfile.h"
#include "typesize.h"
@@ -43,13 +43,13 @@
#define HASTRANSPARENCY(info) (info & 8)
#define SIZEISCOMPRESSED(info) (info & 2)
-
// minimum and maximum overlap to search for in the compression routines
#define MINOVERLAP 3
-#define MAXOVERLAP 15 // must be <= 15 b/o how it's encoded
+#define MAXOVERLAP 15 // must be <= 15 b/o how it's encoded
/** Information about a single sprite. */
-struct SpriteInfo {
+struct SpriteInfo
+{
U8 info; ///< Info byte; bit 1: size is compressed size, bit 3: tile transparancy, value 0xFF: special sprite.
U8 depth; ///< The "depth" of the image.
U8 zoom; ///< The zoom level.
@@ -59,44 +59,64 @@
S16 yrel; ///< Vertical offset
string name;
- int xpos,ypos,imgsize;
+ int xpos, ypos, imgsize;
bool forcereopen;
void writetobuffer(U8 *buffer, int grfcontversion);
void readfromfile(const char *action, int grfcontversion, FILE *grf, int spriteno);
- static int Size(int grfcontversion) { return grfcontversion == 2 ? 10 : 8; }
+ static int Size(int grfcontversion)
+ {
+ return grfcontversion == 2 ? 10 : 8;
+ }
};
-class spriteinfowriter {
- public:
- ~spriteinfowriter() {}
- virtual void addsprite(bool /* first */, const char * /* filename */, int /* y */, int /*x*/, SpriteInfo /*info*/) { };
- virtual void adddata(uint /*size*/, U8 * /*data*/) { };
+class spriteinfowriter
+{
+ public:
+ ~spriteinfowriter()
+ {
+ }
+ virtual void addsprite(bool /* first */, const char * /* filename */, int /* y */, int /*x*/, SpriteInfo /*info*/) {};
+ virtual void adddata(uint /*size*/, U8 * /*data*/) {};
};
-class spritestorage {
- public:
- virtual ~spritestorage(){}
+class spritestorage
+{
+ public:
+ virtual ~spritestorage()
+ {
+ }
virtual void newsprite() {};
virtual void setsize(int /*sx*/, int /*sy*/) {};
- virtual int curspritex() {return 0;};
- virtual int curspritey() {return 0;};
- virtual const char *filename(){return NULL;};
+ virtual int curspritex()
+ {
+ return 0;
+ };
+ virtual int curspritey()
+ {
+ return 0;
+ };
+ virtual const char *filename()
+ {
+ return NULL;
+ };
virtual void newrow() {};
virtual void nextpixel(CommonPixel /*colour*/) {};
virtual void spritedone(int /*sx*/, int /*sy*/) {};
virtual void spritedone() {};
};
-
extern int maxx, maxy, maxs;
-int decodesprite(FILE *grf, spritestorage *imgpal, spritestorage *imgrgba, spriteinfowriter *writer, int spriteno, U32 *dataoffset, int grfcontversion);
+int decodesprite(FILE *grf, spritestorage *imgpal, spritestorage *imgrgba, spriteinfowriter *writer, int spriteno, U32 *dataoffset,
+ int grfcontversion);
long getlasttilesize();
-long encodetile(U8 **compressed_data, long *uncompressed_size, const CommonPixel *image, long imgsize, int sx, int sy, SpriteInfo inf, int docompress, int spriteno, bool has_mask, bool rgba, int grfcontversion);
+long encodetile(U8 **compressed_data, long *uncompressed_size, const CommonPixel *image, long imgsize, int sx, int sy, SpriteInfo inf,
+ int docompress, int spriteno, bool has_mask, bool rgba, int grfcontversion);
long encoderegular(U8 **compressed_data, const U8 *image, long imgsize, SpriteInfo inf, int docompress, int spriteno, int grfcontversion);
-void writesprite(FILE *grf, const U8 *compressed_data, int compressed_size, int uncompressed_size, SpriteInfo inf, int spriteno, int grfcontversion);
+void writesprite(FILE *grf, const U8 *compressed_data, int compressed_size, int uncompressed_size, SpriteInfo inf, int spriteno,
+ int grfcontversion);
void writespritesize(const char *action, unsigned int spritesize, int grfcontversion, FILE *grf);
void writeword(const char *action, unsigned int value, FILE *grf);
void writedword(const char *action, unsigned int value, FILE *grf);
diff --git a/src/strings.cpp b/src/strings.cpp
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -19,158 +19,187 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include<cstdio>
-#include<string>
-#include<cerrno>
-#include<cstdlib>
+#include <cstdio>
+#include <string>
+#include <cerrno>
+#include <cstdlib>
using namespace std;
-#include"nforenum.h"
-#include"inlines.h"
-#include"sanity_defines.h"
-#include"pseudo.h"
-#include"strings.h"
-#include"data.h"
-#include"utf8.h"
-#include"messages.h"
-#include"command.h"
+#include "nforenum.h"
+#include "inlines.h"
+#include "sanity_defines.h"
+#include "pseudo.h"
+#include "strings.h"
+#include "data.h"
+#include "utf8.h"
+#include "messages.h"
+#include "command.h"
-class check4:public Guintp{
-public:
+class check4 : public Guintp
+{
+ public:
int GetGenericPerms(int feature);
int GetNamePerms(int feature);
SINGLETON(check4)
};
-check4::check4(){
- FILE*pFile=myfopen(4);
- _p=new uint[MaxFeature()+1];
- uint i=0;
- for(;i<=MaxFeature();i++)
- _p[i]=fgetc(pFile);
- for(i=0;i<=MaxFeature();i++)
- _p[i]|=GetCheckByte(4)<<8;
+check4::check4()
+{
+ FILE* pFile = myfopen(4);
+ _p = new uint[MaxFeature() + 1];
+ uint i = 0;
+ for (; i <= MaxFeature(); i++) _p[i] = fgetc(pFile);
+ for (i = 0; i <= MaxFeature(); i++) _p[i] |= GetCheckByte(4) << 8;
fclose(pFile);
}
-int check4::GetGenericPerms(int feature){return _p[feature]>>8;}
-int check4::GetNamePerms(int feature){return _p[feature]&0xFF;}
+int check4::GetGenericPerms(int feature)
+{
+ return _p[feature] >> 8;
+}
+int check4::GetNamePerms(int feature)
+{
+ return _p[feature] & 0xFF;
+}
-void Check4(PseudoSprite&data){
- const uint feature=data.ExtractByte(1),lang=data.ExtractByte(2);
+void Check4(PseudoSprite& data)
+{
+ const uint feature = data.ExtractByte(1), lang = data.ExtractByte(2);
data.SetAllHex();
- uint i=5;
- int nument=(signed)data.ExtractByte(3);
- if(!IsValidFeature(ACT4,feature)&&feature!=0x48){IssueMessage(FATAL,INVALID_FEATURE);return;}
- if(_grfver<7&&lang&0x60&&(lang&0x7F)!=0x7F)IssueMessage(WARNING3,UNKNOWN_LANG_BIT,2,lang);
- if(_grfver>6)CheckLangID(lang&0x7F,2);
- if(lang&0x80){
- i=6;
- if(nument!=0) {
+ uint i = 5;
+ int nument = (signed)data.ExtractByte(3);
+ if (!IsValidFeature(ACT4, feature) && feature != 0x48) {
+ IssueMessage(FATAL, INVALID_FEATURE);
+ return;
+ }
+ if (_grfver < 7 && lang & 0x60 && (lang & 0x7F) != 0x7F) IssueMessage(WARNING3, UNKNOWN_LANG_BIT, 2, lang);
+ if (_grfver > 6) CheckLangID(lang & 0x7F, 2);
+ if (lang & 0x80) {
+ i = 6;
+ if (nument != 0) {
uint base_id = data.ExtractWord(4);
uint last_id = base_id + nument - 1;
for (uint i = base_id; i <= last_id; i++) CheckTextID(0x48, i, 4);
} else
- IssueMessage(WARNING1,NO_TEXTS);
- }else if(feature==0x48)IssueMessage(ERROR,INVALID_FEATURE);
- else if(feature>3)IssueMessage(ERROR,NO_BYTE_IDS,feature);
- else if(nument!=0){
- CheckID(feature,data.ExtractExtended(4))&&CheckID(feature,data.ExtractExtended(4)+nument-1);
- i+=data.ExtendedLen(4)-1;
- }else
- IssueMessage(WARNING1,NO_TEXTS);
- int perms=feature==0x48?CTRL_ALL|CTRL_NO_STACK_CHECK
- :(check4::Instance().*(lang&0x80?&check4::GetGenericPerms:&check4::GetNamePerms))(feature);
- if(feature==0x0B){
- for(;nument--||_autocorrect;){
- int result=CheckString(data,i,perms,!nument,MakeStack(1,STACK_WORD));
- if(result){
- if(result!=-1)nument--;
+ IssueMessage(WARNING1, NO_TEXTS);
+ } else if (feature == 0x48)
+ IssueMessage(ERROR, INVALID_FEATURE);
+ else if (feature > 3)
+ IssueMessage(ERROR, NO_BYTE_IDS, feature);
+ else if (nument != 0) {
+ CheckID(feature, data.ExtractExtended(4)) && CheckID(feature, data.ExtractExtended(4) + nument - 1);
+ i += data.ExtendedLen(4) - 1;
+ } else
+ IssueMessage(WARNING1, NO_TEXTS);
+ int perms = feature == 0x48 ? CTRL_ALL | CTRL_NO_STACK_CHECK
+ : (check4::Instance().*(lang & 0x80 ? &check4::GetGenericPerms : &check4::GetNamePerms))(feature);
+ if (feature == 0x0B) {
+ for (; nument-- || _autocorrect;) {
+ int result = CheckString(data, i, perms, !nument, MakeStack(1, STACK_WORD));
+ if (result) {
+ if (result != -1) nument--;
break;
}
- try{
- if(data[i])data.SetEol(i-1,1);
- }catch(uint){}
+ try
+ {
+ if (data[i]) data.SetEol(i - 1, 1);
+ }
+ catch (uint)
+ {
+ }
}
- }else
- for(;nument--||_autocorrect;){
- int result=CheckString(data,i,perms,!nument);
- if(result){
- if(result!=-1)nument--;
+ } else
+ for (; nument-- || _autocorrect;) {
+ int result = CheckString(data, i, perms, !nument);
+ if (result) {
+ if (result != -1) nument--;
break;
}
- try{
- if(data[i])data.SetEol(i-1,1);
- else data.SetNoEol(i-1);
- }catch(uint){}
+ try
+ {
+ if (data[i])
+ data.SetEol(i - 1, 1);
+ else
+ data.SetNoEol(i - 1);
+ }
+ catch (uint)
+ {
+ }
}
- if(++nument){
- if(_autocorrect){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,3,NUMENT,data.ExtractByte(3),data.ExtractByte(3)-nument);
- data.SetByteAt(3,data.ExtractByte(3)-nument);
- }else
- IssueMessage(ERROR,INSUFFICIENT_STRINGS,nument);
+ if (++nument) {
+ if (_autocorrect) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 3, NUMENT, data.ExtractByte(3), data.ExtractByte(3) - nument);
+ data.SetByteAt(3, data.ExtractByte(3) - nument);
+ } else
+ IssueMessage(ERROR, INSUFFICIENT_STRINGS, nument);
}
- if(i<data.Length())IssueMessage(WARNING2,EXTRA_DATA,data.Length(),i);
+ if (i < data.Length()) IssueMessage(WARNING2, EXTRA_DATA, data.Length(), i);
}
-void Check13(PseudoSprite&data){
- if(data.Length()<9){
- IssueMessage(FATAL,INVALID_LENGTH,ACTION,0x13,AT_LEAST,9);
+void Check13(PseudoSprite& data)
+{
+ if (data.Length() < 9) {
+ IssueMessage(FATAL, INVALID_LENGTH, ACTION, 0x13, AT_LEAST, 9);
return;
}
- const uint GRFid=data.ExtractDword(1);
+ const uint GRFid = data.ExtractDword(1);
data.SetGRFID(1);
- if((GRFid&0xFF)==0xFF)IssueMessage(WARNING1,RESERVED_GRFID);
+ if ((GRFid & 0xFF) == 0xFF) IssueMessage(WARNING1, RESERVED_GRFID);
- uint offs=8;
+ uint offs = 8;
data.SetAllHex();
- int nument=(signed)data.ExtractByte(5);
- if(nument!=0){
- const uint id=data.ExtractWord(6);
- if(id>>10==0xD0>>2||id>>8==0xDC||id>>9==0xC4>>1||id>>9==0xC9)
- CheckTextID(0x48,id,6)&&CheckTextID(0x48,id+nument-1,5);
+ int nument = (signed)data.ExtractByte(5);
+ if (nument != 0) {
+ const uint id = data.ExtractWord(6);
+ if (id >> 10 == 0xD0 >> 2 || id >> 8 == 0xDC || id >> 9 == 0xC4 >> 1 || id >> 9 == 0xC9)
+ CheckTextID(0x48, id, 6) && CheckTextID(0x48, id + nument - 1, 5);
else
- IssueMessage(ERROR,OUT_OF_RANGE_TEXTID_13);
- }else
- IssueMessage(WARNING1,NO_TEXTS);
- for(;nument--||_autocorrect;){
- int result=CheckString(data,offs,CTRL_ALL|CTRL_NO_STACK_CHECK,!nument);
- if(result){
- if(result!=-1)nument--;
+ IssueMessage(ERROR, OUT_OF_RANGE_TEXTID_13);
+ } else
+ IssueMessage(WARNING1, NO_TEXTS);
+ for (; nument-- || _autocorrect;) {
+ int result = CheckString(data, offs, CTRL_ALL | CTRL_NO_STACK_CHECK, !nument);
+ if (result) {
+ if (result != -1) nument--;
break;
}
- try{
- if(data[offs])data.SetEol(offs-1,1);
- else data.SetNoEol(offs-1);
- }catch(uint){}
+ try
+ {
+ if (data[offs])
+ data.SetEol(offs - 1, 1);
+ else
+ data.SetNoEol(offs - 1);
+ }
+ catch (uint)
+ {
+ }
}
- if(++nument){
- if(_autocorrect){
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECTING,5,NUMENT,data.ExtractByte(5),data.ExtractByte(5)-nument);
- data.SetByteAt(5,data.ExtractByte(5)-nument);
- }else
- IssueMessage(ERROR,INSUFFICIENT_STRINGS,nument);
+ if (++nument) {
+ if (_autocorrect) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECTING, 5, NUMENT, data.ExtractByte(5), data.ExtractByte(5) - nument);
+ data.SetByteAt(5, data.ExtractByte(5) - nument);
+ } else
+ IssueMessage(ERROR, INSUFFICIENT_STRINGS, nument);
}
- if(offs<data.Length())IssueMessage(WARNING2,EXTRA_DATA,data.Length(),offs);
+ if (offs < data.Length()) IssueMessage(WARNING2, EXTRA_DATA, data.Length(), offs);
}
-#define STACK_CHECK(type,width)\
- if(stackoffs+width>stack.length()){\
- IssueMessage(WARNING1,OVERRAN_STACK,offs,ch);\
- perms|=CTRL_NO_STACK_CHECK;\
- }else if((stack[stackoffs]&0x0F)!=type){\
- IssueMessage(WARNING1,SMASH_STACK,offs,ch,stack[stackoffs]);\
- perms|=CTRL_NO_STACK_CHECK;\
- }else if((stack[stackoffs]&0xF0)!=(stack[stackoffs+width-1]&0xF0)){\
- IssueMessage(WARNING1,SMASH_STACK_SPAN,offs,ch);\
- perms|=CTRL_NO_STACK_CHECK;\
- }\
- stackoffs+=width;\
+#define STACK_CHECK(type, width) \
+ if (stackoffs + width > stack.length()) { \
+ IssueMessage(WARNING1, OVERRAN_STACK, offs, ch); \
+ perms |= CTRL_NO_STACK_CHECK; \
+ } else if ((stack[stackoffs] & 0x0F) != type) { \
+ IssueMessage(WARNING1, SMASH_STACK, offs, ch, stack[stackoffs]); \
+ perms |= CTRL_NO_STACK_CHECK; \
+ } else if ((stack[stackoffs] & 0xF0) != (stack[stackoffs + width - 1] & 0xF0)) { \
+ IssueMessage(WARNING1, SMASH_STACK_SPAN, offs, ch); \
+ perms |= CTRL_NO_STACK_CHECK; \
+ } \
+ stackoffs += width; \
break;
/* Checks the string starting at at offs using perms (bitmask of CTRL_* in
@@ -180,230 +209,273 @@
* (RETURN_NULL), or the number of stack-accessing control characters
* encountered or -1 if the stack was smashed (RETURN_STACK)
*/
-int CheckString(PseudoSprite&data,uint&offs,int perms,bool include_00_safe,string stack,const int retInfo){
- const uint length=data.Length();
- if(offs>=length)return -1;
- uint stackoffs=0,ret=0,ch;
- uint choice_list=0;
- bool utf8=false,valid=true;
- try{
- utf8=data.ExtractWord(offs)==0x9EC3;
- if(utf8){
- data.SetUTF8(offs,2);
- offs+=2;
+int CheckString(PseudoSprite& data, uint& offs, int perms, bool include_00_safe, string stack, const int retInfo)
+{
+ const uint length = data.Length();
+ if (offs >= length) return -1;
+ uint stackoffs = 0, ret = 0, ch;
+ uint choice_list = 0;
+ bool utf8 = false, valid = true;
+ try
+ {
+ utf8 = data.ExtractWord(offs) == 0x9EC3;
+ if (utf8) {
+ data.SetUTF8(offs, 2);
+ offs += 2;
}
- }catch(uint){}
- while(0 != (ch = (utf8?data.ExtractUtf8(offs, valid):data.ExtractByte(offs++)))) {
- if(ch>(uint)-10){
- IssueMessage(ERROR,OUTOFRANGE_UTF8,offs+(int)ch);
+ }
+ catch (uint)
+ {
+ }
+ while (0 != (ch = (utf8 ? data.ExtractUtf8(offs, valid) : data.ExtractByte(offs++)))) {
+ if (ch > (uint) - 10) {
+ IssueMessage(ERROR, OUTOFRANGE_UTF8, offs + (int)ch);
continue;
}
- offs--;//back up to last-parsed; move back to next-to-parse at end of loop (line ~212)
- if(utf8){
- if(ch<128){
+ offs--; // back up to last-parsed; move back to next-to-parse at end of loop (line ~212)
+ if (utf8) {
+ if (ch < 128) {
data.SetText(offs);
- if(ch>0x7A)ch=0x20;//bypass the control-char checks for 7B..7F
- }else if(ch<256){
- if(!valid){//invalid UTF-8, parse as bytes
- if((/*ch>0x7A&&*/ch<0xA1)||ch==0xAA||ch==0xAC||ch==0xAD||ch==0xAF||(ch>0xB3&&ch<0xB9))
- data.SetQEscape(offs);//nonprintable -- control or special.
- else data.SetText(offs);
- }else ch=0x20;//valid UTF-8 encoding of U+0080..U+00FF; bypass control-char checks
- }else if(ch>0xE07A&&ch<0xE100)
- ch&=0xFF;//UTF-8 encoding of U+E07B..U+E0FF; run control-char checks
- }else{//!utf8
- if(ch<0x20||(ch>0x7A&&ch<0xA1)||ch==0xAA||ch==0xAC||ch==0xAD||ch==0xAF||(ch>0xB3&&ch<0xB9))
- data.SetQEscape(offs);//nonprintable -- control or special.
- else data.SetText(offs);
+ if (ch > 0x7A) ch = 0x20; // bypass the control-char checks for 7B..7F
+ } else if (ch < 256) {
+ if (!valid) { // invalid UTF-8, parse as bytes
+ if ((/*ch>0x7A&&*/ ch < 0xA1) || ch == 0xAA || ch == 0xAC || ch == 0xAD || ch == 0xAF ||
+ (ch > 0xB3 && ch < 0xB9))
+ data.SetQEscape(offs); // nonprintable -- control or special.
+ else
+ data.SetText(offs);
+ } else
+ ch = 0x20; // valid UTF-8 encoding of U+0080..U+00FF; bypass control-char checks
+ } else if (ch > 0xE07A && ch < 0xE100)
+ ch &= 0xFF; // UTF-8 encoding of U+E07B..U+E0FF; run control-char checks
+ } else { //!utf8
+ if (ch < 0x20 || (ch > 0x7A && ch < 0xA1) || ch == 0xAA || ch == 0xAC || ch == 0xAD || ch == 0xAF ||
+ (ch > 0xB3 && ch < 0xB9))
+ data.SetQEscape(offs); // nonprintable -- control or special.
+ else
+ data.SetText(offs);
}
- if(ch<0x20){
+ if (ch < 0x20) {
data.SetQEscape(offs);
- if(ch==1){
- if(~perms&CTRL_SPACE)IssueMessage(WARNING1,INVALID_CONTROL,offs,ch);
- if(!data.ExtractByte(++offs)&&!include_00_safe)
- IssueMessage(WARNING1,EMBEDDED_00,offs);
+ if (ch == 1) {
+ if (~perms & CTRL_SPACE) IssueMessage(WARNING1, INVALID_CONTROL, offs, ch);
+ if (!data.ExtractByte(++offs) && !include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
data.SetQEscape(offs);
- }else if(ch==0x0D){
- if(~perms&CTRL_NEWLINE)IssueMessage(WARNING1,INVALID_CONTROL,offs,ch);
- try{
- if(data[offs+1]!=0x0D)data.SetEol(offs,2);
- else data.SetNoEol(offs);
- }catch(uint){}
- }
- else if(ch==0x0E){
- if(~perms&CTRL_FONT_SMALL)IssueMessage(WARNING1,INVALID_CONTROL,offs,ch);
- }else if(ch==0x0F){
- if(~perms&CTRL_FONT_LARGE)IssueMessage(WARNING1,INVALID_CONTROL,offs,ch);
- }else if(ch==0x1F){
- if(~perms&CTRL_SPACE)IssueMessage(WARNING1,INVALID_CONTROL,offs,ch);
- if(!data.ExtractByte(++offs)&&!include_00_safe)
- IssueMessage(WARNING1,EMBEDDED_00,offs);
- data.SetQEscape(offs,2);
- if(!data.ExtractByte(++offs)&&!include_00_safe)
- IssueMessage(WARNING1,EMBEDDED_00,offs);
- }else IssueMessage(WARNING3,UNUSED_CONTROL,offs,ch);
- }else if(ch<0x7B);
- else if(ch==0x81){
- int id=data.ExtractEscapeWord(++offs);
- CheckTextID(0x49,id,offs);
- if((!(id&0xFF)||!(id&0xFF00))&&!include_00_safe)
- IssueMessage(WARNING1,INCLUDING_00_ID,offs,id);
+ } else if (ch == 0x0D) {
+ if (~perms & CTRL_NEWLINE) IssueMessage(WARNING1, INVALID_CONTROL, offs, ch);
+ try
+ {
+ if (data[offs + 1] != 0x0D)
+ data.SetEol(offs, 2);
+ else
+ data.SetNoEol(offs);
+ }
+ catch (uint)
+ {
+ }
+ } else if (ch == 0x0E) {
+ if (~perms & CTRL_FONT_SMALL) IssueMessage(WARNING1, INVALID_CONTROL, offs, ch);
+ } else if (ch == 0x0F) {
+ if (~perms & CTRL_FONT_LARGE) IssueMessage(WARNING1, INVALID_CONTROL, offs, ch);
+ } else if (ch == 0x1F) {
+ if (~perms & CTRL_SPACE) IssueMessage(WARNING1, INVALID_CONTROL, offs, ch);
+ if (!data.ExtractByte(++offs) && !include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
+ data.SetQEscape(offs, 2);
+ if (!data.ExtractByte(++offs) && !include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
+ } else
+ IssueMessage(WARNING3, UNUSED_CONTROL, offs, ch);
+ } else if (ch < 0x7B)
+ ;
+ else if (ch == 0x81) {
+ int id = data.ExtractEscapeWord(++offs);
+ CheckTextID(0x49, id, offs);
+ if ((!(id & 0xFF) || !(id & 0xFF00)) && !include_00_safe) IssueMessage(WARNING1, INCLUDING_00_ID, offs, id);
++offs;
- }else if(ch==0x86){
- if(~perms&CTRL_NO_STACK_CHECK){
- if(stack.length()<8){
- IssueMessage(WARNING1,CANNOT_SHUFFLE,offs);
- perms|=CTRL_NO_STACK_CHECK;
- }else{
- swap(stack[6],stack[0]);
- swap(stack[7],stack[1]);
- swap(stack[4],stack[6]);
- swap(stack[5],stack[7]);
- swap(stack[2],stack[4]);
- swap(stack[3],stack[5]);
+ } else if (ch == 0x86) {
+ if (~perms & CTRL_NO_STACK_CHECK) {
+ if (stack.length() < 8) {
+ IssueMessage(WARNING1, CANNOT_SHUFFLE, offs);
+ perms |= CTRL_NO_STACK_CHECK;
+ } else {
+ swap(stack[6], stack[0]);
+ swap(stack[7], stack[1]);
+ swap(stack[4], stack[6]);
+ swap(stack[5], stack[7]);
+ swap(stack[2], stack[4]);
+ swap(stack[3], stack[5]);
}
}
- }else if(ch<0x88||ch==0x9A){
- if(ch==0x9A){
+ } else if (ch < 0x88 || ch == 0x9A) {
+ if (ch == 0x9A) {
uint arg;
- ch=data.ExtractQEscapeByte(++offs);
- switch(ch){
- case 0x00: // print qword currency
- if(!include_00_safe)IssueMessage(WARNING1,EMBEDDED_00,offs);
- case 0x01: // print qword currency
- case 0x02: // ignore color code
- break;
- case 0x03: // push WORD
- stack = string(2,char(STACK_WORD)) + stack;
- arg=data.ExtractEscapeWord(++offs);
- if(!(arg&0xFF)&&!include_00_safe)IssueMessage(WARNING1,EMBEDDED_00,offs);
- ++offs;
- if(!(arg>>8)&&!include_00_safe)IssueMessage(WARNING1,EMBEDDED_00,offs);
- break;
- case 0x04: // Delete BYTE characters
- arg=data.ExtractQEscapeByte(++offs);
- if(!arg&&!include_00_safe)IssueMessage(WARNING1,EMBEDDED_00,offs);
- case 0x06: // print hex byte
- case 0x07: // ... word
- case 0x08: // ... dword
- case 0x0B: // ... qword
- case 0x0C: // print name of station
- case 0x0D: // print word in weight
- case 0x16: // print dword as long date
- case 0x17: // print dword as short date
- case 0x18: // print word as horse power
- case 0x19: // print word as short volume
- case 0x1A: // print word as short weight
- case 0x1B: // print two words as long cargo amount
- case 0x1C: // print two words as short cargo amount
- case 0x1D: // print two words as tiny cargo amount
- break;
+ ch = data.ExtractQEscapeByte(++offs);
+ switch (ch) {
+ case 0x00: // print qword currency
+ if (!include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
+ case 0x01: // print qword currency
+ case 0x02: // ignore color code
+ break;
+ case 0x03: // push WORD
+ stack = string(2, char(STACK_WORD)) + stack;
+ arg = data.ExtractEscapeWord(++offs);
+ if (!(arg & 0xFF) && !include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
+ ++offs;
+ if (!(arg >> 8) && !include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
+ break;
+ case 0x04: // Delete BYTE characters
+ arg = data.ExtractQEscapeByte(++offs);
+ if (!arg && !include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
+ case 0x06: // print hex byte
+ case 0x07: // ... word
+ case 0x08: // ... dword
+ case 0x0B: // ... qword
+ case 0x0C: // print name of station
+ case 0x0D: // print word in weight
+ case 0x16: // print dword as long date
+ case 0x17: // print dword as short date
+ case 0x18: // print word as horse power
+ case 0x19: // print word as short volume
+ case 0x1A: // print word as short weight
+ case 0x1B: // print two words as long cargo amount
+ case 0x1C: // print two words as short cargo amount
+ case 0x1D: // print two words as tiny cargo amount
+ break;
- case 0x10: // choice list value
- if (choice_list == 0) IssueMessage(ERROR,NOT_IN_CHOICE_LIST,offs);
+ case 0x10: // choice list value
+ if (choice_list == 0) IssueMessage(ERROR, NOT_IN_CHOICE_LIST, offs);
/* FALL THROUGH */
- case 0x0E: // set gender
- case 0x0F: // set case
- if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
- arg = data.ExtractQEscapeByte(++offs);
- if (!arg) IssueMessage(ERROR,EMBEDDED_00, offs);
- break;
+ case 0x0E: // set gender
+ case 0x0F: // set case
+ if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
+ arg = data.ExtractQEscapeByte(++offs);
+ if (!arg) IssueMessage(ERROR, EMBEDDED_00, offs);
+ break;
- case 0x11: // choice list default
- if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
- if (choice_list == 0) IssueMessage(ERROR, NOT_IN_CHOICE_LIST, offs);
- choice_list = 2;
- break;
+ case 0x11: // choice list default
+ if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
+ if (choice_list == 0) IssueMessage(ERROR, NOT_IN_CHOICE_LIST, offs);
+ choice_list = 2;
+ break;
- case 0x12: // end choice list
- if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
- if (choice_list == 0) IssueMessage(ERROR, NOT_IN_CHOICE_LIST, offs);
- if (choice_list == 1) IssueMessage(ERROR, NO_DEFAULT_IN_CHOICE_LIST, offs);
- choice_list = 0;
- break;
+ case 0x12: // end choice list
+ if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
+ if (choice_list == 0) IssueMessage(ERROR, NOT_IN_CHOICE_LIST, offs);
+ if (choice_list == 1) IssueMessage(ERROR, NO_DEFAULT_IN_CHOICE_LIST, offs);
+ choice_list = 0;
+ break;
- case 0x13: // begin gender choice list
- case 0x15: // begin plural choice list
- arg = data.ExtractQEscapeByte(++offs);
- if (!arg) IssueMessage(ERROR, EMBEDDED_00, offs);
+ case 0x13: // begin gender choice list
+ case 0x15: // begin plural choice list
+ arg = data.ExtractQEscapeByte(++offs);
+ if (!arg) IssueMessage(ERROR, EMBEDDED_00, offs);
/* FALL THROUGH */
- case 0x14: // begin case choice list
- if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
- if (choice_list != 0) IssueMessage(ERROR, NESTED_CHOICE_LIST, offs);
- choice_list = 1;
- break;
+ case 0x14: // begin case choice list
+ if (_grfver < 7) IssueMessage(WARNING1, NEED_VERSION_7, _grfver);
+ if (choice_list != 0) IssueMessage(ERROR, NESTED_CHOICE_LIST, offs);
+ choice_list = 1;
+ break;
- default:
- IssueMessage(ERROR,INVALID_EXT_CODE,offs,ch);
- perms|=CTRL_NO_STACK_CHECK;
+ default:
+ IssueMessage(ERROR, INVALID_EXT_CODE, offs, ch);
+ perms |= CTRL_NO_STACK_CHECK;
}
}
- if(~perms&CTRL_NO_STACK_CHECK){
- //for Extended format codes (9A XX), "ch" is the XX
- switch(ch){
- case 0x7D:case 0x06:
- STACK_CHECK(STACK_BYTE,1)
- case 0x82:case 0x83:
- STACK_CHECK(STACK_DATE,2)
- case 0x7C:case 0x7E:case 0x84:case 0x85:case 0x87:case 0x07:case 0x0C:case 0x0D:case 0x18:case 0x19: case 0x1A:
- STACK_CHECK(STACK_WORD,2)
- case 0x80:
- STACK_CHECK(STACK_TEXT,2)
- case 0x7B:case 0x7F:case 0x08:case 0x16:case 0x17:case 0x1B:case 0x1C:case 0x1D:
- STACK_CHECK(STACK_DWORD,4)
- case 0x00:case 0x01:case 0x0B:
- STACK_CHECK(STACK_QWORD,8)
- case 0x02:case 0x03:case 0x04:case 0x0E:case 0x0F:case 0x10:case 0x11:case 0x12:
- case 0x13:case 0x14:case 0x15:
- --ret; // These do not read from the stack.
- break;
- DEFAULT(ch)
+ if (~perms & CTRL_NO_STACK_CHECK) {
+ // for Extended format codes (9A XX), "ch" is the XX
+ switch (ch) {
+ case 0x7D:
+ case 0x06:
+ STACK_CHECK(STACK_BYTE, 1)
+ case 0x82:
+ case 0x83:
+ STACK_CHECK(STACK_DATE, 2)
+ case 0x7C:
+ case 0x7E:
+ case 0x84:
+ case 0x85:
+ case 0x87:
+ case 0x07:
+ case 0x0C:
+ case 0x0D:
+ case 0x18:
+ case 0x19:
+ case 0x1A:
+ STACK_CHECK(STACK_WORD, 2)
+ case 0x80:
+ STACK_CHECK(STACK_TEXT, 2)
+ case 0x7B:
+ case 0x7F:
+ case 0x08:
+ case 0x16:
+ case 0x17:
+ case 0x1B:
+ case 0x1C:
+ case 0x1D:
+ STACK_CHECK(STACK_DWORD, 4)
+ case 0x00:
+ case 0x01:
+ case 0x0B:
+ STACK_CHECK(STACK_QWORD, 8)
+ case 0x02:
+ case 0x03:
+ case 0x04:
+ case 0x0E:
+ case 0x0F:
+ case 0x10:
+ case 0x11:
+ case 0x12:
+ case 0x13:
+ case 0x14:
+ case 0x15:
+ --ret; // These do not read from the stack.
+ break;
+ DEFAULT(ch)
}
++ret;
}
- }else if(ch<0x9A){
+ } else if (ch < 0x9A) {
data.SetQEscape(offs);
- if(~perms&CTRL_COLOR)IssueMessage(WARNING1,INVALID_CONTROL,offs,ch);
- if(ch==0x99){
- if(!data.ExtractByte(++offs)&&!include_00_safe)
- IssueMessage(WARNING1,EMBEDDED_00,offs);
+ if (~perms & CTRL_COLOR) IssueMessage(WARNING1, INVALID_CONTROL, offs, ch);
+ if (ch == 0x99) {
+ if (!data.ExtractByte(++offs) && !include_00_safe) IssueMessage(WARNING1, EMBEDDED_00, offs);
data.SetQEscape(offs);
}
- }else if(ch<0x9E){
+ } else if (ch < 0x9E) {
data.SetQEscape(offs);
- IssueMessage(WARNING3,UNUSED_CONTROL,offs,ch);
+ IssueMessage(WARNING3, UNUSED_CONTROL, offs, ch);
}
- if(++offs>=length)break;
+ if (++offs >= length) break;
}
if (choice_list != 0) IssueMessage(ERROR, CHOICE_LIST_NOT_TERMINATED, offs);
- if(ch) {
- if(_autocorrect) {
- IssueMessage(0,CONSOLE_AUTOCORRECT,_spritenum);
- IssueMessage(0,AUTOCORRECT_ADD,0);
+ if (ch) {
+ if (_autocorrect) {
+ IssueMessage(0, CONSOLE_AUTOCORRECT, _spritenum);
+ IssueMessage(0, AUTOCORRECT_ADD, 0);
data.Append(0);
- ch=0;
+ ch = 0;
offs++;
} else {
- IssueMessage(WARNING1,NO_NULL_FOUND);
+ IssueMessage(WARNING1, NO_NULL_FOUND);
}
}
- if(retInfo==RETURN_NULL)return ch;
- if(retInfo==RETURN_STACK)return(perms&CTRL_NO_STACK_CHECK)?(unsigned)-1:ret;
- INTERNAL_ERROR(retInfo,retInfo);
+ if (retInfo == RETURN_NULL) return ch;
+ if (retInfo == RETURN_STACK) return (perms & CTRL_NO_STACK_CHECK) ? (unsigned)-1 : ret;
+ INTERNAL_ERROR(retInfo, retInfo);
}
-static const uchar stackSize[]={0,1,2,2,4,2,8};
+static const uchar stackSize[] = {0, 1, 2, 2, 4, 2, 8};
-string MakeStack(int items,...){
+string MakeStack(int items, ...)
+{
string ret;
WrapAp(items);
uint item;
- for(int i=0;i<items;i++){
- item=va_arg(ap.operator va_list&(),uint);
+ for (int i = 0; i < items; i++) {
+ item = va_arg(ap.operator va_list&(), uint);
// ^^^^^^^^^^^^^^^^^^^
// gcc complains without that call.
- VERIFY(item&&item<STACK_INVALID,item);
- ret+=string(stackSize[item],char(item|i<<4));
+ VERIFY(item && item < STACK_INVALID, item);
+ ret += string(stackSize[item], char(item | i << 4));
}
return ret;
}
@@ -412,40 +484,44 @@
* Lang ID code
*******************************************************/
-struct langNames{
+struct langNames
+{
string names[0x80];
C_SINGLETON(langNames)
};
-langNames::langNames(){
- FILE*pFile=myfopen(langs);
+langNames::langNames()
+{
+ FILE* pFile = myfopen(langs);
char buffer[102];
- for(uint i=0;i<0x80;i++){
- if (fgets(buffer,102,pFile) == NULL) {
- IssueMessage(0,DATAFILE_ERROR,LOAD,"langs.dat",EOF_READING_NAME,i);
+ for (uint i = 0; i < 0x80; i++) {
+ if (fgets(buffer, 102, pFile) == NULL) {
+ IssueMessage(0, DATAFILE_ERROR, LOAD, "langs.dat", EOF_READING_NAME, i);
}
- if(buffer[strlen(buffer)-1]!='\n'){
- if(strlen(buffer)==101)
- IssueMessage(0,DATAFILE_ERROR,LOAD,"langs.dat",OVERLENGTH_NAME,i);
+ if (buffer[strlen(buffer) - 1] != '\n') {
+ if (strlen(buffer) == 101)
+ IssueMessage(0, DATAFILE_ERROR, LOAD, "langs.dat", OVERLENGTH_NAME, i);
else
- IssueMessage(0,DATAFILE_ERROR,LOAD,"langs.dat",EOF_READING_NAME,i);
+ IssueMessage(0, DATAFILE_ERROR, LOAD, "langs.dat", EOF_READING_NAME, i);
assert(false);
exit(EDATA);
}
- buffer[strlen(buffer)-1]='\0';
- names[i]=buffer;
+ buffer[strlen(buffer) - 1] = '\0';
+ names[i] = buffer;
}
}
-const char*_unknownLanguage="Unknown Language (%2x)";
+const char* _unknownLanguage = "Unknown Language (%2x)";
-void CheckLangID(uint id,uint offs){
- VERIFY(_grfver>6,_grfver);
- if(GetLangName(id)==_unknownLanguage)IssueMessage(WARNING2,UNKNOWN_LANGUAGE,offs,id);
+void CheckLangID(uint id, uint offs)
+{
+ VERIFY(_grfver > 6, _grfver);
+ if (GetLangName(id) == _unknownLanguage) IssueMessage(WARNING2, UNKNOWN_LANGUAGE, offs, id);
}
-string GetLangName(uint id){
- VERIFY(id<0x80,id);
- if(langNames::Instance().names[id]!="")return langNames::Instance().names[id];
+string GetLangName(uint id)
+{
+ VERIFY(id < 0x80, id);
+ if (langNames::Instance().names[id] != "") return langNames::Instance().names[id];
return _unknownLanguage;
}
diff --git a/src/strings.h b/src/strings.h
--- a/src/strings.h
+++ b/src/strings.h
@@ -24,23 +24,34 @@
#define CTRL_FONT_LARGE 1
#define CTRL_FONT_SMALL 2
-#define CTRL_FONT (CTRL_FONT_LARGE|CTRL_FONT_SMALL)
+#define CTRL_FONT (CTRL_FONT_LARGE | CTRL_FONT_SMALL)
#define CTRL_SPACE 4
#define CTRL_NEWLINE 8
#define CTRL_COLOR 0x10
-#define CTRL_ALL (CTRL_FONT|CTRL_SPACE|CTRL_NEWLINE|CTRL_COLOR)
+#define CTRL_ALL (CTRL_FONT | CTRL_SPACE | CTRL_NEWLINE | CTRL_COLOR)
#define CTRL_NO_STACK_CHECK 0x20
-enum{STACK_BYTE=1,STACK_WORD,STACK_TEXT,STACK_DWORD,STACK_DATE,STACK_QWORD,STACK_INVALID};
+enum {
+ STACK_BYTE = 1,
+ STACK_WORD,
+ STACK_TEXT,
+ STACK_DWORD,
+ STACK_DATE,
+ STACK_QWORD,
+ STACK_INVALID
+};
-enum{RETURN_NULL,RETURN_STACK};
+enum {
+ RETURN_NULL,
+ RETURN_STACK
+};
class PseudoSprite;
void Check4(PseudoSprite&);
-int CheckString(PseudoSprite&,uint&,int,bool =false,string="",int =0);
-string MakeStack(int,...);
+int CheckString(PseudoSprite&, uint&, int, bool = false, string = "", int = 0);
+string MakeStack(int, ...);
string GetLangName(uint);
-void CheckLangID(uint,uint);
+void CheckLangID(uint, uint);
-#endif//_RENUM_STRINGS_H_INCLUDED_
+#endif //_RENUM_STRINGS_H_INCLUDED_
diff --git a/src/ttdpal.h b/src/ttdpal.h
--- a/src/ttdpal.h
+++ b/src/ttdpal.h
@@ -3,7 +3,7 @@
#define NUM_PALS 8
-extern U8 defaultpalettes[NUM_PALS][256*3];
+extern U8 defaultpalettes[NUM_PALS][256 * 3];
#define PAL_ttd_norm 0
#define PAL_ttw_norm 1
@@ -16,543 +16,534 @@
#ifdef DEFINE_PALS
- U8 defaultpalettes[NUM_PALS][256*3] = {
-// PAL_ttd_norm
- {
- 0, 0,255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
- 64, 64, 64, 80, 80, 80, 100,100,100, 116,116,116, // 4-7
- 132,132,132, 148,148,148, 168,168,168, 184,184,184, // 8-11
- 200,200,200, 216,216,216, 232,232,232, 252,252,252, // 12-15
- 52, 60, 72, 68, 76, 92, 88, 96,112, 108,116,132, // 16-19
- 132,140,152, 156,160,172, 176,184,196, 204,208,220, // 20-23
- 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
- 120,120, 64, 148,148,100, 176,176,132, 204,204,168, // 28-31
- 72, 44, 4, 88, 60, 20, 104, 80, 44, 124,104, 72, // 32-35
- 152,132, 92, 184,160,120, 212,188,148, 244,220,176, // 36-39
- 64, 0, 4, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
- 160, 56, 76, 188, 84,108, 204,104,124, 220,132,144, // 44-47
- 236,156,164, 252,188,192, 252,208, 0, 252,232, 60, // 48-51
- 252,252,128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
- 136,116, 56, 156,136, 80, 176,156,108, 196,180,136, // 56-59
- 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
- 184,120, 24, 212,156, 32, 232,184, 16, 252,212, 0, // 64-67
- 252,248,128, 252,252,192, 32, 4, 0, 64, 20, 8, // 68-71
- 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
- 168, 92, 76, 184,108, 88, 196,128,108, 212,148,128, // 76-79
- 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
- 64,112, 12, 84,132, 20, 104,148, 28, 128,168, 44, // 84-87
- 28, 52, 24, 44, 68, 32, 60, 88, 48, 80,104, 60, // 88-91
- 104,124, 76, 128,148, 92, 152,176,108, 180,204,124, // 92-95
- 16, 52, 24, 32, 72, 44, 56, 96, 72, 76,116, 88, // 96-99
- 96,136,108, 120,164,136, 152,192,168, 184,220,200, // 100-103
- 32, 24, 0, 56, 28, 0, 72, 40, 4, 88, 52, 12, // 104-107
- 104, 64, 24, 124, 84, 44, 140,108, 64, 160,128, 88, // 108-111
- 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
- 164, 96, 64, 184,112, 80, 204,128, 96, 212,148,112, // 116-119
- 224,168,128, 236,188,148, 80, 28, 4, 100, 40, 20, // 120-123
- 120, 56, 40, 140, 76, 64, 160,100, 96, 184,136,136, // 124-127
- 36, 40, 68, 48, 52, 84, 64, 64,100, 80, 80,116, // 128-131
- 100,100,136, 132,132,164, 172,172,192, 212,212,224, // 132-135
- 40, 20,112, 64, 44,144, 88, 64,172, 104, 76,196, // 136-139
- 120, 88,224, 140,104,252, 160,136,252, 188,168,252, // 140-143
- 0, 24,108, 0, 36,132, 0, 52,160, 0, 72,184, // 144-147
- 0, 96,212, 24,120,220, 56,144,232, 88,168,240, // 148-151
- 128,196,252, 188,224,252, 16, 64, 96, 24, 80,108, // 152-155
- 40, 96,120, 52,112,132, 80,140,160, 116,172,192, // 156-159
- 156,204,220, 204,240,252, 172, 52, 52, 212, 52, 52, // 160-163
- 252, 52, 52, 252,100, 88, 252,144,124, 252,184,160, // 164-167
- 252,216,200, 252,244,236, 72, 20,112, 92, 44,140, // 168-171
- 112, 68,168, 140,100,196, 168,136,224, 200,176,248, // 172-175
- 208,184,255, 232,208,252, 60, 0, 0, 92, 0, 0, // 176-179
- 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
- 252, 0, 0, 252, 80, 0, 252,108, 0, 252,136, 0, // 184-187
- 252,164, 0, 252,192, 0, 252,220, 0, 252,252, 0, // 188-191
- 204,136, 8, 228,144, 4, 252,156, 0, 252,176, 48, // 192-195
- 252,196,100, 252,216,152, 8, 24, 88, 12, 36,104, // 196-199
- 20, 52,124, 28, 68,140, 40, 92,164, 56,120,188, // 200-203
- 72,152,216, 100,172,224, 92,156, 52, 108,176, 64, // 204-207
- 124,200, 76, 144,224, 92, 224,244,252, 200,236,248, // 208-211
- 180,220,236, 132,188,216, 88,152,172, 244, 0,244, // 212-215
- 245, 0,245, 246, 0,246, 247, 0,247, 248, 0,248, // 216-219
- 249, 0,249, 250, 0,250, 251, 0,251, 252, 0,252, // 220-223
- 253, 0,253, 254, 0,254, 255, 0,255, 76, 24, 8, // 224-227
- 108, 44, 24, 144, 72, 52, 176,108, 84, 210,146,126, // 228-231
- 252, 60, 0, 252, 84, 0, 252,104, 0, 252,124, 0, // 232-235
- 252,148, 0, 252,172, 0, 252,196, 0, 64, 0, 0, // 236-239
- 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
- 255,255, 0, 32, 68,112, 36, 72,116, 40, 76,120, // 244-247
- 44, 80,124, 48, 84,128, 72,100,144, 100,132,168, // 248-251
- 216,244,252, 96,128,164, 68, 96,140, 255,255,255, // 252-255
+U8 defaultpalettes[NUM_PALS][256 * 3] = {
+ // PAL_ttd_norm
+ {0, 0, 255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
+ 64, 64, 64, 80, 80, 80, 100, 100, 100, 116, 116, 116, // 4-7
+ 132, 132, 132, 148, 148, 148, 168, 168, 168, 184, 184, 184, // 8-11
+ 200, 200, 200, 216, 216, 216, 232, 232, 232, 252, 252, 252, // 12-15
+ 52, 60, 72, 68, 76, 92, 88, 96, 112, 108, 116, 132, // 16-19
+ 132, 140, 152, 156, 160, 172, 176, 184, 196, 204, 208, 220, // 20-23
+ 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
+ 120, 120, 64, 148, 148, 100, 176, 176, 132, 204, 204, 168, // 28-31
+ 72, 44, 4, 88, 60, 20, 104, 80, 44, 124, 104, 72, // 32-35
+ 152, 132, 92, 184, 160, 120, 212, 188, 148, 244, 220, 176, // 36-39
+ 64, 0, 4, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
+ 160, 56, 76, 188, 84, 108, 204, 104, 124, 220, 132, 144, // 44-47
+ 236, 156, 164, 252, 188, 192, 252, 208, 0, 252, 232, 60, // 48-51
+ 252, 252, 128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
+ 136, 116, 56, 156, 136, 80, 176, 156, 108, 196, 180, 136, // 56-59
+ 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
+ 184, 120, 24, 212, 156, 32, 232, 184, 16, 252, 212, 0, // 64-67
+ 252, 248, 128, 252, 252, 192, 32, 4, 0, 64, 20, 8, // 68-71
+ 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
+ 168, 92, 76, 184, 108, 88, 196, 128, 108, 212, 148, 128, // 76-79
+ 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
+ 64, 112, 12, 84, 132, 20, 104, 148, 28, 128, 168, 44, // 84-87
+ 28, 52, 24, 44, 68, 32, 60, 88, 48, 80, 104, 60, // 88-91
+ 104, 124, 76, 128, 148, 92, 152, 176, 108, 180, 204, 124, // 92-95
+ 16, 52, 24, 32, 72, 44, 56, 96, 72, 76, 116, 88, // 96-99
+ 96, 136, 108, 120, 164, 136, 152, 192, 168, 184, 220, 200, // 100-103
+ 32, 24, 0, 56, 28, 0, 72, 40, 4, 88, 52, 12, // 104-107
+ 104, 64, 24, 124, 84, 44, 140, 108, 64, 160, 128, 88, // 108-111
+ 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
+ 164, 96, 64, 184, 112, 80, 204, 128, 96, 212, 148, 112, // 116-119
+ 224, 168, 128, 236, 188, 148, 80, 28, 4, 100, 40, 20, // 120-123
+ 120, 56, 40, 140, 76, 64, 160, 100, 96, 184, 136, 136, // 124-127
+ 36, 40, 68, 48, 52, 84, 64, 64, 100, 80, 80, 116, // 128-131
+ 100, 100, 136, 132, 132, 164, 172, 172, 192, 212, 212, 224, // 132-135
+ 40, 20, 112, 64, 44, 144, 88, 64, 172, 104, 76, 196, // 136-139
+ 120, 88, 224, 140, 104, 252, 160, 136, 252, 188, 168, 252, // 140-143
+ 0, 24, 108, 0, 36, 132, 0, 52, 160, 0, 72, 184, // 144-147
+ 0, 96, 212, 24, 120, 220, 56, 144, 232, 88, 168, 240, // 148-151
+ 128, 196, 252, 188, 224, 252, 16, 64, 96, 24, 80, 108, // 152-155
+ 40, 96, 120, 52, 112, 132, 80, 140, 160, 116, 172, 192, // 156-159
+ 156, 204, 220, 204, 240, 252, 172, 52, 52, 212, 52, 52, // 160-163
+ 252, 52, 52, 252, 100, 88, 252, 144, 124, 252, 184, 160, // 164-167
+ 252, 216, 200, 252, 244, 236, 72, 20, 112, 92, 44, 140, // 168-171
+ 112, 68, 168, 140, 100, 196, 168, 136, 224, 200, 176, 248, // 172-175
+ 208, 184, 255, 232, 208, 252, 60, 0, 0, 92, 0, 0, // 176-179
+ 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
+ 252, 0, 0, 252, 80, 0, 252, 108, 0, 252, 136, 0, // 184-187
+ 252, 164, 0, 252, 192, 0, 252, 220, 0, 252, 252, 0, // 188-191
+ 204, 136, 8, 228, 144, 4, 252, 156, 0, 252, 176, 48, // 192-195
+ 252, 196, 100, 252, 216, 152, 8, 24, 88, 12, 36, 104, // 196-199
+ 20, 52, 124, 28, 68, 140, 40, 92, 164, 56, 120, 188, // 200-203
+ 72, 152, 216, 100, 172, 224, 92, 156, 52, 108, 176, 64, // 204-207
+ 124, 200, 76, 144, 224, 92, 224, 244, 252, 200, 236, 248, // 208-211
+ 180, 220, 236, 132, 188, 216, 88, 152, 172, 244, 0, 244, // 212-215
+ 245, 0, 245, 246, 0, 246, 247, 0, 247, 248, 0, 248, // 216-219
+ 249, 0, 249, 250, 0, 250, 251, 0, 251, 252, 0, 252, // 220-223
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 76, 24, 8, // 224-227
+ 108, 44, 24, 144, 72, 52, 176, 108, 84, 210, 146, 126, // 228-231
+ 252, 60, 0, 252, 84, 0, 252, 104, 0, 252, 124, 0, // 232-235
+ 252, 148, 0, 252, 172, 0, 252, 196, 0, 64, 0, 0, // 236-239
+ 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
+ 255, 255, 0, 32, 68, 112, 36, 72, 116, 40, 76, 120, // 244-247
+ 44, 80, 124, 48, 84, 128, 72, 100, 144, 100, 132, 168, // 248-251
+ 216, 244, 252, 96, 128, 164, 68, 96, 140, 255, 255, 255, // 252-255
},
-// PAL_ttw_norm
- {
- 0, 0,255, 238, 0,238, 239, 0,239, 240, 0,240, // 0-3
- 241, 0,241, 242, 0,242, 243, 0,243, 244, 0,244, // 4-7
- 245, 0,245, 246, 0,246, 168,168,168, 184,184,184, // 8-11
- 200,200,200, 216,216,216, 232,232,232, 252,252,252, // 12-15
- 52, 60, 72, 68, 76, 92, 88, 96,112, 108,116,132, // 16-19
- 132,140,152, 156,160,172, 176,184,196, 204,208,220, // 20-23
- 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
- 120,120, 64, 148,148,100, 176,176,132, 204,204,168, // 28-31
- 100,100,100, 116,116,116, 104, 80, 44, 124,104, 72, // 32-35
- 152,132, 92, 184,160,120, 212,188,148, 244,220,176, // 36-39
- 132,132,132, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
- 160, 56, 76, 188, 84,108, 204,104,124, 220,132,144, // 44-47
- 236,156,164, 252,188,192, 252,208, 0, 252,232, 60, // 48-51
- 252,252,128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
- 136,116, 56, 156,136, 80, 176,156,108, 196,180,136, // 56-59
- 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
- 184,120, 24, 212,156, 32, 232,184, 16, 252,212, 0, // 64-67
- 252,248,128, 252,252,192, 32, 4, 0, 64, 20, 8, // 68-71
- 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
- 168, 92, 76, 184,108, 88, 196,128,108, 212,148,128, // 76-79
- 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
- 64,112, 12, 84,132, 20, 104,148, 28, 128,168, 44, // 84-87
- 64, 64, 64, 44, 68, 32, 60, 88, 48, 80,104, 60, // 88-91
- 104,124, 76, 128,148, 92, 152,176,108, 180,204,124, // 92-95
- 16, 52, 24, 32, 72, 44, 56, 96, 72, 76,116, 88, // 96-99
- 96,136,108, 120,164,136, 152,192,168, 184,220,200, // 100-103
- 32, 24, 0, 56, 28, 0, 80, 80, 80, 88, 52, 12, // 104-107
- 104, 64, 24, 124, 84, 44, 140,108, 64, 160,128, 88, // 108-111
- 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
- 164, 96, 64, 184,112, 80, 204,128, 96, 212,148,112, // 116-119
- 224,168,128, 236,188,148, 80, 28, 4, 100, 40, 20, // 120-123
- 120, 56, 40, 140, 76, 64, 160,100, 96, 184,136,136, // 124-127
- 36, 40, 68, 48, 52, 84, 64, 64,100, 80, 80,116, // 128-131
- 100,100,136, 132,132,164, 172,172,192, 212,212,224, // 132-135
- 48, 48, 48, 64, 44,144, 88, 64,172, 104, 76,196, // 136-139
- 120, 88,224, 140,104,252, 160,136,252, 188,168,252, // 140-143
- 0, 24,108, 0, 36,132, 0, 52,160, 0, 72,184, // 144-147
- 0, 96,212, 24,120,220, 56,144,232, 88,168,240, // 148-151
- 128,196,252, 188,224,252, 16, 64, 96, 24, 80,108, // 152-155
- 40, 96,120, 52,112,132, 80,140,160, 116,172,192, // 156-159
- 156,204,220, 204,240,252, 172, 52, 52, 212, 52, 52, // 160-163
- 252, 52, 52, 252,100, 88, 252,144,124, 252,184,160, // 164-167
- 252,216,200, 252,244,236, 72, 20,112, 92, 44,140, // 168-171
- 112, 68,168, 140,100,196, 168,136,224, 200,176,248, // 172-175
- 208,184,255, 232,208,252, 60, 0, 0, 92, 0, 0, // 176-179
- 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
- 252, 0, 0, 252, 80, 0, 252,108, 0, 252,136, 0, // 184-187
- 252,164, 0, 252,192, 0, 252,220, 0, 252,252, 0, // 188-191
- 204,136, 8, 228,144, 4, 252,156, 0, 252,176, 48, // 192-195
- 252,196,100, 252,216,152, 8, 24, 88, 12, 36,104, // 196-199
- 20, 52,124, 28, 68,140, 40, 92,164, 56,120,188, // 200-203
- 72,152,216, 100,172,224, 92,156, 52, 108,176, 64, // 204-207
- 124,200, 76, 144,224, 92, 224,244,252, 200,236,248, // 208-211
- 180,220,236, 132,188,216, 88,152,172, 16, 16, 16, // 212-215
- 32, 32, 32, 32, 68,112, 36, 72,116, 40, 76,120, // 216-219
- 44, 80,124, 48, 84,128, 72,100,144, 100,132,168, // 220-223
- 216,244,252, 96,128,164, 68, 96,140, 76, 24, 8, // 224-227
- 108, 44, 24, 144, 72, 52, 176,108, 84, 210,146,126, // 228-231
- 252, 60, 0, 252, 84, 0, 252,104, 0, 252,124, 0, // 232-235
- 252,148, 0, 252,172, 0, 252,196, 0, 64, 0, 0, // 236-239
- 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
- 255,255, 0, 148,148,148, 247, 0,247, 248, 0,248, // 244-247
- 249, 0,249, 250, 0,250, 251, 0,251, 252, 0,252, // 248-251
- 253, 0,253, 254, 0,254, 255, 0,255, 255,255,255, // 252-255
+ // PAL_ttw_norm
+ {0, 0, 255, 238, 0, 238, 239, 0, 239, 240, 0, 240, // 0-3
+ 241, 0, 241, 242, 0, 242, 243, 0, 243, 244, 0, 244, // 4-7
+ 245, 0, 245, 246, 0, 246, 168, 168, 168, 184, 184, 184, // 8-11
+ 200, 200, 200, 216, 216, 216, 232, 232, 232, 252, 252, 252, // 12-15
+ 52, 60, 72, 68, 76, 92, 88, 96, 112, 108, 116, 132, // 16-19
+ 132, 140, 152, 156, 160, 172, 176, 184, 196, 204, 208, 220, // 20-23
+ 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
+ 120, 120, 64, 148, 148, 100, 176, 176, 132, 204, 204, 168, // 28-31
+ 100, 100, 100, 116, 116, 116, 104, 80, 44, 124, 104, 72, // 32-35
+ 152, 132, 92, 184, 160, 120, 212, 188, 148, 244, 220, 176, // 36-39
+ 132, 132, 132, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
+ 160, 56, 76, 188, 84, 108, 204, 104, 124, 220, 132, 144, // 44-47
+ 236, 156, 164, 252, 188, 192, 252, 208, 0, 252, 232, 60, // 48-51
+ 252, 252, 128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
+ 136, 116, 56, 156, 136, 80, 176, 156, 108, 196, 180, 136, // 56-59
+ 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
+ 184, 120, 24, 212, 156, 32, 232, 184, 16, 252, 212, 0, // 64-67
+ 252, 248, 128, 252, 252, 192, 32, 4, 0, 64, 20, 8, // 68-71
+ 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
+ 168, 92, 76, 184, 108, 88, 196, 128, 108, 212, 148, 128, // 76-79
+ 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
+ 64, 112, 12, 84, 132, 20, 104, 148, 28, 128, 168, 44, // 84-87
+ 64, 64, 64, 44, 68, 32, 60, 88, 48, 80, 104, 60, // 88-91
+ 104, 124, 76, 128, 148, 92, 152, 176, 108, 180, 204, 124, // 92-95
+ 16, 52, 24, 32, 72, 44, 56, 96, 72, 76, 116, 88, // 96-99
+ 96, 136, 108, 120, 164, 136, 152, 192, 168, 184, 220, 200, // 100-103
+ 32, 24, 0, 56, 28, 0, 80, 80, 80, 88, 52, 12, // 104-107
+ 104, 64, 24, 124, 84, 44, 140, 108, 64, 160, 128, 88, // 108-111
+ 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
+ 164, 96, 64, 184, 112, 80, 204, 128, 96, 212, 148, 112, // 116-119
+ 224, 168, 128, 236, 188, 148, 80, 28, 4, 100, 40, 20, // 120-123
+ 120, 56, 40, 140, 76, 64, 160, 100, 96, 184, 136, 136, // 124-127
+ 36, 40, 68, 48, 52, 84, 64, 64, 100, 80, 80, 116, // 128-131
+ 100, 100, 136, 132, 132, 164, 172, 172, 192, 212, 212, 224, // 132-135
+ 48, 48, 48, 64, 44, 144, 88, 64, 172, 104, 76, 196, // 136-139
+ 120, 88, 224, 140, 104, 252, 160, 136, 252, 188, 168, 252, // 140-143
+ 0, 24, 108, 0, 36, 132, 0, 52, 160, 0, 72, 184, // 144-147
+ 0, 96, 212, 24, 120, 220, 56, 144, 232, 88, 168, 240, // 148-151
+ 128, 196, 252, 188, 224, 252, 16, 64, 96, 24, 80, 108, // 152-155
+ 40, 96, 120, 52, 112, 132, 80, 140, 160, 116, 172, 192, // 156-159
+ 156, 204, 220, 204, 240, 252, 172, 52, 52, 212, 52, 52, // 160-163
+ 252, 52, 52, 252, 100, 88, 252, 144, 124, 252, 184, 160, // 164-167
+ 252, 216, 200, 252, 244, 236, 72, 20, 112, 92, 44, 140, // 168-171
+ 112, 68, 168, 140, 100, 196, 168, 136, 224, 200, 176, 248, // 172-175
+ 208, 184, 255, 232, 208, 252, 60, 0, 0, 92, 0, 0, // 176-179
+ 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
+ 252, 0, 0, 252, 80, 0, 252, 108, 0, 252, 136, 0, // 184-187
+ 252, 164, 0, 252, 192, 0, 252, 220, 0, 252, 252, 0, // 188-191
+ 204, 136, 8, 228, 144, 4, 252, 156, 0, 252, 176, 48, // 192-195
+ 252, 196, 100, 252, 216, 152, 8, 24, 88, 12, 36, 104, // 196-199
+ 20, 52, 124, 28, 68, 140, 40, 92, 164, 56, 120, 188, // 200-203
+ 72, 152, 216, 100, 172, 224, 92, 156, 52, 108, 176, 64, // 204-207
+ 124, 200, 76, 144, 224, 92, 224, 244, 252, 200, 236, 248, // 208-211
+ 180, 220, 236, 132, 188, 216, 88, 152, 172, 16, 16, 16, // 212-215
+ 32, 32, 32, 32, 68, 112, 36, 72, 116, 40, 76, 120, // 216-219
+ 44, 80, 124, 48, 84, 128, 72, 100, 144, 100, 132, 168, // 220-223
+ 216, 244, 252, 96, 128, 164, 68, 96, 140, 76, 24, 8, // 224-227
+ 108, 44, 24, 144, 72, 52, 176, 108, 84, 210, 146, 126, // 228-231
+ 252, 60, 0, 252, 84, 0, 252, 104, 0, 252, 124, 0, // 232-235
+ 252, 148, 0, 252, 172, 0, 252, 196, 0, 64, 0, 0, // 236-239
+ 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
+ 255, 255, 0, 148, 148, 148, 247, 0, 247, 248, 0, 248, // 244-247
+ 249, 0, 249, 250, 0, 250, 251, 0, 251, 252, 0, 252, // 248-251
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 255, 255, 255, // 252-255
},
-// PAL_ttd_cand
- {
- 0, 0,255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
- 64, 64, 64, 80, 80, 80, 100,100,100, 116,116,116, // 4-7
- 132,132,132, 148,148,148, 168,168,168, 184,184,184, // 8-11
- 200,200,200, 216,216,216, 232,232,232, 252,252,252, // 12-15
- 52, 60, 72, 68, 76, 92, 88, 96,112, 108,116,132, // 16-19
- 132,140,152, 156,160,172, 176,184,196, 204,208,220, // 20-23
- 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
- 120,120, 64, 148,148,100, 176,176,132, 204,204,168, // 28-31
- 72, 44, 4, 88, 60, 20, 104, 80, 44, 124,104, 72, // 32-35
- 152,132, 92, 184,160,120, 212,188,148, 244,220,176, // 36-39
- 64, 0, 4, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
- 160, 56, 76, 188, 84,108, 204,104,124, 220,132,144, // 44-47
- 236,156,164, 252,188,192, 252,208, 0, 252,232, 60, // 48-51
- 252,252,128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
- 136,116, 56, 156,136, 80, 176,156,108, 196,180,136, // 56-59
- 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
- 184,120, 24, 212,156, 32, 232,184, 16, 252,212, 0, // 64-67
- 252,248,128, 252,252,192, 32, 4, 0, 64, 20, 8, // 68-71
- 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
- 168, 92, 76, 184,108, 88, 196,128,108, 212,148,128, // 76-79
- 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
- 64,112, 12, 84,132, 20, 104,148, 28, 128,168, 44, // 84-87
- 28, 52, 24, 44, 68, 32, 60, 88, 48, 80,104, 60, // 88-91
- 104,124, 76, 128,148, 92, 152,176,108, 180,204,124, // 92-95
- 16, 52, 24, 32, 72, 44, 56, 96, 72, 76,116, 88, // 96-99
- 96,136,108, 120,164,136, 152,192,168, 184,220,200, // 100-103
- 32, 24, 0, 56, 28, 0, 72, 40, 4, 88, 52, 12, // 104-107
- 104, 64, 24, 124, 84, 44, 140,108, 64, 160,128, 88, // 108-111
- 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
- 164, 96, 64, 184,112, 80, 204,128, 96, 212,148,112, // 116-119
- 224,168,128, 236,188,148, 80, 28, 4, 100, 40, 20, // 120-123
- 120, 56, 40, 140, 76, 64, 160,100, 96, 184,136,136, // 124-127
- 36, 40, 68, 48, 52, 84, 64, 64,100, 80, 80,116, // 128-131
- 100,100,136, 132,132,164, 172,172,192, 212,212,224, // 132-135
- 40, 20,112, 64, 44,144, 88, 64,172, 104, 76,196, // 136-139
- 120, 88,224, 140,104,252, 160,136,252, 188,168,252, // 140-143
- 0, 24,108, 0, 36,132, 0, 52,160, 0, 72,184, // 144-147
- 0, 96,212, 24,120,220, 56,144,232, 88,168,240, // 148-151
- 128,196,252, 188,224,252, 16, 64, 96, 24, 80,108, // 152-155
- 40, 96,120, 52,112,132, 80,140,160, 116,172,192, // 156-159
- 156,204,220, 204,240,252, 172, 52, 52, 212, 52, 52, // 160-163
- 252, 52, 52, 252,100, 88, 252,144,124, 252,184,160, // 164-167
- 252,216,200, 252,244,236, 72, 20,112, 92, 44,140, // 168-171
- 112, 68,168, 140,100,196, 168,136,224, 200,176,248, // 172-175
- 208,184,255, 232,208,252, 60, 0, 0, 92, 0, 0, // 176-179
- 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
- 252, 0, 0, 252, 80, 0, 252,108, 0, 252,136, 0, // 184-187
- 252,164, 0, 252,192, 0, 252,220, 0, 252,252, 0, // 188-191
- 204,136, 8, 228,144, 4, 252,156, 0, 252,176, 48, // 192-195
- 252,196,100, 252,216,152, 8, 24, 88, 12, 36,104, // 196-199
- 20, 52,124, 28, 68,140, 40, 92,164, 56,120,188, // 200-203
- 72,152,216, 100,172,224, 92,156, 52, 108,176, 64, // 204-207
- 124,200, 76, 144,224, 92, 224,244,252, 200,236,248, // 208-211
- 180,220,236, 132,188,216, 88,152,172, 244, 0,244, // 212-215
- 245, 0,245, 246, 0,246, 247, 0,247, 248, 0,248, // 216-219
- 249, 0,249, 250, 0,250, 251, 0,251, 252, 0,252, // 220-223
- 253, 0,253, 254, 0,254, 255, 0,255, 76, 24, 8, // 224-227
- 108, 44, 24, 144, 72, 52, 176,108, 84, 210,146,126, // 228-231
- 252, 60, 0, 252, 84, 0, 252,104, 0, 252,124, 0, // 232-235
- 252,148, 0, 252,172, 0, 252,196, 0, 64, 0, 0, // 236-239
- 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
- 255,255, 0, 28,108,124, 32,112,128, 36,116,132, // 244-247
- 40,120,136, 44,124,140, 92,164,184, 116,180,196, // 248-251
- 216,244,252, 112,176,192, 88,160,180, 255,255,255, // 252-255
+ // PAL_ttd_cand
+ {0, 0, 255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
+ 64, 64, 64, 80, 80, 80, 100, 100, 100, 116, 116, 116, // 4-7
+ 132, 132, 132, 148, 148, 148, 168, 168, 168, 184, 184, 184, // 8-11
+ 200, 200, 200, 216, 216, 216, 232, 232, 232, 252, 252, 252, // 12-15
+ 52, 60, 72, 68, 76, 92, 88, 96, 112, 108, 116, 132, // 16-19
+ 132, 140, 152, 156, 160, 172, 176, 184, 196, 204, 208, 220, // 20-23
+ 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
+ 120, 120, 64, 148, 148, 100, 176, 176, 132, 204, 204, 168, // 28-31
+ 72, 44, 4, 88, 60, 20, 104, 80, 44, 124, 104, 72, // 32-35
+ 152, 132, 92, 184, 160, 120, 212, 188, 148, 244, 220, 176, // 36-39
+ 64, 0, 4, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
+ 160, 56, 76, 188, 84, 108, 204, 104, 124, 220, 132, 144, // 44-47
+ 236, 156, 164, 252, 188, 192, 252, 208, 0, 252, 232, 60, // 48-51
+ 252, 252, 128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
+ 136, 116, 56, 156, 136, 80, 176, 156, 108, 196, 180, 136, // 56-59
+ 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
+ 184, 120, 24, 212, 156, 32, 232, 184, 16, 252, 212, 0, // 64-67
+ 252, 248, 128, 252, 252, 192, 32, 4, 0, 64, 20, 8, // 68-71
+ 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
+ 168, 92, 76, 184, 108, 88, 196, 128, 108, 212, 148, 128, // 76-79
+ 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
+ 64, 112, 12, 84, 132, 20, 104, 148, 28, 128, 168, 44, // 84-87
+ 28, 52, 24, 44, 68, 32, 60, 88, 48, 80, 104, 60, // 88-91
+ 104, 124, 76, 128, 148, 92, 152, 176, 108, 180, 204, 124, // 92-95
+ 16, 52, 24, 32, 72, 44, 56, 96, 72, 76, 116, 88, // 96-99
+ 96, 136, 108, 120, 164, 136, 152, 192, 168, 184, 220, 200, // 100-103
+ 32, 24, 0, 56, 28, 0, 72, 40, 4, 88, 52, 12, // 104-107
+ 104, 64, 24, 124, 84, 44, 140, 108, 64, 160, 128, 88, // 108-111
+ 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
+ 164, 96, 64, 184, 112, 80, 204, 128, 96, 212, 148, 112, // 116-119
+ 224, 168, 128, 236, 188, 148, 80, 28, 4, 100, 40, 20, // 120-123
+ 120, 56, 40, 140, 76, 64, 160, 100, 96, 184, 136, 136, // 124-127
+ 36, 40, 68, 48, 52, 84, 64, 64, 100, 80, 80, 116, // 128-131
+ 100, 100, 136, 132, 132, 164, 172, 172, 192, 212, 212, 224, // 132-135
+ 40, 20, 112, 64, 44, 144, 88, 64, 172, 104, 76, 196, // 136-139
+ 120, 88, 224, 140, 104, 252, 160, 136, 252, 188, 168, 252, // 140-143
+ 0, 24, 108, 0, 36, 132, 0, 52, 160, 0, 72, 184, // 144-147
+ 0, 96, 212, 24, 120, 220, 56, 144, 232, 88, 168, 240, // 148-151
+ 128, 196, 252, 188, 224, 252, 16, 64, 96, 24, 80, 108, // 152-155
+ 40, 96, 120, 52, 112, 132, 80, 140, 160, 116, 172, 192, // 156-159
+ 156, 204, 220, 204, 240, 252, 172, 52, 52, 212, 52, 52, // 160-163
+ 252, 52, 52, 252, 100, 88, 252, 144, 124, 252, 184, 160, // 164-167
+ 252, 216, 200, 252, 244, 236, 72, 20, 112, 92, 44, 140, // 168-171
+ 112, 68, 168, 140, 100, 196, 168, 136, 224, 200, 176, 248, // 172-175
+ 208, 184, 255, 232, 208, 252, 60, 0, 0, 92, 0, 0, // 176-179
+ 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
+ 252, 0, 0, 252, 80, 0, 252, 108, 0, 252, 136, 0, // 184-187
+ 252, 164, 0, 252, 192, 0, 252, 220, 0, 252, 252, 0, // 188-191
+ 204, 136, 8, 228, 144, 4, 252, 156, 0, 252, 176, 48, // 192-195
+ 252, 196, 100, 252, 216, 152, 8, 24, 88, 12, 36, 104, // 196-199
+ 20, 52, 124, 28, 68, 140, 40, 92, 164, 56, 120, 188, // 200-203
+ 72, 152, 216, 100, 172, 224, 92, 156, 52, 108, 176, 64, // 204-207
+ 124, 200, 76, 144, 224, 92, 224, 244, 252, 200, 236, 248, // 208-211
+ 180, 220, 236, 132, 188, 216, 88, 152, 172, 244, 0, 244, // 212-215
+ 245, 0, 245, 246, 0, 246, 247, 0, 247, 248, 0, 248, // 216-219
+ 249, 0, 249, 250, 0, 250, 251, 0, 251, 252, 0, 252, // 220-223
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 76, 24, 8, // 224-227
+ 108, 44, 24, 144, 72, 52, 176, 108, 84, 210, 146, 126, // 228-231
+ 252, 60, 0, 252, 84, 0, 252, 104, 0, 252, 124, 0, // 232-235
+ 252, 148, 0, 252, 172, 0, 252, 196, 0, 64, 0, 0, // 236-239
+ 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
+ 255, 255, 0, 28, 108, 124, 32, 112, 128, 36, 116, 132, // 244-247
+ 40, 120, 136, 44, 124, 140, 92, 164, 184, 116, 180, 196, // 248-251
+ 216, 244, 252, 112, 176, 192, 88, 160, 180, 255, 255, 255, // 252-255
},
-// PAL_ttw_cand
- {
- 0, 0,255, 238, 0,238, 239, 0,239, 240, 0,240, // 0-3
- 241, 0,241, 242, 0,242, 243, 0,243, 244, 0,244, // 4-7
- 245, 0,245, 246, 0,246, 168,168,168, 184,184,184, // 8-11
- 200,200,200, 216,216,216, 232,232,232, 252,252,252, // 12-15
- 52, 60, 72, 68, 76, 92, 88, 96,112, 108,116,132, // 16-19
- 132,140,152, 156,160,172, 176,184,196, 204,208,220, // 20-23
- 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
- 120,120, 64, 148,148,100, 176,176,132, 204,204,168, // 28-31
- 100,100,100, 116,116,116, 104, 80, 44, 124,104, 72, // 32-35
- 152,132, 92, 184,160,120, 212,188,148, 244,220,176, // 36-39
- 132,132,132, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
- 160, 56, 76, 188, 84,108, 204,104,124, 220,132,144, // 44-47
- 236,156,164, 252,188,192, 252,208, 0, 252,232, 60, // 48-51
- 252,252,128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
- 136,116, 56, 156,136, 80, 176,156,108, 196,180,136, // 56-59
- 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
- 184,120, 24, 212,156, 32, 232,184, 16, 252,212, 0, // 64-67
- 252,248,128, 252,252,192, 32, 4, 0, 64, 20, 8, // 68-71
- 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
- 168, 92, 76, 184,108, 88, 196,128,108, 212,148,128, // 76-79
- 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
- 64,112, 12, 84,132, 20, 104,148, 28, 128,168, 44, // 84-87
- 64, 64, 64, 44, 68, 32, 60, 88, 48, 80,104, 60, // 88-91
- 104,124, 76, 128,148, 92, 152,176,108, 180,204,124, // 92-95
- 16, 52, 24, 32, 72, 44, 56, 96, 72, 76,116, 88, // 96-99
- 96,136,108, 120,164,136, 152,192,168, 184,220,200, // 100-103
- 32, 24, 0, 56, 28, 0, 80, 80, 80, 88, 52, 12, // 104-107
- 104, 64, 24, 124, 84, 44, 140,108, 64, 160,128, 88, // 108-111
- 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
- 164, 96, 64, 184,112, 80, 204,128, 96, 212,148,112, // 116-119
- 224,168,128, 236,188,148, 80, 28, 4, 100, 40, 20, // 120-123
- 120, 56, 40, 140, 76, 64, 160,100, 96, 184,136,136, // 124-127
- 36, 40, 68, 48, 52, 84, 64, 64,100, 80, 80,116, // 128-131
- 100,100,136, 132,132,164, 172,172,192, 212,212,224, // 132-135
- 48, 48, 48, 64, 44,144, 88, 64,172, 104, 76,196, // 136-139
- 120, 88,224, 140,104,252, 160,136,252, 188,168,252, // 140-143
- 0, 24,108, 0, 36,132, 0, 52,160, 0, 72,184, // 144-147
- 0, 96,212, 24,120,220, 56,144,232, 88,168,240, // 148-151
- 128,196,252, 188,224,252, 16, 64, 96, 24, 80,108, // 152-155
- 40, 96,120, 52,112,132, 80,140,160, 116,172,192, // 156-159
- 156,204,220, 204,240,252, 172, 52, 52, 212, 52, 52, // 160-163
- 252, 52, 52, 252,100, 88, 252,144,124, 252,184,160, // 164-167
- 252,216,200, 252,244,236, 72, 20,112, 92, 44,140, // 168-171
- 112, 68,168, 140,100,196, 168,136,224, 200,176,248, // 172-175
- 208,184,255, 232,208,252, 60, 0, 0, 92, 0, 0, // 176-179
- 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
- 252, 0, 0, 252, 80, 0, 252,108, 0, 252,136, 0, // 184-187
- 252,164, 0, 252,192, 0, 252,220, 0, 252,252, 0, // 188-191
- 204,136, 8, 228,144, 4, 252,156, 0, 252,176, 48, // 192-195
- 252,196,100, 252,216,152, 8, 24, 88, 12, 36,104, // 196-199
- 20, 52,124, 28, 68,140, 40, 92,164, 56,120,188, // 200-203
- 72,152,216, 100,172,224, 92,156, 52, 108,176, 64, // 204-207
- 124,200, 76, 144,224, 92, 224,244,252, 200,236,248, // 208-211
- 180,220,236, 132,188,216, 88,152,172, 16, 16, 16, // 212-215
- 32, 32, 32, 28,108,124, 32,112,128, 36,116,132, // 216-219
- 40,120,136, 44,124,140, 92,164,184, 116,180,196, // 220-223
- 216,244,252, 112,176,192, 88,160,180, 76, 24, 8, // 224-227
- 108, 44, 24, 144, 72, 52, 176,108, 84, 210,146,126, // 228-231
- 252, 60, 0, 252, 84, 0, 252,104, 0, 252,124, 0, // 232-235
- 252,148, 0, 252,172, 0, 252,196, 0, 64, 0, 0, // 236-239
- 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
- 255,255, 0, 148,148,148, 247, 0,247, 248, 0,248, // 244-247
- 249, 0,249, 250, 0,250, 251, 0,251, 252, 0,252, // 248-251
- 253, 0,253, 254, 0,254, 255, 0,255, 255,255,255, // 252-255
+ // PAL_ttw_cand
+ {0, 0, 255, 238, 0, 238, 239, 0, 239, 240, 0, 240, // 0-3
+ 241, 0, 241, 242, 0, 242, 243, 0, 243, 244, 0, 244, // 4-7
+ 245, 0, 245, 246, 0, 246, 168, 168, 168, 184, 184, 184, // 8-11
+ 200, 200, 200, 216, 216, 216, 232, 232, 232, 252, 252, 252, // 12-15
+ 52, 60, 72, 68, 76, 92, 88, 96, 112, 108, 116, 132, // 16-19
+ 132, 140, 152, 156, 160, 172, 176, 184, 196, 204, 208, 220, // 20-23
+ 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
+ 120, 120, 64, 148, 148, 100, 176, 176, 132, 204, 204, 168, // 28-31
+ 100, 100, 100, 116, 116, 116, 104, 80, 44, 124, 104, 72, // 32-35
+ 152, 132, 92, 184, 160, 120, 212, 188, 148, 244, 220, 176, // 36-39
+ 132, 132, 132, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
+ 160, 56, 76, 188, 84, 108, 204, 104, 124, 220, 132, 144, // 44-47
+ 236, 156, 164, 252, 188, 192, 252, 208, 0, 252, 232, 60, // 48-51
+ 252, 252, 128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
+ 136, 116, 56, 156, 136, 80, 176, 156, 108, 196, 180, 136, // 56-59
+ 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
+ 184, 120, 24, 212, 156, 32, 232, 184, 16, 252, 212, 0, // 64-67
+ 252, 248, 128, 252, 252, 192, 32, 4, 0, 64, 20, 8, // 68-71
+ 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
+ 168, 92, 76, 184, 108, 88, 196, 128, 108, 212, 148, 128, // 76-79
+ 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
+ 64, 112, 12, 84, 132, 20, 104, 148, 28, 128, 168, 44, // 84-87
+ 64, 64, 64, 44, 68, 32, 60, 88, 48, 80, 104, 60, // 88-91
+ 104, 124, 76, 128, 148, 92, 152, 176, 108, 180, 204, 124, // 92-95
+ 16, 52, 24, 32, 72, 44, 56, 96, 72, 76, 116, 88, // 96-99
+ 96, 136, 108, 120, 164, 136, 152, 192, 168, 184, 220, 200, // 100-103
+ 32, 24, 0, 56, 28, 0, 80, 80, 80, 88, 52, 12, // 104-107
+ 104, 64, 24, 124, 84, 44, 140, 108, 64, 160, 128, 88, // 108-111
+ 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
+ 164, 96, 64, 184, 112, 80, 204, 128, 96, 212, 148, 112, // 116-119
+ 224, 168, 128, 236, 188, 148, 80, 28, 4, 100, 40, 20, // 120-123
+ 120, 56, 40, 140, 76, 64, 160, 100, 96, 184, 136, 136, // 124-127
+ 36, 40, 68, 48, 52, 84, 64, 64, 100, 80, 80, 116, // 128-131
+ 100, 100, 136, 132, 132, 164, 172, 172, 192, 212, 212, 224, // 132-135
+ 48, 48, 48, 64, 44, 144, 88, 64, 172, 104, 76, 196, // 136-139
+ 120, 88, 224, 140, 104, 252, 160, 136, 252, 188, 168, 252, // 140-143
+ 0, 24, 108, 0, 36, 132, 0, 52, 160, 0, 72, 184, // 144-147
+ 0, 96, 212, 24, 120, 220, 56, 144, 232, 88, 168, 240, // 148-151
+ 128, 196, 252, 188, 224, 252, 16, 64, 96, 24, 80, 108, // 152-155
+ 40, 96, 120, 52, 112, 132, 80, 140, 160, 116, 172, 192, // 156-159
+ 156, 204, 220, 204, 240, 252, 172, 52, 52, 212, 52, 52, // 160-163
+ 252, 52, 52, 252, 100, 88, 252, 144, 124, 252, 184, 160, // 164-167
+ 252, 216, 200, 252, 244, 236, 72, 20, 112, 92, 44, 140, // 168-171
+ 112, 68, 168, 140, 100, 196, 168, 136, 224, 200, 176, 248, // 172-175
+ 208, 184, 255, 232, 208, 252, 60, 0, 0, 92, 0, 0, // 176-179
+ 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
+ 252, 0, 0, 252, 80, 0, 252, 108, 0, 252, 136, 0, // 184-187
+ 252, 164, 0, 252, 192, 0, 252, 220, 0, 252, 252, 0, // 188-191
+ 204, 136, 8, 228, 144, 4, 252, 156, 0, 252, 176, 48, // 192-195
+ 252, 196, 100, 252, 216, 152, 8, 24, 88, 12, 36, 104, // 196-199
+ 20, 52, 124, 28, 68, 140, 40, 92, 164, 56, 120, 188, // 200-203
+ 72, 152, 216, 100, 172, 224, 92, 156, 52, 108, 176, 64, // 204-207
+ 124, 200, 76, 144, 224, 92, 224, 244, 252, 200, 236, 248, // 208-211
+ 180, 220, 236, 132, 188, 216, 88, 152, 172, 16, 16, 16, // 212-215
+ 32, 32, 32, 28, 108, 124, 32, 112, 128, 36, 116, 132, // 216-219
+ 40, 120, 136, 44, 124, 140, 92, 164, 184, 116, 180, 196, // 220-223
+ 216, 244, 252, 112, 176, 192, 88, 160, 180, 76, 24, 8, // 224-227
+ 108, 44, 24, 144, 72, 52, 176, 108, 84, 210, 146, 126, // 228-231
+ 252, 60, 0, 252, 84, 0, 252, 104, 0, 252, 124, 0, // 232-235
+ 252, 148, 0, 252, 172, 0, 252, 196, 0, 64, 0, 0, // 236-239
+ 255, 0, 0, 48, 48, 0, 64, 64, 0, 80, 80, 0, // 240-243
+ 255, 255, 0, 148, 148, 148, 247, 0, 247, 248, 0, 248, // 244-247
+ 249, 0, 249, 250, 0, 250, 251, 0, 251, 252, 0, 252, // 248-251
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 255, 255, 255, // 252-255
},
-// PAL_tt1_norm
- {
- 0, 0,255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
- 68, 68, 68, 84, 84, 84, 100,100,100, 116,116,116, // 4-7
- 136,136,136, 152,152,152, 168,168,168, 184,184,184, // 8-11
- 204,204,204, 220,220,220, 236,236,236, 252,252,252, // 12-15
- 204,204,168, 184,184,152, 168,168,116, 152,152,100, // 16-19
- 136,136, 84, 100,100, 68, 84, 84, 48, 68, 68, 32, // 20-23
- 48, 48, 16, 252,220,116, 252,204, 68, 252,184, 32, // 24-27
- 220,152, 48, 184,132, 48, 148,120, 52, 116,100, 48, // 28-31
- 100, 84, 48, 84, 68, 32, 68, 48, 16, 0, 0, 44, // 32-35
- 4, 12, 68, 8, 24, 88, 12, 36,104, 20, 52,124, // 36-39
- 28, 68,140, 40, 92,164, 56,120,188, 72,152,216, // 40-43
- 100,172,224, 132,196,236, 168,216,244, 204,236,252, // 44-47
- 48, 0, 0, 80, 0, 0, 108, 4, 4, 136, 12, 12, // 48-51
- 164, 20, 20, 196, 32, 32, 224, 44, 44, 252, 56, 56, // 52-55
- 84, 32, 0, 100, 48, 0, 132, 64, 0, 168, 80, 0, // 56-59
- 200, 96, 0, 236,152, 0, 236,184, 68, 252,236,136, // 60-63
- 124,140, 60, 116,128, 48, 104,116, 36, 96,104, 28, // 64-67
- 84, 92, 20, 76, 80, 12, 68, 72, 4, 56, 60, 0, // 68-71
- 48, 48, 0, 252, 60, 0, 252, 96, 0, 252,128, 0, // 72-75
- 252,164, 0, 252,196, 0, 48, 16, 0, 68, 32, 0, // 76-79
- 100, 48, 16, 116, 68, 32, 136, 84, 32, 168,100, 48, // 80-83
- 184,116, 48, 220,136, 68, 236,152, 84, 236,168,100, // 84-87
- 252,184,116, 252,204,136, 108, 92, 92, 132, 88, 88, // 88-91
- 148, 80, 80, 164, 64, 64, 40, 16, 92, 64, 48,136, // 92-95
- 88, 64,172, 112, 84,212, 140,100,252, 160,140,252, // 96-99
- 204,192,180, 184,172,152, 164,148,132, 144,132,112, // 100-103
- 120,100, 76, 96, 72, 48, 68, 48, 24, 44, 28, 12, // 104-107
- 56, 44, 12, 56, 64, 32, 64, 48, 0, 100, 68, 28, // 108-111
- 84, 68, 0, 116,184,160, 88,160,124, 64,136, 92, // 112-115
- 44,116, 60, 24, 92, 32, 12, 72, 12, 0, 52, 0, // 116-119
- 116,116, 84, 168,152,100, 220,204,136, 252,236,168, // 120-123
- 116,100, 84, 152,136,116, 204,184,168, 252,220,204, // 124-127
- 200,132,108, 192,120, 96, 176,100, 80, 168, 88, 68, // 128-131
- 148, 68, 52, 132, 48, 36, 116, 32, 20, 100, 28, 12, // 132-135
- 68, 12, 0, 32, 16, 0, 112,140, 24, 80,124, 16, // 136-139
- 56,108, 12, 36, 96, 4, 40, 84, 16, 36, 72, 0, // 140-143
- 36, 64, 0, 136, 96, 60, 124, 84, 44, 112, 68, 32, // 144-147
- 100, 56, 20, 88, 44, 12, 72, 36, 4, 56, 24, 0, // 148-151
- 16, 16, 48, 32, 32, 68, 48, 48,100, 68, 72,120, // 152-155
- 92, 96,140, 120,120,164, 152,152,184, 168,168,204, // 156-159
- 180,196,116, 168,184, 84, 148,168, 84, 128,156, 80, // 160-163
- 112,140, 80, 96,124, 76, 72,100, 60, 52, 76, 48, // 164-167
- 32, 48, 32, 200,116, 32, 176,100, 24, 156, 84, 16, // 168-171
- 132, 72, 12, 112, 56, 4, 88, 40, 0, 68, 28, 0, // 172-175
- 252,252,180, 252,100,100, 148,204,168, 180,208,128, // 176-179
- 236,188,148, 228,172,132, 220,160,120, 212,144,108, // 180-183
- 204,128, 96, 196,116, 84, 184,104, 72, 168, 96, 64, // 184-187
- 148, 84, 52, 128, 76, 40, 112, 64, 32, 92, 52, 20, // 188-191
- 180,124,112, 172,104,100, 164, 88, 84, 132, 72, 68, // 192-195
- 104, 48, 48, 80, 32, 32, 241, 0,241, 242, 0,242, // 196-199
- 243, 0,243, 244, 0,244, 245, 0,245, 246, 0,246, // 200-203
- 247, 0,247, 248, 0,248, 249, 0,249, 250, 0,250, // 204-207
- 198,132,108, 190,120, 96, 174,100, 80, 166, 88, 68, // 208-211
- 146, 68, 52, 130, 48, 36, 114, 32, 20, 98, 28, 12, // 212-215
- 66, 12, 0, 30, 16, 0, 251, 0,251, 252, 0,252, // 216-219
- 253, 0,253, 254, 0,254, 255, 0,255, 0,188, 80, // 220-223
- 4,188, 92, 122,124,124, 142,144,144, 162,164,164, // 224-227
- 182,184,184, 202,204,204, 222,224,224, 242,244,244, // 228-231
- 32, 68,112, 255, 60, 0, 255, 84, 0, 255,108, 0, // 232-235
- 255,132, 0, 255,156, 0, 255,180, 0, 255,204, 0, // 236-239
- 50, 50, 0, 64, 64, 0, 78, 78, 0, 255,255, 0, // 240-243
- 72,100,144, 100,132,168, 216,244,252, 96,128,164, // 244-247
- 68, 96,140, 64, 0, 0, 255, 0, 0, 36, 72,116, // 248-251
- 40, 76,120, 44, 80,124, 48, 84,128, 255,255,255, // 252-255
+ // PAL_tt1_norm
+ {0, 0, 255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
+ 68, 68, 68, 84, 84, 84, 100, 100, 100, 116, 116, 116, // 4-7
+ 136, 136, 136, 152, 152, 152, 168, 168, 168, 184, 184, 184, // 8-11
+ 204, 204, 204, 220, 220, 220, 236, 236, 236, 252, 252, 252, // 12-15
+ 204, 204, 168, 184, 184, 152, 168, 168, 116, 152, 152, 100, // 16-19
+ 136, 136, 84, 100, 100, 68, 84, 84, 48, 68, 68, 32, // 20-23
+ 48, 48, 16, 252, 220, 116, 252, 204, 68, 252, 184, 32, // 24-27
+ 220, 152, 48, 184, 132, 48, 148, 120, 52, 116, 100, 48, // 28-31
+ 100, 84, 48, 84, 68, 32, 68, 48, 16, 0, 0, 44, // 32-35
+ 4, 12, 68, 8, 24, 88, 12, 36, 104, 20, 52, 124, // 36-39
+ 28, 68, 140, 40, 92, 164, 56, 120, 188, 72, 152, 216, // 40-43
+ 100, 172, 224, 132, 196, 236, 168, 216, 244, 204, 236, 252, // 44-47
+ 48, 0, 0, 80, 0, 0, 108, 4, 4, 136, 12, 12, // 48-51
+ 164, 20, 20, 196, 32, 32, 224, 44, 44, 252, 56, 56, // 52-55
+ 84, 32, 0, 100, 48, 0, 132, 64, 0, 168, 80, 0, // 56-59
+ 200, 96, 0, 236, 152, 0, 236, 184, 68, 252, 236, 136, // 60-63
+ 124, 140, 60, 116, 128, 48, 104, 116, 36, 96, 104, 28, // 64-67
+ 84, 92, 20, 76, 80, 12, 68, 72, 4, 56, 60, 0, // 68-71
+ 48, 48, 0, 252, 60, 0, 252, 96, 0, 252, 128, 0, // 72-75
+ 252, 164, 0, 252, 196, 0, 48, 16, 0, 68, 32, 0, // 76-79
+ 100, 48, 16, 116, 68, 32, 136, 84, 32, 168, 100, 48, // 80-83
+ 184, 116, 48, 220, 136, 68, 236, 152, 84, 236, 168, 100, // 84-87
+ 252, 184, 116, 252, 204, 136, 108, 92, 92, 132, 88, 88, // 88-91
+ 148, 80, 80, 164, 64, 64, 40, 16, 92, 64, 48, 136, // 92-95
+ 88, 64, 172, 112, 84, 212, 140, 100, 252, 160, 140, 252, // 96-99
+ 204, 192, 180, 184, 172, 152, 164, 148, 132, 144, 132, 112, // 100-103
+ 120, 100, 76, 96, 72, 48, 68, 48, 24, 44, 28, 12, // 104-107
+ 56, 44, 12, 56, 64, 32, 64, 48, 0, 100, 68, 28, // 108-111
+ 84, 68, 0, 116, 184, 160, 88, 160, 124, 64, 136, 92, // 112-115
+ 44, 116, 60, 24, 92, 32, 12, 72, 12, 0, 52, 0, // 116-119
+ 116, 116, 84, 168, 152, 100, 220, 204, 136, 252, 236, 168, // 120-123
+ 116, 100, 84, 152, 136, 116, 204, 184, 168, 252, 220, 204, // 124-127
+ 200, 132, 108, 192, 120, 96, 176, 100, 80, 168, 88, 68, // 128-131
+ 148, 68, 52, 132, 48, 36, 116, 32, 20, 100, 28, 12, // 132-135
+ 68, 12, 0, 32, 16, 0, 112, 140, 24, 80, 124, 16, // 136-139
+ 56, 108, 12, 36, 96, 4, 40, 84, 16, 36, 72, 0, // 140-143
+ 36, 64, 0, 136, 96, 60, 124, 84, 44, 112, 68, 32, // 144-147
+ 100, 56, 20, 88, 44, 12, 72, 36, 4, 56, 24, 0, // 148-151
+ 16, 16, 48, 32, 32, 68, 48, 48, 100, 68, 72, 120, // 152-155
+ 92, 96, 140, 120, 120, 164, 152, 152, 184, 168, 168, 204, // 156-159
+ 180, 196, 116, 168, 184, 84, 148, 168, 84, 128, 156, 80, // 160-163
+ 112, 140, 80, 96, 124, 76, 72, 100, 60, 52, 76, 48, // 164-167
+ 32, 48, 32, 200, 116, 32, 176, 100, 24, 156, 84, 16, // 168-171
+ 132, 72, 12, 112, 56, 4, 88, 40, 0, 68, 28, 0, // 172-175
+ 252, 252, 180, 252, 100, 100, 148, 204, 168, 180, 208, 128, // 176-179
+ 236, 188, 148, 228, 172, 132, 220, 160, 120, 212, 144, 108, // 180-183
+ 204, 128, 96, 196, 116, 84, 184, 104, 72, 168, 96, 64, // 184-187
+ 148, 84, 52, 128, 76, 40, 112, 64, 32, 92, 52, 20, // 188-191
+ 180, 124, 112, 172, 104, 100, 164, 88, 84, 132, 72, 68, // 192-195
+ 104, 48, 48, 80, 32, 32, 241, 0, 241, 242, 0, 242, // 196-199
+ 243, 0, 243, 244, 0, 244, 245, 0, 245, 246, 0, 246, // 200-203
+ 247, 0, 247, 248, 0, 248, 249, 0, 249, 250, 0, 250, // 204-207
+ 198, 132, 108, 190, 120, 96, 174, 100, 80, 166, 88, 68, // 208-211
+ 146, 68, 52, 130, 48, 36, 114, 32, 20, 98, 28, 12, // 212-215
+ 66, 12, 0, 30, 16, 0, 251, 0, 251, 252, 0, 252, // 216-219
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 0, 188, 80, // 220-223
+ 4, 188, 92, 122, 124, 124, 142, 144, 144, 162, 164, 164, // 224-227
+ 182, 184, 184, 202, 204, 204, 222, 224, 224, 242, 244, 244, // 228-231
+ 32, 68, 112, 255, 60, 0, 255, 84, 0, 255, 108, 0, // 232-235
+ 255, 132, 0, 255, 156, 0, 255, 180, 0, 255, 204, 0, // 236-239
+ 50, 50, 0, 64, 64, 0, 78, 78, 0, 255, 255, 0, // 240-243
+ 72, 100, 144, 100, 132, 168, 216, 244, 252, 96, 128, 164, // 244-247
+ 68, 96, 140, 64, 0, 0, 255, 0, 0, 36, 72, 116, // 248-251
+ 40, 76, 120, 44, 80, 124, 48, 84, 128, 255, 255, 255, // 252-255
},
-// PAL_tt1_mars
- {
- 0, 0,255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
- 68, 68, 68, 84, 84, 84, 100,100,100, 116,116,116, // 4-7
- 136,136,136, 152,152,152, 168,168,168, 184,184,184, // 8-11
- 204,204,204, 220,220,220, 236,236,236, 252,252,252, // 12-15
- 204,204,168, 184,184,152, 168,168,116, 152,152,100, // 16-19
- 136,136, 84, 100,100, 68, 84, 84, 48, 68, 68, 32, // 20-23
- 48, 48, 16, 252,220,116, 252,204, 68, 252,184, 32, // 24-27
- 220,152, 48, 184,132, 48, 148,120, 52, 116,100, 48, // 28-31
- 100, 84, 48, 84, 68, 32, 68, 48, 16, 0, 0, 44, // 32-35
- 4, 12, 68, 8, 24, 88, 12, 36,104, 20, 52,124, // 36-39
- 28, 68,140, 40, 92,164, 56,120,188, 72,152,216, // 40-43
- 100,172,224, 132,196,236, 168,216,244, 204,236,252, // 44-47
- 48, 0, 0, 80, 0, 0, 108, 4, 4, 136, 12, 12, // 48-51
- 164, 20, 20, 196, 32, 32, 224, 44, 44, 252, 56, 56, // 52-55
- 84, 32, 0, 100, 48, 0, 132, 64, 0, 168, 80, 0, // 56-59
- 200, 96, 0, 236,152, 0, 236,184, 68, 252,236,136, // 60-63
- 124,140, 60, 116,128, 48, 104,116, 36, 96,104, 28, // 64-67
- 84, 92, 20, 76, 80, 12, 68, 72, 4, 56, 60, 0, // 68-71
- 48, 48, 0, 252, 60, 0, 252, 96, 0, 252,128, 0, // 72-75
- 252,164, 0, 252,196, 0, 48, 16, 0, 68, 32, 0, // 76-79
- 100, 48, 16, 116, 68, 32, 136, 84, 32, 168,100, 48, // 80-83
- 184,116, 48, 220,136, 68, 236,152, 84, 236,168,100, // 84-87
- 252,184,116, 252,204,136, 108, 92, 92, 132, 88, 88, // 88-91
- 148, 80, 80, 164, 64, 64, 40, 16, 92, 64, 48,136, // 92-95
- 88, 64,172, 112, 84,212, 140,100,252, 160,140,252, // 96-99
- 204,192,180, 184,172,152, 164,148,132, 144,132,112, // 100-103
- 120,100, 76, 96, 72, 48, 68, 48, 24, 44, 28, 12, // 104-107
- 56, 44, 12, 56, 64, 32, 64, 48, 0, 100, 68, 28, // 108-111
- 84, 68, 0, 116,184,160, 88,160,124, 64,136, 92, // 112-115
- 44,116, 60, 24, 92, 32, 12, 72, 12, 0, 52, 0, // 116-119
- 116,116, 84, 168,152,100, 220,204,136, 252,236,168, // 120-123
- 116,100, 84, 152,136,116, 204,184,168, 252,220,204, // 124-127
- 200,132,108, 192,120, 96, 176,100, 80, 168, 88, 68, // 128-131
- 148, 68, 52, 132, 48, 36, 116, 32, 20, 100, 28, 12, // 132-135
- 68, 12, 0, 32, 16, 0, 112,140, 24, 80,124, 16, // 136-139
- 56,108, 12, 36, 96, 4, 40, 84, 16, 36, 72, 0, // 140-143
- 36, 64, 0, 136, 96, 60, 124, 84, 44, 112, 68, 32, // 144-147
- 100, 56, 20, 88, 44, 12, 72, 36, 4, 56, 24, 0, // 148-151
- 16, 16, 48, 32, 32, 68, 48, 48,100, 68, 72,120, // 152-155
- 92, 96,140, 120,120,164, 152,152,184, 168,168,204, // 156-159
- 180,196,116, 168,184, 84, 148,168, 84, 128,156, 80, // 160-163
- 112,140, 80, 96,124, 76, 72,100, 60, 52, 76, 48, // 164-167
- 32, 48, 32, 200,116, 32, 176,100, 24, 156, 84, 16, // 168-171
- 132, 72, 12, 112, 56, 4, 88, 40, 0, 68, 28, 0, // 172-175
- 252,252,180, 252,100,100, 148,204,168, 180,208,128, // 176-179
- 236,188,148, 228,172,132, 220,160,120, 212,144,108, // 180-183
- 204,128, 96, 196,116, 84, 184,104, 72, 168, 96, 64, // 184-187
- 148, 84, 52, 128, 76, 40, 112, 64, 32, 92, 52, 20, // 188-191
- 180,124,112, 172,104,100, 164, 88, 84, 132, 72, 68, // 192-195
- 104, 48, 48, 80, 32, 32, 241, 0,241, 242, 0,242, // 196-199
- 243, 0,243, 244, 0,244, 245, 0,245, 246, 0,246, // 200-203
- 247, 0,247, 248, 0,248, 249, 0,249, 250, 0,250, // 204-207
- 198,132,108, 190,120, 96, 174,100, 80, 166, 88, 68, // 208-211
- 146, 68, 52, 130, 48, 36, 114, 32, 20, 98, 28, 12, // 212-215
- 66, 12, 0, 30, 16, 0, 251, 0,251, 252, 0,252, // 216-219
- 253, 0,253, 254, 0,254, 255, 0,255, 0,188, 80, // 220-223
- 4,188, 92, 122,124,124, 142,144,144, 162,164,164, // 224-227
- 182,184,184, 202,204,204, 222,224,224, 242,244,244, // 228-231
- 116, 0, 0, 255, 60, 0, 255, 84, 0, 255,108, 0, // 232-235
- 255,132, 0, 255,156, 0, 255,180, 0, 255,204, 0, // 236-239
- 50, 50, 0, 64, 64, 0, 78, 78, 0, 255,255, 0, // 240-243
- 156, 40, 12, 200, 76, 68, 228,112,108, 208, 84, 76, // 244-247
- 164, 48, 20, 64, 0, 0, 255, 0, 0, 124, 4, 0, // 248-251
- 136, 16, 4, 148, 28, 8, 160, 44, 16, 255,255,255, // 252-255
+ // PAL_tt1_mars
+ {0, 0, 255, 16, 16, 16, 32, 32, 32, 48, 48, 48, // 0-3
+ 68, 68, 68, 84, 84, 84, 100, 100, 100, 116, 116, 116, // 4-7
+ 136, 136, 136, 152, 152, 152, 168, 168, 168, 184, 184, 184, // 8-11
+ 204, 204, 204, 220, 220, 220, 236, 236, 236, 252, 252, 252, // 12-15
+ 204, 204, 168, 184, 184, 152, 168, 168, 116, 152, 152, 100, // 16-19
+ 136, 136, 84, 100, 100, 68, 84, 84, 48, 68, 68, 32, // 20-23
+ 48, 48, 16, 252, 220, 116, 252, 204, 68, 252, 184, 32, // 24-27
+ 220, 152, 48, 184, 132, 48, 148, 120, 52, 116, 100, 48, // 28-31
+ 100, 84, 48, 84, 68, 32, 68, 48, 16, 0, 0, 44, // 32-35
+ 4, 12, 68, 8, 24, 88, 12, 36, 104, 20, 52, 124, // 36-39
+ 28, 68, 140, 40, 92, 164, 56, 120, 188, 72, 152, 216, // 40-43
+ 100, 172, 224, 132, 196, 236, 168, 216, 244, 204, 236, 252, // 44-47
+ 48, 0, 0, 80, 0, 0, 108, 4, 4, 136, 12, 12, // 48-51
+ 164, 20, 20, 196, 32, 32, 224, 44, 44, 252, 56, 56, // 52-55
+ 84, 32, 0, 100, 48, 0, 132, 64, 0, 168, 80, 0, // 56-59
+ 200, 96, 0, 236, 152, 0, 236, 184, 68, 252, 236, 136, // 60-63
+ 124, 140, 60, 116, 128, 48, 104, 116, 36, 96, 104, 28, // 64-67
+ 84, 92, 20, 76, 80, 12, 68, 72, 4, 56, 60, 0, // 68-71
+ 48, 48, 0, 252, 60, 0, 252, 96, 0, 252, 128, 0, // 72-75
+ 252, 164, 0, 252, 196, 0, 48, 16, 0, 68, 32, 0, // 76-79
+ 100, 48, 16, 116, 68, 32, 136, 84, 32, 168, 100, 48, // 80-83
+ 184, 116, 48, 220, 136, 68, 236, 152, 84, 236, 168, 100, // 84-87
+ 252, 184, 116, 252, 204, 136, 108, 92, 92, 132, 88, 88, // 88-91
+ 148, 80, 80, 164, 64, 64, 40, 16, 92, 64, 48, 136, // 92-95
+ 88, 64, 172, 112, 84, 212, 140, 100, 252, 160, 140, 252, // 96-99
+ 204, 192, 180, 184, 172, 152, 164, 148, 132, 144, 132, 112, // 100-103
+ 120, 100, 76, 96, 72, 48, 68, 48, 24, 44, 28, 12, // 104-107
+ 56, 44, 12, 56, 64, 32, 64, 48, 0, 100, 68, 28, // 108-111
+ 84, 68, 0, 116, 184, 160, 88, 160, 124, 64, 136, 92, // 112-115
+ 44, 116, 60, 24, 92, 32, 12, 72, 12, 0, 52, 0, // 116-119
+ 116, 116, 84, 168, 152, 100, 220, 204, 136, 252, 236, 168, // 120-123
+ 116, 100, 84, 152, 136, 116, 204, 184, 168, 252, 220, 204, // 124-127
+ 200, 132, 108, 192, 120, 96, 176, 100, 80, 168, 88, 68, // 128-131
+ 148, 68, 52, 132, 48, 36, 116, 32, 20, 100, 28, 12, // 132-135
+ 68, 12, 0, 32, 16, 0, 112, 140, 24, 80, 124, 16, // 136-139
+ 56, 108, 12, 36, 96, 4, 40, 84, 16, 36, 72, 0, // 140-143
+ 36, 64, 0, 136, 96, 60, 124, 84, 44, 112, 68, 32, // 144-147
+ 100, 56, 20, 88, 44, 12, 72, 36, 4, 56, 24, 0, // 148-151
+ 16, 16, 48, 32, 32, 68, 48, 48, 100, 68, 72, 120, // 152-155
+ 92, 96, 140, 120, 120, 164, 152, 152, 184, 168, 168, 204, // 156-159
+ 180, 196, 116, 168, 184, 84, 148, 168, 84, 128, 156, 80, // 160-163
+ 112, 140, 80, 96, 124, 76, 72, 100, 60, 52, 76, 48, // 164-167
+ 32, 48, 32, 200, 116, 32, 176, 100, 24, 156, 84, 16, // 168-171
+ 132, 72, 12, 112, 56, 4, 88, 40, 0, 68, 28, 0, // 172-175
+ 252, 252, 180, 252, 100, 100, 148, 204, 168, 180, 208, 128, // 176-179
+ 236, 188, 148, 228, 172, 132, 220, 160, 120, 212, 144, 108, // 180-183
+ 204, 128, 96, 196, 116, 84, 184, 104, 72, 168, 96, 64, // 184-187
+ 148, 84, 52, 128, 76, 40, 112, 64, 32, 92, 52, 20, // 188-191
+ 180, 124, 112, 172, 104, 100, 164, 88, 84, 132, 72, 68, // 192-195
+ 104, 48, 48, 80, 32, 32, 241, 0, 241, 242, 0, 242, // 196-199
+ 243, 0, 243, 244, 0, 244, 245, 0, 245, 246, 0, 246, // 200-203
+ 247, 0, 247, 248, 0, 248, 249, 0, 249, 250, 0, 250, // 204-207
+ 198, 132, 108, 190, 120, 96, 174, 100, 80, 166, 88, 68, // 208-211
+ 146, 68, 52, 130, 48, 36, 114, 32, 20, 98, 28, 12, // 212-215
+ 66, 12, 0, 30, 16, 0, 251, 0, 251, 252, 0, 252, // 216-219
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 0, 188, 80, // 220-223
+ 4, 188, 92, 122, 124, 124, 142, 144, 144, 162, 164, 164, // 224-227
+ 182, 184, 184, 202, 204, 204, 222, 224, 224, 242, 244, 244, // 228-231
+ 116, 0, 0, 255, 60, 0, 255, 84, 0, 255, 108, 0, // 232-235
+ 255, 132, 0, 255, 156, 0, 255, 180, 0, 255, 204, 0, // 236-239
+ 50, 50, 0, 64, 64, 0, 78, 78, 0, 255, 255, 0, // 240-243
+ 156, 40, 12, 200, 76, 68, 228, 112, 108, 208, 84, 76, // 244-247
+ 164, 48, 20, 64, 0, 0, 255, 0, 0, 124, 4, 0, // 248-251
+ 136, 16, 4, 148, 28, 8, 160, 44, 16, 255, 255, 255, // 252-255
},
-// PAL_ttw_pb_pal1
- {
- 0, 0,255, 238, 0,238, 239, 0,239, 240, 0,240, // 0-3
- 241, 0,241, 242, 0,242, 243, 0,243, 244, 0,244, // 4-7
- 245, 0,245, 246, 0,246, 168,168,168, 184,184,184, // 8-11
- 200,200,200, 216,216,216, 232,232,232, 252,252,252, // 12-15
- 52, 60, 72, 68, 76, 92, 88, 96,112, 108,116,132, // 16-19
- 132,140,152, 156,160,172, 176,184,196, 204,208,220, // 20-23
- 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
- 120,120, 64, 148,148,100, 176,176,132, 204,204,168, // 28-31
- 100,100,100, 116,116,116, 104, 80, 44, 124,104, 72, // 32-35
- 152,132, 92, 184,160,120, 212,188,148, 244,220,176, // 36-39
- 132,132,132, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
- 160, 56, 76, 188, 84,108, 204,104,124, 220,132,144, // 44-47
- 236,156,164, 252,188,192, 252,208, 0, 252,232, 60, // 48-51
- 252,252,128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
- 136,116, 56, 156,136, 80, 176,156,108, 196,180,136, // 56-59
- 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
- 184,120, 24, 212,156, 32, 232,184, 16, 252,212, 0, // 64-67
- 252,248,128, 252,252,192, 32, 4, 0, 64, 20, 8, // 68-71
- 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
- 168, 92, 76, 184,108, 88, 196,128,108, 212,148,128, // 76-79
- 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
- 64,112, 12, 84,132, 20, 104,148, 28, 128,168, 44, // 84-87
- 64, 64, 64, 44, 68, 32, 60, 88, 48, 80,104, 60, // 88-91
- 104,124, 76, 128,148, 92, 152,176,108, 180,204,124, // 92-95
- 16, 52, 24, 32, 72, 44, 56, 96, 72, 76,116, 88, // 96-99
- 96,136,108, 120,164,136, 152,192,168, 184,220,200, // 100-103
- 32, 24, 0, 56, 28, 0, 80, 80, 80, 88, 52, 12, // 104-107
- 104, 64, 24, 124, 84, 44, 140,108, 64, 160,128, 88, // 108-111
- 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
- 164, 96, 64, 184,112, 80, 204,128, 96, 212,148,112, // 116-119
- 224,168,128, 236,188,148, 80, 28, 4, 100, 40, 20, // 120-123
- 120, 56, 40, 140, 76, 64, 160,100, 96, 184,136,136, // 124-127
- 36, 40, 68, 48, 52, 84, 64, 64,100, 80, 80,116, // 128-131
- 100,100,136, 132,132,164, 172,172,192, 212,212,224, // 132-135
- 48, 48, 48, 64, 44,144, 88, 64,172, 104, 76,196, // 136-139
- 120, 88,224, 140,104,252, 160,136,252, 188,168,252, // 140-143
- 0, 24,108, 0, 36,132, 0, 52,160, 0, 72,184, // 144-147
- 0, 96,212, 24,120,220, 56,144,232, 88,168,240, // 148-151
- 128,196,252, 188,224,252, 16, 64, 96, 24, 80,108, // 152-155
- 40, 96,120, 52,112,132, 80,140,160, 116,172,192, // 156-159
- 156,204,220, 204,240,252, 172, 52, 52, 212, 52, 52, // 160-163
- 252, 52, 52, 252,100, 88, 252,144,124, 252,184,160, // 164-167
- 252,216,200, 252,244,236, 72, 20,112, 92, 44,140, // 168-171
- 112, 68,168, 140,100,196, 168,136,224, 200,176,248, // 172-175
- 208,184,255, 232,208,252, 60, 0, 0, 92, 0, 0, // 176-179
- 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
- 252, 0, 0, 252, 80, 0, 252,108, 0, 252,136, 0, // 184-187
- 252,164, 0, 252,192, 0, 252,220, 0, 252,252, 0, // 188-191
- 204,136, 8, 228,144, 4, 252,156, 0, 252,176, 48, // 192-195
- 252,196,100, 252,216,152, 8, 24, 88, 12, 36,104, // 196-199
- 20, 52,124, 28, 68,140, 40, 92,164, 56,120,188, // 200-203
- 72,152,216, 100,172,224, 92,156, 52, 108,176, 64, // 204-207
- 124,200, 76, 144,224, 92, 224,244,252, 200,236,248, // 208-211
- 180,220,236, 132,188,216, 88,152,172, 16, 16, 16, // 212-215
- 32, 32, 32, 32, 68,112, 36, 72,116, 40, 76,120, // 216-219
- 44, 80,124, 48, 84,128, 72,100,144, 100,132,168, // 220-223
- 216,244,252, 96,128,164, 68, 96,140, 255, 0,255, // 224-227
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 228-231
- 252, 60, 0, 252, 84, 0, 252,104, 0, 252,124, 0, // 232-235
- 252,148, 0, 252,172, 0, 252,196, 0, 64, 0, 0, // 236-239
- 255, 0, 0, 255, 0,255, 255, 0,255, 255, 0,255, // 240-243
- 255, 0,255, 148,148,148, 247, 0,247, 248, 0,248, // 244-247
- 249, 0,249, 250, 0,250, 251, 0,251, 252, 0,252, // 248-251
- 253, 0,253, 254, 0,254, 255, 0,255, 255,255,255, // 252-255
+ // PAL_ttw_pb_pal1
+ {0, 0, 255, 238, 0, 238, 239, 0, 239, 240, 0, 240, // 0-3
+ 241, 0, 241, 242, 0, 242, 243, 0, 243, 244, 0, 244, // 4-7
+ 245, 0, 245, 246, 0, 246, 168, 168, 168, 184, 184, 184, // 8-11
+ 200, 200, 200, 216, 216, 216, 232, 232, 232, 252, 252, 252, // 12-15
+ 52, 60, 72, 68, 76, 92, 88, 96, 112, 108, 116, 132, // 16-19
+ 132, 140, 152, 156, 160, 172, 176, 184, 196, 204, 208, 220, // 20-23
+ 48, 44, 4, 64, 60, 12, 80, 76, 20, 96, 92, 28, // 24-27
+ 120, 120, 64, 148, 148, 100, 176, 176, 132, 204, 204, 168, // 28-31
+ 100, 100, 100, 116, 116, 116, 104, 80, 44, 124, 104, 72, // 32-35
+ 152, 132, 92, 184, 160, 120, 212, 188, 148, 244, 220, 176, // 36-39
+ 132, 132, 132, 88, 4, 16, 112, 16, 32, 136, 32, 52, // 40-43
+ 160, 56, 76, 188, 84, 108, 204, 104, 124, 220, 132, 144, // 44-47
+ 236, 156, 164, 252, 188, 192, 252, 208, 0, 252, 232, 60, // 48-51
+ 252, 252, 128, 76, 40, 0, 96, 60, 8, 116, 88, 28, // 52-55
+ 136, 116, 56, 156, 136, 80, 176, 156, 108, 196, 180, 136, // 56-59
+ 68, 24, 0, 96, 44, 4, 128, 68, 8, 156, 96, 16, // 60-63
+ 184, 120, 24, 212, 156, 32, 232, 184, 16, 252, 212, 0, // 64-67
+ 252, 248, 128, 252, 252, 192, 32, 4, 0, 64, 20, 8, // 68-71
+ 84, 28, 16, 108, 44, 28, 128, 56, 40, 148, 72, 56, // 72-75
+ 168, 92, 76, 184, 108, 88, 196, 128, 108, 212, 148, 128, // 76-79
+ 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
+ 64, 112, 12, 84, 132, 20, 104, 148, 28, 128, 168, 44, // 84-87
+ 64, 64, 64, 44, 68, 32, 60, 88, 48, 80, 104, 60, // 88-91
+ 104, 124, 76, 128, 148, 92, 152, 176, 108, 180, 204, 124, // 92-95
+ 16, 52, 24, 32, 72, 44, 56, 96, 72, 76, 116, 88, // 96-99
+ 96, 136, 108, 120, 164, 136, 152, 192, 168, 184, 220, 200, // 100-103
+ 32, 24, 0, 56, 28, 0, 80, 80, 80, 88, 52, 12, // 104-107
+ 104, 64, 24, 124, 84, 44, 140, 108, 64, 160, 128, 88, // 108-111
+ 76, 40, 16, 96, 52, 24, 116, 68, 40, 136, 84, 56, // 112-115
+ 164, 96, 64, 184, 112, 80, 204, 128, 96, 212, 148, 112, // 116-119
+ 224, 168, 128, 236, 188, 148, 80, 28, 4, 100, 40, 20, // 120-123
+ 120, 56, 40, 140, 76, 64, 160, 100, 96, 184, 136, 136, // 124-127
+ 36, 40, 68, 48, 52, 84, 64, 64, 100, 80, 80, 116, // 128-131
+ 100, 100, 136, 132, 132, 164, 172, 172, 192, 212, 212, 224, // 132-135
+ 48, 48, 48, 64, 44, 144, 88, 64, 172, 104, 76, 196, // 136-139
+ 120, 88, 224, 140, 104, 252, 160, 136, 252, 188, 168, 252, // 140-143
+ 0, 24, 108, 0, 36, 132, 0, 52, 160, 0, 72, 184, // 144-147
+ 0, 96, 212, 24, 120, 220, 56, 144, 232, 88, 168, 240, // 148-151
+ 128, 196, 252, 188, 224, 252, 16, 64, 96, 24, 80, 108, // 152-155
+ 40, 96, 120, 52, 112, 132, 80, 140, 160, 116, 172, 192, // 156-159
+ 156, 204, 220, 204, 240, 252, 172, 52, 52, 212, 52, 52, // 160-163
+ 252, 52, 52, 252, 100, 88, 252, 144, 124, 252, 184, 160, // 164-167
+ 252, 216, 200, 252, 244, 236, 72, 20, 112, 92, 44, 140, // 168-171
+ 112, 68, 168, 140, 100, 196, 168, 136, 224, 200, 176, 248, // 172-175
+ 208, 184, 255, 232, 208, 252, 60, 0, 0, 92, 0, 0, // 176-179
+ 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
+ 252, 0, 0, 252, 80, 0, 252, 108, 0, 252, 136, 0, // 184-187
+ 252, 164, 0, 252, 192, 0, 252, 220, 0, 252, 252, 0, // 188-191
+ 204, 136, 8, 228, 144, 4, 252, 156, 0, 252, 176, 48, // 192-195
+ 252, 196, 100, 252, 216, 152, 8, 24, 88, 12, 36, 104, // 196-199
+ 20, 52, 124, 28, 68, 140, 40, 92, 164, 56, 120, 188, // 200-203
+ 72, 152, 216, 100, 172, 224, 92, 156, 52, 108, 176, 64, // 204-207
+ 124, 200, 76, 144, 224, 92, 224, 244, 252, 200, 236, 248, // 208-211
+ 180, 220, 236, 132, 188, 216, 88, 152, 172, 16, 16, 16, // 212-215
+ 32, 32, 32, 32, 68, 112, 36, 72, 116, 40, 76, 120, // 216-219
+ 44, 80, 124, 48, 84, 128, 72, 100, 144, 100, 132, 168, // 220-223
+ 216, 244, 252, 96, 128, 164, 68, 96, 140, 255, 0, 255, // 224-227
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 228-231
+ 252, 60, 0, 252, 84, 0, 252, 104, 0, 252, 124, 0, // 232-235
+ 252, 148, 0, 252, 172, 0, 252, 196, 0, 64, 0, 0, // 236-239
+ 255, 0, 0, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 240-243
+ 255, 0, 255, 148, 148, 148, 247, 0, 247, 248, 0, 248, // 244-247
+ 249, 0, 249, 250, 0, 250, 251, 0, 251, 252, 0, 252, // 248-251
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 255, 255, 255, // 252-255
},
-// PAL_ttw_pb_pal2
- {
- 0, 0,255, 238, 0,238, 239, 0,239, 240, 0,240, // 0-3
- 241, 0,241, 242, 0,242, 243, 0,243, 244, 0,244, // 4-7
- 245, 0,245, 246, 0,246, 168,168,168, 184,184,184, // 8-11
- 200,200,200, 216,216,216, 232,232,232, 252,252,252, // 12-15
- 52, 60, 72, 68, 76, 92, 88, 96,112, 108,116,132, // 16-19
- 132,140,152, 156,160,172, 176,184,196, 204,208,220, // 20-23
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 24-27
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 28-31
- 100,100,100, 116,116,116, 255, 0,255, 255, 0,255, // 32-35
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 36-39
- 132,132,132, 255, 0,255, 255, 0,255, 255, 0,255, // 40-43
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 44-47
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 48-51
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 52-55
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 56-59
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 60-63
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 64-67
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 68-71
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 72-75
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 76-79
- 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
- 64,112, 12, 84,132, 20, 104,148, 28, 128,168, 44, // 84-87
- 64, 64, 64, 255, 0,255, 255, 0,255, 255, 0,255, // 88-91
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 92-95
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 96-99
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 100-103
- 32, 24, 0, 56, 28, 0, 80, 80, 80, 255, 0,255, // 104-107
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 108-111
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 112-115
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 116-119
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 120-123
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 124-127
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 128-131
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 132-135
- 48, 48, 48, 255, 0,255, 255, 0,255, 255, 0,255, // 136-139
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 140-143
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 144-147
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 148-151
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 152-155
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 156-159
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 160-163
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 164-167
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 168-171
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 172-175
- 255, 0,255, 255, 0,255, 60, 0, 0, 92, 0, 0, // 176-179
- 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
- 252, 0, 0, 252, 80, 0, 252,108, 0, 252,136, 0, // 184-187
- 252,164, 0, 252,192, 0, 252,220, 0, 252,252, 0, // 188-191
- 204,136, 8, 228,144, 4, 252,156, 0, 252,176, 48, // 192-195
- 252,196,100, 252,216,152, 8, 24, 88, 12, 36,104, // 196-199
- 20, 52,124, 28, 68,140, 40, 92,164, 56,120,188, // 200-203
- 72,152,216, 100,172,224, 255, 0,255, 255, 0,255, // 204-207
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 208-211
- 255, 0,255, 255, 0,255, 255, 0,255, 16, 16, 16, // 212-215
- 32, 32, 32, 255, 0,255, 255, 0,255, 255, 0,255, // 216-219
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 220-223
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 224-227
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 228-231
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 232-235
- 255, 0,255, 255, 0,255, 255, 0,255, 255, 0,255, // 236-239
- 255, 0, 0, 255, 0,255, 255, 0,255, 255, 0,255, // 240-243
- 255, 0,255, 148,148,148, 247, 0,247, 248, 0,248, // 244-247
- 249, 0,249, 250, 0,250, 251, 0,251, 252, 0,252, // 248-251
- 253, 0,253, 254, 0,254, 255, 0,255, 255, 0,255, // 252-255
- },
- };
+ // PAL_ttw_pb_pal2
+ {0, 0, 255, 238, 0, 238, 239, 0, 239, 240, 0, 240, // 0-3
+ 241, 0, 241, 242, 0, 242, 243, 0, 243, 244, 0, 244, // 4-7
+ 245, 0, 245, 246, 0, 246, 168, 168, 168, 184, 184, 184, // 8-11
+ 200, 200, 200, 216, 216, 216, 232, 232, 232, 252, 252, 252, // 12-15
+ 52, 60, 72, 68, 76, 92, 88, 96, 112, 108, 116, 132, // 16-19
+ 132, 140, 152, 156, 160, 172, 176, 184, 196, 204, 208, 220, // 20-23
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 24-27
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 28-31
+ 100, 100, 100, 116, 116, 116, 255, 0, 255, 255, 0, 255, // 32-35
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 36-39
+ 132, 132, 132, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 40-43
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 44-47
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 48-51
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 52-55
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 56-59
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 60-63
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 64-67
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 68-71
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 72-75
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 76-79
+ 8, 52, 0, 16, 64, 0, 32, 80, 4, 48, 96, 4, // 80-83
+ 64, 112, 12, 84, 132, 20, 104, 148, 28, 128, 168, 44, // 84-87
+ 64, 64, 64, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 88-91
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 92-95
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 96-99
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 100-103
+ 32, 24, 0, 56, 28, 0, 80, 80, 80, 255, 0, 255, // 104-107
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 108-111
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 112-115
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 116-119
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 120-123
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 124-127
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 128-131
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 132-135
+ 48, 48, 48, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 136-139
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 140-143
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 144-147
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 148-151
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 152-155
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 156-159
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 160-163
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 164-167
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 168-171
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 172-175
+ 255, 0, 255, 255, 0, 255, 60, 0, 0, 92, 0, 0, // 176-179
+ 128, 0, 0, 160, 0, 0, 196, 0, 0, 224, 0, 0, // 180-183
+ 252, 0, 0, 252, 80, 0, 252, 108, 0, 252, 136, 0, // 184-187
+ 252, 164, 0, 252, 192, 0, 252, 220, 0, 252, 252, 0, // 188-191
+ 204, 136, 8, 228, 144, 4, 252, 156, 0, 252, 176, 48, // 192-195
+ 252, 196, 100, 252, 216, 152, 8, 24, 88, 12, 36, 104, // 196-199
+ 20, 52, 124, 28, 68, 140, 40, 92, 164, 56, 120, 188, // 200-203
+ 72, 152, 216, 100, 172, 224, 255, 0, 255, 255, 0, 255, // 204-207
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 208-211
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 16, 16, 16, // 212-215
+ 32, 32, 32, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 216-219
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 220-223
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 224-227
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 228-231
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 232-235
+ 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 236-239
+ 255, 0, 0, 255, 0, 255, 255, 0, 255, 255, 0, 255, // 240-243
+ 255, 0, 255, 148, 148, 148, 247, 0, 247, 248, 0, 248, // 244-247
+ 249, 0, 249, 250, 0, 250, 251, 0, 251, 252, 0, 252, // 248-251
+ 253, 0, 253, 254, 0, 254, 255, 0, 255, 255, 0, 255, // 252-255
+ }, };
#endif // DEFINE_PALS
diff --git a/src/typesize.h b/src/typesize.h
--- a/src/typesize.h
+++ b/src/typesize.h
@@ -21,9 +21,9 @@
* *
\*****************************************/
-#define maketype(type,size) \
- typedef signed type S ## size; \
- typedef unsigned type U ## size;
+#define maketype(type, size) \
+ typedef signed type S##size; \
+ typedef unsigned type U##size;
#ifndef _MSC_VER
#define strnicmp strncasecmp
@@ -32,63 +32,63 @@
#ifdef __BORLANDC__
-# define HAVE_BYTES
-# define HAVE_SHORTS
-# define HAVE_LONGS
+#define HAVE_BYTES
+#define HAVE_SHORTS
+#define HAVE_LONGS
- maketype(char,8)
- maketype(short,16)
- maketype(long,32)
+maketype(char, 8)
+maketype(short, 16)
+maketype(long, 32)
// disable warnings for "condition is always false" and "unreachable code"
-#pragma warn -ccc
-#pragma warn -rch
+#pragma warn - ccc
+#pragma warn - rch
#elif WIN32
-# define HAVE_BYTES
-# define HAVE_SHORTS
-# define HAVE_LONGS
-# define HAVE_LONGLONGS
+#define HAVE_BYTES
+#define HAVE_SHORTS
+#define HAVE_LONGS
+#define HAVE_LONGLONGS
- maketype(char,8)
- maketype(short int,16)
- maketype(long int,32)
- maketype(long long,64)
+maketype(char, 8)
+maketype(short int, 16)
+maketype(long int, 32)
+maketype(long long, 64)
#elif GCC32
-# define HAVE_BYTES
-# define HAVE_SHORTS
-# define HAVE_LONGS
-# define HAVE_LONGLONGS
+#define HAVE_BYTES
+#define HAVE_SHORTS
+#define HAVE_LONGS
+#define HAVE_LONGLONGS
- maketype(char,8)
- maketype(short int,16)
- maketype(int,32)
- maketype(long long,64)
+maketype(char, 8)
+maketype(short int, 16)
+maketype(int, 32)
+maketype(long long, 64)
#elif GCC64
-# define HAVE_BYTES
-# define HAVE_SHORTS
-# define HAVE_LONGS
-# define HAVE_LONGLONGS
+#define HAVE_BYTES
+#define HAVE_SHORTS
+#define HAVE_LONGS
+#define HAVE_LONGLONGS
- maketype(char,8)
- maketype(short int,16)
- maketype(int,32)
- maketype(long int,64)
+maketype(char, 8)
+maketype(short int, 16)
+maketype(int, 32)
+maketype(long int, 64)
#else
-# error Unknown variables sizes, please define.
+#error Unknown variables sizes, please define.
#endif
#ifdef _MSC_VER
// disable warnings: conversion from $LARGE_SIZE to $SMALL_SIZE
-#pragma warning(disable:4267 4244)
+#pragma warning(disable : 4267 4244)
// ... conditional expression is constant
-#pragma warning(disable:4127)
+#pragma warning(disable : 4127)
#endif
#undef maketype
@@ -96,72 +96,67 @@
#ifdef DOCHECK
void checksizes()
{
- if (
+ if (
#ifdef HAVE_BYTES
- (sizeof( S8) != 1) ||
- (sizeof( U8) != 1) ||
+ (sizeof(S8) != 1) || (sizeof(U8) != 1) ||
#endif
#ifdef HAVE_SHORTS
- (sizeof(S16) != 2) ||
- (sizeof(U16) != 2) ||
+ (sizeof(S16) != 2) || (sizeof(U16) != 2) ||
#endif
#ifdef HAVE_LONGS
- (sizeof(S32) != 4) ||
- (sizeof(U32) != 4) ||
+ (sizeof(S32) != 4) || (sizeof(U32) != 4) ||
#endif
#ifdef HAVE_LONGLONGS
- (sizeof(S64) != 8) ||
- (sizeof(U64) != 8) ||
+ (sizeof(S64) != 8) || (sizeof(U64) != 8) ||
#endif
- (0) // the ||(0) is so that all previous lines can end in ||
- )
- {
+ (0) // the ||(0) is so that all previous lines can end in ||
+ ) {
printf("Fatal: Incorrectly sized variables.\n");
-#define PRINT_SZ(t,s) printf("%s size = %d, expected = %d\n", #t, (int)sizeof(t), s)
+#define PRINT_SZ(t, s) printf("%s size = %d, expected = %d\n", #t, (int)sizeof(t), s)
#ifdef HAVE_BYTES
- PRINT_SZ(S8,1);
- PRINT_SZ(U8,1);
+ PRINT_SZ(S8, 1);
+ PRINT_SZ(U8, 1);
#endif
#ifdef HAVE_SHORTS
- PRINT_SZ(S16,2);
- PRINT_SZ(U16,2);
+ PRINT_SZ(S16, 2);
+ PRINT_SZ(U16, 2);
#endif
#ifdef HAVE_LONGS
- PRINT_SZ(S32,4);
- PRINT_SZ(U32,4);
+ PRINT_SZ(S32, 4);
+ PRINT_SZ(U32, 4);
#endif
#ifdef HAVE_LONGLONGS
- PRINT_SZ(S64,8);
- PRINT_SZ(U64,8);
+ PRINT_SZ(S64, 8);
+ PRINT_SZ(U64, 8);
#endif
#undef PRINT_SZ
exit(254);
}
-
}
#endif /* DOCHECK */
-union multitype {
+union multitype
+{
U32 u32;
S32 s32;
U16 u16[2];
S16 s16[2];
- U8 u8[4];
- S8 s8[4];
+ U8 u8[4];
+ S8 s8[4];
};
#ifdef GRFCODEC_BIG_ENDIAN
-# define BE_SWAP16(b) (*((U8*)(&b))+(*(((U8*)(&b))+1)<<8))
-# define BE_SWAP32(b) (*((U8*)(&b))+(*(((U8*)(&b))+1)<<8)+(*(((U8*)(&b))+2)<<16)+(*(((U8*)(&b))+3)<<24))
-# define BYTE_OFSL 1
-# define BYTE_OFSH 0
+#define BE_SWAP16(b) (*((U8*)(&b)) + (*(((U8*)(&b)) + 1) << 8))
+#define BE_SWAP32(b) (*((U8*)(&b)) + (*(((U8*)(&b)) + 1) << 8) + (*(((U8*)(&b)) + 2) << 16) + (*(((U8*)(&b)) + 3) << 24))
+#define BYTE_OFSL 1
+#define BYTE_OFSH 0
#elif defined(GRFCODEC_LITTLE_ENDIAN)
-# define BE_SWAP16(b) (b)
-# define BE_SWAP32(b) (b)
-# define BYTE_OFSL 0
-# define BYTE_OFSH 1
+#define BE_SWAP16(b) (b)
+#define BE_SWAP32(b) (b)
+#define BYTE_OFSL 0
+#define BYTE_OFSH 1
#else
-# error "Endianness not defined!"
+#error "Endianness not defined!"
#endif
#endif /* _TYPESIZE_H */
diff --git a/src/utf8.cpp b/src/utf8.cpp
--- a/src/utf8.cpp
+++ b/src/utf8.cpp
@@ -7,97 +7,98 @@
/* Original version at http://xsb.sourceforge.net/api/utf8_8c-source.html */
-#include<cassert>
-#include<cstdlib>
+#include <cassert>
+#include <cstdlib>
-#include"nforenum.h"
-#include"pseudo.h"
-#include"utf8.h"
-#include"messages.h"
-#include"command.h"
-#include"globals.h"
+#include "nforenum.h"
+#include "pseudo.h"
+#include "utf8.h"
+#include "messages.h"
+#include "command.h"
+#include "globals.h"
-#define CONT(i) ((data[off+i]&0xc0) == 0x80)
-#define VAL(i, s) ((data[off+i]&0x3f) << s)
+#define CONT(i) ((data[off + i] & 0xc0) == 0x80)
+#define VAL(i, s) ((data[off + i] & 0x3f) << s)
-uint PseudoSprite::ExtractUtf8(uint& off, bool& valid){
- PseudoSprite& data = *this; // Historical
- valid=false;
- if(data[off]<0xC0||data[off]>0xFC){
- CheckLinkage(off,1);
+uint PseudoSprite::ExtractUtf8(uint& off, bool& valid)
+{
+ PseudoSprite& data = *this; // Historical
+ valid = false;
+ if (data[off] < 0xC0 || data[off] > 0xFC) {
+ CheckLinkage(off, 1);
return data[off++];
}
- valid=true;
- /* 2-byte, 0x80-0x7ff */
- if ( (data[off]&0xe0) == 0xc0 && CONT(1) ){
- uint ret = ((data[off]&0x1f) << 6)|VAL(1,0);
- if(ret<0x80){
- IssueMessage(ERROR,OVERLENGTH_UTF8,off);
- valid=false;
+ valid = true;
+ /* 2-byte, 0x80-0x7ff */
+ if ((data[off] & 0xe0) == 0xc0 && CONT(1)) {
+ uint ret = ((data[off] & 0x1f) << 6) | VAL(1, 0);
+ if (ret < 0x80) {
+ IssueMessage(ERROR, OVERLENGTH_UTF8, off);
+ valid = false;
return data[off++];
}
- data.SetUTF8(off,2);
- CheckLinkage(off,2);
- off+=2;
+ data.SetUTF8(off, 2);
+ CheckLinkage(off, 2);
+ off += 2;
return ret;
- } /* 3-byte, 0x800-0xffff */
- if ( (data[off]&0xf0) == 0xe0 && CONT(1) && CONT(2) ){
- uint ret = ((data[off]&0xf) << 12)|VAL(1,6)|VAL(2,0);
- if(ret<0x800){
- IssueMessage(ERROR,OVERLENGTH_UTF8,off);
- valid=false;
+ } /* 3-byte, 0x800-0xffff */
+ if ((data[off] & 0xf0) == 0xe0 && CONT(1) && CONT(2)) {
+ uint ret = ((data[off] & 0xf) << 12) | VAL(1, 6) | VAL(2, 0);
+ if (ret < 0x800) {
+ IssueMessage(ERROR, OVERLENGTH_UTF8, off);
+ valid = false;
return data[off++];
}
- data.SetUTF8(off,3);
- CheckLinkage(off,3);
- if (ret>0xE07A && ret<0xE100)
- SetEscape(off, true, mysprintf("\\U%x", ret), 3);
- off+=3;
+ data.SetUTF8(off, 3);
+ CheckLinkage(off, 3);
+ if (ret > 0xE07A && ret < 0xE100) SetEscape(off, true, mysprintf("\\U%x", ret), 3);
+ off += 3;
return ret;
- } /* 4-byte, 0x10000-0x1FFFFF */
- if ( (data[off]&0xf8) == 0xf0 && CONT(1) && CONT(2) && CONT(3) ){
- if((((data[off]&0x7) << 18)|VAL(1,12)/*|VAL(2,6)|VAL(3,0)*/)<0x10000){
- IssueMessage(ERROR,OVERLENGTH_UTF8,off);
- valid=false;
+ } /* 4-byte, 0x10000-0x1FFFFF */
+ if ((data[off] & 0xf8) == 0xf0 && CONT(1) && CONT(2) && CONT(3)) {
+ if ((((data[off] & 0x7) << 18) | VAL(1, 12) /*|VAL(2,6)|VAL(3,0)*/) < 0x10000) {
+ IssueMessage(ERROR, OVERLENGTH_UTF8, off);
+ valid = false;
return data[off++];
}
- data.SetUTF8(off,4);
- off+=4;
- return(uint)-4;
- } /* 5-byte, 0x200000-0x3FFFFFF */
- if ( (data[off]&0xfc) == 0xf8 && CONT(1) && CONT(2) && CONT(3) && CONT(4) ){
- if((((data[off]&0x3) << 24)|VAL(1,18)/*|VAL(2,12)|VAL(3,6)|VAL(4,0)*/)<0x200000){
- IssueMessage(ERROR,OVERLENGTH_UTF8,off);
- valid=false;
+ data.SetUTF8(off, 4);
+ off += 4;
+ return (uint) - 4;
+ } /* 5-byte, 0x200000-0x3FFFFFF */
+ if ((data[off] & 0xfc) == 0xf8 && CONT(1) && CONT(2) && CONT(3) && CONT(4)) {
+ if ((((data[off] & 0x3) << 24) | VAL(1, 18) /*|VAL(2,12)|VAL(3,6)|VAL(4,0)*/) < 0x200000) {
+ IssueMessage(ERROR, OVERLENGTH_UTF8, off);
+ valid = false;
return data[off++];
}
- data.SetUTF8(off,5);
- off+=5;
- return(uint)-5;
- } /* 6-byte, 0x4000000-0x7FFFFFFF */
- if ( (data[off]&0xfe) == 0xfc && CONT(1) && CONT(2) && CONT(3) && CONT(4) && CONT(5) ){
- if((((data[off]&0x1) << 30)|VAL(1,24)/*|VAL(2,18)|VAL(3,12)|VAL(4,6)|VAL(5,0)*/)<0x4000000){
- IssueMessage(ERROR,OVERLENGTH_UTF8,off);
- valid=false;
+ data.SetUTF8(off, 5);
+ off += 5;
+ return (uint) - 5;
+ } /* 6-byte, 0x4000000-0x7FFFFFFF */
+ if ((data[off] & 0xfe) == 0xfc && CONT(1) && CONT(2) && CONT(3) && CONT(4) && CONT(5)) {
+ if ((((data[off] & 0x1) << 30) | VAL(1, 24) /*|VAL(2,18)|VAL(3,12)|VAL(4,6)|VAL(5,0)*/) < 0x4000000) {
+ IssueMessage(ERROR, OVERLENGTH_UTF8, off);
+ valid = false;
return data[off++];
}
- data.SetUTF8(off,6);
- off+=6;
- return(uint)-6;
+ data.SetUTF8(off, 6);
+ off += 6;
+ return (uint) - 6;
}
- IssueMessage(WARNING2,INVALID_UTF8,off);
+ IssueMessage(WARNING2, INVALID_UTF8, off);
return data[off++];
}
-#define CHAR(x) (char(((ch>>((x)*6))&0x3F)|0x80))
+#define CHAR(x) (char(((ch >> ((x) * 6)) & 0x3F) | 0x80))
-string GetUtf8Encode(uint ch){
- if(ch<0x80)return string()+char(ch);
- if(ch<0x800)return string()+char(((ch>>6 )&0x1F)|0xC0)+CHAR(0);
- if(ch<0x10000)return string()+char(((ch>>12)&0x0F)|0xE0)+CHAR(1)+CHAR(0);
- if(ch<0x200000)return string()+char(((ch>>18)&0x07)|0xF0)+CHAR(2)+CHAR(1)+CHAR(0);
- if(ch<0x4000000)return string()+char(((ch>>24)&0x03)|0xF8)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0);
- if(ch<0x80000000)return string()+char(((ch>>30)&0x01)|0xFC)+CHAR(4)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0);
- INTERNAL_ERROR(ch,ch);
+string GetUtf8Encode(uint ch)
+{
+ if (ch < 0x80) return string() + char(ch);
+ if (ch < 0x800) return string() + char(((ch >> 6) & 0x1F) | 0xC0) + CHAR(0);
+ if (ch < 0x10000) return string() + char(((ch >> 12) & 0x0F) | 0xE0) + CHAR(1) + CHAR(0);
+ if (ch < 0x200000) return string() + char(((ch >> 18) & 0x07) | 0xF0) + CHAR(2) + CHAR(1) + CHAR(0);
+ if (ch < 0x4000000) return string() + char(((ch >> 24) & 0x03) | 0xF8) + CHAR(3) + CHAR(2) + CHAR(1) + CHAR(0);
+ if (ch < 0x80000000) return string() + char(((ch >> 30) & 0x01) | 0xFC) + CHAR(4) + CHAR(3) + CHAR(2) + CHAR(1) + CHAR(0);
+ INTERNAL_ERROR(ch, ch);
}
diff --git a/src/win32.h b/src/win32.h
--- a/src/win32.h
+++ b/src/win32.h
@@ -25,22 +25,28 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
-#include<windows.h>
-#include<direct.h>
+#include <windows.h>
+#include <direct.h>
#undef ERROR
-#define sleep(x) Sleep(x*1000)
+#define sleep(x) Sleep(x * 1000)
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
// mkdir is deprecated in MSVS 8.0+
-inline int mkdir(const char*x,int){return _mkdir(x);}
+inline int mkdir(const char* x, int)
+{
+ return _mkdir(x);
+}
#else
-inline int mkdir(const char*x,int){return mkdir(x);}
+inline int mkdir(const char* x, int)
+{
+ return mkdir(x);
+}
#endif
-//string GetOpt(char*);
+// string GetOpt(char*);
-#endif//_WIN32
+#endif //_WIN32
-#endif//_RENUM_WIN32_H_INCLUDED_
+#endif //_RENUM_WIN32_H_INCLUDED_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment