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

📄 xinit.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   (C) 2001 by Argonne National Laboratory.       See COPYRIGHT in top-level directory.*/#include "mpe_graphics_conf.h"#include <stdio.h>#include "mpetools.h"#include "basex11.h"/* This is used to correct system header files without prototypes */#if defined(NEEDS_STDLIB_PROTOTYPES)#include "protofix.h"#endif#if defined(HAVE_UNISTD_H)#include <unistd.h>#endif#if defined(HAVE_STRING_H) || defined(STDC_HEADERS)#include <string.h>#endif/*    This file contains routines to open an X window display and window   This consists of a number of routines that set the various   fields in the XBaseWindow structure, which is passed to    all of these routines.   Note that if you use the default visual and colormap, then you   can use these routines with any X toolkit that will give you the   Window id of the window that it is managing.  Use that instead of the   call to XBCreateWindow .  Similarly for the Display. */static void ArgSqueeze ( int *, char ** );static int ArgFindName ( int, char **, char * );static int ArgGetString ( int *, char **, int, char *, char *, int );/*   ArgSqueeze - Remove all null arguments from an arg vector;    update the number of arguments.*/static void ArgSqueeze( Argc, argv )int  *Argc;char **argv;{    int argc, i, j;    /* Compress out the eliminated args */    argc = *Argc;    j    = 0;    i    = 0;    while (j < argc) {	while (argv[j] == 0 && j < argc) j++;	if (j < argc) argv[i++] = argv[j++];    }/* Back off the last value if it is null */    if (!argv[i-1]) i--;    *Argc = i;}/*   ArgFindName -  Find a name in an argument list.   Input Parameters:.  argc - number of arguments.  argv - argument vector.  name - name to find   Returns:   index in argv of name; -1 if name is not in argv*/static int ArgFindName( argc, argv, name )int  argc;char **argv;char *name;{    int  i;    for (i=0; i<argc; i++) {	if (strcmp( argv[i], name ) == 0) return i;    }    return -1;}/*  ArgGetString - Get the value (string) of a named parameter.    Input Parameters:. Argc  - pointer to argument count. argv  - argument vector. rflag - if true, remove the argument and its value from argv. val   - pointer to buffer to hold value (will be set only if found).. vallen- length of val   Returns:  1 on success*/static int ArgGetString( Argc, argv, rflag, name, val, vallen )int  *Argc, rflag, vallen;char **argv, *name, *val;{    int idx;    idx = ArgFindName( *Argc, argv, name );    if (idx < 0) return 0;    if (idx + 1 >= *Argc) {	fprintf( stderr, "Missing value for argument\n" );	return 0;    }    strncpy( val, argv[idx+1], vallen );    if (rflag) {	argv[idx]   = 0;	argv[idx+1] = 0;	ArgSqueeze( Argc, argv );    }    return 1;}/*  XBWinCreate - Create an XBWin structure that can be used by all other XB  routines  */XBWindow *XBWinCreate(){    XBWindow *w;    w = NEW(XBWindow);    /*CHKPTRN(w); *//* Initialize the structure */    w->disp      = 0;    w->screen    = 0;    w->win       = 0;    w->gc.set    = 0;    w->vis       = 0;    w->numcolors = 0;    w->maxcolors = 0;    w->cmap      = 0;    w->foreground= 0;    w->background= 0;    w->x         = 0;    w->y         = 0;    w->w         = 0;    w->h         = 0;    w->drw       = 0;    return w;}/*   XBWinDestroy - Recover an XBWindow structure  Input parameter:. w  - XB window structure to destroy.  */void XBWinDestroy( w )XBWindow *w;{/* Should try to recover X resources ... *//* Needs to close window ! */    FREE( w );}/* Thanks to Hubertus Franke */#define MAX_TRY (5)/*  XBOpenDisplay - Open a display    Input Parameters:  XBWin        - pointer to base window structure  display_name - either null ("") or of the form "host:0"  */int XBOpenDisplay( XBWin, display_name )XBWindow *XBWin;char     *display_name;{    int i;    if (display_name && display_name[0] == 0)	display_name = 0;    for (i=0; i<MAX_TRY; i++) {	XBWin->disp = XOpenDisplay( display_name );	if (!XBWin->disp) {	    if (i < MAX_TRY) { sleep(1); continue; }	}	else 	    break;    }    if (!XBWin->disp) 	return ERR_CAN_NOT_OPEN_DISPLAY;/* Set the default screen */    XBWin->screen = DefaultScreen( XBWin->disp );/* ? should this set defaults? */    return 0;}/*    XBSetVisual - set the visual class for a window and colormap    Input Parameters:.   nc - number of colors.  Use the maximum of the visual if    nc == 0.  Use nc = 2 for black and white displays.    */int XBSetVisual( XBWin, q_default_visual, cmap, nc )XBWindow *XBWin;int      q_default_visual;Colormap cmap;int      nc;{if (q_default_visual) {    XBWin->vis    = DefaultVisual( XBWin->disp, XBWin->screen );    XBWin->depth  = DefaultDepth(XBWin->disp,XBWin->screen);    if (!cmap)        XBWin->cmap  = DefaultColormap( XBWin->disp, XBWin->screen );    else        XBWin->cmap  = cmap;    }else {    /* Try to match to some popular types */    XVisualInfo vinfo;    if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 24, DirectColor,			 &vinfo)) {	XBWin->vis    = vinfo.visual;	XBWin->depth  = 24;	}    else if (XMatchVisualInfo( XBWin->disp, XBWin->screen, 8, PseudoColor,			 &vinfo)) {	XBWin->vis    = vinfo.visual;	XBWin->depth  = 8;	}    else if (XMatchVisualInfo( XBWin->disp, XBWin->screen,			 DefaultDepth(XBWin->disp,XBWin->screen), PseudoColor,			 &vinfo)) {	XBWin->vis    = vinfo.visual;	XBWin->depth  = DefaultDepth(XBWin->disp,XBWin->screen);	}    else {	XBWin->vis    = DefaultVisual( XBWin->disp, XBWin->screen );	XBWin->depth  = DefaultDepth(XBWin->disp,XBWin->screen);	}    /* There are other types; perhaps this routine should accept a        "hint" on which types to look for. */    XBWin->cmap = (Colormap) 0;    }/* reset the number of colors from info on the display, the colormap */XBInitColors( XBWin, cmap, nc );return 0;}/*    XBSetGC - set the GC structure in the base window   */int XBSetGC( XBWin, fg )XBWindow *XBWin;PixVal   fg;{XGCValues       gcvalues;       /* window graphics context values *//* Set the graphics contexts *//* create a gc for the ROP_SET operation (writing the fg value to a pixel) *//* (do this with function GXcopy; GXset will automatically write 1) */gcvalues.function   = GXcopy;gcvalues.foreground = fg;XBWin->gc.cur_pix   = fg;XBWin->gc.set = XCreateGC( XBWin->disp, RootWindow(XBWin->disp,XBWin->screen),                              GCFunction | GCForeground, &gcvalues );return 0;}/*   XBOpenWindow - Open the window data structure    Note that before a window can be opened, the Visual class and the   (initial) colormap should be set.    Opening a window comes in two parts:    Creating most of the local window structure, and    actually creating and mapping the window.    This allows us to defer the choice of the window size until    the various tools have been set (note that many tools have    minimum sizes determined by things like the current font size).    This needs to know a few more things inorder to co-exist with    other tools and applications.  In particular, it needs to know    whether to use the default visual or another window's colormap.  */int XBOpenWindow( XBWin )XBWindow *XBWin;{return 0;}/*    Actually display a window at [x,y] with sizes (w,h)    If w and/or h are 0, use the sizes in the fields of XBWin    (which may have been set by, for example, XBSetWindowSize) */int XBDisplayWindow( XBWin, label, x, y, w, h, backgnd_pixel )XBWindow *XBWin;char     *label;int      w, h, x, y;PixVal   backgnd_pixel;{unsigned int    wavail, havail;XSizeHints      size_hints;int             q_user_pos;XWindowAttributes       in_window_attributes;XSetWindowAttributes    window_attributes;int                     depth, border_width;unsigned long           wmask;/* get the available widths */wavail              = DisplayWidth(  XBWin->disp, XBWin->screen );havail              = DisplayHeight( XBWin->disp, XBWin->screen );if (w <= 0 || h <= 0) return ERR_ILLEGAL_SIZE;

⌨️ 快捷键说明

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