Use SConscript configure support to probe for format(printf) attribute

This commit is contained in:
Kp 2013-06-27 02:35:22 +00:00
parent 77d69d0384
commit ff90315978
17 changed files with 51 additions and 22 deletions

View file

@ -140,6 +140,17 @@ help:assume compiler supports __attribute__((format_arg))
self._check_macro(context,macro_name=macro_name,macro_value=macro_value,test="""
char*a(char*)__attribute_format_arg(1);
""", msg='for function __attribute__((format_arg))')
@_custom_test
def check_attribute_format_printf(self,context):
"""
help:assume compiler supports __attribute__((format(printf)))
"""
macro_name = '__attribute_format_printf(A,B)'
macro_value = '__attribute__((format(printf,A,B)))'
self._check_macro(context,macro_name=macro_name,macro_value=macro_value,test="""
int a(char*,...)__attribute_format_printf(1,2);
int b(char*)__attribute_format_printf(1,0);
""", msg='for function __attribute__((format(printf)))')
class LazyObjectConstructor:
def __lazy_objects(self,name,source):

View file

@ -4,6 +4,7 @@
#define _CONSOLE_H_
#include "pstypes.h"
#include "dxxsconf.h"
/* Priority levels */
#define CON_CRITICAL -3
@ -30,7 +31,7 @@ typedef struct console_buffer
} __pack__ console_buffer;
void con_init(void);
void con_printf(int level, const char *fmt, ...);
void con_printf(int level, const char *fmt, ...) __attribute_format_printf(2, 3);
void con_showup(void);
#endif /* _CONSOLE_H_ */

View file

@ -21,22 +21,21 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#define _ERROR_H
#include <stdio.h>
#include "dxxsconf.h"
#include <assert.h>
#ifdef __GNUC__
#define __noreturn __attribute__ ((noreturn))
#define __attribute_gcc_format(X) __attribute__ ((format X))
#else
#define __noreturn
#define __attribute_gcc_format(X)
#endif
void warn_printf(const char *s);
int error_init(void (*func)(const char *)); //init error system, returns 0=ok
void Warning(const char *fmt,...); //print out warning message to user
void Warning(const char *fmt,...) __attribute_format_printf(1, 2); //print out warning message to user
void set_warn_func(void (*f)(const char *s));//specifies the function to call with warning messages
void clear_warn_func();//say this function no longer valid
void Error(const char *fmt,...) __noreturn __attribute_gcc_format((printf, 1, 2)); //exit with error code=1, print message
void Error(const char *fmt,...) __noreturn __attribute_format_printf(1, 2); //exit with error code=1, print message
#define Assert assert
#ifndef NDEBUG //macros for debugging

View file

@ -20,6 +20,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#ifndef _EDITOR_H
#define _EDITOR_H
#include "dxxsconf.h"
#include "vecmat.h"
#include "segment.h"
#include "inferno.h"
@ -481,7 +482,7 @@ extern void print_status_icon( char icon[1], int position );
extern void clear_status_icon( char icon[1], int position );
// Editor status message.
extern void editor_status_fmt(const char *format, ... );
extern void editor_status_fmt(const char *format, ... ) __attribute_format_printf(1, 2);
// Variables in editor.c that the k*.c files need

View file

@ -22,6 +22,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "pstypes.h"
#include "fix.h"
#include "dxxsconf.h"
#ifdef DXX_BUILD_DESCENT_I
extern int HiresGFXAvailable;
@ -328,8 +329,8 @@ void gr_set_curfont( grs_font * );
void gr_set_fontcolor( int fg_color, int bg_color );
int gr_string(int x, int y, const char *s );
int gr_ustring(int x, int y, const char *s );
int gr_printf( int x, int y, const char * format, ... );
int gr_uprintf( int x, int y, const char * format, ... );
int gr_printf( int x, int y, const char * format, ... ) __attribute_format_printf(3, 4);
int gr_uprintf( int x, int y, const char * format, ... ) __attribute_format_printf(3, 4);
void gr_get_string_size(const char *s, int *string_width, int *string_height, int *average_width );

View file

@ -19,6 +19,7 @@
#include <physfs/physfs.h>
#endif
#include "dxxsconf.h"
#include "pstypes.h"
#include "strutil.h"
#include "u_mem.h"
@ -188,6 +189,7 @@ static inline char * PHYSFSX_fgets(char *buf, size_t n, PHYSFS_file *const fp)
return buf;
}
static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...) __attribute_format_printf(2, 3);
static inline int PHYSFSX_printf(PHYSFS_file *file, const char *format, ...)
{
char buffer[1024];

View file

@ -20,6 +20,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#ifndef _UI_H
#define _UI_H
#include "dxxsconf.h"
#include "event.h"
struct window;
@ -261,7 +262,7 @@ extern int ui_scrollbar_do( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar, str
extern void ui_draw_scrollbar( UI_DIALOG *dlg, UI_GADGET_SCROLLBAR * scrollbar );
extern void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, const char * format, ... );
extern void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, const char * format, ... ) __attribute_format_printf(4, 5);
extern void ui_draw_radio( UI_DIALOG *dlg, UI_GADGET_RADIO * radio );
extern UI_GADGET_RADIO * ui_add_gadget_radio( UI_DIALOG * dlg, short x, short y, short w, short h, short group, const char * text );

View file

