Close Back

      1  /*
      2  *	hprintf.h
      3  *
      4  *****************************************************************************
      5  *
      6  *	Highlight printf for C
      7  *     	~~~~~~~~~~~~~~~~~~~~~~
      8  *****************************************************************************
      9  *
     10  *     	Author           :  Rajesh _ThE gReAt
     11  *	Built on         :  Saturday, January  19, 2002, 12:30:01 AM
     12  *	Last Modified on :  Friday, February 08, 2002, 4:04:54 PM
     13  *
     14  *	History : 19/01/2002 written for the first time
     15  *		  28/01/2002 __hprintf written
     16  *
     17  *	Known errors : 1)
     18  *                      When the function hprintf returns it sets textcolor
     19  *		       to LIGHTGRAY which may be undesirable .
     20  *		       So double check your text colors after
     21  *		       you have called any fuction in HPRINTF.H
     22  *		       2)
     23  *		       In Function __hprintf() , a flag char (hb[i] or he[i])
     24  *		       cannot follow a hb[i] , If so the flag gets printed
     25  *		       and the highlight continues ...
     26  *		       There is no way to print a flag char.
     27  *		       
     28  *       Bug Reporting : I do not support hprintf() anymore. Moreover since
     29  *		       I generated it , I cannot support it.
     30  *		       If you see any bugs in __hprintf() plz report it to me.
     31  *		       Since it is an interseting function i will try to fix it.
     32  *		       Use either:
     33  *		        1) mailto  : rajeshgoli@yahoo.com
     34  *		        2) http://www.rajeshgoli.com/feedback
     35  *		       Put "__hprintf() bug report" on subject line. Thank you.
     36  *
     37  *****************************************************************************
     38  *	DISCLAIMER:
     39  *****************************************************************************
     40  *
     41  *	Programmers may incorporate any or all code into their programs,
     42  *	giving proper credit within the source. Publication of the
     43  *	source routines is permitted so long as proper credit is given
     44  *	to Rajesh _ThE gReAt.
     45  *
     46  *	Copyright (C) 2002, 2003 by Rajesh _ThE gReAt.  You may use this program, or
     47  *	code or tables extracted from it, as desired without restriction.
     48  *	I can not and will not be held responsible for any damage caused from
     49  *	the use of this software.
     50  *
     51  *	Read license.txt from http://www.rajeshgoli.com/license.txt
     52  *	                   or http://www.rajeshgoli.com/license.htm
     53  *	before using / distributing / or any sort of use of my source
     54  *	Also read my disclaimer http://www.rajeshgoli.com/disclaimer.htm
     55  *	
     56  *	YOU AGREE TO BE BOUND BY MY DISCLAIMER AND LICENSE BY IN ANY WAY
     57  *	USING THIS FILE .
     58  *
     59  *****************************************************************************
     60  * This source works with Turbo C 2.0 and Turbo C++ 3.0 and above.
     61  *****************************************************************************
     62  *	Rajesh _ThE gReAt is a synonym of Rajesh Goli
     63  *	Source freely distributable 
     64  *****************************************************************************/
     65  
     66  #ifndef __HPRINTF_H
     67  #define __HPRINTF_H
     68  #endif
     69  
     70  #if !defined( __STDIO_H )
     71  #include <stdio.h>
     72  #endif	// __STDIO_H
     73  
     74  #if !defined( __CONIO_H )
     75  #include <conio.h>
     76  #endif	// __CONIO_H
     77  
     78  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     79   *		The __hprintf() fuction                              *   
     80   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
     81  
     82  #define __HPRINTF_FUNC 1
     83  
     84  #ifdef __HPRINTF_FUNC
     85  
     86  void __hprintf(char *,int ,char *,char *,...);
     87  
     88  #ifndef __STRING_H
     89  #include<string.h>
     90  #endif
     91  
     92  #ifndef __STDARG_H
     93  #include<stdarg.h>
     94  #endif
     95  
     96  #define iscprintf(ch) (!((ch) == '\n' || (ch) == '\t'))
     97  
     98  void __hprintf(char *msg,int normcolor,char *hb,char *he,...)
     99  {
    100  	int i,j,k,color;
    101  	char temp[2];
    102  	va_list ap;
    103  
    104  	/* Starting and terminating flags' number should be equal */
    105  	if(strlen(hb) != strlen(he))
    106  		return;
    107  	/* temp[0] is allways msg[i] and temp[1] is allways NULL */
    108  	temp[1] = NULL;
    109  
    110  	/* Start the list */
    111  	va_start(ap,he);
    112  	for(i = 0;msg[i] != NULL;i++)
    113  	{
    114  		for(j = 0;hb[j] != NULL;j++ )
    115  		{
    116  			/* We've found a flag char */
    117  			if(msg[i] == hb[j])
    118  			{
    119  				i++; /* Discard hb[j] */
    120  				if(msg[i] == NULL)
    121  					return;
    122  
    123  				/* Get to j+1 th argument after he
    124  				  i.e., if j = 0 get to 1st arg after he
    125  				*/
    126  				va_start(ap,he);
    127  				for(k = 0;k != j+1;k++)
    128  					color = va_arg(ap,int);
    129  				/*  Set the obtained color */
    130  				textcolor(color);
    131  				for(;msg[i] != NULL && msg[i] != he[j];i++)
    132  				{
    133  					temp[0] = msg[i];
    134  					if(msg[i] == NULL)
    135  						return;
    136  					if(iscprintf(msg[i]))
    137  						cprintf(temp);
    138  					else
    139  						printf(temp);
    140  				}
    141  				i++; /* Discard he[j] */
    142  				/* We've i++ed , so check the new msg[i]
    143  				   i,e., begin the second for loop once more
    144  				   since j++ is going to happen b4 another 
    145  				   iteration begins , set j = 0-1;
    146  				*/
    147  				if(j + 1 == strlen(hb))
    148  					j = -1;
    149  				if(msg[i] == NULL)
    150  					return;
    151  			}
    152  		}
    153  		if(msg[i] == NULL)
    154  			return;
    155  		temp[0] = msg[i];
    156  		/* No highlighting here */
    157  		textcolor(normcolor);
    158  		printf(temp);
    159  	}
    160  }
    161  
    162  #endif
    163  
    164   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    165  
    166  
    167  
    168  /* Most Part of the code below was generated , 
    169     u can do so using the following code .
    170  
    171     using hpgen.c u can generate the whole code
    172     http://www.rajeshgoli.com/c/hpgen.c
    173     
    174     hprint() is too long and not provided here
    175     you can download hpgen.c and compile & run it
    176     to get that function.
    177  */