1
0
Fork 0
forked from Miroirs/x49gp

have only --datadir= options; use opt. instead x49gp-> where relevant

This commit is contained in:
Gwenhael Le Moine 2024-11-14 15:18:55 +01:00
parent 092b7f49af
commit 9f77361637
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
9 changed files with 53 additions and 46 deletions

View file

@ -5,6 +5,13 @@ VERSION_MAJOR = 1
VERSION_MINOR = 3 VERSION_MINOR = 3
PATCHLEVEL = 2 PATCHLEVEL = 2
INSTALL_PREFIX = /usr/local
INSTALL_BINARY_DIR = "$(INSTALL_PREFIX)"/bin
INSTALL_DATA_DIR = "$(INSTALL_PREFIX)"/share/$(TARGET)
INSTALL_DOC_DIR = "$(INSTALL_PREFIX)"/doc/$(TARGET)
INSTALL_MENU_DIR = "$(INSTALL_PREFIX)"/share/applications
INSTALL_MAN_DIR = "$(INSTALL_PREFIX)/share/man/man1"
# #
DEBUG_CFLAGS = -g # -pg DEBUG_CFLAGS = -g # -pg
OPTIM ?= 2 OPTIM ?= 2
@ -216,13 +223,6 @@ else
endif endif
# Installation # Installation
INSTALL_PREFIX = /usr/local
INSTALL_BINARY_DIR = "$(INSTALL_PREFIX)"/bin
INSTALL_DATA_DIR = "$(INSTALL_PREFIX)"/share/$(TARGET)
INSTALL_DOC_DIR = "$(INSTALL_PREFIX)"/doc/$(TARGET)
INSTALL_MENU_DIR = "$(INSTALL_PREFIX)"/share/applications
INSTALL_MAN_DIR = "$(INSTALL_PREFIX)/share/man/man1"
dist/$(TARGET).desktop: dist/$(TARGET).desktop.in dist/$(TARGET).desktop: dist/$(TARGET).desktop.in
perl -p -e "s!TARGET!$(TARGET)!" < dist/$(TARGET).desktop.in >$@ perl -p -e "s!TARGET!$(TARGET)!" < dist/$(TARGET).desktop.in >$@

2
dist/x49gpng.scd vendored
View file

@ -51,7 +51,7 @@ Please consult HP's manual (for their official firmware) or the documentation of
- *-h* *--help* print this message and exit - *-h* *--help* print this message and exit
- *--verbose* print out more information - *--verbose* print out more information
- *--state*[=_filename_] alternate config file - *--datadir*[=_absolute path_] alternate datadir (default: $XDG_CONFIG_HOME/x49gpng/)
- *--50g* emulate an HP 50g (default) - *--50g* emulate an HP 50g (default)
- *--49gp* emulate an HP 49g+ - *--49gp* emulate an HP 49g+
- *--newrpl-keyboard* label keyboard for newRPL - *--newrpl-keyboard* label keyboard for newRPL

View file

