1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the program and library */ 4 /* SCIP --- Solving Constraint Integer Programs */ 5 /* */ 6 /* Copyright (c) 2002-2023 Zuse Institute Berlin (ZIB) */ 7 /* */ 8 /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 /* you may not use this file except in compliance with the License. */ 10 /* You may obtain a copy of the License at */ 11 /* */ 12 /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 /* */ 14 /* Unless required by applicable law or agreed to in writing, software */ 15 /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 /* See the License for the specific language governing permissions and */ 18 /* limitations under the License. */ 19 /* */ 20 /* You should have received a copy of the Apache-2.0 license */ 21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */ 22 /* */ 23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 24 25 /**@file message_default.c 26 * @ingroup PUBLICMETHODS 27 * @brief default message handler 28 * @author Stefan Heinz 29 */ 30 31 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ 32 33 #include "scip/pub_message.h" 34 #include "scip/message_default.h" 35 #include "scip/struct_message.h" 36 37 /* 38 * Local methods 39 */ 40 41 /** prints a message to the given file stream and writes the same messate to the log file */ 42 static 43 void logMessage( 44 FILE* file, /**< file stream to print message into */ 45 const char* msg /**< message to print (or NULL to flush) */ 46 ) 47 { 48 if ( msg != NULL ) 49 fputs(msg, file); 50 fflush(file); 51 } 52 53 /* 54 * Callback methods of message handler 55 */ 56 57 /** warning message print method of message handler */ 58 static 59 SCIP_DECL_MESSAGEWARNING(messageWarningDefault) 60 { /*lint --e{715}*/ 61 if ( msg != NULL && msg[0] != '\0' && msg[0] != '\n' ) 62 fputs("WARNING: ", file); 63 64 logMessage(file, msg); 65 } 66 67 /** dialog message print method of message handler */ 68 static 69 SCIP_DECL_MESSAGEDIALOG(messageDialogDefault) 70 { /*lint --e{715}*/ 71 logMessage(file, msg); 72 } 73 74 /** info message print method of message handler */ 75 static 76 SCIP_DECL_MESSAGEINFO(messageInfoDefault) 77 { /*lint --e{715}*/ 78 logMessage(file, msg); 79 } 80 81 /** Create default message handler. To free the message handler use SCIPmessagehdlrRelease(). */ 82 SCIP_RETCODE SCIPcreateMessagehdlrDefault( 83 SCIP_MESSAGEHDLR** messagehdlr, /**< pointer to store message handler */ 84 SCIP_Bool bufferedoutput, /**< should the output be buffered up to the next newline? */ 85 const char* filename, /**< name of log file, or NULL (stdout) */ 86 SCIP_Bool quiet /**< should screen messages be suppressed? */ 87 ) 88 { 89 /* create message handler */ 90 SCIP_CALL( SCIPmessagehdlrCreate(messagehdlr, bufferedoutput, filename, quiet, 91 messageWarningDefault, messageDialogDefault, messageInfoDefault, 92 NULL, NULL) ); 93 94 return SCIP_OKAY; 95 } 96