remove global variables errbuf and fixbuf

This commit is contained in:
Gwenhael Le Moine 2023-05-10 14:33:53 +02:00
parent c56d5d3c81
commit a425d3477b
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
6 changed files with 32 additions and 53 deletions

View file

@ -15,7 +15,7 @@
#include "resources.h"
#include "romio.h"
#include "timer.h"
#include "x48.h" /* call exit_x48() */
#include "x48.h" /* call exit_x48() */
#define MAX_ARGS 16

View file

@ -1,28 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include "resources.h"
char errbuf[ 1024 ] = {
0,
};
char fixbuf[ 1024 ] = {
0,
};
void fatal_exit( void ) {
if ( quiet )
exit( 1 );
if ( errbuf[ 0 ] == '\0' ) {
void fatal_exit( char* error, char* advice ) {
if ( error[ 0 ] == '\0' ) {
fprintf( stderr, "FATAL ERROR, exit.\n" );
exit( 1 );
}
fprintf( stderr, "FATAL ERROR, exit.\n - %s\n", errbuf );
fprintf( stderr, "FATAL ERROR, exit.\n - %s\n", error );
if ( fixbuf[ 0 ] != '\0' )
fprintf( stderr, " - %s\n", fixbuf );
if ( advice[ 0 ] != '\0' )
fprintf( stderr, " - %s\n", advice );
exit( 1 );
}

View file

@ -1,9 +1,6 @@
#ifndef _ERRORS_H
#define _ERRORS_H
extern char errbuf[ 1024 ];
extern char fixbuf[ 1024 ];
extern void fatal_exit( void );
extern void fatal_exit( char* error, char* advice );
#endif /* !_ERRORS_H */

View file

@ -25,7 +25,7 @@ saturn_t saturn;
void signal_handler( int sig ) {
switch ( sig ) {
case SIGINT: /* Ctrl-C */
case SIGINT: /* Ctrl-C */
enter_debugger |= USER_INTERRUPT;
break;
case SIGALRM:

View file

@ -344,13 +344,16 @@ XFontStruct* get_font_resource( Display* dpy, char* name, char* class ) {
if ( s )
f = XLoadQueryFont( dpy, s );
else {
char errbuf[ 1024 ];
sprintf( errbuf, "can\'t get resource \'%s\'", name );
fatal_exit();
fatal_exit( errbuf, "" );
}
if ( f == ( XFontStruct* )0 ) {
char errbuf[ 1024 ];
char fixbuf[ 1024 ];
sprintf( errbuf, "can\'t load font \'%s\'", s );
sprintf( fixbuf, "Please change resource \'%s\'", name );
fatal_exit();
fatal_exit( errbuf, fixbuf );
}
return f;
}

View file

@ -1278,10 +1278,9 @@ int AllocColors( void ) {
* Create my own Colormap
*/
cmap = XCreateColormap( dpy, mainW, visual, AllocNone );
if ( cmap == ( Colormap )0 ) {
sprintf( errbuf, "can\'t alloc Colormap.\n" );
fatal_exit();
}
if ( cmap == ( Colormap )0 )
fatal_exit( "can\'t alloc Colormap.\n", "" );
xswa.colormap = cmap;
XChangeWindowAttributes( dpy, mainW, CWColormap, &xswa );
if ( iconW )
@ -1313,24 +1312,20 @@ 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 ) {
sprintf( errbuf, "can\'t alloc Color.\n" );
fatal_exit();
}
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 )
fatal_exit( "can\'t alloc Color.\n", "" );
} else if ( colors[ c ].xcolor.pixel >= visual->map_entries ) {
dyn = 0;
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) {
sprintf( errbuf, "can\'t alloc Color.\n" );
fatal_exit();
}
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 )
fatal_exit( "can\'t alloc Color.\n", "" );
} else {
XStoreColor( dpy, cmap, &colors[ c ].xcolor );
}
} else {
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 ) {
sprintf( errbuf, "can\'t alloc Color.\n" );
fatal_exit();
}
if ( XAllocColor( dpy, cmap, &colors[ c ].xcolor ) == 0 )
fatal_exit( "can\'t alloc Color.\n", "" );
}
}
}
@ -1453,10 +1448,8 @@ int InitDisplay( int argc, char** argv ) {
*/
res = get_string_resource_from_db( cmd, "name", "Name" );
if ( res ) {
if ( !( res_name = strdup( res ) ) ) {
sprintf( errbuf, "out of memory in InitDisplay()\n" );
fatal_exit();
}
if ( !( res_name = strdup( res ) ) )
fatal_exit( "out of memory in InitDisplay()\n", "" );
for ( s = res_name; *s; s++ )
*s = isupper( *s ) ? tolower( *s ) : *s;
@ -1467,10 +1460,9 @@ int InitDisplay( int argc, char** argv ) {
argc = saved_argc;
argv = ( char** )malloc( ( argc + 1 ) * sizeof( char* ) );
if ( argv == ( char** )0 ) {
sprintf( errbuf, "out of memory in InitDisplay()\n" );
fatal_exit();
}
if ( argv == ( char** )0 )
fatal_exit( "out of memory in InitDisplay()\n", "" );
argv[ argc ] = ( char* )0;
for ( i = 0; i < argc; i++ )
argv[ i ] = saved_argv[ i ];
@ -3271,10 +3263,9 @@ int CreateWindows( int argc, char** argv ) {
if ( ( name = get_string_resource( "title", "Title" ) ) == ( char* )0 ) {
name = ( char* )malloc( 128 );
if ( name == ( char* )0 ) {
sprintf( errbuf, "malloc failed.\n" );
fatal_exit();
}
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 ] );
}