Linux multi-monitor fullscreen support
[ryzomcore.git] / tool / increment_version / increment_version.cpp
blob45cb93eced4033087f86975e974ed98e2615f351
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
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 Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <nel/misc/types_nl.h>
18 #include <nel/misc/debug.h>
19 #include <nel/misc/common.h>
20 #include <nel/misc/file.h>
23 #include <string>
24 #include <fstream>
26 using namespace std;
27 using namespace NLMISC;
31 //-----------------------------------------------
32 // main
34 //-----------------------------------------------
35 sint main( sint argc, char ** argv )
37 if( argc < 4 )
39 printf("\n");
40 printf("Increment the version number in a version file\n\n");
41 printf("INCREMENT_VERSION <version file> <version motif> <version main number>\n");
42 return 1;
45 // open the version file
46 ifstream input(argv[1], ios::in);
47 if( !input.is_open() )
49 nlwarning("can't open the file %s",argv[1]);
50 return 1;
53 // open the output file
54 string outputFilename = string(argv[1]) + ".out";
55 FILE * output = nlfopen(outputFilename,"w");
56 if( output == NULL )
58 nlwarning("can't open the output file %s",outputFilename.c_str());
59 return 1;
62 bool motifFound = false;
63 bool versionNumberFound = false;
65 while( !input.eof() )
67 // read a line
68 string line;
69 getline(input,line,'\n');
71 // search the version motif
72 string::size_type idx = line.find(argv[2]);
74 // if motif not found
75 if( idx == string::npos )
77 // we write the line in output and continue to the next line
78 fprintf(output,"%s\n",line.c_str());
80 // if motif found
81 else
83 motifFound = true;
85 // search the main version number
86 idx = line.find(argv[3]);
87 if( idx == string::npos )
89 fprintf(output,"%s\n",line.c_str());
90 continue;
93 versionNumberFound = true;
95 // get old build version number
96 string::size_type oldBuildVersionStartIdx = line.rfind(".") + 1;
97 string::size_type oldBuildVersionEndIdx = line.find_first_of(" \"\t",oldBuildVersionStartIdx) - 1;
98 if( oldBuildVersionEndIdx == string::npos)
100 oldBuildVersionEndIdx = line.size() - 1;
102 string oldBuildVersionStr = line.substr( oldBuildVersionStartIdx, oldBuildVersionEndIdx - oldBuildVersionStartIdx + 1 );
103 sint oldBuildVersion = atoi( oldBuildVersionStr.c_str() );
105 // increment build version
106 sint32 buildVersion = oldBuildVersion + 1;
107 string buildVersionStr = toString(buildVersion);
108 printf("%d\n",buildVersion);
110 // replace build version in line
111 line.replace( oldBuildVersionStartIdx, oldBuildVersionStr.size(), buildVersionStr.c_str(), buildVersionStr.size() );
113 // we write the line in output and continue to the next line
114 fprintf(output,"%s\n",line.c_str());
117 input.close();
118 fclose(output);
120 if( !motifFound )
122 nlwarning("version motif %s not found\n",argv[2]);
123 return 1;
125 else
127 if( !versionNumberFound )
129 nlwarning("version number %s not found\n",argv[3]);
130 return 1;
134 return 0;