annotate mtctest/user_cmd.c @ 11:aa2ba9b432af

mtctest: implement play and play-stop commands
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 04:32:57 +0000
parents a902ccbf6bbc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
11
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
2 * In this module we implement stdin command handling: 'disc' command
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
3 * for caller-initiated disconnect; 'play' and 'play-stop' commands
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
4 * for RTP output.
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
11
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
13 static void
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
14 play_cmd(args)
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
15 char *args;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
16 {
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
17 char *cp, *filename;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
18 unsigned frame_len;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
19 int loop;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
20
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
21 for (cp = args; isspace(*cp); cp++)
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
22 ;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
23 if (!*cp) {
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
24 inv_syntax: fprintf(stderr, "error: play command invalid syntax\n");
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
25 return;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
26 }
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
27 for (filename = cp; *cp && !isspace(*cp); cp++)
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
28 ;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
29 if (!*cp)
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
30 goto inv_syntax;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
31 *cp++ = '\0';
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
32 while (isspace(*cp))
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
33 cp++;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
34 if (!isdigit(*cp))
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
35 goto inv_syntax;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
36 frame_len = strtoul(cp, &cp, 0);
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
37 if (*cp && !isspace(*cp))
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
38 goto inv_syntax;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
39 if (frame_len < 1 || frame_len > 160) {
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
40 fprintf(stderr, "error: frame length argument out of range\n");
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
41 return;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
42 }
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
43 while (isspace(*cp))
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
44 cp++;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
45 if (*cp) {
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
46 if (strcmp(cp, "loop"))
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
47 goto inv_syntax;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
48 loop = 1;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
49 } else
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
50 loop = 0;
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
51 play_file_cmdop(filename, frame_len, loop);
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
52 }
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
53
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 void
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 select_stdin()
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 char buf[256], *cp;
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 fgets(buf, sizeof buf, stdin);
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 cp = index(buf, '\n');
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (cp) {
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 while (cp > buf && isspace(cp[-1]))
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 cp--;
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 *cp = '\0';
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 for (cp = buf; isspace(*cp); cp++)
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 ;
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (!*cp)
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return;
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!strcmp(cp, "disc"))
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 disconnect_command();
11
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
72 else if (!strncmp(cp, "play", 4) && isspace(cp[4]))
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
73 play_cmd(cp + 5);
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
74 else if (!strcmp(cp, "play-stop"))
aa2ba9b432af mtctest: implement play and play-stop commands
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
75 play_file_stop();
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 else
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(stderr, "error: non-understood stdin command\n");
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }