store config in a struct

This commit is contained in:
Gwenhael Le Moine 2024-04-14 11:41:46 +02:00
parent 91f6bbe0ce
commit 56d1f70f95
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
11 changed files with 337 additions and 330 deletions

View file

@ -4076,24 +4076,24 @@ int debug( void )
/*
* do we want to debug ???
*/
if ( !useDebugger ) {
if ( !config.useDebugger ) {
if ( enter_debugger & ILLEGAL_INSTRUCTION ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "reset (illegal instruction at 0x%.5lX)\n", saturn.PC );
saturn.PC = 0;
}
if ( enter_debugger & USER_INTERRUPT )
if ( verbose )
if ( config.verbose )
printf( "usnterrupt (SIGINT) ignored\n" );
exit_emulator();
exit( 1 );
if ( enter_debugger & BREAKPOINT_HIT )
if ( verbose )
if ( config.verbose )
printf( "breakpoint hit at 0x%.5lX ignored\n", saturn.PC );
if ( enter_debugger & TRAP_INSTRUCTION )
if ( verbose )
if ( config.verbose )
printf( "trap instruction at 0x%.5lX ignored\n", saturn.PC );
enter_debugger = 0;

View file

@ -320,7 +320,7 @@ static inline int get_identification( void )
static inline void do_shutdown( void )
{
if ( inhibit_shutdown )
if ( config.inhibit_shutdown )
return;
/***************************/
@ -2861,7 +2861,7 @@ void emulate( void )
step_instruction();
for ( int i = 0; i < ( int )( sizeof( saturn.keybuf.rows ) / sizeof( saturn.keybuf.rows[ 0 ] ) ); i++ ) {
if ( saturn.keybuf.rows[ i ] || throttle ) {
if ( saturn.keybuf.rows[ i ] || config.throttle ) {
/* Throttling speed if needed */
gettimeofday( &tv, &tz );
gettimeofday( &tv2, &tz );

View file

@ -146,7 +146,7 @@ int read_8( FILE* fp, word_8* var )
unsigned char tmp;
if ( fread( &tmp, 1, 1, fp ) != 1 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read word_8\n" );
return 0;
}
@ -159,7 +159,7 @@ int read_char( FILE* fp, char* var )
char tmp;
if ( fread( &tmp, 1, 1, fp ) != 1 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read char\n" );
return 0;
}
@ -172,7 +172,7 @@ int read_16( FILE* fp, word_16* var )
unsigned char tmp[ 2 ];
if ( fread( &tmp[ 0 ], 1, 2, fp ) != 2 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read word_16\n" );
return 0;
}
@ -186,7 +186,7 @@ int read_32( FILE* fp, word_32* var )
unsigned char tmp[ 4 ];
if ( fread( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read word_32\n" );
return 0;
}
@ -202,7 +202,7 @@ int read_u_long( FILE* fp, unsigned long* var )
unsigned char tmp[ 4 ];
if ( fread( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read unsigned long\n" );
return 0;
}
@ -388,13 +388,13 @@ int read_mem_file( char* name, word_4* mem, int size )
int i, j;
if ( NULL == ( fp = fopen( name, "r" ) ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ct open %s\n", name );
return 0;
}
if ( stat( name, &st ) < 0 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t stat %s\n", name );
return 0;
}
@ -404,7 +404,7 @@ int read_mem_file( char* name, word_4* mem, int size )
* size is same as memory size, old version file
*/
if ( fread( mem, 1, ( size_t )size, fp ) != ( unsigned long )size ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read %s\n", name );
fclose( fp );
return 0;
@ -415,7 +415,7 @@ int read_mem_file( char* name, word_4* mem, int size )
*/
if ( st.st_size != size / 2 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "strange size %s, expected %d, found %ld\n", name, size / 2, st.st_size );
fclose( fp );
return 0;
@ -424,7 +424,7 @@ int read_mem_file( char* name, word_4* mem, int size )
if ( NULL == ( tmp_mem = ( word_8* )malloc( ( size_t )st.st_size ) ) ) {
for ( i = 0, j = 0; i < size / 2; i++ ) {
if ( 1 != fread( &byte, 1, 1, fp ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read %s\n", name );
fclose( fp );
return 0;
@ -434,7 +434,7 @@ int read_mem_file( char* name, word_4* mem, int size )
}
} else {
if ( fread( tmp_mem, 1, ( size_t )size / 2, fp ) != ( unsigned long )( size / 2 ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read %s\n", name );
fclose( fp );
free( tmp_mem );
@ -452,7 +452,7 @@ int read_mem_file( char* name, word_4* mem, int size )
fclose( fp );
if ( verbose )
if ( config.verbose )
printf( "read %s\n", name );
return 1;
@ -473,7 +473,7 @@ int read_files( void )
if ( !read_rom_file( normalized_rom_path, &saturn.rom, &rom_size ) )
return 0;
if ( verbose )
if ( config.verbose )
printf( "read %s\n", normalized_rom_path );
rom_is_new = false;
@ -482,7 +482,7 @@ int read_files( void )
/* 2. read saved state from ~/.x48ng/state into fp */
/**************************************************/
if ( NULL == ( fp = fopen( normalized_state_path, "r" ) ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t open %s\n", normalized_state_path );
return 0;
}
@ -506,7 +506,7 @@ int read_files( void )
read_version = 1;
for ( i = 0; i < 4; i++ ) {
if ( !read_char( fp, &saturn.version[ i ] ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t read version\n" );
read_version = 0;
}
@ -525,10 +525,10 @@ int read_files( void )
* try to read latest version file
*/
if ( !read_state_file( fp ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t handle %s\n", normalized_state_path );
init_saturn();
} else if ( verbose )
} else if ( config.verbose )
printf( "read %s\n", normalized_state_path );
}
}
@ -542,7 +542,7 @@ int read_files( void )
saturn.ram = ( word_4* )NULL;
if ( NULL == ( saturn.ram = ( word_4* )malloc( ram_size ) ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t malloc RAM[%d]\n", ram_size );
exit( 1 );
}
@ -551,7 +551,7 @@ int read_files( void )
/* 3. read RAM from ~/.x48ng/ram into saturn.ram */
/*************************************************/
if ( ( fp = fopen( normalized_ram_path, "r" ) ) == NULL ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t open %s\n", normalized_ram_path );
return 0;
}
@ -575,7 +575,7 @@ int read_files( void )
port1_size = 2 * st.st_size;
if ( ( port1_size == 0x10000 ) || ( port1_size == 0x40000 ) ) {
if ( NULL == ( saturn.port1 = ( word_4* )malloc( port1_size ) ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t malloc PORT1[%ld]\n", port1_size );
} else if ( !read_mem_file( normalized_port1_path, saturn.port1, port1_size ) ) {
port1_size = 0;
@ -608,7 +608,7 @@ int read_files( void )
if ( ( opt_gx && ( ( port2_size % 0x40000 ) == 0 ) ) ||
( !opt_gx && ( ( port2_size == 0x10000 ) || ( port2_size == 0x40000 ) ) ) ) {
if ( NULL == ( saturn.port2 = ( word_4* )malloc( port2_size ) ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t malloc PORT2[%ld]\n", port2_size );
} else if ( !read_mem_file( normalized_port2_path, saturn.port2, port2_size ) ) {
port2_size = 0;
@ -644,7 +644,7 @@ int write_8( FILE* fp, word_8* var )
tmp = *var;
if ( fwrite( &tmp, 1, 1, fp ) != 1 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t write word_8\n" );
return 0;
}
@ -657,7 +657,7 @@ int write_char( FILE* fp, char* var )
tmp = *var;
if ( fwrite( &tmp, 1, 1, fp ) != 1 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t write char\n" );
return 0;
}
@ -671,7 +671,7 @@ int write_16( FILE* fp, word_16* var )
tmp[ 0 ] = ( *var >> 8 ) & 0xff;
tmp[ 1 ] = *var & 0xff;
if ( fwrite( &tmp[ 0 ], 1, 2, fp ) != 2 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t write word_16\n" );
return 0;
}
@ -687,7 +687,7 @@ int write_32( FILE* fp, word_32* var )
tmp[ 2 ] = ( *var >> 8 ) & 0xff;
tmp[ 3 ] = *var & 0xff;
if ( fwrite( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t write word_32\n" );
return 0;
}
@ -703,7 +703,7 @@ int write_u_long( FILE* fp, unsigned long* var )
tmp[ 2 ] = ( *var >> 8 ) & 0xff;
tmp[ 3 ] = *var & 0xff;
if ( fwrite( &tmp[ 0 ], 1, 4, fp ) != 4 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t write unsigned long\n" );
return 0;
}
@ -718,7 +718,7 @@ int write_mem_file( char* name, word_4* mem, int size )
int i, j;
if ( NULL == ( fp = fopen( name, "w" ) ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t open %s\n", name );
return 0;
}
@ -728,7 +728,7 @@ int write_mem_file( char* name, word_4* mem, int size )
byte = ( mem[ j++ ] & 0x0f );
byte |= ( mem[ j++ ] << 4 ) & 0xf0;
if ( 1 != fwrite( &byte, 1, 1, fp ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t write %s\n", name );
fclose( fp );
return 0;
@ -741,7 +741,7 @@ int write_mem_file( char* name, word_4* mem, int size )
}
if ( fwrite( tmp_mem, 1, ( size_t )size / 2, fp ) != ( unsigned long )size / 2 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t write %s\n", name );
fclose( fp );
free( tmp_mem );
@ -753,7 +753,7 @@ int write_mem_file( char* name, word_4* mem, int size )
fclose( fp );
if ( verbose )
if ( config.verbose )
printf( "wrote %s\n", name );
return 1;
@ -765,7 +765,7 @@ int write_state_file( char* filename )
FILE* fp;
if ( ( fp = fopen( filename, "w" ) ) == NULL ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t open %s, no saving done\n", filename );
return 0;
}
@ -865,7 +865,7 @@ int write_state_file( char* filename )
fclose( fp );
if ( verbose )
if ( config.verbose )
printf( "wrote %s\n", filename );
return 1;
@ -881,13 +881,13 @@ int write_files( void )
if ( errno == ENOENT ) {
make_dir = true;
} else {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t stat %s, saving to /tmp\n", normalized_config_path );
strcpy( normalized_config_path, "/tmp" );
}
} else {
if ( !S_ISDIR( st.st_mode ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "%s is no directory, saving to /tmp\n", normalized_config_path );
strcpy( normalized_config_path, "/tmp" );
}
@ -895,7 +895,7 @@ int write_files( void )
if ( make_dir ) {
if ( mkdir( normalized_config_path, 0777 ) == -1 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t mkdir %s, saving to /tmp\n", normalized_config_path );
strcpy( normalized_config_path, "/tmp" );
}
@ -914,7 +914,7 @@ int write_files( void )
if ( !write_mem_file( new_rom_path, saturn.rom, rom_size ) )
return 0;
if ( verbose )
if ( config.verbose )
printf( "wrote %s\n", new_rom_path );
}
@ -941,7 +941,7 @@ int read_rom( const char* fname )
if ( !read_rom_file( fname, &saturn.rom, &rom_size ) )
return 0;
if ( verbose )
if ( config.verbose )
printf( "read %s\n", fname );
dev_memory_init();
@ -949,7 +949,7 @@ int read_rom( const char* fname )
ram_size = opt_gx ? RAM_SIZE_GX : RAM_SIZE_SX;
if ( NULL == ( saturn.ram = ( word_4* )malloc( ram_size ) ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t malloc RAM\n" );
return 0;
}
@ -1000,11 +1000,11 @@ void start_emulator( void )
{
/* If files are successfully read => return and let's go */
if ( read_files() ) {
if ( resetOnStartup )
if ( config.resetOnStartup )
saturn.PC = 0x00000;
} else {
/* if files were not readable => initialize */
if ( verbose )
if ( config.verbose )
fprintf( stderr, "initialization of %s\n", normalized_config_path );
init_saturn();

View file

@ -264,7 +264,7 @@ void write_dev_mem( long addr, int val )
device.t2_touched = true;
return;
default:
if ( verbose )
if ( config.verbose )
fprintf( stderr, "%.5lx: UNKNOWN DEVICE WRITE AT 0x%lx !!!\n", saturn.PC, addr );
return;
}
@ -379,7 +379,7 @@ int read_dev_mem( long addr )
case 0x13f:
return ( saturn.timer2 >> ( ( addr - 0x138 ) * 4 ) ) & 0xf;
default:
if ( verbose )
if ( config.verbose )
fprintf( stderr, "%.5lx: UNKNOWN DEVICE READ AT 0x%lx !!!\n", saturn.PC, addr );
return 0x00;
}

View file

@ -43,7 +43,7 @@ int init_serial( void )
wire_fd = -1;
ttyp = -1;
if ( useTerminal ) {
if ( config.useTerminal ) {
/* Unix98 PTY (Preferred) */
if ( ( wire_fd = open( "/dev/ptmx", O_RDWR | O_NONBLOCK, 0666 ) ) >= 0 ) {
grantpt( wire_fd );
@ -53,7 +53,7 @@ int init_serial( void )
exit( -1 );
}
if ( ( ttyp = open( tty_dev_name, O_RDWR | O_NDELAY, 0666 ) ) >= 0 ) {
if ( verbose )
if ( config.verbose )
printf( "wire connection on %s\n", tty_dev_name );
wire_name = strdup( tty_dev_name );
}
@ -67,7 +67,7 @@ int init_serial( void )
if ( ( wire_fd = open( tty_dev_name, O_RDWR | O_EXCL | O_NDELAY, 0666 ) ) >= 0 ) {
ttyp = wire_fd;
sprintf( tty_dev_name, "/dev/tty%c%x", c, n );
if ( verbose )
if ( config.verbose )
printf( "wire connection on %s\n", tty_dev_name );
wire_name = strdup( tty_dev_name );
break;
@ -85,7 +85,7 @@ int init_serial( void )
if ( ioctl( ttyp, TCGETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(wire, TCGETS) failed, errno = %d\n", errno );
wire_fd = -1;
ttyp = -1;
@ -108,7 +108,7 @@ int init_serial( void )
if ( ioctl( ttyp, TCSETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(wire, TCSETS) failed, errno = %d\n", errno );
wire_fd = -1;
ttyp = -1;
@ -116,10 +116,10 @@ int init_serial( void )
}
ir_fd = -1;
if ( useSerial ) {
sprintf( tty_dev_name, "%s", serialLine );
if ( config.useSerial ) {
sprintf( tty_dev_name, "%s", config.serialLine );
if ( ( ir_fd = open( tty_dev_name, O_RDWR | O_NDELAY ) ) >= 0 ) {
if ( verbose )
if ( config.verbose )
printf( "IR connection on %s\n", tty_dev_name );
ir_name = strdup( tty_dev_name );
}
@ -132,7 +132,7 @@ int init_serial( void )
if ( ioctl( ir_fd, TCGETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(IR, TCGETS) failed, errno = %d\n", errno );
ir_fd = -1;
}
@ -154,7 +154,7 @@ int init_serial( void )
if ( ioctl( ir_fd, TCSETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(IR, TCSETS) failed, errno = %d\n", errno );
ir_fd = -1;
@ -176,7 +176,7 @@ void serial_baud( int baud )
if ( ioctl( ir_fd, TCGETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(IR, TCGETS) failed, errno = %d\n", errno );
ir_fd = -1;
@ -222,7 +222,7 @@ void serial_baud( int baud )
}
if ( ( ir_fd >= 0 ) && ( ( ttybuf.c_ospeed ) == 0 ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t set baud rate, using 9600\n" );
ttybuf.c_cflag |= B9600;
}
@ -266,7 +266,7 @@ void serial_baud( int baud )
}
if ( ( ir_fd >= 0 ) && ( ( ttybuf.c_cflag & CBAUD ) == 0 ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t set baud rate, using 9600\n" );
ttybuf.c_cflag |= B9600;
@ -279,7 +279,7 @@ void serial_baud( int baud )
if ( ioctl( ir_fd, TCSETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(IR, TCSETS) failed, errno = %d\n", errno );
ir_fd = -1;
@ -294,7 +294,7 @@ void serial_baud( int baud )
if ( ioctl( ttyp, TCGETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(wire, TCGETS) failed, errno = %d\n", errno );
wire_fd = -1;
@ -344,7 +344,7 @@ void serial_baud( int baud )
}
if ( ( ttyp >= 0 ) && ( ( ttybuf.c_cflag & CBAUD ) == 0 ) ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t set baud rate, using 9600\n" );
ttybuf.c_cflag |= B9600;
@ -357,7 +357,7 @@ void serial_baud( int baud )
if ( ioctl( ttyp, TCSETS, ( char* )&ttybuf ) < 0 )
#endif
{
if ( verbose )
if ( config.verbose )
fprintf( stderr, "ioctl(wire, TCSETS) failed, errno = %d\n", errno );
wire_fd = -1;
@ -408,7 +408,7 @@ void transmit_char( void )
if ( saturn.io_ctrl & 0x04 )
do_interupt();
} else {
if ( errno != EAGAIN && verbose )
if ( errno != EAGAIN && config.verbose )
fprintf( stderr, "serial write error: %d\n", errno );
saturn.tcs &= 0x0e;

View file

@ -15,17 +15,51 @@
#include "runtime_options.h"
char* progname = "x48ng";
config_t config = {
.progname = "x48ng",
bool verbose = false;
bool print_config = false;
bool useTerminal = false;
bool useSerial = false;
bool useDebugger = false;
bool throttle = false;
bool resetOnStartup = false;
.verbose = false,
.print_config = false,
.useTerminal = false,
.useSerial = false,
.useDebugger = false,
.throttle = false,
.resetOnStartup = false,
char* serialLine;
.serialLine = NULL,
.frontend_type = FRONTEND_TEXT,
.leave_shift_keys = false,
.inhibit_shutdown = false,
.mono = false,
.gray = false,
/* tui */
.small = false,
.tiny = false,
/* sdl */
.hide_chrome = false,
.show_ui_fullscreen = false,
/* x11 */
.netbook = false,
.name = "x48ng",
.title = "x48ng",
.x11_visual = NULL,
/* default | staticgray | staticcolor | truecolor | grayscale |
* pseudocolor | directcolor | 0xnn | nn
*/
.monoIcon = false,
.iconic = false,
.xrm = true,
.smallFont = NULL,
.mediumFont = NULL,
.largeFont = NULL,
.connFont = NULL,
};
char* configDir = "x48ng";
char* config_file = "config.lua";
@ -35,38 +69,6 @@ char* stateFileName = NULL;
char* port1FileName = NULL;
char* port2FileName = NULL;
int frontend_type = FRONTEND_TEXT;
bool leave_shift_keys = false;
bool inhibit_shutdown = false;
bool mono = false;
bool gray = false;
/* tui */
bool small = false;
bool tiny = false;
/* sdl */
bool hide_chrome = false;
bool show_ui_fullscreen = false;
/* x11 */
bool netbook = false;
char* name = "x48ng";
char* title = "x48ng";
char* x11_visual = NULL;
/* default | staticgray | staticcolor | truecolor | grayscale |
* pseudocolor | directcolor | 0xnn | nn
*/
bool monoIcon = false;
bool iconic = false;
bool xrm = true;
char* smallFont = NULL;
char* mediumFont = NULL;
char* largeFont = NULL;
char* connFont = NULL;
char normalized_config_path[ MAX_LENGTH_FILENAME ];
char normalized_config_file[ MAX_LENGTH_FILENAME ];
char normalized_rom_path[ MAX_LENGTH_FILENAME ];
@ -143,7 +145,7 @@ static inline void get_absolute_config_dir( char* source, char* dest )
char* xdg_config_home = getenv( "XDG_CONFIG_HOME" );
if ( xdg_config_home ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XDG_CONFIG_HOME is %s\n", xdg_config_home );
strcpy( dest, xdg_config_home );
@ -152,7 +154,7 @@ static inline void get_absolute_config_dir( char* source, char* dest )
char* home = getenv( "HOME" );
if ( home ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "HOME is %s\n", home );
strcpy( dest, home );
@ -161,13 +163,13 @@ static inline void get_absolute_config_dir( char* source, char* dest )
struct passwd* pwd = getpwuid( getuid() );
if ( pwd ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "pwd->pw_dir is %s\n", pwd->pw_dir );
strcpy( dest, pwd->pw_dir );
strcat( dest, "/" );
} else {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t figure out your home directory, "
"trying /tmp\n" );
@ -197,7 +199,7 @@ static inline bool normalize_config_dir( void )
struct stat st;
get_absolute_config_dir( configDir, normalized_config_path );
if ( verbose )
if ( config.verbose )
fprintf( stderr, "normalized_config_path: %s\n", normalized_config_path );
if ( stat( normalized_config_path, &st ) == -1 )
@ -253,53 +255,53 @@ int parse_args_and_read_config( int argc, char* argv[] )
char* optstring = "c:hvVtsirT";
struct option long_options[] = {
{"config", required_argument, NULL, 'c' },
{"config-dir", required_argument, NULL, 1000 },
{"rom", required_argument, NULL, 1010 },
{"ram", required_argument, NULL, 1011 },
{"state", required_argument, NULL, 1012 },
{"port1", required_argument, NULL, 1013 },
{"port2", required_argument, NULL, 1014 },
{"config", required_argument, NULL, 'c' },
{"config-dir", required_argument, NULL, 1000 },
{"rom", required_argument, NULL, 1010 },
{"ram", required_argument, NULL, 1011 },
{"state", required_argument, NULL, 1012 },
{"port1", required_argument, NULL, 1013 },
{"port2", required_argument, NULL, 1014 },
{"serial-line", required_argument, NULL, 1015 },
{"serial-line", required_argument, NULL, 1015 },
{"help", no_argument, NULL, 'h' },
{"version", no_argument, NULL, 'v' },
{"help", no_argument, NULL, 'h' },
{"version", no_argument, NULL, 'v' },
{"print-config", no_argument, ( int* )&print_config, true },
{"verbose", no_argument, &clopt_verbose, true },
{"terminal", no_argument, &clopt_useTerminal, true },
{"serial", no_argument, &clopt_useSerial, true },
{"print-config", no_argument, ( int* )&config.print_config, true },
{"verbose", no_argument, &clopt_verbose, true },
{"terminal", no_argument, &clopt_useTerminal, true },
{"serial", no_argument, &clopt_useSerial, true },
{"reset", no_argument, ( int* )&resetOnStartup, true },
{"throttle", no_argument, &clopt_throttle, true },
{"reset", no_argument, ( int* )&config.resetOnStartup, true },
{"throttle", no_argument, &clopt_throttle, true },
{"debug", no_argument, &clopt_useDebugger, true },
{"debug", no_argument, &clopt_useDebugger, true },
{"sdl", no_argument, &clopt_frontend_type, FRONTEND_SDL},
{"no-chrome", no_argument, &clopt_hide_chrome, true },
{"fullscreen", no_argument, &clopt_show_ui_fullscreen, true },
{"sdl", no_argument, &clopt_frontend_type, FRONTEND_SDL},
{"no-chrome", no_argument, &clopt_hide_chrome, true },
{"fullscreen", no_argument, &clopt_show_ui_fullscreen, true },
{"x11", no_argument, &clopt_frontend_type, FRONTEND_X11},
{"netbook", no_argument, &clopt_netbook, true },
{"visual", required_argument, NULL, 8110 },
{"small-font", required_argument, NULL, 8111 },
{"medium-font", required_argument, NULL, 8112 },
{"large-font", required_argument, NULL, 8113 },
{"connection-font", required_argument, NULL, 8114 },
{"x11", no_argument, &clopt_frontend_type, FRONTEND_X11},
{"netbook", no_argument, &clopt_netbook, true },
{"visual", required_argument, NULL, 8110 },
{"small-font", required_argument, NULL, 8111 },
{"medium-font", required_argument, NULL, 8112 },
{"large-font", required_argument, NULL, 8113 },
{"connection-font", required_argument, NULL, 8114 },
{"tui", no_argument, NULL, 9100 },
{"tui-small", no_argument, NULL, 9110 },
{"tui-tiny", no_argument, NULL, 9120 },
{"small", no_argument, NULL, 9109 }, /* DEPRECATED */
{"tiny", no_argument, NULL, 9119 }, /* DEPRECATED */
{"tui", no_argument, NULL, 9100 },
{"tui-small", no_argument, NULL, 9110 },
{"tui-tiny", no_argument, NULL, 9120 },
{"small", no_argument, NULL, 9109 }, /* DEPRECATED */
{"tiny", no_argument, NULL, 9119 }, /* DEPRECATED */
{"mono", no_argument, &clopt_mono, true },
{"gray", no_argument, &clopt_gray, true },
{"leave-shift-keys", no_argument, &clopt_leave_shift_keys, true },
{"inhibit-shutdown", no_argument, &clopt_inhibit_shutdown, true },
{"mono", no_argument, &clopt_mono, true },
{"gray", no_argument, &clopt_gray, true },
{"leave-shift-keys", no_argument, &clopt_leave_shift_keys, true },
{"inhibit-shutdown", no_argument, &clopt_inhibit_shutdown, true },
{0, 0, 0, 0 }
{0, 0, 0, 0 }
};
char* help_text = "usage: %s [options]\n"
@ -368,11 +370,12 @@ int parse_args_and_read_config( int argc, char* argv[] )
switch ( c ) {
case 'h':
fprintf( stderr, help_text, progname, serialLine, smallFont, mediumFont, largeFont, connFont );
fprintf( stderr, help_text, config.progname, config.serialLine, config.smallFont, config.mediumFont, config.largeFont,
config.connFont );
exit( 0 );
break;
case 'v':
fprintf( stderr, "%s %d.%d.%d\n", progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL );
fprintf( stderr, "%s %d.%d.%d\n", config.progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL );
exit( 0 );
break;
case 'c':
@ -443,7 +446,7 @@ int parse_args_and_read_config( int argc, char* argv[] )
clopt_useSerial = true;
break;
case 'r':
resetOnStartup = true;
config.resetOnStartup = true;
break;
case 'T':
clopt_throttle = true;
@ -476,9 +479,9 @@ int parse_args_and_read_config( int argc, char* argv[] )
fprintf( stderr, "\nConfiguration file %s doesn't seem to exist or is invalid!\n", normalized_config_file );
fprintf( stderr, "Continuing using default configuration as printed below.\n\n" );
fprintf( stderr, "You can solve this by running `mkdir -p %s && %s --print-config >> %s`\n\n", normalized_config_path, progname,
normalized_config_file );
print_config = true;
fprintf( stderr, "You can solve this by running `mkdir -p %s && %s --print-config >> %s`\n\n", normalized_config_path,
config.progname, normalized_config_file );
config.print_config = true;
}
lua_getglobal( config_lua_values, "config_dir" );
@ -500,19 +503,19 @@ int parse_args_and_read_config( int argc, char* argv[] )
port2FileName = ( char* )luaL_optstring( config_lua_values, -1, "port2" );
lua_getglobal( config_lua_values, "serial_line" );
serialLine = ( char* )luaL_optstring( config_lua_values, -1, "/dev/ttyS0" );
config.serialLine = ( char* )luaL_optstring( config_lua_values, -1, "/dev/ttyS0" );
lua_getglobal( config_lua_values, "pseudo_terminal" );
useTerminal = lua_toboolean( config_lua_values, -1 );
config.useTerminal = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "serial" );
useSerial = lua_toboolean( config_lua_values, -1 );
config.useSerial = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "debugger" );
useDebugger = lua_toboolean( config_lua_values, -1 );
config.useDebugger = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "throttle" );
throttle = lua_toboolean( config_lua_values, -1 );
config.throttle = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "frontend" );
#ifdef HAS_X11
@ -525,69 +528,69 @@ int parse_args_and_read_config( int argc, char* argv[] )
const char* svalue = luaL_optstring( config_lua_values, -1, DEFAULT_FRONTEND );
if ( svalue != NULL ) {
if ( strcmp( svalue, "x11" ) == 0 )
frontend_type = FRONTEND_X11;
config.frontend_type = FRONTEND_X11;
if ( strcmp( svalue, "sdl" ) == 0 )
frontend_type = FRONTEND_SDL;
config.frontend_type = FRONTEND_SDL;
if ( strcmp( svalue, "tui" ) == 0 ) {
frontend_type = FRONTEND_TEXT;
small = false;
tiny = false;
config.frontend_type = FRONTEND_TEXT;
config.small = false;
config.tiny = false;
}
if ( strcmp( svalue, "tui-small" ) == 0 ) {
frontend_type = FRONTEND_TEXT;
small = true;
tiny = false;
config.frontend_type = FRONTEND_TEXT;
config.small = true;
config.tiny = false;
}
if ( strcmp( svalue, "tui-tiny" ) == 0 ) {
frontend_type = FRONTEND_TEXT;
small = false;
tiny = true;
config.frontend_type = FRONTEND_TEXT;
config.small = false;
config.tiny = true;
}
}
lua_getglobal( config_lua_values, "hide_chrome" );
hide_chrome = lua_toboolean( config_lua_values, -1 );
config.hide_chrome = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "fullscreen" );
show_ui_fullscreen = lua_toboolean( config_lua_values, -1 );
config.show_ui_fullscreen = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "netbook" );
netbook = lua_toboolean( config_lua_values, -1 );
config.netbook = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "mono" );
mono = lua_toboolean( config_lua_values, -1 );
config.mono = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "gray" );
gray = lua_toboolean( config_lua_values, -1 );
config.gray = lua_toboolean( config_lua_values, -1 );
/* DEPRECATED */
lua_getglobal( config_lua_values, "small" );
small = lua_toboolean( config_lua_values, -1 );
config.small = lua_toboolean( config_lua_values, -1 );
/* DEPRECATED */
lua_getglobal( config_lua_values, "tiny" );
tiny = lua_toboolean( config_lua_values, -1 );
config.tiny = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "leave_shift_keys" );
leave_shift_keys = lua_toboolean( config_lua_values, -1 );
config.leave_shift_keys = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "inhibit_shutdown" );
inhibit_shutdown = lua_toboolean( config_lua_values, -1 );
config.inhibit_shutdown = lua_toboolean( config_lua_values, -1 );
lua_getglobal( config_lua_values, "x11_visual" );
x11_visual = ( char* )luaL_optstring( config_lua_values, -1, "default" );
config.x11_visual = ( char* )luaL_optstring( config_lua_values, -1, "default" );
lua_getglobal( config_lua_values, "font_small" );
smallFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-bold-r-normal-*-14-*-*-*-*-*-iso8859-1" );
config.smallFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-bold-r-normal-*-14-*-*-*-*-*-iso8859-1" );
lua_getglobal( config_lua_values, "font_medium" );
mediumFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-bold-r-normal-*-15-*-*-*-*-*-iso8859-1" );
config.mediumFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-bold-r-normal-*-15-*-*-*-*-*-iso8859-1" );
lua_getglobal( config_lua_values, "font_large" );
largeFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-medium-r-normal-*-20-*-*-*-*-*-iso8859-1" );
config.largeFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-medium-r-normal-*-20-*-*-*-*-*-iso8859-1" );
lua_getglobal( config_lua_values, "font_devices" );
connFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-iso8859-1" );
config.connFont = ( char* )luaL_optstring( config_lua_values, -1, "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-iso8859-1" );
/****************************************************/
/* 2. treat command-line params which have priority */
@ -605,48 +608,48 @@ int parse_args_and_read_config( int argc, char* argv[] )
if ( clopt_port2FileName != NULL )
port2FileName = strdup( clopt_port2FileName );
if ( clopt_serialLine != NULL )
serialLine = strdup( clopt_serialLine );
config.serialLine = strdup( clopt_serialLine );
if ( clopt_x11_visual != NULL )
x11_visual = strdup( clopt_x11_visual );
config.x11_visual = strdup( clopt_x11_visual );
if ( clopt_smallFont != NULL )
smallFont = strdup( clopt_smallFont );
config.smallFont = strdup( clopt_smallFont );
if ( clopt_mediumFont != NULL )
mediumFont = strdup( clopt_mediumFont );
config.mediumFont = strdup( clopt_mediumFont );
if ( clopt_largeFont != NULL )
largeFont = strdup( clopt_largeFont );
config.largeFont = strdup( clopt_largeFont );
if ( clopt_connFont != NULL )
connFont = strdup( clopt_connFont );
config.connFont = strdup( clopt_connFont );
if ( clopt_verbose != -1 )
verbose = clopt_verbose;
config.verbose = clopt_verbose;
if ( clopt_useTerminal != -1 )
useTerminal = clopt_useTerminal;
config.useTerminal = clopt_useTerminal;
if ( clopt_useSerial != -1 )
useSerial = clopt_useSerial;
config.useSerial = clopt_useSerial;
if ( clopt_throttle != -1 )
throttle = clopt_throttle;
config.throttle = clopt_throttle;
if ( clopt_useDebugger != -1 )
useDebugger = clopt_useDebugger;
config.useDebugger = clopt_useDebugger;
if ( clopt_frontend_type != -1 )
frontend_type = clopt_frontend_type;
config.frontend_type = clopt_frontend_type;
if ( clopt_hide_chrome != -1 )
hide_chrome = clopt_hide_chrome;
config.hide_chrome = clopt_hide_chrome;
if ( clopt_show_ui_fullscreen != -1 )
show_ui_fullscreen = clopt_show_ui_fullscreen;
config.show_ui_fullscreen = clopt_show_ui_fullscreen;
if ( clopt_netbook != -1 )
netbook = clopt_netbook;
config.netbook = clopt_netbook;
if ( clopt_mono != -1 )
mono = clopt_mono;
config.mono = clopt_mono;
if ( clopt_gray != -1 )
gray = clopt_gray;
config.gray = clopt_gray;
if ( clopt_small != -1 )
small = clopt_small;
config.small = clopt_small;
if ( clopt_tiny != -1 )
tiny = clopt_tiny;
config.tiny = clopt_tiny;
if ( clopt_leave_shift_keys != -1 )
leave_shift_keys = clopt_leave_shift_keys;
config.leave_shift_keys = clopt_leave_shift_keys;
if ( clopt_inhibit_shutdown != -1 )
inhibit_shutdown = clopt_inhibit_shutdown;
config.inhibit_shutdown = clopt_inhibit_shutdown;
/* After getting configs and params */
/* normalize config_dir again in case it's been modified */
@ -655,8 +658,8 @@ int parse_args_and_read_config( int argc, char* argv[] )
normalize_filenames();
print_config |= verbose;
if ( print_config ) {
config.print_config |= config.verbose;
if ( config.print_config ) {
fprintf( stdout, "--------------------------------------------------------------------------------\n" );
fprintf( stdout, "-- Configuration file for x48ng\n" );
fprintf( stdout, "-- This is a comment\n" );
@ -670,19 +673,19 @@ int parse_args_and_read_config( int argc, char* argv[] )
fprintf( stdout, "port1 = \"%s\"\n", port1FileName );
fprintf( stdout, "port2 = \"%s\"\n", port2FileName );
fprintf( stdout, "\n" );
fprintf( stdout, "pseudo_terminal = %s\n", useTerminal ? "true" : "false" );
fprintf( stdout, "serial = %s\n", useSerial ? "true" : "false" );
fprintf( stdout, "serial_line = \"%s\"\n", serialLine );
fprintf( stdout, "pseudo_terminal = %s\n", config.useTerminal ? "true" : "false" );
fprintf( stdout, "serial = %s\n", config.useSerial ? "true" : "false" );
fprintf( stdout, "serial_line = \"%s\"\n", config.serialLine );
fprintf( stdout, "\n" );
fprintf( stdout, "verbose = %s\n", verbose ? "true" : "false" );
fprintf( stdout, "debugger = %s\n", useDebugger ? "true" : "false" );
fprintf( stdout, "throttle = %s\n", throttle ? "true" : "false" );
fprintf( stdout, "verbose = %s\n", config.verbose ? "true" : "false" );
fprintf( stdout, "debugger = %s\n", config.useDebugger ? "true" : "false" );
fprintf( stdout, "throttle = %s\n", config.throttle ? "true" : "false" );
fprintf( stdout, "\n" );
fprintf( stdout, "--------------------\n" );
fprintf( stdout, "-- User Interface --\n" );
fprintf( stdout, "--------------------\n" );
fprintf( stdout, "frontend = \"" );
switch ( frontend_type ) {
switch ( config.frontend_type ) {
case FRONTEND_X11:
fprintf( stdout, "x11" );
break;
@ -690,34 +693,34 @@ int parse_args_and_read_config( int argc, char* argv[] )
fprintf( stdout, "sdl" );
break;
case FRONTEND_TEXT:
if ( small )
if ( config.small )
fprintf( stdout, "tui-small" );
else if ( tiny )
else if ( config.tiny )
fprintf( stdout, "tui-tiny" );
else
fprintf( stdout, "tui" );
break;
}
fprintf( stdout, "\" -- possible values: \"x11\", \"sdl\", \"tui\", \"tui-small\", \"tui-tiny\"\n" );
fprintf( stdout, "hide_chrome = %s\n", hide_chrome ? "true" : "false" );
fprintf( stdout, "fullscreen = %s\n", show_ui_fullscreen ? "true" : "false" );
fprintf( stdout, "mono = %s\n", mono ? "true" : "false" );
fprintf( stdout, "gray = %s\n", gray ? "true" : "false" );
fprintf( stdout, "leave_shift_keys = %s\n", leave_shift_keys ? "true" : "false" );
fprintf( stdout, "inhibit_shutdown = %s\n", inhibit_shutdown ? "true" : "false" );
fprintf( stdout, "hide_chrome = %s\n", config.hide_chrome ? "true" : "false" );
fprintf( stdout, "fullscreen = %s\n", config.show_ui_fullscreen ? "true" : "false" );
fprintf( stdout, "mono = %s\n", config.mono ? "true" : "false" );
fprintf( stdout, "gray = %s\n", config.gray ? "true" : "false" );
fprintf( stdout, "leave_shift_keys = %s\n", config.leave_shift_keys ? "true" : "false" );
fprintf( stdout, "inhibit_shutdown = %s\n", config.inhibit_shutdown ? "true" : "false" );
fprintf( stdout, "\n" );
fprintf( stdout, "x11_visual = \"%s\"\n", x11_visual );
fprintf( stdout, "netbook = %s\n", netbook ? "true" : "false" );
fprintf( stdout, "font_small = \"%s\"\n", smallFont );
fprintf( stdout, "font_medium = \"%s\"\n", mediumFont );
fprintf( stdout, "font_large = \"%s\"\n", largeFont );
fprintf( stdout, "font_devices = \"%s\"\n", connFont );
fprintf( stdout, "x11_visual = \"%s\"\n", config.x11_visual );
fprintf( stdout, "netbook = %s\n", config.netbook ? "true" : "false" );
fprintf( stdout, "font_small = \"%s\"\n", config.smallFont );
fprintf( stdout, "font_medium = \"%s\"\n", config.mediumFont );
fprintf( stdout, "font_large = \"%s\"\n", config.largeFont );
fprintf( stdout, "font_devices = \"%s\"\n", config.connFont );
fprintf( stdout, "--------------------------------------------------------------------------------\n" );
if ( !verbose )
if ( !config.verbose )
exit( 0 );
}
if ( verbose ) {
if ( config.verbose ) {
fprintf( stderr, "normalized_config_path = %s\n", normalized_config_path );
fprintf( stderr, "normalized_rom_path = %s\n", normalized_rom_path );
fprintf( stderr, "normalized_ram_path = %s\n", normalized_ram_path );

View file

@ -7,44 +7,48 @@
#define FRONTEND_X11 1
#define FRONTEND_TEXT 2
extern char* progname;
typedef struct {
char* progname;
extern bool verbose;
extern bool useTerminal;
extern bool useSerial;
extern bool useDebugger;
extern bool throttle;
extern bool resetOnStartup;
extern int frontend_type;
bool verbose;
bool print_config;
bool useTerminal;
bool useSerial;
bool useDebugger;
bool throttle;
bool resetOnStartup;
int frontend_type;
extern char* serialLine;
char* serialLine;
extern bool leave_shift_keys;
extern bool inhibit_shutdown;
bool leave_shift_keys;
bool inhibit_shutdown;
extern bool mono;
extern bool gray;
bool mono;
bool gray;
/* tui */
extern bool small;
extern bool tiny;
/* tui */
bool small;
bool tiny;
/* sdl */
extern bool hide_chrome;
extern bool show_ui_fullscreen;
/* sdl */
bool hide_chrome;
bool show_ui_fullscreen;
/* x11 */
extern bool netbook;
extern char* name;
extern char* title;
extern char* x11_visual;
extern bool monoIcon;
extern bool iconic;
extern bool xrm;
extern char* smallFont;
extern char* mediumFont;
extern char* largeFont;
extern char* connFont;
/* x11 */
bool netbook;
char* name;
char* title;
char* x11_visual;
bool monoIcon;
bool iconic;
bool xrm;
char* smallFont;
char* mediumFont;
char* largeFont;
char* connFont;
} config_t;
extern config_t config;
#define MAX_LENGTH_FILENAME 2048
extern char normalized_config_path[ MAX_LENGTH_FILENAME ];

View file

@ -161,7 +161,7 @@ int SmallTextWidth( const char* string, unsigned int length )
if ( small_font[ ( int )string[ i ] ].h != 0 ) {
w += small_font[ ( int )string[ i ] ].w + 1;
} else {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "Unknown small letter 0x00%x\n", ( int )string[ i ] );
w += 5;
}
@ -174,7 +174,7 @@ void start_UI( int argc, char** argv )
{
ui_init_LCD();
switch ( frontend_type ) {
switch ( config.frontend_type ) {
#if ( defined( HAS_X11 ) )
case FRONTEND_X11:
default:

View file

@ -394,7 +394,7 @@ static void SDLInit( void )
KEYBOARD_OFFSET_Y = _KEYBOARD_OFFSET_Y;
KBD_UPLINE = _KBD_UPLINE;
if ( hide_chrome ) {
if ( config.hide_chrome ) {
width = DISPLAY_WIDTH;
height = DISPLAY_HEIGHT;
DISPLAY_OFFSET_X = 0;
@ -405,7 +405,7 @@ static void SDLInit( void )
}
uint32_t sdl_window_flags = SDL_SWSURFACE | SDL_RESIZABLE;
if ( show_ui_fullscreen )
if ( config.show_ui_fullscreen )
sdl_window_flags |= SDL_FULLSCREEN;
sdlwindow = SDL_SetVideoMode( width, height, 32, sdl_window_flags );
@ -702,11 +702,11 @@ static int SDLKeyToKey( SDLKey k )
return HPKEY_ON;
break;
case SDLK_LSHIFT:
if ( !leave_shift_keys )
if ( !config.leave_shift_keys )
return HPKEY_SHL;
break;
case SDLK_RSHIFT:
if ( !leave_shift_keys )
if ( !config.leave_shift_keys )
return HPKEY_SHR;
break;
case SDLK_F2:
@ -1598,7 +1598,7 @@ static void SDLDrawSerialDevices()
{
char text[ 1024 ] = "";
if ( verbose ) {
if ( config.verbose ) {
fprintf( stderr, "wire_name: %s\n", wire_name );
fprintf( stderr, "ir_name: %s\n", ir_name );
}
@ -1696,7 +1696,7 @@ static void SDLCreateHP( void )
{
unsigned int width, height;
if ( hide_chrome ) {
if ( config.hide_chrome ) {
width = KEYBOARD_WIDTH;
height = DISPLAY_HEIGHT;
} else {
@ -1725,7 +1725,7 @@ static void SDLCreateHP( void )
SDLCreateColors();
if ( !hide_chrome ) {
if ( !config.hide_chrome ) {
int cut = buttons[ HPKEY_MTH ].y + KEYBOARD_OFFSET_Y - 19;
SDLDrawBackground( width, cut, width, height );
@ -1896,7 +1896,7 @@ int sdl_get_event( void )
}
// Display button being pressed, if any
if ( !hide_chrome )
if ( !config.hide_chrome )
SDLUIShowKey( keyispressed );
// If we press long, then the button releases makes SDLUIShowKey restore

View file

@ -22,8 +22,8 @@
#define LCD_HEIGHT 64
#define LCD_OFFSET_X 1
#define LCD_OFFSET_Y 1
#define LCD_BOTTOM LCD_OFFSET_Y + ( small ? ( LCD_HEIGHT / 2 ) : tiny ? ( LCD_HEIGHT / 4 ) : LCD_HEIGHT )
#define LCD_RIGHT LCD_OFFSET_X + ( ( small || tiny ) ? ( LCD_WIDTH / 2 ) + 1 : LCD_WIDTH )
#define LCD_BOTTOM LCD_OFFSET_Y + ( config.small ? ( LCD_HEIGHT / 2 ) : config.tiny ? ( LCD_HEIGHT / 4 ) : LCD_HEIGHT )
#define LCD_RIGHT LCD_OFFSET_X + ( ( config.small || config.tiny ) ? ( LCD_WIDTH / 2 ) + 1 : LCD_WIDTH )
#define LCD_COLOR_BG 48
#define LCD_COLOR_FG 49
@ -75,7 +75,7 @@ static inline void ncurses_draw_lcd_tiny( void )
wchar_t line[ 66 ]; /* ( LCD_WIDTH / step_x ) + 1 */
if ( !mono && has_colors() )
if ( !config.mono && has_colors() )
attron( COLOR_PAIR( LCD_COLORS_PAIR ) );
for ( int y = 0; y < LCD_HEIGHT; y += step_y ) {
@ -114,7 +114,7 @@ static inline void ncurses_draw_lcd_tiny( void )
mvaddwstr( LCD_OFFSET_Y + ( y / step_y ), LCD_OFFSET_X, line );
}
if ( !mono && has_colors() )
if ( !config.mono && has_colors() )
attroff( COLOR_PAIR( LCD_COLORS_PAIR ) );
wrefresh( stdscr );
@ -158,7 +158,7 @@ static inline void ncurses_draw_lcd_small( void )
wchar_t line[ 66 ]; /* ( LCD_WIDTH / step_x ) + 1 */
if ( !mono && has_colors() )
if ( !config.mono && has_colors() )
attron( COLOR_PAIR( LCD_COLORS_PAIR ) );
for ( int y = 0; y < LCD_HEIGHT; y += step_y ) {
@ -184,7 +184,7 @@ static inline void ncurses_draw_lcd_small( void )
mvaddwstr( LCD_OFFSET_Y + ( y / step_y ), LCD_OFFSET_X, line );
}
if ( !mono && has_colors() )
if ( !config.mono && has_colors() )
attroff( COLOR_PAIR( LCD_COLORS_PAIR ) );
wrefresh( stdscr );
@ -199,7 +199,7 @@ static inline void ncurses_draw_lcd_fullsize( void )
wchar_t line[ LCD_WIDTH ];
if ( !mono && has_colors() )
if ( !config.mono && has_colors() )
attron( COLOR_PAIR( LCD_COLORS_PAIR ) );
for ( int y = 0; y < LCD_HEIGHT; ++y ) {
@ -222,7 +222,7 @@ static inline void ncurses_draw_lcd_fullsize( void )
mvaddwstr( LCD_OFFSET_Y + y, LCD_OFFSET_X, line );
}
if ( !mono && has_colors() )
if ( !config.mono && has_colors() )
attroff( COLOR_PAIR( LCD_COLORS_PAIR ) );
wrefresh( stdscr );
@ -230,9 +230,9 @@ static inline void ncurses_draw_lcd_fullsize( void )
static inline void ncurses_draw_lcd( void )
{
if ( small )
if ( config.small )
ncurses_draw_lcd_small();
else if ( tiny )
else if ( config.tiny )
ncurses_draw_lcd_tiny();
else
ncurses_draw_lcd_fullsize();
@ -579,10 +579,10 @@ void init_text_ui( int argc, char** argv )
noecho();
nonl(); /* tell curses not to do NL->CR/NL on output */
if ( !mono && has_colors() ) {
if ( !config.mono && has_colors() ) {
start_color();
if ( gray ) {
if ( config.gray ) {
init_color( LCD_COLOR_BG, 205, 205, 205 );
init_color( LCD_COLOR_FG, 20, 20, 20 );
} else {
@ -605,7 +605,7 @@ void init_text_ui( int argc, char** argv )
mvvline( 1, LCD_RIGHT, ACS_VLINE, LCD_BOTTOM - 1 );
mvprintw( 0, 2, "[ | | | | | ]" ); /* annunciators */
mvprintw( 0, LCD_RIGHT - 18, "< %s v%i.%i.%i >", progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL );
mvprintw( 0, LCD_RIGHT - 18, "< %s v%i.%i.%i >", config.progname, VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL );
mvprintw( LCD_BOTTOM, 2, "[ wire: %s ]-[ IR: %s ]-[ contrast: %i ]", wire_name, ir_name, display.contrast );

View file

@ -611,26 +611,26 @@ Visual* get_visual_resource( Display* dpy, unsigned int* depth )
int vclass;
int id;
if ( !x11_visual || !strcmp( x11_visual, "default" ) )
if ( !config.x11_visual || !strcmp( config.x11_visual, "default" ) )
vclass = -1;
else if ( !strcmp( x11_visual, "staticgray" ) )
else if ( !strcmp( config.x11_visual, "staticgray" ) )
vclass = StaticGray;
else if ( !strcmp( x11_visual, "staticcolor" ) )
else if ( !strcmp( config.x11_visual, "staticcolor" ) )
vclass = StaticColor;
else if ( !strcmp( x11_visual, "truecolor" ) )
else if ( !strcmp( config.x11_visual, "truecolor" ) )
vclass = TrueColor;
else if ( !strcmp( x11_visual, "grayscale" ) )
else if ( !strcmp( config.x11_visual, "grayscale" ) )
vclass = GrayScale;
else if ( !strcmp( x11_visual, "pseudocolor" ) )
else if ( !strcmp( config.x11_visual, "pseudocolor" ) )
vclass = PseudoColor;
else if ( !strcmp( x11_visual, "directcolor" ) )
else if ( !strcmp( config.x11_visual, "directcolor" ) )
vclass = DirectColor;
else if ( 1 == sscanf( x11_visual, " %d %c", &id, &c ) )
else if ( 1 == sscanf( config.x11_visual, " %d %c", &id, &c ) )
vclass = -2;
else if ( 1 == sscanf( x11_visual, " 0x%d %c", &id, &c ) )
else if ( 1 == sscanf( config.x11_visual, " 0x%d %c", &id, &c ) )
vclass = -2;
else {
fprintf( stderr, "unrecognized visual \"%s\".\n", x11_visual );
fprintf( stderr, "unrecognized visual \"%s\".\n", config.x11_visual );
vclass = -1;
}
@ -662,7 +662,7 @@ XFontStruct* load_x11_font( Display* dpy, char* fontname )
char errbuf[ 1024 ];
char fixbuf[ 1024 ];
sprintf( errbuf, "can\'t load font \'%s\'", fontname );
sprintf( fixbuf, "Please change resource \'%s\'", name );
sprintf( fixbuf, "Please change resource \'%s\'", config.name );
fatal_exit( errbuf, fixbuf );
}
@ -724,7 +724,7 @@ int AllocColors( void )
if ( XAllocColorCells( dpy, cmap, True, ( unsigned long* )0, 0, &colors[ c ].xcolor.pixel, 1 ) == 0 ) {
dyn = 0;
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XAllocColor failed.\n" );
error = c;
break;
@ -732,7 +732,7 @@ int AllocColors( void )
} else if ( colors[ c ].xcolor.pixel >= ( unsigned long )( visual->map_entries ) ) {
dyn = 0;
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XAllocColor failed.\n" );
error = c;
break;
@ -742,7 +742,7 @@ int AllocColors( void )
}
} else {
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XAllocColor failed.\n" );
error = c;
break;
@ -756,7 +756,7 @@ int AllocColors( void )
*/
if ( error != -1 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "Using own Colormap.\n" );
/*
* free colors so far allocated
@ -831,7 +831,7 @@ int InitDisplay( int argc, char** argv )
*/
dpy = XOpenDisplay( NULL );
if ( dpy == ( Display* )0 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "can\'t open display\n" );
return -1;
@ -849,10 +849,10 @@ int InitDisplay( int argc, char** argv )
if ( !XShmQueryExtension( dpy ) ) {
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "Xserver does not support XShm extension.\n" );
}
if ( verbose && shm_flag )
if ( config.verbose && shm_flag )
fprintf( stderr, "using XShm extension.\n" );
return 0;
@ -1207,9 +1207,9 @@ void CreateKeypad( unsigned int offset_y, unsigned int offset_x, x11_keypad_t* k
unsigned int pw, ph;
XFontStruct *f_small, *f_med, *f_big;
f_small = load_x11_font( dpy, smallFont );
f_med = load_x11_font( dpy, mediumFont );
f_big = load_x11_font( dpy, largeFont );
f_small = load_x11_font( dpy, config.smallFont );
f_med = load_x11_font( dpy, config.mediumFont );
f_big = load_x11_font( dpy, config.largeFont );
/*
* draw the character labels
@ -1910,7 +1910,7 @@ void CreateLCDWindow( void )
lcd.disp_image = XShmCreateImage( dpy, None, 1, XYBitmap, NULL, &lcd.disp_info, 262, 128 );
if ( lcd.disp_image == NULL ) {
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XShm error in CreateImage(DISP), disabling.\n" );
goto shm_error;
}
@ -1923,7 +1923,7 @@ void CreateLCDWindow( void )
XDestroyImage( lcd.disp_image );
lcd.disp_image = NULL;
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XShm error in shmget(DISP), disabling.\n" );
goto shm_error;
}
@ -1936,7 +1936,7 @@ void CreateLCDWindow( void )
XDestroyImage( lcd.disp_image );
lcd.disp_image = NULL;
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XShm error in shmat(DISP), disabling.\n" );
goto shm_error;
}
@ -1952,7 +1952,7 @@ void CreateLCDWindow( void )
XDestroyImage( lcd.disp_image );
lcd.disp_image = NULL;
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XShm error in CreateImage(MENU), disabling.\n" );
goto shm_error;
}
@ -1967,7 +1967,7 @@ void CreateLCDWindow( void )
XDestroyImage( lcd.menu_image );
lcd.menu_image = NULL;
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XShm error in shmget(MENU), disabling.\n" );
goto shm_error;
}
@ -1982,7 +1982,7 @@ void CreateLCDWindow( void )
XDestroyImage( lcd.menu_image );
lcd.menu_image = NULL;
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XShm error in shmat(MENU), disabling.\n" );
goto shm_error;
}
@ -2000,7 +2000,7 @@ void CreateLCDWindow( void )
XDestroyImage( lcd.menu_image );
lcd.menu_image = NULL;
shm_flag = 0;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "XShm error in shmget(MENU), disabling.\n" );
goto shm_error;
} else {
@ -2011,7 +2011,7 @@ void CreateLCDWindow( void )
memset( lcd.disp_image->data, 0, ( size_t )( lcd.disp_image->bytes_per_line * lcd.disp_image->height ) );
memset( lcd.menu_image->data, 0, ( size_t )( lcd.menu_image->bytes_per_line * lcd.menu_image->height ) );
if ( verbose )
if ( config.verbose )
printf( "using XShm extension.\n" );
CompletionType = XShmGetEventBase( dpy ) + ShmCompletion;
@ -2042,7 +2042,7 @@ void DrawSerialDevices( char* wire, char* ir )
int dir, fa, fd;
Pixmap pix;
finfo = load_x11_font( dpy, connFont );
finfo = load_x11_font( dpy, config.connFont );
val.font = finfo->fid;
gc_mask = GCFont;
XChangeGC( dpy, gc, gc_mask, &val );
@ -2108,7 +2108,7 @@ int CreateWindows( int argc, char** argv )
icon_maps = icon_maps_sx;
}
if ( netbook ) {
if ( config.netbook ) {
int i;
for ( i = 0; i < 6; i++ ) {
buttons[ i ].x -= 3;
@ -2151,29 +2151,29 @@ int CreateWindows( int argc, char** argv )
color_mode = COLOR_MODE_GRAY;
else
color_mode = COLOR_MODE_COLOR;
if ( gray )
if ( config.gray )
color_mode = COLOR_MODE_GRAY;
if ( mono )
if ( config.mono )
color_mode = COLOR_MODE_MONO;
if ( depth == 1 )
color_mode = COLOR_MODE_MONO;
icon_color_mode = color_mode;
if ( monoIcon )
if ( config.monoIcon )
icon_color_mode = COLOR_MODE_MONO;
clh.res_name = res_name;
clh.res_class = res_class;
if ( !XStringListToTextProperty( &progname, 1, &iname ) )
if ( !XStringListToTextProperty( &config.progname, 1, &iname ) )
return -1;
if ( ( name = title ) == ( char* )0 ) {
if ( ( name = config.title ) == ( char* )0 ) {
name = ( char* )malloc( 128 );
if ( name == ( char* )0 )
fatal_exit( "malloc failed.\n", "" );
sprintf( name, "%s-%d.%d.%d", progname, saturn.version[ 0 ], saturn.version[ 1 ], saturn.version[ 2 ] );
sprintf( name, "%s-%d.%d.%d", config.progname, saturn.version[ 0 ], saturn.version[ 1 ], saturn.version[ 2 ] );
}
if ( !XStringListToTextProperty( &name, 1, &wname ) )
@ -2189,7 +2189,7 @@ int CreateWindows( int argc, char** argv )
* create the window
*/
width = KEYBOARD_WIDTH + 2 * SIDE_SKIP;
if ( netbook ) {
if ( config.netbook ) {
height = KEYBOARD_HEIGHT;
} else {
height = DISPLAY_OFFSET_Y + DISPLAY_HEIGHT + DISP_KBD_SKIP + KEYBOARD_HEIGHT + BOTTOM_SKIP;
@ -2229,7 +2229,7 @@ int CreateWindows( int argc, char** argv )
/*
* check if we start iconic
*/
if ( iconic )
if ( config.iconic )
wmh.initial_state = IconicState;
else
wmh.initial_state = NormalState;
@ -2346,7 +2346,7 @@ int CreateWindows( int argc, char** argv )
keypad.pixmap = XCreatePixmap( dpy, mainW, width, height, depth );
if ( netbook ) {
if ( config.netbook ) {
int cut = buttons[ HPKEY_MTH ].y - ( small_ascent + small_descent + 6 + 4 );
CreateBackground( width / 2, height, width, height, &keypad );
DrawMore( KEYBOARD_OFFSET_Y, &keypad );
@ -2516,7 +2516,7 @@ void save_command_line( void )
char** wm_argv = ( char** )malloc( ( saved_argc + 5 ) * sizeof( char* ) );
if ( wm_argv == ( char** )0 ) {
if ( verbose )
if ( config.verbose )
fprintf( stderr, "warning: malloc failed in wm_save_yourself.\n" );
XSetCommand( dpy, mainW, saved_argv, saved_argc );
return;
@ -2674,7 +2674,7 @@ int decode_key( XEvent* xev, KeySym sym, char* buf, int buflen )
wake = 1;
break;
case XK_Shift_L:
if ( !leave_shift_keys ) {
if ( !config.leave_shift_keys ) {
key_event( HPKEY_SHL, xev );
wake = 1;
}
@ -2685,7 +2685,7 @@ int decode_key( XEvent* xev, KeySym sym, char* buf, int buflen )
wake = 1;
break;
case XK_Shift_R:
if ( !leave_shift_keys ) {
if ( !config.leave_shift_keys ) {
key_event( HPKEY_SHR, xev );
wake = 1;
}
@ -3503,7 +3503,7 @@ void x11_adjust_contrast( void )
} else {
if ( XAllocColor( dpy, cmap, &colors[ PIXEL ].xcolor ) == 0 ) {
colors[ PIXEL ].xcolor.pixel = old;
if ( verbose )
if ( config.verbose )
fprintf( stderr, "warning: can\'t alloc new pixel color.\n" );
} else {
XFreeColors( dpy, cmap, &old, 1, 0 );