Close Back

      1  /*
      2  *	cur.h
      3  *
      4  *****************************************************************************
      5  *
      6  *	Textmode Curscor Hide / Show for C
      7  *     	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      8  *****************************************************************************
      9  *
     10  *     	Author           :  Rajesh _ThE gReAt
     11  *	Built on         :  Sunday, January  20, 2002, 11:59:31 AM
     12  *	Last Modified on :  Friday, February 08, 2002,  4:02:14 PM
     13  *
     14  *	Known errors : --==(none)==--
     15  *
     16  *****************************************************************************
     17  *	DISCLAIMER:
     18  *****************************************************************************
     19  *
     20  *	Programmers may incorporate any or all code into their programs,
     21  *	giving proper credit within the source. Publication of the
     22  *	source routines is permitted so long as proper credit is given
     23  *	to Rajesh _ThE gReAt.
     24  *
     25  *	Copyright (C) 2002, 2003 by Rajesh _ThE gReAt.  You may use this program, or
     26  *	code or tables extracted from it, as desired without restriction.
     27  *	I can not and will not be held responsible for any damage caused from
     28  *	the use of this software.
     29  *
     30  *	Read license.txt from http://www.rajeshgoli.com/license.txt
     31  *	                   or http://www.rajeshgoli.com/license.htm
     32  *	before using / distributing / or any sort of use of my source
     33  *	Also read my disclaimer http://www.rajeshgoli.com/disclaimer.htm
     34  *	
     35  *	YOU AGREE TO BE BOUND BY MY DISCLAIMER AND LICENSE BY IN ANY WAY
     36  *	USING THIS FILE .
     37  *
     38  *****************************************************************************
     39  * This source works with Turbo C 2.0 and Turbo C++ 3.0 and above.
     40  *****************************************************************************
     41  *	Rajesh _ThE gReAt is a synonym of Rajesh Goli
     42  *	Source freely distributable 
     43  *****************************************************************************/
     44  
     45  /* Define this to test the header file , 
     46     You need typer.h for this, find it at 
     47     http://www.rajeshgoli.com/c/typer.h
     48    ( cool ) *//*
     49  #define TEST_CUR_H
     50  */
     51  
     52  #ifndef __CUR_H
     53  #define __CUR_H
     54  #endif
     55  
     56  #ifndef __DOS_H
     57  #include <dos.h>
     58  #endif
     59  
     60  /* prototypes for functions */
     61  void hidecur(void);
     62  void restorecur( void );
     63  
     64  /* This function hides text mode cursor */
     65  void hidecur(void)
     66  {
     67  	union REGS wrkregs;
     68  	wrkregs.h.ah = 0x01;
     69  	wrkregs.h.ch = 0x10;
     70  	wrkregs.h.cl = 0x00;
     71  	int86(0x10,&wrkregs,&wrkregs);
     72  }
     73  
     74  /* This function restores default ( Hopefully default ) text mode cursor */
     75  void restorecur( void )
     76  {
     77  	union REGS wrkregs;
     78  	wrkregs.h.ah = 0x01;
     79  	wrkregs.h.ch = 0x00;
     80  	wrkregs.h.cl = 0x01;
     81  	int86(0x10,&wrkregs,&wrkregs);
     82  }
     83  
     84  #ifdef TEST_CUR_H
     85  
     86  #ifndef __TYPER_H
     87  #include "typer.h"
     88  #endif
     89  
     90  #ifndef __STRING_H
     91  #include <string.h>
     92  #endif
     93  
     94  /* typer or loop_typer "ungetch"s any key it trapped 
     95     during its execution if we do not do this */
     96  #undef UNGETCH_EXIT
     97  #define UNGETCH_EXIT 0
     98  
     99  void main(int argc,char *argv[])
    100  {
    101  	char *string;
    102  	int i,how_long = 3; /* This must be atleast 1 , 
    103                                 i have kept +2 to be on the safer side */
    104  	/* Hide the cursor */
    105  	hidecur();
    106  
    107  	/* If we Have arguments passed */
    108  	if(argc > 1)
    109  	{
    110  		/* Find ourt how long our string ( argv[1] + " " + argv[2] + ... ) is */
    111  		for( i = 1 ; i < argc ; i++ )
    112  			how_long += ( strlen(argv[i]) + 1 ); /* The +1 is for " " (blank) */
    113  
    114  		/* try to Allocate memory , if it fails display standard message */
    115  		if((string = (char *)malloc( sizeof(char) * how_long )) == NULL)
    116  			loop_typer("http://www.rajeshgoli.com",LIGHTGREEN,GREEN,200,20,11,0);
    117  
    118  		/* Memory is successfully allocated , copy the arguments to our string */
    119  		else
    120  		{
    121  			strcpy(string,argv[1]);
    122  			for( i = 2 ; i < argc ; i++ )
    123  			{
    124  				strcat(string," ");
    125  				strcat(string,argv[i]);
    126  			}
    127  
    128  			/* Print (type in Matrix style) the arguments */
    129  			loop_typer(string, LIGHTGREEN, GREEN, 200, 40 - ( strlen(string)/2 ) ,( 25/2 -1 ),0);
    130  		}
    131  	}
    132  	/* we do not have any arguments , type the standard message */
    133  	else
    134  		loop_typer("http://www.rajeshgoli.com",LIGHTGREEN,GREEN,200,20,11,0);
    135  
    136  	/* Restore normal cursor */
    137  	restorecur();
    138  	clrscr();
    139  }
    140  
    141  #endif