1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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>
27 using namespace NLMISC
;
31 //-----------------------------------------------
34 //-----------------------------------------------
35 sint
main( sint argc
, char ** argv
)
40 printf("Increment the version number in a version file\n\n");
41 printf("INCREMENT_VERSION <version file> <version motif> <version main number>\n");
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]);
53 // open the output file
54 string outputFilename
= string(argv
[1]) + ".out";
55 FILE * output
= nlfopen(outputFilename
,"w");
58 nlwarning("can't open the output file %s",outputFilename
.c_str());
62 bool motifFound
= false;
63 bool versionNumberFound
= false;
69 getline(input
,line
,'\n');
71 // search the version motif
72 string::size_type idx
= line
.find(argv
[2]);
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());
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());
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());
122 nlwarning("version motif %s not found\n",argv
[2]);
127 if( !versionNumberFound
)
129 nlwarning("version number %s not found\n",argv
[3]);