1
0
Fork 0
forked from Miroirs/x49gp

Compare commits

..

2 commits

Author SHA1 Message Date
Gwenhael Le Moine
6fe6c501b0
use getopt_long to parse options, change semantic of -d and -F slightly 2024-10-23 11:28:20 +02:00
Gwenhael Le Moine
a22ae17352
use stdbool.h 2024-10-23 10:32:39 +02:00
5 changed files with 246 additions and 385 deletions

View file

@ -102,6 +102,7 @@ X49GP_CFLAGS = -O2 \
$(DEBUG) \ $(DEBUG) \
$(INCLUDES) \ $(INCLUDES) \
$(DEFINES) \ $(DEFINES) \
-D_GNU_SOURCE=1 \
-DVERSION_MAJOR=$(VERSION_MAJOR) \ -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \ -DVERSION_MINOR=$(VERSION_MINOR) \
-DPATCHLEVEL=$(PATCHLEVEL) \ -DPATCHLEVEL=$(PATCHLEVEL) \

View file

@ -21,6 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <stdbool.h>
#include "qemu-git/qemu-common.h" #include "qemu-git/qemu-common.h"
#include "block.h" #include "block.h"
#include "block_int.h" #include "block_int.h"
@ -627,7 +630,7 @@ static int raw_pread( BlockDriverState* bs, int64_t offset, uint8_t* buf, int co
ov.OffsetHigh = offset >> 32; ov.OffsetHigh = offset >> 32;
ret = ReadFile( s->hfile, buf, count, &ret_count, &ov ); ret = ReadFile( s->hfile, buf, count, &ret_count, &ov );
if ( !ret ) { if ( !ret ) {
ret = GetOverlappedResult( s->hfile, &ov, &ret_count, TRUE ); ret = GetOverlappedResult( s->hfile, &ov, &ret_count, true );
if ( !ret ) if ( !ret )
return -EIO; return -EIO;
else else
@ -648,7 +651,7 @@ static int raw_pwrite( BlockDriverState* bs, int64_t offset, const uint8_t* buf,
ov.OffsetHigh = offset >> 32; ov.OffsetHigh = offset >> 32;
ret = WriteFile( s->hfile, buf, count, &ret_count, &ov ); ret = WriteFile( s->hfile, buf, count, &ret_count, &ov );
if ( !ret ) { if ( !ret ) {
ret = GetOverlappedResult( s->hfile, &ov, &ret_count, TRUE ); ret = GetOverlappedResult( s->hfile, &ov, &ret_count, true );
if ( !ret ) if ( !ret )
return -EIO; return -EIO;
else else
@ -705,7 +708,7 @@ static int64_t raw_getlength( BlockDriverState* bs )
break; break;
case FTYPE_HARDDISK: case FTYPE_HARDDISK:
status = DeviceIoControl( s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof( dg ), &count, NULL ); status = DeviceIoControl( s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof( dg ), &count, NULL );
if ( status != FALSE ) { if ( status != false ) {
l.QuadPart = dg.Cylinders.QuadPart * dg.TracksPerCylinder * dg.SectorsPerTrack * dg.BytesPerSector; l.QuadPart = dg.Cylinders.QuadPart * dg.TracksPerCylinder * dg.SectorsPerTrack * dg.BytesPerSector;
} }
break; break;

View file

@ -5,6 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
@ -12,6 +13,8 @@
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <getopt.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib.h> #include <glib.h>
@ -20,8 +23,6 @@
#include "x49gp.h" #include "x49gp.h"
#include "x49gp_ui.h" #include "x49gp_ui.h"
#include "s3c2410.h" #include "s3c2410.h"
#include "s3c2410_power.h"
#include "s3c2410_timer.h"
#include "x49gp_timer.h" #include "x49gp_timer.h"
#include "gdbstub.h" #include "gdbstub.h"
@ -53,9 +54,9 @@ int singlestep;
#if !( defined( __APPLE__ ) || defined( _POSIX_C_SOURCE ) && !defined( __sun__ ) ) #if !( defined( __APPLE__ ) || defined( _POSIX_C_SOURCE ) && !defined( __sun__ ) )
static void* oom_check( void* ptr ) static void* oom_check( void* ptr )
{ {
if ( ptr == NULL ) { if ( ptr == NULL )
abort(); abort();
}
return ptr; return ptr;
} }
#endif #endif
@ -205,7 +206,7 @@ void x49gp_gtk_timer( void* data )
{ {
while ( gtk_events_pending() ) { while ( gtk_events_pending() ) {
// printf("%s: gtk_main_iteration_do()\n", __FUNCTION__); // printf("%s: gtk_main_iteration_do()\n", __FUNCTION__);
gtk_main_iteration_do( FALSE ); gtk_main_iteration_do( false );
} }
x49gp_mod_timer( x49gp->gtk_timer, x49gp_get_clock() + X49GP_GTK_REFRESH_INTERVAL ); x49gp_mod_timer( x49gp->gtk_timer, x49gp_get_clock() + X49GP_GTK_REFRESH_INTERVAL );
@ -227,6 +228,10 @@ void x49gp_lcd_timer( void* data )
x49gp_mod_timer( x49gp->lcd_timer, expires ); x49gp_mod_timer( x49gp->lcd_timer, expires );
} }
/***********/
/* OPTIONS */
/***********/
struct options { struct options {
char* config; char* config;
int debug_port; int debug_port;
@ -237,63 +242,47 @@ struct options {
int more_options; int more_options;
}; };
struct option_def; struct options opt;
typedef int ( *option_action )( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname ); static void config_init( char* progname, int argc, char* argv[] )
{
int option_index;
int c = '?';
struct option_def { opt.config = NULL;
option_action action; opt.debug_port = 0;
char* longname; opt.start_debugger = false;
char shortname; opt.reinit = X49GP_REINIT_NONE;
opt.firmware = NULL;
const char* optstring = "hrc:D:df:F";
struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"config", required_argument, NULL, 'c'},
{"enable-debug", required_argument, NULL, 'D'},
{"debug", no_argument, NULL, 'd'},
{"reflash", required_argument, NULL, 'f'},
{"reflash-full", no_argument, NULL, 'F'},
{"reboot", no_argument, NULL, 'r'},
{0, 0, 0, 0 }
}; };
static int action_help( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname ); while ( c != EOF ) {
static int action_debuglater( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname ); c = getopt_long( argc, argv, optstring, long_options, &option_index );
static int action_debug( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_reinit_flash( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_reinit_flash_full( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_reboot( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_unknown_with_param( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_longopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_endopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
struct option_def option_defs[] = {
{action_help, "help", 'h' },
{action_debuglater, "enable-debug", 'D' },
{action_debug, "debug", 'd' },
{action_reinit_flash, "reflash", 'f' },
{action_reinit_flash_full, "reflash-full", 'F' },
{action_reboot, "reboot", 'r' },
{action_longopt, NULL, '-' },
{action_unknown_with_param, NULL, '=' },
{action_endopt, "", '\0'}
};
static void warn_unneeded_param( struct option_def* match, char* this_opt )
{
if ( this_opt[ 1 ] == '-' ) {
fprintf( stderr,
"The option \"--%s\" does not support"
" parameters\n",
match->longname );
} else
fprintf( stderr, "The option '-%c' does not support parameters\n", match->shortname );
}
static int action_help( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
{
if ( param != NULL )
warn_unneeded_param( match, this_opt );
switch ( c ) {
case 'h':
fprintf( stderr, fprintf( stderr,
"%s %i.%i.%i Emulator for HP 49G+ / 50G calculators\n" "%s %i.%i.%i Emulator for HP 49G+ / 50G calculators\n"
"Usage: %s [<options>] [<config-file>]\n" "Usage: %s [<options>] [<config-file>]\n"
"Valid options:\n" "Valid options:\n"
" -D, --enable-debug[=<port] enable the debugger interface\n" " -c, --config[=<filename>] alternate config file\n"
" -D, --enable-debug[=<port>] enable the debugger interface\n"
" (default port: %u)\n" " (default port: %u)\n"
" -d, --debug[=<port>] like -D, but also start the" " -d, --debug use along -D to also start the"
" debugger immediately\n" " debugger immediately\n"
" -f, --reflash[=firmware] rebuild the flash using the" " -f, --reflash[=firmware] rebuild the flash using the"
" supplied firmware\n" " supplied firmware\n"
@ -301,7 +290,7 @@ static int action_help( struct options* opt, struct option_def* match, char* thi
" interactively)\n" " interactively)\n"
" (implies -r for safety" " (implies -r for safety"
" reasons)\n" " reasons)\n"
" -F, --reflash-full[=firmware] like -f, but don't preserve the" " -F, --reflash-full use along -f to drop the"
" flash contents\n" " flash contents\n"
" in the area beyond the" " in the area beyond the"
" firmware\n" " firmware\n"
@ -318,191 +307,63 @@ static int action_help( struct options* opt, struct option_def* match, char* thi
"Please consult the manual for more details on config file" "Please consult the manual for more details on config file"
" settings.\n", " settings.\n",
progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, DEFAULT_GDBSTUB_PORT, progname ); progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, progname, DEFAULT_GDBSTUB_PORT, progname );
exit( 0 ); exit( EXIT_SUCCESS );
} break;
case 'r':
static int action_debuglater( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname ) if ( opt.reinit < X49GP_REINIT_REBOOT_ONLY )
opt.reinit = X49GP_REINIT_REBOOT_ONLY;
break;
case 'c':
opt.config = strdup( optarg );
break;
case 'D':
{ {
char* end; char* end;
int port; int port;
if ( param == NULL ) { if ( optarg == NULL && opt.debug_port == 0 )
if ( opt->debug_port == 0 ) opt.debug_port = DEFAULT_GDBSTUB_PORT;
opt->debug_port = DEFAULT_GDBSTUB_PORT;
return FALSE; port = strtoul( optarg, &end, 0 );
if ( ( end == optarg ) || ( *end != '\0' ) ) {
fprintf( stderr, "Invalid port \"%s\", using default\n", optarg );
if ( opt.debug_port == 0 )
opt.debug_port = DEFAULT_GDBSTUB_PORT;
} }
port = strtoul( param, &end, 0 ); if ( opt.debug_port != 0 && opt.debug_port != DEFAULT_GDBSTUB_PORT )
if ( ( end == param ) || ( *end != '\0' ) ) {
fprintf( stderr, "Invalid port \"%s\", using default\n", param );
if ( opt->debug_port == 0 )
opt->debug_port = DEFAULT_GDBSTUB_PORT;
return TRUE;
}
if ( opt->debug_port != 0 && opt->debug_port != DEFAULT_GDBSTUB_PORT )
fprintf( stderr, fprintf( stderr,
"Additional debug port \"%s\" specified," "Additional debug port \"%s\" specified,"
" overriding\n", " overriding\n",
param ); optarg );
opt->debug_port = port; opt.debug_port = port;
return TRUE;
} }
break;
case 'd':
opt.start_debugger = true;
break;
case 'F':
opt.reinit = X49GP_REINIT_FLASH_FULL;
break;
case 'f':
if ( opt.reinit < X49GP_REINIT_FLASH )
opt.reinit = X49GP_REINIT_FLASH;
static int action_debug( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname ) if ( opt.firmware != NULL )
{
opt->start_debugger = TRUE;
return action_debuglater( opt, match, this_opt, param, progname );
}
static int action_reinit_flash( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
{
if ( opt->reinit < X49GP_REINIT_FLASH )
opt->reinit = X49GP_REINIT_FLASH;
if ( param == NULL )
return FALSE;
if ( opt->firmware != NULL )
fprintf( stderr, fprintf( stderr,
"Additional firmware file \"%s\" specified," "Additional firmware file \"%s\" specified,"
" overriding\n", " overriding\n",
param ); optarg );
opt->firmware = param; opt.firmware = optarg;
return TRUE;
}
static int action_reinit_flash_full( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
{
int result = action_reinit_flash( opt, match, this_opt, param, progname );
opt->reinit = X49GP_REINIT_FLASH_FULL;
return result;
}
static int action_reboot( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
{
if ( param != NULL )
warn_unneeded_param( match, this_opt );
if ( opt->reinit < X49GP_REINIT_REBOOT_ONLY )
opt->reinit = X49GP_REINIT_REBOOT_ONLY;
return param != NULL;
}
static int action_longopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
{
int i;
char *test_str, *option_str;
if ( this_opt[ 1 ] != '-' || param != NULL ) {
fprintf( stderr, "Unrecognized option '-', ignoring\n" );
return FALSE;
}
for ( i = 0; i < sizeof( option_defs ) / sizeof( option_defs[ 0 ] ); i++ ) {
if ( option_defs[ i ].longname == NULL )
continue;
test_str = option_defs[ i ].longname;
option_str = this_opt + 2;
while ( *test_str != '\0' && *test_str == *option_str ) {
test_str++;
option_str++;
}
if ( *test_str != '\0' )
continue;
switch ( *option_str ) {
case '\0':
( option_defs[ i ].action )( opt, option_defs + i, this_opt, NULL, progname );
return TRUE;
case '=':
( option_defs[ i ].action )( opt, option_defs + i, this_opt, option_str + 1, progname );
return TRUE;
}
}
fprintf( stderr, "Unrecognized option \"%s\", ignoring\n", this_opt + 2 );
return TRUE;
}
static int action_unknown_with_param( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
{
return TRUE;
}
static int action_endopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
{
opt->more_options = FALSE;
return TRUE;
}
static void parse_shortopt( struct options* opt, char* this_opt, char* progname )
{
char* option = this_opt + 1;
char* param;
int i;
if ( *option == '\0' ) {
fprintf( stderr, "Empty option present, ignoring\n" );
return;
}
do {
for ( i = 0; i < sizeof( option_defs ) / sizeof( option_defs[ 0 ] ); i++ ) {
if ( *option == option_defs[ i ].shortname ) {
if ( *( option + 1 ) == '=' ) {
param = option + 2;
} else {
param = NULL;
}
if ( ( option_defs[ i ].action )( opt, option_defs + i, this_opt, param, progname ) )
return;
break; break;
}
}
if ( i == sizeof( option_defs ) / sizeof( option_defs[ 0 ] ) )
fprintf( stderr, "Unrecognized option '%c', ignoring\n", *option );
option++;
} while ( *option != '\0' );
}
static void parse_options( struct options* opt, int argc, char** argv, char* progname )
{
opt->more_options = TRUE;
while ( argc > 1 ) {
switch ( argv[ 1 ][ 0 ] ) {
case '\0':
break;
break;
case '-':
if ( opt->more_options ) {
parse_shortopt( opt, argv[ 1 ], progname );
break;
}
/* FALL THROUGH */
default: default:
if ( opt->config != NULL ) { break;
fprintf( stderr,
"Additional config file \"%s\""
" specified, overriding\n",
argv[ 1 ] );
}
opt->config = argv[ 1 ];
}
argc--;
argv++;
} }
} }
}
/************/
/* \OPTIONS */
/************/
void ui_sighnd( int sig ) void ui_sighnd( int sig )
{ {
@ -520,7 +381,6 @@ int main( int argc, char** argv )
{ {
char *progname, *progpath; char *progname, *progpath;
int error; int error;
struct options opt;
const char* home; const char* home;
progname = g_path_get_basename( argv[ 0 ] ); progname = g_path_get_basename( argv[ 0 ] );
@ -528,12 +388,7 @@ int main( int argc, char** argv )
gtk_init( &argc, &argv ); gtk_init( &argc, &argv );
opt.config = NULL; config_init( progname, argc, argv );
opt.debug_port = 0;
opt.start_debugger = FALSE;
opt.reinit = X49GP_REINIT_NONE;
opt.firmware = NULL;
parse_options( &opt, argc, argv, progname );
x49gp = malloc( sizeof( x49gp_t ) ); x49gp = malloc( sizeof( x49gp_t ) );
if ( NULL == x49gp ) { if ( NULL == x49gp ) {

View file

@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -159,7 +160,7 @@ done:
rect.width = ui->lcd_width; rect.width = ui->lcd_width;
rect.height = ui->lcd_height; rect.height = ui->lcd_height;
gdk_window_invalidate_rect( ui->lcd_canvas->window, &rect, FALSE ); gdk_window_invalidate_rect( ui->lcd_canvas->window, &rect, false );
} }
static uint32_t s3c2410_lcd_read( void* opaque, target_phys_addr_t offset ) static uint32_t s3c2410_lcd_read( void* opaque, target_phys_addr_t offset )

115
src/ui.c
View file

@ -5,6 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
@ -1586,7 +1587,7 @@ static GdkPixbuf* x49gp_pixbuf_new_from_inline( gint data_length, const guint8*
pixdata = ( void* )( pbd + 1 ); pixdata = ( void* )( pbd + 1 );
return gdk_pixbuf_new_from_data( pixdata, GDK_COLORSPACE_RGB, TRUE, 8, width, height, rowstride, NULL, NULL ); return gdk_pixbuf_new_from_data( pixdata, GDK_COLORSPACE_RGB, true, 8, width, height, rowstride, NULL, NULL );
} }
static int x49gp_ui_button_pixmaps_init( x49gp_t* x49gp, x49gp_ui_button_t* button, x49gp_ui_color_t color ) static int x49gp_ui_button_pixmaps_init( x49gp_t* x49gp, x49gp_ui_button_t* button, x49gp_ui_color_t color )
@ -2313,7 +2314,7 @@ static void bitmap_font_draw_text( GdkDrawable* drawable, GdkColor* color, const
gdk_gc_set_stipple( gc, bitmap ); gdk_gc_set_stipple( gc, bitmap );
gdk_gc_set_fill( gc, GDK_STIPPLED ); gdk_gc_set_fill( gc, GDK_STIPPLED );
gdk_draw_rectangle( drawable, gc, TRUE, x + glyph->kern, y + font->ascent - glyph->ascent, w, h ); gdk_draw_rectangle( drawable, gc, true, x + glyph->kern, y + font->ascent - glyph->ascent, w, h );
g_object_unref( bitmap ); g_object_unref( bitmap );
@ -2346,8 +2347,8 @@ static void x49gp_ui_choose_file( x49gp_t* x49gp, const char* prompt, GtkFileCho
dialog = gtk_file_chooser_dialog_new( prompt, GTK_WINDOW( ui->window ), action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, dialog = gtk_file_chooser_dialog_new( prompt, GTK_WINDOW( ui->window ), action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN,
GTK_RESPONSE_ACCEPT, NULL ); GTK_RESPONSE_ACCEPT, NULL );
gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( dialog ), TRUE ); gtk_file_chooser_set_local_only( GTK_FILE_CHOOSER( dialog ), true );
gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( dialog ), FALSE ); gtk_file_chooser_set_select_multiple( GTK_FILE_CHOOSER( dialog ), false );
if ( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_ACCEPT ) if ( gtk_dialog_run( GTK_DIALOG( dialog ) ) == GTK_RESPONSE_ACCEPT )
*filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) ); *filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ) );
@ -2374,24 +2375,24 @@ static gboolean x49gp_ui_button_press( GtkWidget* widget, GdkEventButton* event,
#endif #endif
if ( event->type != GDK_BUTTON_PRESS ) if ( event->type != GDK_BUTTON_PRESS )
return FALSE; return false;
switch ( event->button ) { switch ( event->button ) {
case 1: case 1:
ui->buttons_down++; ui->buttons_down++;
if ( button->down ) if ( button->down )
return FALSE; return false;
button->down = TRUE; button->down = true;
break; break;
case 3: case 3:
button->hold = TRUE; button->hold = true;
if ( button->down ) if ( button->down )
return FALSE; return false;
gtk_button_pressed( GTK_BUTTON( button->button ) ); gtk_button_pressed( GTK_BUTTON( button->button ) );
button->down = TRUE; button->down = true;
break; break;
default: default:
return TRUE; return true;
} }
#ifdef DEBUG_X49GP_UI #ifdef DEBUG_X49GP_UI
@ -2404,7 +2405,7 @@ static gboolean x49gp_ui_button_press( GtkWidget* widget, GdkEventButton* event,
else else
s3c2410_io_port_f_set_bit( x49gp, key->eint, 1 ); s3c2410_io_port_f_set_bit( x49gp, key->eint, 1 );
return FALSE; return false;
} }
static void x49gp_release_single_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause ) static void x49gp_release_single_button( x49gp_ui_button_t* button, x49gp_ui_button_t* cause )
@ -2418,13 +2419,13 @@ static void x49gp_release_single_button( x49gp_ui_button_t* button, x49gp_ui_but
button->key->eint ); button->key->eint );
#endif #endif
button->down = FALSE; button->down = false;
button->hold = FALSE; button->hold = false;
gtkbutton = GTK_BUTTON( button->button ); gtkbutton = GTK_BUTTON( button->button );
if ( button != cause ) if ( button != cause )
gtkbutton->in_button = FALSE; gtkbutton->in_button = false;
gtk_button_released( gtkbutton ); gtk_button_released( gtkbutton );
key = button->key; key = button->key;
@ -2457,13 +2458,13 @@ static gboolean x49gp_ui_button_release( GtkWidget* widget, GdkEventButton* even
x49gp_ui_t* ui = x49gp->ui; x49gp_ui_t* ui = x49gp->ui;
if ( event->type != GDK_BUTTON_RELEASE ) if ( event->type != GDK_BUTTON_RELEASE )
return FALSE; return false;
switch ( event->button ) { switch ( event->button ) {
case 1: case 1:
break; break;
default: default:
return TRUE; return true;
} }
if ( ui->buttons_down > 0 ) if ( ui->buttons_down > 0 )
@ -2474,7 +2475,7 @@ static gboolean x49gp_ui_button_release( GtkWidget* widget, GdkEventButton* even
else else
x49gp_release_single_button( button, button ); x49gp_release_single_button( button, button );
return FALSE; return false;
} }
static gboolean x49gp_ui_show_menu( GtkWidget* widget, GdkEventButton* event, gpointer user_data ) static gboolean x49gp_ui_show_menu( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
@ -2488,10 +2489,10 @@ static gboolean x49gp_ui_show_menu( GtkWidget* widget, GdkEventButton* event, gp
if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) { if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
gtk_menu_popup( GTK_MENU( ui->menu ), NULL, NULL, NULL, NULL, event->button, event->time ); gtk_menu_popup( GTK_MENU( ui->menu ), NULL, NULL, NULL, NULL, event->button, event->time );
return TRUE; return true;
} }
return FALSE; return false;
} }
static gboolean x49gp_ui_button_leave( GtkWidget* widget, GdkEventCrossing* event, gpointer user_data ) static gboolean x49gp_ui_button_leave( GtkWidget* widget, GdkEventCrossing* event, gpointer user_data )
@ -2499,12 +2500,12 @@ static gboolean x49gp_ui_button_leave( GtkWidget* widget, GdkEventCrossing* even
x49gp_ui_button_t* button = user_data; x49gp_ui_button_t* button = user_data;
if ( event->type != GDK_LEAVE_NOTIFY ) if ( event->type != GDK_LEAVE_NOTIFY )
return FALSE; return false;
if ( !button->hold ) if ( !button->hold )
return FALSE; return false;
return TRUE; return true;
} }
static gboolean x49gp_ui_focus_lost( GtkWidget* widget, GdkEventFocus* event, gpointer user_data ) static gboolean x49gp_ui_focus_lost( GtkWidget* widget, GdkEventFocus* event, gpointer user_data )
@ -2513,12 +2514,12 @@ static gboolean x49gp_ui_focus_lost( GtkWidget* widget, GdkEventFocus* event, gp
x49gp_ui_t* ui = x49gp->ui; x49gp_ui_t* ui = x49gp->ui;
if ( event->type != GDK_FOCUS_CHANGE ) if ( event->type != GDK_FOCUS_CHANGE )
return FALSE; return false;
ui->buttons_down = 0; ui->buttons_down = 0;
x49gp_release_all_buttons( x49gp, NULL ); x49gp_release_all_buttons( x49gp, NULL );
return FALSE; return false;
} }
static void x49gp_ui_popup_at_widget( GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data ) static void x49gp_ui_popup_at_widget( GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data )
@ -2587,7 +2588,7 @@ static gboolean x49gp_ui_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
/* which normally is represented by MOD2. */ /* which normally is represented by MOD2. */
if ( !gdk_keymap_translate_keyboard_state( gdk_keymap_get_default(), event->hardware_keycode, event->state & GDK_MOD2_MASK, if ( !gdk_keymap_translate_keyboard_state( gdk_keymap_get_default(), event->hardware_keycode, event->state & GDK_MOD2_MASK,
event->group, &keyval, NULL, NULL, NULL ) ) event->group, &keyval, NULL, NULL, NULL ) )
return FALSE; return false;
#ifdef DEBUG_X49GP_UI #ifdef DEBUG_X49GP_UI
fprintf( stderr, "%s:%u: state %u, base keyval %04x\n", __FUNCTION__, __LINE__, event->state, keyval ); fprintf( stderr, "%s:%u: state %u, base keyval %04x\n", __FUNCTION__, __LINE__, event->state, keyval );
#endif #endif
@ -2812,7 +2813,7 @@ static gboolean x49gp_ui_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
case GDK_KEY_F10: case GDK_KEY_F10:
x49gp->arm_exit = 1; x49gp->arm_exit = 1;
cpu_exit( x49gp->env ); cpu_exit( x49gp->env );
return FALSE; return false;
case GDK_KEY_F12: case GDK_KEY_F12:
switch ( event->type ) { switch ( event->type ) {
@ -2827,7 +2828,7 @@ static gboolean x49gp_ui_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
default: default:
break; break;
} }
return FALSE; return false;
case GDK_KEY_Menu: case GDK_KEY_Menu:
gtk_widget_set_sensitive( ui->menu_unmount, s3c2410_sdi_is_mounted( x49gp ) ); gtk_widget_set_sensitive( ui->menu_unmount, s3c2410_sdi_is_mounted( x49gp ) );
@ -2835,10 +2836,10 @@ static gboolean x49gp_ui_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
gtk_widget_set_sensitive( ui->menu_debug, !gdbserver_isactive() ); gtk_widget_set_sensitive( ui->menu_debug, !gdbserver_isactive() );
gtk_menu_popup( GTK_MENU( ui->menu ), NULL, NULL, x49gp_ui_popup_at_widget, ui->lcd_canvas, 0, event->time ); gtk_menu_popup( GTK_MENU( ui->menu ), NULL, NULL, x49gp_ui_popup_at_widget, ui->lcd_canvas, 0, event->time );
return FALSE; return false;
default: default:
return FALSE; return false;
} }
button = &ui->buttons[ index ]; button = &ui->buttons[ index ];
@ -2855,22 +2856,22 @@ static gboolean x49gp_ui_key_event( GtkWidget* widget, GdkEventKey* event, gpoin
case GDK_KEY_PRESS: case GDK_KEY_PRESS:
bev.type = GDK_BUTTON_PRESS; bev.type = GDK_BUTTON_PRESS;
x49gp_ui_button_press( button->button, &bev, button ); x49gp_ui_button_press( button->button, &bev, button );
GTK_BUTTON( button->button )->in_button = TRUE; GTK_BUTTON( button->button )->in_button = true;
gtk_button_pressed( GTK_BUTTON( button->button ) ); gtk_button_pressed( GTK_BUTTON( button->button ) );
GTK_BUTTON( button->button )->in_button = save_in; GTK_BUTTON( button->button )->in_button = save_in;
break; break;
case GDK_KEY_RELEASE: case GDK_KEY_RELEASE:
bev.type = GDK_BUTTON_RELEASE; bev.type = GDK_BUTTON_RELEASE;
GTK_BUTTON( button->button )->in_button = TRUE; GTK_BUTTON( button->button )->in_button = true;
gtk_button_released( GTK_BUTTON( button->button ) ); gtk_button_released( GTK_BUTTON( button->button ) );
GTK_BUTTON( button->button )->in_button = save_in; GTK_BUTTON( button->button )->in_button = save_in;
x49gp_ui_button_release( button->button, &bev, button ); x49gp_ui_button_release( button->button, &bev, button );
break; break;
default: default:
return FALSE; return false;
} }
return TRUE; return true;
} }
static int x49gp_button_expose_event( GtkWidget* widget, GdkEventExpose* event, gpointer user_data ) static int x49gp_button_expose_event( GtkWidget* widget, GdkEventExpose* event, gpointer user_data )
@ -2887,7 +2888,7 @@ static int x49gp_button_expose_event( GtkWidget* widget, GdkEventExpose* event,
gdk_draw_drawable( widget->window, widget->style->black_gc, button->pixmap, 0, 0, x, y, widget->allocation.width, gdk_draw_drawable( widget->window, widget->style->black_gc, button->pixmap, 0, 0, x, y, widget->allocation.width,
widget->allocation.height ); widget->allocation.height );
return FALSE; return false;
} }
static void x49gp_button_realize( GtkWidget* widget, gpointer user_data ) static void x49gp_button_realize( GtkWidget* widget, gpointer user_data )
@ -2983,7 +2984,7 @@ static int x49gp_lcd_expose_event( GtkWidget* widget, GdkEventExpose* event, gpo
g_free( rects ); g_free( rects );
return FALSE; return false;
} }
static int x49gp_lcd_configure_event( GtkWidget* widget, GdkEventConfigure* event, gpointer user_data ) static int x49gp_lcd_configure_event( GtkWidget* widget, GdkEventConfigure* event, gpointer user_data )
@ -2992,7 +2993,7 @@ static int x49gp_lcd_configure_event( GtkWidget* widget, GdkEventConfigure* even
x49gp_ui_t* ui = x49gp->ui; x49gp_ui_t* ui = x49gp->ui;
if ( NULL != ui->lcd_pixmap ) if ( NULL != ui->lcd_pixmap )
return FALSE; return false;
ui->ann_left = gdk_bitmap_create_from_data( ui->lcd_canvas->window, ( char* )ann_left_bits, ann_left_width, ann_left_height ); ui->ann_left = gdk_bitmap_create_from_data( ui->lcd_canvas->window, ( char* )ann_left_bits, ann_left_width, ann_left_height );
ui->ann_right = gdk_bitmap_create_from_data( ui->lcd_canvas->window, ( char* )ann_right_bits, ann_right_width, ann_right_height ); ui->ann_right = gdk_bitmap_create_from_data( ui->lcd_canvas->window, ( char* )ann_right_bits, ann_right_width, ann_right_height );
@ -3067,7 +3068,7 @@ static int x49gp_lcd_configure_event( GtkWidget* widget, GdkEventConfigure* even
gdk_draw_drawable( ui->lcd_pixmap, widget->style->black_gc, ui->bg_pixmap, ui->lcd_x_offset, ui->lcd_y_offset, 0, 0, ui->lcd_width, gdk_draw_drawable( ui->lcd_pixmap, widget->style->black_gc, ui->bg_pixmap, ui->lcd_x_offset, ui->lcd_y_offset, 0, 0, ui->lcd_width,
ui->lcd_height ); ui->lcd_height );
return FALSE; return false;
} }
static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* event, gpointer user_data ) static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* event, gpointer user_data )
@ -3085,7 +3086,7 @@ static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* e
int dl = 0, dr = 0; int dl = 0, dr = 0;
if ( NULL != ui->bg_pixmap ) if ( NULL != ui->bg_pixmap )
return FALSE; return false;
ui->bg_pixmap = gdk_pixmap_new( widget->window, ui->width, ui->height, -1 ); ui->bg_pixmap = gdk_pixmap_new( widget->window, ui->width, ui->height, -1 );
@ -3106,7 +3107,7 @@ static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* e
x49gp_ui_draw_text( cr, &widget->style->black, X49GP_UI_NORMAL_FONT, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1, x49gp_ui_draw_text( cr, &widget->style->black, X49GP_UI_NORMAL_FONT, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1,
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "graphing calculator" ); CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "graphing calculator" );
x49gp_ui_draw_symbol( cr, &widget->style->black, 10.0, 0.0, TRUE, 114 /* 138 */, 8 /* 25 */, x49gp_ui_draw_symbol( cr, &widget->style->black, 10.0, 0.0, true, 114 /* 138 */, 8 /* 25 */,
symbol_get_by_name( "triangleup" ) ); symbol_get_by_name( "triangleup" ) );
left_color = UI_COLOR_GREEN; left_color = UI_COLOR_GREEN;
@ -3127,7 +3128,7 @@ static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* e
x49gp_ui_draw_text( cr, &widget->style->white, X49GP_UI_NORMAL_FONT, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1, x49gp_ui_draw_text( cr, &widget->style->white, X49GP_UI_NORMAL_FONT, 13.0, 0.0, 14 /* 38 */, 34 /* 56 */, 1,
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "Graphing Calculator" ); CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL, "Graphing Calculator" );
x49gp_ui_draw_symbol( cr, &widget->style->white, 10.0, 0.0, TRUE, 134 /* 168 */, 8 /* 25 */, x49gp_ui_draw_symbol( cr, &widget->style->white, 10.0, 0.0, true, 134 /* 168 */, 8 /* 25 */,
symbol_get_by_name( "triangleup" ) ); symbol_get_by_name( "triangleup" ) );
left_color = UI_COLOR_WHITE; left_color = UI_COLOR_WHITE;
@ -3185,16 +3186,16 @@ static int x49gp_window_configure_event( GtkWidget* widget, GdkEventConfigure* e
#if 0 /* Debug Button Layout */ #if 0 /* Debug Button Layout */
gdk_draw_rectangle(ui->bg_pixmap, ui->window->style->white_gc, gdk_draw_rectangle(ui->bg_pixmap, ui->window->style->white_gc,
FALSE, false,
ui->kb_x_offset + key->x, ui->kb_x_offset + key->x,
ui->kb_y_offset + key->y, ui->kb_y_offset + key->y,
key->width, key->height); key->width, key->height);
#endif #endif
} }
gdk_window_set_back_pixmap( widget->window, ui->bg_pixmap, FALSE ); gdk_window_set_back_pixmap( widget->window, ui->bg_pixmap, false );
return FALSE; return false;
} }
static gboolean x49gp_window_button_press( GtkWidget* widget, GdkEventButton* event, gpointer user_data ) static gboolean x49gp_window_button_press( GtkWidget* widget, GdkEventButton* event, gpointer user_data )
@ -3207,14 +3208,14 @@ static gboolean x49gp_window_button_press( GtkWidget* widget, GdkEventButton* ev
gdk_window_raise( widget->window ); gdk_window_raise( widget->window );
if ( event->type != GDK_BUTTON_PRESS ) if ( event->type != GDK_BUTTON_PRESS )
return FALSE; return false;
if ( event->button != 1 ) if ( event->button != 1 )
return FALSE; return false;
gdk_window_begin_move_drag( widget->window, event->button, event->x_root, event->y_root, event->time ); gdk_window_begin_move_drag( widget->window, event->button, event->x_root, event->y_root, event->time );
return FALSE; return false;
} }
static void x49gp_ui_quit( gpointer user_data, GtkWidget* widget, GdkEvent* event ) static void x49gp_ui_quit( gpointer user_data, GtkWidget* widget, GdkEvent* event )
@ -3321,11 +3322,11 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
close( fd ); close( fd );
ui->window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); ui->window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_widget_set( ui->window, "can-focus", TRUE, NULL ); gtk_widget_set( ui->window, "can-focus", true, NULL );
gtk_widget_set( ui->window, "accept-focus", TRUE, NULL ); gtk_widget_set( ui->window, "accept-focus", true, NULL );
gtk_widget_set( ui->window, "focus-on-map", TRUE, NULL ); gtk_widget_set( ui->window, "focus-on-map", true, NULL );
gtk_widget_set( ui->window, "resizable", FALSE, NULL ); gtk_widget_set( ui->window, "resizable", false, NULL );
gtk_window_set_decorated( GTK_WINDOW( ui->window ), TRUE ); gtk_window_set_decorated( GTK_WINDOW( ui->window ), true );
gtk_widget_set_name( ui->window, ui->name ); gtk_widget_set_name( ui->window, ui->name );
gtk_window_set_title( GTK_WINDOW( ui->window ), ui->name ); gtk_window_set_title( GTK_WINDOW( ui->window ), ui->name );
@ -3388,8 +3389,8 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
ui->lcd_canvas = gtk_drawing_area_new(); ui->lcd_canvas = gtk_drawing_area_new();
gtk_drawing_area_size( GTK_DRAWING_AREA( ui->lcd_canvas ), ui->lcd_width, ui->lcd_height ); gtk_drawing_area_size( GTK_DRAWING_AREA( ui->lcd_canvas ), ui->lcd_width, ui->lcd_height );
screen_box = gtk_event_box_new(); screen_box = gtk_event_box_new();
gtk_event_box_set_visible_window( GTK_EVENT_BOX( screen_box ), TRUE ); gtk_event_box_set_visible_window( GTK_EVENT_BOX( screen_box ), true );
gtk_event_box_set_above_child( GTK_EVENT_BOX( screen_box ), FALSE ); gtk_event_box_set_above_child( GTK_EVENT_BOX( screen_box ), false );
gtk_container_add( GTK_CONTAINER( screen_box ), ui->lcd_canvas ); gtk_container_add( GTK_CONTAINER( screen_box ), ui->lcd_canvas );
x49gp_ui_place_at( x49gp, GTK_FIXED( ui->fixed ), screen_box, ui->lcd_x_offset, ui->lcd_y_offset, ui->lcd_width, ui->lcd_height ); x49gp_ui_place_at( x49gp, GTK_FIXED( ui->fixed ), screen_box, ui->lcd_x_offset, ui->lcd_y_offset, ui->lcd_width, ui->lcd_height );
@ -3418,7 +3419,7 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
button->button = gtk_button_new(); button->button = gtk_button_new();
gtk_widget_set_size_request( button->button, key->width, key->height ); gtk_widget_set_size_request( button->button, key->width, key->height );
gtk_widget_set( button->button, "can-focus", FALSE, NULL ); gtk_widget_set( button->button, "can-focus", false, NULL );
x49gp_ui_button_pixmaps_init( x49gp, button, key->color ); x49gp_ui_button_pixmaps_init( x49gp, button, key->color );
@ -3433,8 +3434,8 @@ static int gui_load( x49gp_module_t* module, GKeyFile* keyfile )
} }
button->box = gtk_event_box_new(); button->box = gtk_event_box_new();
gtk_event_box_set_visible_window( GTK_EVENT_BOX( button->box ), TRUE ); gtk_event_box_set_visible_window( GTK_EVENT_BOX( button->box ), true );
gtk_event_box_set_above_child( GTK_EVENT_BOX( button->box ), FALSE ); gtk_event_box_set_above_child( GTK_EVENT_BOX( button->box ), false );
gtk_widget_shape_combine_mask( button->box, ui->shapes[ key->shape ], 0, 0 ); gtk_widget_shape_combine_mask( button->box, ui->shapes[ key->shape ], 0, 0 );
gtk_container_add( GTK_CONTAINER( button->box ), button->button ); gtk_container_add( GTK_CONTAINER( button->box ), button->button );