Files
veejay/veejay-ng/libvjmsg/vj-common.c
Niels Elburg 6239e2e729 refurbished encoders, added vims events for recording and parameter binding, some cleanup and bugfixes.
git-svn-id: svn://code.dyne.org/veejay/trunk@586 eb8d1916-c9e9-0310-b8de-cf0c9472ead5
2006-08-11 11:27:57 +00:00

208 lines
3.7 KiB
C

/*
* Linux VeeJay
*
* Copyright(C)2002-2004 Niels Elburg <nelburg@looze.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License , or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
*/
/** \defgroup msg Veejay Message System
*/
#include <config.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <strings.h>
#include "vj-common.h"
#define TXT_RED "\033[0;31m"
#define TXT_RED_B "\033[1;31m"
#define TXT_GRE "\033[0;32m"
#define TXT_GRE_B "\033[1;32m"
#define TXT_YEL "\033[0;33m"
#define TXT_YEL_B "\033[1;33m"
#define TXT_BLU "\033[0;34m"
#define TXT_BLU_B "\033[1;34m"
#define TXT_WHI "\033[0;37m"
#define TXT_WHI_B "\033[1;37m"
#define TXT_END "\033[0m"
static int _debug_level = 0;
static int _color_level = 0;
static int _no_msg = 0;
#define MAX_LINES 100
void veejay_set_debug_level(int level)
{
if(level)
{
_debug_level = 1;
}
else
{
_debug_level = 0;
}
}
void veejay_set_colors(int l)
{
if(l) _color_level = 1;
else _color_level = 0;
}
int veejay_is_colored()
{
return _color_level;
}
void veejay_silent()
{
_no_msg = 1;
}
int veejay_is_silent()
{
if(_no_msg) return 1;
return 0;
}
void veejay_msg(int type, const char format[], ...)
{
char prefix[10];
static char buf[256];
va_list args;
int line = 0;
FILE *out = (_no_msg ? stderr: stdout );
if( type != VEEJAY_MSG_ERROR && _no_msg )
return;
if( !_debug_level && type == VEEJAY_MSG_DEBUG )
return ; // bye
// parse arguments
va_start(args, format);
bzero(buf,256);
vsnprintf(buf, sizeof(buf) - 1, format, args);
if(_color_level)
{
switch (type) {
case 2: //info
sprintf(prefix, "%sI: ", TXT_GRE);
break;
case 1: //warning
sprintf(prefix, "%sW: ", TXT_YEL);
break;
case 0: // error
sprintf(prefix, "%sE: ", TXT_RED);
break;
case 3:
line = 1;
break;
case 4: // debug
sprintf(prefix, "%sD: ", TXT_BLU);
break;
}
if(!line)
fprintf(out,"%s %s %s\n", prefix, buf, TXT_END);
else
fprintf(out,"%s%s%s", TXT_GRE, buf, TXT_END );
}
else
{
switch (type) {
case 2: //info
sprintf(prefix, "I: ");
break;
case 1: //warning
sprintf(prefix, "W: ");
break;
case 0: // error
sprintf(prefix, "E: ");
break;
case 3:
line = 1;
break;
case 4: // debug
sprintf(prefix, "D: ");
break;
}
if(!line)
fprintf(out,"%s %s\n", prefix, buf);
else
fprintf(out,"%s", buf );
}
va_end(args);
}
int veejay_get_file_ext( char *file, char *dst, int dlen)
{
int len = strlen(file)-1;
int i = 0;
char tmp[dlen];
bzero(tmp,dlen);
while(len)
{
if(file[len] == '.')
{
if(i==0) return 0;
int j;
int k = 0;
for(j = i-1; j >= 0;j--)
{
dst[k] = tmp[j];
k ++;
}
return 1;
}
tmp[i] = file[len];
i++;
if( i >= dlen)
return 0;
len --;
}
return 0;
}
void veejay_strrep(char *s, char delim, char tok)
{
unsigned int i;
unsigned int len = strlen(s);
if(!s) return;
for(i=0; i < len; i++)
{
if( s[i] == delim ) s[i] = tok;
}
}
void veejay_chomp_str( char *msg, int *nlen )
{
int len = strlen( msg ) - 1;
if(len > 0 )
{
if( msg[len] == '\n' )
{
msg[len] = '\0';
*nlen = len;
}
}
}