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

📄 ckcfns.c

📁 linux终端仿真程序
💻 C
📖 第 1 页 / 共 5 页
字号:
 Returns:   1 if send operation begins successfully   0 if send operation fails*/#ifdef DYNAMICchar *cmargbuf = NULL;#elsechar cmargbuf[256];#endif /* DYNAMIC */char *cmargp[2];VOIDfnlist() {    sndsrc = nfils;			/* Source for filenames */#ifdef DYNAMIC    if (!cmargbuf && !(cmargbuf = malloc(256)))	fatal("fnlist: no memory for cmargbuf");#endif /* DYNAMIC */    cmargbuf[0] = NUL;			/* Initialize name buffer */    debug(F101,"sinit nfils","",nfils);    debug(F110,"sinit cmarg",cmarg,0);    debug(F110,"sinit cmarg2",cmarg2,0);    if (nfils == 0) {			/* Sending from stdin or memory. */	if ((cmarg2 != NULL) && (*cmarg2)) {	    cmarg = cmarg2;		/* If F packet, "as-name" is used */	    cmarg2 = "";		/* if provided */	} else cmarg = "stdin";		/* otherwise just use "stdin" */	strcpy(cmargbuf,cmarg);	cmargp[0] = cmargbuf;	cmargp[1] = "";	cmlist = cmargp;	nfils = 1;    }}intsinit() {    int x;				/* Worker int */    char *tp, *xp, *m;			/* Worker string pointers *//*  The DECC prototype for sleep() moved from <signal.h> to <unistd.h>  in DECC 5.2, but rather than pull in an entire header file (that might  not even be there), potentially involving unwanted conflicts, just do this:*/  #ifdef __DECC#ifndef __DECC_VER			/* This exists only in 5.0 and above */    _PROTOTYP( int sleep, (unsigned) );#else#if __DECC_VER < 50200000    _PROTOTYP( int sleep, (unsigned) );#endif /* __DECC_VER */#endif /* __DECC_VER */#endif /* __DECC */    filcnt = filrej = 0;		/* Initialize file counters */    fnlist();    if (nfils < 0) {	xp = cmarg;    } else {#ifndef NOMSEND	if (addlist)	  xp = filehead->fl_name;	else#endif /* NOMSEND */	  xp = *cmlist;    }    x = gnfile();			/* Get first filename. */    m = NULL;				/* Error message pointer */    debug(F101,"sinit gnfil","",x);    switch (x) {      case -5: m = "Too many files match wildcard"; break;      case -4: m = "Cancelled"; break;      case -3: m = "Read access denied"; break;      case -2: m = "File is not readable"; break;      case -1: m = iswild(filnam) ? "No files match" : "File not found";	break;      case  0: m = "No filespec given!"; break;      default:	break;    }    debug(F101,"sinit nfils","",nfils);    debug(F110,"sinit filnam",filnam,0);    if (x < 1) {			/* Didn't get a file. */	if (server)			/* Doing GET command */	  errpkt((CHAR *)m);		/* so send Error packet. */	else				/* Doing SEND command */	  screen(SCR_EM,0,0l,m);	/* so print message. */	tlog(F110,xp,m,0L);		/* Make transaction log entry. */	freerbuf(rseqtbl[0]);		/* Free the buffer the GET came in. */	return(0);			/* Return failure code */    }    if (!local && !server && delay > 0)	/* OS-9 sleep(0) == infinite */      sleep(delay);			/* Delay if requested */#ifdef datageneral    if ((local) && (!quiet))            /* Only do this if local & not quiet */        consta_mt();                    /* Start the asynch read task */#endif /* datageneral */    freerbuf(rseqtbl[0]);		/* Free the buffer the GET came in. */    sipkt('S');				/* Send the Send-Init packet. */    ztime(&tp);				/* Get current date/time */    tlog(F110,"Transaction begins",tp,0L); /* Make transaction log entry */    tlog(F110,"Global file mode:", binary ? "binary" : "text", 0L);    tlog(F100,"","",0);    debug(F111,"sinit ok",filnam,0);    return(1);}int#ifdef CK_ANSICsipkt(char c)				/* Send S or I packet. */#elsesipkt(c) char c;#endif/* sipkt */ {    CHAR *rp; int k;    debug(F101,"sipkt pktnum","",pktnum);    k = sseqtbl[pktnum];		/* Find slot for this packet */    debug(F101,"sipkt k","",k);    if (k < 0) {			/* No slot? */	k = getsbuf(winlo = pktnum);	/* Make one. */	debug(F101,"sipkt getsbuf","",k);        }    ttflui();				/* Flush pending input. */    rp = rpar();			/* Get protocol parameters. */    return(spack(c,pktnum,(int)strlen((char *)rp),rp)); /* Send them. */}/*  X S I N I T  --  Retransmit S-packet  *//*  For use in the GET-SEND sequence, when we start to send, but receive another  copy of the GET command because the receiver didn't get our S packet.  This retransmits the S packet and frees the receive buffer for the ACK.  This special case is necessary because packet number zero is being re-used.*/VOIDxsinit() {    int k;    k = rseqtbl[0];    debug(F101,"xsinit k","",k);    if (k > -1)      freerbuf(k);    resend(0);}/*  R C V F I L -- Receive a file  *//*  Incoming filename is in data field of F packet.  This function decodes it into the srvcmd buffer, substituting an  alternate "as-name", if one was given.  Then it does any requested transformations (like converting to  lowercase), and finally if a file of the same name already exists,   takes the desired collision action.*/char ofn1[CKMAXPATH+1];			/* Buffer for output file name */char * ofn2;				/* Pointer to backup file name */int ofn1x;				/* Flag output file already exists */int opnerr;				/* Flag for open error */int					/* Returns success ? 1 : 0 */rcvfil(n) char *n; {#ifdef OS2#ifdef __32BIT__    char *zs, *longname, *newlongname, *pn; /* OS/2 long name items */#endif /* __32BIT__ */#endif /* OS2 */#ifdef DTILDE    char *dirp, *tilde_expand();#endif /* DTILDE */    int dirflg;    opnerr = 0;    ofn2 = NULL;			/* No new name (yet) */    lsstate = 0;			/* Cancel locking-shift state */    srvptr = srvcmd;			/* Decode file name from packet. */    decode(rdatap,putsrv,0);		/* Don't xlate charsets. */    if (*srvcmd == '\0')		/* Watch out for null F packet. */      strcpy((char *)srvcmd,"NONAME");#ifdef DTILDE    if (*srvcmd == '~') {	dirp = tilde_expand((char *)srvcmd); /* Expand tilde, if any. */	if (*dirp != '\0') strcpy((char *)srvcmd,dirp);    }#else#ifdef OS2    if (isalpha(*srvcmd) && srvcmd[1] == ':' && srvcmd[2] == '\0')      strcat((char *)srvcmd,"NONAME");#endif /* OS2 */#endif /* DTILDE */    screen(SCR_FN,0,0l,(char *)srvcmd);	/* Put it on screen if local */    debug(F110,"rcvfil",(char *)srvcmd,0); /* Debug log entry */    debug(F110,"rcvfil cmarg2",cmarg2,0);    tlog(F110,"Receiving",(char *)srvcmd,0L); /* Transaction log entry */    if (cmarg2) {			/* Check for alternate name */        if (*cmarg2) {	    debug(F110,"rcvfil substituting cmarg2",cmarg2,0);	    strcpy((char *)srvcmd,cmarg2); /* Got one, use it. */	}    }    cmarg2 = "";			/* Done with alternate name */    if ((int)strlen((char *)srvcmd) > CKMAXPATH) /* Watch out for overflow */      *(srvcmd + CKMAXPATH - 1) = NUL;    /* At this point, srvcmd[] contains the incoming filename or as-name */    if (fnrpath) {			/* RECEIVE PATHNAMES OFF? */	char *t;			/* Yes. */	zstrip((char *)srvcmd,&t);	/* Off with it. */	debug(F110,"rcvfil zstrip",t,0);	if (!t)				/* Be sure we didn't strip too much */	  strcpy(ofn1,"UNKNOWN");	else if (*t == '\0')	  strcpy(ofn1,"UNKNOWN");	else	  strcpy(ofn1,t);	strcpy((char *)srvcmd,ofn1);	/* Now copy it back. */    }    /* Now srvcmd contains incoming filename with path possibly stripped */    if (fncnv)				/* FILE NAMES CONVERTED? */      zrtol((char *)srvcmd,(char *)ofn1); /* Yes, convert to local form */    else      strcpy(ofn1,(char *)srvcmd);	/* No, copy literally. */    /* Now the incoming filename, possibly converted, is in ofn1[]. */#ifdef OS2    /* Don't refuse the file just because the name is illegal. */    if (!IsFileNameValid(ofn1)) {	/* Name is OK for OS/2? */#ifdef __32BIT__	char *zs = NULL;	zstrip(ofn1, &zs);		/* Not valid, strip unconditionally */	if (zs) {	    if (iattr.longname.len &&	/* Free previous longname, if any */		iattr.longname.val)	      free(iattr.longname.val);	    iattr.longname.len = strlen(zs); /* Store in attribute structure */	    iattr.longname.val = (char *) malloc(iattr.longname.len + 1);	    if (iattr.longname.val)	/* Remember this (illegal) name */	      strcpy(iattr.longname.val, zs);	}#endif /* __32BIT__ */	debug(F110,"rcvfil: invalid file name",ofn1,0);	ChangeNameForFAT(ofn1);	/* Change to an acceptable name */	debug(F110,"rcvfil: FAT file name",ofn1,0);    } else {				/* Name is OK. */	debug(F110,"rcvfil: valid file name",ofn1,0);#ifdef __32BIT__	if (iattr.longname.len &&	     iattr.longname.val)	/* Free previous longname, if any */	  free(iattr.longname.val);	iattr.longname.len = 0;	iattr.longname.val = NULL;	/* This file doesn't need a longname */#endif /* __32BIT__ */    }#endif /* OS2 */    debug(F110,"rcvfil as",ofn1,0);/* Filename collision action section. */    dirflg =				/* Is it a directory name? */#ifdef CK_TMPDIR        isdir(ofn1)#else	0#endif /* CK_TMPDIR */	  ;    debug(F101,"rcvfil dirflg","",dirflg);    ofn1x = (zchki(ofn1) != -1);	/* File already exists? */    debug(F101,"rcvfil ofn1x",ofn1,ofn1x);    if ( (#ifdef UNIX	strcmp(ofn1,"/dev/null") &&	/* It's not the null device? */#else#ifdef OSK	strcmp(ofn1,"/nil") &&	/* It's not the null device? */#endif /* OSK */#endif /* UNIX */	!stdouf ) &&			/* Not copying to standard output? */	ofn1x ||			/* File of same name exists? */	dirflg ) {			/* Or file is a directory? */        debug(F111,"rcvfil exists",ofn1,fncact);	switch (fncact) {		/* Yes, do what user said. */	  case XYFX_A:			/* Append */	    debug(F100,"rcvfil append","",0);	    if (dirflg) {		rf_err = "Can't append to a directory";		tlog(F100," error - can't append to directory","",0);		discard = opnerr = 1;		return(0);	    }	    tlog(F110," appending to",ofn1,0);	    break;	  case XYFX_Q:			/* Query (Ask) */	    break;			/* not implemented */	  case XYFX_B:			/* Backup (rename old file) */	    if (dirflg) {		rf_err = "Can't rename existing directory";		tlog(F100," error - can't rename directory","",0);		discard = opnerr = 1;		return(0);	    }	    znewn(ofn1,&ofn2);		/* Get new unique name */	    tlog(F110," backup:",ofn2,0);	    debug(F110,"rcvfil backup ofn1",ofn1,0);	    debug(F110,"rcvfil backup ofn2",ofn2,0);#ifdef OS2#ifdef CK_LABELED#ifdef __32BIT__/*  In case this is a FAT file system, we can't change only the FAT name, we  also have to change the longname from the extended attributes block.  Otherwise, we'll have many files with the same longname and if we copy them  to an HPFS volume, only one will survive.*/	    if (os2getlongname(ofn1, &longname) > -1) {		if (strlen(longname)) {		    char tmp[10];		    extern int ck_znewn;		    sprintf(tmp,".~%d~",ck_znewn);		    newlongname =		      (char *) malloc(strlen(longname) + strlen(tmp) + 1);		    if (newlongname) {			strcpy(newlongname, longname);			strcat(newlongname, tmp);			os2setlongname(ofn1, newlongname);			free(newlongname);			newlongname = NULL;		    }		}	    } else debug(F100,"rcvfil os2getlongname failed","",0);#endif /* __32BIT__ */#endif /* CK_LABELED */#endif /* OS2 */#ifdef COMMENT	    /* Do this later, in opena()... */	    if (zrename(ofn1,ofn2) < 0) {		rf_err = "Can't transform filename";		debug(F110,"rcvfil rename fails",ofn1,0);		discard = opnerr = 1;		return(0);	    }#endif /* COMMENT */	    break;	  case XYFX_D:			/* Discard (refuse new file) */	    discard = 1;	    rejection = 1;		/* Horrible hack: reason = name */	    debug(F101,"rcvfil discard","",discard);	    tlog(F100," refused: name","",0);	    break;	  case XYFX_R:			/* Rename incoming file */	    znewn(ofn1,&ofn2);		/* Make new name for it */#ifdef OS2#ifdef __32BIT__		if (iattr.longname.len) {		    char tmp[10];		    extern int ck_znewn;		    sprintf(tmp,".~%d~",ck_znewn);		    newlongname =		      (char *) malloc(iattr.longname.len + strlen(tmp) + 1);		    if (newlongname) {			strcpy(newlongname, iattr.longname.val);			strcat(newlongname, tmp);			debug(F110,			      "Rename Incoming: newlongname",newlongname,0);			if (iattr.longname.len &&			     iattr.longname.val)			  free(iattr.longname.val);			iattr.longname.len = strlen(newlongname);			iattr.longname.val = newlongname;		    }		}#endif /* __32BIT__ */#endif /* OS2 */	    break;	  case XYFX_X:			/* Replace old file */	    debug(F100,"rcvfil overwrite","",0);	    if (dirflg) {		rf_err = "Can't overwrite existing directory";		tlog(F100," error - can't overwrite directory","",0);		discard = opnerr = 1;#ifdef COMMENT		return(0);#else		break;#endif /* COMMENT */	    }	    tlog(F110,"overwriting",ofn1,0);	    break;	  case XYFX_U:			/* Refuse if older */	    debug(F100,"rcvfil update","",0);	    if (dirflg) {		rf_err = "File has same name as existing directory";

⌨️ 快捷键说明

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