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

📄 xtranslcl.c

📁 手写识别Chinput3.0.2源代码,可以在linux下开发手写板程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	return(-1);    }        /*     * Everything looks good: fill in the XtransConnInfo structure.     */        newciptr->addrlen=ciptr->addrlen;    if( (newciptr->addr=(char *)xalloc(newciptr->addrlen)) == NULL ) {	PRMSG(1,	      "SCOAccept: failed to allocate memory for peer addr\n",	      0,0,0);	close(fd);	*status = TRANS_ACCEPT_BAD_MALLOC;	return -1;    }        memcpy(newciptr->addr,ciptr->addr,newciptr->addrlen);        newciptr->peeraddrlen=newciptr->addrlen;    if( (newciptr->peeraddr=(char *)xalloc(newciptr->peeraddrlen)) == NULL ) {	PRMSG(1,	      "SCOAccept: failed to allocate memory for peer addr\n",	      0,0,0);	xfree(newciptr->addr);	close(fd);	*status = TRANS_ACCEPT_BAD_MALLOC;	return -1;    }        memcpy(newciptr->peeraddr,newciptr->addr,newciptr->peeraddrlen);        *status = 0;    return(fd);}#endif /* TRANS_SERVER */#ifdef TRANS_REOPENstatic intTRANS(PTSReopenServer)(ciptr, fd, port)XtransConnInfo	ciptr;int		fd;char		*port;{    char server_path[64];    PRMSG(2,"PTSReopenServer(%d,%s)\n", fd, port, 0 );#if !defined(PTSNODENAME)    PRMSG(1,"PTSReopenServer: Protocol is not supported by a pts connection\n", 0,0,0);    return 0;#else    if (port && *port ) {	if( *port == '/' ) { /* A full pathname */		(void) sprintf(server_path, "%s", port);	    } else {		(void) sprintf(server_path, "%s%s", PTSNODENAME, port);	    }    } else {	(void) sprintf(server_path, "%s%d", PTSNODENAME, getpid());    }    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)    {	PRMSG(1,"PTSReopenServer: failed to fill in addr info\n",								0,0,0);	return 0;    }    return 1;#endif /* !PTSNODENAME */}static intTRANS(NAMEDReopenServer)(ciptr, fd, port)XtransConnInfo	ciptr;int		fd;char		*port;{    char server_path[64];    PRMSG(2,"NAMEDReopenServer(%s)\n", port, 0,0 );#if !defined(NAMEDNODENAME)    PRMSG(1,"NAMEDReopenServer: Protocol is not supported by a NAMED connection\n", 0,0,0);    return 0;#else    if ( port && *port ) {	if( *port == '/' ) { /* A full pathname */	    (void) sprintf(server_path, "%s", port);	} else {	    (void) sprintf(server_path, "%s%s", NAMEDNODENAME, port);	}    } else {	(void) sprintf(server_path, "%s%d", NAMEDNODENAME, getpid());    }    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)    {	PRMSG(1,"NAMEDReopenServer: failed to fill in addr info\n",								0,0,0);	return 0;    }    return 1;#endif /* !NAMEDNODENAME */}static intTRANS(ISCReopenServer)(ciptr, fd, port)XtransConnInfo	ciptr;int		fd;char		*port;{    char server_path[64],server_unix_path[64];        PRMSG(2,"ISCReopenServer(%s)\n", port, 0,0 );    #if !defined(ISCDEVNODENAME)    PRMSG(1,"ISCReopenServer: Protocol is not supported by a ISC connection\n", 0,0,0);    return 0;#else    (void) sprintf(server_path, ISCDEVNODENAME, port);    (void) sprintf(server_unix_path, ISCTMPNODENAME, port);    if (TRANS(FillAddrInfo) (ciptr, server_path, server_path) == 0)    {	PRMSG(1,"ISCReopenServer: failed to fill in addr info\n",								0,0,0);	return 0;    }        return 1;#endif /* !ISCDEVNODENAME */}static intTRANS(SCOReopenServer)(ciptr, fd, port)XtransConnInfo	ciptr;int		fd;char		*port;{    char		serverR_path[64];    char		serverS_path[64];        PRMSG(2,"SCOReopenServer(%s)\n", port, 0,0 );    #if !defined(SCORNODENAME)    PRMSG(1,"SCOReopenServer: Protocol is not supported by a SCO connection\n", 0,0,0);    return 0;#else    (void) sprintf(serverR_path, SCORNODENAME, port);    (void) sprintf(serverS_path, SCOSNODENAME, port);        if (TRANS(FillAddrInfo) (ciptr, serverS_path, serverR_path) == 0)    {	PRMSG(1,"SCOReopenServer: failed to fill in addr info\n",	      0,0,0);	return 0;    }        return 1;#endif /* SCORNODENAME */}#endif /* TRANS_REOPEN *//* * This table contains all of the entry points for the different local * connection mechanisms. */typedef struct _LOCALtrans2dev {    char	*transname;#ifdef TRANS_CLIENT    int	(*devcotsopenclient)(#if NeedFunctionPrototypes	XtransConnInfo, char * /*port*/#endif);#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER    int	(*devcotsopenserver)(#if NeedFunctionPrototypes	XtransConnInfo, char * /*port*/#endif);#endif /* TRANS_SERVER */#ifdef TRANS_CLIENT    int	(*devcltsopenclient)(#if NeedFunctionPrototypes	XtransConnInfo, char * /*port*/#endif);#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER    int	(*devcltsopenserver)(#if NeedFunctionPrototypes	XtransConnInfo, char * /*port*/#endif);#endif /* TRANS_SERVER */#ifdef TRANS_REOPEN    int	(*devcotsreopenserver)(#if NeedFunctionPrototypes	XtransConnInfo,	int, 	/* fd */	char * 	/* port */#endif);    int	(*devcltsreopenserver)(#if NeedFunctionPrototypes	XtransConnInfo,	int, 	/* fd */	char *	/* port */#endif);#endif /* TRANS_REOPEN */#ifdef TRANS_SERVER    int	(*devaccept)(#if NeedFunctionPrototypes	XtransConnInfo, XtransConnInfo, int *#endif);#endif /* TRANS_SERVER */} LOCALtrans2dev;static LOCALtrans2dev LOCALtrans2devtab[] = {{"",#ifdef TRANS_CLIENT     TRANS(PTSOpenClient),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(PTSOpenServer),#endif /* TRANS_SERVER */#ifdef TRANS_CLIENT     TRANS(OpenFail),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(OpenFail),#endif /* TRANS_SERVER */#ifdef TRANS_REOPEN     TRANS(PTSReopenServer),     TRANS(ReopenFail),#endif#ifdef TRANS_SERVER     TRANS(PTSAccept)#endif /* TRANS_SERVER */},{"local",#ifdef TRANS_CLIENT     TRANS(PTSOpenClient),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(PTSOpenServer),#endif /* TRANS_SERVER */#ifdef TRANS_CLIENT     TRANS(OpenFail),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(OpenFail),#endif /* TRANS_SERVER */#ifdef TRANS_REOPEN     TRANS(PTSReopenServer),     TRANS(ReopenFail),#endif#ifdef TRANS_SERVER     TRANS(PTSAccept)#endif /* TRANS_SERVER */},{"pts",#ifdef TRANS_CLIENT     TRANS(PTSOpenClient),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(PTSOpenServer),#endif /* TRANS_SERVER */#ifdef TRANS_CLIENT     TRANS(OpenFail),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(OpenFail),#endif /* TRANS_SERVER */#ifdef TRANS_REOPEN     TRANS(PTSReopenServer),     TRANS(ReopenFail),#endif#ifdef TRANS_SERVER     TRANS(PTSAccept)#endif /* TRANS_SERVER */},#ifdef SVR4{"named",#ifdef TRANS_CLIENT     TRANS(NAMEDOpenClient),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(NAMEDOpenServer),#endif /* TRANS_SERVER */#ifdef TRANS_CLIENT     TRANS(OpenFail),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(OpenFail),#endif /* TRANS_SERVER */#ifdef TRANS_REOPEN     TRANS(NAMEDReopenServer),     TRANS(ReopenFail),#endif#ifdef TRANS_SERVER     TRANS(NAMEDAccept)#endif /* TRANS_SERVER */},#endif /* SVR4 */{"isc",#ifdef TRANS_CLIENT     TRANS(ISCOpenClient),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(ISCOpenServer),#endif /* TRANS_SERVER */#ifdef TRANS_CLIENT     TRANS(OpenFail),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(OpenFail),#endif /* TRANS_SERVER */#ifdef TRANS_REOPEN     TRANS(ISCReopenServer),     TRANS(ReopenFail),#endif#ifdef TRANS_SERVER     TRANS(ISCAccept)#endif /* TRANS_SERVER */},{"sco",#ifdef TRANS_CLIENT     TRANS(SCOOpenClient),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(SCOOpenServer),#endif /* TRANS_SERVER */#ifdef TRANS_CLIENT     TRANS(OpenFail),#endif /* TRANS_CLIENT */#ifdef TRANS_SERVER     TRANS(OpenFail),#endif /* TRANS_SERVER */#ifdef TRANS_REOPEN     TRANS(SCOReopenServer),     TRANS(ReopenFail),#endif#ifdef TRANS_SERVER     TRANS(SCOAccept)#endif /* TRANS_SERVER */},};#define NUMTRANSPORTS	(sizeof(LOCALtrans2devtab)/sizeof(LOCALtrans2dev))    static	char	*XLOCAL=NULL;static	char	*workingXLOCAL=NULL;static	char	*freeXLOCAL=NULL;static voidTRANS(LocalInitTransports)(protocol)char *protocol;{    PRMSG(3,"LocalInitTransports(%s)\n", protocol, 0,0 );        if( strcmp(protocol,"local") && strcmp(protocol,"LOCAL") )    {	workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (protocol) + 1);	if (workingXLOCAL)	    strcpy (workingXLOCAL, protocol);    }    else {	XLOCAL=(char *)getenv("XLOCAL");	if(XLOCAL==NULL)	    XLOCAL="UNIX:PTS:NAMED:ISC:SCO";	workingXLOCAL=freeXLOCAL=(char *)xalloc (strlen (XLOCAL) + 1);	if (workingXLOCAL)	    strcpy (workingXLOCAL, XLOCAL);    }}static voidTRANS(LocalEndTransports)(){    PRMSG(3,"LocalEndTransports()\n", 0,0,0 );    xfree(freeXLOCAL);}static LOCALtrans2dev *TRANS(LocalGetNextTransport)(){    int	i,j;    char	*typetocheck;#define TYPEBUFSIZE	32    char	typebuf[TYPEBUFSIZE];    PRMSG(3,"LocalGetNextTransport()\n", 0,0,0 );        while(1)    {	if( workingXLOCAL == NULL || *workingXLOCAL == '\0' )	    return NULL;		typetocheck=workingXLOCAL;	workingXLOCAL=strchr(workingXLOCAL,':');	if(workingXLOCAL && *workingXLOCAL)	    *workingXLOCAL++='\0';		for(i=0;i<NUMTRANSPORTS;i++)	{	    /*	     * This is equivilent to a case insensitive strcmp(),	     * but should be more portable.	     */	    strncpy(typebuf,typetocheck,TYPEBUFSIZE);	    for(j=0;j<TYPEBUFSIZE;j++)		if (isupper(typebuf[j]))		    typebuf[j]=tolower(typebuf[j]);	    	    /* Now, see if they match */	    if(!strcmp(LOCALtrans2devtab[i].transname,typebuf))		return &LOCALtrans2devtab[i];	}    }    /*NOTREACHED*/    return NULL;}#ifdef TRANS_CLIENT#ifdef NEED_UTSNAME#include <sys/utsname.h>#endif/* * Make sure 'host' is really local. */static intHostReallyLocal (host)char *host;{    /*     * The 'host' passed to this function may have been generated     * by either uname() or gethostname().  We try both if possible.     */#ifdef NEED_UTSNAME    struct utsname name;#endif    char buf[256];#ifdef NEED_UTSNAME    if (uname (&name) >= 0 && strcmp (host, name.nodename) == 0)	return (1);#endif    buf[0] = '\0';    (void) gethostname (buf, 256);    buf[255] = '\0';    if (strcmp (host, buf) == 0)	return (1);    return (0);}static XtransConnInfoTRANS(LocalOpenClient)(type, protocol, host, port)int  type;char *protocol;char *host;char *port;{    int	fd = -1;    LOCALtrans2dev *transptr;    XtransConnInfo ciptr;    int index;    PRMSG(3,"LocalOpenClient()\n", 0,0,0 );        /*     * Make sure 'host' is really local.  If not, we return failure.     * The reason we make this check is because a process may advertise     * a "local" address for which it can accept connections, but if a     * process on a remote machine tries to connect to this address,     * we know for sure it will fail.     */    if (strcmp (host, "unix") != 0 && !HostReallyLocal (host))    {	PRMSG (1,	   "LocalOpenClient: Cannot connect to non-local host %s\n",	       host, 0, 0);	return NULL;    }#if defined(X11_t)    /*     * X has a well known port, that is transport dependant. It is easier     * to handle it here, than try and come up with a transport independent     * representation that can be passed in and resolved the usual way.     *     * The port that is passed here is really a string containing the idisplay     * from ConnectDisplay(). Since that is what we want for the local transports,     * we don't have to do anything special.     */#endif /* X11_t */        if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )    {	PRMSG(1,"LocalOpenClient: calloc(1,%d) failed\n",	      sizeof(struct _XtransConnInfo),0,0 );	return NULL;    }        ciptr->fd = -1;        TRANS(LocalInitTransports)(protocol);        index = 0;    for(transptr=TRANS(LocalGetNextTransport)();	transptr!=NULL;transptr=TRANS(LocalGetNextTransport)(), index++)    {	switch( type )	{	case XTRANS_OPEN_COTS_CLIENT:	    ciptr->fd=transptr->devcotsopenclient(ciptr,port);	    break;	case XTRANS_OPEN_CLTS_CLIENT:	    ciptr->fd=transptr->devcltsopenclient(ciptr,port);	    break;	case XTRANS_OPEN_COTS_SERVER:	case XTRANS_OPEN_CLTS_SERVER:	    PRMSG(1,		  "LocalOpenClient: Should not be opening a server with this function\n",		  0,0,0);	    break;	default:	    PRMSG(1,		  "LocalOpenClient: Unknown Open type %d\n",		  type, 0,0 );	}	if( ciptr->fd >= 0 )	    break;    }        TRANS(LocalEndTransports)();        if( ciptr->fd < 0 )    {	xfree(ciptr);	return NULL;    }        ciptr->priv=(char *)transptr;    ciptr->index = index;        return ciptr;}#endif /* TRANS_CLIENT */#ifdef TRANS_SERVERstatic XtransConnInfoTRANS(LocalOpenServer)(type, protocol, host, port)int  type;char *protocol;char *host;char *port;{    int	i,fd = -1;    XtransConnInfo ciptr;        PRMSG(2,"LocalOpenServer(%d,%s,%s)\n", type, protocol, port);    #if defined(X11_t)    /*     * For X11, the port will be in the format xserverN where N is the     * display number. All of the local connections just need to know     * the display number because they don't do any name resolution on     * the port. This just truncates port to the display portion.     */#endif /* X11_t */        if( (ciptr=(XtransConnInfo)xcalloc(1,sizeof(struct _XtransConnInfo))) == NULL )    {	PRMSG(1,"LocalOpenServer: calloc(1,%d) failed\n",	      sizeof(struct _XtransConnInfo),0,0 );	return NULL;    }        for(i=1;i<NUMTRANSPORTS;i++)    {	if( strcmp(protocol,LOCALtrans2devtab[i].transname) != 0 )	    continue;	switch( type )	{	case XTRANS_OPEN_COTS_CLIENT:	case XTRANS_OPEN_CLTS_CLIENT:	    PRMSG(1,		  "LocalOpenServer: Should not be opening a client with this function\n",

⌨️ 快捷键说明

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