-
Notifications
You must be signed in to change notification settings - Fork 2
/
bf2sh.sh
executable file
·74 lines (70 loc) · 831 Bytes
/
bf2sh.sh
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/sh
read LINE
echo PTR=0
N=1
while : ;
do
CH=`echo $LINE | cut -c $N`
N=$(($N + 1))
if [ -z "$CH" ]; then
break
fi
case $CH in
'>' ) cat << 'EOC'
# >
PTR=$(($PTR + 1))
EOC
;;
'<' ) cat << 'EOC'
# <
PTR=$(($PTR - 1))
EOC
;;
'+' ) cat << 'EOC'
# +
VAL=VAL_$PTR
VAL=$(($VAL))
eval VAL_$PTR=$(($VAL + 1))
EOC
;;
'-' ) cat << 'EOC'
# -
VAL=VAL_$PTR
VAL=$(($VAL))
eval VAL_$PTR=$(($VAL - 1))
EOC
;;
'.' ) cat << 'EOC'
# .
VAL=VAL_$PTR
VAL=$(($VAL))
OCH=`echo "obase=8; $VAL" | bc`
OCH=`echo "\0$OCH"`
/bin/echo -n "$OCH"
EOC
;;
',' ) cat << 'EOC'
# ,
# CANT IMPLEMENT
# read VAL
# eval VAL_$PTR=$VAL
EOC
;;
'[' ) cat << 'EOC'
# [
VAL=VAL_$PTR
VAL=$(($VAL))
while [ "$VAL" != "0" ]; do
EOC
;;
']' ) cat << 'EOC'
# ]
VAL=VAL_$PTR
VAL=$(($VAL))
done
EOC
;;
* )
echo $CH;;
esac
done