My own rewrite of the BSD morse code recreational utility
Revision | b9a88d7c2576f91f49923ae02c1c4266b21a7437 (tree) |
---|---|
Time | 2021-08-29 19:49:35 |
Author | Joel Matthew Rees <joel.rees@gmai...> |
Commiter | Joel Matthew Rees |
morse()
@@ -122,10 +122,7 @@ const struct punc { | ||
122 | 122 | { '\0', NULL } |
123 | 123 | }; |
124 | 124 | |
125 | -int main(int, char *[]); | |
126 | -void morse(int); | |
127 | 125 | void decode(const char *); |
128 | -/* void show(const char *); */ | |
129 | 126 | |
130 | 127 | static int sflag; |
131 | 128 | static int dflag; |
@@ -144,6 +141,33 @@ show(s) | ||
144 | 141 | } |
145 | 142 | |
146 | 143 | |
144 | +void | |
145 | +morse(c) | |
146 | + int c; | |
147 | +{ | |
148 | + int i; | |
149 | + | |
150 | + if (isalpha(c)) | |
151 | + show(alph[c - (isupper(c) ? 'A' : 'a')]); | |
152 | + else if (isdigit(c)) | |
153 | + show(digit[c - '0']); | |
154 | + else if (isspace(c)) | |
155 | + show(""); /* could show BT for a pause */ | |
156 | + else { | |
157 | + i = 0; | |
158 | + while (other[i].c) { | |
159 | + if (other[i].c == c) { | |
160 | + show(other[i].morse); | |
161 | + break; | |
162 | + } | |
163 | + i++; | |
164 | + } | |
165 | + } | |
166 | +} | |
167 | + | |
168 | + | |
169 | +int main(int, char *[]); | |
170 | + | |
147 | 171 | int |
148 | 172 | main(argc, argv) |
149 | 173 | int argc; |
@@ -256,27 +280,3 @@ decode(s) | ||
256 | 280 | putchar('x'); /* line noise */ |
257 | 281 | } |
258 | 282 | |
259 | -void | |
260 | -morse(c) | |
261 | - int c; | |
262 | -{ | |
263 | - int i; | |
264 | - | |
265 | - if (isalpha(c)) | |
266 | - show(alph[c - (isupper(c) ? 'A' : 'a')]); | |
267 | - else if (isdigit(c)) | |
268 | - show(digit[c - '0']); | |
269 | - else if (isspace(c)) | |
270 | - show(""); /* could show BT for a pause */ | |
271 | - else { | |
272 | - i = 0; | |
273 | - while (other[i].c) { | |
274 | - if (other[i].c == c) { | |
275 | - show(other[i].morse); | |
276 | - break; | |
277 | - } | |
278 | - i++; | |
279 | - } | |
280 | - } | |
281 | -} | |
282 | - |