//////////////////////////////////////////////////////////// // error.cpp // // Error message functions for EDrive, a multiplatform driving simulator // // Error messages are written to the file "error.log", although you // could make some trivial changes to display them instead. // // Copyright 2004 by Evan Alexander Weaver // // Despite the copyright, this is free software. See edrive.cpp for details. // // Date last modified: 31 May 2004 #include #include #include "error.h" // If you are debugging on windows and want to pop up a message box, uncomment: //#include // Output the string in "msg" to the file "error.log". If the file can't // be written to, nothing bad happens. // void error(const char *msg) { // each time EDrive starts we want to start with a fresh log file static bool firsttime = true; FILE *fp = fopen("error.log", firsttime ? "w" : "a"); firsttime = false; if (fp) { fprintf(fp, "%s\n", msg); fclose(fp); } // Uncomment the following line if you are debugging in Windows and // want to pop up an annoying message box: //MessageBox(NULL, msg, "EDrive Error", MB_OK); } // Output printf-style formatted data. // Lazy Programmer Alert: don't try to output more than 399 characters in // one call. // void errorf(const char *fmt, ...) { char msg[400]; va_list ap; va_start(ap, fmt); vsprintf(msg, fmt, ap); error(msg); va_end(ap); }