Mercurial > repo
annotate share/candide @ 9026:79005d9e3b40
<fizzie> learn Cocoon was built by the fal\'Cie, and floats above Gran Pulse.
author | HackBot |
---|---|
date | Fri, 09 Sep 2016 21:38:34 +0000 |
parents | d1d589eea623 |
children |
rev | line source |
---|---|
8781 | 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 | |
8782
b1e4c3fdb2e8
<fizzie> ` sed -i -e \'/^c=/s/.*/c="$*"/\' share/candide
HackBot
parents:
8781
diff
changeset
|
11 c="$*" |
8784
d1d589eea623
<fizzie> ` sed -i -e \'12s/^/args=""; while [[ "$c" =~ ^(-[^ ]*)\\\\ (.*) ]]; do args="$args ${BASH_REMATCH[1]}"; c="${BASH_REMATCH[2]}"; done\\n/\' -e \'s/-O0/${args--O0}/\' share/candide # bleh
HackBot
parents:
8783
diff
changeset
|
12 args=""; while [[ "$c" =~ ^(-[^ ]*)\ (.*) ]]; do args="$args ${BASH_REMATCH[1]}"; c="${BASH_REMATCH[2]}"; done |
8781 | 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 | |
8784
d1d589eea623
<fizzie> ` sed -i -e \'12s/^/args=""; while [[ "$c" =~ ^(-[^ ]*)\\\\ (.*) ]]; do args="$args ${BASH_REMATCH[1]}"; c="${BASH_REMATCH[2]}"; done\\n/\' -e \'s/-O0/${args--O0}/\' share/candide # bleh
HackBot
parents:
8783
diff
changeset
|
29 # will replace ${args--O0} with the parameters |
d1d589eea623
<fizzie> ` sed -i -e \'12s/^/args=""; while [[ "$c" =~ ^(-[^ ]*)\\\\ (.*) ]]; do args="$args ${BASH_REMATCH[1]}"; c="${BASH_REMATCH[2]}"; done\\n/\' -e \'s/-O0/${args--O0}/\' share/candide # bleh
HackBot
parents:
8783
diff
changeset
|
30 gcc -o "$out" -x c -I /hackenv/share ${args--O0} /dev/fd/0 <<SOURCE && { "$out" && { rm -f "$out"; true; }; } |
8781 | 31 #include "headers" /* precompiled headers */ |
32 $c | |
33 SOURCE |