1
0
Fork 0
forked from Miroirs/x49gp

So-called config file is really about state. Name it so.

This commit is contained in:
Gwenhael Le Moine 2024-11-10 16:37:36 +01:00
parent c7d1a1700e
commit 94b8e7b04d
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
5 changed files with 18 additions and 18 deletions

View file

@ -278,12 +278,12 @@ int main( int argc, char** argv )
if ( x49gp_modules_init( x49gp ) ) if ( x49gp_modules_init( x49gp ) )
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
x49gp->basename = g_path_get_dirname( opt.config ); x49gp->basename = g_path_get_dirname( opt.state_filename );
x49gp->debug_port = opt.debug_port; x49gp->debug_port = opt.debug_port;
x49gp->startup_reinit = opt.reinit; x49gp->startup_reinit = opt.reinit;
x49gp->firmware = opt.firmware; x49gp->firmware = opt.firmware;
int error = x49gp_modules_load( x49gp, opt.config ); int error = x49gp_modules_load( x49gp, opt.state_filename );
if ( error || opt.reinit >= X49GP_REINIT_REBOOT_ONLY ) { if ( error || opt.reinit >= X49GP_REINIT_REBOOT_ONLY ) {
if ( error && error != -EAGAIN ) if ( error && error != -EAGAIN )
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
@ -312,7 +312,7 @@ int main( int argc, char** argv )
x49gp_main_loop( x49gp ); x49gp_main_loop( x49gp );
x49gp_modules_save( x49gp, opt.config ); x49gp_modules_save( x49gp, opt.state_filename );
x49gp_modules_exit( x49gp ); x49gp_modules_exit( x49gp );
#if false #if false

View file

@ -100,16 +100,16 @@ int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
return error; return error;
} }
x49gp->config = g_key_file_new(); x49gp->state_filename = g_key_file_new();
if ( NULL == x49gp->config ) { if ( NULL == x49gp->state_filename ) {
fprintf( stderr, "%s:%u: g_key_file_new: Out of memory\n", __FUNCTION__, __LINE__ ); fprintf( stderr, "%s:%u: g_key_file_new: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM; return -ENOMEM;
} }
if ( !g_key_file_load_from_file( x49gp->config, filename, G_KEY_FILE_KEEP_COMMENTS, &gerror ) && if ( !g_key_file_load_from_file( x49gp->state_filename, filename, G_KEY_FILE_KEEP_COMMENTS, &gerror ) &&
!g_error_matches( gerror, G_FILE_ERROR, G_FILE_ERROR_NOENT ) ) { !g_error_matches( gerror, G_FILE_ERROR, G_FILE_ERROR_NOENT ) ) {
fprintf( stderr, "%s:%u: g_key_file_load_from_file: %s\n", __FUNCTION__, __LINE__, gerror->message ); fprintf( stderr, "%s:%u: g_key_file_load_from_file: %s\n", __FUNCTION__, __LINE__, gerror->message );
g_key_file_free( x49gp->config ); g_key_file_free( x49gp->state_filename );
return -EIO; return -EIO;
} }
@ -117,7 +117,7 @@ int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
list_for_each_entry( module, &x49gp->modules, list ) list_for_each_entry( module, &x49gp->modules, list )
{ {
error = module->load( module, x49gp->config ); error = module->load( module, x49gp->state_filename );
if ( error ) { if ( error ) {
if ( error == -EAGAIN ) if ( error == -EAGAIN )
result = -EAGAIN; result = -EAGAIN;
@ -126,15 +126,15 @@ int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
} }
} }
#ifdef DEBUG_X49GP_MODULES
{ {
extern unsigned char* phys_ram_base; extern unsigned char* phys_ram_base;
#ifdef DEBUG_X49GP_MODULES
printf( "%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base ); printf( "%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base );
printf( "\t%02x %02x %02x %02x %02x %02x %02x %02x\n", phys_ram_base[ 0 ], phys_ram_base[ 1 ], phys_ram_base[ 2 ], printf( "\t%02x %02x %02x %02x %02x %02x %02x %02x\n", phys_ram_base[ 0 ], phys_ram_base[ 1 ], phys_ram_base[ 2 ],
phys_ram_base[ 3 ], phys_ram_base[ 4 ], phys_ram_base[ 5 ], phys_ram_base[ 6 ], phys_ram_base[ 7 ] ); phys_ram_base[ 3 ], phys_ram_base[ 4 ], phys_ram_base[ 5 ], phys_ram_base[ 6 ], phys_ram_base[ 7 ] );
#endif
} }
#endif
return result; return result;
} }
@ -154,12 +154,12 @@ int x49gp_modules_save( x49gp_t* x49gp, const char* filename )
list_for_each_entry( module, &x49gp->modules, list ) list_for_each_entry( module, &x49gp->modules, list )
{ {
error = module->save( module, x49gp->config ); error = module->save( module, x49gp->state_filename );
if ( error ) if ( error )
return error; return error;
} }
data = g_key_file_to_data( x49gp->config, &length, &gerror ); data = g_key_file_to_data( x49gp->state_filename, &length, &gerror );
if ( NULL == data ) { if ( NULL == data ) {
fprintf( stderr, "%s:%u: g_key_file_to_data: %s\n", __FUNCTION__, __LINE__, gerror->message ); fprintf( stderr, "%s:%u: g_key_file_to_data: %s\n", __FUNCTION__, __LINE__, gerror->message );
return -ENOMEM; return -ENOMEM;

View file

@ -21,7 +21,7 @@ void config_init( char* progname, int argc, char* argv[] )
bool do_reflash = false; bool do_reflash = false;
bool do_reflash_full = false; bool do_reflash_full = false;
opt.config = NULL; opt.state_filename = NULL;
opt.debug_port = 0; opt.debug_port = 0;
opt.start_debugger = false; opt.start_debugger = false;
opt.reinit = X49GP_REINIT_NONE; opt.reinit = X49GP_REINIT_NONE;
@ -103,7 +103,7 @@ void config_init( char* progname, int argc, char* argv[] )
opt.reinit = X49GP_REINIT_REBOOT_ONLY; opt.reinit = X49GP_REINIT_REBOOT_ONLY;
break; break;
case 'c': case 'c':
opt.config = strdup( optarg ); opt.state_filename = strdup( optarg );
break; break;
case 'D': case 'D':
do_enable_debugger = true; do_enable_debugger = true;
@ -181,11 +181,11 @@ void config_init( char* progname, int argc, char* argv[] )
opt.reinit = X49GP_REINIT_FLASH_FULL; opt.reinit = X49GP_REINIT_FLASH_FULL;
} }
if ( opt.config == NULL ) { if ( opt.state_filename == NULL ) {
char config_dir[ strlen( progname ) + 9 ]; char config_dir[ strlen( progname ) + 9 ];
const char* home = g_get_home_dir(); const char* home = g_get_home_dir();
sprintf( config_dir, ".config/%s", progname ); sprintf( config_dir, ".config/%s", progname );
opt.config = g_build_filename( home, config_dir, "config", NULL ); opt.state_filename = g_build_filename( home, config_dir, "state", NULL );
} }
} }

View file

@ -16,7 +16,7 @@
typedef enum { MODEL_49GP = 0, MODEL_49GP_NEWRPL, MODEL_50G, MODEL_50G_NEWRPL } x49gpng_model_t; typedef enum { MODEL_49GP = 0, MODEL_49GP_NEWRPL, MODEL_50G, MODEL_50G_NEWRPL } x49gpng_model_t;
struct options { struct options {
char* config; char* state_filename;
int debug_port; int debug_port;
int start_debugger; int start_debugger;
char* firmware; char* firmware;

View file

@ -83,7 +83,7 @@ struct __x49gp_s__ {
x49gp_ui_t* ui; x49gp_ui_t* ui;
GKeyFile* config; GKeyFile* state_filename;
const char* progname; const char* progname;
const char* progpath; const char* progpath;
const char* basename; const char* basename;