1 /***************************************************************************
2 Dummy function to redirect unwanted printf
3
4
5 begin : Fri Apr 20 2003
6 copyright : (C) 2003 by mean
7 email : fixounet@free.fr
8 ***************************************************************************/
9
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19 #include "ADM_default.h"
20 #include <stdarg.h>
21 #include <math.h>
22
23
24
25
26 #define ADM_COLOR_YELLOW "\e[33m"
27 #define ADM_COLOR_RED "\e[31m"
28 #define ADM_COLOR_GREEN "\e[32m"
29 #define ADM_DEFAULT_COLOR "\e[m"
30
31 extern "C"
32 {
33
ADM_prettyPrint(const char * func,const char * color,const char * p)34 static void ADM_prettyPrint(const char *func,const char *color, const char *p)
35 {
36 // construct time code
37 struct timeval pz;
38 TIMZ tz;
39 gettimeofday(&pz, &tz);
40 long int tvSec=pz.tv_sec;
41 long int tvUSec=pz.tv_usec;
42
43 long int mseconds = tvUSec/1000;
44 long int seconds=(tvSec)%60;
45 long int mn=((tvSec)/60)%60;
46 long int hh=((tvSec)/3600)%24;
47
48 #if _WIN32
49 printf("[%s] %02d:%02d:%02d-%03d %s", func, (int)hh,(int)mn,(int)seconds,(int)mseconds,p);
50 #else
51 if(isatty(STDOUT_FILENO))
52 printf("%s [%s] %02d:%02d:%02d-%03d %s%s",color,func,(int)hh,(int)mn,(int)seconds,(int)mseconds,p,ADM_DEFAULT_COLOR);
53 else
54 printf(" [%s] %02d:%02d:%02d-%03d %s",func,(int)hh,(int)mn,(int)seconds,(int)mseconds,p);
55 #endif
56 }
57
58
ADM_info2(const char * func,const char * prf,...)59 void ADM_info2(const char *func, const char *prf, ...)
60 {
61 static char print_buffer[1024];
62
63 va_list list;
64 va_start(list, prf);
65 vsnprintf(print_buffer,1023,prf,list);
66 va_end(list);
67 print_buffer[1023]=0; // ensure the string is terminated
68 ADM_prettyPrint(func,ADM_COLOR_GREEN,print_buffer);
69
70 }
ADM_warning2(const char * func,const char * prf,...)71 void ADM_warning2( const char *func, const char *prf, ...)
72 {
73 static char print_buffer[1024];
74
75 va_list list;
76 va_start(list, prf);
77 vsnprintf(print_buffer,1023,prf,list);
78 va_end(list);
79 print_buffer[1023]=0; // ensure the string is terminated
80 ADM_prettyPrint(func,ADM_COLOR_YELLOW,print_buffer);
81
82 }
ADM_error2(const char * func,const char * prf,...)83 void ADM_error2( const char *func, const char *prf, ...)
84 {
85 static char print_buffer[1024];
86
87 va_list list;
88 va_start(list, prf);
89 vsnprintf(print_buffer,1023,prf,list);
90 va_end(list);
91 print_buffer[1023]=0; // ensure the string is terminated
92 ADM_prettyPrint(func,ADM_COLOR_RED,print_buffer);
93
94 }
95
96
97 }
98 //EOF
99