1
0
Fork 0
forked from Miroirs/x49gp

prettify code

This commit is contained in:
Gwenhael Le Moine 2024-10-24 15:35:14 +02:00
parent 18ef08eb32
commit c09f925e32
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
2 changed files with 66 additions and 69 deletions

View file

@ -29,7 +29,6 @@ void config_init( char* progname, int argc, char* argv[] )
opt.model = MODEL_50G; opt.model = MODEL_50G;
opt.name = NULL; opt.name = NULL;
const char* optstring = "hrc:D:df:Fn:"; const char* optstring = "hrc:D:df:Fn:";
struct option long_options[] = { struct option long_options[] = {
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
@ -42,11 +41,11 @@ void config_init( char* progname, int argc, char* argv[] )
{"reflash-full", no_argument, NULL, 'F'}, {"reflash-full", no_argument, NULL, 'F'},
{"reboot", no_argument, NULL, 'r'}, {"reboot", no_argument, NULL, 'r'},
{"50g", no_argument, NULL, 506}, {"50g", no_argument, NULL, 506},
{"50g-newrpl", no_argument, NULL, 507}, {"50g-newrpl", no_argument, NULL, 507},
{"49gp", no_argument, NULL, 496}, {"49gp", no_argument, NULL, 496},
{"49gp-newrpl", no_argument, NULL, 497}, {"49gp-newrpl", no_argument, NULL, 497},
{"name", required_argument, NULL, 'n'}, {"name", required_argument, NULL, 'n'},
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
@ -84,80 +83,78 @@ void config_init( char* progname, int argc, char* argv[] )
progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, DEFAULT_GDBSTUB_PORT, progname ); progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, DEFAULT_GDBSTUB_PORT, progname );
exit( EXIT_SUCCESS ); exit( EXIT_SUCCESS );
break; break;
case 'r': case 'r':
if ( opt.reinit < X49GP_REINIT_REBOOT_ONLY ) if ( opt.reinit < X49GP_REINIT_REBOOT_ONLY )
opt.reinit = X49GP_REINIT_REBOOT_ONLY; opt.reinit = X49GP_REINIT_REBOOT_ONLY;
break; break;
case 'c': case 'c':
opt.config = strdup( optarg ); opt.config = strdup( optarg );
break; break;
case 'D': case 'D':
do_enable_debugger = true; do_enable_debugger = true;
break; break;
case 'd': case 'd':
do_start_debugger = true; do_start_debugger = true;
break; break;
case 'f': case 'f':
do_reflash = true; do_reflash = true;
break; break;
case 'F': case 'F':
do_reflash_full = true; do_reflash_full = true;
break; break;
case 496: case 496:
opt.model = MODEL_49GP; opt.model = MODEL_49GP;
break; break;
case 497: case 497:
opt.model = MODEL_49GP_NEWRPL; opt.model = MODEL_49GP_NEWRPL;
break; break;
case 506: case 506:
opt.model = MODEL_50G; opt.model = MODEL_50G;
break; break;
case 507: case 507:
opt.model = MODEL_50G_NEWRPL; opt.model = MODEL_50G_NEWRPL;
break; break;
case 'n': case 'n':
opt.name = strdup( optarg ); opt.name = strdup( optarg );
break; break;
default: default:
break; break;
} }
} }
if ( do_enable_debugger ) { if ( do_enable_debugger ) {
char* end; char* end;
int port; int port;
if ( optarg == NULL && opt.debug_port == 0 ) if ( optarg == NULL && opt.debug_port == 0 )
opt.debug_port = DEFAULT_GDBSTUB_PORT; opt.debug_port = DEFAULT_GDBSTUB_PORT;
port = strtoul( optarg, &end, 0 ); port = strtoul( optarg, &end, 0 );
if ( ( end == optarg ) || ( *end != '\0' ) ) { if ( ( end == optarg ) || ( *end != '\0' ) ) {
fprintf( stderr, "Invalid port \"%s\", using default\n", optarg ); fprintf( stderr, "Invalid port \"%s\", using default\n", optarg );
if ( opt.debug_port == 0 ) if ( opt.debug_port == 0 )
opt.debug_port = DEFAULT_GDBSTUB_PORT; opt.debug_port = DEFAULT_GDBSTUB_PORT;
} }
if ( opt.debug_port != 0 && opt.debug_port != DEFAULT_GDBSTUB_PORT ) if ( opt.debug_port != 0 && opt.debug_port != DEFAULT_GDBSTUB_PORT )
fprintf( stderr, fprintf( stderr, "Additional debug port \"%s\" specified, overriding\n", optarg );
"Additional debug port \"%s\" specified, overriding\n", opt.debug_port = port;
optarg );
opt.debug_port = port;
opt.start_debugger = do_start_debugger; opt.start_debugger = do_start_debugger;
} }
if ( do_reflash ) { if ( do_reflash ) {
if ( opt.reinit < X49GP_REINIT_FLASH ) if ( opt.reinit < X49GP_REINIT_FLASH )
opt.reinit = X49GP_REINIT_FLASH; opt.reinit = X49GP_REINIT_FLASH;
if ( opt.firmware != NULL ) if ( opt.firmware != NULL )
fprintf( stderr, fprintf( stderr,
"Additional firmware file \"%s\" specified," "Additional firmware file \"%s\" specified,"
" overriding\n", " overriding\n",
optarg ); optarg );
opt.firmware = optarg; opt.firmware = optarg;
if ( do_reflash_full ) if ( do_reflash_full )
opt.reinit = X49GP_REINIT_FLASH_FULL; opt.reinit = X49GP_REINIT_FLASH_FULL;
} }
if ( opt.config == NULL ) { if ( opt.config == NULL ) {

View file

@ -7,7 +7,7 @@
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
# include "list.h" #include "list.h"
#include "x49gp_types.h" #include "x49gp_types.h"
#define X49GP_TIMER_VIRTUAL 0 #define X49GP_TIMER_VIRTUAL 0