
/**************************************************************************
 *                                                                        *
 * Copyright (c) 1996 Michael Richmond and Richard Treffers               *
 *                                                                        *
 *                    This software may be copied and distributed for     *
 *                    educational, research and not for profit services   *
 *                    provided that this copyright and statement are      *
 *                    included in all such copies.                        *
 *                                                                        *
 **************************************************************************/


/*	
	tries to get a cursor position from any currently-open window.

		CURSOR	[help]

	continue getting position/value information 
	from the cursor until the user signals that he wants to stop
	(by pressing the Right Button, as opposed to Left Button - but that
	code is in image.c, and we just look here for a value of CURSOR_STOP
	as opposed to CURSOR_CONTINUE in one of the property data values.)

	if no windows are open, the program should wait for a short time,
	and then exit with an error message if no window appears. 
	otherwise, it waits
	for the user to move to some desired position in an image window
	and presses a button.  the pixel row, col, value 
	are then printed to standard output.
	if Right Button was pressed, the program stops.

	interrupts are trapped so that the property can be restored to its
	NORMAL state before the process dies.  That way image windows don't
	wait forever to be acknowledged after sending the cursor information. 

	It would be nice to get the image filename, too.

	10/28/92 - put newline in stderr
			 - add number switch to number the output for stars -rrt
	12/13/92 - modified Button roles - now Button1 continues, while
	           Button3 quits (and doesn't print value). MWR
	7/23/93  - add quiet flag -rrt
	4/22/94  - read/set_property moved to image
*/

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "pcvista.h"
#include "pcvistax.h"
#include "pcvimage.h"


#ifdef PROTO
int main(int, char **);
#else
int main();
#endif


char *progname="cursor";


#define MAX_TRIES 10		/* number of seconds to wait before giving up */
                    		/*   if no image windows present at first */

#define USAGE "cursor [number] [quiet] [help]"

int 
main(argc, argv)
int argc;
char *argv[];
{
	int i;
	int number_flag=0;	/* whether to print index infront of row/col info */
	int quiet_flag=0;	/* don't print message */

	if (argc == 1) {
		;
	}

	for (i = 1; i < argc; i++) {	
		if (keyword("help", argv[i])) {
			printf("%s\n", USAGE);
			exit(0);
		}
		if (keyword("number", argv[i])) {
			number_flag=1;
			continue;
		}
		if (keyword("quiet", argv[i])) {
			quiet_flag=1;
			continue;
		}
		fprintf(stderr,"unknown option '%s' \n",argv[i]);
		exit(1);
	}

	image_init(TV_GREYSCALE);

	if (image_curpos(number_flag,quiet_flag) == 0) {
		exit(0);
	}
	else
		exit(1);
}


