/*
 * xtvr.c
 *
 * Compile with:
 *
 * cc -o xtvr xtvr.c
 *
 * Copyright (C) 1996 John Gotts <jgotts@engin.umich.edu>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int
main(int argc, char **argv)
{
	int i, j;
	int length;
	int color = 0;
	char buffer[3];
	char *name = "tvr";
	char *library_path = "/usr/lib/X11/xtvr";
	char *command_line;

	for (j = 1; j < argc; j++)
		if (strcmp (argv[j], "-c") == 0)
			color = 1;
	srand (time(NULL));
	i = 13.0 * rand() / (RAND_MAX + 1.0);
	sprintf(buffer, "%d", i);
	length = strlen (library_path) + 1 + strlen (name) + 1 + strlen
		(buffer) + 7 + strlen (library_path) + 1 + 6;
	if (color) length += 3;
	command_line = malloc (length + 1);
	if (command_line == NULL) exit(EXIT_FAILURE);
	strcpy (command_line, library_path);
	strcat (command_line, "/");
	strcat (command_line, name);
	strcat (command_line, " ");
	strcat (command_line, buffer);
	strcat (command_line, " 180 < ");
	strcat (command_line, library_path);
	strcat (command_line, "/tvr.");
	if (color)
		strcat (command_line, "color");
	else
		strcat (command_line, "bw");
	execlp ("/bin/sh", "sh", "-c", command_line, NULL);
	return 0;
}
