]> Creatis software - bbtk.git/blob - kernel/appli/bbpConfigurator/bbpConfigurator.cpp
Feature #2042 bbpConfigurator
[bbtk.git] / kernel / appli / bbpConfigurator / bbpConfigurator.cpp
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27 #include <cstdlib>
28 #include <fstream>
29 #include <iostream>
30 #include <vector>
31 #include "boost/filesystem.hpp"
32 //#include "boost/filesystem/operations.hpp"
33 //#include "boost/filesystem/path.hpp"
34
35 namespace bf = boost::filesystem;
36
37 //using namespace bbtk;
38
39 int main(int argc, char **argv)
40 {
41   if (argc != 4)
42   {
43     std::cout << "usage : bbConfigurator <path_to_bbs> <package_name> <output_path>" << std::endl;
44     return 1;
45   }
46
47   std::string path_bbs(argv[1]);
48   std::string package_name(argv[2]);
49   std::string path_out(argv[3]);
50   
51   std::vector<bf::path> files;
52
53   bf::path pth(path_bbs.c_str());
54   if(bf::exists(pth) && bf::is_directory(pth))
55   {
56     bf::directory_iterator end_itr;
57     for(bf::directory_iterator itr(pth); itr != end_itr; ++itr)
58     {
59       if(!is_directory(itr->status()))
60       {
61         std::string nm(itr->path().filename().string());
62         if(nm.substr(nm.size()-4) == ".bbs")
63         {
64           std::cout << itr->path().filename().string() << std::endl;
65           files.push_back(itr->path());
66         }
67       }
68     }
69   }
70   else
71   {
72     std::cout<< "the path to the bbs's should be a folder and not a file.";
73     return 1;
74   }
75
76   for (int i = 0; i < (int)files.size()-1; ++i) {
77     for (int j = i+1; j < (int)files.size(); ++j) {
78       if(files[j].filename().string() < files[i].filename().string())
79       {
80         bf::path tmp = files[i];
81         files[i] = files[j];
82         files[j] = tmp;
83       }
84     }
85   }
86
87 #ifdef WIN32
88   std::string fname = path_out + "\\" + package_name + ".bbp";
89 #else
90   std::string fname = path_out + "/" + package_name + ".bbp";
91 #endif
92   
93   std::ofstream out(fname.c_str());
94   out << "#-----------------------------------------" << std::endl;
95   out << "# Include script for bbtk package '" << package_name << "'" << std::endl;
96   out << "# Automatically generated by bbpConfigurator" << std::endl;
97   out << "#-----------------------------------------" << std::endl;
98   out << "load "<< package_name << std::endl;
99   out << "#-----------------------------------------" << std::endl;
100   out << "package "<< package_name << std::endl;
101   out << "#-----------------------------------------" << std::endl;
102
103   //each bbs file ordered.
104   //include [package_name]/boxes/[file_bbs]
105   //#-----------------------------------------
106   for (int i = 0; i < (int)files.size(); ++i) {
107     out << "include " << package_name << "/boxes/" << files[i].filename().string() << std::endl;
108     out << "#-----------------------------------------" << std::endl;
109   }
110
111   out << "endpackage" << std::endl;
112   out << "#-- EOF ----------------------------------" << std::endl;
113
114   out.close();
115
116   return 0;
117 }
118 //==========================================================================
119
120