-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.bat
More file actions
100 lines (85 loc) · 2.28 KB
/
run.bat
File metadata and controls
100 lines (85 loc) · 2.28 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
@echo off
setlocal EnableDelayedExpansion
REM ============================================
REM Donut.cpp – Build & Run launcher
REM ============================================
REM Ensure bin\ exists
if not exist bin mkdir bin
REM --- Compile all sources --------------------
echo.
echo [BUILD] Compiling all sources...
echo.
set BUILD_OK=1
call :compile donut src\donut.cpp
call :compile donut_improved src\donut_improved.cpp
call :compile cube src\cube.cpp
call :compile pyramid src\pyramid.cpp
if "!BUILD_OK!"=="0" (
echo.
echo [WARN] One or more files failed to compile.
)
REM --- Interactive menu loop ------------------
:MENU
echo.
echo ============================================
echo Select a shape to run:
echo 1. Donut (classic)
echo 2. Donut Improved (coloured)
echo 3. Cube
echo 4. Pyramid
echo 0. Exit
echo ============================================
set /p CHOICE=" Your choice: "
set TARGET=
if "%CHOICE%"=="1" set TARGET=donut
if "%CHOICE%"=="2" set TARGET=donut_improved
if "%CHOICE%"=="3" set TARGET=cube
if "%CHOICE%"=="4" set TARGET=pyramid
if "%CHOICE%"=="0" goto :EOF
if not defined TARGET (
echo [ERROR] Invalid choice. Try again.
goto MENU
)
if not exist "bin\%TARGET%.exe" (
echo [ERROR] bin\%TARGET%.exe was not built. Check compiler errors above.
goto MENU
)
echo.
echo [RUN] Running %TARGET%... (press Ctrl+C to stop early)
echo.
"bin\%TARGET%.exe"
REM After the program exits, offer to run again or pick another
:AFTER_RUN
echo.
echo ============================================
echo Done. What next?
echo R. Run the same shape again
echo M. Back to the menu
echo 0. Exit
echo ============================================
set /p NEXT=" Your choice: "
if /i "%NEXT%"=="R" goto :RUN_AGAIN
if /i "%NEXT%"=="M" goto MENU
if "%NEXT%"=="0" goto :EOF
goto AFTER_RUN
:RUN_AGAIN
echo.
echo [RUN] Running %TARGET% again...
echo.
"bin\%TARGET%.exe"
goto AFTER_RUN
REM ============================================
REM Subroutine: compile <name> <source>
REM ============================================
:compile
set NAME=%~1
set SRC=%~2
echo Compiling %SRC% ...
g++ -O2 -o "bin\%NAME%.exe" "%SRC%" -lm 2>&1
if errorlevel 1 (
echo [FAIL] %NAME%
set BUILD_OK=0
) else (
echo [OK] %NAME%
)
exit /b