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

📄 xnftp.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
			return;		}	}}listproc(attr)	FilingSubset1_AttributeSequence attr;{	int i;	char *thisname;	char *slash;	Boolean istemp = 0;	Boolean isdir = 0;	LongCardinal thistype = 0;	LongCardinal thissize = 0;	LongCardinal thisdate = 0;	FilingSubset1_AttributeType t;	char filetypestr[25];	char filetypebuf[20];	Cardinal thisversion = 0;	char *filedatestr;	char *ctime();	char *rindex();	files_found= TRUE;	for (i = 0; i < attr.length; i++) {		t = attr.sequence[i].type;		if (t == FilingSubset1_name || t == FilingSubset1_pathname)			thisname = AttrToString(&attr.sequence[i]);		else if (t == FilingSubset1_isDirectory)			isdir = AttrToBoolean(&attr.sequence[i]);		else if (t == FilingSubset1_isTemporary)			istemp = AttrToBoolean(&attr.sequence[i]);		else if (t == FilingSubset1_type)			thistype = AttrToLongCardinal(&attr.sequence[i]);		else if (t == FilingSubset1_dataSize)			thissize = AttrToLongCardinal(&attr.sequence[i]);		else if (t == FilingSubset1_version)			thisversion = AttrToCardinal(&attr.sequence[i]);		else if (t == FilingSubset1_createdOn) {			thisdate = AttrToLongCardinal(&attr.sequence[i]);			thisdate = thisdate - XNS_TIME_DIFFERENCE;			filedatestr= ctime(&thisdate);			filedatestr[24]= '\0';			filedatestr += 4;		}	}	strcpy(filetypestr, "(");	strcat(filetypestr, typetostring(thistype));	strcat(filetypestr, ")");	if ( (slash= rindex(thisname, '/')) == NULL )		slash= thisname;	else		slash++;	fprintf(fout, "%c%c%-16s%7ld %s %s",		isdir?'D':' ', istemp?'T':' ',		filetypestr, thissize, filedatestr, slash);	if ( thisversion != 0)		fprintf(fout,"!%d",thisversion);	fprintf(fout,"\n");	clear_String(&thisname);}/* *	process used by retrieve to get file type, createdOn and pathname */rlistproc(attr)	FilingSubset1_AttributeSequence attr;{	int i;	char *thisname;	FilingSubset1_AttributeType t;	char *AttrToString();	files_found= TRUE;/* *	Xerox file servers will return all versions of the requested file in *	ascending version order. We assume that the last version will be the *	highest and remember that name so that the retrieve will pull the *	highest version of the file. If we request just the file with no *	version, the server will return the oldest version (not what I would *	expect...) */	for (i= 0; i < attr.length; i++) {		t= attr.sequence[i].type;		if (t == FilingSubset1_createdOn) {		    	gettimeofday(&timbuf[0],(struct timezone *)0);			timbuf[1].tv_sec= AttrToLongCardinal(&attr.sequence[i]) - XNS_TIME_DIFFERENCE;			timbuf[1].tv_usec= 0;		} else if (t == FilingSubset1_type) {		    	if (typevalue == TYPE_Guess) {				filetypevalue= AttrToLongCardinal(&attr.sequence[i]);			} 		} else if (t == FilingSubset1_pathname) {			thisname= AttrToString(&attr.sequence[i]);			if (verbose) {				printf("%s to ", thisname);				fflush(stdout);			}			clear_String(&thisname);		} else if (t == FilingSubset1_isDirectory) {			is_a_directory= AttrToBoolean(&attr.sequence[i]);		}	}}cdproc(attr)	FilingSubset1_AttributeSequence attr;{    	char *AttrtoString();	char *dest;	int i;	files_found= TRUE;	dest= 0;	for (i= 0; i < attr.length; i++) {	    	if (attr.sequence[i].type == FilingSubset1_isDirectory		    && AttrToBoolean(&attr.sequence[i])) {				isdir= TRUE;			/* if directory, change handles */		}		if (attr.sequence[i].type == FilingSubset1_pathname)			dest= AttrToString(&attr.sequence[i]);	}	if (!isdir || dest == 0) {	/* if no directory or pathname */		isdir= FALSE;		/* assume failure */	}}#define MAXPACKS 20staticGetAttributeSequences(conn)	CourierConnection *conn;{	int count, i;	Unspecified buffer[MAXWORDS*MAXPACKS], *bp, *bufend;	FilingSubset1_StreamOfAttributeSequence attrs;	Boolean overflow= FALSE;		files_found= FALSE;	bufend = buffer;	bp = buffer+((MAXWORDS-1)*MAXPACKS);    /* end of available space */	while ((count = BDTread(conn, (char*)bufend, 				MAXWORDS*sizeof(Unspecified))) > 0) {		bufend += count/sizeof(Unspecified);		bytessent += count;		if (bufend > bp) {			fprintf(stderr,"BDT read too big to fit\n");			BDTabort(conn);			/* should clear out stuff here if we knew how much			 * fall back to previous block on the assumption			 * we can give a truncated list			 */			bufend -= count/sizeof(Unspecified);			overflow=TRUE;		}	}	bp = buffer;	while (bp < bufend) {		bp += internalize_FilingSubset1_StreamOfAttributeSequence(&attrs,bp);		if (0 == (int) attrs.designator) {		   for (i=0; i < attrs.nextSegment_case.segment.length; i++) {			(*ProcEachSeq)(				attrs.nextSegment_case.segment.sequence[i]);		   }		   free(attrs.nextSegment_case.segment.sequence);		} else {		   for (i = 0; i < attrs.lastSegment_case.length; i++) {			(*ProcEachSeq)(				attrs.lastSegment_case.sequence[i]);		   }		   free(attrs.lastSegment_case.sequence);		   return;		}	}	if ( overflow ) {		fprintf(stderr, "\nListing was truncated due to internal bulk data buffer size\n");		overflow= FALSE;	}}intgetBDTch(conn,bpp)	CourierConnection *conn;	u_char **bpp;{	static u_char buffer[SPPMAXDATA];	static int count;	if (*bpp == NULL) {*bpp = buffer; count = 0;}	if (*bpp >= buffer+count) {		count=BDTread(conn,buffer,sizeof(buffer));		*bpp = buffer;	}	if (count <= 0) return(EOF);	else return(*((*bpp)++));		}retrieveproc(conn)	CourierConnection *conn;{	int count, ocount, ch, hashbytes;	char buffer[SPPMAXDATA];	int charset, charset16;	char *bp;	switch (filetypevalue) {	default :		errno = ocount = 0;		fflush(fout);		while ((count = BDTread(conn, buffer, sizeof(buffer))) > 0) {			if ((ocount = write(fileno(fout),buffer,count)) < 0) {				perror("write");				BDTabort(conn);				break;			}			bytessent += count;			if (hash) {				putchar('#');				fflush(stdout);			}		}		if (count < 0) perror("netin");		break;	case TYPE_VPMailNote :	case TYPE_A :		charset = 0; charset16 = 0; bp = NULL;		hashbytes = 0;		while ((ch = getBDTch(conn,&bp)) != EOF) {			if (ch == '\377') {				ch = getBDTch(conn,&bp);				if (ch == '\377') charset16 = 1;				else charset = ch;				continue;			}			if (charset16) {				charset = ch;				ch = getBDTch(conn,&bp);			}			switch (charset) {			case 0:	/* normal character set -- minimal xlation */				if (ch == '\r') {				    	int nextch;				    	putc('\n',fout);					bytessent++;				    	if ( (nextch = getBDTch(conn,&bp)) != '\n'){					    if (nextch == '\r')						putc('\n',fout);					    else if ( nextch == ','+0200 ) 						putc('_',fout);					    else if ( nextch != EOF )				    		putc(nextch,fout);					    else						continue;					}				    	bytessent= bytessent++;					while (hash && bytessent >= hashbytes){						putchar('#');						fflush(stdout);						hashbytes += sizeof(buffer);					}					break;				}				else if (ch == ','+0200) ch = '_';				/* more mapping here */				putc(ch,fout);				bytessent++;				break;			default:				break; /* ignore */			}		}		if (hash) {			while (bytessent >= hashbytes) {				putchar('#');				hashbytes += sizeof(buffer);			}			putchar('\n');			fflush(stdout);		}		/* if (count < 0) perror("netin"); */		break;	}}storeproc(conn)	CourierConnection *conn;{	int count, ocount;	u_char buffer[SPPMAXDATA];	u_char *bp;	errno = ocount = 0;	clearerr(fin);	switch (filetypevalue) {	default :		while ((count = fread(buffer, sizeof(char), SPPMAXDATA, fin)) > 0		       && (ocount = BDTwrite(conn, buffer, count)) > 0) {			bytessent += count;			if (hash) {				putchar('#');				fflush(stdout);			}		}		break;	case TYPE_VPMailNote :	case TYPE_A :		while ((count = fread(buffer, sizeof(char), SPPMAXDATA, fin))		       > 0) {			ocount = count;			for (bp = buffer; count > 0; count--, bp++) {				if (*bp == '\n') *bp = '\r';				else if (*bp == '_') *bp = ','+0200;				/* more translations here */			}			if ((ocount = BDTwrite(conn, buffer, ocount)) <= 0)				break;			bytessent += ocount;			if (hash) {				putchar('#');				fflush(stdout);			}		}		break;	}	if (ocount < 0) {		BDTabort(conn);		perror("netout");	}	else if (ferror(fin)) {		BDTabort(conn);		perror("fread");	}	else		BDTclosewrite(conn);}isdirproc(attr)	FilingSubset1_AttributeSequence attr;{	int i;	char *name;	FilingSubset1_AttributeType t;	for ( i= 0; i < attr.length; i++ ) {		t= attr.sequence[i].type;		if ( t == FilingSubset1_isDirectory ) {			isdir= AttrToBoolean(&attr.sequence[i]);		} else if ( t == FilingSubset1_pathname ) {			name= AttrToString(&attr.sequence[1]);			strcpy(cur_pathname, name);			clear_String(&name);		}	}}deleteproc(attr)	FilingSubset1_AttributeSequence attr;{	int i;	char *name;	struct name_entry *entry;	FilingSubset1_AttributeType t;	if ( name_count > name_size ) {		name_size += MAXNAMES;		name_list= (struct name_entry *) realloc(name_list, 				sizeof(struct name_entry) * name_size);	}	entry= &name_list[name_count];	for ( i= 0; i < attr.length; i++ ) {		t= attr.sequence[i].type;		if ( t == FilingSubset1_type ) {			entry->type= AttrToLongCardinal(&attr.sequence[i]);		} else if ( t == FilingSubset1_pathname ) {			entry->pathname= AttrToString(&attr.sequence[1]);		}	}	name_count++;}GetAllAttributes(attr)	FilingSubset1_AttributeSequence attr;{	int i;	char *thisname;	FilingSubset1_AttributeType t;	int got_createdon, got_type, got_pathname;	files_found= TRUE;	got_createdon= got_pathname= got_type= 0;/* *	Xerox file servers will return all versions of the requested file in *	ascending version order. We assume that the last version will be the *	highest and remember that name so that the retrieve will pull the *	highest version of the file. If we request just the file with no *	version, the server will return the oldest version (not what I would *	expect...) */	for (i= 0; i < attr.length; i++) {	    	t= attr.sequence[i].type;		if (t == FilingSubset1_createdOn) {		    	gettimeofday(&timbuf[0],(struct timezone *)0);			timbuf[1].tv_sec= AttrToLongCardinal(&attr.sequence[i]) - XNS_TIME_DIFFERENCE;			timbuf[1].tv_usec= 0;			got_createdon++;		} else if (t == FilingSubset1_type) {		    	if (typevalue == TYPE_Guess) {				filetypevalue= AttrToLongCardinal(&attr.sequence[i]);			} 			got_type++;		} else if (t == FilingSubset1_pathname) {			thisname= AttrToString(&attr.sequence[i]);			strcpy(cur_pathname, thisname);			clear_String(&thisname);			got_pathname++;		} 		if ( got_createdon && got_type && got_pathname )			break;	}	SaveExtendedAttributes(fout, attr);	return;}

⌨️ 快捷键说明

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