Table Of Contents
I decided to create a small script that highlights the words reserved of c++. Here the code:
#!/bin/bash
rutaCodigo=`zenity --file-selection --title="Select a File"`
case $? in
0)
keyWords="continue float new signed try auto default for operator sizeof typedef break delete friend private static union case do goto protected struct unsigned catch double if public switch virtual char else inline register template void enum int return this volatile const extern long short throw while bool cout cin using namespace"
sed "s/^#include/#include/" < "$rutaCodigo" > temp # coloreo el include
sed "s/^#define/#define/" < temp > "$rutaCodigo" # coloreo el define
for word in $keyWords
do
#Busco en el texto, cada palabra clave contenida en keyWords, y le añado la etiqueta span
sed "s/b$wordb/$word/" < "$rutaCodigo" > temp
cp temp $rutaCodigo
done
sed "s/^class /class/g" < "$rutaCodigo" > temp
rm temp
;;
*)
echo "No se seleciciono nada.";;
esac
I am going to explain a bit the code:
The variable keyWords contains the key words of c ++, fewer “class”, which later I will explain because. In this variable, the words have to be separated by a space, and all in the same line, In order that the “for” takes word to word.
Both following lines
sed "s/^#include..... and sed "s/^#define...
search the pattern “#define” or “#include”, initially of every line of the text, this is indicated by ^, and replaces it with his corresponding style, to format the text. Once we enter the “for”, there is applied basically the same procedure that for it “define” and “include”, but with every word of the variable keyWords.
Finally, I do the same for the reserved word “class”, the motive for which I have left this one by the end, it is because the label contains the word, “class”, and then the code would not go out well, since on having been this word inside the label span, it would replace it also.
How Use It:
It is necessary to create a css class for the blog, of this form:
.prp { color: "#0a0"; font-weight: bold; }
.cpp { color: "#a40"; font-weight: bold; }
Once done this, we have to execute the script and introduce the code path to formatting with this style.
Here you can see the result.
Regards, I hope that it is useful
Spot a typo?: Help me fix it by contacting me or commenting below!