LCOV - code coverage report
Current view: top level - src - m_print.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 28 28 100.0 %
Date: 2017-02-27 17:05:36 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*********************************** LICENSE **********************************\
       2             : *                            Copyright 2017 Morphux                            *
       3             : *                                                                              *
       4             : *        Licensed under the Apache License, Version 2.0 (the "License");       *
       5             : *        you may not use this file except in compliance with the License.      *
       6             : *                  You may obtain a copy of the License at                     *
       7             : *                                                                              *
       8             : *                 http://www.apache.org/licenses/LICENSE-2.0                   *
       9             : *                                                                              *
      10             : *      Unless required by applicable law or agreed to in writing, software     *
      11             : *       distributed under the License is distributed on an "AS IS" BASIS,      *
      12             : *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
      13             : *        See the License for the specific language governing permissions and   *
      14             : *                       limitations under the License.                         *
      15             : \******************************************************************************/
      16             : 
      17             : #include <m_print.h>
      18             : 
      19             : /*!
      20             :  * \brief Print a string in an error fomat, then call exit with 1
      21             :  * \note Support printf format
      22             :  */
      23           1 : void            m_panic(const char *str, ...) {
      24             :         va_list         ap;
      25             : 
      26           1 :         write(2, "\033[0;31m> \033[0m", 13);
      27           1 :         va_start(ap, str);
      28           1 :         vfprintf(stderr, str, ap);
      29           1 :         va_end(ap);
      30           1 :         if (str[strlen(str) - 1] != '\n')
      31           1 :                 fprintf(stderr, "\n");
      32           1 :         exit(1);
      33             : }
      34             : 
      35             : /*!
      36             :  * \brief Print a string with an error format
      37             :  * \note Support printf format
      38             :  */
      39           9 : void            m_error(const char *str, ...) {
      40             :         va_list         ap;
      41             : 
      42           9 :         write(2, "\033[0;31m> \033[0m", 13);
      43           9 :         va_start(ap, str);
      44           9 :         vfprintf(stderr, str, ap);
      45           9 :         va_end(ap);
      46           9 :         if (str[strlen(str) - 1] != '\n')
      47           2 :                 fprintf(stderr, "\n");
      48           9 : }
      49             : 
      50             : /*!
      51             :  * \brief Print a string with a warning format
      52             :  * \note Support printf format
      53             :  */
      54           4 : void            m_warning(const char *str, ...) {
      55             :         va_list         ap;
      56             : 
      57           4 :         write(2, "\033[0;31m> \033[0m", 13);
      58           4 :         va_start(ap, str);
      59           4 :         vfprintf(stderr, str, ap);
      60           4 :         va_end(ap);
      61           4 : }
      62             : 
      63             : /*!
      64             :  * \brief Print a string with an information format
      65             :  * \note Support printf format
      66             :  */
      67         124 : void            m_info(const char *str, ...) {
      68             :         va_list         ap;
      69             : 
      70         124 :         write(1, "\033[0;34m> \033[0m", 13);
      71         124 :         va_start(ap, str);
      72         124 :         vprintf(str, ap);
      73         124 :         va_end(ap);
      74         124 : }

Generated by: LCOV version 1.11