Example #1
0
File: v4pi.c Project: miellaby/v4p
Boolean v4pDisplayError(char *formatString, ...) {
  va_list args ; Char text[0x100] ;
  va_start(args, formatString) ;
  StrVPrintF(text, formatString, args) ;
  va_end(args);
  WinDrawChars(text, StrLen(text), 0, 0) ;
}
void localOutput(const char *format, va_list args) {
   static int initializedTrace XPT_DATA_SECTION = 0;
   char buffer[256];

   Int16 len = StrVPrintF(buffer, format, args);

   if (len >= sizeof buffer) {
      /* Bad news:  We overflowed the buffer.  Die now. */
      ErrDisplayFileLineMsg(__FILE__, (UInt16) __LINE__,
         "Overflowed msg buffer in utilities.c, localOutput()");
   }

   if (!initializedTrace) {
      HostTraceInit();
      initializedTrace = 1;
   }

   /* Call either HostTraceOutputT() or HostTraceOutputTL(), depending on     */
   /* whether or not the given string ends in a newline.  We don't support    */
   /* strings that have embedded newlines anywhere but at the end.            */
   len = StrLen(buffer);
   if (len) {
      if (buffer[len-1]=='\n') {
         buffer[len-1]='\0';
         HostTraceOutputTL(appErrorClass, buffer);
      } else {
         HostTraceOutputT(appErrorClass, buffer);
      }
   }
}
Example #3
0
unsigned long filePrintF(FILE *stream, const char *format, ...)
{
    va_list args;
    Char    *text; // [0x100];
    Int16   ret             = -1;
    UInt32  bytesWritten    = 0;
    Err     err             = errNone;
    
#ifdef USE_FILE_API
    if (!stream || !stream->fileHand)
        return 0;
#else
    if (!stream || !stream->fileRef)
        return 0;
#endif
    
    text = memMgrChunkNew(DEFAULT_BUF_SIZE);
    if (!text) {
        return -1;
    }
    
    va_start(args, format);
    
    ret = StrVPrintF(text, format, args);
    
    va_end(args);
    
    if (ret <= 0)
        return ret;
    
    do {
#ifdef USE_FILE_API
        bytesWritten = FileWrite(stream->fileHand, text + bytesWritten,
                                 1, ret - bytesWritten, &err);
#else
        err = VFSFileWrite(stream->fileRef, ret - bytesWritten,
                           text + bytesWritten, &bytesWritten);
#endif
    } while ((bytesWritten < ret) && (err == errNone));
    
    /*
        This gets really ugly. Basically we return -1 if StrVPrintF does so,
        or return bytes written.
    */
    if (ret < 0) {
        ret = -1;
    } else if ((err != errNone) || (bytesWritten != ret)) {
        ret = bytesWritten;
    }
    
    memMgrChunkFree(text);
    
    //MyPutS(text);
    return (Int32)ret; 
}