pmc: add a simple interactive help command.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-08-28 19:16:08 +02:00
parent 81648e81ed
commit afd2a50b5b
1 changed files with 19 additions and 0 deletions

19
pmc.c
View File

@ -277,11 +277,30 @@ static int parse_id(char *s)
return index;
}
static void print_help(FILE *fp)
{
int i;
fprintf(fp, "\n");
for (i = 0; i < ARRAY_SIZE(idtab); i++) {
if (idtab[i].func != not_supported)
fprintf(fp, "\t[action] %s\n", idtab[i].name);
}
fprintf(fp, "\n");
fprintf(fp, "\tThe [action] can be GET, SET, CMD, or COMMAND\n");
fprintf(fp, "\tCommands are case insensitive and may be abbreviated.\n");
fprintf(fp, "\n");
}
static int do_command(char *str)
{
int action, id;
char action_str[10+1] = {0}, id_str[64+1] = {0};
if (0 == strncasecmp(str, "HELP", strlen(str))) {
print_help(stdout);
return 0;
}
if (2 != sscanf(str, " %10s %64s", action_str, id_str))
return -1;