8778
|
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=$(readinput)
|
|
12 if ! [[ $c ]] || ! out=$(mktemp); then
|
|
13 echo Error >&2
|
|
14 exit 1
|
|
15 fi
|
|
16
|
|
17 # if you don't write 'main' it assumes that you're writing a full program (with free includes)
|
|
18 # this allows you to use other functions and stuff
|
|
19 # it will get false positives, but who cares?
|
|
20 if [[ $c != *main* ]]; then c=$(cat <<SOURCE
|
|
21 int main(int argc, char *argv[]) {
|
|
22 $c
|
|
23 return 0;
|
|
24 }
|
|
25 SOURCE
|
|
26 ); fi
|
|
27
|
|
28 # will replace -O0 with the parameters
|
|
29 gcc -o "$out" -x c -I /hackenv "${@--O0}" /dev/fd/0 <<SOURCE && { "$out" && { rm -f "$out"; true; }; }
|
|
30 #include "headers" /* precompiled headers */
|
|
31 $c
|
|
32 SOURCE
|