Rewrite Fl_abort.cxx under the driver model.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11452 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-03-28 15:22:20 +00:00
parent 244a1a5bc4
commit 28d1a2d684
5 changed files with 86 additions and 73 deletions

View File

@ -25,6 +25,7 @@
#define FL_SYSTEM_DRIVER_H
#include <FL/Fl_Export.H>
#include <stdarg.h>
#ifdef __APPLE__
typedef struct CGContext* Fl_Offscreen;
@ -51,13 +52,14 @@ typedef struct _XRegion *Fl_Region;
#endif // __APPLE__
/**
\brief A base class for platform specific window handling code.
\brief A base class for platform-specific system operations.
*/
class FL_EXPORT Fl_System_Driver {
protected:
Fl_System_Driver();
public:
virtual ~Fl_System_Driver();
// copy the implementation in Fl_XXX_System_Driver.cxx to the corresponding file for the new platform
static Fl_System_Driver *driver();
static const int flNoValue;
static const int flWidthValue;
@ -66,10 +68,23 @@ public:
static const int flYValue;
static const int flXNegative;
static const int flYNegative;
// implement if the system adds unwanted program argument(s)
virtual int single_arg(const char *arg) { return 0; }
// implement if the system adds unwanted program argument pair(s)
virtual int arg_and_value(const char *name, const char *value) { return 0; }
// implement to process the -display argument
virtual void display_arg(const char *arg) { }
// default implementation should be enough
virtual int XParseGeometry(const char*, int*, int*, unsigned int*, unsigned int*);
static void warning(const char* format, ...);
// implement to set the default effect of Fl::warning()
virtual void warning(const char* format, va_list args);
static void error(const char* format, ...);
// implement to set the default effect of Fl::error()
virtual void error(const char* format, va_list args);
static void fatal(const char* format, ...);
// implement to set the default effect of Fl::error()
virtual void fatal(const char* format, va_list args);
};
#endif // FL_SYSTEM_DRIVER_H

View File

@ -19,6 +19,8 @@
#include <FL/Fl_System_Driver.H>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
const int Fl_System_Driver::flNoValue = 0x0000;
const int Fl_System_Driver::flWidthValue = 0x0004;
@ -38,6 +40,46 @@ Fl_System_Driver::~Fl_System_Driver()
{
}
void Fl_System_Driver::warning(const char* format, ...) {
va_list args;
va_start(args, format);
driver()->warning(format, args);
va_end(args);
}
void Fl_System_Driver::warning(const char* format, va_list args) {
vfprintf(stderr, format, args);
fputc('\n', stderr);
fflush(stderr);
}
void Fl_System_Driver::error(const char* format, ...) {
va_list args;
va_start(args, format);
driver()->error(format, args);
va_end(args);
}
void Fl_System_Driver::error(const char *format, va_list args) {
vfprintf(stderr, format, args);
fputc('\n', stderr);
fflush(stderr);
}
void Fl_System_Driver::fatal(const char* format, ...) {
va_list args;
va_start(args, format);
driver()->fatal(format, args);
va_end(args);
}
void Fl_System_Driver::fatal(const char *format, va_list args) {
vfprintf(stderr, format, args);
fputc('\n', stderr);
fflush(stderr);
exit(1);
}
/* the following function was stolen from the X sources as indicated. */
/* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */

View File

@ -16,83 +16,15 @@
// http://www.fltk.org/str.php
//
// This method is in its own source file so that stdlib and stdio
// do not need to be included in Fl.cxx:
// You can also override this by redefining all of these.
#include <FL/Fl.H>
#include <stdio.h>
#include <stdlib.h>
#include <FL/Fl_System_Driver.H>
#include <stdarg.h>
#include "flstring.h"
#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Screen_Driver - native message box
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: use native message box below if one is available"
#else
#endif
#ifdef WIN32
# include <windows.h>
static void warning(const char *, ...) {
// Show nothing for warnings under WIN32...
}
static void error(const char *format, ...) {
va_list args;
char buf[1024];
va_start(args, format);
vsnprintf(buf, 1024, format, args);
va_end(args);
MessageBox(0,buf,"Error",MB_ICONEXCLAMATION|MB_SYSTEMMODAL);
}
static void fatal(const char *format, ...) {
va_list args;
char buf[1024];
va_start(args, format);
vsnprintf(buf, 1024, format, args);
va_end(args);
MessageBox(0,buf,"Error",MB_ICONSTOP|MB_SYSTEMMODAL);
::exit(1);
}
#else
static void warning(const char *format, ...) {
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
fflush(stderr);
}
static void error(const char *format, ...) {
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
fflush(stderr);
}
static void fatal(const char *format, ...) {
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
fflush(stderr);
::exit(1);
}
#endif
void (*Fl::warning)(const char* format, ...) = ::warning;
void (*Fl::error)(const char* format, ...) = ::error;
void (*Fl::fatal)(const char* format, ...) = ::fatal;
void (*Fl::warning)(const char* format, ...) = Fl_System_Driver::warning;
void (*Fl::error)(const char* format, ...) = Fl_System_Driver::error;
void (*Fl::fatal)(const char* format, ...) = Fl_System_Driver::fatal;
//
// End of "$Id$".

View File

@ -26,6 +26,7 @@
#define FL_WINAPI_SYSTEM_DRIVER_H
#include <FL/Fl_System_Driver.H>
#include <stdarg.h>
/*
Move everything here that manages the system interface.
@ -41,6 +42,9 @@
class Fl_WinAPI_System_Driver : public Fl_System_Driver
{
public:
virtual void warning(const char *format, va_list args);
virtual void error(const char *format, va_list args);
virtual void fatal(const char *format, va_list args);
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H

View File

@ -19,6 +19,8 @@
#include "../../config_lib.h"
#include "Fl_WinAPI_System_Driver.H"
#include <stdio.h>
#include <windows.h>
#if !defined(FL_DOXYGEN)
const char* fl_local_alt = "Alt";
@ -32,6 +34,24 @@ Fl_System_Driver *Fl_System_Driver::driver() {
return d;
}
void Fl_WinAPI_System_Driver::warning(const char *format, va_list args) {
// Show nothing for warnings under WIN32...
}
void Fl_WinAPI_System_Driver::error(const char *format, va_list args) {
char buf[1024];
vsnprintf(buf, 1024, format, args);
MessageBox(0,buf,"Error",MB_ICONEXCLAMATION|MB_SYSTEMMODAL);
}
void Fl_WinAPI_System_Driver::fatal(const char *format, va_list args) {
char buf[1024];
vsnprintf(buf, 1024, format, args);
MessageBox(0,buf,"Error",MB_ICONSTOP|MB_SYSTEMMODAL);
::exit(1);
}
//
// End of "$Id$".
//