save_options() from main to x48; deduplicate exit_x48()

This commit is contained in:
Gwenhael Le Moine 2023-05-04 16:06:57 +02:00
parent 7b4039d65c
commit 76e9272d9e
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
3 changed files with 584 additions and 590 deletions

View file

@ -39,45 +39,11 @@ void signal_handler( int sig ) {
}
}
#if defined( GUI_IS_X11 )
void save_options( int argc, char** argv ) {
int l;
saved_argc = argc;
saved_argv = ( char** )malloc( ( argc + 2 ) * sizeof( char* ) );
if ( saved_argv == ( char** )0 ) {
fprintf( stderr, "%s: malloc failed in save_options(), exit\n",
progname );
exit( 1 );
}
saved_argv[ argc ] = ( char* )0;
while ( argc-- ) {
l = strlen( argv[ argc ] ) + 1;
saved_argv[ argc ] = ( char* )malloc( l );
if ( saved_argv[ argc ] == ( char* )0 ) {
fprintf( stderr, "%s: malloc failed in save_options(), exit\n",
progname );
exit( 1 );
}
memcpy( saved_argv[ argc ], argv[ argc ], l );
}
}
#endif
int main( int argc, char** argv ) {
sigset_t set;
struct sigaction sa;
long flags;
struct itimerval it;
#if defined( GUI_IS_SDL1 )
int rv, i;
// SDL Initialization
SDLInit();
// Global parameter initialization
get_resources();
#endif
setlocale( LC_ALL, "C" );
@ -129,12 +95,17 @@ int main( int argc, char** argv ) {
"",
"Install these files and try again.",
0 };
// SDL Initialization
SDLInit();
// Global parameter initialization
get_resources();
// initialize emulator stuff
rv = init_emulator();
int rv = init_emulator();
if ( rv != 0 ) {
printf( "%s\n", errinit_title );
for ( i = 0; errinit_text[ i ]; i++ )
for ( int i = 0; errinit_text[ i ]; i++ )
printf( "%s\n", errinit_text[ i ] );
SDLMessageBox( 300, 200, errinit_title, errinit_text, 0xf0e0c0c0,
0xff000000, 0 );
@ -158,6 +129,7 @@ int main( int argc, char** argv ) {
init_display();
}
/*
* install a handler for SIGALRM
*/

View file

@ -1724,6 +1724,17 @@ int SmallTextWidth( const char* string, unsigned int length ) {
return w;
}
void exit_x48( int tell_x11 ) {
exit_emulator();
#if defined( GUI_IS_X11 )
if ( tell_x11 )
XCloseDisplay( dpy );
#endif
exit( 0 );
}
#if defined( GUI_IS_X11 )
int DrawSmallString( Display* the_dpy, Drawable d, GC the_gc, int x, int y,
const char* string, unsigned int length ) {
@ -3686,6 +3697,29 @@ void get_geometry_string( Window win, char* s, int allow_off_screen ) {
x, ( y_s > 0 ) ? "+" : "-", y );
}
void save_options( int argc, char** argv ) {
int l;
saved_argc = argc;
saved_argv = ( char** )malloc( ( argc + 2 ) * sizeof( char* ) );
if ( saved_argv == ( char** )0 ) {
fprintf( stderr, "%s: malloc failed in save_options(), exit\n",
progname );
exit( 1 );
}
saved_argv[ argc ] = ( char* )0;
while ( argc-- ) {
l = strlen( argv[ argc ] ) + 1;
saved_argv[ argc ] = ( char* )malloc( l );
if ( saved_argv[ argc ] == ( char* )0 ) {
fprintf( stderr, "%s: malloc failed in save_options(), exit\n",
progname );
exit( 1 );
}
memcpy( saved_argv[ argc ], argv[ argc ], l );
}
}
void save_command_line( void ) {
XWindowAttributes xwa;
int wm_argc, ac;
@ -3736,13 +3770,6 @@ void save_command_line( void ) {
XSetCommand( dpy, mainW, wm_argv, wm_argc );
}
void exit_x48( int tell_x11 ) {
exit_emulator();
if ( tell_x11 )
XCloseDisplay( dpy );
exit( 0 );
}
int decode_key( XEvent* xev, KeySym sym, char* buf, int buflen ) {
int wake;
@ -4178,12 +4205,6 @@ static int button_release_all( void ) {
return 0;
}
void exit_x48( int tell_x11 ) {
exit_emulator();
exit( 0 );
}
#define MAX_PASTE 128
int paste[ MAX_PASTE * 3 ];
int paste_count = 0;

1083
src/x48.h

File diff suppressed because it is too large Load diff