view rvinterf/tmsh/audiocmd.c @ 126:777172bcea3c

fc-tmsh: txpw and txpr implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 19 Feb 2017 09:52:58 +0000
parents 2159f260ed13
children 86e4d8aea021
line wrap: on
line source

/*
 * ETM audio commands
 */

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "limits.h"
#include "localtypes.h"
#include "etm.h"
#include "exitcodes.h"

cmd_audio_load(argc, argv)
	char **argv;
{
	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
	int slen;

	slen = strlen(argv[1]);
	if (slen > 9) {
		printf("error: audio config name is limited to 9 chars\n");
		return(ERROR_USAGE);
	}
	dp = cmdpkt + 1;
	*dp++ = ETM_AUDIO;
	*dp++ = 'L';
	strcpy(dp, argv[1]);
	dp += slen + 1;
	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
	return(0);
}

cmd_audio_save(argc, argv)
	char **argv;
{
	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
	int slen;

	slen = strlen(argv[1]);
	if (slen > 9) {
		printf("error: audio config name is limited to 9 chars\n");
		return(ERROR_USAGE);
	}
	dp = cmdpkt + 1;
	*dp++ = ETM_AUDIO;
	*dp++ = 'S';
	strcpy(dp, argv[1]);
	dp += slen + 1;
	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
	return(0);
}

static struct cmdtab {
	char *cmd;
	int minargs;
	int maxargs;
	int (*func)();
} audio_cmds[] = {
	{"load", 1, 1, cmd_audio_load},
	{"save", 1, 1, cmd_audio_save},
	{0, 0, 0, 0}
};

cmd_audio(argc, argv)
	char **argv;
{
	struct cmdtab *tp;
	int extargs;

	for (tp = audio_cmds; tp->cmd; tp++)
		if (!strcmp(tp->cmd, argv[1]))
			break;
	if (!tp->func) {
		printf("error: no such audio command\n");
		return(ERROR_USAGE);
	}
	extargs = argc - 2;
	if (extargs > tp->maxargs) {
		printf("error: too many arguments\n");
		return(ERROR_USAGE);
	}
	if (extargs < tp->minargs) {
		printf("error: too few arguments\n");
		return(ERROR_USAGE);
	}
	return tp->func(argc - 1, argv + 1);
}