2016-07-18 00:11:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 - EATON
|
2011-09-29 18:14:46 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2016-07-18 00:11:41 +00:00
|
|
|
/*! \file nutscan-display.c
|
|
|
|
\brief format and display scanned devices
|
|
|
|
\author Frederic Bohe <fredericbohe@eaton.com>
|
|
|
|
*/
|
|
|
|
|
2011-09-29 18:14:46 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "nutscan-device.h"
|
2022-06-29 10:37:36 +00:00
|
|
|
#include "nut-scan.h"
|
|
|
|
|
|
|
|
static char * nutscan_device_type_string[TYPE_END] = {
|
|
|
|
"NONE",
|
|
|
|
"USB",
|
|
|
|
"SNMP",
|
|
|
|
"XML",
|
|
|
|
"NUT",
|
|
|
|
"IPMI",
|
|
|
|
"AVAHI",
|
|
|
|
"EATON_SERIAL"
|
|
|
|
};
|
2011-09-29 18:14:46 +00:00
|
|
|
|
|
|
|
void nutscan_display_ups_conf(nutscan_device_t * device)
|
|
|
|
{
|
|
|
|
nutscan_device_t * current_dev = device;
|
|
|
|
nutscan_options_t * opt;
|
|
|
|
static int nutdev_num = 1;
|
|
|
|
|
2022-06-29 10:37:36 +00:00
|
|
|
if (device == NULL) {
|
2011-09-29 18:14:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find start of the list */
|
2022-06-29 10:37:36 +00:00
|
|
|
while (current_dev->prev != NULL) {
|
2011-09-29 18:14:46 +00:00
|
|
|
current_dev = current_dev->prev;
|
|
|
|
}
|
|
|
|
|
2022-06-29 10:37:36 +00:00
|
|
|
/* Display each device */
|
2011-09-29 18:14:46 +00:00
|
|
|
do {
|
|
|
|
printf("[nutdev%i]\n\tdriver = \"%s\"\n\tport = \"%s\"\n",
|
|
|
|
nutdev_num, current_dev->driver,
|
|
|
|
current_dev->port);
|
|
|
|
|
2013-11-24 15:00:12 +00:00
|
|
|
opt = current_dev->opt;
|
2011-09-29 18:14:46 +00:00
|
|
|
|
2013-11-24 15:00:12 +00:00
|
|
|
while (NULL != opt) {
|
2022-06-29 10:37:36 +00:00
|
|
|
if (opt->option != NULL) {
|
|
|
|
printf("\t%s", opt->option);
|
|
|
|
if (opt->value != NULL) {
|
2011-09-29 18:14:46 +00:00
|
|
|
printf(" = \"%s\"", opt->value);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
opt = opt->next;
|
2013-11-24 15:00:12 +00:00
|
|
|
}
|
2011-09-29 18:14:46 +00:00
|
|
|
|
|
|
|
nutdev_num++;
|
|
|
|
|
|
|
|
current_dev = current_dev->next;
|
|
|
|
}
|
2022-06-29 10:37:36 +00:00
|
|
|
while (current_dev != NULL);
|
2011-09-29 18:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nutscan_display_parsable(nutscan_device_t * device)
|
|
|
|
{
|
|
|
|
nutscan_device_t * current_dev = device;
|
|
|
|
nutscan_options_t * opt;
|
|
|
|
|
2022-06-29 10:37:36 +00:00
|
|
|
if (device == NULL) {
|
2011-09-29 18:14:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find start of the list */
|
2022-06-29 10:37:36 +00:00
|
|
|
while (current_dev->prev != NULL) {
|
2011-09-29 18:14:46 +00:00
|
|
|
current_dev = current_dev->prev;
|
|
|
|
}
|
|
|
|
|
2022-06-29 10:37:36 +00:00
|
|
|
/* Display each device */
|
2011-09-29 18:14:46 +00:00
|
|
|
do {
|
2022-06-29 10:37:36 +00:00
|
|
|
/* Do not separate by whitespace, in case someone already parses this */
|
2011-09-29 18:14:46 +00:00
|
|
|
printf("%s:driver=\"%s\",port=\"%s\"",
|
|
|
|
nutscan_device_type_string[current_dev->type],
|
|
|
|
current_dev->driver,
|
|
|
|
current_dev->port);
|
|
|
|
|
2013-11-24 15:00:12 +00:00
|
|
|
opt = current_dev->opt;
|
2011-09-29 18:14:46 +00:00
|
|
|
|
2013-11-24 15:00:12 +00:00
|
|
|
while (NULL != opt) {
|
2022-06-29 10:37:36 +00:00
|
|
|
if (opt->option != NULL) {
|
|
|
|
/* Do not separate by whitespace, in case someone already parses this */
|
|
|
|
printf(",%s", opt->option);
|
|
|
|
if (opt->value != NULL) {
|
2011-09-29 18:14:46 +00:00
|
|
|
printf("=\"%s\"", opt->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
opt = opt->next;
|
2013-11-24 15:00:12 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 18:14:46 +00:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
current_dev = current_dev->next;
|
|
|
|
}
|
2022-06-29 10:37:36 +00:00
|
|
|
while (current_dev != NULL);
|
2011-09-29 18:14:46 +00:00
|
|
|
}
|