From 85314f8310ff134cd77977d27084aee5addb2491 Mon Sep 17 00:00:00 2001 From: Slyvtt Date: Wed, 20 Apr 2022 13:07:30 +0200 Subject: [PATCH] change option name to -q, --quiet and improved code layout --- fxlink/interactive.c | 18 ++++++------------ fxlink/main.c | 25 ++++++++++++------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/fxlink/interactive.c b/fxlink/interactive.c index 806a764..109279e 100644 --- a/fxlink/interactive.c +++ b/fxlink/interactive.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; diff --git a/fxlink/main.c b/fxlink/main.c index 0e4fcb7..1892eda 100644 --- a/fxlink/main.c +++ b/fxlink/main.c @@ -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;