Skip to content

Instantly share code, notes, and snippets.

@julienr
Created December 22, 2011 16:14
Show Gist options
  • Save julienr/1510842 to your computer and use it in GitHub Desktop.
Save julienr/1510842 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# This is a simple pre-processor for a boustrophedonic dialect of the C
# programming language :
# http://en.wikipedia.org/wiki/Boustrophedonic
#
# A sample program is :
# #include <stdio.h>
# { )( niam tni
# printf("Hello dlrow\n");
# ;)"n\world olleH"(ftnirp
# return 0;
# }
#
# To compile, use ./boustrocc.py foobar.c, it will create a boustro executable
# in the current directory
from __future__ import with_statement
import sys
import os
if len(sys.argv) < 2:
print('Usage %s <input file>'%(sys.argv[0]))
TMP_FILE = '/tmp/boustro_file.c'
with open(sys.argv[1]) as f, open(TMP_FILE, 'wt') as o:
for i, l in enumerate(f):
if i%2:
o.write(l[::-1])
else:
o.write(l)
os.system('gcc -o boustro %s'%TMP_FILE)
#include <stdio.h>
{ )( niam tni
printf("Hello dlrow\n");
;)"n\world olleH"(ftnirp
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment