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

📄 ckutio.c

📁 C-Kermit源码。是使用串口/Modem和网络通讯的程序
💻 C
📖 第 1 页 / 共 5 页
字号:
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 */}SIGTYPxtimerh(foo) int foo; {			/* Like timerh() but does */#ifdef BEOSORBEBOX			/* not reset the 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 */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 */#ifndef NONAWSextern int tt_rows, tt_cols;#endif /* NONAWS */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 */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;#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;	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 */}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);}intsysinit() {    int x;    char * s;#ifdef CK_UTSNAME    struct utsname name;#endif /* CK_UTSNAME */    extern char startupdir[];/*  BEFORE ANYTHING ELSE: Initialize the setuid package.  Change to the user's real user and group ID.  If this can't be done, don't run at all.*/    debug(F100,"sysinit calling priv_ini","",0);    if (x = priv_ini()) {	if (x & 1) fprintf(stderr,"Fatal: setuid failure.\n");	if (x & 2) fprintf(stderr,"Fatal: setgid failure.\n");	if (x & 4) fprintf(stderr,"Fatal: C-Kermit setuid to root!\n");	exit(1);    }    signal(SIGINT,SIG_IGN);		/* Ignore interrupts at first */    signal(SIGHUP,sighup);		/* Catch SIGHUP */#ifndef NOJC/*  Get the initial job control state.  If it is SIG_IGN, that means the shell does not support job control,  and so we'd better not suspend ourselves.*/#ifdef SIGTSTP    jchdlr = signal(SIGTSTP,SIG_IGN);    if (jchdlr == SIG_IGN) {	jcshell = 0;	debug(F100,"sysinit jchdlr: SIG_IGN","",0);    } else if (jchdlr == SIG_DFL) {	debug(F100,"sysinit jchdlr: SIG_DFL","",0);	jcshell = 1;    } else {	debug(F100,"sysinit jchdlr: other","",0);	jcshell = 3;    }    (VOID) signal(SIGTSTP,jchdlr);	/* Put it back... */#endif /* SIGTSTP */#endif /* NOJC */    conbgt(0);				/* See if we're in the background */    congm();				/* Get console modes */    (VOID) signal(SIGALRM,SIG_IGN);	/* Ignore alarms */    ignorsigs();			/* Ignore some other signals */#ifdef F_SETFL    iniflags = fcntl(0,F_GETFL,0);	/* Get stdin flags */#endif /* F_SETFL */#ifdef ultrix    gtty(0,&vanilla);			/* Get sgtty info */#else#ifdef AUX    set42sig();				/* Don't ask! (hakanson@cs.orst.edu) */#endif /* AUX */#endif /* ultrix *//*  Warning: on some UNIX systems (SVR4?), ttyname() reportedly opens /dev but  never closes it.  If it is called often enough, we run out of file  descriptors and subsequent open()'s of other devices or files can fail.*/    s = NULL;#ifndef MINIX    if (isatty(0))			/* Name of controlling terminal */      s = ttyname(0);    else if (isatty(1))      s = ttyname(1);    else if (isatty(2))      s = ttyname(2);    debug(F110,"sysinit ttyname(0)",s,0);#endif /* MINIX */#ifdef BEOS    if (!dftty)      makestr(&dftty,s);#endif /* BEOS */    if (s)      ckstrncpy((char *)cttnam,s,DEVNAMLEN+1);#ifdef SVORPOSIX    if (!cttnam[0])      ctermid(cttnam);#endif /* SVORPOSIX */    if (!cttnam[0])      ckstrncpy((char *)cttnam,dftty,DEVNAMLEN+1);    debug(F110,"sysinit CTTNAM",CTTNAM,0);    debug(F110,"sysinit cttnam",cttnam,0);    ttgwsiz();				/* Get window (screen) dimensions. */#ifdef _SC_OPEN_MAX    ckmaxfiles = sysconf(_SC_OPEN_MAX);#endif /* _SC_OPEN_MAX */#ifdef Plan9    if (!backgrd) {    	consctlfd = open("/dev/consctl", O_WRONLY);    	/*noisefd = open("/dev/noise", O_WRONLY)*/    }    ckxech = 1;#endif /* Plan9 */#ifdef CK_UTSNAME    if (uname(&name) > -1) {	ckstrncpy(unm_mch,name.machine,CK_SYSNMLN);	ckstrncpy(unm_nam,name.sysname,CK_SYSNMLN);	ckstrncpy(unm_rel,name.release,CK_SYSNMLN);	ckstrncpy(unm_ver,name.version,CK_SYSNMLN);#ifdef DEBUG	if (deblog) {	    debug(F110,"sysinit uname machine",unm_mch,0);	    debug(F110,"sysinit uname sysname",unm_nam,0);	    debug(F110,"sysinit uname release",unm_rel,0);	    debug(F110,"sysinit uname version",unm_ver,0);	}#endif /* DEBUG */

⌨️ 快捷键说明

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