Removed trailing whitespaces and CRLFs
[auctionmangos.git] / src / tools / gensvnrevision / gensvnrevision.cpp
blob3533a0bffc76f2179f45c196b8bdfedc0eed1b40
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <fstream>
20 #include <sstream>
22 #pragma warning(disable:4996)
24 int main(int argc, char **argv)
26 std::string path;
28 if(argc >= 1 && argv[1] )
30 path = argv[1];
31 if(path.size() > 0 && (path[path.size()-1]!='/' || path[path.size()-1]!='\\'))
32 path += '/';
35 FILE* EntriesFile = fopen((path+".svn/entries").c_str(), "r");
36 if(!EntriesFile)
37 EntriesFile = fopen((path+"_svn/entries").c_str(), "r");
39 std::ostringstream newData;
41 if(!EntriesFile)
43 newData << "#ifndef __SVN_REVISION_H__" << std::endl;
44 newData << "#define __SVN_REVISION_H__" << std::endl;
45 newData << " #define SVN_REVISION \"Unknown\"" << std::endl;
46 newData << " #define SVN_DATE \"Unknown\"" << std::endl;
47 newData << " #define SVN_TIME \"Unknown\""<< std::endl;
48 newData << "#endif // __SVN_REVISION_H__" << std::endl;
50 else
52 char buf[200];
53 int revision;
54 char date_str[200];
55 char time_str[200];
57 fgets(buf,200,EntriesFile);
58 fgets(buf,200,EntriesFile);
59 fgets(buf,200,EntriesFile);
60 fscanf(EntriesFile,"%i",&revision);
61 fgets(buf,200,EntriesFile);
62 fgets(buf,200,EntriesFile);
63 fgets(buf,200,EntriesFile);
64 fgets(buf,200,EntriesFile);
65 fgets(buf,200,EntriesFile);
66 fscanf(EntriesFile,"%10sT%8s",date_str,time_str);
68 newData << "#ifndef __SVN_REVISION_H__" << std::endl;
69 newData << "#define __SVN_REVISION_H__" << std::endl;
70 newData << " #define SVN_REVISION \"" << revision << "\"" << std::endl;
71 newData << " #define SVN_DATE \"" << date_str << "\"" << std::endl;
72 newData << " #define SVN_TIME \"" << time_str << "\""<< std::endl;
73 newData << "#endif // __SVN_REVISION_H__" << std::endl;
75 fclose(EntriesFile);
78 std::string oldData;
80 if(FILE* HeaderFile = fopen("svn_revision.h","rb"))
82 while(!feof(HeaderFile))
84 int c = fgetc(HeaderFile);
85 if(c < 0)
86 break;
87 oldData += (char)c;
90 fclose(HeaderFile);
93 if(newData.str() != oldData)
95 if(FILE* OutputFile = fopen("svn_revision.h","wb"))
97 fprintf(OutputFile,"%s",newData.str().c_str());
98 fclose(OutputFile);
102 return 0;