PhoenixLecture  2.0.0
Set of tools to make lectures
main.cpp
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #include "OptionParser.h"
8 
9 #include "psrc_split_lib.h"
10 
12 
15  OptionParser parser(true, __PROGRAM_VERSION__);
16  parser.setExampleLongOption("phoenix_psrcsplittex --input=fileInput.cpp --output=output.ptex --platex");
17  parser.setExampleShortOption("phoenix_psrcsplittex -i fileInput.cpp -o output.ptex -p");
18 
19  parser.addOption("input", "i", OptionType::FILENAME, true, "name of the input file (source, c, cpp, cmake, py, cu)");
20 
21  PPath defaultOutputFile("./output.txt");
22  parser.addOption("output", "o", defaultOutputFile, "output file to be generated");
23 
24  parser.addOption("keepcomment", "k", OptionType::NONE, false, "keep the comment of the targeted language");
25  parser.addOption("keeptex", "t", OptionType::NONE, false, "keep the ptex comment in the output file");
26  parser.addOption("removefirstcomment", "f", OptionType::NONE, false, "remove the first comment of the file (can be the Licence or whatever)");
27  parser.addOption("platex", "p", OptionType::NONE, false, "activate platex mode (add begin and end around code part)");
28 
29  return parser;
30 }
31 
32 int main(int argc, char** argv){
34  parser.parseArgument(argc, argv);
35 
36  const OptionMode & defaultMode = parser.getDefaultMode();
37  PPath inputFile;
38  defaultMode.getValue(inputFile, "input");
39 
40  PPath outputDir(".");
41  defaultMode.getValue(outputDir, "output");
42 
43  bool keepComment(false), keepTex(false), removefirstcomment(false), isPlatexMode(false);
44  keepComment = defaultMode.isOptionExist("keepcomment");
45  keepTex = defaultMode.isOptionExist("keeptex");
46  removefirstcomment = defaultMode.isOptionExist("removefirstcomment");
47  isPlatexMode = defaultMode.isOptionExist("platex");
48 
49  bool b(processFile(outputDir, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode));
50  return b - 1;
51 }
52 
53 
54 
55 
int main(int argc, char **argv)
Definition: main.cpp:228
OptionParser createOptionParser()
Create the OptionParser of this program.
Definition: main.cpp:17
bool processFile(const PPath &inputFile, const PString &command, size_t firstToken, size_t lastToken, size_t incrementToken, const PString &delimitor, bool isNoFail)
Process the file.
Definition: main.cpp:49
Describe a mode in the program arguments.
Definition: OptionMode.h:13
bool isOptionExist(const PString &optionName) const
Say if the given option has been passed to the program.
Definition: OptionMode.cpp:210
bool getValue(T &value, const PString &optionName) const
Get the value of the option.
Parse the options passed to a program.
Definition: OptionParser.h:15
void parseArgument(int argc, char **argv)
Parse the arguments passed to the program.
void addOption(const PString &longOption, const PString &shortOption, OptionType::OptionType optionType, bool isRequired, const PString &docString)
Add an option in the OptionParser.
void setExampleShortOption(const PString &example)
Set the example usage of the program.
void setExampleLongOption(const PString &example)
Set the example usage of the program.
const OptionMode & getDefaultMode() const
Get default mode.
Path of a directory or a file.
Definition: PPath.h:17