-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
43 lines (42 loc) · 862 Bytes
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include "morsecode.h"
int main(int argc, char *argv[])
{
char *p;
if(argc != 2) {
fprintf(stderr,"usage: %s text\n", argv[0]);
exit(1);
}
init_morse();
play_buzzer(500);
wait_word();
p = argv[1];
while(*p) {
if(*p == ' ')
wait_word();
else {
char *v = char2morse(*p);
printf("character %c translates to %s\n", *p, v);
while(*v) {
switch(*v) {
case '*' : send_dot(); break;
case '=' : send_dash(); break;
default:
/*NOTREACHED*/
fprintf(stderr,"internal logic error\n");
exit(1);
}
if(*(v+1) != '\0')
wait_dot();
else if(*(p+1) == ' ')
wait_word();
else if(*(p+1) != '\0')
wait_letter();
v++;
}
}
p++;
}
return 0;
}