From 2d8aec31812c31c23aec691adf55104b7fb1eb9a Mon Sep 17 00:00:00 2001 From: Aaron Gutierrez Date: Mon, 23 Mar 2015 16:07:46 -0400 Subject: [PATCH] cc0.cgi takes in cc0 code as plain text and return a json object with the resulting bytecode. It is currently running at ~amgutier/cc0.cgi on the cc contrib servers, and is liable to be extremely buggy --- src/cc0.cgi | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 src/cc0.cgi diff --git a/src/cc0.cgi b/src/cc0.cgi new file mode 100755 index 0000000..ae51b9a --- /dev/null +++ b/src/cc0.cgi @@ -0,0 +1,37 @@ +#!/usr/bin/python +from subprocess import call, CalledProcessError +from urllib import quote_plus, unquote_plus +from json import dumps +import cgitb, cgi +import sys + +cgitb.enable() + + +form = cgi.FieldStorage() + +infile = open('/tmp/a.c0', 'w') +infile.write(unquote_plus(form["data"].value)) +infile.close() + +stderr = open('/tmp/a.err', 'w') + +if call(['/afs/andrew.cmu.edu/course/15/122/bin/cc0', '-b', '/tmp/a.c0', + '-o', '/tmp/a.bc0'], stderr=stderr, stdout=stderr) == 0: + bytecode = open('/tmp/a.bc0', 'r') + data = bytecode.read() + bytecode.close() + stderr.close() +else: + stderr.close() + stderr = open('/tmp/a.err', 'r') + data = stderr.read() + stderr.close() + + +name = "test" + +print("Content-type:text/json\n\n") +print dumps({"data": quote_plus(data), + "name": quote_plus(name), + "input": form["data"].value)})