@ -20,6 +20,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#ifndef _AI_H
#define _AI_H
#include "dxxsconf.h"
#include "object.h"
#if defined(DXX_BUILD_DESCENT_II)
#include "fvi.h"
@ -314,7 +315,7 @@ extern int Buddy_objnum, Buddy_allowed_to_talk;
extern void start_robot_death_sequence(object *objp);
extern int do_any_robot_dying_frame(object *objp);
extern void buddy_message(const char * format, ... );
extern void buddy_message(const char * format, ... ) __attribute_format_printf(1, 2);
#define SPECIAL_REACTOR_ROBOT 65
extern void special_reactor_stuff(void);

View file

@ -2,6 +2,7 @@
#define _HUD_MSG_H
#include <stdarg.h>
#include "dxxsconf.h"
#define HUD_MESSAGE_LENGTH 150
#define HUD_MAX_NUM_DISP 4
@ -16,8 +17,8 @@
extern int HUD_toolong;
extern void HUD_clear_messages();
extern void HUD_render_message_frame();
int HUD_init_message(int class_flag, const char * format, ... );
int HUD_init_message_va(int class_flag, const char * format, va_list args);
int HUD_init_message(int class_flag, const char * format, ... ) __attribute_format_printf(2, 3);
int HUD_init_message_va(int class_flag, const char * format, va_list args) __attribute_format_printf(2, 0);
int HUD_init_message_literal(int class_flag, const char *str);
#endif

View file

@ -21,6 +21,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#ifndef _POWERUP_H
#define _POWERUP_H
#include "dxxsconf.h"
#include "vclip.h"
enum powerup_type_t
@ -133,7 +134,7 @@ extern void diminish_towards_max(void);
extern void do_megawow_powerup(int quantity);
extern void powerup_basic(int redadd, int greenadd, int blueadd, int score, const char *format, ...) __attribute_gcc_format((printf, 5, 6));
extern void powerup_basic(int redadd, int greenadd, int blueadd, int score, const char *format, ...) __attribute_format_printf(5, 6);
/*
* reads n powerup_type_info structs from a PHYSFS_file

View file

@ -72,7 +72,8 @@ char *object_ids(int objnum)
return NULL;
}
void err_printf(PHYSFS_file *my_file, char * format, ... )
static void err_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3);
static void err_printf(PHYSFS_file *my_file, char * format, ... )
{
va_list args;
char message[256];
@ -86,7 +87,8 @@ void err_printf(PHYSFS_file *my_file, char * format, ... )
Errors_in_mine++;
}
void warning_printf(PHYSFS_file *my_file, char * format, ... )
static void warning_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3);
static void warning_printf(PHYSFS_file *my_file, char * format, ... )
{
va_list args;
char message[256];

View file

@ -787,7 +787,8 @@ int draw_rock(newmenu *menu, d_event *event, grs_bitmap *background)
return 0;
}
void do_screen_message(char *fmt, ...)
static void do_screen_message(const char *fmt, ...) __attribute_format_printf(1, 2);
static void do_screen_message(const char *fmt, ...)
{
va_list arglist;
grs_bitmap background;

View file

@ -87,7 +87,8 @@ char *object_ids(int objnum)
return NULL;
}
void err_printf(PHYSFS_file *my_file, char * format, ... )
static void err_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3);
static void err_printf(PHYSFS_file *my_file, char * format, ... )
{
va_list args;
char message[256];
@ -101,7 +102,8 @@ void err_printf(PHYSFS_file *my_file, char * format, ... )
Errors_in_mine++;
}
void warning_printf(PHYSFS_file *my_file, char * format, ... )
static void warning_printf(PHYSFS_file *my_file, char * format, ... ) __attribute_format_printf(2, 3);
static void warning_printf(PHYSFS_file *my_file, char * format, ... )
{
va_list args;
char message[256];

View file

@ -426,7 +426,8 @@ void buddy_message(const char * format, ... )
}
// -----------------------------------------------------------------------------
void thief_message(const char * format, ... )
static void thief_message(const char * format, ... ) __attribute_format_printf(1, 2);
static void thief_message(const char * format, ... )
{
char gb_str[16], new_format[128];

View file

@ -945,7 +945,8 @@ int draw_stars_bg(newmenu *menu, d_event *event, grs_bitmap *background)
return 0;
}
void do_screen_message(char *fmt, ...)
static void do_screen_message(const char *fmt, ...) __attribute_format_printf(1, 2);
static void do_screen_message(const char *fmt, ...)
{
va_list arglist;
grs_bitmap background;

View file

@ -134,7 +134,9 @@ void print_clock( int seconds, char message[10] ) {
static char the_time[14]; // changed from 10, I don't think that was long enough
void clock_message( int seconds, char *format, ... ) {
static void clock_message( int seconds, const char *format, ... ) __attribute_format_printf(2, 3);
static void clock_message( int seconds, const char *format, ... )
{
va_list ap;
va_start(ap, format);

View file

@ -265,7 +265,8 @@ void scores_maybe_add_player(int abort_flag)
window_close(Game_wind); // prevent the next game from doing funny things
}
void scores_rprintf(int x, int y, char * format, ... )
static void scores_rprintf(int x, int y, const char * format, ... ) __attribute_format_printf(3, 4);
static void scores_rprintf(int x, int y, const char * format, ... )
{
va_list args;
char buffer[128];