コード例 #1
0
ファイル: message.c プロジェクト: hhexiy/scip
/** prints a message into a file depending on the verbosity level, acting like the vfprintf() command */
void SCIPmessageVFPrintVerbInfo(
   SCIP_MESSAGEHDLR*     messagehdlr,        /**< message handler */
   SCIP_VERBLEVEL        verblevel,          /**< current verbosity level */
   SCIP_VERBLEVEL        msgverblevel,       /**< verbosity level of this message */
   FILE*                 file,               /**< file stream to print into, or NULL for stdout */
   const char*           formatstr,          /**< format string like in printf() function */
   va_list               ap                  /**< variable argument list */
   )
{
   assert(msgverblevel > SCIP_VERBLEVEL_NONE);
   assert(msgverblevel <= SCIP_VERBLEVEL_FULL);
   assert(verblevel <= SCIP_VERBLEVEL_FULL);

   if( msgverblevel <= verblevel )
   {
      char msg[SCIP_MAXSTRLEN];
      int n;
      va_list aq;

      va_copy(aq, ap);

      n = vsnprintf(msg, SCIP_MAXSTRLEN, formatstr, ap);
      if( n < 0 )
         msg[SCIP_MAXSTRLEN-1] = '\0';
      else if( n >= SCIP_MAXSTRLEN )
      {
         char* bigmsg;
#ifndef NDEBUG
         int m;
#endif

         if( BMSallocMemorySize(&bigmsg, n+1) == NULL )
         {
            va_end(aq);
            return;
         }

#ifndef NDEBUG
         m = vsnprintf(bigmsg, (size_t) n+1, formatstr, aq);
#else
         vsnprintf(bigmsg, (size_t) n+1, formatstr, aq);
#endif
         assert(m == n);
         va_end(aq);
         messagePrintInfo(messagehdlr, file, bigmsg);
         BMSfreeMemory(&bigmsg);
         return;
      }
      messagePrintInfo(messagehdlr, file, msg);
      va_end(aq);
   }
}
コード例 #2
0
/** prints warning message with the current message handler, or buffers the message if no newline exists */
static
void messagePrintWarning(
   SCIP_MESSAGEHDLR*     messagehdlr,        /**< message handler */
   const char*           msg,                /**< message to print; NULL to flush the output buffer */
   int                   msglength           /**< message length if bigger than SCIP_MAXSTRLEN, or SCIP_MAXSTRLEN */
   )
{
   if( messagehdlr != NULL && messagehdlr->messagewarning != NULL && (!messagehdlr->quiet || messagehdlr->logfile != NULL) )
   {
      char* outmsg;
      int outmsgsize;

      outmsgsize = msglength + 1;

      if( BMSallocMemorySize(&outmsg, outmsgsize) == NULL )
         return;

      if( !bufferMessage(messagehdlr->warningbuffer, &messagehdlr->warningbufferlen, msg, outmsg, &outmsgsize) )
      {
         assert(outmsgsize > msglength + 1);
         if( BMSreallocMemorySize(&outmsg, outmsgsize) != NULL )
         {
#ifndef NDEBUG
            SCIP_Bool ret;

            ret = bufferMessage(messagehdlr->warningbuffer, &messagehdlr->warningbufferlen, msg, outmsg, &outmsgsize);
            assert(ret);
#else
            bufferMessage(messagehdlr->warningbuffer, &messagehdlr->warningbufferlen, msg, outmsg, &outmsgsize);
#endif
         }
         else
         {
            BMSfreeMemory(&outmsg);
            return;
         }
      }

      if( *outmsg != '\0' )
      {
         if( !messagehdlr->quiet )
            messagehdlr->messagewarning(messagehdlr, stderr, outmsg);
         if( messagehdlr->logfile != NULL )
            messagehdlr->messagewarning(messagehdlr, messagehdlr->logfile, outmsg);
      }

      BMSfreeMemory(&outmsg);
   }
}
コード例 #3
0
ファイル: message.c プロジェクト: hhexiy/scip
/** prints a dialog message that requests user interaction into a file, acting like the vfprintf() command */
void SCIPmessageVFPrintDialog(
   SCIP_MESSAGEHDLR*     messagehdlr,        /**< message handler */
   FILE*                 file,               /**< file stream to print into, or NULL for stdout */
   const char*           formatstr,          /**< format string like in printf() function */
   va_list               ap                  /**< variable argument list */
   )
{
   char msg[SCIP_MAXSTRLEN];
   int n;
   va_list aq;

   va_copy(aq, ap);

   n = vsnprintf(msg, SCIP_MAXSTRLEN, formatstr, ap);
   if( n < 0 )
      msg[SCIP_MAXSTRLEN-1] = '\0';
   else if( n >= SCIP_MAXSTRLEN )
   {
      char* bigmsg;
#ifndef NDEBUG
      int m;
#endif

      if( BMSallocMemorySize(&bigmsg, n+1) == NULL )
      {
         va_end(aq);
         return;
      }

#ifndef NDEBUG
      m = vsnprintf(bigmsg, (size_t) n+1, formatstr, aq);
#else
      vsnprintf(bigmsg, (size_t) n+1, formatstr, aq);
#endif
      assert(m == n);
      va_end(aq);
      messagePrintDialog(messagehdlr, file, bigmsg);
      BMSfreeMemory(&bigmsg);
      return;
   }
   messagePrintDialog(messagehdlr, file, msg);
   va_end(aq);
}
コード例 #4
0
ファイル: message.c プロジェクト: hhexiy/scip
/** prints an error message, acting like the vprintf() command using the static message handler */
void SCIPmessageVPrintError(
   const char*           formatstr,          /**< format string like in printf() function */
   va_list               ap                  /**< variable argument list */
   )
{
   char msg[SCIP_MAXSTRLEN];
   int n;
   va_list aq;

   va_copy(aq, ap);

   n = vsnprintf(msg, SCIP_MAXSTRLEN, formatstr, ap);
   if( n < 0 )
      msg[SCIP_MAXSTRLEN-1] = '\0';
   else if( n >= SCIP_MAXSTRLEN )
   {
      char* bigmsg;
#ifndef NDEBUG
      int m;
#endif

      if( BMSallocMemorySize(&bigmsg, n+1) == NULL )
      {
         va_end(aq);
         return;
      }

#ifndef NDEBUG
      m = vsnprintf(bigmsg, (size_t) n+1, formatstr, aq);
#else
      vsnprintf(bigmsg, (size_t) n+1, formatstr, aq);
#endif
      assert(m == n);
      va_end(aq);
      messagePrintError(bigmsg);
      BMSfreeMemory(&bigmsg);
      return;
   }

   messagePrintError(msg);
   va_end(aq);
}
コード例 #5
0
/** prints a error message, acting like the printf() command */
void SCIPmessagePrintError(
   const char*           formatstr,          /**< format string like in printf() function */
   ...                                       /**< format arguments line in printf() function */
   )
{
   char msg[SCIP_MAXSTRLEN];
   int n;
   va_list ap;

   va_start(ap, formatstr);  /*lint !e826*/

   n = vsnprintf(msg, SCIP_MAXSTRLEN, formatstr, ap);
   if( n < 0 )
      msg[SCIP_MAXSTRLEN-1] = '\0';
   else if( n >= SCIP_MAXSTRLEN )
   {
      char* bigmsg;
#ifndef NDEBUG
      int m;
#endif

      if( BMSallocMemorySize(&bigmsg, n+1) == NULL )
      {
         va_end(ap);
         return;
      }

#ifndef NDEBUG
      m = vsnprintf(bigmsg, (size_t) n+1, formatstr, ap);
#else
      vsnprintf(bigmsg, (size_t) n+1, formatstr, ap);
#endif
      assert(m == n);
      va_end(ap);
      messagePrintError(bigmsg, n);
      BMSfreeMemory(&bigmsg);
      return;
   }

   messagePrintError(msg, SCIP_MAXSTRLEN);
   va_end(ap);
}
コード例 #6
0
ファイル: buffer.c プロジェクト: hhexiy/scip
/** allocates the next unused buffer */
SCIP_RETCODE SCIPbufferAllocMem(
   SCIP_BUFFER*          buffer,             /**< memory buffer storage */
   SCIP_SET*             set,                /**< global SCIP settings */
   void**                ptr,                /**< pointer to store the allocated memory buffer */
   int                   size                /**< minimal required size of the buffer */
   )
{
#ifndef SCIP_NOBUFFERMEM
   int bufnum;

   assert(buffer != NULL);
   assert(buffer->firstfree <= buffer->ndata);
   assert(ptr != NULL);
   assert(size >= 0);
   
   /* allocate minimal 1 byte */
   if( size == 0 )
      size = 1;

   /* check, if we need additional buffers */
   if( buffer->firstfree == buffer->ndata )
   {
      int newsize;
      int i;

      /* create additional buffers */
      newsize = SCIPsetCalcMemGrowSize(set, buffer->firstfree+1);
      SCIP_ALLOC( BMSreallocMemoryArray(&buffer->data, newsize) );
      SCIP_ALLOC( BMSreallocMemoryArray(&buffer->size, newsize) );
      SCIP_ALLOC( BMSreallocMemoryArray(&buffer->used, newsize) );
      for( i = buffer->ndata; i < newsize; ++i )
      {
         buffer->data[i] = NULL;
         buffer->size[i] = 0;
         buffer->used[i] = FALSE;
      }
      buffer->ndata = newsize;
   }
   assert(buffer->firstfree < buffer->ndata);

   /* check, if the current buffer is large enough */
   bufnum = buffer->firstfree;
   assert(!buffer->used[bufnum]);
   if( buffer->size[bufnum] < size )
   {
      int newsize;

      /* enlarge buffer */
      newsize = SCIPsetCalcMemGrowSize(set, size);
      SCIP_ALLOC( BMSreallocMemorySize(&buffer->data[bufnum], newsize) );
      buffer->size[bufnum] = newsize;
   }
   assert(buffer->size[bufnum] >= size);

   *ptr = buffer->data[bufnum];
   buffer->used[bufnum] = TRUE;
   buffer->firstfree++;

   SCIPdebugMessage("allocated buffer %d/%d at %p of size %d (required size: %d) for pointer %p\n", 
      bufnum, buffer->ndata, buffer->data[bufnum], buffer->size[bufnum], size, (void*)ptr);

#else
   SCIP_ALLOC( BMSallocMemorySize(ptr, size) );
#endif

   return SCIP_OKAY;
}
コード例 #7
0
/** prints info message with the current message handler, or buffers the message if no newline exists */
static
void messagePrintInfo(
   SCIP_MESSAGEHDLR*     messagehdlr,        /**< message handler */
   FILE*                 file,               /**< file stream to print into, or NULL for stdout */
   const char*           msg,                /**< message to print; NULL to flush the output buffer */
   int                   msglength           /**< message length if bigger than SCIP_MAXSTRLEN, or SCIP_MAXSTRLEN */
   )
{
   if( messagehdlr != NULL && messagehdlr->messageinfo != NULL )
   {
      if( (file == NULL || file == stdout) && !messagehdlr->quiet && (msg == NULL || strlen(msg) < SCIP_MAXSTRLEN) )
      {
         char* outmsg;
         int outmsgsize;

         outmsgsize = msglength + 1;

         if( BMSallocMemorySize(&outmsg, outmsgsize) == NULL )
            return;

         if( !bufferMessage(messagehdlr->infobuffer, &messagehdlr->infobufferlen, msg, outmsg, &outmsgsize) )
         {
            assert(outmsgsize > msglength + 1);
            if( BMSreallocMemorySize(&outmsg, outmsgsize) != NULL )
            {
#ifndef NDEBUG
               SCIP_Bool ret;

               ret = bufferMessage(messagehdlr->infobuffer, &messagehdlr->infobufferlen, msg, outmsg, &outmsgsize);
               assert(ret);
#else
               bufferMessage(messagehdlr->infobuffer, &messagehdlr->infobufferlen, msg, outmsg, &outmsgsize);
#endif
            }
            else
            {
               BMSfreeMemory(&outmsg);
               return;
            }
         }

         if( *outmsg != '\0' )
         {
            messagehdlr->messageinfo(messagehdlr, stdout, outmsg);

            if( messagehdlr->logfile != NULL )
               messagehdlr->messageinfo(messagehdlr, messagehdlr->logfile, outmsg);
         }

         BMSfreeMemory(&outmsg);
      }
      else if( msg != NULL )
      {
         /* file output cannot be buffered because the output file may change or the message is to long */
         if( *msg != '\0' )
         {
            if( !messagehdlr->quiet || (file != NULL && file != stdout) )
               messagehdlr->messageinfo(messagehdlr, file == NULL ? stdout : file, msg);
            if( messagehdlr->logfile != NULL && (file == NULL || file == stdout) )
               messagehdlr->messageinfo(messagehdlr, messagehdlr->logfile, msg);
         }
      }
   }
}