-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·63 lines (50 loc) · 2.61 KB
/
run.sh
File metadata and controls
executable file
·63 lines (50 loc) · 2.61 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
#!/usr/bin/env bash
# run.sh — Linux wrapper for cobol-safe-translator
# Usage: ./run.sh [path/to/program.cob]
# Default: samples/hello.cob
set -euo pipefail
# ── Resolve project root ──────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── Check Python 3.11+ ───────────────────────────────────────────
if ! command -v python3 &>/dev/null; then
echo "ERROR: python3 not found on PATH." >&2
exit 1
fi
PY_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PY_MAJOR=$(echo "$PY_VERSION" | cut -d. -f1)
PY_MINOR=$(echo "$PY_VERSION" | cut -d. -f2)
if [ "$PY_MAJOR" -lt 3 ] || { [ "$PY_MAJOR" -eq 3 ] && [ "$PY_MINOR" -lt 11 ]; }; then
echo "ERROR: Python 3.11+ required (found $PY_VERSION)." >&2
exit 1
fi
# ── Check cobol2py is installed ───────────────────────────────────
if ! command -v cobol2py &>/dev/null; then
echo "ERROR: cobol2py not found. Install with: pip install -e ." >&2
exit 1
fi
# ── Determine input file ─────────────────────────────────────────
COBOL_FILE="${1:-samples/hello.cob}"
if [ ! -f "$COBOL_FILE" ]; then
echo "ERROR: File not found: $COBOL_FILE" >&2
exit 1
fi
# ── Derive output directory from filename ─────────────────────────
BASENAME="$(basename "$COBOL_FILE" | sed 's/\.[^.]*$//')"
OUT_DIR="output/${BASENAME}"
echo "=== cobol-safe-translator ==="
echo "Input: $COBOL_FILE"
echo "Output: $OUT_DIR/"
echo ""
# ── Run translate ─────────────────────────────────────────────────
echo "--- Translating to Python skeleton ---"
cobol2py translate "$COBOL_FILE" --output "$OUT_DIR"
echo ""
# ── Run map ───────────────────────────────────────────────────────
echo "--- Generating analysis reports ---"
cobol2py map "$COBOL_FILE" --output "$OUT_DIR"
echo ""
# ── Show output files ─────────────────────────────────────────────
echo "=== Done ==="
echo "Output files:"
ls -1 "$OUT_DIR/"