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

📄 xopendis.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $XConsortium: XOpenDis.c,v 11.123 91/12/20 16:04:29 rws Exp $ *//* Copyright    Massachusetts Institute of Technology    1985, 1986	*//*Permission to use, copy, modify, distribute, and sell this software and itsdocumentation for any purpose is hereby granted without fee, provided thatthe above copyright notice appear in all copies and that both thatcopyright notice and this permission notice appear in supportingdocumentation, and that the name of M.I.T. not be used in advertising orpublicity pertaining to distribution of the software without specific,written prior permission.  M.I.T. makes no representations about thesuitability of this software for any purpose.  It is provided "as is"without express or implied warranty.*/#include <X11/Xlibint.h>#include <X11/Xos.h>#include <X11/Xatom.h>#include <stdio.h>#ifdef X_NOT_STDC_ENVextern char *getenv();#endifextern int _Xdebug;#ifndef lintstatic int lock;	/* get rid of ifdefs when locking implemented */#endifstatic xReq _dummy_request = {	0, 0, 0};static OutOfMemory();extern Bool _XWireToEvent();extern Status _XUnknownNativeEvent();extern Bool _XUnknownWireEvent();/*  * Connects to a server, creates a Display object and returns a pointer to * the newly created Display back to the caller. */#if NeedFunctionPrototypesDisplay *XOpenDisplay (	register _Xconst char *display)#elseDisplay *XOpenDisplay (display)	register char *display;#endif{	register Display *dpy;		/* New Display object being created. */	register int i;	int j, k;			/* random iterator indexes */	char *display_name;		/* pointer to display name */	int endian;			/* to determine which endian. */	xConnClientPrefix client;	/* client information */	xConnSetupPrefix prefix;	/* prefix information */	int vendorlen;			/* length of vendor string */	char *setup = NULL;		/* memory allocated at startup */	char *fullname = NULL;		/* expanded name of display */	int idisplay;			/* display number */	int iscreen;			/* screen number */	union {		xConnSetup *setup;		char *failure;		char *vendor;		xPixmapFormat *sf;		xWindowRoot *rp;		xDepth *dp;		xVisualType *vp;	} u;				/* proto data returned from server */	long setuplength;	/* number of bytes in setup message */	char *conn_auth_name, *conn_auth_data;	int conn_auth_namelen, conn_auth_datalen;	unsigned long mask;	extern Bool _XSendClientPrefix();	extern int _XConnectDisplay();	extern XID _XAllocID();	/*	 * If the display specifier string supplied as an argument to this 	 * routine is NULL or a pointer to NULL, read the DISPLAY variable.	 */	if (display == NULL || *display == '\0') {		if ((display_name = getenv("DISPLAY")) == NULL) {			/* Oops! No DISPLAY environment variable - error. */			return(NULL);		}	}	else {		/* Display is non-NULL, copy the pointer */		display_name = (char *)display;	}/* * Lock against other threads trying to access global data (like the error * handlers and display list). */	LockMutex(&lock);/* * Set the default error handlers.  This allows the global variables to * default to NULL for use with shared libraries. */	if (_XErrorFunction == NULL) (void) XSetErrorHandler (NULL);	if (_XIOErrorFunction == NULL) (void) XSetIOErrorHandler (NULL);/* * Attempt to allocate a display structure. Return NULL if allocation fails. */	if ((dpy = (Display *)Xcalloc(1, sizeof(Display))) == NULL) {		UnlockMutex(&lock);		return(NULL);	}/* * Call the Connect routine to get the network socket. If -1 is returned, the * connection failed. The connect routine will set fullname to point to the * expanded name. */	if ((dpy->fd = _XConnectDisplay (display_name, &fullname, &idisplay,					 &iscreen, &conn_auth_name,					 &conn_auth_namelen, &conn_auth_data,					 &conn_auth_datalen)) < 0) {		Xfree ((char *) dpy);		UnlockMutex(&lock);		return(NULL);	}	/* Initialize as much of the display structure as we can */	dpy->display_name	= fullname;	dpy->keysyms		= (KeySym *) NULL;	dpy->modifiermap	= NULL;	dpy->lock_meaning	= NoSymbol;	dpy->keysyms_per_keycode = 0;	dpy->current		= None;	dpy->xdefaults		= (char *)NULL;	dpy->scratch_length	= 0L;	dpy->scratch_buffer	= NULL;	dpy->key_bindings	= NULL;	dpy->ext_procs		= (_XExtension *)NULL;	dpy->ext_data		= (XExtData *)NULL;	dpy->ext_number 	= 0;	dpy->event_vec[X_Error] = _XUnknownWireEvent;	dpy->event_vec[X_Reply] = _XUnknownWireEvent;	dpy->wire_vec[X_Error]  = _XUnknownNativeEvent;	dpy->wire_vec[X_Reply]  = _XUnknownNativeEvent;	for (i = KeyPress; i < LASTEvent; i++) {	    dpy->event_vec[i] 	= _XWireToEvent;	    dpy->wire_vec[i] 	= NULL;	}	for (i = LASTEvent; i < 128; i++) {	    dpy->event_vec[i] 	= _XUnknownWireEvent;	    dpy->wire_vec[i] 	= _XUnknownNativeEvent;	}	dpy->resource_id	= 0;	dpy->db 		= (struct _XrmHashBucketRec *)NULL;	dpy->cursor_font	= None;	dpy->flags		= 0;/*  * Initialize pointers to NULL so that XFreeDisplayStructure will * work if we run out of memory */	dpy->screens = NULL;	dpy->vendor = NULL;	dpy->buffer = NULL;	dpy->atoms = NULL;	dpy->error_vec = NULL;	dpy->context_db = NULL;/* * Setup other information in this display structure. */	dpy->vnumber = X_PROTOCOL;	dpy->resource_alloc = _XAllocID;	dpy->synchandler = NULL;	dpy->request = 0;	dpy->last_request_read = 0;	dpy->default_screen = iscreen;  /* Value returned by ConnectDisplay */	dpy->last_req = (char *)&_dummy_request;	/* Set up the output buffers. */	if ((dpy->bufptr = dpy->buffer = Xmalloc(BUFSIZE)) == NULL) {	        OutOfMemory (dpy, setup);		UnlockMutex(&lock);		return(NULL);	}	dpy->bufmax = dpy->buffer + BUFSIZE; 	/* Set up the input event queue and input event queue parameters. */	dpy->head = dpy->tail = NULL;	dpy->qlen = 0;	/* Set up free-function record */	if ((dpy->free_funcs = (_XFreeFuncRec *)Xcalloc(1,							sizeof(_XFreeFuncRec)))	    == NULL) {	    OutOfMemory (dpy, setup);	    UnlockMutex(&lock);	    return(NULL);	}/* * The xConnClientPrefix describes the initial connection setup information * and is followed by the authorization information.  Sites that are interested * in security are strongly encouraged to use an authentication and  * authorization system such as Kerberos. */	endian = 1;	if (*(char *) &endian)	    client.byteOrder = '\154'; /* 'l' */	else	    client.byteOrder = '\102'; /* 'B' */	client.majorVersion = X_PROTOCOL;	client.minorVersion = X_PROTOCOL_REVISION;	client.nbytesAuthProto = conn_auth_namelen;	client.nbytesAuthString = conn_auth_datalen;	if (!_XSendClientPrefix(dpy, &client, conn_auth_name, conn_auth_data))	{	    _XDisconnectDisplay (dpy->fd);	    Xfree ((char *)dpy);	    UnlockMutex(&lock);	    return(NULL);	}	    	if (conn_auth_name) Xfree(conn_auth_name);	if (conn_auth_data) Xfree(conn_auth_data);/* * Now see if connection was accepted... */	_XRead (dpy, (char *)&prefix,(long)SIZEOF(xConnSetupPrefix));	if (prefix.majorVersion < X_PROTOCOL) {	    fprintf (stderr,       "Xlib:  warning, client built for newer rev (%d) than server (%d)!\r\n",		     X_PROTOCOL, prefix.majorVersion);	}	if (prefix.minorVersion != X_PROTOCOL_REVISION) {	    fprintf (stderr,     "Xlib:  warning, client is protocol rev %d, server is rev %d!\r\n",		     X_PROTOCOL_REVISION, prefix.minorVersion);	}	setuplength = prefix.length << 2;	if ( (u.setup = (xConnSetup *)	      (setup =  Xmalloc ((unsigned) setuplength))) == NULL) {		_XDisconnectDisplay (dpy->fd);		Xfree ((char *)dpy);		UnlockMutex(&lock);		return(NULL);	}	_XRead (dpy, (char *)u.setup, setuplength);/* * If the connection was not accepted by the server due to problems, * give error message to the user.... */	if (prefix.success != xTrue) {		/* XXX - printing messages marks a bad programming interface */		fprintf (stderr, 			 "%s:  connection to \"%s\" refused by server\r\n%s:  ",			 "Xlib", fullname, "Xlib");		(void) fwrite (u.failure, sizeof(char),			(int)prefix.lengthReason, stderr);		(void) fwrite ("\r\n", sizeof(char), 2, stderr);		OutOfMemory(dpy, setup);		UnlockMutex(&lock);		return (NULL);	}/* * We succeeded at authorization, so let us move the data into * the display structure. */	dpy->proto_major_version= prefix.majorVersion;	dpy->proto_minor_version= prefix.minorVersion;	dpy->release 		= u.setup->release;	dpy->resource_base	= u.setup->ridBase;	dpy->resource_mask	= u.setup->ridMask;	dpy->min_keycode	= u.setup->minKeyCode;	dpy->max_keycode	= u.setup->maxKeyCode;	dpy->motion_buffer	= u.setup->motionBufferSize;	dpy->nformats		= u.setup->numFormats;	dpy->nscreens		= u.setup->numRoots;	dpy->byte_order		= u.setup->imageByteOrder;	dpy->bitmap_unit	= u.setup->bitmapScanlineUnit;	dpy->bitmap_pad		= u.setup->bitmapScanlinePad;	dpy->bitmap_bit_order   = u.setup->bitmapBitOrder;	dpy->max_request_size	= u.setup->maxRequestSize;	mask = dpy->resource_mask;	dpy->resource_shift	= 0;	while (!(mask & 1)) {	    dpy->resource_shift++;	    mask = mask >> 1;	}/* * now extract the vendor string...  String must be null terminated, * padded to multiple of 4 bytes. */	dpy->vendor = (char *) Xmalloc((unsigned) (u.setup->nbytesVendor + 1));	if (dpy->vendor == NULL) {

⌨️ 快捷键说明

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