• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

My own rewrite of the BSD morse code recreational utility


Commit MetaInfo

Revisão27e89af5bab875e5d53b6057109c0dd7237e62ed (tree)
Hora2021-08-29 21:25:53
AutorJoel Matthew Rees <joel.rees@gmai...>
CommiterJoel Matthew Rees

Mensagem de Log

first step not working right

Mudança Sumário

Diff

--- a/bsdmorseplus.c
+++ b/bsdmorseplus.c
@@ -122,11 +122,94 @@ const struct punc {
122122 { '\0', NULL }
123123 };
124124
125+char errorcode[] = "........"; /* JMR20210829 */
126+
127+
128+/* JMR20210829 */
129+const char *
130+tomorseif(c)
131+ int c;
132+{
133+ int i;
134+
135+ if (isalpha(c))
136+ return alph[c - (isupper(c)) ? 'A' : 'a'];
137+ else if (isdigit(c))
138+ return digit[c - '0'];
139+ else if (isspace(c))
140+ return " "; /* BT has a different purpose. */
141+ else {
142+ for ( i = 0; other[i].c; ++i ) {
143+ if (other[i].c == c) {
144+ return other[i].morse ;
145+ }
146+ }
147+ }
148+ return errorcode;
149+}
150+
125151
126152 static int sflag;
153+
154+/* JMR20210829 */
155+static char vocbuf[ 8 * 4 + 1 ]; /* Enough to copy errorcode[] */
156+
157+const char *
158+tovocalmorse( code )
159+ const char * code;
160+{
161+ if (sflag)
162+ return code;
163+ else {
164+ char * insertion = vocbuf;
165+ while ( *code ) {
166+ const char * conv = (*code == '.')
167+ ? "dit"
168+ : (*code == '-') ? "daw" : " ";
169+ strcpy(insertion, conv);
170+ insertion += strlen(conv);
171+ if ( *++code == '\0' )
172+ break;
173+ * insertion++ = ' ';
174+ }
175+ * insertion++ = '\n';
176+ * insertion = '\0';
177+ return vocbuf;
178+ }
179+}
180+
181+
127182 static int dflag;
128183
129184
185+/* JMR20210829 */
186+int
187+totextif(s)
188+ const char *s;
189+{
190+ int i;
191+
192+ for (i = 0; i < 10; i++)
193+ if (strcmp(digit[i], s) == 0) {
194+ return '0' + i;
195+ }
196+
197+ for (i = 0; i < 26; i++)
198+ if (strcmp(alph[i], s) == 0) {
199+ return 'A' + i;
200+ }
201+ i = 0;
202+ while (other[i].c) {
203+ if (strcmp(other[i].morse, s) == 0) {
204+ return other[i].c;
205+ }
206+ i++;
207+ }
208+ if (strcmp("...-.-", s) == 0) /* Why SK but no KA? */
209+ return '\n';
210+ return 'x'; /* line noise */
211+}
212+
130213 void
131214 decode(s)
132215 const char *s;
@@ -226,8 +309,11 @@ main(argc, argv)
226309
227310 if (dflag) {
228311 if (*argv) {
312+ char outstr;
229313 do {
230- decode(*argv);
314+/* decode(*argv); */
315+ outstr = totextif( argv );
316+ putchar( outstr );
231317 } while (*++argv);
232318 } else {
233319 char foo[10]; /* All morse chars shorter than this */