Last active
February 4, 2019 16:26
-
-
Save theol0403/74953d83934759cdffed7a09fabb43a0 to your computer and use it in GitHub Desktop.
Bash C Translator Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shopt -s nullglob | |
TRANSLATEFILE=./TRANSLATE_ME.txt | |
for dir in $1 $2 $3 $4 $5 | |
do | |
for file in `find $dir -type f -name "*.cpp" -o -name "*.hpp"`; | |
do | |
[ -f "$file" ] || break | |
echo "Translating \"$file\"" | |
./translateFile.sh $file $TRANSLATEFILE | |
done | |
done | |
rm $TRANSLATEFILE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ $# -eq 1 ] | |
then | |
TRANSLATEFILE=$1.TRANSLATE_ME.txt | |
else | |
TRANSLATEFILE=$2 | |
fi | |
STAR="^\s*\*" #Search for beginning of line, a couple spaces, then a * | |
SLASHSTAR="\/\*" #Search for /* | |
SLASH="\/\/" #Search for // | |
#Remove code on lines with comments | |
#Export lines with comments to comment file | |
sed -E -e "s/.*$SLASH/$SLASH/" -e "s/.*$SLASHSTAR/$SLASHSTAR/" -e "s/.*$SLASH/$SLASH/" -e "/($SLASH|$SLASHSTAR|$STAR)/!s|.*||" $1 > $TRANSLATEFILE | |
sed -i 's/\r$//' $TRANSLATEFILE #convert line endings to LF to sanitize clipboard | |
sed -E -i -e "s/($STAR|$SLASHSTAR|$SLASH).*//" $1 #Remove comments from source file | |
read -p "Please Translate \"$TRANSLATEFILE\" Then Press Enter" | |
#./trans -s zh -b -i $TRANSLATEFILE -o $TRANSLATEFILE -e google | |
unix2dos $TRANSLATEFILE | |
sed -i 's/\/\s\//\/\//' $TRANSLATEFILE # Find accedental / / and replace to // | |
#merge files together | |
paste -d '\0' $1 $TRANSLATEFILE | tee $1 >/dev/null | |
unix2dos $1 | |
if [ $# -eq 1 ] | |
then | |
rm $TRANSLATEFILE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment