Tidy the usaco CLI: prefixes everywhere, LOCAL debug builds, git-based dates
- done/skip/undo accept unique prefixes like every other command - builds define LOCAL (-I repo root): the template includes debugging.h and enables DBG/printV only locally, so main.cpp is submittable as-is - run/build/test --debug (or USACO_DEBUG=1): ASan/UBSan + _GLIBCXX_DEBUG - list/stats date problems by git history, not mtimes reset by checkouts - template/tpl is now an alias of reset (which gains -y); fixes template dropping the STDIO line - run shows <io>.out via detect_io instead of the first *.out - debugging.h: size_t loop indices (no -Wsign-compare noise) - zsh completion for i/cat/copy; README covers test, io, reset, --debug - ignore a.out Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+29
-2
@@ -1,7 +1,10 @@
|
||||
# common.sh - shared helpers for usaco commands (sourced, not executed)
|
||||
# Expects ROOT to be set by the dispatcher.
|
||||
|
||||
CXXFLAGS=(-O2 -std=c++17 -Wall -Wextra)
|
||||
# -DLOCAL turns on the template's debugging.h include and DBG macros (judges don't define it)
|
||||
CXXFLAGS=(-O2 -std=c++17 -Wall -Wextra -DLOCAL -I"$ROOT")
|
||||
# --debug (or USACO_DEBUG=1): catch out-of-bounds, overflow and UB at runtime
|
||||
DEBUG_CXXFLAGS=(-g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -D_GLIBCXX_DEBUG)
|
||||
|
||||
find_problem() { # echoes dir of problem in solving/, solved/, or skipped/; unique prefix ok
|
||||
local name="$1" s d matches=()
|
||||
@@ -24,7 +27,12 @@ find_problem() { # echoes dir of problem in solving/, solved/, or skipped/; uni
|
||||
}
|
||||
|
||||
build_problem() { # $1 = problem dir
|
||||
g++ "${CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main"
|
||||
if [[ -n "${USACO_DEBUG:-}" ]]; then
|
||||
echo "${DIM}(debug build: sanitizers on)${RST}" >&2
|
||||
g++ "${CXXFLAGS[@]}" "${DEBUG_CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main"
|
||||
else
|
||||
g++ "${CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main"
|
||||
fi
|
||||
}
|
||||
|
||||
detect_io() { # echoes the io basename (first *.in in $1), or nothing
|
||||
@@ -33,6 +41,25 @@ detect_io() { # echoes the io basename (first *.in in $1), or nothing
|
||||
return 1
|
||||
}
|
||||
|
||||
last_touched() { # $1 = problem dir: epoch of its last change
|
||||
# uncommitted work counts as "now"-ish (newest mtime); otherwise the last commit.
|
||||
# File mtimes alone are useless here: every checkout/pull resets them.
|
||||
local t
|
||||
if [[ -n "$(git -C "$ROOT" status --porcelain -- "$1" 2>/dev/null)" ]]; then
|
||||
find "$1" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1
|
||||
elif t="$(git -C "$ROOT" log -1 --format=%ct -- "$1" 2>/dev/null)" && [[ -n "$t" ]]; then
|
||||
echo "$t"
|
||||
else
|
||||
find "$1" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1
|
||||
fi
|
||||
}
|
||||
|
||||
solved_at() { # $1 = solved/<name> dir: epoch it (last) entered solved/
|
||||
local t
|
||||
t="$(git -C "$ROOT" log -1 --diff-filter=A --format=%ct -- "$1" 2>/dev/null)"
|
||||
[[ -n "$t" ]] && echo "$t" || last_touched "$1"
|
||||
}
|
||||
|
||||
fresh_main() { # $1 = problem dir, $2 = io name: main.cpp from template with STDIO wired up
|
||||
sed "s/^int main() {$/int main() {\n STDIO(\"$2\");/" "$ROOT/template.cpp" > "$1/main.cpp"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user