/* Authors: Jon Alder/Ed Schaefer
 * set cursor at row and column on screen
 * usage:  <cursor> row col
 * where row and col are integer screen coordinates
 * with upper left corner being 0,0.
 * TERM must be set and defined in the TERMINFO database
 * or program aborts.
 * to compile:  cc cursor.c -lcurses -o cursor 
 */
#include        <stdio.h>
#include        <curses.h>
#include        <term.h>

main(argc, argv)
int argc;
char *argv[];
{
int row, col;

if(argc != 3)
   {
   fprintf(stderr, "Usage: <cursor> row column\n");
   exit(1);
   }

if((row = atoi(argv[1])), row == NULL)
   row = 0; /*default to zero if illegal conversion*/

if((col = atoi(argv[2])), col == NULL)
   col = 0; /*default to zero if illegal conversion*/

t_init();            
if(cursor_address == NULL)
   {
   fprintf(stderr, "Can NOT set cursor motion string\n");
   exit(1);
   }
   
putp(tparm(cursor_address, row, col));
exit(0);                                
}

/*
 * t_init()
 *
 * Initialize the terminfo system with the current
 * terminal type.   
 */
t_init()
{
int rv; 
extern char     *getenv();
char            *term;

setupterm((char *)0, fileno(stdout), &rv);

if (rv != 1)
   {
   if (term = getenv("TERM"), term == NULL)
      {
      fprintf(stderr, "Cannot set up terminal %s\n", term);
      exit(1);
      }
   }
}
