Patch #3086 2010-11-18 00:30

mastersumdumguy

Enhancements used in autoversion tool, as per GPL.
Download
3086-Enhancements_u.patch (12.4 KB)
Category
Application::FeatureAdd
Status
Open
Close date
 
Assigned to
 
/*
 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * $Revision: 6201 $
 * $Id: autorevision.cpp 6201 2010-04-04 08:21:27Z killerbot $
 * $HeadURL: svn://svn.berlios.de/codeblocks/trunk/src/build_tools/autorevision/autorevision.cpp $
 */
 // Be careful with this file, be sure none of it's code is included in anything proprietary, as it's covered by the GPL.

#include <stdio.h>
#include <string>
#include <vector>
#include <fstream>

#include "tinyxml/tinystr.h"
#include "tinyxml/tinyxml.h"

using namespace std;

#ifdef __WIN32__
    #define WIN32_LEAN_AND_MEAN 1
    #define NOGDI
    #include <windows.h>
    inline void set_env(const char* k, const char* v) { SetEnvironmentVariable(k, v); };
#ifdef __MSVC__
    // Why windows likes to add the underscore but otherwise keep the function I'll never know. 
#define popen(A,B) _popen(A,B)
#define pclose(A) _pclose(A)
#endif
#else
    #include <stdlib.h>
    inline void set_env(const char* k, const char* v) { setenv(k, v, 1); };
#endif

// Const definitions
/// This is what the slashes (\) will be converted to.
const std::string desired_slashes("/");
//const std::string desired_slashes("\\\\");

// Structure to hold settings rather then use half global, half passed variables.  It's inconsistent.
struct ProgramSettings
{
   bool do_int ;
   bool do_std ;
   bool do_wx  ;
   bool do_translate  ;
   bool be_verbose  ;
   bool do_error  ;
   bool do_mod ;
   bool do_external ;
   bool do_updated;
   bool do_forced;
   int error_level;

   string outputFile;
   string workingDir;
   vector<string> Namespaces; // If empty, use autoversion.
   string inconsistentFiles;
   string revision;
   string date;
   string externalFiles;
};

/// Get the subversion revision, and revision date.
bool QuerySvn(ProgramSettings& set);
/// Determine if any files are modified.
bool QuerySvnStatus(ProgramSettings& set);
bool ParseFile(const string& docFile, ProgramSettings& set);
bool WriteOutput(ProgramSettings& set);
string ChangePathInfo(string data);
int main(int argc, char** argv);



int main(int argc, char** argv)
{
     ProgramSettings set;
   set.do_int = false;
   set.do_std = false;
   set.do_wx  = false;
   set.do_translate  = false;
   set.be_verbose  = false;
   set.do_error  = false;
   set.do_mod  = false;
   set.do_updated  = false;
   set.do_external = false;
   set.do_forced = false;
   set.error_level  = 0;


    for(int i = 1; i < argc; ++i)
    {
        if(strcmp("+int", argv[i]) == 0)
            set.do_int = true;
        else if(strcmp("+std", argv[i]) == 0)
            set.do_std = true;
        else if(strcmp("+mod", argv[i]) == 0)
            set.do_mod = true;
        else if(strcmp("+ext", argv[i]) == 0)
            set.do_external = true;
        else if(strcmp("+mode", argv[i]) == 0)
          {
            set.do_mod = true;
            set.do_error = true;
          }
        else if(strcmp("+modu", argv[i]) == 0)
          {
            set.do_mod = true;
            set.do_updated = true;
          }
        else if(strcmp("+wx", argv[i]) == 0)
            set.do_wx = true;
        else if(strcmp("+t", argv[i]) == 0)
            set.do_translate = true;
        else if(strcmp("-v", argv[i]) == 0)
            set.be_verbose = true;
        else if(strcmp("-f", argv[i]) == 0)
            set.do_forced = true;
        else if(set.workingDir.empty())
            set.workingDir.assign(argv[i]);
        else if(set.outputFile.empty())
            set.outputFile.assign(argv[i]);
        else
            set.Namespaces.push_back(string(argv[i]));
    }

    if (set.workingDir.empty())
    {
        puts("Usage: autorevision [options] directory [autorevision.h] [namespaces*]");
        puts("Options:");
        puts("         +int assign const unsigned int");
        puts("         +std assign const std::string");
        puts("         +wx  assing const wxString");
        puts("         +mod generate a list of modified files.");
        puts("         +modu Include non-updated files as modified.");
        puts("         +ext generate a list of external repositories.");
        puts("         +mode treat any files other then unversioned in the tree as an error.");
        puts("         +t   add Unicode translation macros to strings");
        puts("         -v   be verbose");
        puts("         -f   force update, even if revisions are the same.");
        return 1;
    }

    if(set.outputFile.empty())
        set.outputFile.assign("autorevision.h");


    QuerySvn(set);
    if ((set.do_mod) ||(set.do_external))
       QuerySvnStatus(set);
    WriteOutput(set);

    return set.error_level;
}



bool QuerySvn( ProgramSettings& set)
{
    set.revision = "0";
    set.date = "unknown date";
    string svncmd("svn info --xml --non-interactive ");
    svncmd.append(set.workingDir);

    FILE *svn = popen(svncmd.c_str(), "r");

    if(svn)
    {
        char
download for full patch...