ommited to install the header file neuro_engine.h,
[neuro.git] / src / debug.c
blob545aa46ee0bd2df2ca4138a09aa71810e4a48e2d
2 /*
3 * libneuro, a light weight abstraction of high or lower libraries
4 * and toolkit for applications.
5 * Copyright (C) 2005-2006 Nicholas Niro, Robert Lemay
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 /* debug.c
23 * Module : Debug
26 /*-------------------- Extern Headers Including --------------------*/
27 #include <stdlib.h>
28 #include <stdio.h> /* printf vfprintf */
29 #include <stdarg.h> /* va_start va_end */
30 #include <string.h> /* strcmp */
32 /*-------------------- Local Headers Including ---------------------*/
33 #include <ebuf.h>
35 /*-------------------- Main Module Header --------------------------*/
36 #include "debug.h"
39 /*-------------------- Other ----------------------------*/
41 typedef struct DEBUG_CHANNEL
43 char *channel; /* should only contain unallocated strings */
44 }DEBUG_CHANNEL;
46 /*-------------------- Global Variables ----------------------------*/
48 /*-------------------- Static Variables ----------------------------*/
50 static u8 debug_level = 0;
52 static EBUF *debug_l;
54 /*-------------------- Static Prototypes ---------------------------*/
58 /*-------------------- Static Functions ----------------------------*/
60 /*-------------------- Global Functions ----------------------------*/
62 void
63 Neuro_DebugPrint(char *type, char *control, char *filename, char *funcName, u32 lineNum)
66 va_list args;
67 char *msg = calloc(1, 520);
69 va_start(args, control);
70 vasprintf(msg, control, args);
71 va_end(args);
73 fprintf(stderr, "%s : %s:%s:%d -- %s\n", type, filename, funcName, lineNum, control);
74 /* fprintf(stderr, "%s\n", control); */
76 /* free(msg); */
79 void
80 Debug_Channel(const char *channel, char *type, char *filename,
81 char *funcName, u32 lineNum, u8 output_detailed, char *control, ...)
83 va_list args;
84 DEBUG_CHANNEL *buf;
85 u32 total = 0;
87 if (Neuro_EBufIsEmpty(debug_l))
88 return;
90 total = Neuro_GiveEBufCount(debug_l) + 1;
92 while (total-- > 0)
95 buf = Neuro_GiveEBuf(debug_l, total);
97 if (!strcmp(channel, buf->channel) || !strcmp(type, buf->channel))
99 if (output_detailed == 1)
100 fprintf(stderr, "%s : (%s) %s:%s:%d -- ", type, channel, filename, funcName, lineNum);
102 va_start(args, control);
103 vfprintf(stderr, control, args);
104 va_end(args);
106 fprintf(stderr, "\n"); /* we do a line feed */
111 /* */
112 void
113 Debug_Val(u8 level, char *control, ...)
115 va_list args;
116 /* char *msg;*/
118 if (debug_level >= level)
120 /* msg = calloc(1, 520); */
121 va_start(args, control);
122 /* vasprintf(msg, control, args); */
123 vfprintf(stderr, control, args);
124 va_end(args);
126 /* free(msg); */
130 void
131 Neuro_SetDebugLevel(u8 level)
133 debug_level = level;
137 IsLittleEndian()
139 int i = 1;
140 char *p;
142 p = (char*)&i;
143 if (p[0] == 1)
144 return 1;
145 else
146 return 0;
149 void
150 Debug_VerboseChannel(char *channel)
152 DEBUG_CHANNEL *buf;
154 if (!channel)
155 return;
157 Neuro_AllocEBuf(debug_l, sizeof(DEBUG_CHANNEL*), sizeof(DEBUG_CHANNEL));
159 buf = Neuro_GiveCurEBuf(debug_l);
161 buf->channel = channel;
164 /*-------------------- Constructor Destructor ----------------------*/
167 Debug_Init()
169 Neuro_CreateEBuf(&debug_l);
170 return 0;
173 void
174 Debug_Clean()
176 Neuro_CleanEBuf(&debug_l);