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

📄 ckuusx.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
}/*  B L D L E N  --  Make length-encoded copy of string  */char *bldlen(str,dest) char *str, *dest; {    int len;    len = (int)strlen(str);    if (len > 94)      *dest = SP;    else      *dest = (char) tochar(len);    strcpy(dest+1,str);    return(dest+len+1);}/*  S E T G E N  --  Construct a generic command  *//*  Call with Generic command character followed by three string arguments.    Trailing strings are allowed to be empty ("").  Each string except the last  non-empty string must be less than 95 characters long.  The final nonempty  string is allowed to be longer.*/CHAR#ifdef CK_ANSICsetgen(char type, char * arg1, char * arg2, char * arg3)#elsesetgen(type,arg1,arg2,arg3) char type, *arg1, *arg2, *arg3;#endif /* CK_ANSIC *//* setgen */ {    char *upstr, *cp;#ifdef DYNAMIC    if (!cmdstr)      if (!(cmdstr = malloc(MAXSP + 1)))	fatal("setgen: can't allocate memory");#endif /* DYNAMIC */    cp = cmdstr;    *cp++ = type;    *cp = NUL;    if (!arg1) arg1 = "";    if (!arg2) arg2 = "";    if (!arg3) arg3 = "";    if (*arg1 != NUL) {	upstr = bldlen(arg1,cp);	if (*arg2 != NUL) {	    upstr = bldlen(arg2,upstr);	    if (*arg3 != NUL) bldlen(arg3,upstr);	}    }    cmarg = cmdstr;    debug(F110,"setgen",cmarg,0);    return('g');}#ifndef NOMSENDstatic char *mgbufp = NULL;/*  F N P A R S E  --  *//*  Argument is a character string containing one or more filespecs.  This function breaks the string apart into an array of pointers, one  to each filespec, and returns the number of filespecs.  Used by server  when it receives a GET command to allow it to process multiple file  specifications in one transaction.  Sets cmlist to point to a list of  file pointers, exactly as if they were command line arguments.  This version of fnparse treats spaces as filename separators.  If your  operating system allows spaces in filenames, you'll need a different  separator.  This version of fnparse mallocs a string buffer to contain the names.  It  cannot assume that the string that is pointed to by the argument is safe.*/intfnparse(string) char *string; {    char *p, *s, *q;    int r = 0, x;			/* Return code */    if (mgbufp) free(mgbufp);		/* Free this from last time. */    mgbufp = malloc((int)strlen(string)+2);    if (!mgbufp) {	debug(F100,"fnparse malloc error","",0);	return(0);    }	#ifndef NOICP#ifndef NOSPL    strncpy(fspec,string,CKMAXPATH);	/* Make copy for \v(filespec) */#endif /* NOSPL */#endif /* NOICP */    s = string;				/* Input string */    p = q = mgbufp;			/* Point to the copy */    r = 0;				/* Initialize our return code */    while (*s == SP || *s == HT)	/* Skip leading spaces and tabs */      s++;    for (x = strlen(s);			/* Strip trailing spaces */	 (x > 1) && (s[x-1] == SP || s[x-1] == HT);	 x--)      s[x-1] = NUL;    while (1) {				/* Loop through rest of string */	if (*s == CMDQ) {		/* Backslash (quote character)? */	    if ((x = xxesc(&s)) > -1) {	/* Go interpret it. */		*q++ = (char) x;	/* Numeric backslash code, ok */	    } else {			/* Just let it quote next char */		s++;			/* get past the backslash */		*q++ = *s++;		/* deposit next char */	    }	    continue;	} else if (*s == SP || *s == NUL) { /* Unquoted space or NUL? */	    *q++ = NUL;			/* End of output filename. */	    msfiles[r] = p;		/* Add this filename to the list */	    debug(F111,"fnparse",msfiles[r],r);	    r++;			/* Count it */	    if (*s == NUL) break;	/* End of string? */	    while (*s == SP) s++;	/* Skip repeated spaces */	    p = q;			/* Start of next name */	    continue;	} else *q++ = *s;		/* Otherwise copy the character */	s++;				/* Next input character */    }    debug(F101,"fnparse r","",r);    msfiles[r] = "";			/* Put empty string at end of list */    cmlist = msfiles;    return(r);}#endif /* NOMSEND */char *					/* dbchr() for DEBUG SESSION */dbchr(c) int c; {    static char s[8];    char *cp = s;    c &= 0xff;    if (c & 0x80) {			/* 8th bit on */	*cp++ = '~';	c &= 0x7f;    }    if (c < SP) {			/* Control character */	*cp++ = '^';	*cp++ = (char) ctl(c);    } else if (c == DEL) {	*cp++ = '^';	*cp++ = '?';    } else {				/* Printing character */	*cp++ = (char) c;    }    *cp = '\0';				/* Terminate string */    cp = s;				/* Return pointer to it */    return(cp);}/*  C K H O S T  --  Get name of local host (where C-Kermit is running)  *//*  Call with pointer to buffer to put hostname in, and length of buffer.  Copies hostname into buffer on success, puts null string in buffer on  failure.*/#ifdef BSD44#define BSD4#undef ATTSV#endif /* BSD44 */#ifdef SVORPOSIX#ifndef BSD44#ifndef apollo#include <sys/utsname.h>#endif /* apollo */#endif /* BSD44 */#else#ifdef BELLV10#include <utsname.h>#endif /* BELLV10 */#endif /* SVORPOSIX*/VOIDckhost(vvbuf,vvlen) char * vvbuf; int vvlen; {#ifndef NOPUSH    extern int nopush;#ifndef NOSERVER    extern int en_hos;#endif /* NOSERVER */#endif /* NOPUSH */#ifdef pdp11    *vvbuf = NUL;#else  /* Everything else - rest of this routine */    char *g;#ifdef VMS    int x;#endif /* VMS */#ifdef SVORPOSIX#ifndef BSD44#ifndef _386BSD    struct utsname hname;#endif /* _386BSD */#endif /* BSD44 */#endif /* SVORPOSIX */#ifdef datageneral    int ac0 = (char *) vvbuf, ac1 = -1, ac2 = 0;#endif /* datageneral */#ifndef NOPUSH        if (getenv("CK_NOPUSH")) {		/* No shell access allowed */        nopush = 1;			/* on this host... */#ifndef NOSERVER        en_hos = 0;#endif /* NOSERVER */    }#endif /* NOPUSH */    *vvbuf = NUL;			/* How let's get our host name ... */#ifndef BELLV10				/* Does not have gethostname() */#ifndef OXOS#ifdef SVORPOSIX#ifdef BSD44    if (gethostname(vvbuf,vvlen) < 0)      *vvbuf = NUL;#else#ifdef _386BSD    if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;#else#ifdef QNX#ifdef TCPSOCKET    if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;#else    if (uname(&hname) > -1) strncpy(vvbuf,hname.nodename,vvlen);#endif /* TCPSOCKET */#else /* SVORPOSIX but not _386BSD or BSD44 */    if (uname(&hname) > -1) strncpy(vvbuf,hname.nodename,vvlen);#endif /* QNX */#endif /* _386BSD */#endif /* BSD44 */#else /* !SVORPOSIX */#ifdef BSD4    if (gethostname(vvbuf,vvlen) < 0) *vvbuf = NUL;#else /* !BSD4 */#ifdef VMS    g = getenv("SYS$NODE");    if (g) strncpy(vvbuf,g,vvlen);    x = (int)strlen(vvbuf);    if (x > 1 && vvbuf[x-1] == ':' && vvbuf[x-2] == ':') vvbuf[x-2] = NUL;#else#ifdef datageneral    if (sys($HNAME,&ac0,&ac1,&ac2) == 0) /* successful */        vvlen = ac2 + 1;		/* enh - have to add one */#else#ifdef OS2				/* OS/2 */    g = getenv("HOSTNAME");		/* (Created by TCP/IP install) */    if (!g) g = getenv("SYSTEMNAME");	/* (Created by PATHWORKS install?) */    if (g) strncpy(vvbuf,g,vvlen);#else /* OS2 */#ifdef OSK#ifdef TCPSOCKET	if (gethostname(vvbuf, vvlen) < 0) *vvbuf = NUL;#endif /* TCPSOCKET */#endif /* OSK */#endif /* OS2 */#endif /* datageneral */#endif /* VMS */#endif /* BSD4 */#endif /* SVORPOSIX */#else /* OXOS */    /* If TCP/IP is not installed, gethostname() fails, use uname() */    if (gethostname(vvbuf,vvlen) < 0) {	if (uname(&hname) > -1)	    strncpy(vvbuf,hname.nodename,vvlen);	else	    *vvbuf = NUL;    }#endif /* OXOS */#endif /* BELLV10 */    if (*vvbuf == NUL) {		/* If it's still empty */        g = getenv("HOST");		/* try this */        if (g) strncpy(vvbuf,g,vvlen);    }    vvbuf[vvlen-1] = NUL;		/* Make sure result is terminated. */#endif /* pdp11 */}#ifdef BSD44#undef BSD4#define ATTSV#endif /* BSD44 *//*  A S K M O R E  --  Poor person's "more".  Returns 0 if no more, 1 if more wanted.*/int xaskmore = 1;intaskmore() {    char c; int rv;    if (!xaskmore)      return(1);    rv = -1;    while (rv < 0) {#ifndef OS2	printf("more? ");#ifdef UNIX#ifdef NOSETBUF	fflush(stdout);#endif /* NOSETBUF */#endif /* UNIX */#else	printf("more? (Y or space-bar for yes, N for no) ");	fflush(stdout);#endif /* OS2 */	c = (char) coninc(0);	switch (c) {	  /* Yes */	  case SP: case 'y': case 'Y': case 012:  case 015:#ifdef OSK	    write(1, "\015      \015", sizeof "\015      \015" - 1);#else	    printf("\015      \015");#endif /* OSK */	    rv = 1;	    break;          /* No */	  case 'n': case 'N': case 'q': case 'Q':#ifdef OSK	    printf("\n");#else	    printf("\015\012");#endif /* OSK */	    rv = 0;	    break;	  /* Invalid answer */	  default:	    printf("Y or space-bar for yes, N for no\n");	    continue;	}#ifdef OS2	printf("\r                                         \r");	fflush(stdout);#endif /* OS2 */    }    return(rv);}/*  T R A P  --  Terminal interrupt handler */SIGTYP#ifdef CK_ANSICtrap(int sig)#else trap(sig) int sig;#endif /* CK_ANSIC *//* trap */ {    extern int b_save, f_save;#ifdef OS2    extern int cursor_ena[], cursor_save;    extern BYTE vmode;#endif /* OS2 */#ifndef NOSPL    extern int i_active, instatus;#endif /* NOSPL */#ifdef NTSIG    connoi();#endif /* NTSIG */#ifdef VMS    int i; FILE *f;#endif /* VMS */#ifdef __EMX__    signal(SIGINT, SIG_ACK);#endif#ifdef GEMDOS/* GEM is not reentrant, no i/o from interrupt level */    cklongjmp(cmjbuf,1);		/* Jump back to parser now! */#endif /* GEMDOS */    debug(F101,"^C trap() caught signal","",sig);#ifndef NOSPL    if (i_active) {			/* INPUT command was active? */	i_active = 0;			/* Not any more... */	instatus = INP_UI;		/* INPUT status = User Interrupted */    }#endif /* NOSPL */    binary = b_save;			/* Restore these */    fncnv  = f_save;    bye_active = 0;    zclose(ZIFILE);			/* If we were transferring a file, */    zclose(ZOFILE);			/* close it. */#ifndef NOICP    cmdsquo(cmd_quoting);		/* If command quoting was turned off */#endif /* NOICP */#ifdef CK_APC    apcactive = APC_INACTIVE;#endif /* CK_APC */#ifdef VMS/*  Fix terminal.*/    if (ft_win) {			/* If curses window open */	debug(F100,"^C trap() curses","",0);	screen(SCR_CW,0,0L,"");		/* Close it */	conres();			/* Restore terminal */	i = printf("^C...");		/* Echo ^C to standard output */    } else {	conres();	i = printf("^C...\n");		/* Echo ^C to standard output */    }    if (i < 1 && ferror(stdout)) {	/* If there was an error */	debug(F100,"^C trap() error","",0);		fclose(stdout);			/* close standard output */	f = fopen(dftty, "w");		/* open the controlling terminal */	if (f) stdout = f;		/* and make it standard output */	printf("^C...\n");		/* and echo the ^C again. */    }#else					/* Not VMS */#ifdef STRATUS    conres();				/* Set console back to normal mode */#endif /* STRATUS */    if (ft_win) {			/* If curses window open, */	debug(F100,"^C trap() curses","",0);	screen(SCR_CW,0,0L,"");		/* close it. */	printf("^C...");		/* Echo ^C to standard output */    } else {	printf("^C...\n");    }#endif /* VMS */#ifdef datageneral    connoi_mt(); 			/* Kill asynch task that listens to */    ttimoff();    conres();				/* the keyboard */#endif /* datageneral */#ifndef NOCCTRAP/*  This is stupid -- every version should have ttimoff()...  */#ifdef UNIX    ttimoff();				/* Turn off any timer interrupts */#else#ifdef OSK    ttimoff();				/* Turn off any timer interrupts */#else#ifdef STRATUS    ttimoff();				/* Turn off any timer interrupts */#else#ifdef OS2#ifdef TCPSOCKET#ifdef NT    /* WSAIsBlocking() returns FALSE in Win95 during a blocking accept call */    if ( WSASafeToCancel /* && WSAIsBlocking() */ ) {	WSACancelBlockingCall();    }#endif /* NT */#endif /* TCPSOCKET */#ifdef CK_NETBIOS     if (netbiosAvail) {       int i;       NCB CancelNCB;       /* Cancel all outstanding Netbios Send or Work requests */       for ( i = 0 ; i < MAXWS ; i++) {	   if (pSendNCB[i]->basic_ncb.bncb.ncb_retcode ==	       NB_COMMAND_IN_PROCESS ) {	       NCBCancel( NetbeuiAPI,			 &CancelNCB,			 NetBiosAdapter,			 pSendNCB[i] ) ;	       Dos16SemWait( pSendNCB[i]->basic_ncb.ncb_semaphore,			    SEM_INDEFINITE_WAIT);	   }       }       if ( pWorkNCB->basic_ncb.bncb.ncb_retcode == NB_COMMAND_IN_PROCESS ) {	   NCBCancel( NetbeuiAPI, &CancelNCB, NetBiosAdapter, pWorkNCB ) ;	   Dos16SemWait( pWorkNCB->basic_ncb.ncb_semaphore,                        SEM_INDEFINITE_WAIT ) ;       }   }#endif /* CK_NETBIOS */    ttimoff();				/* Turn off any timer interrupts */#else#ifdef VMS    ttimoff();				/* Turn off any timer interrupts */#endif /* VMS */#endif /* OS2 */#endif /* STRATUS */#endif /* OSK */#endif /* UNIX */#ifdef OSK    sigmask(-1);/*  We are in an intercept routine but do not perform a F$RTE (done implicitly  but rts).  We have to decrement the sigmask as F$RTE does.  Warning:  longjump only restores the cpu registers, NOT the fpu registers.  So don't  use fpu at all or at least don't use common fpu (double or float) register

⌨️ 快捷键说明

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