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
26 /*-------------------- Extern Headers Including --------------------*/
28 #include <stdio.h> /* printf vfprintf */
29 #include <stdarg.h> /* va_start va_end */
30 #include <string.h> /* strcmp */
32 /*-------------------- Local Headers Including ---------------------*/
35 /*-------------------- Main Module Header --------------------------*/
39 /*-------------------- Other ----------------------------*/
41 typedef struct DEBUG_CHANNEL
43 char *channel
; /* should only contain unallocated strings */
46 /*-------------------- Global Variables ----------------------------*/
48 /*-------------------- Static Variables ----------------------------*/
50 static u8 debug_level
= 0;
54 /*-------------------- Static Prototypes ---------------------------*/
58 /*-------------------- Static Functions ----------------------------*/
60 /*-------------------- Global Functions ----------------------------*/
63 Neuro_DebugPrint(char *type
, char *control
, char *filename
, char *funcName
, u32 lineNum
)
67 char *msg = calloc(1, 520);
69 va_start(args, control);
70 vasprintf(msg, control, args);
73 fprintf(stderr
, "%s : %s:%s:%d -- %s\n", type
, filename
, funcName
, lineNum
, control
);
74 /* fprintf(stderr, "%s\n", control); */
80 Debug_Channel(const char *channel
, char *type
, char *filename
,
81 char *funcName
, u32 lineNum
, u8 output_detailed
, char *control
, ...)
87 if (Neuro_EBufIsEmpty(debug_l
))
90 total
= Neuro_GiveEBufCount(debug_l
) + 1;
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
);
106 fprintf(stderr
, "\n"); /* we do a line feed */
113 Debug_Val(u8 level
, char *control
, ...)
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
);
131 Neuro_SetDebugLevel(u8 level
)
150 Debug_VerboseChannel(char *channel
)
157 Neuro_AllocEBuf(debug_l
, sizeof(DEBUG_CHANNEL
*), sizeof(DEBUG_CHANNEL
));
159 buf
= Neuro_GiveCurEBuf(debug_l
);
161 buf
->channel
= channel
;
164 /*-------------------- Constructor Destructor ----------------------*/
169 Neuro_CreateEBuf(&debug_l
);
176 Neuro_CleanEBuf(&debug_l
);