⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 one2all.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * =========================================================================== * PRODUCTION $Log: one2all.cpp,v $ * PRODUCTION Revision 1000.2  2004/06/01 19:42:05  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.10 * PRODUCTION * =========================================================================== *//*  $Id: one2all.cpp,v 1000.2 2004/06/01 19:42:05 gouriano Exp $ * =========================================================================== * *                            PUBLIC DOMAIN NOTICE *               National Center for Biotechnology Information * *  This software/database is a "United States Government Work" under the *  terms of the United States Copyright Act.  It was written as part of *  the author's official duties as a United States Government employee and *  thus cannot be copyrighted.  This software/database is freely available *  to the public for use. The National Library of Medicine and the U.S. *  Government have not placed any restriction on its use or reproduction. * *  Although all reasonable efforts have been taken to ensure the accuracy *  and reliability of the software and data, the NLM and the U.S. *  Government do not and cannot warrant the performance or results that *  may be obtained by using this software or data. The NLM and the U.S. *  Government disclaim all warranties, express or implied, including *  warranties of performance, merchantability or fitness for any particular *  purpose. * *  Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors:  Anton Lavrentiev, Vladimir Ivanov * * File Description: *    MSVC 6.0 project file converter. Expand a signle configuration project *    file to multi-configuration project file. * *//*  !!! Warning !!!    Seems that PCRE has a bug (or may be this is a feature?).    It doesn't correct handle regular expressions with brackets "[]"    if a PCRE_MULTILINE / PCRE_DOTALL flag is specified    (may be and some other).    It is necessary to investigate and try a new PCRE version.*/#include <ncbi_pch.hpp>#include <corelib/ncbiapp.hpp>#include <corelib/ncbienv.hpp>#include <corelib/ncbiargs.hpp>#include <corelib/ncbifile.hpp>#include <util/regexp.hpp>USING_NCBI_SCOPE;/// End-of-line symbol.const char* kEOL = "\n";/// String to replace matched data in templates.const char* kTemplate = "@@@";/// Single/Multiline PCRE compilation flags.const CRegexp::TCompile kSL = PCRE_DOTALL + PCRE_UNGREEDY;const CRegexp::TCompile kML = PCRE_MULTILINE + PCRE_UNGREEDY;const CRegexp::TCompile kDF = 0;///////////////////////////////////////////////////////////////////////////////  //  Configurations///// Configurations.static const char* kConfigName[] = { "Release", "Debug"  };/// Suffixes. Empty suffix ("") should be last.static const char* kSuffixName[] = { "DLL", "MT",  ""    };  static const char* kSuffixLib[]  = { "/MD", "/MT", "/ML" };/////////////////////////////////////////////////////////////////////////////////  Main application class//class CMainApplication : public CNcbiApplication{public:    /// Configuration enumerators.    /// Lesser value have more priority.    enum EConfig {        eRelease = 0,        eDebug,        eConfigMax    };    enum ESuffix {        eDLL = 0,        eMT,        eST,        eSuffixMax    };    /// Define a replacement command.     struct SReplacement {        const char*  from;  ///< Change from value.        const char*  to;    ///< Change to value.        size_t       count; ///< Maximum count of changes (0 - infinite).    };public:    /// Constructor.    CMainApplication(void);    /// Overrided methods.    virtual void Init(void);    virtual int  Run (void);private:    /// Parse program arguments.    void ParseArguments(void);    /// Process all project files in the specified directory.    void ProcessDir(const string& dir_name);    /// Process one project file only.    void ProcessFile(const string& file_name);    /// Replace configuration settings accordingly required configuration.    /// Return name of the configuration with or without used GUI.    string Configure(        const string& cfg_template,        string&       cfg_str,        EConfig       config,        ESuffix       suffix    );private:    /// Parameters.    bool    m_Cfg[eConfigMax][eSuffixMax]; //< Configurations    string  m_Path;                        //< Directory or file name    bool    m_IsRecursive;                 //< Process m_Path recursively    bool    m_IsDistribution;              //< Distribution mode    bool    m_CreateBackup;                //< Create backup files};/// Iterators by possible configurations.#define ITERATE_CONFIG(i) \    for (int i = 0; i < CMainApplication::eConfigMax; i++)#define ITERATE_SUFFIX(i) \    for (int i = 0; i < CMainApplication::eSuffixMax; i++)/// Compose configuration name.#define CONFIG_NAME(config, suffix) \    ((string)kConfigName[config] + kSuffixName[suffix]);CMainApplication::CMainApplication(void)    : m_Path(kEmptyStr), m_IsRecursive(false), m_IsDistribution(false){    memset(m_Cfg, 0, sizeof(m_Cfg));}void CMainApplication::Init(void){    // Set error posting and tracing on maximum.    SetDiagTrace(eDT_Enable);    SetDiagPostFlag(eDPF_Default);    SetDiagPostLevel(eDiag_Info);    // Describe the expected command-line arguments.    auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);    arg_desc->AddPositional        ("path",         "Directory or project file name to convert",         CArgDescriptions::eString);    arg_desc->AddOptionalPositional        ("config_type",         "Type of configuration to produce (default is \"all\")",         CArgDescriptions::eString);    arg_desc->SetConstraint        ("config_type", &(*new CArgAllow_Strings, "all", "release", "debug"));    arg_desc->AddOptionalPositional        ("config_spec",         "Set of build configurations (default is all)",         CArgDescriptions::eInteger);    arg_desc->SetConstraint        ("config_spec", new CArgAllow_Integers(2, 4));    arg_desc->AddFlag        ("r", "Process all project files in the <path> recursively " \         "(only if <path> is a directory)");    arg_desc->AddFlag        ("d", "Distributive mode;  remove include/library paths, " \         "which refers to DIZZY");    arg_desc->AddFlag        ("b", "Create backup file");/*    arg_desc->AddFlag        ("dll", "generate DLL configuration");    arg_desc->AddFlag        ("st", "generate single-threaded configuration");    arg_desc->AddFlag        ("mt", "generate multi-threaded configuration");*/    // Specify USAGE context.    arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),       "Automatic multi config for Microsoft Visual C++ Project File V 6.0");    // Setup arg.descriptions for this application.    SetupArgDescriptions(arg_desc.release());}void CMainApplication::ParseArguments(void){    CArgs args = GetArgs();    // Path    m_Path = args["path"].AsString();    // Flags    m_IsRecursive    = args["r"];    m_IsDistribution = args["d"];    m_CreateBackup   = args["b"];    // Configurations    string cfg = args["config_type"] ? args["config_type"].AsString() : "all";    bool cfg_enable[eConfigMax];    memset(cfg_enable, 0, sizeof(cfg_enable));    if (cfg == "all") {        cfg_enable[eRelease] = true;        cfg_enable[eDebug]   = true;    }    else if (cfg == "debug") {        cfg_enable[eDebug] = true;    }    else if (cfg == "release") {        cfg_enable[eRelease] = true;    }    // Special parameter    int spec = args["config_spec"] ? args["config_spec"].AsInteger() : 0;    ITERATE_CONFIG(i) {        if ( cfg_enable[i] ) {            switch ( spec ) {            case 2:                // DLL                m_Cfg[i][eDLL] = true;                break;            case 3:                // MT                m_Cfg[i][eMT]  = true;                break;            case 4:                // DLL, ST                m_Cfg[i][eDLL] = true;                m_Cfg[i][eST]  = true;                break;            default:                // DLL, MT, ST                m_Cfg[i][eDLL] = true;                m_Cfg[i][eMT]  = true;                m_Cfg[i][eST]  = true;            }        }    }}void CMainApplication::ProcessDir(const string& dir_name){    CDir dir(dir_name);    CDir::TEntries contents = dir.GetEntries("*");    ITERATE(CDir::TEntries, i, contents) {        string name  = (*i)->GetName();        if ( name == "."  ||  name == ".."  ||               name == string(1,CDir::GetPathSeparator()) ) {            continue;        }        string path = (*i)->GetPath();        if ( (*i)->IsFile()  &&  NStr::EndsWith(name, ".dsp") ) {            ProcessFile(path);        }         else if ( (*i)->IsDir() ) {            if ( m_IsRecursive ) {                ProcessDir(path);            }        }    }}void CMainApplication::ProcessFile(const string& file_name){    try     {        string content;  // File content        string str;      // Temporary string        // Read all file into memory.        CNcbiIfstream is(file_name.c_str(), IOS_BASE::in | IOS_BASE::binary);        if ( !is.is_open() ) {            throw (string)"cannot be opened";        }        while ( is ) {            char buf[16384];            is.read(buf, sizeof(buf));            size_t count = is.gcount();            if ( count ) {                buf[count] = '\0';                content.append(buf);            }        }        is.close();        // DOS-2-UNIX conversion.        // (shouldn't be here, but just in case for sanity).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -