changeset 8777:30f86e019a0c

<fizzie> fetch https://raw.githubusercontent.com/izabera/candide/master/candide-to-conf
author HackBot
date Sun, 10 Jul 2016 08:41:35 +0000
parents 3c8030de1ce7
children abfbcd1a21d5
files candide-to-conf
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/candide-to-conf	Sun Jul 10 08:41:35 2016 +0000
@@ -0,0 +1,32 @@
+#!/bin/bash
+# compile c from stdin
+# candide, kinda
+
+readinput () {
+  while read -r -e || { printf %s "$REPLY"; false; } ; do
+    printf '%s\n' "$REPLY"
+  done
+}
+
+c=$(readinput)
+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 -O0 with the parameters
+gcc -o "$out" -x c -I %%DIRECTORY%% "${@--O0}" /dev/fd/0 <<SOURCE && { "$out" && { rm -f "$out"; true; }; }
+#include "headers"    /* precompiled headers */
+$c
+SOURCE