@ -10,6 +10,7 @@
#include "x49gp.h" #include "x49gp.h"
#include "ui.h" #include "ui.h"
#include "options.h"
#define FLASH_STATE_NORMAL 0 #define FLASH_STATE_NORMAL 0
@ -435,11 +436,11 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key )
if ( flash->size > st.st_size ) { if ( flash->size > st.st_size ) {
fprintf( stderr, "Flash too small, rebuilding\n" ); fprintf( stderr, "Flash too small, rebuilding\n" );
x49gp->startup_reinit = X49GP_REINIT_FLASH_FULL; opt.reinit = X49GP_REINIT_FLASH_FULL;
} }
if ( x49gp->startup_reinit >= X49GP_REINIT_FLASH ) { if ( opt.reinit >= X49GP_REINIT_FLASH ) {
if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL ) if ( opt.reinit == X49GP_REINIT_FLASH_FULL )
memset( phys_ram_base + flash->offset, 0xff, flash->size - st.st_size ); memset( phys_ram_base + flash->offset, 0xff, flash->size - st.st_size );
bootfd = x49gp_module_open_rodata( bootfd = x49gp_module_open_rodata(
@ -467,7 +468,7 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key )
close( bootfd ); close( bootfd );
g_free( bootfile ); g_free( bootfile );
if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL ) { if ( opt.reinit == X49GP_REINIT_FLASH_FULL ) {
/* The stock firmware expects special markers in certain /* The stock firmware expects special markers in certain
spots across the flash. Without these, the user banks spots across the flash. Without these, the user banks
act up and are not usable, and PINIT apparently won't act up and are not usable, and PINIT apparently won't
@ -485,8 +486,8 @@ static int flash_load( x49gp_module_t* module, GKeyFile* key )
retry: retry:
filename = NULL; filename = NULL;
if ( x49gp->firmware != NULL ) if ( opt.firmware != NULL )
filename = g_strdup( x49gp->firmware ); filename = g_strdup( opt.firmware );
else else
gui_open_firmware( x49gp, &filename ); gui_open_firmware( x49gp, &filename );
@ -496,7 +497,7 @@ retry:
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) ); fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
/* Mark firmware as invalid if there is one */ /* Mark firmware as invalid if there is one */
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
if ( x49gp->firmware != NULL ) { if ( opt.firmware != NULL ) {
fprintf( stderr, "Warning: Could not " fprintf( stderr, "Warning: Could not "
"open selected firmware, " "open selected firmware, "
"falling back to bootloader " "falling back to bootloader "
@ -514,7 +515,7 @@ retry:
/* Mark firmware as invalid /* Mark firmware as invalid
if there is one */ if there is one */
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
if ( x49gp->firmware != NULL ) { if ( opt.firmware != NULL ) {
fprintf( stderr, "Warning: " fprintf( stderr, "Warning: "
"Could not read " "Could not read "
"selected firmware, " "selected firmware, "
@ -531,7 +532,7 @@ retry:
} else if ( bytes_read < 16 || memcmp( phys_ram_base + flash->offset + BOOT_SIZE, "KINPOUPDATEIMAGE", 16 ) != 0 ) { } else if ( bytes_read < 16 || memcmp( phys_ram_base + flash->offset + BOOT_SIZE, "KINPOUPDATEIMAGE", 16 ) != 0 ) {
/* Mark firmware as invalid */ /* Mark firmware as invalid */
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
if ( x49gp->firmware != NULL ) { if ( opt.firmware != NULL ) {
fprintf( stderr, "Warning: " fprintf( stderr, "Warning: "
"Firmware is invalid, " "Firmware is invalid, "
"falling back to " "falling back to "
@ -553,7 +554,7 @@ retry:
/* Mark firmware as invalid /* Mark firmware as invalid
if there is one */ if there is one */
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 ); memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
if ( x49gp->firmware != NULL ) { if ( opt.firmware != NULL ) {
fprintf( stderr, "Warning: " fprintf( stderr, "Warning: "
"Could not read " "Could not read "
"selected firmware, " "selected firmware, "

View file

@ -285,11 +285,6 @@ 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.state_filename );
x49gp->debug_port = opt.debug_port;
x49gp->startup_reinit = opt.reinit;
x49gp->firmware = opt.firmware;
int error = x49gp_modules_load( x49gp, opt.state_filename ); 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 )

View file

@ -8,6 +8,7 @@
#include "list.h" #include "list.h"
#include "x49gp.h" #include "x49gp.h"
#include "options.h"
int x49gp_modules_init( x49gp_t* x49gp ) int x49gp_modules_init( x49gp_t* x49gp )
{ {
@ -94,7 +95,7 @@ int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
printf( "%s:%u:\n", __FUNCTION__, __LINE__ ); printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
#endif #endif
if ( g_mkdir_with_parents( x49gp->basename, 0755 ) ) { if ( g_mkdir_with_parents( opt.datadir, 0755 ) ) {
error = -errno; error = -errno;
fprintf( stderr, "%s:%u: g_mkdir_with_parents: %s\n", __FUNCTION__, __LINE__, strerror( errno ) ); fprintf( stderr, "%s:%u: g_mkdir_with_parents: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
return error; return error;
@ -213,7 +214,6 @@ int x49gp_module_unregister( x49gp_module_t* module )
int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep, char** path ) int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep, char** path )
{ {
x49gp_t* x49gp = module->x49gp;
int error; int error;
error = x49gp_module_get_string( module, key, name, reset, valuep ); error = x49gp_module_get_string( module, key, name, reset, valuep );
@ -223,7 +223,7 @@ int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char
return error; return error;
} }
*path = g_build_filename( x49gp->basename, *valuep, NULL ); *path = g_build_filename( opt.datadir, *valuep, NULL );
if ( NULL == path ) { if ( NULL == path ) {
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ ); fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
g_free( *valuep ); g_free( *valuep );
@ -374,6 +374,8 @@ int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** p
int error; int error;
*path = g_build_filename( x49gp->progpath, name, NULL ); *path = g_build_filename( x49gp->progpath, name, NULL );
if ( opt.verbose )
fprintf( stderr, "reading %s\n", *path );
if ( NULL == *path ) { if ( NULL == *path ) {
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ ); fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
return -ENOMEM; return -ENOMEM;
@ -386,6 +388,8 @@ int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** p
g_free( *path ); g_free( *path );
*path = g_build_filename( X49GP_DATADIR, name, NULL ); *path = g_build_filename( X49GP_DATADIR, name, NULL );
if ( opt.verbose )
fprintf( stderr, "reading %s\n", *path );
if ( NULL == *path ) { if ( NULL == *path ) {
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ ); fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
return -ENOMEM; return -ENOMEM;

View file

@ -13,6 +13,7 @@
#include "gdbstub.h" #include "gdbstub.h"
struct options opt = { struct options opt = {
.datadir = NULL,
.config_lua_filename = NULL, .config_lua_filename = NULL,
.state_filename = NULL, .state_filename = NULL,
.debug_port = 0, .debug_port = 0,
@ -140,9 +141,7 @@ void config_init( char* progname, int argc, char* argv[] )
{"print-config", no_argument, &print_config_and_exit, true}, {"print-config", no_argument, &print_config_and_exit, true},
{"verbose", no_argument, &clopt_verbose, true}, {"verbose", no_argument, &clopt_verbose, true},
{"config", required_argument, NULL, 'c' }, {"datadir", required_argument, NULL, 1 },
{"state", required_argument, NULL, 1 },
{"enable-debug", required_argument, NULL, 'D' }, {"enable-debug", required_argument, NULL, 'D' },
{"debug", no_argument, NULL, 'd' }, {"debug", no_argument, NULL, 'd' },
@ -173,17 +172,22 @@ void config_init( char* progname, int argc, char* argv[] )
"Valid options:\n" "Valid options:\n"
" -h --help print this message and exit\n" " -h --help print this message and exit\n"
" --verbose print out more information\n" " --verbose print out more information\n"
" --state[=<filename>] alternate config file\n" "\n"
" --datadir[=<absolute path>] alternate datadir (default: $XDG_CONFIG_HOME/%s/)\n"
"\n"
" --50g emulate an HP 50g (default)\n" " --50g emulate an HP 50g (default)\n"
" --49gp emulate an HP 49g+\n" " --49gp emulate an HP 49g+\n"
" --newrpl-keyboard label keyboard for newRPL\n" " --newrpl-keyboard label keyboard for newRPL\n"
"\n"
" -n --name[=<name>] set alternate UI name\n" " -n --name[=<name>] set alternate UI name\n"
" -t --font[=<fontname>] set alternate UI font\n" " -t --font[=<fontname>] set alternate UI font\n"
" -s --font-size[=<X>] scale text by X (default: 3)\n" " -s --font-size[=<X>] scale text by X (default: 3)\n"
" -S --display-scale[=<X>] scale LCD by X (default: 2)\n" " -S --display-scale[=<X>] scale LCD by X (default: 2)\n"
"\n"
" -D --enable-debug[=<port>] enable the debugger interface\n" " -D --enable-debug[=<port>] enable the debugger interface\n"
" (default port: %u)\n" " (default port: %u)\n"
" -d --debug use along -D to also start the debugger immediately\n" " -d --debug use along -D to also start the debugger immediately\n"
"\n"
" -f --reflash[=firmware] rebuild the flash using the supplied firmware\n" " -f --reflash[=firmware] rebuild the flash using the supplied firmware\n"
" (default: select one interactively)\n" " (default: select one interactively)\n"
" (implies -r for safety reasons)\n" " (implies -r for safety reasons)\n"
@ -191,11 +195,12 @@ void config_init( char* progname, int argc, char* argv[] )
" in the area beyond the firmware\n" " in the area beyond the firmware\n"
" -r --reboot reboot on startup instead of continuing from the\n" " -r --reboot reboot on startup instead of continuing from the\n"
" saved state in the state file\n\n" " saved state in the state file\n\n"
"\n"
"The state file is formatted as INI file and contains the settings for which persistence makes sense like CPU " "The state file is formatted as INI file and contains the settings for which persistence makes sense like CPU "
"registers, etc.\n" "registers, etc.\n"
"If the state file is omitted, ~/.config/%s/state is used.\n" "If the state file is omitted, ~/.config/%s/state is used.\n"
"Please consult the manual for more details on state file settings.\n", "Please consult the manual for more details on state file settings.\n",
progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, DEFAULT_GDBSTUB_PORT, progname ); progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, progname, DEFAULT_GDBSTUB_PORT, progname );
exit( EXIT_SUCCESS ); exit( EXIT_SUCCESS );
break; break;
case 'r': case 'r':
@ -203,7 +208,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 1: case 1:
opt.state_filename = strdup( optarg ); opt.datadir = strdup( optarg );
break; break;
case 'D': case 'D':
do_enable_debugger = true; do_enable_debugger = true;
@ -245,9 +250,14 @@ void config_init( char* progname, int argc, char* argv[] )
} }
} }
const char* user_config_dir = g_get_user_config_dir(); if ( opt.datadir == NULL ) {
const char* user_config_dir = g_get_user_config_dir();
opt.datadir = g_build_filename( user_config_dir, progname, NULL );
}
opt.config_lua_filename = g_build_filename( user_config_dir, progname, config_lua_filename, NULL ); opt.config_lua_filename = g_build_filename( opt.datadir, progname, config_lua_filename, NULL );
opt.state_filename = g_build_filename( opt.datadir, "state", NULL );
/**********************/ /**********************/
/* 1. read config.lua */ /* 1. read config.lua */
@ -316,8 +326,8 @@ void config_init( char* progname, int argc, char* argv[] )
if ( !haz_config_file ) { if ( !haz_config_file ) {
fprintf( stderr, "\nConfiguration file %s doesn't seem to exist or is invalid!\n", opt.config_lua_filename ); fprintf( stderr, "\nConfiguration file %s doesn't seem to exist or is invalid!\n", opt.config_lua_filename );
fprintf( stderr, "You can solve this by running `mkdir -p %s/%s && %s --print-config >> %s`\n\n", user_config_dir, progname, fprintf( stderr, "You can solve this by running `mkdir -p %s/ && %s --print-config >> %s`\n\n", opt.datadir, progname,
progname, opt.config_lua_filename ); opt.config_lua_filename );
} }
if ( do_enable_debugger ) { if ( do_enable_debugger ) {
@ -337,7 +347,4 @@ void config_init( char* progname, int argc, char* argv[] )
if ( do_reflash_full ) if ( do_reflash_full )
opt.reinit = X49GP_REINIT_FLASH_FULL; opt.reinit = X49GP_REINIT_FLASH_FULL;
} }
if ( opt.state_filename == NULL )
opt.state_filename = g_build_filename( user_config_dir, progname, "state", NULL );
} }

View file

@ -1,6 +1,8 @@
#ifndef _CONFIG_H #ifndef _CONFIG_H
#define _CONFIG_H 1 #define _CONFIG_H 1
#include <stdbool.h>
#include "x49gp.h" #include "x49gp.h"
#ifndef VERSION_MAJOR #ifndef VERSION_MAJOR
@ -31,6 +33,8 @@ struct options {
int font_size; int font_size;
char* config_lua_filename; char* config_lua_filename;
bool verbose; bool verbose;
char* datadir;
}; };
extern struct options opt; extern struct options opt;

View file

@ -826,8 +826,8 @@ static void do_start_gdb_server( GtkMenuItem* menuitem, gpointer user_data )
{ {
x49gp_t* x49gp = user_data; x49gp_t* x49gp = user_data;
if ( x49gp->debug_port != 0 && !gdbserver_isactive() ) { if ( opt.debug_port != 0 && !gdbserver_isactive() ) {
gdbserver_start( x49gp->debug_port ); gdbserver_start( opt.debug_port );
gdb_handlesig( x49gp->env, 0 ); gdb_handlesig( x49gp->env, 0 );
} }
} }
@ -1541,7 +1541,7 @@ static int ui_load( x49gp_module_t* module, GKeyFile* keyfile )
g_signal_connect_swapped( G_OBJECT( menu_unmount ), "activate", G_CALLBACK( s3c2410_sdi_unmount ), x49gp ); g_signal_connect_swapped( G_OBJECT( menu_unmount ), "activate", G_CALLBACK( s3c2410_sdi_unmount ), x49gp );
ui->menu_unmount = menu_unmount; ui->menu_unmount = menu_unmount;
if ( x49gp->debug_port != 0 ) { if ( opt.debug_port != 0 ) {
gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), gtk_separator_menu_item_new() ); gtk_menu_shell_append( GTK_MENU_SHELL( ui->menu ), gtk_separator_menu_item_new() );
GtkWidget* menu_debug = gtk_menu_item_new_with_label( "Start debugger" ); GtkWidget* menu_debug = gtk_menu_item_new_with_label( "Start debugger" );

View file

@ -86,10 +86,6 @@ struct __x49gp_s__ {
GKeyFile* state_filename; GKeyFile* state_filename;
const char* progname; const char* progname;
const char* progpath; const char* progpath;
const char* basename;
int debug_port;
x49gp_reinit_t startup_reinit;
char* firmware;
}; };
extern void x49gp_set_idle( x49gp_t*, x49gp_arm_idle_t idle ); extern void x49gp_set_idle( x49gp_t*, x49gp_arm_idle_t idle );