diff share/candide @ 9075:c989a1669243

<fizzie> revert 58b9ee8f97a7
author HackBot
date Sun, 25 Sep 2016 20:31:46 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/candide	Sun Sep 25 20:31:46 2016 +0000
@@ -0,0 +1,33 @@
+#!/bin/bash
+# compile c from stdin
+# candide, kinda
+
+readinput () {
+  while read -r -e || { printf %s "$REPLY"; false; } ; do
+    printf '%s\n' "$REPLY"
+  done
+}
+
+c="$*"
+args=""; while [[ "$c" =~ ^(-[^ ]*)\ (.*) ]]; do args="$args ${BASH_REMATCH[1]}"; c="${BASH_REMATCH[2]}"; done
+if ! [[ $c ]] || ! out=$(mktemp); then
+  echo Error >&2
+  exit 1
+fi
+
+# if you don't write 'main' it assumes that you're writing a full program (with free includes)
+# this allows you to use other functions and stuff
+# it will get false positives, but who cares?
+if [[ $c != *main* ]]; then c=$(cat <<SOURCE
+int main(int argc, char *argv[]) {
+$c
+  return 0;
+}
+SOURCE
+); fi
+
+# will replace ${args--O0} with the parameters
+gcc -o "$out" -x c -I /hackenv/share ${args--O0} /dev/fd/0 <<SOURCE && { "$out" && { rm -f "$out"; true; }; }
+#include "headers"    /* precompiled headers */
+$c
+SOURCE