-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwmcconv
executable file
·181 lines (174 loc) · 8.87 KB
/
pwmcconv
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
# This script's framework was created using makescript
# version v1.0.3, dated 2019-07-19
# Makescript and its accompanying scripts are copyrighted
# by Aetesaki (c) 2018
#
# letterconv (c) 2019 aetesaki
#
# ##################################################
# HISTORY:
# ##################################################
#
# * 2019-07-21 - v0.0.0 - First Creation
# * 2019-07-21 - v1.0.0 - First release
# * 2019-07-25 - v1.0.1 - converting letterconv to pwmcconv
#
# ##################################################
# Initializing constants and variables
# ##################################################
# Setting constants
version="v1.0.1" # Sets version variable
lastEdited="2019-07-25" # Sets last edited variable
[ ! -t 0 ] && pipe=$(cat) # if stdin is open dump stdin to $pipe
# Declaring variables
declare conv # converted letter
# Declare array
declare -A letter
# Declare all variables to be used in the script
# ##################################################
# short help function
# ##################################################
shorthelp() {
# Edit as required
cat << EOF
Usage: pwmcconv [letter or sign]
pwmcconv --help
pwmcconv --version"
EOF
}
# ##################################################
# no arguments gives short help
# ##################################################
# if number of arguments is 0
if [ "$#" == "0" ]; then
# if length of $pipe is 0
if [ -z "$pipe" ]; then
# display shorthelp and exit
shorthelp
exit 1
else
# else set arguments to $pipe
set -- "$pipe"
fi
fi
# ##################################################
# -- help
# ##################################################
# if the first argument is --help
if [ "$1" == "--help" ]; then
shorthelp
# Write options and explanations
cat << EOF
pwmcconv converts a single Delang letter or sign to Illomi Pulse
Width Modulation Code, a pulse width modulation code akin to Samuel
Morse's pulse width modulation code which bares his name (morse code)
Note that the delang letters L, Z, and z, has to be prefixed with
del.
The following signs displays special codes:
% (SHIFT)
^ (START/END OF TRANSMISSION)
= or + (EMERGENCY)
~ (ATTENTION)
Punctuation must be converted as following
. (PERIOD) %.%
, (COMMA) %,%
? (QUESTION MARK) %?%
! (EXCLAMATION MARK) %%%
--help Displays this text and exit.
--version Displays the version of the script and exit.
EOF
# Write information on arguments afterwards
# Write examples as required
exit 0
fi
# ##################################################
# -- version
# ##################################################
# if the first argument is --version
if [ "$1" == "--version" ]; then
# display the version text
cat << EOF
pwmcconv ${version}, dated ${lastEdited}
(c) 2019 aetesaki
EOF
exit 0
fi
# ##################################################
# Array setup section
# ##################################################
# Delang to pwmcconv
letter["А"]="▄▄"; letter["а"]="▄▄"
letter["Ҩ"]="▄▄ ▄▄▄▄ ▄▄"; letter["ҩ"]="▄▄ ▄▄▄▄ ▄▄"
letter["Б"]="▄▄▄▄ ▄▄ ▄▄ ▄▄ ▄▄"; letter["б"]="▄▄▄▄ ▄▄ ▄▄ ▄▄ ▄▄"
letter["З"]="▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄"; letter["з"]="▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄"
letter["Δ"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄"; letter["δ"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄"
letter["Е"]="▄▄ ▄▄"; letter["е"]="▄▄ ▄▄"
letter["Є"]="▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄"; letter["є"]="▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄"
letter["F"]="▄▄ ▄▄▄▄"; letter["ƒ"]="▄▄ ▄▄▄▄"
letter["Г"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄ ▄▄"; letter["г"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄ ▄▄"
letter["Ƕ"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄"; letter["ƕ"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄"
letter["І"]="▄▄▄▄"; letter["і"]="▄▄▄▄"
letter["Ј"]="▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄"; letter["ј"]="▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄"
letter["К"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄"; letter["к"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄"
letter["Л"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄"; letter["л"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄"
letter["Љ"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄"; letter["љ"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄"
letter["М"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄"; letter["м"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
letter["Н"]="▄▄▄▄ ▄▄ ▄▄▄▄"; letter["н"]="▄▄▄▄ ▄▄ ▄▄▄▄"
letter["Њ"]="▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄"; letter["њ"]="▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄"
letter["О"]="▄▄ ▄▄ ▄▄ ▄▄"; letter["о"]="▄▄ ▄▄ ▄▄ ▄▄"
letter["П"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"; letter["п"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
letter["Ь"]="▄▄▄▄ ▄▄▄▄ ▄▄"; letter["Ь"]="▄▄▄▄ ▄▄▄▄ ▄▄"
letter["Ҍ"]="▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄"; letter["ҍ"]="▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄"
letter["del L"]="▄▄▄▄ ▄▄▄▄"; letter["ł"]="▄▄▄▄ ▄▄▄▄"
letter["Ѕ"]="▄▄ ▄▄ ▄▄ ▄▄ ▄▄"; letter["ѕ"]="▄▄ ▄▄ ▄▄ ▄▄ ▄▄"
letter["del Z"]="▄▄▄▄ ▄▄ ▄▄ ▄▄ ▄▄▄▄"; letter["del z"]="▄▄▄▄ ▄▄ ▄▄ ▄▄ ▄▄▄▄"
letter["Т"]="▄▄▄▄ ▄▄"; letter["т"]="▄▄▄▄ ▄▄"
letter["И"]="▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄"; letter["и"]="▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄"
letter["В"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄"; letter["в"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄"
letter["Ѡ"]="▄▄ ▄▄▄▄ ▄▄▄▄"; letter["ѡ"]="▄▄ ▄▄▄▄ ▄▄▄▄"
letter["Р"]="▄▄▄▄ ▄▄ ▄▄ ▄▄"; letter["р"]="▄▄▄▄ ▄▄ ▄▄ ▄▄"
letter["Y"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄▄▄"; letter["y"]="▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄▄▄"
letter["С"]="▄▄ ▄▄ ▄▄"; letter["с"]="▄▄ ▄▄ ▄▄"
letter["Ҫ"]="▄▄ ▄▄▄▄ ▄▄ ▄▄"; letter["ҫ"]="▄▄ ▄▄▄▄ ▄▄ ▄▄"
letter["ツ"]="▄▄▄▄ ▄▄ ▄▄"
letter["つ"]="▄▄ ▄▄ ▄▄▄▄ ▄▄▄▄"
letter["〶"]="▄▄ ▄▄ ▄▄▄▄ ▄▄▄▄"
# shift
letter["%"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
# start of transmission
letter["^"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
# emergency codes
letter["="]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
letter["+"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
# attention code
letter["!"]="▄▄ ▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄ ▄▄"
# numbers
letter["1"]="▄▄"
letter["2"]="▄▄ ▄▄"
letter["3"]="▄▄ ▄▄ ▄▄"
letter["4"]="▄▄ ▄▄ ▄▄ ▄▄"
letter["5"]="▄▄ ▄▄ ▄▄ ▄▄ ▄▄"
letter["6"]="▄▄▄▄ ▄▄"
letter["7"]="▄▄▄▄ ▄▄ ▄▄"
letter["8"]="▄▄▄▄ ▄▄ ▄▄ ▄▄"
letter["9"]="▄▄▄▄ ▄▄ ▄▄ ▄▄ ▄▄"
letter["0"]="▄▄▄▄ ▄▄▄▄"
# punctuation
letter["%.%"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
letter["%,%"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
letter["%?%"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
letter["%%%"]="▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄"
# ##################################################
# Main section
# ##################################################
# Write your script here
# convert the letter
conv=${letter["$@"]}
# if $conv is empty
if [ -z "$conv" ]; then
# display error message and exit
echo "$@ is not a valid letter." >&2
exit 1
fi
echo $conv