Changeset 329

Show
Ignore:
Timestamp:
Tue Nov 20 07:25:35 2007
Author:
giovannibajo
Message:

Introduce printf()-style error macros in bootloader for Windows.

From: Anton Gyllenberg <anton@iki.fi>

The output macros -- VS(), FATALERROR() and OTHERERROR(), had no output
formatting options. This lead to unnatural constructs like

VS("Loading dll: ");
VS(dllpath);
VS("\n");

Worse, for a Windows windowed application, the above example would
generate three dialog boxes of which the last one blank.

Therefore, make the functions behave like and have the same signature
as printf(). They should be backwards compatible as the old invocations
had just one argument which for some configurations was used as a format
string to printf.

I could not find a way to use preprocessor macros with a variable
amount of arguments on Microsoft Visual Studio 2003, so I opted to
make real functions for the message boxes on Windows.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/source/common/launch.h

    r288 r329  
    197 197  
    198 198 #ifdef _CONSOLE  
    199   # define FATALERROR(x) printf(x)  
    200   # define OTHERERROR(x) printf(x)  
      199 # define FATALERROR printf  
      200 # define OTHERERROR printf  
    201 201 #else  
    202   # define FATALERROR(x) MessageBox(NULL, x, "Fatal Error!", MB_OK | MB_ICONEXCLAMATION)  
    203   # define OTHERERROR(x) MessageBox(NULL, x, "Error!", MB_OK | MB_ICONWARNING)  
      202 # define FATALERROR mbfatalerror  
      203 # define OTHERERROR mbothererror  
    204 204 #endif  
    205 205  
    206 206 #ifdef LAUNCH_DEBUG  
    207 207 # ifdef _CONSOLE  
    208   #  define VS(arg) printf(arg)  
      208 #  define VS printf  
    208 208 # else  
    209   #  define VS(arg) MessageBox(NULL, arg, "Tracing", MB_OK)  
      209 #  define VS mbvs  
    209 209 # endif  
    210 210 #else  
    211   # define VS(arg)  
      211 # ifdef WIN32  
      212 #  define VS  
      213 # else  
      214 #  define VS(...)  
      215 # endif  
    212 216 #endif  
    213 217  
  • trunk/source/common/launch.c

    r304 r329  
    37 37  #include <dirent.h>  
    38 38 #endif  
    39   #include <stdio.h>  
    40 39 #include <sys/types.h>  
    41 40 #include <sys/stat.h>  
     
    121 120  */  
    122 121  
      122  
      123 #ifndef _CONSOLE  
      124 /* This code will be used only on windows as for other platforms _CONSOLE  
      125  * will be true. The code duplication in the functions below are because  
      126  * standard macros with variable numer of arguments (variadic macros) are  
      127  * supported by Microsoft only starting from Visual C++ 2005.  
      128  */  
      129  
      130 #define MBTXTLEN 200  
      131  
      132 void mbfatalerror(const char *fmt, ...)  
      133 {  
      134         char msg[MBTXTLEN];  
      135         va_list args;  
      136  
      137         va_start(args, fmt);  
      138         _vsnprintf(msg, MBTXTLEN, fmt, args);  
      139         msg[MBTXTLEN-1] = '\0';  
      140         va_end(args);  
      141  
      142         MessageBox(NULL, msg, "Fatal Error!", MB_OK | MB_ICONEXCLAMATION);  
      143 }  
      144  
      145 void mbothererror(const char *fmt, ...)  
      146 {  
      147         char msg[MBTXTLEN];  
      148         va_list args;  
      149  
      150         va_start(args, fmt);  
      151         _vsnprintf(msg, MBTXTLEN, fmt, args);  
      152         msg[MBTXTLEN-1] = '\0';  
      153         va_end(args);  
      154  
      155         MessageBox(NULL, msg, "Error!", MB_OK | MB_ICONWARNING);  
      156 }  
      157  
      158 void mbvs(const char *fmt, ...)  
      159 {  
      160         char msg[MBTXTLEN];  
      161         va_list args;  
      162  
      163         va_start(args, fmt);  
      164         _vsnprintf(msg, MBTXTLEN, fmt, args);  
      165         msg[MBTXTLEN-1] = '\0';  
      166         va_end(args);  
      167  
      168         MessageBox(NULL, msg, "Tracing", MB_OK);  
      169 }  
      170  
      171 #endif /* _CONSOLE */  
      172  
      173  
    123 174 int testTempPath(char *buff)  
    124 175 {