26 fs <<
"\\begin{" << envName <<
"}" << std::endl;
27 fs << code << std::endl;
28 fs <<
"\\end{" << envName <<
"}" << std::endl << std::endl;
52 bool keepComment,
bool keepTex,
bool isPlatexMode,
const PString & envName,
54 const PString & monolineComment,
55 const PString & ptexLineCommentBegin,
const PString & ptexLineCommenEnd,
56 const PString & ptexMonolineComment)
58 PString ptexComment(
""), code(
"");
62 if(parser.
isMatch(ptexLineCommentBegin)){
64 flushCode(fs, typeCode, code, isPlatexMode, envName, keepTex);
66 ptexComment += fullComment;
67 }
else if(parser.
isMatch(ptexMonolineComment)){
69 flushCode(fs, typeCode, code, isPlatexMode, envName, keepTex);
71 ptexComment += fullComment;
72 }
else if(parser.
isMatch(lineCommentBegin)){
75 if(keepTex){fs << ptexComment << std::endl;}
82 }
else if(parser.
isMatch(monolineComment)){
85 if(keepTex){fs << ptexComment << std::endl;}
94 if(keepTex){fs << ptexComment << std::endl;}
103 flushCode(fs, typeCode, code, isPlatexMode, envName, keepTex);
104 if(ptexComment !=
"" && keepTex){
105 fs << ptexComment << std::endl;
124 bool keepComment,
bool keepTex,
bool removefirstcomment,
bool isPlatexMode,
128 PString ptexLineCommentBegin(
"");
130 if(lineCommentBegin !=
"" && lineCommenEnd !=
""){
131 ptexLineCommentBegin = lineCommentBegin +
"{";
132 ptexLineCommenEnd =
"}" + lineCommenEnd;
134 PString ptexMonolineComment(
"");
135 if(monolineComment !=
""){
136 ptexMonolineComment = monolineComment +
"{";
143 if(!parser.
open(inputFile)){
144 std::cerr <<
"createPTexFile : can't parse input file '"<<inputFile<<
"'" << std::endl;
149 if(removefirstcomment){
150 if(parser.
isMatch(lineCommentBegin)){
154 splitInputFile(fs, parser, keepComment, keepTex, isPlatexMode, envName, lineCommentBegin, lineCommenEnd, monolineComment,
155 ptexLineCommentBegin, ptexLineCommenEnd, ptexMonolineComment);
166 PString nameOutputFile(outputFile);
168 if(isPlatexMode && ext !=
"ptex"){
169 nameOutputFile +=
".ptex";
171 return nameOutputFile;
184 bool keepComment,
bool keepTex,
bool removefirstcomment,
bool isPlatexMode)
186 if(outputFile ==
"" || inputFile ==
""){
187 std::cerr <<
"processFile : missing input or output file" << std::endl;
193 if(ext ==
"c" || ext ==
"cpp" || ext ==
"c++" || ext ==
"h" || ext ==
"hpp"){
194 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"cpp",
"/*",
"*/",
"//");
195 }
else if(ext ==
"cu"){
196 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"cuda",
"/*",
"*/",
"//");
197 }
else if(ext ==
"cmake" || baseFileName ==
"CMakeLists"){
198 return createPTexFile(outputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"cmake",
"#[[",
"]]",
"#");
199 }
else if(ext ==
"py"){
200 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"python",
"'''",
"'''",
"#");
201 }
else if(ext ==
"sh"){
202 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"bash",
": '",
"'",
"#");
203 }
else if(baseFileName ==
"Dockerfile"){
204 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"dockerfile",
"",
"",
"#");
205 }
else if(baseFileName ==
"Singularity" || baseFileName ==
"Apptainer"){
206 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"apptainer",
"",
"",
"#");
207 }
else if(ext ==
"submit"){
208 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"condor",
"",
"",
"#");
209 }
else if(ext ==
"yml"){
210 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"yml",
"",
"",
"#");
212 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"toml",
"",
"",
"#");
213 }
else if(ext ==
"md"){
214 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"markdown",
"<!--",
"-->",
"");
215 }
else if(ext ==
"gnuplot"){
216 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"gnuplot",
"",
"",
"#");
217 }
else if(ext ==
"rs"){
218 return createPTexFile(nameOutputFile, inputFile, keepComment, keepTex, removefirstcomment, isPlatexMode,
"rust",
"/*",
"*/",
"//");
220 std::cout <<
"Copy file '"<<inputFile<<
"' into '"<<nameOutputFile<<
"'" << std::endl;
221 std::ifstream ifs(inputFile.c_str());
222 std::ofstream fs(nameOutputFile.c_str());
classe qui permet de parser des fichiers texte en renvoyant les tokens les uns après les autres
bool open(const PPath &fileName)
Fonction qui ouvre le fichier que l'on va parser.
PString getUntilKeyWithoutPatern(const PString &patern)
Renvoie la chaine de caractère du caractère courant jusqu'à patern exclu.
void setEscapeChar(char escapeChar)
Sets the escape character of the PFileParser.
void setWhiteSpace(const PString &whiteSpace)
Initialise la liste des caractères blancs.
bool isMatch(const PString &patern)
Says if the patern match with the current caracters of the PFileParser.
char getCurrentCh() const
Renvoie le caractère courant.
bool isEndOfFile() const
Dit si on est à la fin du fichier.
char getNextChar()
Fonction qui renvoie le prochain caractère du fichier courant.
Path of a directory or a file.
PPath & eraseExtension()
Erase the extension of the PPath.
PString getExtension() const
Get file extension.
PPath getFileName() const
Get the name of the file, from last char to /.
PString eraseFirstLastChar(const PString &vecChar) const
Erase first and last char in a string.
PString eraseFirstChar(const PString &vecChar) const
Erase first char in a string.
PTypeCode
Get the type of the parsed text.
bool openFileStream(std::ofstream &fs, const PPath &fileName)
Open a ofstream and says if there is a problem.
void flushCode(std::ofstream &fs, PTypeCode::PTypeCode typeCode, PString &code, bool isPlatexMode, const PString &envName, bool keepTex)
Save the code into the output file.
bool processFile(const PPath &outputFile, const PPath &inputFile, bool keepComment, bool keepTex, bool removefirstcomment, bool isPlatexMode)
Process the input file.
bool createPTexFile(const PPath &outputFile, const PPath &inputFile, bool keepComment, bool keepTex, bool removefirstcomment, bool isPlatexMode, const PString &envName, const PString &lineCommentBegin, const PString &lineCommenEnd, const PString &monolineComment)
Create the PTex file.
PPath getSplitOutputFileName(const PPath &outputFile, bool isPlatexMode)
Get the output file name.
void splitInputFile(std::ofstream &fs, PFileParser &parser, bool keepComment, bool keepTex, bool isPlatexMode, const PString &envName, const PString &lineCommentBegin, const PString &lineCommenEnd, const PString &monolineComment, const PString &ptexLineCommentBegin, const PString &ptexLineCommenEnd, const PString &ptexMonolineComment)
Split the input file into the output file.