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

📄 ckcfn3.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    if (retcode < 0) {			/* If we are rejecting */	discard = 1;			/* remember to discard the file */	rejection = rpbuf[1];		/* and use the first reason given. */	if (fncsav != -1) {	    fncact = fncsav;	    fncsav = -1;	}    }    debug(F111,"gattr return",rpbuf,retcode);    return(retcode);}/*  I N I T A T T R  --  Initialize file attribute structure  */intinitattr(yy) struct zattr *yy; {    yy->lengthk = yy->length = -1L;    yy->type.val = "";    yy->type.len = 0;    yy->date.val = "";    yy->date.len = 0;    yy->encoding.val = "";    yy->encoding.len = 0;    yy->disp.val = "";    yy->disp.len = 0;    yy->systemid.val = "";    yy->systemid.len = 0;    yy->sysparam.val = "";    yy->sysparam.len = 0;    yy->creator.val = "";    yy->creator.len = 0;    yy->account.val = "";    yy->account.len = 0;    yy->area.val = "";    yy->area.len = 0;    yy->password.val = "";    yy->password.len = 0;    yy->blksize = -1L;    yy->xaccess.val = "";    yy->xaccess.len = 0;    yy->lprotect.val = "";    yy->lprotect.len = 0;    yy->gprotect.val = "";    yy->gprotect.len = 0;    yy->recfm.val = "";    yy->recfm.len = 0;    yy->reply.val = "";    yy->reply.len = 0;#ifdef OS2    yy->longname.len = 0 ;    yy->longname.val = "" ;#endif /* OS2 */    return(0);}/*  A D E B U -- Write attribute packet info to debug log  */intadebu(f,zz) char *f; struct zattr *zz; {#ifdef DEBUG    if (deblog == 0) return(0);    debug(F110,"Attributes for incoming file ",f,0);    debug(F101," length in K","",(int) zz->lengthk);    debug(F111," file type",zz->type.val,zz->type.len);    debug(F111," creation date",zz->date.val,zz->date.len);    debug(F111," creator",zz->creator.val,zz->creator.len);    debug(F111," account",zz->account.val,zz->account.len);    debug(F111," area",zz->area.val,zz->area.len);    debug(F111," password",zz->password.val,zz->password.len);    debug(F101," blksize","",(int) zz->blksize);    debug(F111," access",zz->xaccess.val,zz->xaccess.len);    debug(F111," encoding",zz->encoding.val,zz->encoding.len);    debug(F111," disposition",zz->disp.val,zz->disp.len);    debug(F111," lprotection",zz->lprotect.val,zz->lprotect.len);    debug(F111," gprotection",zz->gprotect.val,zz->gprotect.len);    debug(F111," systemid",zz->systemid.val,zz->systemid.len);    debug(F111," recfm",zz->recfm.val,zz->recfm.len);    debug(F111," sysparam",zz->sysparam.val,zz->sysparam.len);    debug(F101," length","",(int) zz->length);    debug(F110," reply",zz->reply.val,0);#endif /* DEBUG */    return(0);}/*  O P E N A -- Open a file, with attributes.  *//*  This function tries to open a new file to put the arriving data in.  The  filename is the one in the srvcmd buffer.  File collision actions are:  OVERWRITE (the existing file is overwritten), RENAME (the new file is  renamed), BACKUP (the existing file is renamed), DISCARD (the new file is  refused), UPDATE (the incoming file replaces the existing file only if the  incoming file has a newer creation date).  Returns 0 on failure, nonzero on success.*/extern char *rf_err;intopena(f,zz) char *f; struct zattr *zz; {    int x, dispos = 0;    static struct filinfo fcb;		/* Must be static! */    debug(F110,"opena f",f,0);    debug(F101,"opena discard","",discard);    adebu(f,zz);			/* Write attributes to debug log */    ffc = 0L;				/* Init file-character counter */    /* Set up file control structure */    fcb.bs = fblksiz;			/* Blocksize */#ifndef NOCSETS    fcb.cs = fcharset;			/* Character set */#else    fcb.cs = 0;				/* Character set */#endif /* NOCSETS */    fcb.rl = frecl;			/* Record Length */    fcb.fmt = frecfm;			/* Record Format */    fcb.org = forg;			/* Organization */    fcb.cc = fcctrl;			/* Carriage control */    fcb.typ = binary;			/* Type */    debug(F101,"opena xflg","",xflg);    debug(F101,"opena remfile","",remfile);    debug(F101,"opena remappd","",remappd);    if (xflg && remfile && remappd)	/* REMOTE output redirected with >> */      fcb.dsp = XYFZ_A;    else      fcb.dsp = (fncact == XYFX_A) ? XYFZ_A : XYFZ_N; /* Disposition */    debug(F101,"opena disp","",fcb.dsp);    fcb.os_specific = '\0';		/* OS-specific info */#ifdef CK_LABELED    fcb.lblopts = lf_opts;		/* Labeled file options */#else    fcb.lblopts = 0;#endif /* CK_LABELED */    if (zz->disp.len > 0) {		/* Incoming file has a disposition? */	debug(F111,"open disposition",zz->disp.val,zz->disp.len);	dispos = (int) (*(zz->disp.val));    }    if (!dispos && xflg && remfile && remappd) /* REMOTE redirect append ? */      dispos = fcb.dsp;    debug(F101,"opena dispos","",dispos);    if (!dispos) {			         /* No special disposition? */	if (fncact == XYFX_B && ofn1x && ofn2) { /* File collision = BACKUP? */	    if (zrename(ofn1,ofn2) < 0) {        /* Rename existing file. */		debug(F110,"opena rename fails",ofn1,0);		rf_err = "Can't create backup file";		return(0);	    } else debug(F110,"opena rename ok",ofn2,0);	}    } else if (dispos == 'R') {		/* Receiving a RESEND */#ifdef COMMENT        if (fncact == XYFX_R)		/* and file collision = RENAME */	  if (ofn1x)#endif /* COMMENT */	if (ofn1[0])	  f = ofn1;			/* use original name. */        if (fncact == XYFX_R)		/* if file collision is RENAME */          strcpy(filnam,ofn1);		/* restore the real name */        screen(SCR_AN,0,0L,f);		/* update name on screen */    }    debug(F111,"opena [file]=mode: ",f,fcb.dsp);    if (x = openo(f,zz,&fcb)) {		/* Try to open the file. */#ifdef pdp11	tlog(F110," local name:",f,0L);	/* OK, open, record local name. */#else#ifndef ZFNQFP	tlog(F110," local name:",f,0L);#else	{				/* Log full local pathname */	    char *p = NULL, *q = f;	    if ((p = malloc(CKMAXPATH+1)))	      if (zfnqfp(filnam, CKMAXPATH, p))		q = p;	    tlog(F110," local name:",q,0L);	    if (p) free(p);	}#endif /* ZFNQFP */#endif /* pdp11 */	if (binary) {			/* Log file mode in transaction log */	    tlog(F101," mode: binary","",(long) binary);	} else {			/* If text mode, check character set */	    tlog(F100," mode: text","",0L);#ifndef NOCSETS	    tlog(F110," file character-set",fcsinfo[fcharset].name,0L);	    if (tcharset == TC_TRANSP)	      tlog(F110," xfer character-set","transparent",0L);	    else	      tlog(F110," xfer character-set",tcsinfo[tcharset].name,0L);#endif /* NOCSETS */	    debug(F111," opena charset",zz->encoding.val,zz->encoding.len);	}	if (fsize > -1L) screen(SCR_FS,0,fsize,"");#ifdef datageneral/*  Need to turn on multi-tasking console interrupt task here, since multiple  files may be received (huh?) ...*/        if ((local) && (!quiet))        /* Only do this if local & not quiet */	  consta_mt();			/* Start the async read task */#endif /* datageneral */    } else {				/* Did not open file OK. */	char * e;	e = ck_errstr();		/* Get system error message */	if (*e)	  screen(SCR_EM,0,0l,e);	else	  screen(SCR_EM,0,0l,"Can't open output file");        tlog(F110,"Failure to open",f,0L);        tlog(F110,"Error:",e,0L);	debug(F110,"opena error",e,0);    }    return(x);				/* Pass on return code from openo */}/*  C A N N E D  --  Check if current file transfer cancelled */intcanned(buf) CHAR *buf; {    if (*buf == 'X') cxseen = 1;    if (*buf == 'Z') czseen = 1;    debug(F101,"canned: cxseen","",cxseen);    debug(F101," czseen","",czseen);    return((czseen || cxseen) ? 1 : 0);}/*  O P E N I  --  Open an existing file for input  */intopeni(name) char *name; {    int x, filno;    char *name2;    if (memstr) return(1);		/* Just return if file is memory. */    debug(F110,"openi",name,0);    debug(F101," sndsrc","",sndsrc);    filno = (sndsrc == 0) ? ZSTDIO : ZIFILE;    /* ... */    debug(F101," file number","",filno);    if (server && !en_cwd) {		/* If running as server */	zstrip(name,&name2);		/* and CWD is disabled... */	if (				/* check if pathname was included. */#ifdef VMS	zchkpath(name)#else	strcmp(name,name2)#endif /* VMS */        ) {	    tlog(F110,name,"authorization failure",0L);	    debug(F110," openi authorization failure",name,0);	    return(0);	} else name = name2;    }    if (zopeni(filno,name)) {		/* Otherwise, try to open it. */	debug(F110," ok",name,0);    	return(1);    } else {				/* If not found, */	char xname[100];		/* convert the name */	zrtol(name,xname);		/* to local form and then */	x = zopeni(filno,xname);	/* try opening it again. */	debug(F101," zopeni","",x);	if (x) {	    debug(F110," ok",xname,0);	    return(1);			/* It worked. */        } else {#ifdef COMMENT	    screen(SCR_EM,0,0l,"Can't open file");  /* It didn't work. */#endif /* COMMENT */	    tlog(F110,xname,"could not be opened",0L);	    debug(F110," openi failed",xname,0);	    return(0);        }    }}/*  O P E N O  --  Open a new file for output.  */static int isopen = 0;intopeno(name,zz,fcb) char *name; struct zattr *zz; struct filinfo *fcb; {    char *name2;    int channel;    if (stdouf)				/* Receiving to stdout? */      return(zopeno(ZSTDIO,"",zz,NULL));    debug(F110,"openo: name",name,0);    if (cxseen || czseen || discard) {	/* If interrupted, get out before */	debug(F100," open cancelled","",0); /* destroying existing file. */	return(1);			/* Pretend to succeed. */    }    channel = ZOFILE;			/* SET DESTINATION DISK or PRINTER */    if (dest == DEST_S) {		/* SET DEST SCREEN... */	channel = ZCTERM;	fcb = NULL;    }    if (server && !en_cwd) {		/* If running as server */	zstrip(name,&name2);		/* and CWD is disabled, */	if (strcmp(name,name2)) {	/* check if pathname was included. */	    tlog(F110,name,"authorization failure",0L);	    debug(F110," openo authorization failure",name,0);	    return(0);	} else name = name2;    }    if (zopeno(channel,name,zz,fcb) == 0) { /* Try to open the file */	isopen = 0;	debug(F110,"openo failed",name,0);	tlog(F110,"Failure to open",name,0L);	return(0);    } else {	isopen = 1;	debug(F110,"openo ok, name",name,0);	return(1);    }}/*  O P E N T  --  Open the terminal for output, in place of a file  */intopent(zz) struct zattr *zz; {    ffc = tfc = 0L;    binary = XYFT_T;    return(zopeno(ZCTERM,"",zz,NULL));}/*  C L S I F  --  Close the current input file. */intclsif() {    int x = 0;#ifdef datageneral    if ((local) && (!quiet))    /* Only do this if local & not quiet */        if (nfils < 1)          /* More files to send ... leave it on! */            connoi_mt();#endif /* datageneral */    if (memstr) {			/* If input was memory string, */	memstr = 0;			/* indicate no more. */    } else x = zclose(ZIFILE);		/* else close input file. */    if (cxseen || czseen)		/* If interrupted */      screen(SCR_ST,ST_INT,0l,"");	/* say so */    else if (discard)			/* If I'm refusing */      screen(SCR_ST,ST_REFU,0l,refused); /* say why */    else {				/* Otherwise */	fstats();			/* update statistics */	screen(SCR_ST,ST_OK,0l,"");	/* and say transfer was OK */    }    hcflg = 0;				/* Reset flags */    sendstart = 0L;			/* Don't do this again! */#ifdef COMMENT/*  This prevents a subsequent call to clsof() from deleting the file  when given the discard flag.*/    *filnam = '\0';			/* and current file name */#endif /* COMMENT */    return(x);}/*  C L S O F  --  Close an output file.  *//*  Call with disp != 0 if file is to be discarded.  *//*  Returns -1 upon failure to close, 0 or greater on success. */intclsof(disp) int disp; {    int x;    debug(F101,"clsof disp","",disp);    if (fncsav != -1) {			/* Saved file collision action... */	fncact = fncsav;		/* Restore it. */	fncsav = -1;			/* Unsave it. */    }#ifdef datageneral    if ((local) && (!quiet))		/* Only do this if local & not quiet */        connoi_mt();#endif /* datageneral */    if ((x = zclose(ZOFILE)) < 0) {	/* Try to close the file */	tlog(F100,"Failure to close",filnam,0L);	screen(SCR_ST,ST_ERR,0l,"");    } else if (disp) {			/* Interrupted or refused */	if (keep == 0) {		/* If not keeping incomplete files */	    if (isopen &&		/* AND the file is actually open */		*filnam && (what & W_RECV)) /* AND we're receiving!!!... */	      zdelet(filnam);		    /* ONLY THEN, delete it */	    if (what != W_NOTHING) {		debug(F100,"Incomplete: discarded","",0);		tlog(F100," incomplete: discarded","",0L);		screen(SCR_ST,ST_DISC,0l,"");	    }	} else {			/* Keep incomplete copy */	    fstats();	    if (!discard) { /* Unless discarding for other reason... */		if (what != W_NOTHING) {		    debug(F100,"Incomplete: Kept","",0);		    tlog(F100," incomplete: kept","",0L);		}	    }	    if (what != W_NOTHING)	      screen(SCR_ST,ST_INC,0l,"");	}    } else {				/* Nothing wrong, just keep it */	debug(F100,"Closed","",0);	/* and give comforting messages. */	fstats();	screen(SCR_ST,ST_OK,0L,"");    }    rs_len = 0;    isopen = 0;				/* It's not open any more. */    cxseen = 0;				/* Reset per-file interruption flag */    return(x);				/* Send back zclose() return code. */}#ifdef SUNOS4S5tolower(c) char c; { return((c)-'A'+'a'); }toupper(c) char c; { return((c)-'a'+'A'); }#endif /* SUNOS4S5 */

⌨️ 快捷键说明

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