init_cutbuffers();
int pt_main(int argc, char **argv){    extern Backend *select_backend(Config *cfg);    extern int cfgbox(Config *cfg);    struct gui_data *inst;    /*     * Create an instance structure and initialise to zeroes     */    inst = snew(struct gui_data);    memset(inst, 0, sizeof(*inst));    inst->alt_keycode = -1;            /* this one needs _not_ to be zero */    /* defer any child exit handling until we're ready to deal with     * it */    block_signal(SIGCHLD, 1);    inst->progname = argv[0];    /*     * Copy the original argv before letting gtk_init fiddle with     * it. It will be required later.     */    {	int i, oldargc;	inst->gtkargvstart = snewn(argc-1, char *);	for (i = 1; i < argc; i++)	    inst->gtkargvstart[i-1] = dupstr(argv[i]);	oldargc = argc;	gtk_init(&argc, &argv);	inst->ngtkargs = oldargc - argc;    }    if (argc > 1 && !strncmp(argv[1], "---", 3)) {	read_dupsession_data(inst, &inst->cfg, argv[1]);	/* Splatter this argument so it doesn't clutter a ps listing */	memset(argv[1], 0, strlen(argv[1]));    } else {	if (do_cmdline(argc, argv, 0, inst, &inst->cfg))	    exit(1);		       /* pre-defaults pass to get -class */	do_defaults(NULL, &inst->cfg);	if (do_cmdline(argc, argv, 1, inst, &inst->cfg))	    exit(1);		       /* post-defaults, do everything */	cmdline_run_saved(&inst->cfg);	if (!*inst->cfg.host && !cfgbox(&inst->cfg))	    exit(0);		       /* config box hit Cancel */    }    if (!compound_text_atom)        compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);    if (!utf8_string_atom)        utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);    setup_fonts_ucs(inst);    inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    /*     * Set up the colour map.     */    palette_reset(inst);    inst->width = inst->cfg.width;    inst->height = inst->cfg.height;    inst->area = gtk_drawing_area_new();    gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area),			  inst->font_width * inst->cfg.width + 2*inst->cfg.window_border,			  inst->font_height * inst->cfg.height + 2*inst->cfg.window_border);    inst->sbar_adjust = GTK_ADJUSTMENT(gtk_adjustment_new(0,0,0,0,0,0));    inst->sbar = gtk_vscrollbar_new(inst->sbar_adjust);    inst->hbox = GTK_BOX(gtk_hbox_new(FALSE, 0));    /*     * We always create the scrollbar; it remains invisible if     * unwanted, so we can pop it up quickly if it suddenly becomes     * desirable.     */    if (inst->cfg.scrollbar_on_left)        gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);    gtk_box_pack_start(inst->hbox, inst->area, TRUE, TRUE, 0);    if (!inst->cfg.scrollbar_on_left)        gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);    gtk_container_add(GTK_CONTAINER(inst->window), GTK_WIDGET(inst->hbox));    set_geom_hints(inst);    gtk_widget_show(inst->area);    if (inst->cfg.scrollbar)	gtk_widget_show(inst->sbar);    else	gtk_widget_hide(inst->sbar);    gtk_widget_show(GTK_WIDGET(inst->hbox));    if (inst->gotpos) {        int x = inst->xpos, y = inst->ypos;        GtkRequisition req;        gtk_widget_size_request(GTK_WIDGET(inst->window), &req);        if (inst->gravity & 1) x += gdk_screen_width() - req.width;        if (inst->gravity & 2) y += gdk_screen_height() - req.height;	gtk_window_set_position(GTK_WINDOW(inst->window), GTK_WIN_POS_NONE);	gtk_widget_set_uposition(GTK_WIDGET(inst->window), x, y);    }    gtk_signal_connect(GTK_OBJECT(inst->window), "destroy",		       GTK_SIGNAL_FUNC(destroy), inst);    gtk_signal_connect(GTK_OBJECT(inst->window), "delete_event",		       GTK_SIGNAL_FUNC(delete_window), inst);    gtk_signal_connect(GTK_OBJECT(inst->window), "key_press_event",		       GTK_SIGNAL_FUNC(key_event), inst);    gtk_signal_connect(GTK_OBJECT(inst->window), "key_release_event",		       GTK_SIGNAL_FUNC(key_event), inst);    gtk_signal_connect(GTK_OBJECT(inst->window), "focus_in_event",		       GTK_SIGNAL_FUNC(focus_event), inst);    gtk_signal_connect(GTK_OBJECT(inst->window), "focus_out_event",		       GTK_SIGNAL_FUNC(focus_event), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "configure_event",		       GTK_SIGNAL_FUNC(configure_area), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "expose_event",		       GTK_SIGNAL_FUNC(expose_area), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "button_press_event",		       GTK_SIGNAL_FUNC(button_event), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "button_release_event",		       GTK_SIGNAL_FUNC(button_event), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "motion_notify_event",		       GTK_SIGNAL_FUNC(motion_event), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "selection_received",		       GTK_SIGNAL_FUNC(selection_received), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "selection_get",		       GTK_SIGNAL_FUNC(selection_get), inst);    gtk_signal_connect(GTK_OBJECT(inst->area), "selection_clear_event",		       GTK_SIGNAL_FUNC(selection_clear), inst);    if (inst->cfg.scrollbar)	gtk_signal_connect(GTK_OBJECT(inst->sbar_adjust), "value_changed",			   GTK_SIGNAL_FUNC(scrollbar_moved), inst);    gtk_timeout_add(20, timer_func, inst);    gtk_widget_add_events(GTK_WIDGET(inst->area),			  GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |			  GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |			  GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK);    gtk_widget_show(inst->window);    set_window_background(inst);    /*     * Set up the Ctrl+rightclick context menu.     */    {	GtkWidget *menuitem;	char *s;	extern const int use_event_log, new_session, saved_sessions;	inst->menu = gtk_menu_new();#define MKMENUITEM(title, func) do { \    menuitem = title ? gtk_menu_item_new_with_label(title) : \    gtk_menu_item_new(); \    gtk_container_add(GTK_CONTAINER(inst->menu), menuitem); \    gtk_widget_show(menuitem); \    if (func != NULL) \	gtk_signal_connect(GTK_OBJECT(menuitem), "activate", \			       GTK_SIGNAL_FUNC(func), inst); \} while (0)	if (new_session)	    MKMENUITEM("New Session", new_session_menuitem);        MKMENUITEM("Duplicate Session", dup_session_menuitem);	if (saved_sessions) {	    struct sesslist sesslist;	    int i;	    inst->sessionsmenu = gtk_menu_new();	    get_sesslist(&sesslist, TRUE);	    for (i = 1; i < sesslist.nsessions; i++) {		menuitem = gtk_menu_item_new_with_label(sesslist.sessions[i]);		gtk_container_add(GTK_CONTAINER(inst->sessionsmenu), menuitem);		gtk_widget_show(menuitem);		gtk_object_set_data(GTK_OBJECT(menuitem), "user-data",				    dupstr(sesslist.sessions[i]));		gtk_signal_connect(GTK_OBJECT(menuitem), "activate",				   GTK_SIGNAL_FUNC(saved_session_menuitem),				   inst);		gtk_signal_connect(GTK_OBJECT(menuitem), "destroy",				   GTK_SIGNAL_FUNC(saved_session_freedata),				   inst);	    }	    get_sesslist(&sesslist, FALSE);	    MKMENUITEM("Saved Sessions", NULL);	    gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem),				      inst->sessionsmenu);	}	MKMENUITEM(NULL, NULL);        MKMENUITEM("Change Settings", change_settings_menuitem);	MKMENUITEM(NULL, NULL);	if (use_event_log)	    MKMENUITEM("Event Log", event_log_menuitem);	MKMENUITEM("Special Commands", NULL);	inst->specialsmenu = gtk_menu_new();	gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), inst->specialsmenu);	inst->specialsitem1 = menuitem;	MKMENUITEM(NULL, NULL);	inst->specialsitem2 = menuitem;	MKMENUITEM("Clear Scrollback", clear_scrollback_menuitem);	MKMENUITEM("Reset Terminal", reset_terminal_menuitem);	MKMENUITEM("Copy All", copy_all_menuitem);	MKMENUITEM(NULL, NULL);	s = dupcat("About ", appname, NULL);	MKMENUITEM(s, about_menuitem);	sfree(s);#undef MKMENUITEM    }    inst->textcursor = make_mouse_ptr(inst, GDK_XTERM);    inst->rawcursor = make_mouse_ptr(inst, GDK_LEFT_PTR);    inst->blankcursor = make_mouse_ptr(inst, -1);    make_mouse_ptr(inst, -2);	       /* clean up cursor font */    inst->currcursor = inst->textcursor;    show_mouseptr(inst, 1);    inst->eventlogstuff = eventlogstuff_new();    inst->term = term_init(&inst->cfg, &inst->ucsdata, inst);    inst->logctx = log_init(inst, &inst->cfg);    term_provide_logctx(inst->term, inst->logctx);    uxsel_init();    term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);    inst->back = select_backend(&inst->cfg);    {	char *realhost;	const char *error;	error = inst->back->init((void *)inst, &inst->backhandle,                                 &inst->cfg, inst->cfg.host, inst->cfg.port,                                 &realhost, inst->cfg.tcp_nodelay);	if (error) {	    char *msg = dupprintf("Unable to open connection to %s:\n%s",                                  inst->cfg.host, error);            inst->exited = TRUE;	    fatal_message_box(inst->window, msg);            sfree(msg);	    return 0;	}        if (inst->cfg.wintitle[0]) {            set_title(inst, inst->cfg.wintitle);            set_icon(inst, inst->cfg.wintitle);	} else {            char *title = make_default_wintitle(realhost);            set_title(inst, title);            set_icon(inst, title);            sfree(title);        }    }    inst->back->provide_logctx(inst->backhandle, inst->logctx);    update_specials_menu(inst);    term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);    inst->ldisc =	ldisc_create(&inst->cfg, inst->term, inst->back, inst->backhandle, inst);    ldisc_send(inst->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */    /* now we're reday to deal with the child exit handler being     * called */    block_signal(SIGCHLD, 0);    /*     * Block SIGPIPE: if we attempt Duplicate Session or similar     * and it falls over in some way, we certainly don't want     * SIGPIPE terminating the main pterm/PuTTY. Note that we do     * this _after_ (at least pterm) forks off its child process,     * since the child wants SIGPIPE handled in the usual way.     */    block_signal(SIGPIPE, 1);    inst->exited = FALSE;    gtk_main();    return 0;}