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

📄 ckuus3.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
} /*  S E T O N  --  Parse on/off (default on), set parameter to result  */ seton(prm) int *prm; {    int x, y;    if ((y = cmkey(onoff,2,"","on")) < 0) return(y);    if ((x = cmcfm()) < 0) return(x);    *prm = y;    return(0);} /*  S E T N U M  --  Set parameter to result of cmnum() parse.  *//* Call with x - number from cnum parse, y - return code from cmnum*/setnum(prm,x,y,max) int x, y, *prm, max; {    debug(F101,"setnum","",y);    if (y < 0) return(y);    if (x > max) {	printf("\n?Sorry, %d is the maximum\n",max);	return(-2);    }    if ((y = cmcfm()) < 0) return(y);    *prm = x;    return(0);} /*  S E T C C  --  Set parameter to an ASCII control character value.  */ setcc(prm,x,y) int x, y, *prm; {    if (y < 0) return(y);    if ((x > 037) && (x != 0177)) {	printf("\n?Not in ASCII control range - %d\n",x);	return(-2);    }    if ((y = cmcfm()) < 0) return(y);    *prm = x;    return(0);}/*  D O R M T  --  Do a remote command  */ dormt(xx) int xx; {    int x;    char *s, sbuf[50], *s2;     if (xx < 0) return(xx);    switch (xx) { case XZCWD:				/* CWD */    if ((x = cmtxt("Remote directory name","",&s)) < 0) return(x);    debug(F111,"XZCWD: ",s,x);    *sbuf = NUL;    s2 = sbuf;    if (*s != NUL) {			/* If directory name given, */					/* get password on separate line. */        if (tlevel > -1) {		/* From take file... */ 	    if (fgets(sbuf,50,tfile[tlevel]) == NULL)	    	fatal("take file ends prematurely in 'remote cwd'");	    debug(F110," pswd from take file",s2,0);	    for (x = strlen(sbuf);	     	 x > 0 && (sbuf[x-1] == '\n' || sbuf[x-1] == '\r');		 x--)		sbuf[x-1] = '\0';         } else {			/* From terminal... */ 	    printf(" Password: "); 		/* get a password */	    while (((x = getchar()) != NL) && (x != CR)) { /* with no echo */	    	if ((x &= 0177) == '?') {	    	    printf("? Password of remote directory\n Password: ");		    s2 = sbuf;		    *sbuf = NUL;	    	}	    	else if (x == ESC)	/* Mini command line editor... */	    	    putchar(BEL);		else if (x == BS || x == 0177)		    s2--;		else if (x == 025) {	/* Ctrl-U */		    s2 = sbuf;		    *sbuf = NUL;		}	    	else		    *s2++ = x;            }	    *s2 = NUL;	    putchar('\n');        }        s2 = sbuf;    } else s2 = "";    debug(F110," password",s2,0);    sstate = setgen('C',s,s2,"");    return(0);case XZDEL:				/* Delete */    if ((x = cmtxt("Name of remote file(s) to delete","",&s)) < 0) return(x);    return(sstate = rfilop(s,'E')); case XZDIR:				/* Directory */    if ((x = cmtxt("Remote directory or file specification","",&s)) < 0)    	return(x);    return(sstate = setgen('D',s,"","")); case XZHLP:				/* Help */    if (x = (cmcfm()) < 0) return(x);    sstate = setgen('H',"","","");    return(0); case XZHOS:				/* Host */    if ((x = cmtxt("Command for remote system","",&cmarg)) < 0) return(x);    return(sstate = 'c'); case XZPRI:				/* Print */    if ((x = cmtxt("Remote file(s) to print on remote printer","",&s)) < 0)    	return(x);    return(sstate = rfilop(s,'S')); case XZSPA:				/* Space */    if ((x = cmtxt("Confirm, or remote directory name","",&s)) < 0) return(x);    return(sstate = setgen('U',s,"",""));    case XZTYP:				/* Type */    if ((x = cmtxt("Remote file specification","",&s)) < 0) return(x);    return(sstate = rfilop(s,'T')); case XZWHO:    if ((x = cmtxt("Remote user name, or carriage return","",&s)) < 0)    	return(x);    return(sstate = setgen('W',s,"","")); default:    if (x = (cmcfm()) < 0) return(x);    printf("not working yet - %s\n",cmdbuf);    return(-2);    }}   /*  R F I L O P  --  Remote File Operation  */ rfilop(s,t) char *s, t; {    if (*s == NUL) {	printf("?File specification required\n");	return(-2);    }    debug(F111,"rfilop",s,t);    return(setgen(t,s,"",""));}/*  S C R E E N  --  Screen display function  */ /*  screen(f,c,n,s)      f - argument descriptor      c - a character or small integer      n - a long integer      s - a string. Fill in this routine with the appropriate display update for the system. This version is for a dumb tty.*/screen(f,c,n,s) int f; long n; char c; char *s; {    static int p = 0;			/* Screen position */    int len;				/* Length of string */    char buf[80];			/* Output buffer */    len = strlen(s);			/* Length of string */    if (!displa || quiet) return;	/* No update if display flag off */     switch (f) { case SCR_FN:    			/* filename */    conoll(""); conol(s); conoc(SP); p = len + 1; return; case SCR_AN:    			/* as-name */    if (p + len > 75) { conoll(""); p = 0; }    conol("=> "); conol(s); if ((p += (len + 3)) > 78) { conoll(""); p = 0; }    return; case SCR_FS: 				/* file-size */    sprintf(buf,", Size: %ld",n);  conoll(buf);  p = 0; return; case SCR_XD:    			/* x-packet data */    conoll(""); conoll(s); p = 0; return;    case SCR_ST:      			/* File status */    switch (c) {	case ST_OK:   	   		/*  Transferred OK */	    if ((p += 5) > 78) { conoll(""); p = 0; }	    conoll(" [OK]"); p += 5; return; 	case ST_DISC: 			/*  Discarded */	    if ((p += 12) > 78) { conoll(""); p = 0; }	    conoll(" [discarded]"); p += 12; return; 	case ST_INT:       		/*  Interrupted */	    if ((p += 14) > 78) { conoll(""); p = 0; }	    conoll(" [interrupted]"); p += 14; return; 	case ST_SKIP: 			/*  Skipped */	    conoll("");	    conol("Skipping "); conoll(s); p = 0;	    return;         default:	    conoll("*** screen() called with bad status ***"); p = 0; return;    }case SCR_PN:    			/* Packet number */    sprintf(buf,"%s: %ld",s,n); conol(buf); p += strlen(buf); return; case SCR_PT:    			/* Packet type or pseudotype */    if (c == 'Y') return;		/* Don't bother with ACKs */    if (c == 'D') {			/* Only show every 4th data packet */	if (n % 4) return;	c = '.';    }#ifndef AMIGA    if (p++ > 78) {			/* If near right margin, */	conoll("");			/* Start new line */	p = 0;				/* and reset counter. */    }#endif    conoc(c);				/* Display the character. */#ifdef AMIGA    if (c == 'G') conoll("");           /* new line after G packets */#endif    return; case SCR_TC:    			/* transaction complete */    conoc(BEL); return; case SCR_EM:				/* Error message */    conoll(""); conoc('?'); conoll(s); p = 0; return;		/* +1	*/ case SCR_WM:				/* Warning message */    conoll(""); conoll(s); p = 0; return; case SCR_TU:				/* Undelimited text */    if ((p += len) > 78) { conoll(""); p = len; }    conol(s); return; case SCR_TN:				/* Text delimited at beginning */    conoll(""); conol(s); p = len; return; case SCR_TZ:				/* Text delimited at end */    if ((p += len) > 78) { conoll(""); p = len; }    conoll(s); return;    case SCR_QE:				/* Quantity equals */    sprintf(buf,"%s: %ld",s,n);    conoll(buf); p = 0; return; default:    conoll("*** screen() called with bad object ***"); p = 0; return;    }}/*  I N T M S G  --  Issue message about terminal interrupts  */ intmsg(n) long n; {    extern char *chstr();    char buf[80];     if ((!displa) || (quiet)) return;#ifdef UXIII    (void) conchk();	/* clear out pending escape-signals in ckxbsd.c */#endif    if (n == 1) {#ifdef UXIII#ifndef apollo#ifndef datageneral				/* we need to signal before kb input */	sprintf(buf,"Type escape (%s) followed by:",chstr(escape));	screen(SCR_TN,0,0l,buf);#endif#endif#endif screen(SCR_TN,0,0l,"CTRL-F to cancel file,  CTRL-R to resend current packet"); screen(SCR_TN,0,0l,"CTRL-B to cancel batch, CTRL-A for status report: ");    }    else screen(SCR_TU,0,0l," ");}/*  C H K I N T  --  Check for console interrupts  */ /*** should rework not to destroy typeahead ***/ chkint() {    int ch, cn;     if ((!local) || (quiet)) return(0);	/* Only do this if local & not quiet */#ifdef datageneral    cn = (con_reads_mt) ? 1 : conchk();	/* Any input waiting? */#else    cn = conchk();			/* Any input waiting? */#endif    debug(F101,"conchk","",cn);     while (cn > 0) {			/* Yes, read it. */	cn--;			/* give read 5 seconds for interrupt character */#ifdef datageneral        /* We must be careful to just print out one result for each character         * read.  The flag, conint_avl, controls duplication of characters.         * Only one character is handled at a time, which is a reasonable         * limit.  More complicated schemes could handle a buffer.         */        if (con_reads_mt) {            if ((ch = conint_ch) <= 0) return(0);   /* I/O error, or no data */            else if (conint_avl == 0) return(0);    /* Char already read */            else conint_avl = 0;                    /* Flag character as read */        }        else { if ((ch = coninc(5)) < 0) return(0);  }#else	if ((ch = coninc(5)) < 0) return(0);#endif	switch (ch & 0177) {	    case 0001:			/* CTRL-A */		screen(SCR_TN,0,0l,"^A  Status report:");		screen(SCR_TN,0,0l," file type: ");		if (binary) screen(SCR_TZ,0,0l,"binary");		    else    screen(SCR_TZ,0,0l,"text");		screen(SCR_QE,0,(long)filcnt," file number");		screen(SCR_QE,0,(long)ffc,   " characters ");		screen(SCR_QE,0,(long)bctu,  " block check");		screen(SCR_QE,0,(long)rptflg," compression");		screen(SCR_QE,0,(long)ebqflg," 8th-bit prefixing");		continue;	    case 0002:			/* CTRL-B */	    	screen(SCR_TN,0,0l,"^B - Cancelling Batch ");	    	czseen = 1;		continue;	    case 0006:			/* CTRL-F */	    	screen(SCR_TN,0,0l,"^F - Cancelling File ");	    	cxseen = 1;		continue;	    case 0022:	    	    	/* CTRL-R */	    	screen(SCR_TN,0,0l,"^R - Resending ");	    	resend();		return(1);	    default:			/* Anything else, just ignore */	    	screen(SCR_TU,0,0l," [Ignored] ");		continue;    	}    }    return(0);}/*  D E B U G  --  Enter a record in the debugging log  */ /* Call with a format, two strings, and a number:   f  - Format, a bit string in range 0-7.        If bit x is on, then argument number x is printed.   s1 - String, argument number 1.  If selected, printed as is.   s2 - String, argument number 2.  If selected, printed in brackets.   n  - Int, argument 3.  If selected, printed preceded by equals sign.    f=0 is special: print s1,s2, and interpret n as a char.*/#ifdef DEBUG#define DBUFL 1000debug(f,s1,s2,n) int f, n; char *s1, *s2; {    static char s[DBUFL];    char *sp = s;     if (!deblog) return;		/* If no debug log, don't */    switch (f) {    	case F000:			/* 0, print both strings, */	    if (strlen(s1) + strlen(s2) + 3 > DBUFL)	      sprintf(sp,"DEBUG string too long\n");	    else sprintf(sp,"%s%s%c\n",s1,s2,n); /* interpret n as a char */	    zsout(ZDFILE,s);	    break;    	case F001:			/* 1, "=n" */	    sprintf(sp,"=%d\n",n);	    zsout(ZDFILE,s);	    break;    	case F010:			/* 2, "[s2]" */	    if (strlen(s2) + 4 > DBUFL)	      sprintf(sp,"DEBUG string too long\n");	    else sprintf(sp,"[%s]\n",s2);	    zsout(ZDFILE,"");	    break;    	case F011:			/* 3, "[s2]=n" */	    if (strlen(s2) + 15 > DBUFL)	      sprintf(sp,"DEBUG string too long\n");	    else sprintf(sp,"[%s]=%d\n",s2,n);	    zsout(ZDFILE,s);	    break;    	case F100:			/* 4, "s1" */	    zsoutl(ZDFILE,s1);	    break;    	case F101:			/* 5, "s1=n" */	    if (strlen(s1) + 15 > DBUFL)	      sprintf(sp,"DEBUG string too long\n");	    else sprintf(sp,"%s=%d\n",s1,n);	    zsout(ZDFILE,s);	    break;    	case F110:			/* 6, "s1[s2]" */	    if (strlen(s1) + strlen(s2) + 4 > DBUFL)	      sprintf(sp,"DEBUG string too long\n");	    else sprintf(sp,"%s[%s]\n",s1,s2);	    zsout(ZDFILE,s);	    break;    	case F111:			/* 7, "s1[s2]=n" */	    if (strlen(s1) + strlen(s2) + 15 > DBUFL)	      sprintf(sp,"DEBUG string too long\n");	    else sprintf(sp,"%s[%s]=%d\n",s1,s2,n);	    zsout(ZDFILE,s);	    break;	default:	    sprintf(sp,"\n?Invalid format for debug() - %d\n",n);	    zsout(ZDFILE,s);    }}#endif#ifdef TLOG#define TBUFL 300/*  T L O G  --  Log a record in the transaction file  *//* Call with a format and 3 arguments: two strings and a number:   f  - Format, a bit string in range 0-7, bit x is on, arg #x is printed.   s1,s2 - String arguments 1 and 2.   n  - Int, argument 3.*/tlog(f,s1,s2,n) int f; long n; char *s1, *s2; {    static char s[TBUFL];    char *sp = s; int x;        if (!tralog) return;		/* If no transaction log, don't */    switch (f) {    	case F000:			/* 0 (special) "s1 n s2"  */	    if (strlen(s1) + strlen(s2) + 15 > TBUFL)	      sprintf(sp,"?T-Log string too long\n");	    else sprintf(sp,"%s %ld %s\n",s1,n,s2);	    zsout(ZTFILE,s);	    break;    	case F001:			/* 1, " n" */	    sprintf(sp," %ld\n",n);	    zsout(ZTFILE,s);	    break;    	case F010:			/* 2, "[s2]" */	    x = strlen(s2);	    if (s2[x] == '\n') s2[x] = '\0';	    if (x + 6 > TBUFL)	      sprintf(sp,"?T-Log string too long\n");	    else sprintf(sp,"[%s]\n",s2);	    zsout(ZTFILE,"");	    break;    	case F011:			/* 3, "[s2] n" */	    x = strlen(s2);	    if (s2[x] == '\n') s2[x] = '\0';	    if (x + 6 > TBUFL)	      sprintf(sp,"?T-Log string too long\n");	    else sprintf(sp,"[%s] %ld\n",s2,n);	    zsout(ZTFILE,s);	    break;    	case F100:			/* 4, "s1" */	    zsoutl(ZTFILE,s1);	    break;    	case F101:			/* 5, "s1: n" */	    if (strlen(s1) + 15 > TBUFL)	      sprintf(sp,"?T-Log string too long\n");	    else sprintf(sp,"%s: %ld\n",s1,n);	    zsout(ZTFILE,s);	    break;    	case F110:			/* 6, "s1 s2" */	    x = strlen(s2);	    if (s2[x] == '\n') s2[x] = '\0';	    if (strlen(s1) + x + 4 > TBUFL)	      sprintf(sp,"?T-Log string too long\n");	    else sprintf(sp,"%s %s\n",s1,s2);	    zsout(ZTFILE,s);	    break;    	case F111:			/* 7, "s1 s2: n" */	    x = strlen(s2);	    if (s2[x] == '\n') s2[x] = '\0';	    if (strlen(s1) + x + 15 > TBUFL)	      sprintf(sp,"?T-Log string too long\n");	    else sprintf(sp,"%s %s: %ld\n",s1,s2,n);	    zsout(ZTFILE,s);	    break;	default:	    sprintf(sp,"\n?Invalid format for tlog() - %ld\n",n);	    zsout(ZTFILE,s);    }}#endif

⌨️ 快捷键说明

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