File: dpl.c

package info (click to toggle)
ecere-sdk 0.44.15-1
  • links: PTS
  • area: main
  • in suites: sid, stretch
  • size: 97,712 kB
  • ctags: 54,695
  • sloc: ansic: 593,042; makefile: 12,250; yacc: 4,955; lex: 707; objc: 259; python: 252; xml: 102
file content (61 lines) | stat: -rw-r--r-- 1,702 bytes parent folder | download | duplicates (2)
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
// dpl.c
// Functions:
//    _dplf  - Debug Print Line Format
//    _dpclf - Debug Print Channel Line Format
// Usage:
//    #define _DPL_ON
//    #include <dpl.c>
//    _dplf(int indent, const char * format, ...);
//    _dpclf(const char ** channelNames, int channel, int indent, const char * format, ...);

#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>

#define MAX_F_STRING 1025

// Debug Print Line Format (_dplf)
#ifdef _DPL_ON
#define _dplf(...) __dplf(__FILE__, __LINE__, ##__VA_ARGS__)
#else
#define _dplf(...)
#endif
void __dplf(const char * file, int line, int indent, const char * format, ...)
{
   int c;
   char string[MAX_F_STRING];
   va_list args;
   va_start(args, format);
   vsnprintf(string, sizeof(string), format, args);
   string[sizeof(string)-1] = '\0';
   printf("%s:% 5d: ", file, line);
   for(c = 0; c<indent; c++)
      printf(" ");
   printf("%s\n", string);
   va_end(args);
}

// Debug Print Channel Line Format (_dpclf)
#ifdef _DPL_ON
#define _dpclf(...) __dpclf(__FILE__, __LINE__, ##__VA_ARGS__)
#else
#define _dpclf(...)
#endif
void __dpclf(const char * file, int line, const char ** channels, int channel, int indent, const char * format, ...)
{
   bool chan = channel && channels && channels[channel];
   if(chan || !channels)
   {
      int c;
      char string[MAX_F_STRING];
      va_list args;
      va_start(args, format);
      vsnprintf(string, sizeof(string), format, args);
      string[sizeof(string)-1] = '\0';
      printf("%s:% 5d: %s%s", file, line, chan ? channels[channel] : "", chan && channels[channel][0] ? ": " : "");
      for(c = 0; c<indent; c++)
         printf(" ");
      printf("%s\n", string);
      va_end(args);
   }
}