File: [Platon] / libco / libco / co_debug.c (download)
Revision 1.2, Sun Mar 9 10:32:17 2003 UTC (21 years ago) by yenar
Changes since 1.1: +4 -2
lines
fix documentation (doxygen) headers (co_conv.h, co_debug.c, co_gettext.h, co_gettext.c, co_module.h, co_type.c)
|
/***{{{*******************************************************************
* This file is part of libco - object library for C *
* Copyright (c) 2002 *
* Peter Rockai (yenar) <yenar@host.sk> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, *
* Boston, MA 02111-1307 USA *
*******************************************************************}}}***/
/* {{{ file description */
/**
* @file co_debug.c
* @brief Helper functions for debugging output.
**/
/* }}} */
/* {{{ includes */
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "co_debug.h"
/* }}} */
#define DEBUG_FD 7
int __co_debug_msg_level = 0;
/* {{{ */ void __co_debug_print (const char *_file, int line, const char *fnc,
const char *fmt, ...)
{
char buf1 [1024];
char buf2 [1024];
char file [64];
char prefix [64];
char *tmp;
int i;
va_list ap;
if ((tmp = strrchr (_file, '/')))
strcpy (file, tmp + 1);
else
strcpy (file, _file);
for (i = 0; i < __co_debug_msg_level && i < 64; i ++)
prefix [i] = ' ';
prefix [i] = 0;
va_start (ap, fmt);
snprintf (buf1, 1024, "%s| %16s (%04d) | %23s | %s\n",
prefix, file, line, fnc, fmt);
vsnprintf (buf2, 1024, buf1, ap);
buf2 [1024] = 0;
i = strlen (buf2);
write (DEBUG_FD, buf2, i);
va_end (ap);
} /* }}} */
/* {{{ */ void __co_debug_print2 (const char *fmt, ...)
{
char buf1 [1024];
char buf2 [1024];
char prefix [64];
int i;
va_list ap;
for (i = 0; i < __co_debug_msg_level && i < 64; i ++)
prefix [i] = ' ';
prefix [i] = 0;
va_start (ap, fmt);
snprintf (buf1, 1024, "%s| %s", prefix, fmt);
vsnprintf (buf2, 1024, buf1, ap);
buf2 [1024] = 0;
i = strlen (buf2);
write (DEBUG_FD, buf2, i);
va_end (ap);
} /* }}} */
Platon Group <platon@platon.org> http://platon.org/
|