Added 'list-devices' menu.
This commit is contained in:
parent
36accb7eb8
commit
aa148554fc
|
@ -136,6 +136,12 @@ static const char help_info[] =
|
|||
"Dump information about the calculator.\n"
|
||||
FOOT;
|
||||
|
||||
/* List serial devices */
|
||||
static const char help_listcom[] =
|
||||
"Usage: " QUOTE(BIN) " list-devices\n"
|
||||
"List serial devices.\n"
|
||||
FOOT;
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
|
@ -255,6 +261,10 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
} else if (!strcmp(aav[0], "version")) {
|
||||
puts(version_message);
|
||||
return (0);
|
||||
} else if (!strcmp(aav[0], "list-devices")) {
|
||||
if (help || aac > 1) puts(help_listcom);
|
||||
else list_devices();
|
||||
return (0);
|
||||
} else if (!strcmp(aav[0], "info")) {
|
||||
sub_init(info, 0)
|
||||
} else if (!strcmp(aav[0], "list") || !strcmp(aav[0], "ls")) {
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/* ************************************************************************** */
|
||||
/* _____ _ */
|
||||
/* p7/list_devices.c |_ _|__ _ _| |__ ___ _ _ */
|
||||
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
|
||||
/* | | (_) | |_| | | | | __/ |_| | */
|
||||
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
||||
/* Last updated: 2017/02/09 17:55:40 |___/ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* list_a_device:
|
||||
* List one serial device.
|
||||
*
|
||||
* @arg cookie the cookie (unused)
|
||||
* @arg path the path.
|
||||
*/
|
||||
|
||||
static int initialized = 0;
|
||||
static void list_a_device(void *cookie, const char *path)
|
||||
{
|
||||
(void)cookie;
|
||||
if (!initialized) {
|
||||
printf("Available devices:\n");
|
||||
initialized = 1;
|
||||
}
|
||||
printf("- %s\n", path);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_devices:
|
||||
* List serial devices.
|
||||
*
|
||||
* @return the program return code.
|
||||
*/
|
||||
|
||||
int list_devices(void)
|
||||
{
|
||||
p7_comlist(list_a_device, NULL);
|
||||
if (!initialized)
|
||||
fprintf(stderr, "Could not find any devices.\n");
|
||||
return (0);
|
||||
}
|
|
@ -42,6 +42,9 @@ typedef struct {
|
|||
/* Parsing function */
|
||||
int parse_args(int ac, char **av, args_t *args);
|
||||
|
||||
/* List devices function */
|
||||
int list_devices(void);
|
||||
|
||||
/* Dumping function */
|
||||
int dump(p7_handle_t *handle);
|
||||
|
||||
|
|
Reference in New Issue