/* * hprintf.h * ***************************************************************************** * * Highlight printf for C * ~~~~~~~~~~~~~~~~~~~~~~ ***************************************************************************** * * Author : Rajesh _ThE gReAt * Built on : Saturday, January 19, 2002, 12:30:01 AM * Last Modified on : Friday, February 08, 2002, 4:04:54 PM * * History : 19/01/2002 written for the first time * 28/01/2002 __hprintf written * * Known errors : 1) * When the function hprintf returns it sets textcolor * to LIGHTGRAY which may be undesirable . * So double check your text colors after * you have called any fuction in HPRINTF.H * 2) * In Function __hprintf() , a flag char (hb[i] or he[i]) * cannot follow a hb[i] , If so the flag gets printed * and the highlight continues ... * There is no way to print a flag char. * * Bug Reporting : I do not support hprintf() anymore. Moreover since * I generated it , I cannot support it. * If you see any bugs in __hprintf() plz report it to me. * Since it is an interseting function i will try to fix it. * Use either: * 1) mailto : rajeshgoli@yahoo.com * 2) http://www.rajeshgoli.com/feedback * Put "__hprintf() bug report" on subject line. Thank you. * ***************************************************************************** * DISCLAIMER: ***************************************************************************** * * Programmers may incorporate any or all code into their programs, * giving proper credit within the source. Publication of the * source routines is permitted so long as proper credit is given * to Rajesh _ThE gReAt. * * Copyright (C) 2002, 2003 by Rajesh _ThE gReAt. You may use this program, or * code or tables extracted from it, as desired without restriction. * I can not and will not be held responsible for any damage caused from * the use of this software. * * Read license.txt from http://www.rajeshgoli.com/license.txt * or http://www.rajeshgoli.com/license.htm * before using / distributing / or any sort of use of my source * Also read my disclaimer http://www.rajeshgoli.com/disclaimer.htm * * YOU AGREE TO BE BOUND BY MY DISCLAIMER AND LICENSE BY IN ANY WAY * USING THIS FILE . * ***************************************************************************** * This source works with Turbo C 2.0 and Turbo C++ 3.0 and above. ***************************************************************************** * Rajesh _ThE gReAt is a synonym of Rajesh Goli * Source freely distributable *****************************************************************************/ #ifndef __HPRINTF_H #define __HPRINTF_H #endif #if !defined( __STDIO_H ) #include #endif // __STDIO_H #if !defined( __CONIO_H ) #include #endif // __CONIO_H /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * The __hprintf() fuction * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #define __HPRINTF_FUNC 1 #ifdef __HPRINTF_FUNC void __hprintf(char *,int ,char *,char *,...); #ifndef __STRING_H #include #endif #ifndef __STDARG_H #include #endif #define iscprintf(ch) (!((ch) == '\n' || (ch) == '\t')) void __hprintf(char *msg,int normcolor,char *hb,char *he,...) { int i,j,k,color; char temp[2]; va_list ap; /* Starting and terminating flags' number should be equal */ if(strlen(hb) != strlen(he)) return; /* temp[0] is allways msg[i] and temp[1] is allways NULL */ temp[1] = NULL; /* Start the list */ va_start(ap,he); for(i = 0;msg[i] != NULL;i++) { for(j = 0;hb[j] != NULL;j++ ) { /* We've found a flag char */ if(msg[i] == hb[j]) { i++; /* Discard hb[j] */ if(msg[i] == NULL) return; /* Get to j+1 th argument after he i.e., if j = 0 get to 1st arg after he */ va_start(ap,he); for(k = 0;k != j+1;k++) color = va_arg(ap,int); /* Set the obtained color */ textcolor(color); for(;msg[i] != NULL && msg[i] != he[j];i++) { temp[0] = msg[i]; if(msg[i] == NULL) return; if(iscprintf(msg[i])) cprintf(temp); else printf(temp); } i++; /* Discard he[j] */ /* We've i++ed , so check the new msg[i] i,e., begin the second for loop once more since j++ is going to happen b4 another iteration begins , set j = 0-1; */ if(j + 1 == strlen(hb)) j = -1; if(msg[i] == NULL) return; } } if(msg[i] == NULL) return; temp[0] = msg[i]; /* No highlighting here */ textcolor(normcolor); printf(temp); } } #endif /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Most Part of the code below was generated , u can do so using the following code . using hpgen.c u can generate the whole code http://www.rajeshgoli.com/c/hpgen.c hprint() is too long and not provided here you can download hpgen.c and compile & run it to get that function. */