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

📄 suntools.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	  case KBD_REQUEST:	/* Always refuse keyboard focus request */	    (void)win_refuse_kbd_focus(rootfd);	    break;	  case KEY_PUT:	  case KEY_GET:	  case KEY_FIND:	  case KEY_DELETE:	    if (root_seln_handle != (Seln_client) NULL) {		seln_report_event((Seln_client)(LINT_CAST(			root_seln_handle)), &event);	    }	    break;	  case KEY_CLOSE:	    break;	  case MS_LEFT:	    if (win_inputposevent(&event)) {		/*  the left button went down; clear the selection.  */		(void)selection_set(&empty_selection, dummy_proc, dummy_proc, rootfd);		if (root_seln_handle != (Seln_client) NULL) {		    Seln_rank             rank;		    rank = seln_acquire((Seln_client)(LINT_CAST(		    	root_seln_handle)), SELN_UNSPECIFIED);		    (void)seln_done((Seln_client)(LINT_CAST(root_seln_handle)),		    	 rank);		}	    }	    break;	  case MENU_BUT:	    if (win_inputposevent(&event)) {		if (!root_menu_mgr(&event)) {		    return;		}	    }	    break;	  case KEY_HELP:	    if (win_inputposevent(&event))		(void)help_request(NULL, "sunview:rootwindow", &event);	    break;	  default:	    break;	}	keyexit = 0;    }}static introot_menu_mgr(event)	struct inputevent    *event;{	Menu_item     mi; /* Old and new menu item */	int	      exit_local;	if (GET_MENU(rootmenufile) <= 0) {	    (void) _error(NO_PERROR, "invalid root menu");	    return 1;	}	for (;;) {	    struct inputevent tevent;	    exit_local = 0;	    tevent = *event;	    mi = menu_show_using_fd(wmgr_rootmenu, rootfd, event);	    if (mi)		exit_local = MENU_ITEM(wmgr_rootmenu, mi, rootfd) == -1;	    if (event_action(event) == MS_LEFT && !exit_local) {		*event = tevent;/*		win_setmouseposition(rootfd, event->ie_locx, event->ie_locy);*/	    } else {		break;	    }	}	return (!exit_local);}static voidroot_sigchldhandler(){	union	wait status;	root_SIGCHLD = 0;	while (wait3(&status, WNOHANG, (struct rusage *)0) > 0)		{}}static voidroot_sigwinchhandler(){	root_SIGWINCH = 0;	(void)pw_damaged(pixwin);	switch (root_image_type) {	case ROOT_IMAGE_PATTERN:		(void)pw_replrop(pixwin,		    screen.scr_rect.r_left, screen.scr_rect.r_top,		    screen.scr_rect.r_width, screen.scr_rect.r_height,		    PIX_SRC | PIX_COLOR(root_color), root_image_pixrect, 0, 0);		break;	case ROOT_IMAGE_SOLID:	default:		(void)pw_writebackground(pixwin,		    screen.scr_rect.r_left, screen.scr_rect.r_top,		    screen.scr_rect.r_width, screen.scr_rect.r_height,		    PIX_SRC | PIX_COLOR(root_color));	}	(void)pw_donedamaged(pixwin);	return;}static voidroot_sigchldcatcher(){	root_SIGCHLD = 1;}static voidroot_sigwinchcatcher(){	root_SIGWINCH = 1;}static voidroot_sigusr1catcher(){        if (sv_journal) {                (void)sprintf(window_journal, "WINDOW_JOURNAL = OFF");                setenv("WINDOW_JOURNAL", "OFF");                sv_journal=FALSE;        }        else {                (void)sprintf(window_journal, "WINDOW_JOURNAL = ON");                setenv("WINDOW_JOURNAL","ON");                sv_journal=TRUE;        }}#ifdef ecd.suntools  static voidroot_sigtermhandler(){	root_SIGTERM = TRUE ;}#endifstatic char *get_home_dir(){	extern	char *getlogin();	extern	struct	passwd *getpwnam(), *getpwuid();	struct	passwd *passwdent;	char	*home_dir = getenv("HOME"), *loginname;	if (home_dir != NULL)		return(home_dir);	loginname = getlogin();	if (loginname == NULL) {		passwdent = getpwuid(getuid());	} else {		passwdent = getpwnam(loginname);	}	if (passwdent == NULL) {		(void) _error(NO_PERROR,			"cannot find user in password file");		return(NULL);	}	if (passwdent->pw_dir == NULL) {		(void) _error(NO_PERROR,			"no home directory for %s in password file",			passwdent->pw_name);		return(NULL);	}	return(passwdent->pw_dir);}#define	ROOT_ARGBUFSIZE		1000#define ROOT_SETUPFILE		"/.sunview"#define	ROOT_SETUPFILE_ALT	"/.suntools"#define	ROOT_MAXTOOLDELAY	10#define	ROOT_DEFAULTSETUPFILE	"/usr/lib/.sunview"static voidroot_initialsetup(requestedfilename)	char	*requestedfilename;{	register i;	FILE	*file;	char	filename[MAXNAMLEN], programname[MAXNAMLEN],		otherargs[ROOT_ARGBUFSIZE];	struct	rect rectnormal, recticonic;	int	iconic, topchild, bottomchild, seconds, j;	char	line[ARG_CHARS], full_programname[MAXPATHLEN];	if (requestedfilename[0] == NULL) { /* first look for .sunview */		char *home_dir = get_home_dir();		if (home_dir == NULL)			return;		(void) strcpy(filename, home_dir);		(void) strncat(filename, ROOT_SETUPFILE,		    sizeof(filename)-1-strlen(filename)-strlen(			ROOT_SETUPFILE));	} else (void) strncpy(filename,requestedfilename,sizeof(filename)-1);	file = fopen(filename, "r");	if (!file && !requestedfilename[0]) { /* else get .suntools */		char *home_dir = get_home_dir();		if (home_dir == NULL)			return;		(void) strcpy(filename, home_dir);		(void) strncat(filename, ROOT_SETUPFILE_ALT,		    sizeof(filename)-1-strlen(filename)-strlen(			ROOT_SETUPFILE_ALT));		file = fopen(filename, "r");	}	if (!file && !requestedfilename[0]) {	/* If default file not found in HOME, look in public library */		(void) strcpy(filename, ROOT_DEFAULTSETUPFILE);		file = fopen(filename, "r");	}/*  We used to not give an error if looking for default .sunview.    Now that we check the defaults lib dir, we give an error message.		if (requestedfilename[0] == NULL)			return;*//* If we cannot open startup file specified by the -s option * or we cannot open any of the default startup files then we exit * rather than return, so that we avoid hanging.*/	if (!file) {		(void) _error("cannot open startup file %s", filename);		exit(1);	}	while (fgets(line, sizeof (line), file)) {		register char *t;		for (t = line; isspace(*t); t++);		if (*t == '#' || *t == '\0')			continue;		otherargs[0] = '\0';		programname[0] = '\0';		i = sscanf(line, "%s%hd%hd%hd%hd%hd%hd%hd%hd%hd%[^\n]\n",		    programname,		    &rectnormal.r_left, &rectnormal.r_top,		    &rectnormal.r_width, &rectnormal.r_height,		    &recticonic.r_left, &recticonic.r_top,		    &recticonic.r_width, &recticonic.r_height,		    &iconic, otherargs);		if (i == EOF)			break;		if (i < 10 || i > 11) {		   /*		    * Just get progname and args.		    */		    otherargs[0] = '\0';		    programname[0] = '\0';		    j = sscanf(line, "%s%[^\n]\n", programname, otherargs);		    if (j > 0) {			iconic = 0;			rect_construct(&recticonic, WMGR_SETPOS, WMGR_SETPOS,			    WMGR_SETPOS, WMGR_SETPOS);			rect_construct(&rectnormal, WMGR_SETPOS, WMGR_SETPOS,			    WMGR_SETPOS, WMGR_SETPOS);		    } else {			(void)_error(NO_PERROR, "\in file %s fscanf gave %ld, correct format is:\n\n\program open-left open-top open-width open-height close-left close-top close-width close-height iconicflag [args] <newline>\n\ OR\n\program [args] <newline>\n",				filename, i);			continue;		    }		}		/*		 * Remember who top and bottom children windows are for use when		 * trying to determine when tool is installed.		 */		topchild = win_getlink(rootfd, WL_TOPCHILD);		bottomchild = win_getlink(rootfd, WL_BOTTOMCHILD);		/*		 * Fork tool.		 */		suntools_mark_close_on_exec();		expand_path(programname, full_programname);		(void) wmgr_forktool(full_programname, otherargs,		    &rectnormal, &recticonic, iconic);		/*		 * Give tool chance to intall self in tree before starting next.		 */		for (seconds = 0; seconds < ROOT_MAXTOOLDELAY; seconds++) {			usleep(1 << 20);			if (topchild != win_getlink(rootfd, WL_TOPCHILD) ||			    bottomchild != win_getlink(rootfd, WL_BOTTOMCHILD))				break;		}	}	(void) fclose(file);}Pkg_privatesuntools_mark_close_on_exec(){	register i;	int limit_fds = GETDTABLESIZE();	/* Mark all fds (other than stds) as close on exec */	for (i = 3; i < limit_fds; i++)		(void) fcntl(i, F_SETFD, 1);}static voidroot_set_pattern(token, ptr_single_color)	char *token;	struct singlecolor *ptr_single_color;{	char err[IL_ERRORMSG_SIZE];	struct pixrect *mpr;	if (strcmp(token, "on") == 0) {		root_image_type = ROOT_IMAGE_PATTERN;	} else if (strcmp(token, "off") == 0) {		root_image_type = ROOT_IMAGE_SOLID;	} else if (strcmp(token, "grey") == 0 || strcmp(token, "gray") == 0) {		ptr_single_color->red = ptr_single_color->green =		    ptr_single_color->blue = 128;		root_color = 1;		root_image_type = ROOT_IMAGE_SOLID;	} else if ((mpr = icon_load_mpr(token, err))== (struct pixrect *)0) {		(void) _error(NO_PERROR, "pattern file %s, error %s",			token, err);	} else {		root_image_pixrect = mpr;		root_image_type = ROOT_IMAGE_PATTERN;	}}static voidroot_set_background(filename)	char	*filename;{	int		 x, y;	FILE		*file;	register struct pixrect	*tmp_pr, *root_pr;	if ((file = fopen(filename, "r"))  == (FILE *) NULL)  {		(void) _error("cannot open background file %s", filename);		return;	}	if ((tmp_pr = pr_load(file, (colormap_t *)NULL/* Ignoring colormap */))	    == (struct pixrect *) NULL)  {		(void) _error(NO_PERROR, "cannot load background from %s",			 filename);		(void)fclose(file);		return;	}	(void)fclose(file);	root_pr =	    mem_create(screen.scr_rect.r_width, screen.scr_rect.r_height, 1);	/* Center image */	x = (screen.scr_rect.r_width - tmp_pr->pr_width) / 2;	y = (screen.scr_rect.r_height - tmp_pr->pr_height) / 2;	/* Initialize background */	switch (root_image_type) {	case ROOT_IMAGE_PATTERN:		(void)pr_replrop(root_pr, 0, 0,		    screen.scr_rect.r_width, screen.scr_rect.r_height,		    PIX_SRC | PIX_COLOR(root_color), root_image_pixrect, 			    0, 0);		break;	case ROOT_IMAGE_SOLID:	default:		(void)pr_rop(root_pr, 0, 0,		    screen.scr_rect.r_width, screen.scr_rect.r_height,		    PIX_SRC | PIX_COLOR(root_color), (Pixrect *)0, 0, 0);	}	/* Draw picture on image pixrect */	(void)pr_rop(root_pr, x, y, tmp_pr->pr_width, tmp_pr->pr_height,		PIX_SRC, tmp_pr, 0, 0);	(void)pr_destroy(tmp_pr);	root_image_pixrect = root_pr;	/* PATTERN will cause image pixrect to be roped without replication */	root_image_type = ROOT_IMAGE_PATTERN;}Pkg_private intwmgr_menufile_changes(){	struct stat statb;	int sa_count;	if (wmgr_nextfile == 0) return 1;	/* Whenever existing menu going up, stat menu files */	for (sa_count = 0;sa_count < wmgr_nextfile;sa_count++) {		if (stat(wmgr_stat_array[sa_count].name, &statb) < 0) {			if (errno == ENOENT)				return(1);			return _error("menu file %s stat error",				wmgr_stat_array[sa_count].name);		}		if (statb.st_mtime > wmgr_stat_array[sa_count].mftime)			return(1);	}	return 0;}Pkg_privatewmgr_free_changes_array(){       int sa_count = 0;        while (sa_count < wmgr_nextfile) {	free(wmgr_stat_array[sa_count].name);      /* file name */	wmgr_stat_array[sa_count].name = NULL;	wmgr_stat_array[sa_count].mftime = 0;	sa_count++;    }    wmgr_nextfile = 0;}Pkg_private char *wmgr_save2str(s, t)	register char *s, *t;{	register int len = strlen(s) + 1;	register char *p;	if ((p = malloc((unsigned) len + (t ? strlen(t) + 1 : 0))) == NULL) {		if (rootfd)			(void)win_screendestroy(rootfd);		(void) _error(NO_PERROR, "out of memory for menu strings");		exit(1);	}	(void) strcpy(p, s);	if (t)		(void) strcpy(p + len, t);	return (p);}Pkg_private char *wmgr_savestr(s)	register char *s;{	return wmgr_save2str(s, (char *) 0);}/* dummy proc for selection_set()*/static intdummy_proc(){}static voidroot_start_service(){	register int	i;	static char *args[2] = {"selection_svc", 0 };	if (vfork() == 0)  {		/* XXX: should this be getdtablesize? */		for (i = 30; i > 2; i--)  {			(void)close(i);		}		execvp(seln_svc_file, args, 0);		(void)_error(NO_PERROR, "cannot fork selection service");		usleep(7 << 20);		_exit(1);	}}static char *basename(path)	char *path;{	register char *p = path, c;	while (c = *p++)		if (c == '/')			path = p;	return path;}/* _error([no_perror, ] fmt [, arg ...]) *//*VARARGS*/Pkg_private int_error(va_alist)va_dcl{	int saved_errno;	va_list ap;	int no_perror = 0;	char *fmt;	extern int errno;	saved_errno = errno;	(void) fprintf(stderr, "%s: ", progname);	va_start(ap);	if ((fmt = va_arg(ap, char *)) == 0) {		no_perror = 1;		fmt = va_arg(ap, char *);	}	(void) _doprnt(fmt, ap, stderr);	va_end(ap);	if (no_perror)		(void) fprintf(stderr, "\n");	else {		(void) fprintf(stderr, ": ");		errno = saved_errno;		perror("");	}	return -1;}

⌨️ 快捷键说明

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