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

📄 x_hilinit.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 5 页
字号:
	devuse[0] = '\0';	parms = sscanf (buf, "%s%s%s", pos, path, devuse);	if (pos[0] == '#')	/* comment, skip it */	    continue;	else if (path[0] == '#')/* 1 parm           */	    parms = 1;	else if (devuse[0] == '#')/* 2 parms        */	    parms = 2;	if (parms == EOF)		/* blank line            */	    continue;	else if (parms == 1)	    {	    for (i=0; i<strlen(pos); i++)		pos[i] = toupper(pos[i]);	    if (strcmp (pos,"BEGIN_DEVICE_DESCRIPTION") == 0)		parse_description (fd, serial, &sother);	    else		{		ErrorF("Invalid X*devices entry: \"%s\" - Entry skipped\n",buf);		continue;		}	    }	else if (parms == 2)	/* device name specified */	    parse_2_parms (pos, path, opendevs, &other);	else if (parms ==3)	    parse_3_parms (pos, path, devuse, opendevs, &other);	}    return (other);    }/*********************************************************************** * * This routine is invoked when two parameters are specified. * Either they are a device path and intended use, or a device loop path. * */parse_2_parms (dev, use, o, ondx)    char *dev;    char *use;    struct	opendevs o[];    int  *ondx;    {    int i;    int ndx;    int len = strlen(use);    for (i=0; i<len; i++)	use[i] = toupper(use[i]);    if (strcmp (use,"HIL_PATH") == 0)	{	strcpy (hilpath,dev);	return;	}    else if (strcmp (use, "POINTER") == 0)	ndx = XPOINTER;    else if (strcmp (use, "KEYBOARD") == 0)	ndx = XKEYBOARD;    else if (strcmp (use, "OTHER") == 0)	ndx = (*ondx)++;    else	{	ErrorF ("Bad device use \"%s\" in X*devices file - Entry skipped.\n",		use);	return;	}    o[ndx].type = -1;    o[ndx].pos = -1;    strcpy (o[ndx].path, dev);    }/*********************************************************************** * * This routine is invoked when three parameters are specified. * They are a position, a device type, and its intended use. * */parse_3_parms (pos, name, use, o, ondx)    char *pos;    char *name;    char *use;    struct	opendevs o[];    int  *ondx;    {    int i;    int ndx;    for (i=0; i<strlen(pos); i++)	pos[i] = toupper(pos[i]);    for (i=0; i<strlen(use); i++)	use[i] = toupper(use[i]);    if (strcmp (use, "POINTER") == 0)	ndx = XPOINTER;    else if (strcmp (use, "KEYBOARD") == 0)	ndx = XKEYBOARD;    else if (strcmp (use, "OTHER") == 0)	ndx = *ondx;    else	{	ErrorF ("Bad device use \"%s\" in X*devices file - Entry skipped.\n",	    use);	return;	}    for (i=0; i<MAX_POSITIONS; i++)	if (strcmp (position[i], pos) == 0)	    {	    o[ndx].pos = i;	    break;	    }    if (i == MAX_POSITIONS) /* failed, skip to next */	{	ErrorF ("Bad ordinal \"%s\" in X*devices file - Entry skipped.\n",	    pos);	return;	}    for (i=0; i<strlen(name); i++)	name[i] = toupper(name[i]);    for (i=0; i<MAX_DEV_TYPES; i++)	if (strcmp (devices[i].name,name) == 0)	    {	    o[ndx].type = devices[i].dev_type;	    break;	    }    if (i == MAX_DEV_TYPES) /* failed, skip to next */	{	ErrorF ("Bad device type \"%s\" in X*devices file - Entry skipped.\n",		name);	return;	}    else if (ndx == *ondx)	(*ondx)++;    }/******************************************************************** * * * * */parse_description(fd, o, ondx)    FILE	*fd;    struct	opendevs o[];    int  	*ondx;    {    int		ndx = -1, i, len;    char buf[256], ubuf[256], name[256], uname[256], path[256], var[64], 	use[64], entry[64];    char *fgets();    name[0] = '\0';    entry[0] = '\0';    while (fgets(buf,256,fd) != NULL)	{	len = strlen(buf);	for (i=0; i<len; i++)	    ubuf[i] = toupper(buf[i]);	if (sscanf (ubuf,"PATH %s", var) == 1)	    sscanf (buf,"%s %s", var, path);	else if (sscanf (ubuf,"NAME %s", uname) == 1)	    sscanf (buf,"%s %s", var, name);	else if (sscanf (ubuf,"ENTRYPOINT %s", var) == 1)	    sscanf (buf,"%s %s", var, entry);	else if (sscanf (ubuf,"USE %s",use) == 1)	    {	    if (!strcmp(use,"POINTER"))		ndx = XPOINTER;	    else if (!strcmp(use,"KEYBOARD"))		ndx = XKEYBOARD;	    else		ndx = (*ondx)++;	     }	else if (sscanf (ubuf," %s",var) == 1 &&		 strcmp (var,"END_DEVICE_DESCRIPTION")==0)	    {	    if (device_ndx < 0)		{		ErrorF("Too many devices in X*devices file - entry skipped.\n");		return;		}	    if (ndx != -1 && path)		{		o[ndx].type = 99;		strcpy (o[ndx].path, path);		strcpy (o[ndx].name, name);		if (entry[0])		    strcpy (o[ndx].entry, entry);		else		    {		    len = strcspn (name,".");		    strncpy (o[ndx].entry, name, len);		    o[ndx].entry[len] = '\0';		    strcat (o[ndx].entry, "_Init");		    }		sdev_num++;		}	    return;	    }	else	    {	    ErrorF ("Invalid line in device description - ignored.\n");	    ErrorF ("line was: %s",buf);	    }	}    ErrorF("No END_DESCRIPTION line in X*devices file - description skipped.\n");    }/******************************************************************** * * get_codes() * Used to assign codes to keys used to move the pointer. * Also to assign numbers to the amount to move the pointer. * This routine uses the index into the file to determine the keycode. * The down keycode is (index * 2), the up keycode is that plus 1. * If the type is NUMBER, the key string is assumed to be an ascii * representation of a number. * This is used as the increment to move the pointer. * */#define 	MAX_HIL_KEYS		128static get_codes (key, code, type)    char	*key;    int		*code;    int		type;    {    int		i;    for (i=0; i<strlen(key); i++)	*(key+i) = toupper(*(key+i));    if (type == UCHAR_NUMBER || type == USHORT_NUMBER || type == UINT_NUMBER)	{	*code = atoi (key);	return (0);	}    else if (type == STRING)	for (i=0; i<MAX_STRINGS; i++)	    if (strcmp (key, strings[i].string) == 0)		{		*code = strings[i].value;		return (0);		}    for (i=0; i<MAX_HIL_KEYS; i++)        if (strcmp (key, keyset1[i]) == 0)	    {	    *code = i+8;	    return (0);	    }#if defined(__hpux) || defined(__hp_osf) || defined(hp9000)    for (i=0; i<MAX_HIL_KEYS; i++)        if (strcmp (key, newkeyset1[i]) == 0)	    {	    *code = i+8;	    return (0);	    }#endif /* __hpux */    return (-1);    }/******************************************************************** * * get_vars() * get the address of variables to contain keycodes for pointer functions. * */static get_vars (func, codevar, index)    char	*func;    u_char	**codevar;    int		*index;    {    int		i;        for (i=0; i<strlen(func); i++)	*(func+i) = toupper(*(func+i));    for (i=0; i<MAX_POINTER_FUNCS; i++)        if (strcmp (func, pointerfunc[i].name) == 0)	    {	    *codevar = pointerfunc[i].code;	    *index = i;	    return (0);	    }    return (-1);    }/******************************************************************** * * get_pointerkeys(). * This routine provides the ability to configure keyboard keys to  * move the pointer and act like buttons on the pointer device. * The file processed is the X*pointerkeys file, which consists * of pairs.  The form is: * * 	function	key, modifier, or value * * Look at the pointerfunc table in x_hilinit.h to understand this code. * There are 3 types of assignment done: * 	1). keys - have both a down and an up code to assign. *	2). modifiers - are a bit position in a mask. *	3). values - are a single integer number. * Possible errors: *	1). only 1 of the pair was specified. *	2). an invalid function was specified. *	3). an invalid key or modifier was specified. */get_pointerkeys()    {    char	fname[MAXNAMLEN+1];    FILE	*fp;    int 	len;    int 	cret;    int 	vret;    int 	ret2;    int 	index;    char 	buf[MAXNAMLEN+1];    char 	function[MAXNAMLEN+1];    char 	key[MAXNAMLEN+1];    char 	*fgets();    int		code;    union	{	u_char 	*cptr;	u_short *sptr;	u_int 	*iptr;	} codevar;    (void) sprintf(fname, "%sX%spointerkeys", DEF_DIRECTORY, display);    fp = fopen ( fname, "r");    if (fp == NULL)	return;    while (fgets(buf,MAXNAMLEN+1,fp) != NULL)	{	ret2 = sscanf (buf,"%s%s",function,key);	/* comments begin with a '#'.  Skip them. */	if (function[0] == '#')		/* comment, skip it 	*/	    continue;	if (ret2 == 2)			/* error if < 2 items 	*/	    {	    vret = get_vars (function, &codevar, &index);	    if (vret < 0)		/* invalid function     */		{		ErrorF ("Bad function \"%s\" skipped in X*pointerkeys file.\n",		    function);		continue;		/* error - skip this one*/		}	    cret = get_codes (key, &code, pointerfunc[index].type);	    if (cret < 0 &&		/* not a key or modifier*/	        pointerfunc[index].type == KEY) /* but must be  */		{		ErrorF ("Bad key name \"%s\" skipped in X*pointerkeys file.\n",		    key);		continue;		/* error - skip this one*/		}	    if (pointerfunc[index].type==MODIFIER) /* modifier - compute bit*/	        *codevar.cptr = code - 8;	    else if (pointerfunc[index].type==UINT_NUMBER)	        *codevar.iptr = code;		/* code for 16-bit number */	    else if (pointerfunc[index].type==USHORT_NUMBER)	        *codevar.sptr = code;		/* code for 16-bit number */	    else	        *codevar.cptr = code;		/* code for 8-bit key */	    }	else	    {	    len = strlen(buf) - 1;	/* fgets adds a newline */	    buf[len] = '\0';	    if (len > 0)	        ErrorF ("Bad entry \"%s\" skipped in X*pointerkeys file.\n",		    buf);	    }	}	    fclose (fp);    }/**************************************************************************** * * TimeSinceLastInputEvent() * - aparently returns time in miliseconds since last input event * */TimeSinceLastInputEvent()    {    if (lastEventTime == 0)	lastEventTime = GetTimeInMillis();    return GetTimeInMillis() - lastEventTime;    }/**************************************************************************** * * hpAddInputDevice(deviceProc, autoStart, pHPDev) * create an X input device, then assign pHPDev to it's devicePrivate field. * */static DevicePtr hpAddInputDevice(deviceProc, autoStart, pHPDev)    DeviceProc deviceProc;    Bool autoStart;    HPInputDevice *pHPDev;    {    DevicePtr pXDev;    if ((pXDev = AddInputDevice(deviceProc, autoStart)) == NULL)	FatalError ("Too many input devices - X server terminating!\n");    pHPDev->dev_id = ((DeviceIntPtr) pXDev)->id;#ifdef XINPUT    if (pHPDev == hpPointer)	{#ifdef NOT_DONE	hp_device_ids[pHPDev->dev_id] = XPOINTER;#endif	x_device_ids[XPOINTER] = pHPDev->dev_id;	}    else if (pHPDev == hpKeyboard)	{#ifdef NOT_DONE	hp_device_ids[pHPDev->dev_id] = XKEYBOARD;#endif	x_device_ids[XKEYBOARD] = pHPDev->dev_id;	}    else	{#ifdef NOT_DONE	hp_device_ids[pHPDev->dev_id] = otherndx;#endif	x_device_ids[otherndx++] = pHPDev->dev_id;	}#endif /* XINPUT */    pXDev->devicePrivate = (pointer) pHPDev;    return  pXDev;    }/**************************************************************************** * * We allow any keycode to be specified as a modifer, Even one that can't * be generated by our keyboard. * */LegalModifier(key, dev)    BYTE key;    DeviceIntPtr dev;    {    return TRUE;    }/**************************************************************************** * * close_device closes one of the input devices. * */close_device(d)    HPInputDevice	*d;    {    BITCLEAR(valid_inputs.input_mask, d->file_ds);    if (d->file_ds == valid_inputs.max_fd) 	{	valid_inputs.max_fd--;	}#ifdef __apollo    if (!strcmp (d->dev_name, "Apollo_internal"))	return;#endif /* __apollo */#ifdef __hp_osf    if (d->file_ds != -1)	ioctl(d->file_ds, HILUNMAPQ, &hil_qp->hil_evqueue.qnum);    if (!ANYSET(valid_inputs.input_mask))	{	RemoveEnabledDevice (beeper_fd);	ioctl (beeper_fd, HILFREEQ, &hil_qp->hil_evqueue.qnum);	close (beeper_fd);	hil_qp = 0;	}#endif /* __hp_osf */    close (d->file_ds);    d->file_ds = -1;    }/***************************** * * init_events_queue (queue) *  */init_events_queue(queue)    struct  x11EventQueue	*queue;		    {    queue->events = events_array;	    queue->head = 0;    queue->tail = 0;    queue->size = MAX_EVENTS;    events_queue = queue;    }/***************************************************************** * * allocate_event ()

⌨️ 快捷键说明

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