9075
|
1 #!/bin/bash
|
|
2 # compile c from stdin
|
|
3 # candide, kinda
|
|
4
|
|
5 readinput () {
|
|
6 while read -r -e || { printf %s "$REPLY"; false; } ; do
|
|
7 printf '%s\n' "$REPLY"
|
|
8 done
|
|
9 }
|
|
10
|
|
11 c="$*"
|
|
12 args=""; while [[ "$c" =~ ^(-[^ ]*)\ (.*) ]]; do args="$args ${BASH_REMATCH[1]}"; c="${BASH_REMATCH[2]}"; done
|
|
13 if ! [[ $c ]] || ! out=$(mktemp); then
|
|
14 echo Error >&2
|
|
15 exit 1
|
|
16 fi
|
|
17
|
|
18 # if you don't write 'main' it assumes that you're writing a full program (with free includes)
|
|
19 # this allows you to use other functions and stuff
|
|
20 # it will get false positives, but who cares?
|
|
21 if [[ $c != *main* ]]; then c=$(cat <<SOURCE
|
|
22 int main(int argc, char *argv[]) {
|
|
23 $c
|
|
24 return 0;
|
|
25 }
|
|
26 SOURCE
|
|
27 ); fi
|
|
28
|
|
29 # will replace ${args--O0} with the parameters
|
|
30 gcc -o "$out" -x c -I /hackenv/share ${args--O0} /dev/fd/0 <<SOURCE && { "$out" && { rm -f "$out"; true; }; }
|
|
31 #include "headers" /* precompiled headers */
|
|
32 $c
|
|
33 SOURCE
|