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