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

📄 ckuus6.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifndef NOFRILLSintdorenam() {    if ((x = cmifi("File to rename","",&s,&y,xxstring)) < 0) {	if (x == -3) {	    printf("?Name of existing file required\n");	    return(-9);	} else return(x);    }    if (y) {				/* No wildcards allowed */	printf("\n?Please specify a single file\n");	return(-9);    }    strcpy(line,s);			/* Make a safe copy of the old name */    p = line + (int)strlen(line) + 2;	/* Place for new name */    if ((x = cmofi("New name","",&s,xxstring)) < 0) { /* Get new name */	if (x == -3) {	    printf("?New name for file required\n");	    return(-9);	} else return(x);    }    strcpy(p,s);			/* Make a safe copy of the new name */    if ((y = cmcfm()) < 0) return(y);#ifdef VMS    conres();				/* Let Ctrl-C work. */#endif /* VMS */    return(zrename(line,p));}#endif /* NOFRILLS */#ifndef NOSPL/* Do the RETURN command */intdoreturn(s) char *s; {    int x; char *p;    if (maclvl < 0) {	printf("\n?Can't return from level %d\n",maclvl);	return(success = 0);    }    lp = line;				/* Expand return value now */    x = LINBUFSIZ-1;    if (xxstring(s,&lp,&x) > -1) {	s = line;    }    x = (int)strlen(s);			/* Is there a return value? */    if (x) {				/* Yes */	p = malloc(x+2);		/* Allocate a place to keep it */	if (p) {			/* Did we get a place? */	    strcpy(p, s);		/* Yes, copy the string into it. */	    mrval[maclvl] = p;		/* Make return value point to it. */	} else {			/* No, could not get space. */	    mrval[maclvl] = NULL;	/* Return null pointer. */	    x = 0;			/* Set failure return code. */	}    } else mrval[maclvl] = NULL;	/* Blank return code */#undef FORRET/*  If we are in a FOR, WHILE, or XIF command list, also copy the return value  two levels up.  (But this doesn't work, so forget it.)*/#ifdef FORRET    if (maclvl > 1) {	if (!strncmp(m_arg[maclvl][0],"_for",4) ||	    !strncmp(m_arg[maclvl][0],"_whi",4) ||	    !strncmp(m_arg[maclvl][0],"_xif",4)) {	    mrval[maclvl-2] = p;	}    }#endif /* FORRET */    popclvl();				/* Pop command level */#ifdef DEBUG    if (mrval[maclvl+1])      debug(F111,"&return",mrval[maclvl+1],maclvl);    else debug(F111,"&return","NULL",maclvl);#endif /* DEBUG */    return(success = x ? 1 : 0);	/* Return status code */	}#endif /* NOSPL */#ifndef NOSPL/* Do the OPEN command */intdoopen()  {				/* OPEN { append, read, write } */    int x, y, z; char *s;    static struct filinfo fcb;		/* (must be static) */    if ((x = cmkey(opntab,nopn,"mode","",xxstring)) < 0) {	if (x == -3) {	    printf("?Mode required\n");	    return(-9);	} else return(x);    }    switch (x) {      case XYFZ_O:			/* Old file (READ) */	if (chkfn(ZRFILE) > 0) {	    printf("?Read file already open\n");	    return(-2);	}	if ((z = cmifi("File to read","",&s,&y,xxstring)) < 0) {	    if (z == -3) {		printf("?Input filename required\n");		return(-9);	    } else return(z);	}	if (y) {				/* No wildcards allowed */	    printf("\n?Please specify a single file\n");	    return(-2);	}	strcpy(line,s);	if ((int)strlen(line) < 1) return(-2);	if ((y = cmcfm()) < 0) return(y);	return(success = zopeni(ZRFILE,line));#ifndef MAC#ifndef NOPUSH      case XYFZ_Y:			/* Pipe/Process (READ) */	if (chkfn(ZRFILE) > 0) {	    printf("?Read file already open\n");	    return(-2);	}        if ((y = cmtxt("System command to read from","",&s,xxstring)) < 0) {	    if (y == -3) {		printf("?Command name required\n");		return(-9);	    } else return(y);	}	strcpy(line,s);	if ((int)strlen(line) < 1) return(-2);	if ((y = cmcfm()) < 0) return(y);	return(success = zxcmd(ZRFILE,line));      case XYFZ_X:			/* Write to pipe */	if (chkfn(ZWFILE) > 0) {	    printf("?Write file already open\n");	    return(-2);	}        if ((y = cmtxt("System command to write to","",&s,xxstring)) < 0) {	    if (y == -3) {		printf("?Command name required\n");		return(-9);	    } else return(y);	}	strcpy(line,s);	if ((int)strlen(line) < 1) return(-2);	if ((y = cmcfm()) < 0) return(y);	success = zxcmd(ZWFILE,line);	if (!success && msgflg)	  printf("Can't open process for writing: %s\n",line);	return(success);#endif /* NOPUSH */#endif /* MAC */      case XYFZ_N:			/* New file (WRITE) */      case XYFZ_A:			/* (APPEND) */	if ((z = cmofi("Name of local file to create","",&s,xxstring)) < 0) {	    if (z == -3) {		printf("?Filename required\n");		return(-9);	    } else return(z);	}	if (chkfn(ZWFILE) > 0) {	    printf("?Write/Append file already open\n");	    return(-2);	}        fcb.bs = fcb.cs = fcb.rl = fcb.fmt = fcb.org = fcb.cc = fcb.typ = 0;	fcb.lblopts = 0;	fcb.dsp = x;			/* Create or Append */	strcpy(line,s);	if ((int)strlen(line) < 1) return(-2);	if ((y = cmcfm()) < 0) return(y);	return(success = zopeno(ZWFILE,line,NULL,&fcb));      default:	printf("?Not implemented");	return(-2);    }}#endif /* NOSPL *//* Finish parsing and do the GET command */intdoget() {    int x;    char *cbp;    cmarg2 = "";			/* Initialize as-name to nothing */    x = 0;#ifdef NOFRILLS    if (*cmarg == NUL) {	printf("?Remote filespec required\n");	return(-3);    }#else/*  If remote file name omitted, get foreign and local names separately.  But multine GET is allowed only if NOFRILLS is not defined.*/    if (*cmarg == NUL) { 	if (tlevel > -1#ifndef NOSPL	    && cmdstk[cmdlvl].src == CMD_TF#endif /* NOSPL */	    ) {/* Input is from a command file. */	    /* Read 2nd line of GET command */	    if (getnct(cmdbuf,CMDBL) < 0) {		printf("Command file ends prematurely in multiline GET\n");		popclvl();		return(-9);	    }	    cmres();			/* Parse it */	    if ((x = cmtxt("Oofa","",&s,xxstring)) < 0)	      return(x);	    if (*s == '{') {		/* Strip enclosing braces */		x = (int)strlen(s);		if (s[x-1] == '}') {		    s[x-1] = NUL;		    s++;		}	    }	    strcpy(line,s);		/* Make a safe copy */	    cmarg = line;		/* Point to remote filename */	    if (*cmarg == NUL) {	/* Make sure there is one */		printf("Remote filename missing in multiline GET\n");		return(-9);	    }	    lp = line + strlen(line) + 1; /* Place for as-name */	    /* And third line... */	    cmarg2 = "";		/* Assume no as-name */	    if (getnct(cmdbuf,CMDBL) < 0) { /* Get next line */		popclvl();		/* There isn't one. */	    } else {			/* There is... */		if (*cmdbuf >= ' ') {	/* Parse as output filename */		    cmres();		    if ((x = cmofi("Mupeen",cmarg,&s,xxstring)) < 0)		      return(x);		    strcpy(lp,s);	/* Make a safe copy */		    cmarg2 = lp;	/* Point as-name pointer at it */		}	    }            x = 0;			/* Return code OK */#ifndef NOSPL/* Reading commands from a macro definition */	} else if (cmdlvl > 0 && cmdstk[cmdlvl].src == CMD_MD) {	    /* Read second line of GET command */	    cbp = cmdbuf;	    if (getncm(cbp,CMDBL) < 0) {		printf("Macro definition ends prematurely in multiline GET\n");		return(-9);	    }	    cmres();	    if ((x = cmtxt("Oofa","",&s,xxstring)) < 0) return(x);	    if (*s == NUL) {		/* Make sure we got something */		printf("Remote filename missing in multiline GET\n");		return(-9);	    }	    if (*s == '{') {		/* Strip enclosing braces */		x = (int)strlen(s);		if (s[x-1] == '}') {		    s[x-1] = NUL;		    s++;		}	    }	    strcpy(line,s);		/* Copy filename to safe place */	    cmarg = line;		/* Point to it */	    x = strlen(line);		/* Get its length */	    lp = line + x + 1;		/* Where to put the next bit */	    y = LINBUFSIZ - x - 1;	/* Room left for next bit */	    /* And third line... */	    cmarg2 = "";		/* Assume no as-name */	    if (getncm(lp,y) > -1 && *lp >= ' ') { /* Read next line */		x = strlen(lp);		if (lp[x-1] == CR) lp[x-1] = NUL; /* Remove CR */		cbp = cmdbuf;		/* Interpret the line */		*cbp = NUL;		/* ... */		y = CMDBL;		/* into the command buffer */		xxstring(lp,&cbp,&y);		if (*cmdbuf) {		/* If we have something */		    cmres();		/* parse it as an output filename */		    strcat(cmdbuf," ");		    if ((x = cmofi("Mupeen","",&s,NULL)) < 0)		      return(x);		    strcpy(lp,s);	/* Copy the name to safe place */		    cmarg2 = lp;	/* and make as-name pointer */		}	    }            x = 0;			/* Return code OK */#endif /* NOSPL */        } else {			/* Input is from terminal */ 	    cmsavp(psave,80);	    cmsetp(" Remote file specification: "); /* Make new one */	    cmini(ckxech);	    x = -1;	    if (pflag) prompt(xxstring);	    while (x == -1) {		/* Prompt till they answer */	    	x = cmtxt("Name of remote file(s)","",&cmarg,xxstring);		debug(F111," cmtxt",cmarg,x);	    }	    if (x < 0) {		cmsetp(psave);		return(x);	    }	    if (*cmarg == NUL) { 	/* If user types a bare CR, */		printf("(cancelled)\n"); /* Forget about this. */	    	cmsetp(psave);		/* Restore old prompt, */		return(0);		/* and return. */	    }	    if (*cmarg == '{') {	/* Strip enclosing braces */		x = (int)strlen(cmarg);		if (cmarg[x-1] == '}') {		    cmarg[x-1] = NUL;		    cmarg++;		}	    }	    strcpy(line,cmarg);		/* Make a safe copy */	    cmarg = line;	    cmsetp(" Local name to store it under: "); /* New prompt */	    cmini(ckxech);	    x = -1;	    if (pflag) prompt(xxstring);	    while (x == -1) {		/* Again, parse till answered */	    	x = cmofi("Local file name","",&cmarg2,xxstring);	    }	    if (x < 0) {		/* Parse error */		if (x == -3) {		/* CR = cancel */		    printf("(cancelled)\n"); /* Print message */		    x = 0;		/* Avoid further messages */		}		cmsetp(psave);		/* Restore prompt */		return(x);	    }	    	    x = -1;			/* Get confirmation. */	    while (x == -1) x = cmcfm();	    cmsetp(psave);		/* Restore old prompt. */        }    }#endif /* NOFRILLS */    if (x == 0) {			/* Good return from cmtxt or cmcfm, */	debug(F110,"xxget cmarg",cmarg,0);	strncpy(fspec,cmarg,FSPECL);	debug(F111,"xxget fspec",fspec,FSPECL);	sstate = 'r';			/* Set start state. */	if (local) {	    displa = 1;	    ttflui();	}    }    return(x);}#ifndef NOSPLintdogta(cx) int cx; {    int i; char c; char mbuf[4]; char *p;    if ((y = cmcfm()) < 0)      return(y);    if (cx == XXGTA)      debug(F101,"_getargs maclvl","",maclvl);    else if (cx == XXPTA)      debug(F101,"_putargs maclvl","",maclvl);    else      return(-2);    if (maclvl < 1)      return(success = 0);#ifdef COMMENT#ifdef NEXT/*   For some reason, this routine makes Kermit core dump on the next after  it returns to docmd().  It works fine, as the debug log shows, but when  docmd returns, it gets a memory fault.*/    else return(1);#endif /* NEXT */#endif /* COMMENT */    mbuf[0] = '%'; mbuf[1] = '0'; mbuf[2] = '\0'; /* Argument name buf */    for (i = 0; i < 10; i++) {		/* For all args */	c = (char) i + '0';		/* Make name */	mbuf[1] = c;			/* Insert digit */	if (cx == XXGTA) {		/* Get arg from level-minus-2 */	    if (maclvl == 1) p = g_var[c]; /* If at level 1 use globals 0..9 */	    else p = m_arg[maclvl-2][i]; /* Otherwise they're on the stack */	    if (!p) {		debug(F111,"_getarg p","(null pointer)",i);	    } else debug(F111,"_getarg p",p,i);	    addmac(mbuf,p);	} else if (cx == XXPTA) {	/* Put args level+2 */#ifndef MAC	    connoi();			/* Turn off interrupts. */#endif /* MAC */	    maclvl -= 2;		/* This is gross.. */	    p = m_arg[maclvl+2][i];	    if (p)	      debug(F111,"_putarg m_arg[maclvl+2][i]",p,i);	    else	      debug(F111,"_putarg m_arg[maclvl+2][i]","(null pointer)",i);	    addmac(mbuf,m_arg[maclvl+2][i]);	    maclvl += 2;#ifndef MAC	    conint(trap,stptrap);	/* Restore interrupts */#endif /* MAC */	} else return(success = 0);    }    debug(F101,"_get/putarg exit","",i);    debug(F101,"_get/putarg exit maclvl","",maclvl);    return(success = 1);}#endif /* NOSPL */#ifndef NOSPL/* Do the GOTO command */intdogoto(s) char *s; {    int i, j, x, y;    char tmplbl[50], *lp;    debug(F101,"goto cmdlvl","",cmdlvl);    debug(F101,"goto maclvl","",maclvl);    debug(F101,"goto tlevel","",tlevel);    debug(F110,"goto before conversion",s,0);    y = (int)strlen(s);    if (*s != ':') {			/* If the label mentioned */	for (i = y; i > 0; i--) {	/* does not begin with a colon, */	    s[i] = s[i-1];		/* then insert one. */	}				/* Also, convert to lowercase. */	s[0] = ':';	s[++y] = '\0';    }    debug(F111,"goto after conversion",s,y);    if (s[1] == '.' || s[1] == SP || s[1] == NUL) {	printf("?Bad label syntax - '%s'\n",s);	return(success = 0);    }    if (cmdlvl == 0) {	printf("?Sorry, GOTO only works in a command file or macro\n");	return(success = 0);    }    while (cmdlvl > 0) {		/* Only works inside macros & files */	if (cmdstk[cmdlvl].src == CMD_MD) { /* GOTO inside macro */	    int i, m, flag;	    char *xp, *tp;	    lp = macx[maclvl];	    m = (int)strlen(lp) - y + 1;	    debug(F111,"goto in macro",lp,m);	    flag = 1;			/* flag for valid label position */

⌨️ 快捷键说明

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