view mtctest/user_cmd.c @ 8:a902ccbf6bbc

mtctest: introduce general user command structure
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 02:48:55 +0000
parents
children aa2ba9b432af
line wrap: on
line source

/*
 * In this module we implement stdin command handling: we start with
 * 'disc' command for caller-initiated disconnect, and then we'll add
 * play commands for RTP output.
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

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, "disc"))
		disconnect_command();
	else
		fprintf(stderr, "error: non-understood stdin command\n");
}