Skip to content

Commit aa1c066

Browse files
author
Ryan Jacobs
committed
separate and expand flags
1 parent aa4c416 commit aa1c066

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,25 @@ for f in "${comp[@]}"; do
182182
done
183183

184184
# final operations before compilation
185-
final_comp=()
185+
rest=()
186+
flags=()
186187
for f in "${comp[@]}"; do
188+
# skip empty elements
189+
[[ -z "$f" ]] && break
190+
187191
# remove shebangs
188192
if [[ -f "$f" ]] && [[ "$(head -n1 "$f")" == \#\!* ]]; then
189193
echo "$(tail -n +2 "$f")" > "$f"
190194
fi
191195

192-
[[ -n "$f" ]] && final_comp+=("$f")
193-
done
194-
195-
i=0
196-
for c in "${final_comp[@]}"; do
197-
let i++
198-
echo $i "$c"
196+
# separate the flags from other arguments
197+
[[ "$f" =~ ^- ]] &&\
198+
flags+=("$f") ||\
199+
rest+=("$f")
199200
done
200201

201202
# compile and run
202-
if "$CC" -O2 -o "$binname" "${final_comp[@]}" "${includes[@]}"; then
203+
if "$CC" -O2 -o "$binname" ${flags[@]} "${includes[@]}" "${rest[@]}"; then
203204
run "$@"
204205
else
205206
cleanup

tests/examples/test.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,25 @@ header1 "Test #6: Ensure ./examples are running correctly."
77
files=("dns.c" "hello.c" "hello.cpp" "rand.c")
88
returns=(1 0 0 0 1)
99

10-
for i in `seq 0 $((${#files[@]} - 1))`; do
11-
for shebang in $c ""; do
12-
eval $shebang ../examples/${files[$i]}
10+
for shebang in "" "$c"; do
11+
[ -z "$shebang" ] &&\
12+
header2 "using shebang" ||\
13+
header2 "calling directly"
14+
15+
for i in `seq 0 $((${#files[@]} - 1))`; do
16+
cmd="$shebang ../examples/${files[$i]}"
17+
18+
# set CFLAGS for non-shebang
19+
unset cf
20+
[ -n "$shebang" ] && cf="-DRUN -std=c99"
21+
22+
# run cmd
23+
echo $cmd
24+
CFLAGS=$cf eval $cmd
25+
1326
assert "return" "$? -eq ${returns[$i]}"
1427
done
28+
echo
1529
done
1630

1731
echo

tests/test.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
source "./test_helpers.sh"
55

66
# Run tests
7-
#source ./argument_and_link_test/test.sh
8-
#source ./complex_arguments/test.sh
9-
#source ./stdin/test.sh
10-
#source ./C++/test.sh
11-
#source ./shell/test.sh
7+
source ./argument_and_link_test/test.sh
8+
source ./complex_arguments/test.sh
9+
source ./stdin/test.sh
10+
source ./C++/test.sh
11+
source ./shell/test.sh
1212
source ./examples/test.sh
1313

1414
quit

0 commit comments

Comments
 (0)