Repository navigation
Expand file tree
/
Copy pathrun
More file actions
executable file
·71 lines (64 loc) · 1.94 KB
/
Copy pathrun
File metadata and controls
executable file
·71 lines (64 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/zsh
# Copyright 2026 Trevor Stone
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
# Runs an Advent of Code program, with interpreter determined by filename.
# Usage: run [-v] day0/day0.awk day0/input.example.txt day0/input.actual.txt
# run day0/day0.lang checks for a runner script of the form day0/day0lang.sh
# and uses that if the language doesn't have special support. If no runner
# script is found, the named file must be executable.
if [[ $1 == -v ]]; then
verbose=(-v)
shift
else
verbose=()
fi
if (( $# == 0 )); then
print -u 2 "Usage: $0 2001/day1/file 2001/day1/input.example.txt ..."
exit 1
fi
program="$1"
shift
if [[ ! -f "$program" ]]; then
print -u 2 "$program file not found"
exit 1
fi
daydir=${program:h}
langdir=${0:h}/lang
runner=${program:t:r}${program:e}
# make if needed
if [[ -f $daydir/Makefile ]]; then
case $program in
(*)
if make -n -C $daydir bin/$runner > /dev/null 2>&1 ; then
maketarget=bin/$runner
fi
;;
esac
if [[ ! -z $maketarget ]]; then
make --quiet -C $daydir $maketarget || exit $!
fi
fi
case "$program" in
(*.awk) cmd=(gawk --lint=no-ext -i $langdir/awk/runner.gawk -f $program -- $verbose) ;;
(*.fs) cmd=(gforth -e "${#verbose} constant verbose" $program -e bye) ;;
(*.go) cmd=(go run $program ${program:h}/runner.go $verbose) ;;
(*.jq) cmd=($langdir/jq/runjq $verbose $program) ;;
(*.jsonnet) cmd=($langdir/jsonnet/runjsonnet $verbose $program) ;;
(*.rs) export RUST_BACKTRACE=1 ; cmd=($daydir/bin/$runner $verbose) ;;
(*)
if [[ -x "$daydir/$runner" ]]; then
cmd=("$daydir/$runner" $verbose)
elif [[ -x "$daydir/bin/$runner" ]]; then
cmd=("$daydir/bin/$runner" $verbose)
elif [[ -x "$program" ]]; then
cmd=("$program" $verbose)
else
print -u 2 "Don't know how to run $program"
exit 1
fi
;;
esac
exec $cmd "$@"