⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 overview.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifndef lint#ifdef sccsstatic	char sccsid[] = "@(#)overview.c 1.1 92/07/30 Copyr 1989 Sun Micro";#endif#endif/* * Copyright (c) 1989 by Sun Microsystems, Inc. *//* * Overview.c - Run the second argument to overall in an environment that *		overlays a running SunWindows environment (e.g., suntools). *		Programs read ASCII from stdin. * *		Can run SunWindows based programs (read input from a windowfd) *		with overall if use -w flag.  The -w must come before the *		command. */#include <suntool/sunview.h>#include <sys/wait.h>#include <sys/ioctl.h>#include <sys/stat.h>#include <sundev/kbd.h>#include <stdio.h>#include <fcntl.h>#include <errno.h>struct cbuf {    char               *cb_rbp;	   /* read pointer */    char               *cb_wbp;	   /* write pointer */    char               *cb_ebp;	   /* end of buffer */    char                cb_buf[8192];};typedef	struct	ptytty {    struct cbuf         inbuf;			/* input buffer */    struct cbuf         outbuf;			/* output buffer */    /* pty and subprocess */    int                 pty;			/* pty file descriptor */    int                 tty;			/* tty file descriptor */    int                 ttyslot;		/* ttyslot in utmp for tty */    int                 (*output) ();		/* handle ouput from program */    int			waiting_for_pty_input;	/* Accelerator to avoid						 * excessive notifier activity*/    int			waiting_for_pty_output;	/* Accelerator to avoid						 * excessive notifier activity*/    Notify_func		cached_pri;		/* Default prioritizer */} Ptytty;static Ptytty * ptytty_create();static short ic_image[258] = {#include <images/overview.icon>};mpr_static(overic_mpr, 64, 64, 1, ic_image);static	struct icon icon = {64, 64, (struct pixrect *)NULL, 0, 0, 64, 64,	    &overic_mpr, 0, 0, 0, 0, NULL, (struct pixfont *)NULL,	    ICON_BKGRDCLR};static	struct pixrect pr = {0, 0, 0, 0, 0};static	struct cursor newcurs = {0, 0, 0, &pr};	/* Blank cursor */#ifdef  get_cursorstatic	Cursor oldcurs_ptr;	/* Remembered cursor */#endif  get_cursorstatic	int winfd = -1;		/* Frame window fd */static	struct screen screen;	/* Screen data */static	Frame frame;		/* Frame with no subwindows */static	int taken_over_screen;	/* Has frame taken over screen? */static	char *command;static	char **arglist;static	int over_pid;		/* pid of child */static	int suspended;		/* Is child in suspended state? */static	int window_prog;	/* Is program a SunWindows based program? */static	Notify_value	event_interposer();static	Notify_value	child_process_state_change();static	Ptytty *pty_tty;	/* pty assistance */static	int overview_handle_output();static	void send_escape_sequence();static	char *strsetwithdecimal();char	*calloc(), *strcpy();#ifdef STANDALONEmain(argc, argv)#elseoverview_main(argc, argv)#endif	int argc;	char **argv;{	char	name[WIN_NAMESIZE];		struct	icon *icon_use;	/* Create frame */	argc--; argv++;	frame = window_create((Window)0, FRAME,	    FRAME_ICON,		&icon,	    FRAME_ARGC_PTR_ARGV,&argc, argv,	    0);	/* Look for flags before command name */	while (argc > 0 && **argv == '-') {		switch (argv[0][1]) {		case 'w':			window_prog = 1;			break;		default:			{}		}		argv++;		argc--;	}	/* Get program name and args */	if (argc > 0) {	    extern	char *rindex();	    arglist = argv;	    command = *arglist;	    /* Get icon that are using */	    icon_use = (struct icon *)(LINT_CAST(window_get(frame, FRAME_ICON)));	    /* Strip off command back to first backslash */	    icon_use->ic_text = rindex(command, '/');	    if (!icon_use->ic_text)		icon_use->ic_text = command;	    else		icon_use->ic_text++;	} else {	    (void)fprintf(stderr,		"Need to specify program name to run under overview.\n");	    exit(1);	}	/* Modify frame */	(void)window_set(frame,	    FRAME_OPEN_RECT,	window_get(frame, WIN_SCREEN_RECT),	    FRAME_ICON,		icon_use,	    0);	/* Interpose frame's event stream */	(void) notify_interpose_event_func(frame,	    event_interposer, NOTIFY_SAFE);	winfd = (int) window_get(frame, WIN_FD);	/* Set environment so that can run SunWindows programs */	(void)win_fdtoname(winfd, name);		(void)we_setgfxwindow(name);		(void)we_setmywindow(name);		/* Get screen */	(void)win_screenget(winfd, &screen);	/* Make pty */	pty_tty = ptytty_create(overview_handle_output);	/*	 * Set so mouse and ascii input will get stopped at this window	 * instead of being directed to underlaying windows.	 */	(void)window_set(frame,	    WIN_CONSUME_PICK_EVENT,	WIN_MOUSE_BUTTONS,	    WIN_CONSUME_KBD_EVENTS,		WIN_ASCII_EVENTS, WIN_LEFT_KEYS, WIN_RIGHT_KEYS,		WIN_TOP_KEYS, 0,						/* See event_interposer */	    WIN_SHOW,			TRUE,	    0);	if (!window_get(frame, FRAME_CLOSED))		takeover();	(void)notify_start();	if (suspended) {		(void)killpg(suspended, SIGKILL);		suspended = 0;	}	exit(0);}staticNotify_valueevent_interposer(frame_local, event, arg, type)    Window    frame_local;    Event    *event;    Notify_arg arg;    Notify_event_type type;{    if (taken_over_screen) {        char    c = event_id(event);        /* Send ASCII to child */        if (event_is_down(event)) {            if (event_is_ascii(event))                (void) ptytty_input(pty_tty, &c, 1);            else if (event_is_key_left(event))                send_escape_sequence(                    event_id(event) - KEY_LEFTFIRST + LEFTFUNC);            else if (event_is_key_right(event))                send_escape_sequence(                    event_id(event) - KEY_RIGHTFIRST + RIGHTFUNC);            else if (event_is_key_top(event))                send_escape_sequence(                    event_id(event) - KEY_TOPFIRST + TOPFUNC);            else                return (NOTIFY_IGNORED);        } else            return (NOTIFY_IGNORED);        return (NOTIFY_DONE);    } else {        Notify_value value;        value = notify_next_event_func(frame_local, (Notify_event)(            LINT_CAST(event)), arg, type);        /* See if not iconic */        if (!window_get(frame_local, FRAME_CLOSED)) {            /* Takeover if not already */            takeover();        }        return (value);    }}static	voidsend_escape_sequence(id)	short	id;{	char	buf[10];	char	*cp;	u_int	entry;	char	c;	/* Get string going to send */	entry = id;	cp = strsetwithdecimal(&buf[0], entry, sizeof (buf) - 1);	/* Send escape sequence */	c = '\033'; /*Esc*/	(void) ptytty_input(pty_tty, &c, 1);	c = '[';	(void) ptytty_input(pty_tty, &c, 1);	while (*cp != '\0') {		(void) ptytty_input(pty_tty, cp, 1);		cp++;	}	c = 'z';	(void) ptytty_input(pty_tty, &c, 1);}static	char *	/* From sundev/kbd.c */strsetwithdecimal(buf, val, maxdigs)	char	*buf;	u_int	val, maxdigs;{	int	hradix = 5;	char	*bp;	int	lowbit;	char	*tab = "0123456789abcdef";	bp = buf + maxdigs;	*(--bp) = '\0';	while (val) {		lowbit = val & 1;		val = (val >> 1);		*(--bp) = tab[val % hradix * 2 + lowbit];		val /= hradix;	}	return (bp);}statictakeover(){	if (taken_over_screen)		return;	if (over_pid == 0) {		if ((over_pid = ptytty_fork(pty_tty, command, arglist)) < 0) {			perror("fork");			exit(1);		}		/* Wait for child process to die */		(void) notify_set_wait3_func(frame,		    child_process_state_change, over_pid);	}#ifdef	get_cursor	/* Remember old cursor */	oldcurs_ptr = (Cursor) window_get(frame, WIN_CURSOR);	/* Give frame an invisible cursor */	(void)window_set(frame, WIN_CURSOR, &newcurs, 0);#else	/* Give frame an invisible cursor */	(void)win_setcursor(winfd, (Cursor)(LINT_CAST(&newcurs)));#endif	/* Prepare framebuffer */	clear_full_framebuffer();	if (!window_prog) {		int fd;		int fdflags;		char buf[30];		/* Direct all keyboard input to over window */		(void)win_grabio(winfd);		/* Turn off mouse (application will read directly) */		(void)win_remove_input_device(winfd, screen.scr_msname);		/* flush mouse */		fd = open(screen.scr_msname, 0);		/* make non-blocking so will generate an error when empty */		if ((fdflags = fcntl(fd, F_GETFL, 0)) == -1)			exit(1);		fdflags |= FNDELAY;		if (fcntl(fd, F_SETFL, fdflags) == -1)			exit(1);		while (read(fd, buf, sizeof buf) > 0)			;		(void)close(fd);	}	taken_over_screen = 1;	if (suspended) {		(void)killpg(suspended, SIGCONT);		suspended = 0;	}}staticclear_full_framebuffer(){	int	fullplanes = 255;	struct	pixwin *pw = pw_open(winfd);	/*	 * Lock screen before clear so don't clobber frame buffer while	 * cursor moving.	 */	(void)pw_lock(pw, &screen.scr_rect);	/* Enable writing to entire depth of frame buffer.  */	(void)pr_putattributes(pw->pw_pixrect, &fullplanes);	/* Clear entire frame buffer */	(void)pr_rop(pw->pw_pixrect, screen.scr_rect.r_left, screen.scr_rect.r_top,	 screen.scr_rect.r_width, screen.scr_rect.r_height, PIX_CLR, 	 (Pixrect *)0, 0, 0);	/* Unlock screen  */	(void)pw_unlock(pw);	(void)pw_close(pw);}/* ARGSUSED */staticNotify_valuechild_process_state_change(frame_local, pid, status, rusage)	Window	frame_local;	int	pid;	union	wait *status;	struct	rusage *rusage;{	if (WIFSTOPPED(*status)) {		/* suspended */		if (window_get(frame_local, FRAME_CLOSED))			return (NOTIFY_IGNORED);		suspended = pid;		putback();		(void)window_set(frame_local, FRAME_CLOSED, TRUE, 0);		return (NOTIFY_DONE);	}	/* dead child */	putback();	exit((int)(status->w_retcode));	/* NOREACH */	return (NOTIFY_DONE);}staticputback(){	if (!taken_over_screen)		return;	if (!window_prog) {		/* Turn on input devices */		(void)win_setms(winfd, &screen);		/*		 * 3.0 arbitrary input device addition with:		 * win_set_input_device(winfd, fd, name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -