openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

cint_error.c (2379B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        cint_error.c
      8  * Purpose:     CINT error handling functions
      9  */
     10 
     11 #include "cint_config.h"
     12 #include "cint_porting.h"
     13 #include "cint_error.h"
     14 
     15 const char* 
     16 cint_error_name(cint_error_t err)
     17 {
     18     switch(err) {                       
     19 #define CINT_ERROR_LIST_ENTRY(_entry) case CINT_E_##_entry : return #_entry ; 
     20 #include "cint_error_entry.h"
     21 
     22         default: return "<UNKNOWN>";
     23     }
     24 }       
     25 
     26 
     27 void 
     28 cint_internal_error(const char* f, int l, const char* fmt, ...)
     29 {
     30     va_list args; 
     31     va_start(args, fmt); 
     32     
     33     CINT_PRINTF("*** internal error (%s:%d): ", f, l); 
     34     CINT_VPRINTF(fmt, args); 
     35     CINT_PRINTF("\n"); 
     36     va_end(args); 
     37     cint_errno = CINT_E_INTERNAL; 
     38 }       
     39 
     40 static void 
     41 __cint_vmsg(const char* f, int l, const char* type, const char* fmt, va_list args)
     42      COMPILER_ATTRIBUTE((format (printf, 4, 0)));
     43 
     44 static void 
     45 __cint_vmsg(const char* f, int l, const char* type, const char* fmt, va_list args)
     46 {
     47     if(f) {
     48         CINT_PRINTF("** %s:%d: %s: ", f, l, type); 
     49     }
     50     else if(l != 0) {
     51         CINT_PRINTF("** %d: %s: ", l, type); 
     52     }
     53     else {
     54         CINT_PRINTF("** %s: ", type); 
     55     }
     56     CINT_VPRINTF(fmt, args); 
     57     CINT_PRINTF("\n"); 
     58 }
     59 
     60 void
     61 cint_error(const char* f, int l, cint_error_t e, const char* fmt, ...)
     62 {
     63     va_list args; 
     64     va_start(args, fmt); 
     65     __cint_vmsg(f, l, "error", fmt, args); 
     66     va_end(args); 
     67     cint_errno = e; 
     68 }
     69 
     70 int
     71 cint_ast_error(const cint_ast_t* ast, cint_error_t e, const char* fmt, ...)
     72 {
     73     va_list args; 
     74     va_start(args, fmt); 
     75     __cint_vmsg(ast ? ast->file : NULL, 
     76                 ast ? ast->line : 0, 
     77                 "error", fmt, args); 
     78     va_end(args);
     79     cint_errno = e;
     80 
     81     return e; 
     82 }       
     83     
     84 int 
     85 cint_ast_warn(const cint_ast_t* ast, const char* fmt, ...)
     86 {
     87     va_list args;
     88     va_start(args, fmt); 
     89     __cint_vmsg(ast ? ast->file : NULL, 
     90                 ast ? ast->line : 0,
     91                 "warning", fmt, args); 
     92     va_end(args); 
     93     return 0; 
     94 }
     95    
     96 void 
     97 cint_warn(const char* f, int l, const char* fmt, ...)
     98 {
     99     va_list args; 
    100     va_start(args, fmt); 
    101     __cint_vmsg(f, l, "warning", fmt, args); 
    102     va_end(args); 
    103 }