FreeCalypso > hg > sipout-test-utils
diff test-v22/user_cmd.c @ 10:3c5734b88c20
sipout-test-v22 put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 07 Mar 2024 02:33:49 -0800 |
parents | test-fsk/user_cmd.c@030d52b96a23 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-v22/user_cmd.c Thu Mar 07 02:33:49 2024 -0800 @@ -0,0 +1,58 @@ +/* + * In this module we implement stdin command handling, supporting + * user-initiated CANCEL and BYE. + */ + +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +static void +pcm_fill_cmd(arg) + char *arg; +{ + char *cp; + unsigned octet; + + for (cp = arg; isspace(*cp); cp++) + ; + if (!isxdigit(*cp)) { +inv_syntax: fprintf(stderr, "error: pcm-fill command invalid syntax\n"); + return; + } + octet = strtoul(cp, &cp, 16); + if (*cp) + goto inv_syntax; + if (octet > 0xFF) { + fprintf(stderr, + "error: pcm-fill octet argument out of range\n"); + return; + } + set_pcm_fill_octet(octet); +} + +void +select_stdin() +{ + char buf[256], *cp; + + fgets(buf, sizeof buf, stdin); + cp = index(buf, '\n'); + if (cp) { + while (cp > buf && isspace(cp[-1])) + cp--; + *cp = '\0'; + } + for (cp = buf; isspace(*cp); cp++) + ; + if (!*cp) + return; + if (!strcmp(cp, "b") || !strcasecmp(cp, "bye")) + send_bye_req(); + else if (!strcmp(cp, "c") || !strcasecmp(cp, "cancel")) + send_cancel_req(); + else + fprintf(stderr, "error: non-understood stdin command\n"); +}