My own rewrite of the BSD morse code recreational utility
Révision | 793788138d47273e8db9c52f6f6f4e3f0dcbdc2e (tree) |
---|---|
l'heure | 2021-08-29 19:52:04 |
Auteur | Joel Matthew Rees <joel.rees@gmai...> |
Commiter | Joel Matthew Rees |
was it morse or really decode?
@@ -122,12 +122,41 @@ const struct punc { | ||
122 | 122 | { '\0', NULL } |
123 | 123 | }; |
124 | 124 | |
125 | -void decode(const char *); | |
126 | 125 | |
127 | 126 | static int sflag; |
128 | 127 | static int dflag; |
129 | 128 | |
130 | 129 | |
130 | +void | |
131 | +decode(s) | |
132 | + const char *s; | |
133 | +{ | |
134 | + int i; | |
135 | + | |
136 | + for (i = 0; i < 10; i++) | |
137 | + if (strcmp(digit[i], s) == 0) { | |
138 | + putchar('0' + i); | |
139 | + return; | |
140 | + } | |
141 | + | |
142 | + for (i = 0; i < 26; i++) | |
143 | + if (strcmp(alph[i], s) == 0) { | |
144 | + putchar('A' + i); | |
145 | + return; | |
146 | + } | |
147 | + i = 0; | |
148 | + while (other[i].c) { | |
149 | + if (strcmp(other[i].morse, s) == 0) { | |
150 | + putchar(other[i].c); | |
151 | + return; | |
152 | + } | |
153 | + i++; | |
154 | + } | |
155 | + if (strcmp("...-.-", s) == 0) | |
156 | + return; | |
157 | + putchar('x'); /* line noise */ | |
158 | +} | |
159 | + | |
131 | 160 | |
132 | 161 | void |
133 | 162 | show(s) |
@@ -250,33 +279,3 @@ main(argc, argv) | ||
250 | 279 | return 0; |
251 | 280 | } |
252 | 281 | |
253 | -void | |
254 | -decode(s) | |
255 | - const char *s; | |
256 | -{ | |
257 | - int i; | |
258 | - | |
259 | - for (i = 0; i < 10; i++) | |
260 | - if (strcmp(digit[i], s) == 0) { | |
261 | - putchar('0' + i); | |
262 | - return; | |
263 | - } | |
264 | - | |
265 | - for (i = 0; i < 26; i++) | |
266 | - if (strcmp(alph[i], s) == 0) { | |
267 | - putchar('A' + i); | |
268 | - return; | |
269 | - } | |
270 | - i = 0; | |
271 | - while (other[i].c) { | |
272 | - if (strcmp(other[i].morse, s) == 0) { | |
273 | - putchar(other[i].c); | |
274 | - return; | |
275 | - } | |
276 | - i++; | |
277 | - } | |
278 | - if (strcmp("...-.-", s) == 0) | |
279 | - return; | |
280 | - putchar('x'); /* line noise */ | |
281 | -} | |
282 | - |