Imported Upstream version 1.72.0
[platform/upstream/boost.git] / tools / bcp / bcp_imp.hpp
1 /*
2  *
3  * Copyright (c) 2003 Dr John Maddock
4  * Use, modification and distribution is subject to the 
5  * Boost Software License, Version 1.0. (See accompanying file 
6  * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9
10 #include "bcp.hpp"
11 #include <string>
12 #include <cstring>
13 #include <list>
14 #include <set>
15 #include <map>
16 #include <queue>
17 #include <boost/filesystem/path.hpp>
18
19 namespace fs = boost::filesystem;
20
21 class fileview;
22
23 //
24 //path operations:
25 //
26 int compare_paths(const fs::path& a, const fs::path& b);
27 inline bool equal_paths(const fs::path& a, const fs::path& b)
28 { return compare_paths(a, b) == 0; }
29
30 struct path_less
31 {
32    bool operator()(const fs::path& a, const fs::path& b)const
33    { return compare_paths(a, b) < 0; }
34 };
35
36 struct license_data
37 {
38    std::set<fs::path, path_less> files;
39    std::set<std::string>         authors;
40 };
41
42 class bcp_implementation
43    : public bcp_application
44 {
45 public:
46    bcp_implementation();
47    ~bcp_implementation();
48    static bool is_source_file(const fs::path& p);
49    static bool is_html_file(const fs::path& p);
50    static bool is_jam_file(const fs::path& p);
51 private:
52    //
53    // the following are the overridden virtuals from the base class:
54    //
55    void enable_list_mode();
56    void enable_summary_list_mode();
57    void enable_cvs_mode();
58    void enable_svn_mode();
59    void enable_unix_lines();
60    void enable_scan_mode();
61    void enable_license_mode();
62    void enable_bsl_convert_mode();
63    void enable_bsl_summary_mode();
64    void set_boost_path(const char* p);
65    void set_destination(const char* p);
66    void add_module(const char* p);
67    void set_namespace(const char* name);
68    void set_namespace_alias(bool);
69    void set_namespace_list(bool);
70
71    virtual int run();
72
73    // internal helper functions:
74    bool is_binary_file(const fs::path& p);
75    void scan_cvs_path(const fs::path& p);
76    void scan_svn_path(const fs::path& p);
77    void add_path(const fs::path& p);
78    void add_pending_path(const fs::path& p) { m_pending_paths.push(p); }
79    void add_directory(const fs::path& p);
80    void add_file(const fs::path& p);
81    void copy_path(const fs::path& p);
82    void add_file_dependencies(const fs::path& p, bool scanfile);
83    void add_dependent_lib(const std::string& libname, const fs::path& p, const fileview& view);
84    void create_path(const fs::path& p);
85    // license code:
86    void scan_license(const fs::path& p, const fileview& v);
87    void output_license_info();
88
89    std::list<std::string> m_module_list; // the modules to process
90    bool m_list_mode;                     // list files only
91    bool m_list_summary_mode;             // list file summary only
92    bool m_license_mode;                  // generate license information for files listed
93    bool m_cvs_mode;                      // check cvs for files
94    bool m_svn_mode;                      // check svn for files
95    bool m_unix_lines;                    // fix line endings
96    bool m_scan_mode;                     // scan non-boost files.
97    bool m_bsl_convert_mode;              // try to convert to the BSL
98    bool m_bsl_summary_mode;              // summarise BSL issues only
99    bool m_namespace_alias;               // make "boost" a namespace alias when doing a namespace rename.
100    bool m_list_namespaces;               // list all the top level namespaces found.
101    fs::path m_boost_path;                // the path to the boost root
102    fs::path m_dest_path;                 // the path to copy to
103    std::map<fs::path, bool, path_less>                   m_cvs_paths;                  // valid files under cvs control
104    std::set<fs::path, path_less>                         m_copy_paths;                 // list of files to copy
105    std::map<int, license_data>                           m_license_data;               // licenses in use
106    std::set<fs::path, path_less>                         m_unknown_licenses;           // files with no known license
107    std::set<fs::path, path_less>                         m_unknown_authors;            // files with no known copyright/author
108    std::set<fs::path, path_less>                         m_can_migrate_to_bsl;         // files that can migrate to the BSL
109    std::set<fs::path, path_less>                         m_cannot_migrate_to_bsl;      // files that cannot migrate to the BSL
110    std::set<std::string>                                 m_bsl_authors;                // authors giving blanket permission to use the BSL
111    std::set<std::string>                                 m_authors_for_bsl_migration;  // authors we need for BSL migration
112    std::map<fs::path, std::pair<std::string, std::string>, path_less> 
113                                                          m_converted_to_bsl;
114    std::map<std::string, std::set<fs::path, path_less> > m_author_data;                // all the authors
115    std::map<fs::path, fs::path, path_less>               m_dependencies;               // dependency information
116    std::string                                           m_namespace_name;             // namespace rename.
117    std::set<std::string>                                 m_lib_names;                  // List of library binary names
118    std::map<std::string, fs::path>                       m_top_namespaces;             // List of top level namespace names
119    std::queue<fs::path, std::list<fs::path> >            m_pending_paths;              // Queue of paths we haven't scanned yet.
120 };
121