📄 suntools.c
字号:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)suntools.c 1.1 92/07/30 SMI";#endif#endif/* * Sun Microsystems, Inc. *//* * Root window: Provides the background window for a screen. * Put up environment manager menu. */#include <suntool/tool_hs.h>#include <sys/ioctl.h>#include <sys/dir.h>#include <sys/file.h>#include <sys/wait.h>#include <sys/resource.h>#include <sys/stat.h>#include <sys/types.h>#include <ctype.h>#include <errno.h>#include <stdio.h>#include <pwd.h>#include <syslog.h>#include <strings.h>#include <varargs.h>#include <vfork.h>#include <sunwindow/defaults.h>#include <suntool/alert.h>#include <suntool/frame.h>#include <suntool/wmgr.h>#include <suntool/selection.h>#include <suntool/selection_svc.h>#include <suntool/walkmenu.h>#include <suntool/icon.h>#include <suntool/icon_load.h>#include <sunwindow/win_keymap.h>#include <suntool/help.h>#ifndef PRE_IBIS#include <sun/fbio.h> /* ioctl definitions */#endif /* !PRE_IBIS */#define Pkg_private/* performance: global cache of getdtablesize() */extern int dtablesize_cache;#define GETDTABLESIZE() \ (dtablesize_cache?dtablesize_cache:(dtablesize_cache=getdtablesize()))Pkg_private int walk_getrootmenu(), walk_handlerootmenuitem();void expand_path();int wmgr_forktool();#define GET_MENU (walk_getrootmenu)#define MENU_ITEM (walk_handlerootmenuitem)#define KEY_STOP ACTION_STOP#define KEY_PUT ACTION_COPY#define KEY_CLOSE ACTION_CLOSE#define KEY_GET ACTION_PASTE#define KEY_FIND ACTION_FIND_FORWARD#define KEY_DELETE ACTION_CUT#define KEY_HELP ACTION_HELP#define MAXPATHLEN 1024#define MAXARGLEN 3000extern int errno;extern char *malloc(), *calloc(), *getenv();extern struct pixrect *pr_load();extern struct pixfont *pf_default(), *pf_open();static void root_winmgr(), root_sigchldhandler(), root_sigwinchhandler(), root_sigchldcatcher(), root_sigwinchcatcher(), root_sigusr1catcher(),#ifdef ecd.suntools root_sigtermhandler(),#endif root_initialsetup(), root_set_background(), root_set_pattern(), root_start_service();Pkg_private char *wmgr_savestr();static int dummy_proc();static struct selection empty_selection = { SELTYPE_NULL, 0, 0, 0, 0};static Seln_client root_seln_handle;static char *seln_svc_file;static int rootfd, rootnumber, root_SIGCHLD, root_SIGUSR1,#ifdef ecd.suntools root_SIGTERM = FALSE,#endif root_SIGWINCH;static struct screen screen;static struct pixwin *pixwin;#define ROOTMENUITEMS 20#define ROOTMENUFILE "/usr/lib/rootmenu"#define ROOTMENUNAME "SunView"#define ARG_CHARS 1024/* These files will be deleted when sunview exits */static char *tmp_file[] = { "/tmp/textsw_shelf", "/tmp/ttyselection", "/tmp/winselection"};static char window_journal[30]; /* string for WINDOW_JOURNAL env var */static int honor_sigusr1; /* whether or not to catch siguser */extern int sv_journal; /* journalling is running */char *rootmenufile;Pkg_private Menu wmgr_rootmenu;struct stat_rec { char *name; /* Dynamically allocated menu file name */ time_t mftime; /* Modified file time */};#define MAX_FILES 40Pkg_private struct stat_rec wmgr_stat_array[MAX_FILES];Pkg_private int wmgr_nextfile;static enum root_image_type { ROOT_IMAGE_PATTERN, ROOT_IMAGE_SOLID,} root_image_type;static struct pixrect *root_image_pixrect;static root_color;static short hglass_data[] = {#include <images/hglass.cursor>};mpr_static_static(hglass_cursor, 16, 16, 1, hglass_data);static short arrow_data[] = { 0x0000, 0x7fe0, 0x7f80, 0x7e00, 0x7e00, 0x7f00, 0x7f80, 0x67c0, 0x63e0, 0x41f0, 0x40f8, 0x007c, 0x003e, 0x001f, 0x000e, 0x0004};mpr_static_static(arrow_cursor, 16, 16, 1, arrow_data);static char *progname; /* my name */static char *basename();Pkg_private int _error();#define NO_PERROR ((char *) 0)/* bug 1027565 -- add suntools security features */#define SV_ACQUIRE "/bin/sunview1/sv_acquire"#define SV_RELEASE "/bin/sunview1/sv_release"#ifdef STANDALONEmain(argc, argv)#elsesuntools_main(argc, argv)#endif int argc; char **argv;{ char name[WIN_NAMESIZE], setupfile[MAXNAMLEN]; int placeholderfd; int donosetup = 0, printname = 0; char *root_background_file = 0;#ifdef PRE_IBIS unsigned char red[256], green[256], blue[256]; unsigned char red_o [2], green_o [2], blue_o [2]; unsigned char red_oe [2], green_oe [2], blue_oe [2];#else /* !PRE_IBIS */ /* * The number of plane groups and their respective colormap size * will vary dramatically between frame buffers. We will declare * some pointers here and malloc the exact colormap size later. */ int cmsize; unsigned char *red [PIX_MAX_PLANE_GROUPS], *green [PIX_MAX_PLANE_GROUPS], *blue [PIX_MAX_PLANE_GROUPS];#endif /* PRE_IBIS */ register struct pixrect *fb_pixrect;#define DONT_CARE_SHIFT -1 Firm_event fe_focus; int fe_focus_shift; Firm_event fe_restore_focus; int fe_restore_focus_shift; int set_focus = 0, set_restore_focus = 0, set_sync_tv = 0; struct timeval sync_tv; char *font_name; char **args; struct singlecolor single_color; register int i; struct sigvec vec; struct stat tmpb; register int j; int file_exists; Cursor cursor; int original_pg; char plane_groups [PIX_MAX_PLANE_GROUPS]; char *journal_ptr; union wait status; progname = basename(argv[0]); seln_svc_file = "selection_svc"; root_image_type = ROOT_IMAGE_PATTERN; root_image_pixrect = tool_bkgrd; root_color = -1; root_set_pattern(defaults_get_string("/SunView/Root_Pattern", "on", (int *)NULL), &single_color); if (defaults_get_boolean("/SunView/Click_to_Type", (Bool)FALSE, (int *)NULL)) { /* 's'plit focus (See -S below if change) */ fe_focus.id = MS_LEFT; fe_focus.value = 1; fe_focus_shift = DONT_CARE_SHIFT; set_focus = 1; fe_restore_focus.id = MS_MIDDLE; fe_restore_focus.value = 1; fe_restore_focus_shift = DONT_CARE_SHIFT; set_restore_focus = 1; } /* * Parse cmd line. */ setupfile[0] = NULL; (void)win_initscreenfromargv(&screen, argv); if (argv) { for (args = ++argv;*args;args++) { if ((strcmp(*args, "-s") == 0) && *(args+1)) { (void) strcpy(setupfile, *(args+1)); args++; } else if (strcmp(*args, "-F") == 0) { root_color = -1; root_image_type = ROOT_IMAGE_SOLID; } else if (strcmp(*args, "-B") == 0) { root_color = 0; root_image_type = ROOT_IMAGE_SOLID; } else if (strcmp(*args, "-P") == 0) root_set_pattern("on", &single_color); else if (strcmp(*args, "-n") == 0) donosetup = 1; else if (strcmp(*args, "-p") == 0) printname = 1; else if (strcmp(*args, "-color") == 0) { if (args_remaining(args) < 4) goto Arg_Count_Error; ++args; if (win_getsinglecolor(&args, &single_color)) continue; root_color = 1; } else if (strcmp(*args, "-background") == 0) { if (args_remaining(args) < 2) goto Arg_Count_Error; root_background_file = *++args; } else if (strcmp(*args, "-pattern") == 0) { if (args_remaining(args) < 2) goto Arg_Count_Error; ++args; root_set_pattern(*args, &single_color); } else if (strcmp(*args, "-svc") == 0) { if (args_remaining(args) < 2) goto Arg_Count_Error; seln_svc_file = *++args; (void) _error(NO_PERROR, "starting selection service \"%s\"", seln_svc_file); } else if (strcmp(*args, "-S") == 0) { /* * 's'plit focus (See Click_to_type above * if change) */ fe_focus.id = MS_LEFT; fe_focus.value = 1; fe_focus_shift = DONT_CARE_SHIFT; set_focus = 1; fe_restore_focus.id = MS_MIDDLE; fe_restore_focus.value = 1; fe_restore_focus_shift = DONT_CARE_SHIFT; set_restore_focus = 1; } else if (strcmp(*args, "-c") == 0) { /* set 'c'aret */ get_focus_from_args(&args, (short *)&fe_focus.id, &fe_focus.value, &fe_focus_shift); set_focus = 1; } else if (strcmp(*args, "-r") == 0) { /* 'r'estore caret */ get_focus_from_args(&args, (short *)&fe_restore_focus.id, &fe_restore_focus.value, &fe_restore_focus_shift); set_restore_focus = 1; } else if (strcmp(*args, "-t") == 0) { /* set 't'imeout */ if (args_remaining(args) < 2) goto Arg_Count_Error; args++; sync_tv.tv_usec = 0; sync_tv.tv_sec = atoi(*args); set_sync_tv = 1; } else if (argc == 2 && *args[0] != '-') /* * If only arg and not a flag then treat as * setupfile (backward compatibility with 1.0). */ (void) strcpy(setupfile, *args); else if (strcmp(*args, "-J") == 0) honor_sigusr1 = 1; } } /* * Set up signal catchers. */ /* (void) signal(SIGCHLD, (void (*)())(LINT_CAST(root_sigchldcatcher))); */ vec.sv_handler = (void (*)())(LINT_CAST(root_sigchldcatcher)); vec.sv_mask = vec.sv_onstack = 0; sigvec(SIGCHLD, &vec, 0); /* (void) signal(SIGWINCH, (void (*)())(LINT_CAST(root_sigwinchcatcher))); */ vec.sv_handler = (void (*)())(LINT_CAST(root_sigwinchcatcher)); sigvec(SIGWINCH, &vec, 0); /* journalling */ if (honor_sigusr1) { vec.sv_handler = (void (*)())(LINT_CAST(root_sigusr1catcher)) ; sigvec(SIGUSR1, &vec, 0) ; }#ifdef ecd.suntools vec.sv_handler = (void (*)())(LINT_CAST(root_sigtermhandler)) ; sigvec(SIGTERM, &vec, 0) ;#endif /* intialization for journalling */ if (honor_sigusr1) { sv_journal = FALSE; (void)sprintf(window_journal, "WINDOW_JOURNAL = OFF"); setenv("WINDOW_JOURNAL", "OFF"); } /* * Find out what colormap is so can restore later. * Do now before call win_screennew which changes colormap. */ if (screen.scr_fbname[0] == NULL) (void)strcpy(screen.scr_fbname, "/dev/fb"); if ((fb_pixrect = pr_open(screen.scr_fbname)) == (struct pixrect *)0) { (void) _error(NO_PERROR, "invalid frame buffer %s", screen.scr_fbname); exit(1); } original_pg = pr_get_plane_group (fb_pixrect);/* bug 1027565 -- fork to change owner/group/permissions of window system devices */ switch (vfork()) { case -1: /* ERROR */ (void)fprintf(stderr, "sunview: Fork failed.\n"); _exit(1); case 0: /* CHILD */ (void)execl(SV_ACQUIRE, "sv_acquire", "0", "256", "240", 0); /* should not return */ (void)fprintf(stderr, "sunview: exec for sv_acquire failed\n"); _exit(1); default: /* PARENT */ /* do nothing */ break; } (void)wait(&status); /* child dies after changing 16 */ if (status.w_retcode != 0) { (void)fprintf(stderr, "sunview: failed to set ownership of win devices\n"); exit(1); }#ifdef PRE_IBIS (void) pr_available_plane_groups (fb_pixrect, 6, plane_groups); for (i = 1; i < PIX_MAX_PLANE_GROUPS; i++) { if (plane_groups [i]) { pr_set_plane_group (fb_pixrect, i); switch (i) { case PIXPG_MONO: case PIXPG_OVERLAY: (void)pr_getcolormap(fb_pixrect, 0, 2, red_o, green_o, blue_o); break; case PIXPG_OVERLAY_ENABLE: (void)pr_getcolormap(fb_pixrect, 0, 2, red_oe, green_oe, blue_oe); break; case PIXPG_8BIT_COLOR: case PIXPG_24BIT_COLOR: (void)pr_getcolormap(fb_pixrect, 0, 256, red, green, blue); break; } } }#else /* !PRE_IBIS */ /* Alloc the exact amount of space and save the colormap. */ (void) pr_available_plane_groups(fb_pixrect,PIX_MAX_PLANE_GROUPS,plane_groups); for (i = 1; i < PIX_MAX_PLANE_GROUPS; i++) { if (plane_groups[i]) { pr_set_plane_group(fb_pixrect, i); if (pr_ioctl(fb_pixrect, FBIOGCMSIZE, &cmsize) < 0) { /* for frame buffers which have no pr_ioctl implemented */ switch (i) { case PIXPG_CURSOR: case PIXPG_CURSOR_ENABLE: /* Dont post a colormap */ continue; break; case PIXPG_MONO: case PIXPG_OVERLAY: case PIXPG_OVERLAY_ENABLE: cmsize = 2; break; default: cmsize = 256; break; } } red[i] = (unsigned char *) malloc(cmsize); blue[i] = (unsigned char *) malloc(cmsize); green[i] = (unsigned char *) malloc(cmsize); (void) pr_getcolormap(fb_pixrect, 0, cmsize, red[i],green[i],blue[i]); } }#endif /* !PRE_IBIS */ pr_set_plane_group (fb_pixrect, original_pg); /* * Create root window */ if ((rootfd = win_screennew(&screen)) == -1) { (void) _error("\cannot create root window\n\The devices necessary to run SunView may not be available (check /dev).\n\System call error"); exit(1); } /* * Set up root's name in environment (must be before call to * pf_use_vm(), which must be before fonts are loaded, directly * or indirectly). */ (void)win_fdtoname(rootfd, name); rootnumber = win_nametonumber(name); (void)we_setparentwindow(name); if (printname) (void)fprintf(stderr, "SunView window name is %s\n", name); /* * Set DEFAULT_FONT environment variable from Defaults database. */ font_name = defaults_get_string("/SunView/Font", "", (int *)NULL); if (*font_name != '\0') (void)setenv("DEFAULT_FONT", font_name); /* * If loaded with shared libraries, turn on vm allocator for * fonts then load all of the fonts listed in defaults database. * This must happen AFTER the framebuffer is opened to increase * the probability that the vm address chosen for the fonts will * also be free in the individual tools. */#define ALERTS_DEFAULT_MENU_FONT "/usr/lib/fonts/fixedwidthfonts/screen.b.14"#define MENU_IMAGE_FONT "/usr/lib/fonts/fixedwidthfonts/screen.b.12" if (pf_linked_dynamic()) { pf_use_vm(1); pf_default(); font_name = defaults_get_string("/Menu/Font", "", (int *)NULL); if (font_name[0] == 0) font_name = ALERTS_DEFAULT_MENU_FONT; (void) pf_open(font_name); (void) pf_open(MENU_IMAGE_FONT); font_name = defaults_get_string("/Text/Font", "", (int *)NULL); if (*font_name != '\0') (void) pf_open(font_name); pf_use_vm(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -