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

📄 ckutio.c

📁 KERMIT工具 这在办公室下载不了,很多人都没有载不到.
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif /* SELECT */#include <kernel/OS.h>/* #ifdef BE_DR_7 */static double time_started = 0.0;struct ALARM_STRUCT {    thread_id thread;    int time;};static thread_id alarm_thread = -1;static struct ALARM_STRUCT alarm_struct;_PROTOTYP( long do_alarm, (void *) );_PROTOTYP( unsigned int alarm, (unsigned int) );_PROTOTYP( void alarm_expired, (void) );/* #endif */ /* BE_DR_7 */#endif /* BEOSORBEBOX */#ifndef xunchar#define xunchar(ch) (((ch) - 32 ) & 0xFF )	/* Character to number */#endif /* xunchar */#ifdef CK_ANSICstatic char *xxlast(char *s, char c)#elsestatic char *xxlast(s,c) char *s; char c;#endif /* CK_ANSIC *//* xxlast */ {		/*  Last occurrence of character c in string s. */    int i;    for (i = (int)strlen(s); i > 0; i--)      if (s[i-1] == c ) return(s + (i - 1));    return(NULL);}/* Timeout handler for communication line input functions *//*ARGSUSED*/SIGTYPtimerh(foo) int foo; {    ttimoff();#ifdef BEOSORBEBOX/* #ifdef BE_DR_7 */    alarm_expired();/* #endif */ /* BE_DR_7 */#endif /* BEOSORBEBOX */#ifdef CK_POSIX_SIG    siglongjmp(sjbuf,1);#else    longjmp(sjbuf,1);#endif /* CK_POSIX_SIG */}/*ARGSUSED*/SIGTYPxtimerh(foo) int foo; {			/* Like timerh() but does */#ifdef BEOSORBEBOX			/* not reset the timer itslef *//* #ifdef BE_DR_7 */    alarm_expired();/* #endif */ /* BE_DR_7 */#endif /* BEOSORBEBOX */#ifdef CK_POSIX_SIG    siglongjmp(sjbuf,1);#else    longjmp(sjbuf,1);#endif /* CK_POSIX_SIG */}/* Control-C trap for communication line input functions */int cc_int;				/* Flag */SIGTYP (* occt)();			/* For saving old SIGINT handler *//*ARGSUSED*/SIGTYPcctrap(foo) int foo; {			/* Needs arg for ANSI C */  cc_int = 1;				/* signal() prototype. */  return;}/*  S Y S I N I T  --  System-dependent program initialization.  *//* * ttgwsiz() returns: *	1    tt_rows and tt_cols are known, both altered, both > 0 *	0    tt_rows and/or tt_cols are known, both altered, one or both <= 0 *	-1   tt_rows and tt_cols are unknown and unaltered */extern int tt_rows, tt_cols;static intxttgwsiz() {    char *p;    int rows = 0, cols = 0;    p = getenv("LINES");    debug(F110,"xttgwsiz LINES",p,0);    if (p) {	rows = atol(p);	if (rows > 0) {	    p = getenv("COLUMNS");	    debug(F110,"xttgwsiz COLUMNS",p,0);	    if (p) {		cols = atol(p);		if (cols > 0) {		    tt_rows = rows;		    tt_cols = cols;		    return(1);		}		return(0);	    }	}    }    return(-1);}#ifdef TTLEBUFVOIDle_init() {				/* LocalEchoInit() */    int i;    for (i = 0; i < LEBUFSIZ; i++)      le_buf[i] = '\0';    le_start = 0;    le_end = 0;    le_data = 0;}VOIDle_clean() {				/* LocalEchoCleanup() */    le_init();    return;}intle_inbuf() {    int rc = 0;    if (le_start != le_end) {	rc = (le_end -	      le_start +	      LEBUFSIZ) % LEBUFSIZ;    }    debug(F111,"le_inbuf","chars waiting",rc);    return(rc);}int#ifdef CK_ANSICle_putchar(CHAR ch)#elsele_putchar(ch) CHAR ch;#endif /* CK_ANSIC *//* le_putchar */ {#ifdef COMMENT    /* In UNIX we do not have another thread taking chars out of the buffer */    while ((le_start - le_end == 1) ||            (le_start == 0 && le_end == LEBUFSIZ - 1)) {	/* Buffer is full */        debug(F111,"le_putchar","Buffer is Full",ch);        ReleaseLocalEchoMutex() ;        msleep(250);        RequestLocalEchoMutex( SEM_INDEFINITE_WAIT ) ;    }#else    if ((le_start - le_end + LEBUFSIZ)%LEBUFSIZ == 1) {        debug(F110,"le_putchar","buffer is full",0);        return(-1);    }#endif /* COMMENT */    le_buf[le_end++] = ch;    if (le_end == LEBUFSIZ)      le_end = 0;    le_data = 1;    return(0);}int#ifdef CK_ANSICle_puts(CHAR * s, int n)#elsele_puts(s,n) CHAR * s; int n;#endif /* CK_ANSIC *//* le_puts */ {    int rc = 0;    int i = 0;    CHAR * p = (CHAR *)"le_puts";    hexdump(p,s,n);    for (i = 0; i < n; i++)      rc = le_putchar((char)s[i]);    debug(F101,"le_puts","",rc);    return(rc);}int#ifdef CK_ANSICle_putstr(CHAR * s)#elsele_putstr(s) CHAR * s;#endif /* CK_ANSIC *//* le_puts */ {    CHAR * p;    int rc = 0;    p = (CHAR *)"le_putstr";    hexdump(p,s,(int)strlen((char *)s));    for (p = s; *p && !rc; p++)      rc = le_putchar(*p);    return(rc);}int#ifdef CK_ANSICle_getchar(CHAR * pch)#else /* CK_ANSIC */le_getchar(pch) CHAR * pch;#endif /* CK_ANSIC *//* le_gatchar */ {    int rc = 0;    if (le_start != le_end) {        *pch = le_buf[le_start];        le_buf[le_start] = 0;        le_start++;        if (le_start == LEBUFSIZ)          le_start = 0;        if (le_start == le_end) {            le_data = 0;        }        rc++;    } else {        *pch = 0;    }    return(rc);}#endif /* TTLEBUF */#ifdef COMMENT/*  Some systems like OSF/1 use TIOCGSIZE instead of TIOCGWINSZ.  But as far as I know, whenever TIOCGSIZE is defined, it is  equated to TIOCGWINSZ.  For cases where this is not done, try this:*/#ifndef TIOCGWINSZ#ifdef TIOCGSIZE#define TIOCGWINSZ TIOCGSIZE#endif /* TIOCGSIZE */#endif /* TIOCGWINSZ */#endif /* COMMENT */static int tt_xpixel = 0, tt_ypixel = 0;intttgwsiz() {    int x = 0;#ifndef NONAWS#ifdef QNX/*  NOTE: TIOCGWSIZ works here too, but only in the 32-bit version.  This code works for both the 16- and 32-bit versions.*/    extern int dev_size(int, int, int, int *, int *);    int r, c;    if (dev_size(0, -1, -1, &r, &c) == 0) {	debug(F101,"ttgwsiz QNX r","",r);	debug(F101,"ttgwsiz QNX c","",c);	tt_rows = r;	tt_cols = c;	return ((r > 0 && c > 0) ? 1 : 0);    } else return(xttgwsiz());#else /* QNX */#ifdef TIOCGWINSZ/* Note, this was M_UNIX, changed to XENIX to allow cross compilation... */#ifdef XENIX				/* SCO UNIX 3.2v4.0 */#include <sys/stream.h>			/* typedef mblk_t needed by ptem.h */#include <sys/ptem.h>			/* for ttgwsiz() */#endif /* XENIX */#ifdef I386IX				/* Ditto for Interactive */#include <sys/stream.h>#include <sys/ptem.h>#endif /* I386IX *//* Note, the above might be needed for some other older SVR3 Intel makes... */    struct winsize w;    tt_xpixel = 0;    tt_ypixel = 0;#ifdef IKSD    if (inserver)      return(xttgwsiz());#endif /* IKSD */    x = ioctl(0, (int)TIOCGWINSZ, (char *)&w);    debug(F101,"ttgwsiz TIOCGWINSZ","",x);    if (x < 0) {	return(xttgwsiz());    } else if (w.ws_row > 0 && w.ws_col > 0) {	tt_rows = w.ws_row;	tt_cols = w.ws_col;	tt_xpixel = w.ws_xpixel;	tt_ypixel = w.ws_ypixel;	debug(F101,"ttgwsiz tt_rows","",tt_rows);	debug(F101,"ttgwsiz tt_cols","",tt_cols);	return(1);    } else {	debug(F100,"ttgwsiz TIOCGWINSZ 00","",0);	return(xttgwsiz());    }#else    return(xttgwsiz());#endif /* TIOCGWINSZ */#endif /* QNX */#endif /* NONAWS */}#ifndef NOSIGWINCH#ifdef SIGWINCHSIGTYPwinchh(foo) int foo; {			/* SIGWINCH handler */    int x = 0;#ifdef NETPTY    extern int pty_fork_pid;#endif /* NETPTY */#ifdef CK_TTYFD#ifndef VMS    extern int ttyfd;#endif /* VMS */#endif /* CK_TTYFD */    extern int tt_rows, tt_cols, cmd_rows, cmd_cols;#ifdef DEBUG    if (deblog) {	debug(F100,"***************","",0);	debug(F100,"SIGWINCH caught","",0);	debug(F100,"***************","",0);#ifdef NETPTY	debug(F101,"SIGWINCH pty_fork_pid","",pty_fork_pid);#endif /* NETPTY */    }#endif /* DEUB */    signal(SIGWINCH,winchh);            /* Re-arm the signal */    x = ttgwsiz();                      /* Get new window size */    cmd_rows = tt_rows;			/* Adjust command screen too */    cmd_cols = tt_cols;#ifdef CK_TTYFD    if					/* If we don't have a connection */#ifdef VMS				/* we're done. */      (vmsttyfd() == -1)#else      (ttyfd == -1)#endif /* VMS */#else      (!local)#endif /* CK_TTYFD */        return;#ifdef NETPTY    if (pty_fork_pid > -1) {		/* "set host" to a PTY? */	int x;#ifdef TIOCSWINSZ	struct winsize w;		/* Resize the PTY */	errno = 0;	w.ws_col = tt_cols;	w.ws_row = tt_rows;	w.ws_xpixel = tt_xpixel;	w.ws_ypixel = tt_ypixel;	x = ioctl(ttyfd,TIOCSWINSZ,&w);	debug(F101,"winchh TIOCSWINSZ","",x);	debug(F101,"winchh TIOCSWINSZ errno","",errno);#endif /* TIOCSWINSZ */	errno = 0;	x = kill(pty_fork_pid,SIGWINCH);	debug(F101,"winchh kill","",x);	debug(F101,"winchh kill errno","",errno);    }#endif /* NETPTY *//*  This should be OK.  It might seem that sending this from  interrupt level could interfere with another TELNET IAC string  that was in the process of being sent.  But we always send  TELNET strings with a single write(), which should prevent mixups.  blah_snaws() should protect themselves from being called on the  wrong kind of connection.*/#ifdef TCPSOCKET#ifndef NOTTGWSIZ    if (x > 0 && tt_rows > 0 && tt_cols > 0) {        tn_snaws();#ifdef RLOGCODE        rlog_naws();#endif /* RLOGCODE */    }#endif /* NOTTGWSIZ */#endif /* TCPSOCKET */    SIGRETURN;}#endif /* SIGWINCH */#endif /* NOSIGWINCH */SIGTYPsighup(foo) int foo; {			/* SIGHUP handler */    backgrd = 1;    debug(F100,"***************","",0);    debug(F100,"SIGHUP received","",0);    debug(F100,"***************","",0);    doexit(BAD_EXIT,-1);    /*NOTREACHED*/    SIGRETURN;				/* Shut picky compilers up... */}#ifdef CK_SCO32V4/* Exists but there is no prototype in the header files */_PROTOTYP( char * ttyname, (int) );#else#ifdef SV68R3V6_PROTOTYP( char * ttyname, (int) );#else#ifdef ultrix_PROTOTYP( char * ttyname, (int) );#else#ifdef HPUX6_PROTOTYP( char * ttyname, (int) );#else#ifdef HPUX5_PROTOTYP( char * ttyname, (int) );#else#ifdef PS2AIX10_PROTOTYP( char * ttyname, (int) );#else#ifdef BSD42_PROTOTYP( char * ttyname, (int) );#endif /* BSD42 */#endif /* PS2AIX10 */#endif /* HPUX5 */#endif /* HPUX6 */#endif /* ultrix */#endif /* SV68R3V6 */#endif /* CK_SCO32V4 */#ifndef SIGUSR1				/* User-defined signals */#define SIGUSR1 30#endif /* SIGUSR1 */#ifndef SIGUSR2#define SIGUSR2 31#endif /* SIGUSR2 *//*  ignorsigs() sets certain signals to SIG_IGN.  But when a signal is  ignored, it remains ignored across exec(), so we have to restore these  signals before exec(), which is the purpose of restorsigs().*/static VOIDignorsigs() {				/* Ignore these signals */    savquit = signal(SIGQUIT,SIG_IGN);	/* Ignore Quit signal */#ifdef SIGDANGER			/* Ignore danger signals *//*  This signal is sent when the system is low on swap space.  Processes  that don't handle it are candidates for termination.  If swap space doesn't  clear out enough, we still might be terminated via kill() -- nothing we can  do about that!  Conceivably, this could be improved by installing a real  signal handler that warns the user, but that would be pretty complicated,  since we are not always in control of the screen -- e.g. during remote-mode  file transfer.*/    savdanger = signal(SIGDANGER,SIG_IGN); /* e.g. in AIX */#endif /* SIGDANGER */#ifdef SIGPIPE/*  This one comes when a TCP/IP connection is broken by the remote.  We prefer to catch this situation by examining error codes from write().*/    savpipe = signal(SIGPIPE,SIG_IGN);#endif /* SIGPIPE */    savusr1 = signal(SIGUSR1,SIG_IGN);	/* Ignore user-defined signals */    savusr2 = signal(SIGUSR2,SIG_IGN);}VOIDrestorsigs() {				/* Restore these signals */    (VOID) signal(SIGQUIT,savquit);	/* (used in ckufio.c) */#ifdef SIGDANGER    (VOID) signal(SIGDANGER,savdanger);#endif /* SIGDANGER */#ifdef SIGPIPE    (VOID) signal(SIGPIPE,savpipe);#endif /* SIGPIPE */    (VOID) signal(SIGUSR1,savusr1);    (VOID) signal(SIGUSR2,savusr2);}int

⌨️ 快捷键说明

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