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 | * This file implements the cpp_main entry point |
9 | */ |
10 | |
11 | |
12 | #include <iostream> |
13 | #include <cstring> |
14 | #include <string> |
15 | #include <list> |
16 | #include "bcp.hpp" |
17 | #include <boost/filesystem/path.hpp> |
18 | #include <boost/version.hpp> |
19 | |
20 | #ifdef BOOST_NO_STDC_NAMESPACE |
21 | namespace std{ |
22 | using ::strcmp; |
23 | using ::strncmp; |
24 | } |
25 | #endif |
26 | |
27 | void show_usage() |
28 | { |
29 | std::cout << |
30 | "Usage:\n" |
31 | " bcp --list [options] module-list\n" |
32 | " bcp --list-short [options] module-list\n" |
33 | " bcp --report [options] module-list html-file\n" |
34 | " bcp [options] module-list output-path\n" |
35 | "\n" |
36 | "Options:\n" |
37 | " --boost=path sets the location of the boost tree to path\n" |
38 | " --scan treat the module list as a list of (possibly non-boost)\n" |
39 | " files to scan for boost dependencies\n" |
40 | " --svn only copy files under cvs version control\n" |
41 | " --unix-lines make sure that all copied files use Unix style line endings\n" |
42 | " --namespace=name rename the boost namespace to name (also changes library names).\n" |
43 | " --namespace-alias Makes namespace boost an alias of the namespace set with --namespace.\n" |
44 | "\n" |
45 | "module-list: a list of boost files or library names to copy\n" |
46 | "html-file: the name of a html file to which the report will be written\n" |
47 | "output-path: the path to which files will be copied\n" ; |
48 | } |
49 | |
50 | bool filesystem_name_check( const std::string & ) |
51 | { |
52 | return true; |
53 | } |
54 | |
55 | int cpp_main(int argc, char* argv[]) |
56 | { |
57 | // |
58 | // Before anything else replace Boost.filesystem's file |
59 | // name checker with one that does nothing (we only deal |
60 | // with files that already exist, if they're not portable |
61 | // names it's too late for us to do anything about it). |
62 | // |
63 | /*boost::filesystem::path::default_name_check(filesystem_name_check);*/ |
64 | // |
65 | // without arguments just show help: |
66 | // |
67 | if(argc < 2) |
68 | { |
69 | std::cout << "Error: insufficient arguments, don't know what to do." << std::endl; |
70 | show_usage(); |
71 | return 1; |
72 | } |
73 | // |
74 | // create the application object: |
75 | // |
76 | pbcp_application papp(bcp_application::create()); |
77 | // |
78 | // work through args, and tell the application |
79 | // object what ir needs to do: |
80 | // |
81 | bool list_mode = false; |
82 | std::list<const char*> positional_args; |
83 | for(int i = 1; i < argc; ++i) |
84 | { |
85 | if(0 == std::strcmp(s1: "-h" , s2: argv[i]) |
86 | || 0 == std::strcmp(s1: "--help" , s2: argv[i])) |
87 | { |
88 | show_usage(); |
89 | return 0; |
90 | } |
91 | if(0 == std::strcmp(s1: "-v" , s2: argv[i]) |
92 | || 0 == std::strcmp(s1: "--version" , s2: argv[i])) |
93 | { |
94 | std::cout << "bcp " << (BOOST_VERSION / 100000) << "." << (BOOST_VERSION / 100 % 1000) << "." << (BOOST_VERSION % 100) << std::endl; |
95 | std::cout << __DATE__ << std::endl; |
96 | return 0; |
97 | } |
98 | else if(0 == std::strcmp(s1: "--list" , s2: argv[i])) |
99 | { |
100 | list_mode = true; |
101 | papp->enable_list_mode(); |
102 | } |
103 | else if(0 == std::strcmp(s1: "--list-short" , s2: argv[i])) |
104 | { |
105 | list_mode = true; |
106 | papp->enable_summary_list_mode(); |
107 | } |
108 | else if(0 == std::strcmp(s1: "--report" , s2: argv[i])) |
109 | { |
110 | papp->enable_license_mode(); |
111 | } |
112 | else if(0 == std::strcmp(s1: "--cvs" , s2: argv[i])) |
113 | { |
114 | papp->enable_cvs_mode(); |
115 | } |
116 | else if(0 == std::strcmp(s1: "--svn" , s2: argv[i])) |
117 | { |
118 | papp->enable_svn_mode(); |
119 | } |
120 | else if(0 == std::strcmp(s1: "--scan" , s2: argv[i])) |
121 | { |
122 | papp->enable_scan_mode(); |
123 | } |
124 | else if(0 == std::strcmp(s1: "--bsl-convert" , s2: argv[i])) |
125 | { |
126 | papp->enable_bsl_convert_mode(); |
127 | } |
128 | else if(0 == std::strcmp(s1: "--bsl-summary" , s2: argv[i])) |
129 | { |
130 | papp->enable_bsl_summary_mode(); |
131 | } |
132 | else if(0 == std::strcmp(s1: "--unix-lines" , s2: argv[i])) |
133 | { |
134 | papp->enable_unix_lines(); |
135 | } |
136 | else if(0 == std::strncmp(s1: "--boost=" , s2: argv[i], n: 8)) |
137 | { |
138 | papp->set_boost_path(argv[i] + 8); |
139 | } |
140 | else if(0 == std::strncmp(s1: "--namespace=" , s2: argv[i], n: 12)) |
141 | { |
142 | papp->set_namespace(argv[i] + 12); |
143 | } |
144 | else if(0 == std::strncmp(s1: "--namespace-alias" , s2: argv[i], n: 17)) |
145 | { |
146 | papp->set_namespace_alias(true); |
147 | } |
148 | else if(0 == std::strncmp(s1: "--list-namespaces" , s2: argv[i], n: 17)) |
149 | { |
150 | list_mode = true; |
151 | papp->set_namespace_list(true); |
152 | } |
153 | else if(argv[i][0] == '-') |
154 | { |
155 | std::cout << "Error: Unknown argument " << argv[i] << std::endl; |
156 | show_usage(); |
157 | return 1; |
158 | } |
159 | else |
160 | { |
161 | positional_args.push_back(x: argv[i]); |
162 | } |
163 | } |
164 | // |
165 | // Handle positional args last: |
166 | // |
167 | for(std::list<const char*>::const_iterator i = positional_args.begin(); |
168 | i != positional_args.end(); ++i) |
169 | { |
170 | if(!list_mode && (i == --positional_args.end())) |
171 | papp->set_destination(*i); |
172 | else |
173 | papp->add_module(p: *i); |
174 | } |
175 | // |
176 | // run the application object: |
177 | // |
178 | return papp->run(); |
179 | } |
180 | |
181 | |
182 | |
183 | |