1 /* logprint.h  -  Macros to print debugging output
2  * 20.10.1999, Sampo Kellomaki <sampo@iki.fi>
3  * 21.10.1999, added IMoaFile2 interface
4  *
5  * Logging needs to be enabled at compile time by defining these
6  * macros as nonempty.  Once latent in program, logging needs to be
7  * turned on by opening Log to desired file. If Log is NULL (the
8  * default), the logging is off.
9  */
10 
11 #ifndef _LOGPRINT_H
12 #define _LOGPRINT_H
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /* All logging macros are conditional on Log_fd, which usually means Log,
19  * but by defining Log_fd differently, you can control separately logging
20  * in some source files, e.g. malloc.c, which see. */
21 
22 # ifndef Log_fd
23 # define Log_fd Log
24 # endif
25 
26 # if 1
27 
28 /* Production code, no logging overhead, please. Like as if the program
29  * does not have bugs?!? This option is for those who do not want to
30  * maintain their code. */
31 
32 #  define LOG_PRINT(s)
33 #  define LOG_PRINT2(s,x)
34 #  define LOG_PRINT3(s,x,y)
35 
36 # else
37 
38 /* Logging desired */
39 
40 #  if 1
41 
42 /* Use IMoaFile2 and IMoaStream2 for macromedia compatibility. NB: to avoid
43  * dynamic memory allocation, the maximum size of one write is 4K. Further,
44  * no attempt is made to see if the stuff actually got written. */
45 
46 //#include <moafile2.h>
47 #include "moastr2.h"
48 #include <string.h>
49 
50 extern PIMoaStream2 Log /* = NULL */;
51 extern PIMoaStream2 Log2;
52 extern PIMoaStream2 Log_malloc;
53 
54 #   ifdef __cplusplus
55 #     define _LOG_WRITE  Log_fd->Write(Logbuf, strlen(Logbuf), &written); Log_fd->Flush();
56 #   else
57 #     define _LOG_WRITE  Log_fd->lpVtbl->Write(Log, Logbuf, strlen(Logbuf), &written); \
58                          Log_fd->lpVtbl->Flush(Log);
59 #   endif
60 
61 #   define LOG_PRINT(s) do{ if (Log_fd) { char Logbuf[1024]; MoaStreamCount written; \
62      snprintf(Logbuf, sizeof(Logbuf), "%s %d: %s\n", __FILE__, __LINE__, (s)); \
63      _LOG_WRITE } }while(0)
64 
65 #   define LOG_PRINT2(s,x) do{ if (Log_fd) { char Logbuf[1024]; MoaStreamCount written; \
66      snprintf(Logbuf, sizeof(Logbuf), "%s %d: " s "\n", __FILE__, __LINE__, (x)); \
67      _LOG_WRITE } }while(0)
68 
69 #   define LOG_PRINT3(s,x,y) do{ if (Log_fd) { char Logbuf[1024]; MoaStreamCount written; \
70      snprintf(Logbuf, sizeof(Logbuf), "%s %d: " s "\n", __FILE__, __LINE__, (x), (y)); \
71      _LOG_WRITE } }while(0)
72 
73 #  else
74 
75 /* Use libc FILE* interface */
76 
77 #include <stdio.h>
78 
79 extern FILE* Log /* = NULL */;
80 
81 #   define LOG_PRINT(s) do{ if (Log_fd) { \
82      fprintf(Log_fd, "%s %d: %s\n", __FILE__, __LINE__, (s)); \
83      fflush(Log_fd);} }while(0)
84 
85 #   define LOG_PRINT2(s,x) do{ if (Log_fd) { \
86      fprintf(Log_fd, "%s %d: " s "\n", __FILE__, __LINE__, (x)); \
87      fflush(Log_fd);} }while(0)
88 
89 #   define LOG_PRINT3(s,x,y) do{ if (Log_fd) { \
90      fprintf(Log_fd, "%s %d: " s "\n", __FILE__, __LINE__, (x), (y)); \
91      fflush(Log_fd);} }while(0)
92 
93 #  endif
94 # endif
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif /* logprint.h */
101