/* * Linux VeeJay * * Copyright(C)2002-2004 Niels Elburg * * 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 */ #include #include #include #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 = 1; static int _no_msg = 0; 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]; char buf[1024]; va_list args; int line = 0; if(_no_msg) return; if(type == 4 && _debug_level==0 ) return; // bye va_start(args, format); 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) printf("%s %s %s\n", prefix, buf, TXT_END); else printf("%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) printf("%s %s\n", prefix, buf); else printf("%s", buf ); } va_end(args); } 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; } }