Created
May 25, 2017 00:56
-
-
Save aaronryank/74fed7cefc9cca11e9a55810676ca50c to your computer and use it in GitHub Desktop.
This file contains 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
#! /bin/bash | |
# C1R compiler | |
# remove HTML tags, but replace "<br />" by newlines | |
function removeHTMLtags() { | |
sed -e 's~<br */>~\ | |
~g' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' | |
} | |
# unescape HTML codes: replace "<" by "<" etc | |
function unescapeHTML() { | |
sed -e 's/<\;/</g;s/>\;/>/g;s/ \;/ /g;s/ \;/ /g;s/ \;/ /g;s/"\;/"/g;s/(\;/(/g;s/)\;/)/g;s/[\;/[/g;s/]\;/]/g;s/{\;/{/g;s/}\;/}/g' | |
} | |
FILENAME=$1 | |
if [ -z ${FILENAME} ] | |
then | |
echo "Usage: $0 <fileName>" | |
exit 1 | |
fi | |
FILENAME1=${FILENAME}.c | |
ROSETTAURL=rosettacode.org/wiki | |
WORDCOUNT=`cat $FILENAME|wc -l` | |
cp ${FILENAME} ${FILENAME1} | |
if [ $WORDCOUNT -eq 1 ] | |
then | |
# Note: the self-printing Quine program requires special treatment | |
if [ `cat $FILENAME` = "Quine" ] | |
then | |
cat << EOF > $FILENAME1 | |
#include <stdio.h> | |
int main(char args[]) {printf("Quine\\n");} | |
EOF | |
else | |
PAGEURL=$ROSETTAURL/`cat $FILENAME` | |
curl $PAGEURL 2>/dev/null | grep -m 1 "<pre class=\"c highlighted_source\">" | removeHTMLtags | unescapeHTML >${FILENAME1} | |
fi | |
fi | |
cc $FILENAME1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment