forked from esjeon/hack-alienfx
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrunseq.c
54 lines (40 loc) · 748 Bytes
/
runseq.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
44
45
46
47
48
49
50
51
52
53
54
#include "functions.h"
int main() {
unsigned char buf[9];
char *line;
int ret;
if(init_device() != 0)
return 1;
while(1) {
line = readline("> ");
if(line == NULL)
break;
if(line[0] == '#') /* comment */
goto skip_line;
if(line[0] == 'q') /* quit */
break;
if(line[0] == 'w') /* wait */ {
usleep(100000);
goto skip_line;
}
ret = parse_bytes(line, buf);
if(ret != 0) {
fprintf(stderr, "Error: invalid input - \"%s\"\n", line);
break;
}
ret = send_message(buf);
if(ret != 0) {
fprintf(stderr, "Error: failed to send message\n");
break;
}
add_history(line);
skip_line:
free(line);
line = NULL;
}
if(line)
free(line);
deinit_device();
printf("\n");
return ret;
}