inst->master_fd = pty_master_fd; inst->exited = FALSE; inst->master_func_id = gdk_input_add(pty_master_fd, GDK_INPUT_READ, pty_input_func, inst);
int main(int argc, char **argv){    extern int pty_master_fd;	       /* declared in pty.c */    extern void pty_pre_init(void);    /* declared in pty.c */    struct gui_data *inst;    int font_charset;    /* defer any child exit handling until we're ready to deal with     * it */    block_signal(SIGCHLD, 1);    pty_pre_init();    gtk_init(&argc, &argv);    /*     * 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 */    if (do_cmdline(argc, argv, 0, &inst->cfg))	exit(1);		       /* pre-defaults pass to get -class */    do_defaults(NULL, &inst->cfg);    if (do_cmdline(argc, argv, 1, &inst->cfg))	exit(1);		       /* post-defaults, do everything */    inst->fonts[0] = gdk_font_load(inst->cfg.font.name);    if (!inst->fonts[0]) {	fprintf(stderr, "pterm: unable to load font \"%s\"\n",		inst->cfg.font.name);	exit(1);    }    font_charset = set_font_info(inst, 0);    if (inst->cfg.boldfont.name[0]) {	inst->fonts[1] = gdk_font_load(inst->cfg.boldfont.name);	if (!inst->fonts[1]) {	    fprintf(stderr, "pterm: unable to load bold font \"%s\"\n",		    inst->cfg.boldfont.name);	    exit(1);	}	set_font_info(inst, 1);    } else	inst->fonts[1] = NULL;    if (inst->cfg.widefont.name[0]) {	inst->fonts[2] = gdk_font_load(inst->cfg.widefont.name);	if (!inst->fonts[2]) {	    fprintf(stderr, "pterm: unable to load wide font \"%s\"\n",		    inst->cfg.widefont.name);	    exit(1);	}	set_font_info(inst, 2);    } else	inst->fonts[2] = NULL;    if (inst->cfg.wideboldfont.name[0]) {	inst->fonts[3] = gdk_font_load(inst->cfg.wideboldfont.name);	if (!inst->fonts[3]) {	    fprintf(stderr, "pterm: unable to load wide/bold font \"%s\"\n",		    inst->cfg.wideboldfont.name);	    exit(1);	}	set_font_info(inst, 3);    } else	inst->fonts[3] = NULL;    inst->font_width = gdk_char_width(inst->fonts[0], ' ');    inst->font_height = inst->fonts[0]->ascent + inst->fonts[0]->descent;    inst->compound_text_atom = gdk_atom_intern("COMPOUND_TEXT", FALSE);    inst->utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE);    inst->direct_to_font = init_ucs(&inst->ucsdata,				    inst->cfg.line_codepage, font_charset);    inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    if (inst->cfg.wintitle[0])	set_title(inst, inst->cfg.wintitle);    else	set_title(inst, "pterm");    /*     * Set up the colour map.     */    palette_reset(inst);    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);    if (inst->cfg.scrollbar) {	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));    if (inst->cfg.scrollbar) {	if (inst->cfg.scrollbar_on_left)	    gtk_box_pack_start(inst->hbox, inst->sbar, FALSE, FALSE, 0);	else	    gtk_box_pack_end(inst->hbox, inst->sbar, FALSE, FALSE, 0);    }    gtk_box_pack_start(inst->hbox, inst->area, TRUE, TRUE, 0);    gtk_container_add(GTK_CONTAINER(inst->window), GTK_WIDGET(inst->hbox));    {	GdkGeometry geom;	geom.min_width = inst->font_width + 2*inst->cfg.window_border;	geom.min_height = inst->font_height + 2*inst->cfg.window_border;	geom.max_width = geom.max_height = -1;	geom.base_width = 2*inst->cfg.window_border;	geom.base_height = 2*inst->cfg.window_border;	geom.width_inc = inst->font_width;	geom.height_inc = inst->font_height;	geom.min_aspect = geom.max_aspect = 0;	gtk_window_set_geometry_hints(GTK_WINDOW(inst->window), inst->area, &geom,				      GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE |				      GDK_HINT_RESIZE_INC);    }    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->area);    if (inst->cfg.scrollbar)	gtk_widget_show(inst->sbar);    gtk_widget_show(GTK_WIDGET(inst->hbox));    gtk_widget_show(inst->window);    set_window_background(inst);    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->term = term_init(&inst->cfg, &inst->ucsdata, inst);    inst->logctx = log_init(inst, &inst->cfg);    term_provide_logctx(inst->term, inst->logctx);    inst->back = &pty_backend;    inst->back->init((void *)inst->term, &inst->backhandle, &inst->cfg,		     NULL, 0, NULL, 0);    inst->back->provide_logctx(inst->backhandle, inst->logctx);    term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);    term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);    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 */    inst->master_fd = pty_master_fd;    inst->exited = FALSE;    inst->master_func_id = gdk_input_add(pty_master_fd, GDK_INPUT_READ,					 pty_input_func, inst);    /* now we're reday to deal with the child exit handler being     * called */    block_signal(SIGCHLD, 0);        gtk_main();    return 0;}