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

📄 ckuusr.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
#define CLR_C_BOS 2#define CLR_C_EOL 3#define CLR_C_EOS 4#define CLR_C_LIN 5#define CLR_C_SCR 6struct keytab clrcmdtab[] = {    /* CLEAR COMMMAND-SCREEN options */    "all",     CLR_C_ALL, 0,    "bol",     CLR_C_BOL, 0,    "bos",     CLR_C_BOS, 0,    "eol",     CLR_C_EOL, 0,    "eos",     CLR_C_EOS, 0,    "line",    CLR_C_LIN, 0,    "scrollback", CLR_C_SCR, 0};int nclrcmd = sizeof(clrcmdtab)/sizeof(struct keytab);#endif /* OS2 */#endif /* NOSPL */#ifndef NODIALstatic struct keytab looktab[] = {    "dial", 0, 0};#endif /* NODIAL *//* Forward declarations of functions */_PROTOTYP (int doask,   ( int  ) );_PROTOTYP (int dodef,   ( int  ) );_PROTOTYP (int dodel,   ( void ) );_PROTOTYP (int dodial,  ( int  ) );_PROTOTYP (int dodir,   ( void ) );_PROTOTYP (int doelse,  ( void ) );_PROTOTYP (int dofor,   ( void ) );_PROTOTYP (int dogta,   ( int  ) );_PROTOTYP (int doincr,  ( int  ) );_PROTOTYP (int dopaus,  ( int  ) );_PROTOTYP (int doping,  ( void ) );_PROTOTYP (int doftp,   ( void ) );#ifndef NOFRILLS_PROTOTYP (int dorenam, ( void ) );#endif /* NOFRILLS */#ifdef ZCOPY_PROTOTYP (int docopy, ( void ) );#endif /* ZCOPY */#ifdef CK_REXX_PROTOTYP (int dorexx,  ( void ) );#endif /* CK_REXX */#ifdef CK_REDIR_PROTOTYP (int ttruncmd, ( char * ) );#endif /* CK_REDIR */_PROTOTYP (int dotype,   ( char * ) );#ifdef TCPSOCKETstatic struct keytab telcmd[] = {   "do",   DO,   0,   "dont", DONT, 0,   "will", WILL, 0,   "wont", WONT, 0};static struct keytab tnopts[] = {    "binary", TELOPT_BINARY, 0,    "echo", TELOPT_ECHO, 0,#ifdef CK_NAWS    "naws", TELOPT_NAWS, 0,#endif /* CK_NAWS */    "sga", TELOPT_SGA, 0,    "ttype", TELOPT_TTYPE, 0,    "", 0, 0};static int ntnopts = (sizeof(tnopts) / sizeof(struct keytab)) - 1;int doftp() {    char *p;    int x;    if (network)			/* If we have a current connection */      strcpy(line,ttname);		/* get the host name */    else *line = '\0';			/* as default host */    for (p = line; *p; p++)		/* Remove ":service" from end. */      if (*p == ':') { *p = '\0'; break; }    if ((x = cmtxt("IP host name or number", line, &s, xxstring)) < 0)      return(x);/* Construct FTP command */#ifdef VMS#ifdef MULTINET				/* TGV MultiNet */    sprintf(line,"multinet ftp %s",s);#else    sprintf(line,"ftp %s",s);		/* Other VMS TCP/IP's */#endif /* MULTINET */#else					/* Not VMS */    sprintf(line,"ftp %s",s);#endif /* VMS */    conres();				/* Make console normal  */#ifdef DEC_TCPIP    printf("\n");			/* Prevent prompt-stomping */#endif /* DEC_TCPIP */    x = zshcmd(line);    concb((char)escape);    return(success = x);}   intdoping() {    char *p;    int x;    if (network)			/* If we have a current connection */      strcpy(line,ttname);		/* get the host name */    else *line = '\0';			/* as default host to be pinged. */    for (p = line; *p; p++)		/* Remove ":service" from end. */      if (*p == ':') { *p = '\0'; break; }    if ((x = cmtxt("IP host name or number", line, &s, xxstring)) < 0)      return(x);/* Construct PING command */#ifdef VMS#ifdef MULTINET				/* TGV MultiNet */    sprintf(line,"multinet ping %s /num=1",s);#else    sprintf(line,"ping %s 56 1",s);	/* Other VMS TCP/IP's */#endif /* MULTINET */#else					/* Not VMS */    sprintf(line,"ping %s",s);#endif /* VMS */    conres();				/* Make console normal  */#ifdef DEC_TCPIP    printf("\n");			/* Prevent prompt-stomping */#endif /* DEC_TCPIP */    x = zshcmd(line);    concb((char)escape);    return(success = x);}#endif /* TCPSOCKET *//*  D O C M D  --  Do a command  *//* Returns:   -2: user typed an illegal command   -1: reparse needed    0: parse was successful (even tho command may have failed).*/intdocmd(cx) int cx; {    debug(F101,"docmd entry, cx","",cx);    activecmd = cx;/*  Massive switch() broken up into many smaller ones, for the benefit of  compilers that run out of space when trying to handle large switch  statements.*/    switch (cx) {      case -4:			/* EOF */#ifdef OSK	if (msgflg)  printf("\n");#else	if (msgflg)  printf("\r\n");#endif /* OSK */	  doexit(GOOD_EXIT,xitsta);      case -3:				/* Null command */	return(0);      case -9:				/* Like -2, but errmsg already done */      case -1:				/* Reparse needed */	return(cx);      case -6:				/* Special */      case -2:				/* Error, maybe */#ifndef NOSPL/*  Maybe they typed a macro name.  Let's look it up and see.*/	if (cx == -6)			/* If they typed CR */	  strcat(cmdbuf,"\015");	/*  add it back to command buffer. */	if (ifcmd[cmdlvl] == 2)		/* Watch out for IF commands. */	  ifcmd[cmdlvl]--;	repars = 1;			/* Force reparse */	cmres();	cx = XXDO;			/* Try DO command */#else	return(cx);#endif /* NOSPL */      default:	break;    }#ifndef NOSPL/* Copy macro args from/to two levels up, used internally by _floop et al. */    if (cx == XXGTA || cx == XXPTA) {	/* _GETARGS, _PUTARGS */	int x;	debug(F101,"docmd XXGTA","",XXGTA);	debug(F101,"docmd cx","",cx);	debug(F101,"docmd XXGTA maclvl","",maclvl);	x = dogta(cx);	debug(F101,"docmd dogta returns","",x);	debug(F101,"docmd dogta maclvl","",maclvl);	return(x);    }#endif /* NOSPL */#ifndef NOSPL/* ASK, ASKQ, READ */    if (cx == XXASK || cx == XXASKQ || cx == XXREA ||	cx == XXRDBL || cx == XXGETC) {	return(doask(cx));    }#endif /* NOSPL */#ifndef NOFRILLS    if (cx == XXBUG) {			/* BUG */	if ((x = cmcfm()) < 0) return(x);	return(dobug());    }#endif /* NOFRILLS */    if (cx == XXBYE) {			/* BYE */	bye_active = 1;#ifdef CK_XYZ	if (protocol != PROTO_K) {	    printf("Sorry, BYE only works with Kermit protocol\n");	    return(-9);	}#endif /* CK_XYZ */	if ((x = cmcfm()) < 0) return(x);	sstate = setgen('L',"","","");	if (local) ttflui();		/* If local, flush tty input buffer */	return(0);    }#ifndef NOSPL    if ( cx == XXBEEP ) {        /* BEEP */        int x;#ifdef OS2	int y;        if ((y = cmkey( beeptab, nbeeptab, "which kind of beep", "information",		       xxstring)) < 0 )	  return (y);    	if ((x = cmcfm()) < 0) return(x);        bleep(y);			/* y is one of the BP_ values */#else  /* OS2 */    	if ((x = cmcfm()) < 0) return(x);        bleep(BP_NOTE);#endif /* OS2 */        return(0);    }#endif /* NOSPL */#ifndef NOFRILLS    if (cx == XXCLE) {			/* CLEAR */	if ((x = cmkey(clrtab,nclear,"item to clear",#ifdef NOSPL		  "device-buffer"#else		  "device-and-input"#endif /* NOSPL */		  ,xxstring)) < 0) return(x);#ifndef NOSPL#ifdef OS2        if ( x == CLR_CMD || x == CLR_TRM ) {            if ((z = cmkey(clrcmdtab,nclrcmd,"how much screen to clear\n",			   "all",xxstring)) < 0)	      return(z);        }#endif /* OS2 */#endif /* NOSPL */	if ((y = cmcfm()) < 0) return(y);	/* Clear device input buffer if requested */	y = (x & CLR_DEV) ? ttflui() : 0;#ifndef NOSPL	/* Clear INPUT command buffer if requested */	if (x & CLR_INP) {	    for (x = 0; x < inbufsize; x++)	      inpbuf[x] = NUL;	    inpbp = inpbuf;	    y = 0;	}#ifdef CK_APC	if (x & CLR_APC) {	    apcactive = 0;	    y = 0;	}#endif /* CK_APC */#endif /* NOSPL */#ifndef NODIAL	if (x & CLR_DIA) {	    dialsta = DIA_UNK;	    y = 0;	}#endif /* NODIAL */#ifndef NOMSEND	if (x & CLR_SFL) {		/* CLEAR SEND-LIST */	    if (filehead) {		struct filelist * flp, * next;		flp = filehead;		while (flp) {		    if (flp->fl_name)		      free(flp->fl_name);		    if (flp->fl_alias)		      free(flp->fl_alias);		    next = flp->fl_next;		    free(flp);		    flp = next;		}	    }	    filesinlist = 0;	    filehead = NULL;	    filetail = NULL;	    y = 0;	}#endif /* NOMSEND */#ifdef OS2	switch (x) {	  case CLR_SCL:	    clearscrollback(VTERM);	    break;	  case CLR_CMD:	    switch ( z ) {	      case CLR_C_ALL:		clear();		break;	      case CLR_C_BOS:		clrboscr_escape(VCMD,SP);		break;	      case CLR_C_BOL:		clrbol_escape(VCMD,SP);		break;	      case CLR_C_EOL:		clrtoeoln(VCMD,SP);		break;	      case CLR_C_EOS:		clreoscr_escape(VCMD,SP);		break;	      case CLR_C_LIN:		clrline_escape(VCMD,SP);		break;	      case CLR_C_SCR:		clearscrollback(VCMD);		break;            default:		printf("Not implemented yet, sorry.\n");		break;	    }	    break;	  case CLR_TRM:             switch ( z ) {	      case CLR_C_ALL:                 if (VscrnGetBufferSize(VTERM) > 0 ) {                     VscrnScroll(VTERM, UPWARD, 0, 				 VscrnGetHeight(VTERM)-(tt_status?2:1),				 VscrnGetHeight(VTERM) -				 (tt_status?1:0), TRUE, SP				 );                     cleartermscreen(VTERM);                 }                 break;	      case CLR_C_BOS:		clrboscr_escape(VTERM,SP);		break;	      case CLR_C_BOL:		clrbol_escape(VTERM,SP);		break;	      case CLR_C_EOL:		clrtoeoln(VTERM,SP);		break;	      case CLR_C_EOS:		clreoscr_escape(VTERM,SP);		break;	      case CLR_C_LIN:		clrline_escape(VTERM,SP);		break;             case CLR_C_SCR:                 clearscrollback(VTERM);                 break;             default:                 printf("Not implemented yet, sorry.\n");                 break;	    }	    break;	}	y = 0;	#endif /* OS2 */    	return(success = (y == 0));    }#endif /* NOFRILLS */    if (cx == XXCOM) {			/* COMMENT */	if ((x = cmtxt("Text of comment line","",&s,NULL)) < 0)	  return(x);	/* Don't change SUCCESS flag for this one */	return(0);    }#ifndef NOLOCAL    if (cx == XXCON) {			/* CONNECT */	if ((x = cmkey(conntab,1,"Carriage return to confirm, or option",		       "",xxstring)) < 0) {	    if (x == -3)	      return(success = doconect(0));	    else return(x);	}	if ((y = cmcfm()) < 0)	  return(y);	return(success = doconect(x));    }#endif /* NOLOCAL */#ifndef NOFRILLS#ifdef ZCOPY    if (cx == XXCPY) {			/* COPY a file */#ifdef CK_APC	if (apcactive == APC_LOCAL ||         apcactive == APC_REMOTE && apcstatus != APC_UNCH) return(success = 0);#endif /* CK_APC */	return(docopy());    }#endif /* ZCOPY */#endif /* NOFRILLS */    if (cx == XXCWD)			/* CWD */      return(success = docd());    if (cx == XXCHK)			/* CHECK */      return(success = dochk());    if (cx == XXCLO) {			/* CLOSE */	x = cmkey(clstab,ncls,"Which log or file to close","",xxstring);	if (x == -3) {	    printf("?You must say which file or log\n");	    return(-9);	}	if (x < 0) return(x);	if ((y = cmcfm()) < 0) return(y);	y = doclslog(x);	success = (y == 1);	return(success);    }#ifndef NOSPL    if (cx == XXDEC || cx == XXINC)	/* DECREMENT, INCREMENT */      return(doincr(cx));    if (cx == XXEVAL) {	char *p;	if ((x = cmtxt("Integer arithmetic expression","",&s,xxstring)) < 0)	  return(x);	p = evala(s);	if (!p) p = "";	if (*p)	  printf("%s\n", p);	strncpy(evalbuf,p,32);	return(success = *p ? 1 : 0);    }#endif /* NOSPL */#ifndef NOSPL    if (cx == XXDEF || cx == XXASS ||	cx == XXDFX || cx == XXASX || cx == XXUNDEF)      return(dodef(cx));		/* DEFINE, ASSIGN, etc... */#endif /* NOSPL */#ifndef NOSPL    if (cx == XXDCL) {			/* DECLARE an array */	if ((y = cmfld("Array name","",&s,NULL)) < 0) {	    if (y == -3) {		printf("?Array name required\n");		return(-9);	    } else return(y);	}	if ((y = arraynam(s,&x,&z)) < 0) return(y);	if ((y = cmcfm()) < 0) return(y);	if (dclarray((char)x,z) < 0) {	    printf("?Declare failed\n");	    return(success = 0);

⌨️ 快捷键说明

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