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-03-13 16:41:56 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           2 : void            m_panic(const char *str, ...) {
      24             :         va_list         ap;
      25             : 
      26           2 :         write(2, "\033[0;31m> \033[0m", 13);
      27           2 :         va_start(ap, str);
      28           2 :         vfprintf(stderr, str, ap);
      29           2 :         va_end(ap);
      30           2 :         if (str[strlen(str) - 1] != '\n')
      31           2 :                 fprintf(stderr, "\n");
      32           2 :         exit(1);
      33             : }
      34             : 
      35             : /*!
      36             :  * \brief Print a string with an error format
      37             :  * \note Support printf format
      38             :  */
      39          10 : void            m_error(const char *str, ...) {
      40             :         va_list         ap;
      41             : 
      42          10 :         write(2, "\033[0;31m> \033[0m", 13);
      43          10 :         va_start(ap, str);
      44          10 :         vfprintf(stderr, str, ap);
      45          10 :         va_end(ap);
      46          10 :         if (str[strlen(str) - 1] != '\n')
      47           4 :                 fprintf(stderr, "\n");
      48          10 : }
      49             : 
      50             : /*!
      51             :  * \brief Print a string with a warning format
      52             :  * \note Support printf format
      53             :  */
      54           8 : void            m_warning(const char *str, ...) {
      55             :         va_list         ap;
      56             : 
      57           8 :         write(2, "\033[0;31m> \033[0m", 13);
      58           8 :         va_start(ap, str);
      59           8 :         vfprintf(stderr, str, ap);
      60           8 :         va_end(ap);
      61           8 : }
      62             : 
      63             : /*!
      64             :  * \brief Print a string with an information format
      65             :  * \note Support printf format
      66             :  */
      67         268 : void            m_info(const char *str, ...) {
      68             :         va_list         ap;
      69             : 
      70         268 :         write(1, "\033[0;34m> \033[0m", 13);
      71         268 :         va_start(ap, str);
      72         268 :         vprintf(str, ap);
      73         268 :         va_end(ap);
      74         268 : }

Generated by: LCOV version 1.11