/* Stubby - Generate stubs for dynamic-link libraries.
 * Copyright 1999 Tom Rothamel
 *
 * Stubby 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, or (at your option)
 * any later version. It 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* This file contains an example program showing the functionality
 * provided by Stubby. If this code is run under X, and the gtk library
 * is present, this code will use gtk to display a graphical Hello,
 * World message. If not, it will display the message on standard output.
 * The Gtk library must be present to compile this code, but it doesn't
 * need to be present to run the program.
 */

#include <stdio.h>
#include <unistd.h>
#include <gtk/gtk.h>

void destroy(void) {
	gtk_exit(0);
}

int gui_main(int argc, char **argv) {
	GtkWidget *window;
	GtkWidget *label;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_container_set_border_width (GTK_CONTAINER (window), 10);

	gtk_signal_connect_object (GTK_OBJECT (window), "destroy",
				   GTK_SIGNAL_FUNC (destroy),
				   GTK_OBJECT (window));
 	
 	label = gtk_label_new ("Hello World");
	gtk_container_add (GTK_CONTAINER (window), label);

 	gtk_widget_show (label);
 	gtk_widget_show (window);

 	gtk_main ();

	return 0;
}

int text_main() {
	printf("Hello, World.\n");
}

int main(int argc, char **argv) {
	if (getenv("DISPLAY") && stubgtk_lib_check()) {
		gui_main(argc, argv);
	} else {
		text_main();
	}
}
	
