00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 # include "incls/_precompiled.incl"
00025 # include "incls/_lprintf.cpp.incl"
00026 #include <string.h>
00027 
00028 static FILE* logFile = NULL;
00029 static char fname[80];
00030 
00031 
00032 
00033 extern "C" bool PrintVMMessages;
00034 extern "C" bool LogVMMessages;
00035 extern "C" bool AlwaysFlushVMMessages;
00036 extern "C" {
00037   void breakpoint();
00038   void error_breakpoint();
00039 }
00040 
00041 void lprintf_exit() {
00042   if (logFile) {
00043     fclose(logFile);
00044     logFile = NULL;
00045     unlink(fname);
00046   }
00047 }
00048 
00049 static void check_log_file() {
00050   if (LogVMMessages && !logFile) {
00051     os::move_file(SYSTEM_NAME ".log", SYSTEM_NAME ".log.old");
00052     logFile = fopen(SYSTEM_NAME ".log", "w");
00053   }
00054 }
00055 
00056 
00057 extern "C" void lprintf(char* m, ...) {
00058   char buf[1024];
00059   va_list ap;
00060   va_start(ap, m);
00061   vsprintf(buf, m, ap);
00062   va_end(ap);
00063 
00064   check_log_file();
00065   if (LogVMMessages) {
00066     fputs(buf, logFile);
00067     if (AlwaysFlushVMMessages) fflush(logFile);
00068   }
00069   if (PrintVMMessages) {
00070     fputs(buf, stdout);
00071     if (AlwaysFlushVMMessages) fflush(stdout);
00072   }
00073 }
00074 
00075 extern "C" void lputc(char c) {
00076   check_log_file();
00077   if (LogVMMessages) {
00078     fputc(c, logFile);
00079     if (AlwaysFlushVMMessages) fflush(logFile);
00080   }
00081   if (PrintVMMessages) {
00082     fputc(c, stdout);
00083     if (AlwaysFlushVMMessages) fflush(stdout);
00084   }
00085 }
00086 
00087 extern "C" void lputs(char* str) {
00088   check_log_file();
00089   if (LogVMMessages) {
00090     fputs(str, logFile);
00091     if (AlwaysFlushVMMessages) fflush(logFile);
00092   }
00093   if (PrintVMMessages) {
00094     fputs(str, stdout);
00095     if (AlwaysFlushVMMessages) fflush(stdout);
00096   }
00097 }
00098 
00099 extern "C" void error(char* format, ...) {
00100   std->print_cr("VM Error:");
00101   va_list ap;
00102   va_start(ap, format);
00103   std->vprint_cr(format, ap);
00104   va_end(ap);
00105   DEBUG_EXCEPTION
00106 }
00107 
00108 extern "C" void warning(char* format, ...) {
00109   std->print_cr("VM Warning:");
00110   va_list ap;
00111   va_start(ap, format);
00112   std->vprint_cr(format, ap);
00113   va_end(ap);
00114   if (BreakAtWarning) DEBUG_EXCEPTION;
00115 }
00116 
00117 extern "C" void compiler_warning(char* format, ...) {
00118   if (PrintCompilerWarnings) {
00119     std->print_cr("Compiler Warning:");
00120     va_list ap;
00121     va_start(ap, format);
00122     std->vprint_cr(format, ap);
00123     va_end(ap);
00124     if (BreakAtWarning) DEBUG_EXCEPTION;
00125   }
00126 }
00127 
00128 void flush_logFile() { if (logFile) fflush(logFile); }
00129 
00130 extern "C" void my_sprintf(char*& buf, const char* format, ...){
00131   
00132   
00133   va_list ap;
00134   va_start(ap, format);
00135   vsprintf(buf, format, ap);
00136   va_end(ap);
00137   buf += strlen(buf);
00138 }
00139 
00140 extern "C" void my_sprintf_len(char*& buf, const int len, const char* format, ...){
00141   char* oldbuf = buf;
00142   va_list ap;
00143   va_start(ap, format);
00144   vsprintf(buf, format, ap);
00145   va_end(ap);
00146   buf += strlen(buf);
00147   for ( ; buf < oldbuf + len; *buf++ = ' ') ;
00148   *buf = '\0';
00149 }
00150