20 parser.
setExampleLongOption(
"phoenix_dripfile --input=fileInput.txt --command=\"some_program FILENAME\"");
24 parser.
addOption(
"command",
"c",
OptionType::STRING,
true,
"Command to be executed by the program. The token 'FILENAME' specifies where the generated file has to be passed in the command");
26 size_t firstToken(0lu), lastToken(-1lu), incrementToken(1lu);
27 parser.
addOption(
"firsttoken",
"f", firstToken,
"Index of the first token to be tested");
28 parser.
addOption(
"lasttoken",
"l", lastToken,
"Index of the last token to be tested");
29 parser.
addOption(
"incrementtoken",
"k", incrementToken,
"Increment of the index to be used");
31 PString delimitor(
"+-*/!:~&|<>.()[]{}\"'%");
32 parser.
addOption(
"delimitor",
"d", delimitor,
"All delimitor characters to be used to tokenise the input file");
34 parser.
addOption(
"nofail",
"x",
OptionType::NONE,
false,
"Does not take account if the tested program failed or not. Always retruns 0");
50 size_t firstToken,
size_t lastToken,
size_t incrementToken,
const PString & delimitor,
bool isNoFail)
52 std::cout <<
"processFile : using file '"<<inputFile<<
"'" << std::endl;
54 if(extention !=
""){extention =
"." + extention;}
55 PPath configFile(
"temporary_file" + extention);
57 if(command == updatedCommand){
58 std::cerr <<
"processFile : 'FILENAME' token missing in the command" << std::endl;
59 std::cerr <<
"\t" << command << std::endl;
62 std::cout <<
"Command : '"<<updatedCommand<<
"'" << std::endl;
66 if(!parser.
open(inputFile)){
return false;}
69 size_t tokenIndex(firstToken);
71 for(
size_t i(0lu); i < firstToken; ++i){
74 body += skippedStr + token;
76 while(tokenIndex < lastToken && !parser.
isEndOfFile()){
79 std::cerr <<
"processFile : cannot save file '"<<configFile<<
"'" << std::endl;
83 std::cout <<
"- token " << tokenIndex <<
" => ";
84 if(system(updatedCommand.c_str()) != 0 && !isNoFail){
85 std::cout <<
"FAIL" << std::endl;
88 std::cout <<
"OK" << std::endl;
89 for(
size_t i(0lu); i < incrementToken; ++i){
92 body += skippedStr + token;
111 size_t firstToken,
size_t lastToken,
size_t incrementToken,
const PString & delimitor,
bool isNoFail)
114 for(PVecPath::const_iterator it(vecInputFile.begin()); it != vecInputFile.end() && b; ++it){
115 b &=
processFile(*it, command, firstToken, lastToken, incrementToken, delimitor, isNoFail);
121 int main(
int argc,
char** argv){
127 defaultMode.
getValue(vecInputFile,
"input");
130 defaultMode.
getValue(command,
"command");
132 size_t firstToken(0lu), lastToken(-1lu), incrementToken(1lu);
133 defaultMode.
getValue(firstToken,
"firsttoken");
134 defaultMode.
getValue(lastToken,
"lasttoken");
135 defaultMode.
getValue(incrementToken,
"incrementtoken");
136 if(incrementToken == 0lu){incrementToken = 1lu;}
139 defaultMode.
getValue(delimitor,
"delimitor");
144 firstToken, lastToken, incrementToken, delimitor, isNoFail));
std::vector< PPath > PVecPath
int main(int argc, char **argv)
OptionParser createOptionParser()
Create the OptionParser of this program.
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.
bool processVecFile(const PVecPath &vecInputFile, const PString &command, size_t firstToken, size_t lastToken, size_t incrementToken, const PString &delimitor, bool isNoFail)
Process the program.
Describe a mode in the program arguments.
bool isOptionExist(const PString &optionName) const
Say if the given option has been passed to the program.
bool getValue(T &value, const PString &optionName) const
Get the value of the option.
Parse the options passed to a program.
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.
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
void setSeparator(const PString &separator)
Initialise la liste des caractères séparateurs.
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.
PString getNextToken()
Get the next token.
bool isEndOfFile() const
Dit si on est à la fin du fichier.
Path of a directory or a file.
bool saveFileContent(const PString &content) const
Save a PString in a file.
PString getExtension() const
Get file extension.
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.