diff --git a/src/ExpandingArray.h b/src/ExpandingArray.h index eebecb7..7a8e009 100644 --- a/src/ExpandingArray.h +++ b/src/ExpandingArray.h @@ -31,17 +31,16 @@ #else #include #endif -using namespace std; -templateclass ExpandingArray:public vector<_Ty>{ +templateclass ExpandingArray:public std::vector<_Ty>{ typedef ExpandingArray<_Ty> _MyT; - typedef vector<_Ty> _Mybase; + typedef std::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; - return vector<_Ty>::operator[](x); + return std::vector<_Ty>::operator[](x); } _Ty&operator[](unsigned int x){ if(x>=_MyT::size())_MyT::resize(x+1); @@ -52,27 +51,27 @@ templateclass ExpandingArray:public vector<_Ty>{ _Ty m_fill; }; -templateclass Expanding0Array:public vector<_Ty>{ +templateclass Expanding0Array:public std::vector<_Ty>{ typedef Expanding0Array<_Ty> _MyT; public: _Ty operator[](unsigned int x)const{ if(x>=_MyT::size())return 0; - return vector<_Ty>::operator[](x); + return std::vector<_Ty>::operator[](x); } _Ty&operator[](unsigned int x){ if(x>=_MyT::size())_MyT::resize(x+1,0); - return vector<_Ty>::operator[](x); + return std::vector<_Ty>::operator[](x); } }; -template<>class Expanding0Array:public vector{ +template<>class Expanding0Array:public std::vector{ public: bool operator[](unsigned int x)const{ if(x>=size())return false; - return vector::operator[](x); + return std::vector::operator[](x); } reference operator[](unsigned int x){ if(x>=size())resize(x+1,false); - return vector::operator[](x); + return std::vector::operator[](x); } }; diff --git a/src/IDs.cpp b/src/IDs.cpp index cd76f03..92419b0 100644 --- a/src/IDs.cpp +++ b/src/IDs.cpp @@ -26,7 +26,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"inlines.h" diff --git a/src/act0.cpp b/src/act0.cpp index a3e163a..f8dc6aa 100644 --- a/src/act0.cpp +++ b/src/act0.cpp @@ -31,7 +31,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"inlines.h" @@ -92,12 +91,12 @@ char FD takes the same type of parameter as r, but adds that value to the char FE as above char C0 means to insert a linebreak (as if encountering C1..C4) but without reading any bytes -A backslash is used to escape nulls that are not end-of-string characters +A backslash is used to escape nulls that are not end-of-std::string characters char FF is undef */ -typedef basic_string ustring; -typedef vector int_str; +typedef std::basic_string ustring; +typedef std::vector int_str; class PropData:public auto_array{ public: @@ -111,7 +110,7 @@ class PropData:public auto_array{ uint maxlast(int prop){return (idRange[prop]>>8)&0xFF;} private: ustring length; - vector idRange; + std::vector idRange; void readString(FILE*,bool); int CountFE(); void operator=(const PropData&); @@ -259,7 +258,7 @@ void Init0(){ bool IsTextDefined(uint); -static vector lengthlist; +static std::vector lengthlist; static void FormatSprite(PseudoSprite&str, uint&ofs, const uint format, const uint IDs = 1) { uint feature = str.ExtractByte(1); diff --git a/src/act0.h b/src/act0.h index 90e76c7..f8b106c 100644 --- a/src/act0.h +++ b/src/act0.h @@ -22,6 +22,6 @@ #ifndef _RENUM_PROPERTIES_H_INCLUDED_ #define _RENUM_PROPERTIES_H_INCLUDED_ -void Check0(const string&); +void Check0(const std::string&); #endif diff --git a/src/act123.cpp b/src/act123.cpp index d9d73ad..080e2ad 100644 --- a/src/act123.cpp +++ b/src/act123.cpp @@ -25,7 +25,6 @@ #include #include -using namespace std; #include"inlines.h" #include"ExpandingArray.h" diff --git a/src/act123.h b/src/act123.h index 7fb7f25..a1abbdf 100644 --- a/src/act123.h +++ b/src/act123.h @@ -110,7 +110,7 @@ class varRange{ private: int num; uint width; - vectorranges; + std::vectorranges; void AddRangeInternal(uint min,uint max,RenumMessageId unreachable); }; diff --git a/src/act123_classes.cpp b/src/act123_classes.cpp index ec08ef3..f24ccbd 100644 --- a/src/act123_classes.cpp +++ b/src/act123_classes.cpp @@ -24,7 +24,6 @@ #include #include -using namespace std; #include"inlines.h" #include"ExpandingArray.h" @@ -54,10 +53,10 @@ void act123::init(){ } uint act123::MaxFoundFeat()const{ - const vector&m=defined2IDs._m; + const std::vector&m=defined2IDs._m; short ret=0; for(uint i=0;i<(uint)m.size();i++) - ret=max(ret,m[i].feature); + ret=std::max(ret,m[i].feature); return ret; } @@ -243,7 +242,7 @@ void varRange::UpdateRange(uint Var,uint op,uint shift,const PseudoSprite&data,u } if(shift&0x80){// % var.min=0; - var.max=min(var.max,divmod-1); + var.max=std::min(var.max,divmod-1); add%=divmod; }else{// / var.min/=divmod; @@ -288,12 +287,12 @@ void varRange::UpdateRange(uint Var,uint op,uint shift,const PseudoSprite&data,u break; case 4:// min case 0xB:// & - dflt.min=min(dflt.min,var.min); - dflt.max=min(dflt.max,var.max); + dflt.min=std::min(dflt.min,var.min); + dflt.max=std::min(dflt.max,var.max); break; case 5:// max - dflt.min=max(dflt.min,var.min); - dflt.max=max(dflt.max,var.max); + dflt.min=std::max(dflt.min,var.min); + dflt.max=std::max(dflt.max,var.max); /* FALLTHROUGH */ case 8:// / if(var.min==0){ diff --git a/src/act14.cpp b/src/act14.cpp index 2c596c3..96530d7 100644 --- a/src/act14.cpp +++ b/src/act14.cpp @@ -23,7 +23,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"pseudo.h" @@ -31,13 +30,13 @@ using namespace std; #include"strings.h" #include"command.h" -static bool Check14(PseudoSprite&data, uint&offset, vector&idstack) +static bool Check14(PseudoSprite&data, uint&offset, std::vector&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 std::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) @@ -94,7 +93,7 @@ static bool Check14(PseudoSprite&data, uint&offset, vector&idstack) void Check14(PseudoSprite&data) { - vectoridstack; + std::vectoridstack; uint offset = 1; Check14(data, offset, idstack); } diff --git a/src/act5.cpp b/src/act5.cpp index 965ac43..75e284e 100644 --- a/src/act5.cpp +++ b/src/act5.cpp @@ -24,7 +24,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"sanity.h" @@ -41,15 +40,15 @@ extern bool _base_grf; class c5{ public: int maxFeature(){return (int)sizes.size()+3;} - const vector&operator[](int x)const {return sizes[x-4];} + const std::vector&operator[](int x)const {return sizes[x-4];} SINGLETON(c5) private: - vector >sizes; + std::vector >sizes; }; c5::c5(){ FILE*pFile=myfopen(5); - vector temp; + std::vector temp; int ch, count, opts, flags; while((ch=GetCheckByte(5))!=0){ flags = 0; @@ -72,9 +71,9 @@ c5::c5(){ } // 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&sizes){ - string str = mysprintf("%S",ACT5_SIZE, sizes[1], sizes[1]); +// But I can't, so I have to manually generate the std::string instead. +void Act5CountWarn(const std::vector&sizes){ + std::string str = mysprintf("%S",ACT5_SIZE, sizes[1], sizes[1]); int count=(int)sizes.size()-1; switch(count){ case 1: @@ -101,7 +100,7 @@ int Check5(PseudoSprite&data,sanstate&state){ IssueMessage(FATAL,INVALID_FEATURE); return sprites; } - const vector&expSprites=c5::Instance()[feature]; + const std::vector&expSprites=c5::Instance()[feature]; if(!hasoffset){ for(int i=(int)expSprites.size();--i;){ // Test [1] ... [.size()-1] if(expSprites[i] == 0)goto countok; diff --git a/src/act6.cpp b/src/act6.cpp index 362714c..62323a9 100644 --- a/src/act6.cpp +++ b/src/act6.cpp @@ -23,7 +23,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"inlines.h" diff --git a/src/act79D.cpp b/src/act79D.cpp index 3555e6d..b214c64 100644 --- a/src/act79D.cpp +++ b/src/act79D.cpp @@ -24,7 +24,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"inlines.h" @@ -87,7 +86,7 @@ struct act7{ uint act,spriteno,skips; }; -static vectorjumps; +static std::vectorjumps; int Check7(PseudoSprite&data){ uint desiredSize=data.Length()-5; diff --git a/src/actB.cpp b/src/actB.cpp index ba53fdb..d5b659a 100644 --- a/src/actB.cpp +++ b/src/actB.cpp @@ -22,7 +22,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"inlines.h" diff --git a/src/actF.cpp b/src/actF.cpp index 3207fa5..8b35731 100644 --- a/src/actF.cpp +++ b/src/actF.cpp @@ -23,7 +23,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"inlines.h" @@ -111,7 +110,7 @@ void CheckF(PseudoSprite&data){ 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; + std::ostringstream s; int first=-1,bits=bitsused&BITS(firstbit,numbits); for(int j=0;j<32;j++){ if(bits&(1< #include -using namespace std; #include"globals.h" #include"nforenum.h" @@ -88,7 +87,7 @@ struct command{ Expanding0Arraywarnstate; }_commandState,_CLstate; -static map_varmap,_CLvar; +static std::map_varmap,_CLvar; const command&crCommandState=_commandState; @@ -101,23 +100,23 @@ command::command(){ // verbose=0; } -int find_command(const string&command,const commandData type[]){ +int find_command(const std::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 std::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]=='@'; + std::string::size_type x=line.find_first_not_of(COMMENT+WHITESPACE); + return x!=std::string::npos&&x<(line.length()-1)&&line[x]=='@'&&line[x+1]=='@'; } -bool is_message(const string&line){ +bool is_message(const std::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]=='!'; + std::string::size_type x=line.find_first_not_of(COMMENT+WHITESPACE); + return x!=std::string::npos&&x<(line.length()-1)&&line[x]=='!'&&line[x+1]=='!'; } void reset_commands(){ @@ -125,7 +124,7 @@ void reset_commands(){ _varmap=_CLvar; } -string GetOnOffString(string str){ +std::string GetOnOffString(std::string str){ if(str[str.length()-1]=='+'){ str[str.length()-1]=' '; str+="ON"; @@ -141,21 +140,21 @@ bool CLCommand(int command){ _commandState.locked=false; switch(command){ case'd':parse_comment("//@@DIFF");break; - case'L':parse_comment("//@@LET "+string(optarg));break; + case'L':parse_comment("//@@LET "+std::string(optarg));break; case'l':parse_comment("//@@LINT "+GetOnOffString(optarg));break; - case'r':parse_comment("//@@REALSPRITES "+string(optarg));break; + case'r':parse_comment("//@@REALSPRITES "+std::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); + std::string s(optarg); if (s.find_first_not_of("0123456789,") != NPOS) return false; - string::size_type loc; + std::string::size_type loc; while ( (loc=s.find_first_of(',')) != NPOS) s[loc]='+'; - istringstream arg(s); + std::istringstream arg(s); uint opt; while(arg>>opt){ parse_comment((command=='w'?"//@@WARNING DISABLE ":"//@@WARNING ENABLE ")+itoa(opt)); @@ -170,18 +169,18 @@ bool CLCommand(int command){ return true; } -void SetVar(const string&,const string&); -string ReadVar(istream&); +void SetVar(const std::string&,const std::string&); +std::string ReadVar(std::istream&); -bool parse_comment(const string&line){ +bool parse_comment(const std::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; + std::string command=line.c_str()+line.find_first_not_of(COMMENT+WHITESPACE+'@'),command_part; while(command.find('=')!=NPOS)command[command.find('=')]=' '; - istringstream commandstream(command); + std::istringstream commandstream(command); commandstream>>command_part; int id; switch(find_command(command_part,gen)){ @@ -202,7 +201,7 @@ bool parse_comment(const string&line){ return true; case USEID2:{ int feature; - commandstream>>setbase(16)>>feature>>id; + commandstream>>std::setbase(16)>>feature>>id; if(!commandstream) id=feature; else if(!IsValid2Feature(feature)){ @@ -215,7 +214,7 @@ bool parse_comment(const string&line){ sanity_use_id(id); return true; }case USESET: - commandstream>>setbase(16)>>id; + commandstream>>std::setbase(16)>>id; sanity_use_set(id); return true; case DIFF: @@ -280,7 +279,7 @@ bool parse_comment(const string&line){ //if(GetState(REMOVEMESSAGES))inject("//@@REMOVEMESSAGES NOPRESERVE"); return false; }case LET:{ - string var=ReadVar(commandstream); + std::string var=ReadVar(commandstream); if(var=="")return true; if(eat_white(commandstream).peek()=='=')commandstream.ignore(); getline(eat_white(commandstream),command_part); @@ -395,7 +394,7 @@ bool parse_comment(const string&line){ break; case TESTID2:{ int feature; - commandstream>>setbase(16)>>feature>>id; + commandstream>>std::setbase(16)>>feature>>id; if(!commandstream) id=feature; else if(!IsValid2Feature(feature)){ @@ -409,7 +408,7 @@ bool parse_comment(const string&line){ return true; }case DEFINEID2:{ int feature; - commandstream>>setbase(16)>>feature>>id; + commandstream>>std::setbase(16)>>feature>>id; if(!commandstream) id=feature; else if(!IsValid2Feature(feature)){ @@ -420,7 +419,7 @@ bool parse_comment(const string&line){ return true; }case LOCATEID2:{ int feature; - commandstream>>setbase(16)>>feature>>id; + commandstream>>std::setbase(16)>>feature>>id; if(!commandstream) id=feature; else if(!IsValid2Feature(feature)){ @@ -521,9 +520,9 @@ bool GetWarn(int message,int minSan){ return GetState(LINT)>=minSan; } -void SetVar(const string&var,const string&value){ +void SetVar(const std::string&var,const std::string&value){ int val; - string::size_type offs; + std::string::size_type offs; if((offs=value.find('('))==NPOS){ const char*pch=value.c_str(); while(isspace(*pch))pch++; @@ -535,42 +534,42 @@ void SetVar(const string&var,const string&value){ _varmap[var] = val; } -int GetVar(const string&var,int&err){ - map::const_iterator it; +int GetVar(const std::string&var,int&err){ + std::map::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){ +std::string ReadVar(std::istream&in){ eat_white(in); int ch; - string delim="=()+/-*",var; + std::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){ +int ReadNum(std::istream&in){ if (in.get()=='0') { - if (in.get()=='x') in>>setbase(16); + if (in.get()=='x') in>>std::setbase(16); else{ - in.unget()>>setbase(8); + in.unget()>>std::setbase(8); if (!isdigit(in.peek())) return 0; } - } else in.unget()>>setbase(10); + } else in.unget()>>std::setbase(10); int ret; in>>ret; return ret; } -int DoCalc(istream&data,int&err){ - stacknums; +int DoCalc(std::istream&data,int&err){ + std::stacknums; // the unary and binary op charcters. - string unyops="-~)", + std::string unyops="-~)", binops="+-*/%|&^<>"; int ch,l; while(true){ @@ -646,22 +645,22 @@ int DoCalc(istream&data,int&err){ return 0; }else{ data.unget(); // And now, restore first character of the var name. - string var=ReadVar(data); + std::string var=ReadVar(data); nums.push(GetVar(var,err)); if(err)return 0; } } } -int DoCalc(const string&data,string::size_type&offs){ - istringstream in(data); +int DoCalc(const std::string&data,std::string::size_type&offs){ + std::istringstream in(data); 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){ +/*int DoCalc(std::istringstream&data,int&err){ char ch=eat_white(data).peek(); int l,r,op; if(isdigit(ch))data>>l; @@ -669,14 +668,14 @@ int DoCalc(const string&data,string::size_type&offs){ l=DoCalc(data.ignore(),err); if(err)return l; }else{ - string var; + std::string var; data>>var; l=GetVar(var,err); if(err)return l; } eat_white(data).get(ch); if(ch==')')return l; - string ops="+-*" "/"; + std::string ops="+-*" "/"; int op=(int)ops.find(ch); if(op==NPOS){ err=NOT_OP; @@ -687,7 +686,7 @@ int DoCalc(const string&data,string::size_type&offs){ r=DoCalc(data.ignore(),err); if(err)return r; }else{ - string var; + std::string var; data>>var; r=GetVar(var,err); if(err)return r; @@ -700,7 +699,7 @@ int DoCalc(const string&data,string::size_type&offs){ DEFAULT(DoCalc,op); } } -int DoCalc(const string&data,size_t&offs){ +int DoCalc(const std::string&data,size_t&offs){ char ch; int l=0,r=0,op=0; while(true){ diff --git a/src/command.h b/src/command.h index 4387e26..4aa7a12 100644 --- a/src/command.h +++ b/src/command.h @@ -121,11 +121,11 @@ COMMAND_DATA_END() int GetState(enum gen); uint GetState(enum beaut,int =0); bool GetWarn(int,int); -bool is_command(const string&); -bool parse_comment(const string&); +bool is_command(const std::string&); +bool parse_comment(const std::string&); void reset_commands(); -int DoCalc(const string&,size_t&); -int DoCalc(istream&,int&); +int DoCalc(const std::string&,size_t&); +int DoCalc(std::istream&,int&); bool CLCommand(int); #endif//_RENUM_COMMAND_H_FUNCTIONS_INCLUDED_ diff --git a/src/data.cpp b/src/data.cpp index ab331a8..1abdd6a 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -34,7 +34,6 @@ # include #endif -using namespace std; #include"nforenum.h" #include"inlines.h" @@ -208,9 +207,9 @@ static const char _datTextIDs[]="\x04\x09" "\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: +// Number of special std::string ID ranges: "\x03" -// High bytes of special string IDs: +// High bytes of special std::string IDs: "\xC4\xC5\xC9" ; @@ -460,7 +459,7 @@ NDF_END #define DWORD 0x04 /* Formatting */ -#define QUOTED 0x10 /* Quoted string */ +#define QUOTED 0x10 /* Quoted std::string */ #define DECIMAL 0x20 /* Escaped decimal */ #define HEX 0x30 /* Escaped hex */ @@ -1155,7 +1154,7 @@ struct dat{ #include "data.h" -bool makedir(const string&dir,bool dieonfail=false){ +bool makedir(const std::string&dir,bool dieonfail=false){ if(dir==""){ if(dieonfail)exit(EDATA); return false; @@ -1173,7 +1172,7 @@ bool makedir(const string&dir,bool dieonfail=false){ } } -bool finddir(string&dir){ +bool finddir(std::string&dir){ if(dir=="")return false; struct stat Stat; if(dir[dir.length()-1]=='\\'||dir[dir.length()-1]=='/') @@ -1183,9 +1182,9 @@ bool finddir(string&dir){ return true; } -static string getdir(bool allow_mkdir){ - string *pret; - string cwd,home,homedrpath; +static std::string getdir(bool allow_mkdir){ + std::string *pret; + std::string cwd,home,homedrpath; if(datadir!=""){ verify(finddir(datadir)||makedir(datadir,true)); pret=&datadir; @@ -1216,7 +1215,7 @@ static string getdir(bool allow_mkdir){ } FILE*tryopen(const char*name,const char*mode,bool allownull=false){ - string dir = getdir(mode[0] == 'w'); + std::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); diff --git a/src/globals.cpp b/src/globals.cpp index 9a32d0a..09c8abe 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -22,15 +22,14 @@ #include #include -using namespace std; #include "globals.h" -ostream*pNfo=&cout,*pOut,*pErr=&cerr; +std::ostream*pNfo=&std::cout,*pOut,*pErr=&std::cerr; const char*const VALID_PSEUDO="0123456789ABCDEFabcdef \t\v\r\n",*const WHITESPACE=" \t\v\r\n"; -const string COMMENT="/;#"; -string datadir; +const std::string COMMENT="/;#"; +std::string datadir; const char*COMMENT_PREFIX="//"; bool dosleep=true; unsigned int _spritenum,_grfver,_autocorrect=0,_act14_pal; diff --git a/src/grfcodec.cpp b/src/grfcodec.cpp index 22f82bc..dd05b6a 100644 --- a/src/grfcodec.cpp +++ b/src/grfcodec.cpp @@ -970,10 +970,10 @@ int main(int argc, char **argv) printf("%s\n", version); return 0; case 'w': - width = min(max(atoi(optarg), 16), 65535); + width = std::min(std::max(atoi(optarg), 16), 65535); break; case 'h': - height = min(max(atoi(optarg), 16), 65535); + height = std::min(std::max(atoi(optarg), 16), 65535); break; case 'b': box = atoi(optarg); diff --git a/src/help.cpp b/src/help.cpp index cbc8df0..284b3cd 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -26,13 +26,12 @@ #include "language_mgr.h" #include "help.h" -using namespace std; // -------- // Generate a ShowHelp function for each supported language. #define START_HELP_TEXT(lang) void ShowHelp_##lang(){ \ - cout << "" + std::cout << "" #define END_HELP_TEXT() ; } #include "lang/all_help.h" diff --git a/src/info.cpp b/src/info.cpp index f370a01..62bf50b 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -24,16 +24,16 @@ int makeint(U8 low, S8 high) return combined; } -void read_file(istream&in,int infover,int grfcontversion,AllocArray&sprites); +void read_file(std::istream&in,int infover,int grfcontversion,AllocArray&sprites); nfe_map nfo_escapes; inforeader::inforeader(char *fn, int grfcontversion) { - ifstream f; + std::ifstream f; f.open(fn); - string buffer; + std::string buffer; int infover; imgfile = NULL; @@ -58,8 +58,8 @@ inforeader::inforeader(char *fn, int grfcontversion) if (infover > 6) { while (strncmp(buffer.c_str(), "// Format: ", 11)) { if (!strncmp(buffer.c_str(), "// Escapes: ", 12)) { // Nope. That was an escapes line. - istringstream esc(buffer); - string str; + std::istringstream esc(buffer); + std::string str; int byte = 0; esc.ignore(12); while (esc>>str){ diff --git a/src/info.h b/src/info.h index 84be115..bf9cd4d 100644 --- a/src/info.h +++ b/src/info.h @@ -30,7 +30,7 @@ class inforeader { protected: - string imgname; + std::string imgname; int *colourmap; AllocArray nfofile; private: diff --git a/src/inject.cpp b/src/inject.cpp index 90268c7..c592e91 100644 --- a/src/inject.cpp +++ b/src/inject.cpp @@ -24,15 +24,14 @@ #include #include -using namespace std; #include"globals.h" #include"inject.h" -static queue_injected; -static const istream*_into; +static std::queue_injected; +static const std::istream*_into; -istream&inj_getline(istream&in,string&str){ +std::istream&inj_getline(std::istream&in,std::string&str){ assert(&in==_into); if(_injected.size()){ str=_injected.front(); @@ -42,18 +41,18 @@ istream&inj_getline(istream&in,string&str){ return getline(in,str); } -int peek(istream&in){ +int peek(std::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)<=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(std::istream&in,uint digits){ uint ret; while(isspace(in.peek()))in.ignore(); char ch; in.get(ch); if((ret=ctoi(ch))==0&&ch!='0'){ - in.unget().clear(ios::badbit); + in.unget().clear(std::ios::badbit); return ret; } for(;--digits;){ diff --git a/src/language_mgr.cpp b/src/language_mgr.cpp index 36878c7..fa8a873 100644 --- a/src/language_mgr.cpp +++ b/src/language_mgr.cpp @@ -23,7 +23,6 @@ #include "language_mgr.h" -using namespace std; #include "inlines.h" @@ -33,11 +32,11 @@ LanguageMgr::LanguageMgr() { } RenumLanguageId LanguageMgr::DetectLanguage() const { - string langCode = safetostring(getenv("LANG")); + std::string langCode = safetostring(getenv("LANG")); return DecodeLanguageCode(langCode); } -RenumLanguageId LanguageMgr::DecodeLanguageCode(const string& code) const { +RenumLanguageId LanguageMgr::DecodeLanguageCode(const std::string& code) const { str2lang_map::const_iterator pos = codeIdMap.find(code); if(pos != codeIdMap.end()) return pos->second; @@ -52,6 +51,6 @@ RenumLanguageId LanguageMgr::DecodeLanguageCode(const string& code) const { #undef END_LANGUAGES #define START_LANGUAGES() void LanguageMgr::InitLanguageMap() { #define RENUM_LANGUAGE(name,code) \ - codeIdMap.insert(make_pair(code,name)); + codeIdMap.insert(std::make_pair(code,name)); #define END_LANGUAGES() } #include "lang/language_list.h" diff --git a/src/mapescapes.cpp b/src/mapescapes.cpp index 4b7e32d..8844344 100644 --- a/src/mapescapes.cpp +++ b/src/mapescapes.cpp @@ -21,14 +21,13 @@ #include -using namespace std; #include "nforenum.h" #include "inlines.h" #include "messages.h" #include "mapescapes.h" -string FindEscape(char action, int byte) { +std::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) @@ -37,15 +36,15 @@ string FindEscape(char action, int byte) { // Look for a built-in escape foreach(const esc& e, escapes) if (e.action==ctoi(action) && e.byte==byte) - return ' ' + string(e.str); + return ' ' + std::string(e.str); return ""; } -string FindEscape(char action, int byte, uint offset) { +std::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); + return ' ' + std::string(e.str); // Look for a custom escape foreach(const nfe_rpair& p, nfo_escapes.right.equal_range(byte)) if (p.second[0] == action) @@ -53,7 +52,7 @@ string FindEscape(char action, int byte, uint offset) { return ""; } -int FindEscape(string str) { +int FindEscape(std::string str) { foreach(esc e, escapes) if(str == e.str+1) return e.byte; diff --git a/src/mapescapes.h b/src/mapescapes.h index b40290a..f5a36cd 100644 --- a/src/mapescapes.h +++ b/src/mapescapes.h @@ -33,7 +33,7 @@ using namespace boost::bimaps; typedef unsigned char U8; #include "escapes.h" -typedef bimap > nfe_map; +typedef bimap > nfe_map; typedef nfe_map::value_type nfe_pair; typedef nfe_map::left_value_type nfe_lpair; typedef nfe_map::right_value_type nfe_rpair; diff --git a/src/message_mgr.cpp b/src/message_mgr.cpp index 3bc9c86..3e37072 100644 --- a/src/message_mgr.cpp +++ b/src/message_mgr.cpp @@ -27,28 +27,27 @@ #include "globals.h" #include "message_mgr.h" -using namespace std; -const string MessageData::commentPrefix = "!!"; +const std::string MessageData::commentPrefix = "!!"; MessageData::MessageData(char props_) : textMap() { props = props_; } -MessageData::MessageData(char props_, const string& default_text) : textMap() { +MessageData::MessageData(char props_, const std::string& default_text) : textMap() { props = props_; SetText(RL_DEFAULT, default_text); } -string MessageData::Display(const string& prefix, va_list& ap) const { - string ret = myvsprintf(GetMessage(prefix).c_str(), ap); - ostream* const stream[] = {pErr, pOut, pNfo}; +std::string MessageData::Display(const std::string& prefix, va_list& ap) const { + std::string ret = myvsprintf(GetMessage(prefix).c_str(), ap); + std::ostream* const stream[] = {pErr, pOut, pNfo}; if((props & TO_MASK) != TO_NULL) (*(stream[(props & TO_MASK) >> TO_SHIFT])) << ret; return ret; } -const string& MessageData::GetText() const { +const std::string& MessageData::GetText() const { lang2str_map::const_iterator pos = textMap.find( LanguageMgr::Instance().GetCurrentLanguage()); if(pos == textMap.end()) { @@ -60,12 +59,12 @@ const string& MessageData::GetText() const { return pos->second; } -void MessageData::SetText(RenumLanguageId lang, const string& text) { +void MessageData::SetText(RenumLanguageId lang, const std::string& text) { textMap[lang] = text; } -string MessageData::GetMessage(const string& prefix) const { - string ret = GetText(); +std::string MessageData::GetMessage(const std::string& prefix) const { + std::string ret = GetText(); if(props & HAS_OFFSET) ret = MessageMgr::Instance().GetExtraText(OFFSET) + ret; if(props & USE_PREFIX) @@ -77,7 +76,7 @@ string MessageData::GetMessage(const string& prefix) const { // -------- -const string MessageMgr::UNDEFINED_TEXT = "UNDEFINED_TEXT"; +const std::string MessageMgr::UNDEFINED_TEXT = "UNDEFINED_TEXT"; const MessageData MessageMgr::UNKNOWN_MESSAGE = MessageData(0,"UNKNOWN_MESSAGE"); MessageMgr::MessageMgr() { @@ -112,7 +111,7 @@ const std::string& MessageMgr::GetExtraText(RenumExtraTextId i) const { } bool MessageMgr::AddMessage(RenumMessageId i, char props) { - return msgDataMap.insert(make_pair(i, MessageData(props))).second; + return msgDataMap.insert(std::make_pair(i, MessageData(props))).second; } bool MessageMgr::SetMessageText(RenumMessageId i, RenumLanguageId lang, const std::string& text) { @@ -127,9 +126,9 @@ bool MessageMgr::SetMessageText(RenumMessageId i, RenumLanguageId lang, const st 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; + pos = extraTextMap.insert(std::make_pair(i,lang2str_map())).first; } - pos->second.insert(make_pair(lang, text)); + pos->second.insert(std::make_pair(lang, text)); } // ------- diff --git a/src/messages.cpp b/src/messages.cpp index 5e7fc7d..f581756 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -26,7 +26,6 @@ #include //#include -using namespace std; // The prefered method for generating version.h for Visual Studio is to // install Cygwin and use the command "make version.h". @@ -59,10 +58,10 @@ void ManualConsoleMessages(){ bAutoMessage=false; } -string mysprintf(const char*str,...){ +std::string mysprintf(const char*str,...){ va_list ap; va_start(ap, str); - string result = myvsprintf(str,ap); + std::string result = myvsprintf(str,ap); va_end(ap); return result; } @@ -71,16 +70,16 @@ string mysprintf(const char*str,...){ static RenumMessageId curMessage; #endif -string internal::IssueMessage(int minSan,...){ +std::string internal::IssueMessage(int minSan,...){ va_list ap; va_start(ap, minSan); RenumMessageId id = (RenumMessageId)va_arg(ap, int); - string result = vIssueMessage(minSan,id,ap); + std::string result = vIssueMessage(minSan,id,ap); va_end(ap); return result; } -string vIssueMessage(int minSan,RenumMessageId id,va_list& arg_ptr){ +std::string vIssueMessage(int minSan,RenumMessageId id,va_list& arg_ptr){ #if defined DEBUG || defined _DEBUG curMessage=id; #endif @@ -116,14 +115,14 @@ string vIssueMessage(int minSan,RenumMessageId id,va_list& arg_ptr){ return MessageMgr::Instance().GetMessageData(id).Display( mysprintf(MessageMgr::Instance().GetExtraText(prefix).c_str(),id),arg_ptr); }catch(...){ - (*pErr)< #include #include #include @@ -47,7 +48,6 @@ #include #endif//_MSC_VER -using namespace std; #include"getopt.h" #include"globals.h" @@ -94,21 +94,21 @@ struct RealSpriteState { } }; -int process_file(istream&); -void output_buffer(const string&,bool,int); -bool verify_real(string&,RealSpriteState&); +int process_file(std::istream&); +void output_buffer(const std::string&,bool,int); +bool verify_real(std::string&,RealSpriteState&); static int _retval=EOK; static int _force=0; bool _interactive; -void SetCode(int x){_retval=max(_retval,x);} +void SetCode(int x){_retval=std::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; + std::string infilename,outfilename,bakfilename,basename; int result,longind,opt=0,replace=1; static const option optlist[]={ /* Command-line only options */ @@ -139,9 +139,9 @@ int __cdecl main(const int argc,char**argv){ }; _interactive = (isatty(fileno(stdout)) != 0); bool seen_startup_message = false; - pOut=argc==1?&cerr:&cout; - ifstream fin; - ofstream fout; + pOut=argc==1?&std::cerr:&std::cout; + std::ifstream fin; + std::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){ @@ -266,9 +266,9 @@ int __cdecl main(const int argc,char**argv){ } if (_interactive) IssueMessage(0,PROCESSING_COMPLETE); } - pNfo=&cout; + pNfo=&std::cout; IssueMessage(0,PROCESSING); - process_file(cin); + process_file(std::cin); IssueMessage(0,PROCESSING_COMPLETE); return _retval; } @@ -284,7 +284,7 @@ int __cdecl main(const int argc,char**argv){ (void(0)) #define SetVersion(x)\ - (NFOversion=max((x),NFOversion)) + (NFOversion=std::max((x),NFOversion)) static bool hasHeader; int NFOversion; @@ -296,16 +296,16 @@ bool TrySetVersion(int x){ return true; } -string smash(const string&,int&); +std::string smash(const std::string&,int&); -int process_file(istream&in){ +int process_file(std::istream&in){ NFOversion=4; - string sprite,datapart,buffer; + std::string sprite,datapart,buffer; inject_into(in); nfo_escapes.clear(); - vector extra_lines; + std::vector extra_lines; - if(string(" \t\n*0123456789/;#*").find((char)in.peek())==NPOS){ + if(std::string(" \t\n*0123456789/;#*").find((char)in.peek())==NPOS){ IssueMessage(0,APPARENTLY_NOT_NFO); if(!_force){ IssueMessage(0,SKIPPING_FILE); @@ -337,8 +337,8 @@ int process_file(istream&in){ 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. - istringstream esc(sprite); - string str; + std::istringstream esc(sprite); + std::string str; int byte = 0; esc.ignore(12); while (esc>>str) @@ -371,16 +371,16 @@ int process_file(istream&in){ int temp=-1,size,oldspritenum=-1; _spritenum=(unsigned)-1; RealSpriteState realsprite_state; - string::size_type firstnotpseudo; + std::string::size_type firstnotpseudo; bool isPatch=false; - ostringstream outbuffer; - ostream*real_out=pNfo; + std::ostringstream outbuffer; + std::ostream*real_out=pNfo; pNfo=&outbuffer; SetVersion(4); AutoConsoleMessages(); while(true){ //IssueMessage(0,SPRITE,spritenum+1,sprite.c_str()); - istringstream spritestream(sprite); + std::istringstream spritestream(sprite); eat_white(spritestream); if(spritestream.peek()==EOF) { buffer+='\n'; @@ -408,7 +408,7 @@ int process_file(istream&in){ IssueMessage(ERROR,UNEXPECTED,BIN_INCLUDE); } _spritenum++; - (*pNfo)<>size).clear(); eat_white(spritestream); @@ -416,7 +416,7 @@ int process_file(istream&in){ if(_spritenum==(uint)-1){ isPatch=true; if(size!=4 && size!=0) - outbuffer<=32){ - string depth; + std::string depth; int xpos, ypos, xsize, ysize, xrel, yrel, zoom; - string meta=data.substr(loc+5); - string processed; + std::string meta=data.substr(loc+5); + std::string processed; bool anyprocessing = false; if (extract_string(meta,depth,processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"depth"); return COMMENTOFF(); } if (depth=="mask"){ @@ -633,14 +633,14 @@ bool verify_real(string&data,RealSpriteState&formats){ if(xpos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,XPOS,0); if(ypos<0)IssueMessage(ERROR,REAL_VAL_TOO_SMALL,YPOS,0); - string flag; + std::string flag; 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"; - string zoom_str; + std::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(); } @@ -669,7 +669,7 @@ bool verify_real(string&data,RealSpriteState&formats){ else if (zoom_str=="zo8") zoom = 5; else { IssueMessage(0,REAL_MISSING_DATA,"zoom"); return COMMENTOFF(); } - string flag; + std::string flag; bool chunked = false, nocrop=false; while (!extract_string(meta,flag,processed,anyprocessing)) { if (!chunked&&flag=="chunked") chunked = true; @@ -692,8 +692,8 @@ bool verify_real(string&data,RealSpriteState&formats){ return true; }else{ int xpos, ypos, comp, ysize, xsize, xrel, yrel; - string meta=data.substr(loc+5); - string processed; + std::string meta=data.substr(loc+5); + std::string processed; bool anyprocessing = false; if (extract_int(meta,xpos, processed,anyprocessing)) { IssueMessage(0,REAL_MISSING_DATA,"xpos"); return COMMENTOFF(); } @@ -722,7 +722,7 @@ bool verify_real(string&data,RealSpriteState&formats){ } } -void output_buffer(const string&sprite,bool isPatch,int spriteno){ +void output_buffer(const std::string&sprite,bool isPatch,int spriteno){ PseudoSprite data(sprite,spriteno); if(data.IsValid()){ _spritenum++; diff --git a/src/nfosprite.h b/src/nfosprite.h index aac2ef3..44799db 100644 --- a/src/nfosprite.h +++ b/src/nfosprite.h @@ -40,25 +40,25 @@ class Sprite{ virtual SpriteType GetType()const =0; class unparseable{//thrown by the constructors public: - unparseable(string reason,size_t sprite); - string reason; + unparseable(std::string reason,size_t sprite); + std::string reason; }; }; class Real:public Sprite{ public: - void AddSprite(size_t,int,const string&); + void AddSprite(size_t,int,const std::string&); Sprite::SpriteType GetType()const{return ST_REAL;} - vector infs; + std::vector infs; private: - ostream&output(ostream&)const; - static string prevname; + std::ostream&output(std::ostream&)const; + static std::string prevname; static int prevy; }; class Pseudo:public Sprite{ public: - Pseudo(size_t,int,int,const string&,int); + Pseudo(size_t,int,int,const std::string&,int); U8 operator[](int offs)const{return packed[offs];} uint size()const; @@ -67,22 +67,22 @@ class Pseudo:public Sprite{ const char*GetData()const{return packed.c_str();} //static bool CanQuote(uint); - static bool MayBeSprite(const string&); + static bool MayBeSprite(const std::string&); enum width {_B_, _BX_, _W_, _D_}; - static uint ReadValue(istream&, width); + static uint ReadValue(std::istream&, width); private: - string packed; + std::string packed; }; class Include:public Sprite{ public: - Include(const string&); + Include(const std::string&); Sprite::SpriteType GetType()const{return ST_INCLUDE;} const char *GetName()const{return name.c_str();} private: - string name; + std::string name; }; #endif /* _NFOSPRITE_H */ diff --git a/src/pseudo.cpp b/src/pseudo.cpp index ae75fc6..1ab46e7 100644 --- a/src/pseudo.cpp +++ b/src/pseudo.cpp @@ -36,7 +36,6 @@ using namespace boost::gregorian; #define foreach BOOST_FOREACH -using namespace std; #include"nforenum.h" #include"pseudo.h" @@ -65,22 +64,22 @@ enum{HEX,TEXT,UTF8,ENDQUOTE,QESC,QEXT,NQEXT,NOBREAK=0x80}; white="";\ }else ((void)0) -int FindEscape(string str); -string FindEscape(char, int); -string FindEscape(char, int, uint); +int FindEscape(std::string str); +std::string FindEscape(char, int); +std::string FindEscape(char, int, uint); -PseudoSprite::PseudoSprite(const string&sprite,int oldspritenum): +PseudoSprite::PseudoSprite(const std::string&sprite,int oldspritenum): orig(sprite), valid(true), useorig(false), oldspritenum(oldspritenum), extract_offs(0) { - istringstream in(sprite); - ostringstream out; + std::istringstream in(sprite); + std::ostringstream out; char ch; bool newline=true; - string white; + std::string white; while(in){ switch(in.peek()){ case EOF:continue; @@ -181,7 +180,7 @@ PseudoSprite::PseudoSprite(const string&sprite,int oldspritenum): continue; default:{ in.unget(); - string esc; + std::string esc; in>>esc; int byte = FindEscape(esc); if(byte == -1) @@ -199,7 +198,7 @@ PseudoSprite::PseudoSprite(const string&sprite,int oldspritenum): /* FALLTHROUGH */ default: if (is_comment(in)) { - string comment; + std::string comment; getline(in,comment); comment=white+comment; white=""; @@ -260,8 +259,8 @@ void PseudoSprite::CheckLinkage(int ofs, int count)const{ } } -bool PseudoSprite::MayBeSprite(const string&sprite){ - istringstream in(sprite); +bool PseudoSprite::MayBeSprite(const std::string&sprite){ + std::istringstream in(sprite); char ch; while(in.get(ch)){ if(ch=='"')return true; @@ -269,7 +268,7 @@ bool PseudoSprite::MayBeSprite(const string&sprite){ in.ignore(INT_MAX,'\n'); continue; } - if(isspace(ch)||string(VALID_PSEUDO).find(ch)==NPOS)continue; + if(isspace(ch)||std::string(VALID_PSEUDO).find(ch)==NPOS)continue; return true; } return false; @@ -299,12 +298,12 @@ PseudoSprite&PseudoSprite::SetText(uint i,uint num){ } PseudoSprite&PseudoSprite::SetOpByte (uint i, char action) { - string s = FindEscape(action, ExtractByte(i)); + std::string s = FindEscape(action, ExtractByte(i)); if (s != "") SetEscape(i, false, s, 1); return *this; } PseudoSprite&PseudoSprite::SetPositionalOpByte (uint i, char action) { - string s = FindEscape(action, ExtractByte(i), i); + std::string s = FindEscape(action, ExtractByte(i), i); if (s != "") SetEscape(i, false, s, 1); return *this; } @@ -384,7 +383,7 @@ PseudoSprite&PseudoSprite::SetQEscape(uint i,uint num){ return SetHex(i,num); } -PseudoSprite&PseudoSprite::SetEscape(uint i, bool quote, string ext, uint len){ +PseudoSprite&PseudoSprite::SetEscape(uint i, bool quote, std::string ext, uint len){ if(GetState(USEESCAPES)){ while(len--){ ext_print[i+len]=""; @@ -400,7 +399,7 @@ PseudoSprite&PseudoSprite::SetEot(uint i){beauty[i]=ENDQUOTE;return*this;} PseudoSprite&PseudoSprite::SetEol(uint i,uint minbreaks,uint lead){ if(GetState(CONVERTONLY)||GetState(LINEBREAKS) Tokenize(const string& str, char delimiter) { - vector tokens; - // 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); - - 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); - } +std::vector Tokenize(const std::string& str, char delimiter) { + std::vector tokens; + // Skip delimiters at beginning. + std::string::size_type lastPos = str.find_first_not_of(delimiter); + // Find first "non-delimiter". + std::string::size_type pos = str.find_first_of(delimiter, lastPos); + + while (std::string::npos != pos || std::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){ +std::ostream&PseudoSprite::output(std::ostream&out){ if(!valid){ - istringstream datastream(orig); - string line; + std::istringstream datastream(orig); + std::string line; getline(datastream,line); - out<6 && (beauty[i]&~NOBREAK)==NQEXT) str = ext_print[i].c_str()+skipspace; else @@ -701,42 +700,42 @@ ostream&PseudoSprite::output(ostream&out){ outbuf<<'"'; instr=false; } - outbuf<<(noendl?"":"\n")< > sections; - foreach(const string &line, (Tokenize(buffer, '\n'))) + std::vector > sections; + foreach(const std::string &line, (Tokenize(buffer, '\n'))) sections.push_back(Tokenize(line, '\t')); // Count the columns - uint columns = (uint)max_element(sections.begin(),sections.end(), boost::lambda::bind(&vector::size,boost::lambda::_1) < boost::lambda::bind(&vector::size,boost::lambda::_2))->size(); + uint columns = (uint)max_element(sections.begin(),sections.end(), boost::lambda::bind(&std::vector::size,boost::lambda::_1) < boost::lambda::bind(&std::vector::size,boost::lambda::_2))->size(); // For each column, for(uint i=0;i §ion, sections) - if(section.size()>i+1) padWidth = max(padWidth, section[i].length()+1); + std::string::size_type padWidth = 0; + foreach(const std::vector §ion, sections) + if(section.size()>i+1) padWidth = std::max(padWidth, section[i].length()+1); // and make it that wide. - foreach(vector §ion, sections) - if(section.size()>i+1) section[i] += string(padWidth - section[i].length(), ' '); + foreach(std::vector §ion, sections) + if(section.size()>i+1) section[i] += std::string(padWidth - section[i].length(), ' '); } // Tabs are expanded, write each line - foreach(const vector&line, sections) + foreach(const std::vector&line, sections) for_each(line.begin(),line.end(),out<>setbase(16)>>ret>>setbase(10); + in.ignore()>>std::setbase(16)>>ret>>std::setbase(10); return ret; } if (in.peek() == '(') { // Read any RPN value @@ -798,16 +797,16 @@ uint PseudoSprite::ReadValue(istream& in, width w) { // Replace the original RPN with value auto e = in.tellg(); - size_t p = orig.find(((istringstream&)in).str().substr(size_t(s), size_t(e - s))); + size_t p = orig.find(((std::istringstream&)in).str().substr(size_t(s), size_t(e - s))); orig.erase(p, size_t(e - s)); - ostringstream Val; + std::ostringstream Val; Val << val; orig.insert(p, Val.str()); return val; } // Read any other value - string str; + std::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) @@ -828,13 +827,13 @@ uint PseudoSprite::ReadValue(istream& in, width w) { if (w == _W_) { // word date - if (d==0 || (d>31 && d<100) || d>1919) swap(y, d); // Try DMY instead + if (d==0 || (d>31 && d<100) || d>1919) std::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 + if (d >= 32) std::swap(y, d); // Try DMY instead // Boost doesn't support years out of the range 1400..9999 while (y>9999) { y -= 400; @@ -854,6 +853,6 @@ uint PseudoSprite::ReadValue(istream& in, width w) { } fail: // Nothing worked - in.clear(ios::badbit); + in.clear(std::ios::badbit); return (uint)-1; } diff --git a/src/pseudo.h b/src/pseudo.h index c978e46..610dd90 100644 --- a/src/pseudo.h +++ b/src/pseudo.h @@ -29,7 +29,7 @@ class PseudoSprite{ public: //PseudoSprite(); - PseudoSprite(const string&,int); + PseudoSprite(const std::string&,int); void CheckLinkage(int ofs,int count)const; // Use to read a single byte if you don't know/care about its meaning. @@ -58,7 +58,7 @@ class PseudoSprite{ PseudoSprite&SetQEscape(uint); PseudoSprite&SetQEscape(uint,uint); private: - PseudoSprite&SetEscape(uint,bool,string,uint); + PseudoSprite&SetEscape(uint,bool,std::string,uint); public: PseudoSprite&SetHex(uint); @@ -99,21 +99,21 @@ class PseudoSprite{ SetBE(offs,2); return ExtractWord(offs); } - void AddComment(const string&,uint); - void TrailComment(const string&,uint); + void AddComment(const std::string&,uint); + void TrailComment(const std::string&,uint); void AddBlank(uint); void NoBeautify(); - friend ostream&operator<<(ostream&,PseudoSprite&); + friend std::ostream&operator<<(std::ostream&,PseudoSprite&); private: - ostream&output(ostream&); + std::ostream&output(std::ostream&); public: static bool CanQuote(uint); - static bool MayBeSprite(const string&); + static bool MayBeSprite(const std::string&); enum width {_B_, _BX_, _W_, _D_}; - uint ReadValue(istream&, width); + uint ReadValue(std::istream&, width); private: bool DoQuote(uint)const; @@ -126,9 +126,9 @@ class PseudoSprite{ void Invalidate(); bool UseOrig()const; - string orig,packed; + std::string orig,packed; Expanding0Arraybeauty; - ExpandingArraycontext,ext_print; + ExpandingArraycontext,ext_print; bool valid,useorig; const int oldspritenum; diff --git a/src/readinfo.cpp b/src/readinfo.cpp index dc92840..85ba56f 100644 --- a/src/readinfo.cpp +++ b/src/readinfo.cpp @@ -41,7 +41,6 @@ Version 7: Add backslash escapes #include #include -using namespace std; // grfcodec requires boost::date_time for its processing of the \wYMD and // \wDMY formats. Get boost from www.boost.org @@ -73,14 +72,14 @@ const char *depths[DEPTHS] = { "8bpp", "32bpp", "mask" }; }else\ (void(0)) -void read_file(istream&in,int infover,int grfcontversion,AllocArray&sprites){ - string sprite,datapart,buffer; +void read_file(std::istream&in,int infover,int grfcontversion,AllocArray&sprites){ + std::string sprite,datapart,buffer; int temp=-1,spriteno=-1,claimed_size=1; - string::size_type firstnotpseudo; + std::string::size_type firstnotpseudo; while(true){ getline(in,sprite); - istringstream spritestream(sprite); + std::istringstream spritestream(sprite); eat_white(spritestream); if(spritestream.peek()==EOF || // blank is_comment(spritestream)){ // comment @@ -133,13 +132,13 @@ void read_file(istream&in,int infover,int grfcontversion,AllocArray&spri } } -Sprite::unparseable::unparseable(string reason,size_t sprite){ +Sprite::unparseable::unparseable(std::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); +void Real::AddSprite(size_t sprite,int infover,const std::string&data){ + std::string::size_type loc=NPOS; + std::string udata=UCase(data); while(true){ loc=udata.find(".PCX",loc+1); #ifdef WITH_PNG @@ -267,28 +266,28 @@ void Real::AddSprite(size_t sprite,int infover,const string&data){ infs.push_back(inf); } -string Real::prevname; +std::string Real::prevname; int Real::prevy=0; #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); +std::string GetUtf8Encode(uint ch){ + if(ch<0x80)return std::string()+char(ch); + if(ch<0x800)return std::string()+char(((ch>>6 )&0x1F)|0xC0)+CHAR(0); + /*if(ch<0x10000)*/return std::string()+char(((ch>>12)&0x0F)|0xE0)+CHAR(1)+CHAR(0); + //if(ch<0x200000)return std::string()+char(((ch>>18)&0x07)|0xF0)+CHAR(2)+CHAR(1)+CHAR(0); + //if(ch<0x4000000)return std::string()+char(((ch>>24)&0x03)|0xF8)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0); + //if(ch<0x80000000)return std::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); +int FindEscape(std::string); -Pseudo::Pseudo(size_t num,int infover,int grfcontversion,const string&sprite,int claimed_size){ - istringstream in(sprite); - ostringstream out; +Pseudo::Pseudo(size_t num,int infover,int grfcontversion,const std::string&sprite,int claimed_size){ + std::istringstream in(sprite); + std::ostringstream out; char ch; while(in){ eat_white(in); @@ -298,7 +297,7 @@ Pseudo::Pseudo(size_t num,int infover,int grfcontversion,const string&sprite,int in.ignore(); while(true){ if(!in.get(ch)) - throw Sprite::unparseable("Unterminated literal string",num); + throw Sprite::unparseable("Unterminated literal std::string",num); if(ch=='"') break; if(ch=='\\'&&infover>6){ @@ -370,7 +369,7 @@ Pseudo::Pseudo(size_t num,int infover,int grfcontversion,const string&sprite,int continue; default:{ in.unget(); - string esc; + std::string esc; in>>esc; int byte = FindEscape(esc); if(byte == -1) break; @@ -398,8 +397,8 @@ Pseudo::Pseudo(size_t num,int infover,int grfcontversion,const string&sprite,int uint Pseudo::size()const{return (uint)packed.size();} -bool Pseudo::MayBeSprite(const string&sprite){ - istringstream in(sprite); +bool Pseudo::MayBeSprite(const std::string&sprite){ + std::istringstream in(sprite); char ch; while(in.get(ch)){ if(ch=='"')return true; @@ -407,19 +406,19 @@ bool Pseudo::MayBeSprite(const string&sprite){ in.ignore(INT_MAX,'\n'); continue; } - if(isspace(ch)||string(VALID_PSEUDO).find(ch)==NPOS)continue; + if(isspace(ch)||std::string(VALID_PSEUDO).find(ch)==NPOS)continue; return true; } return false; } -Include::Include(const string&data):name(data){} +Include::Include(const std::string&data):name(data){} -uint Pseudo::ReadValue(istream& in, width w) +uint Pseudo::ReadValue(std::istream& in, width w) { if (in.peek() == 'x') { // Read any hex value uint ret; - in.ignore()>>setbase(16)>>ret>>setbase(10); + in.ignore()>>std::setbase(16)>>ret>>std::setbase(10); return ret; } /*if (in.peek() == '(') { // Read any RPN value @@ -427,7 +426,7 @@ uint Pseudo::ReadValue(istream& in, width w) }*/ // Read any other value - string str; + std::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) @@ -448,13 +447,13 @@ uint Pseudo::ReadValue(istream& in, width w) if (w == _W_) { // word date - if (d==0 || (d>31 && d<100) || d>1919) swap(y, d); // Try DMY instead + if (d==0 || (d>31 && d<100) || d>1919) std::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 + if (d >= 32) std::swap(y, d); // Try DMY instead // Boost doesn't support years out of the range 1400..9999 while (y>9999) { y -= 400; @@ -475,6 +474,6 @@ uint Pseudo::ReadValue(istream& in, width w) fail: // Nothing worked - in.clear(ios::badbit); + in.clear(std::ios::badbit); return (uint)-1; } diff --git a/src/sanity.cpp b/src/sanity.cpp index 356662d..66d7132 100644 --- a/src/sanity.cpp +++ b/src/sanity.cpp @@ -25,7 +25,6 @@ #include #include #include -using namespace std; #include"nforenum.h" #include"globals.h" diff --git a/src/sanity_defines.h b/src/sanity_defines.h index 573ac44..413055d 100644 --- a/src/sanity_defines.h +++ b/src/sanity_defines.h @@ -42,7 +42,7 @@ void InitF(); void finalF(); bool IsLabel(uint); -//int GetBit(const string&); +//int GetBit(const std::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}; diff --git a/src/sprites.h b/src/sprites.h index 9cc33d4..ba2beae 100644 --- a/src/sprites.h +++ b/src/sprites.h @@ -23,7 +23,6 @@ #include #include -using namespace std; #define ZOOM_LEVELS (6) extern const char *zoom_levels[ZOOM_LEVELS]; @@ -58,7 +57,7 @@ struct SpriteInfo { S16 xrel; ///< Horizontal offset S16 yrel; ///< Vertical offset - string name; + std::string name; int xpos,ypos,imgsize; bool forcereopen; diff --git a/src/strings.cpp b/src/strings.cpp index e184825..b62cb7b 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -25,7 +25,6 @@ #include #include -using namespace std; #include"nforenum.h" #include"inlines.h" @@ -181,7 +180,7 @@ void Check13(PseudoSprite&data){ * (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){ +int CheckString(PseudoSprite&data,uint&offs,int perms,bool include_00_safe,std::string stack,const int retInfo){ const uint length=data.Length(); if(offs>=length)return -1; uint stackoffs=0,ret=0,ch; @@ -256,12 +255,12 @@ int CheckString(PseudoSprite&data,uint&offs,int perms,bool include_00_safe,strin 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]); + std::swap(stack[6],stack[0]); + std::swap(stack[7],stack[1]); + std::swap(stack[4],stack[6]); + std::swap(stack[5],stack[7]); + std::swap(stack[2],stack[4]); + std::swap(stack[3],stack[5]); } } }else if(ch<0x88||ch==0x9A){ @@ -275,7 +274,7 @@ int CheckString(PseudoSprite&data,uint&offs,int perms,bool include_00_safe,strin case 0x02: // ignore color code break; case 0x03: // push WORD - stack = string(2,char(STACK_WORD)) + stack; + stack = std::string(2,char(STACK_WORD)) + stack; arg=data.ExtractEscapeWord(++offs); if(!(arg&0xFF)&&!include_00_safe)IssueMessage(WARNING1,EMBEDDED_00,offs); ++offs; @@ -356,7 +355,7 @@ int CheckString(PseudoSprite&data,uint&offs,int perms,bool include_00_safe,strin 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. + --ret; // These do not read from the stack. break; DEFAULT(ch) } @@ -395,15 +394,15 @@ int CheckString(PseudoSprite&data,uint&offs,int perms,bool include_00_safe,strin static const uchar stackSize[]={0,1,2,2,4,2,8}; -string MakeStack(int items,...){ - string ret; +std::string MakeStack(int items,...){ + std::string ret; va_list ap; va_start(ap, items); uint item; for(int i=0;i>((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); +std::string GetUtf8Encode(uint ch){ + if(ch<0x80)return std::string()+char(ch); + if(ch<0x800)return std::string()+char(((ch>>6 )&0x1F)|0xC0)+CHAR(0); + if(ch<0x10000)return std::string()+char(((ch>>12)&0x0F)|0xE0)+CHAR(1)+CHAR(0); + if(ch<0x200000)return std::string()+char(((ch>>18)&0x07)|0xF0)+CHAR(2)+CHAR(1)+CHAR(0); + if(ch<0x4000000)return std::string()+char(((ch>>24)&0x03)|0xF8)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0); + if(ch<0x80000000)return std::string()+char(((ch>>30)&0x01)|0xFC)+CHAR(4)+CHAR(3)+CHAR(2)+CHAR(1)+CHAR(0); INTERNAL_ERROR(ch,ch); } diff --git a/src/utf8.h b/src/utf8.h index ec532ae..7d7f4fc 100644 --- a/src/utf8.h +++ b/src/utf8.h @@ -10,6 +10,6 @@ #ifndef UTF8_H_INCLUDED #define UTF8_H_INCLUDED -string GetUtf8Encode(uint); +std::string GetUtf8Encode(uint); #endif /*UTF8_H_INCLUDED*/ diff --git a/src/win32.h b/src/win32.h index 2c8e05c..bf90060 100644 --- a/src/win32.h +++ b/src/win32.h @@ -25,6 +25,7 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN +#define NOMINMAX #include #include @@ -39,7 +40,7 @@ inline int mkdir(const char*x,int){return _mkdir(x);} inline int mkdir(const char*x,int){return mkdir(x);} #endif -//string GetOpt(char*); +//std::string GetOpt(char*); #endif//_WIN32