-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontroller.sh
More file actions
74 lines (66 loc) · 1.73 KB
/
controller.sh
File metadata and controls
74 lines (66 loc) · 1.73 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
#!/bin/zsh
FIFO_PATH="/tmp/physics_fifo"
if [ ! -p "$FIFO_PATH" ]; then
echo "FIFO does not exist: $FIFO_PATH"
exit 1
fi
while true; do
echo "Enter command in the format:"
echo " add <shapeType (C/S)> <Name> <Size> <X_position> <Y_position> <X_velocity> <Y_velocity>"
echo " remove <Name>"
echo " set gravity <value>"
echo " set coe <value>"
echo " random <count>"
echo " clear"
echo " exit"
printf "> "
read -r INPUT
if [[ "$INPUT" == "exit" ]]; then
echo "Exiting..."
break
fi
COMMAND=$(echo "$INPUT" | awk '{print $1}')
case "$COMMAND" in
add)
ARG_COUNT=$(echo "$INPUT" | wc -w)
if [ "$ARG_COUNT" -ne 8 ]; then
echo "Invalid 'add' command format. Expected 7 arguments after 'add'."
continue
fi
;;
remove)
ARG_COUNT=$(echo "$INPUT" | wc -w)
if [ "$ARG_COUNT" -ne 2 ]; then
echo "Invalid 'remove' command format. Expected 1 argument after 'remove'."
continue
fi
;;
set)
ARG_COUNT=$(echo "$INPUT" | wc -w)
if [ "$ARG_COUNT" -ne 3 ]; then
echo "Invalid 'set' command format. Expected 2 arguments after 'set'."
continue
fi
;;
random)
ARG_COUNT=$(echo "$INPUT" | wc -w)
if [ "$ARG_COUNT" -ne 2 ]; then
echo "Invalid 'random' command format. Expected 1 argument after 'random'."
continue
fi
;;
clear)
ARG_COUNT=$(echo "$INPUT" | wc -w)
if [ "$ARG_COUNT" -ne 1 ]; then
echo "Invalid 'clear' command format. No arguments expected after 'clear'."
continue
fi
;;
*)
echo "Unknown command: $COMMAND"
continue
;;
esac
echo "$INPUT" > "$FIFO_PATH"
echo "Command sent: $INPUT"
done