📄 ximproto.c
字号:
/* * $XConsortium: XIMProto.c,v 1.9 91/05/07 19:27:52 rws Exp $ *//* * Copyright 1990, 1991 by OMRON Corporation * Copyright 1991 by the Massachusetts Institute of Technology * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the names of OMRON and MIT not be used in * advertising or publicity pertaining to distribution of the software without * specific, written prior permission. OMRON and MIT make no representations * about the suitability of this software for any purpose. It is provided * "as is" without express or implied warranty. * * OMRON AND MIT DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL OMRON OR MIT BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. * * Author: Seiji Kuwari OMRON Corporation * kuwa@omron.co.jp * kuwa%omron.co.jp@uunet.uu.net */ #include "Xlibint.h"#include "Xi18nint.h"#include "XIMlibint.h"#include <stdio.h>#ifndef lintstatic lock_err_fun;#endif /* lint */static void (*_XipIOErrorFunction)();/*ARGSUSED*/static void_XipDefaultIOError(im) XipIM im;{ (void)fprintf(stderr, "XIM: fatal IO error on X Input Manager\n");}static void_XipIOError(im) XipIM im;{ LockMutex(&lock_err_fun); if (_XipIOErrorFunction) (*_XipIOErrorFunction)(im); else _XipDefaultIOError(im); UnlockMutex(&lock_err_fun);}void (*_XipSetIOErrorHandler(handler))() void (*handler)();{ void (*oldhandler)(); LockMutex(&lock_err_fun); oldhandler = _XipIOErrorFunction; if (!oldhandler) { oldhandler = _XipDefaultIOError; } if (handler != NULL) { _XipIOErrorFunction = handler; } else { _XipIOErrorFunction = _XipDefaultIOError; } UnlockMutex(&lock_err_fun); return oldhandler;}static int_Writen(im, num) register XipIM im; register int num;{ register int i, ret; for (i = 0; i < num;) { ret = _Write(im->fd, &im->send_buf[i], num - i); if (ret <= 0) { im->fd = -1; _XipIOError(im); return(-1); } i += ret; } return(0);}int_XipFlushToIM(im) register XipIM im;{ if (im->sp == 0) return(0); if (_Writen(im, im->sp) < 0) return(-1); im->sp = 0; return(0);}int_XipWriteToIM(im, p, num) register XipIM im; register char *p; register int num;{ if (num <= 0) return(0); for(;;) { if ((im->sp + num) > SEND_BUF_SZ) { bcopy(p, &im->send_buf[im->sp], SEND_BUF_SZ - im->sp); if (_Writen(im, SEND_BUF_SZ) < 0) return(-1); num -= (SEND_BUF_SZ - im->sp); p += (SEND_BUF_SZ - im->sp); im->sp = 0; } else { bcopy(p, &im->send_buf[im->sp], num); im->sp +=num; return(0); } }}int_XipReadFromIM(im, p, num) register XipIM im; register char *p; register int num;{ register char *x = p; if (num <= 0) return(0); for(;;) { if (num > im->rc) { if (im->rc > 0) { bcopy(&im->recv_buf[im->rp], x, im->rc); x += im->rc; num -= im->rc; im->rc = 0; } im->rc = _Read(im->fd, im->recv_buf, RECV_BUF_SZ); if (im->rc <= 0) { im->rc = 0; im->rp = 0; im->fd = -1; _XipIOError(im); return(-1); } im->rp = 0; } else { bcopy(&im->recv_buf[im->rp], x, num); im->rc -= num; im->rp += num; return(0); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -