mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-29 13:03:37 +01:00
change option name to -q, --quiet and improved code layout
This commit is contained in:
parent
89ca11678c
commit
85314f8310
2 changed files with 18 additions and 25 deletions
|
@ -108,45 +108,39 @@ static void message_finish(message_t *msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strncmp(msg->header.type, "text", 16)) {
|
if(!strncmp(msg->header.type, "text", 16)) {
|
||||||
|
|
||||||
/* I choose the option of maintening a console ouptut even if log in file is set */
|
/* 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 */
|
/* this can be removed by uncommenting the following line */
|
||||||
|
|
||||||
//if (!loginfile)
|
//if (!loginfile)
|
||||||
{
|
{
|
||||||
if (!silentmode)
|
if (!silentmode) {
|
||||||
{
|
|
||||||
printf("------------------\n");
|
printf("------------------\n");
|
||||||
fwrite(msg->output, 1, msg->header.size, stdout);
|
fwrite(msg->output, 1, msg->header.size, stdout);
|
||||||
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
|
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
|
||||||
printf("------------------\n");
|
printf("------------------\n");
|
||||||
}
|
}
|
||||||
else if (silentmode)
|
else {
|
||||||
{
|
|
||||||
fwrite(msg->output, 1, msg->header.size, stdout);
|
fwrite(msg->output, 1, msg->header.size, stdout);
|
||||||
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
|
if(msg->output[msg->header.size - 1] != '\n') printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (loginfile)
|
if (loginfile) {
|
||||||
{
|
|
||||||
FILE *fp = fopen( userlogfilename, "a" );
|
FILE *fp = fopen( userlogfilename, "a" );
|
||||||
if(!fp) {
|
if(!fp) {
|
||||||
err("could not save to '%s': %m", userlogfilename);
|
err("could not save to '%s': %m", userlogfilename);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silentmode)
|
if (!silentmode) {
|
||||||
{
|
|
||||||
fprintf(fp, "------------------\n");
|
fprintf(fp, "------------------\n");
|
||||||
fwrite(msg->output, 1, msg->header.size, fp);
|
fwrite(msg->output, 1, msg->header.size, fp);
|
||||||
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
|
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
|
||||||
fprintf(fp, "------------------\n");
|
fprintf(fp, "------------------\n");
|
||||||
}
|
}
|
||||||
else if (silentmode)
|
else {
|
||||||
{
|
|
||||||
fwrite(msg->output, 1, msg->header.size, fp);
|
fwrite(msg->output, 1, msg->header.size, fp);
|
||||||
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
|
if(msg->output[msg->header.size - 1] != '\n') fprintf(fp, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( fp );
|
fclose( fp );
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -40,8 +40,8 @@ static const char *help_string =
|
||||||
" --libusb-log=LEVEL libusb log level: NONE, ERROR, WARNING, INFO, DEBUG\n"
|
" --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"
|
" --fxlink-log=file Log text data into a logfile called file. If file is\n"
|
||||||
" missing, a generic filename will be created.\n"
|
" missing, a generic filename will be created.\n"
|
||||||
" --silent-mode Will turn output to the minimum value, without\n"
|
" -q, --quiet Activate quiet mode, i.e. minimum verbosity and very\n"
|
||||||
" decorations (no extra messages).\n"
|
" limited decorations (no extra messages).\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Device filters:\n"
|
"Device filters:\n"
|
||||||
" A device filter is a comma-separated list of properties that a device has\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 { LIBUSB_LOG=1 };
|
||||||
enum { SILENT_MODE=2 };
|
enum { LOG_IN_FILE=2 };
|
||||||
enum { LOG_IN_FILE=3 };
|
|
||||||
const struct option longs[] = {
|
const struct option longs[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "list", no_argument, NULL, 'l' },
|
{ "list", no_argument, NULL, 'l' },
|
||||||
|
@ -85,12 +84,12 @@ int main(int argc, char **argv)
|
||||||
{ "send", no_argument, NULL, 's' },
|
{ "send", no_argument, NULL, 's' },
|
||||||
{ "interactive", no_argument, NULL, 'i' },
|
{ "interactive", no_argument, NULL, 'i' },
|
||||||
{ "libusb-log", required_argument, NULL, LIBUSB_LOG },
|
{ "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 },
|
{ "fxlink-log", optional_argument, NULL, LOG_IN_FILE },
|
||||||
};
|
};
|
||||||
|
|
||||||
while(option >= 0 && option != '?')
|
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':
|
case 'h':
|
||||||
fprintf(stderr, help_string, argv[0]);
|
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 "
|
else fprintf(stderr, "warning: ignoring log level '%s'; should be "
|
||||||
"NONE, ERROR, WARNING, INFO or DEBUG\n", optarg);
|
"NONE, ERROR, WARNING, INFO or DEBUG\n", optarg);
|
||||||
break;
|
break;
|
||||||
case SILENT_MODE:
|
case 'q':
|
||||||
printf("Enabling Silent (i.e. minimum verbosity) Mode\n");
|
printf("Enabling quiet mode (i.e. minimum verbosity)\n");
|
||||||
silentmode = true;
|
silentmode = true;
|
||||||
break;
|
break;
|
||||||
case LOG_IN_FILE:
|
case LOG_IN_FILE:
|
||||||
printf("Enabling Log in File Mode\n");
|
printf("Enabling Log in File Mode\n");
|
||||||
loginfile = true;
|
loginfile = true;
|
||||||
if (optarg)
|
if (optarg) {
|
||||||
{
|
|
||||||
asprintf( &userlogfilename, "%s", optarg );
|
asprintf( &userlogfilename, "%s", optarg );
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
time_t time_raw;
|
time_t time_raw;
|
||||||
struct tm time_bd;
|
struct tm time_bd;
|
||||||
time(&time_raw);
|
time(&time_raw);
|
||||||
localtime_r(&time_raw, &time_bd);
|
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 );
|
printf("Log File will be : %s \n", userlogfilename );
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue