File: debugutil.c

package info (click to toggle)
paraview 4.0.1-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 526,572 kB
  • sloc: cpp: 2,284,430; ansic: 816,374; python: 239,936; xml: 70,162; tcl: 48,295; fortran: 39,116; yacc: 5,466; java: 3,518; perl: 3,107; lex: 1,620; sh: 1,555; makefile: 932; asm: 471; pascal: 228
file content (146 lines) | stat: -rw-r--r-- 2,705 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
** $RCSfile: debugutil.c,v $
** $Name:  $
**
** ASCI Visualization Project 
**
** Lawrence Livermore National Laboratory
** Information Management and Graphics Group
** P.O. Box 808, Mail Stop L-561
** Livermore, CA 94551-0808
**
** For information about this project see:
**     http://www.llnl.gov/sccd/lc/img/
**
**      or contact: asciviz@llnl.gov
**
** For copyright and disclaimer information see:
**      $(ASCIVIS_ROOT)/copyright_notice_1.txt
**
**     or man llnl_copyright
**
** $Id: debugutil.c,v 1.8 2008/09/28 01:02:23 rcook Exp $
**
*/
/*
**
**  Abstract:
**
**  Author:
**
*/

#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <math.h>
#include <stdarg.h>
#include "debugutil.h"
#include <time.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif

static  int    iVerbose = 0;
static    int    iCheck = 0;

static FILE *gDebugFile = NULL; 
#define INITDEBUGFILE if (!gDebugFile) gDebugFile = stderr

char *datestring(void) {
  static char timebuf[32]; 
  time_t now;

  now = time(NULL);
  strftime(timebuf, 31, "%d/%m/%y %H:%M:%S", (struct tm *)localtime(&now));
  return timebuf;
}

void dbfprintf(FILE *stream, int level, const char *fmt, ...){
  if(iVerbose >= level){
    vafprintf(stream, fmt);
    /*    va_list ap;
      va_start(ap, fmt);
      vfprintf(stream,fmt,ap);
      va_end(ap);
    */
  }    
  return;

}

void dbprintf(int level, const char *fmt, ...){
  if(iVerbose >= level){
    INITDEBUGFILE; 
    vafprintf(gDebugFile, fmt);
    /*    va_list ap;
      va_start(ap, fmt);
      vfprintf(gDebugFile,fmt,ap);
      va_end(ap);
    */
  }    
  return;
}

static int check_verbose(void)
{
    if (!iCheck) {
        if (getenv("DEBUG_VERBOSE")) {
            iVerbose = atoi(getenv("DEBUG_VERBOSE"));
        }
        iCheck = 1;
    }
    return(iVerbose);
}

int dbg_isverbose(void)
{
    return(check_verbose());
}


void dbg_setverbose(int verbose)
{
    iVerbose = verbose;
    iCheck = 1;
}

void dbg_stderr(char *fmt, ...) 
{
  /*va_list ap;*/

    if (check_verbose()) {
      vafprintf(stderr, fmt);
      /*        va_start(ap, fmt);
            vfprintf(stderr,fmt,ap);
            va_end(ap);
      */
    }
}

void dbg_maskstderr(int mask, char *fmt, ...) 
{
  /*    va_list ap;*/

    if (check_verbose() & mask) {
      vafprintf(stderr, fmt);
      /*    va_start(ap, fmt);
        vfprintf(stderr,fmt,ap);
        va_end(ap);*/
    }
}

/* return 0 on failure, 1 on success */
int dbg_setfile(const char *dbgfile) {
  FILE *tmpf = NULL; 
  INITDEBUGFILE; 
  if (!dbgfile) return 0; 
  tmpf = fopen(dbgfile, "w"); 
  if (!tmpf) return 0; 
  gDebugFile = tmpf; 
  return 1;
}