change option name to -q, --quiet and improved code layout

pull/7/head
Sylvain PILLOT 5 months ago
parent 89ca11678c
commit 85314f8310
  1. 18
      fxlink/interactive.c
  2. 25
      fxlink/main.c

@ -108,45 +108,39 @@ static void message_finish(message_t *msg)
}
if(!strncmp(msg->header.type, "text", 16)) {
/* I choose the option of maintening a console ouptut even if log in file is set */
/* this can be removed by uncommenting the following line */
//if (!loginfile)
{
if (!silentmode)
{
if (!silentmode) {
printf("------------------\n");
fwrite(msg->output, 1, msg->header.size, stdout);
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
printf("------------------\n");
}
else if (silentmode)
{
else {
fwrite(msg->output, 1, msg->header.size, stdout);
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
}
}
if (loginfile)
{
if (loginfile) {
FILE *fp = fopen( userlogfilename, "a" );
if(!fp) {
err("could not save to '%s': %m", userlogfilename);
return;
}
if (!silentmode)
{
if (!silentmode) {
fprintf(fp, "------------------\n");
fwrite(msg->output, 1, msg->header.size, fp);
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
fprintf(fp, "------------------\n");
}
else if (silentmode)
{
else {
fwrite(msg->output, 1, msg->header.size, fp);
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
}
fclose( fp );
}
return;

@ -40,8 +40,8 @@ static const char *help_string =
" --libusb-log=LEVEL libusb log level: NONE, ERROR, WARNING, INFO, DEBUG\n"
" --fxlink-log=file Log text data into a logfile called file. If file is\n"
" missing, a generic filename will be created.\n"
" --silent-mode Will turn output to the minimum value, without\n"
" decorations (no extra messages).\n"
" -q, --quiet Activate quiet mode, i.e. minimum verbosity and very\n"
" limited decorations (no extra messages).\n"
"\n"
"Device filters:\n"
" A device filter is a comma-separated list of properties that a device has\n"
@ -76,8 +76,7 @@ int main(int argc, char **argv)
//---
enum { LIBUSB_LOG=1 };
enum { SILENT_MODE=2 };
enum { LOG_IN_FILE=3 };
enum { LOG_IN_FILE=2 };
const struct option longs[] = {
{ "help", no_argument, NULL, 'h' },
{ "list", no_argument, NULL, 'l' },
@ -85,12 +84,12 @@ int main(int argc, char **argv)
{ "send", no_argument, NULL, 's' },
{ "interactive", no_argument, NULL, 'i' },
{ "libusb-log", required_argument, NULL, LIBUSB_LOG },
{ "silent-mode", no_argument, NULL, SILENT_MODE },
{ "quiet", no_argument, NULL, 'q' },
{ "fxlink-log", optional_argument, NULL, LOG_IN_FILE },
};
while(option >= 0 && option != '?')
switch((option = getopt_long(argc, argv, "hlbsif:w::", longs, NULL)))
switch((option = getopt_long(argc, argv, "hlbsiqf:w::", longs, NULL)))
{
case 'h':
fprintf(stderr, help_string, argv[0]);
@ -115,24 +114,24 @@ int main(int argc, char **argv)
else fprintf(stderr, "warning: ignoring log level '%s'; should be "
"NONE, ERROR, WARNING, INFO or DEBUG\n", optarg);
break;
case SILENT_MODE:
printf("Enabling Silent (i.e. minimum verbosity) Mode\n");
case 'q':
printf("Enabling quiet mode (i.e. minimum verbosity)\n");
silentmode = true;
break;
case LOG_IN_FILE:
printf("Enabling Log in File Mode\n");
loginfile = true;
if (optarg)
{
if (optarg) {
asprintf( &userlogfilename, "%s", optarg );
}
else
{
else {
time_t time_raw;
struct tm time_bd;
time(&time_raw);
localtime_r(&time_raw, &time_bd);
asprintf( &userlogfilename, "./fxlink-logfile-%04d.%02d.%02d-%02dh%02d.log", time_bd.tm_year + 1900, time_bd.tm_mon + 1, time_bd.tm_mday, time_bd.tm_hour, time_bd.tm_min );
asprintf( &userlogfilename, "./fxlink-logfile-%04d.%02d.%02d-%02dh%02d.log",
time_bd.tm_year + 1900, time_bd.tm_mon + 1, time_bd.tm_mday,
time_bd.tm_hour, time_bd.tm_min );
}
printf("Log File will be : %s \n", userlogfilename );
break;

Loading…
Cancel
Save