-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ю⎔⎔
executable file
·109 lines (94 loc) · 2 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
101
102
103
104
105
106
107
108
109
#!/bin/bash
HEADER=$(cat <<HEADER
᛭ᛋᚴᛁᛒᛅ ≨stdio᛫h≩
᛭ᚱᛁᛋᛏᛅ писать«…» printf«ᚼᛚᚢᛏᛅᚱ»
᛭ᚱᛁᛋᛏᛅ получатзнак«» getchar«»
HEADER
)
SUBS=$(cat <<SUBS
⌂→ℤmain
«→(
»→)
☹→{
☺→}
[“”]→\"
[‘’]→'
❝→\/*
❞→*\/
¦→,
।→;
⨢→+
−→-
×→*
÷→\/
←→=
ℤ→int
␊→\\\n
SUBS
)
NEW=$(cat <<NEW
≤→<=
≥→>=
≨→<
≩→>
﹪ℤ→%i
﹪ቁምፊ→%c
،→,
﹪→%
⇔→==
¿→if
¬→else
∀→for
∆→++
∇→--
∨→||
∧→&&
ቁምፊ→char
NEW
)
PRE=$(cat <<PRE
᛫→.
…→...
᛭ᚱᛁᛋᛏᛅ→#define
᛭ᛋᚴᛁᛒᛅ→#include
ᚼᛚᚢᛏᛅᚱ→__VA_ARGS__
PRE
)
OCTAL=☰☱☲☳☴☵☶☷
DECIMAL=᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙
numlist () {
out='';i=0
for char in $(sed "s/\(.\)/\1 \
/g" <<<$1); do
out+=$"${char}→$((i++))\n"
done
echo -e "$out"
}
used () {
sed 's/^ *\([^→]*\)→\(.*\)$/s\/\1\/\2\/g;/g;' <<<"$1"
}
ucn_ids () {
for ident in $(LC_ALL=POSIX egrep '^#|int|char' <<<"$1" |LC_ALL=POSIX egrep -o '[^ -~]*'); do
rep=$(echo -n $(iconv -futf8 -tutf16be <<<$ident) | xxd -p | sed 's/\([0-9a-f]\{4\}\)/\\\\u\1/g')
csource="$(sed "s/$ident/$rep/g" <<<"$csource")"
done
}
main () {
# Get Юᓂ곧⎔ source file to compile + options to pass to gcc
echo "⎔⎔ing $1 ..."
source=$(cat $1)
shift
replacements+=$(used "$PRE")
replacements+=$(used "$NEW")
replacements+=$(used "$SUBS")
replacements+=$(used "$(numlist $OCTAL)")
replacements+=$(used "$(numlist $DECIMAL)")
# octal digit escaping
source="$(sed 's/⁌\(['"$OCTAL"']\)/\\\1/g;s/⁍//g;' <<<"$source")"
csource="$(sed "${replacements}" <<<"$HEADER"$'\n'"$source")"
ucn_ids "$csource"
if gcc $@ -fextended-identifiers -std=c99 -w -xc <(echo "$csource"); then
echo Done!
fi
}
main $@