scantape.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,286 行 · 第 1/3 页

C
1,286
字号
			    		perror(Progname);					printf("\n");				}			}/*E if Func != TABLE */			/* Skip to EOF1			*/			fsf(1);		}/*E if !strcmp(Tfypes, "sym") && Ultrixvol) */		if ((Func == TABLE) && !linkflag) {			/* Skip to start of EOF labels	 	 	 */			fsf(1);		}		/*		 * Is this file hard linked to another file ?		 */		if (lnk_fseqno && Ultrixvol) {			int found = 0;			strcpy((char*)lnk_msg,HLINKTO);			for (lp = X_head; lp; lp = lp->x_next) {				if (lp->x_fseqno == lnk_fseqno) {					found++;					linkflag = YES;					strcpy(lnk_name,lp->x_pathname);					break;				}			}/*E for lp = X_head ..*/			if (!found)				PERROR "\n%s:  %s %s\n%s%c\n", Progname,CANTL1,Name,MHL,BELL);			if (found && (Func == EXTRACT)) {				unlink(Name);				if (link(lnk_name, Name) < 0) {			    		PERROR "\n%s: %s -> %s\n    to -> %s%c\n", Progname, CANTLF, Name, lnk_name, BELL);					perror(Progname);					printf("\n");			    		linkflag = NO;				}				else {					/* If link found, skip to next					 * EOF1?					 */					fsf(1);				}			}/*E if found */		}/*E if lnk_fseqno ..*/		if (!lnk_fseqno && hlink && Ultrixvol) {		    lp = (struct XLINKBUF *) malloc(sizeof(*lp));		    if (!lp) {			PERROR "\n%s: %s%c\n", Progname,NOMEM,BELL);		    	exit(FAIL);		    }/*E if !lp */		    /* Save enough information about this file	 	     * in order to identify it in case there are	 	     * other files linked to it on the input volume.	 	     */		    lp->x_next = X_head; /* Pointers run backward ! */		    X_head = lp;		    lp->x_fseqno = L_fseqno;		    lp->x_fsecno = L_fsecno;		    lp->x_pathname = (char *) malloc(strlen(Name) + 1);		    if (!lp) {			PERROR "\n%s: %s%c\n", Progname,NOMEM,BELL);		    	exit(FAIL);		    }/*E if !lp */		    else			strcpy(lp->x_pathname, Name);		}/*T if (!lnk_fseqno && hlink %% Ultrixvol) *//**/		if (Func == EXTRACT && Numrecs && fstat->f_flags) {			if (fstat->f_flags & FUF && fstat->f_flags & DD) {				PERROR "\n%s: %s\n", Progname, MS1);				exit(FAIL);			}								if (fstat->f_flags & FUF) {				if (L_recformat == VARIABLE)	    				L_recformat = FUF;				else {	    				PERROR "\n%s: %s\n", Progname, MS2);					exit(FAIL);				}			}/*E if fstat->f_flags & FUF */			if (fstat->f_flags & DD) {				if (L_recformat == VARIABLE)	    				L_recformat = DD;				else {	    				PERROR "\n%s: %s\n", Progname, MS3);					exit(FAIL);				}			}/*E if fstat->f_flags & DD */			}/*E if (Func == EXTRACT && Numrecs && fstat->f_flags) *//**/		if (Func == EXTRACT && !linkflag) {			Xname[0] = 0;		 	ret = xtractf(pathname, ! Numrecs || isdir ? "" : fstat->f_src, charcnt, Xname);			if (Xname[0] != 0)			    strcpy(Name, Xname);			if (ret >= 0L && !strcmp(L_systemid, IMPID)) {				if (permission == TRUE) {				    chmod(Name, mode);				    chown(Name, uid, gid);				}				if (modtime > 0L) {					time_t	timep[2];					timep[0] = time((long *)NULL);					timep[1] = modtime;					utime(Name, timep);				}/*E if modtime > 0L */			}/*E if (ret >= 0L && ! strcmp(L_systemid, IMPID)) */			if ( !linkflag  && (lp != NULL)) {				if (ret < 0L) {#if 0					X_head = lp->x_next;					free((char*)lp);#endif					continue;				}				else if (Xname[0] != 0 && !Wildc)					strcpy(lp->x_pathname, Xname);			}/*E if !linkflag && lp */			/* Stop processing any files with	 	 	 * ret < 0L that haven't been caught	 	 	 * before this.  e.g., non-head link	 	 	 * files that were not extracted.	 	 	 */			if (ret < 0L)				continue;			}/*E if (Func == EXTRACT && ! linkflag) *//**/		if ((nbytes = read(fileno(Magtfp), Labelbuf, BUFSIZE)) < 0){			PERROR "\n%s: %s EOF1\n", Progname, CANTRL);		        ceot();		}		sscanf(Labelbuf, "%3s%1d%*50c%6ld", L_labid,			&L_labno, &L_nblocks);		if (strcmp(L_labid, "EOF") || L_labno != 1) {			PERROR "\n%s: %s EOF1\n", Progname, INVLF);			wbadlab();		}		/*	 	 *	Skip over the rest of the "EOF" label	 	 *	set ...  for the TIME BEING !!	 	 */		fsf(1);			if (Func == TABLE) {			if (Verbose) {			    /*			     * If this file is not a directory file,			     * list it. If it is a directory file and			     * the user really wants to see it (them),			     * list the name. Else, directory files			     * are not listed.			     */			    if (strcmp(Tftypes,"dir") || Dverbose) {				sprintf(cat_misc, "t(%d,%d)",					L_fseqno, L_fsecno);				printf("%-7s", cat_misc);					/* If this is not an Ultrix volume.			 	 */				if (strcmp(L_systemid, IMPID))					printf("---------   -/-   ");				else {					expand_mode(mode);					printf("%4d/%-4d%s", uid, gid, Owner);				}				if (modtime > 0L)					date_time(sdate, &modtime);				else					date_year(sdate, &L_crecent, L_credate);						printf("%12s", sdate);				if (!Ultrixvol) {					sprintf(cat_misc, "%ld(%d)%c", L_nblocks,			    		L_blklen, L_recformat);					printf("%11s", cat_misc);				}/*T if !Ultrixvol */				else {					if (strcmp(Tftypes,"dir"))					    sprintf(cat_misc,"  %04ld bytes  <%s>%c",				    	    charcnt,Tftypes,L_recformat);					else 					     /* Directory files are					      * always 0000 bytes long,					      * so don't bother to list					      * the size.					      */					    sprintf(cat_misc,"              <%s>%c",					    Tftypes,L_recformat);					printf("%s", cat_misc);				}/*F if !Ultrixvol */				/* For loong path names..			 	 */				if (strlen(Name) > 12)					printf("\n       %s", Name);				else					printf(" %s", Name);						if (linkflag)			    		printf("\n      %s %s\n", lnk_msg, lnk_name);				else			    		if (strcmp(Tftypes,"dir") || Dverbose) 						printf ("\n");			   }/*E if strcmp(Tftypes .. */			}/*E if (Verbose) */			else {			    /*			     * If this file is not a directory file,			     * list it. If it is a directory file and			     * the user really wants to see it (them),			     * list the name. Else, directory files			     * are not listed.			     */			    if (strcmp(Tftypes,"dir") || Dverbose) {				printf("t  %s", Name);				if (!Noheader3)				    printf("  (%s %s)\n", INTERCH, L_filename);				else				    printf ("\n");			    }			}		}/*T if (Func == TABLE) */		else {			/*		 	 * Func == EXTRACT		 	 */			if (Verbose) {			    /*			     * If this file is not a directory file,			     * list it. If it is a directory file and			     * the user really wants to see it (them),			     * list the name. Else, directory files			     * are not listed.			     */			    if (strcmp(Tftypes,"dir") || Dverbose || Dircre) {				if (linkflag)					printf("x<%s>%c %04ld byte%c,  %s  %s %s\n", 					Tftypes, L_recformat, charcnt, 					charcnt == 1 ? ' ' : 's', Name, 					lnk_msg, lnk_name);				else {#if 0	/* If we want to see how many tape blocks, put this back in.	 */				printf("x<%s>%c %04ld byte%c, %03ld %d-byte tape block%c  %s\n\n",				Tftypes,L_recformat,				ret, ret == 1 ? ' ' : 's',				L_nblocks, L_blklen,				L_nblocks == 1L ? ' ' : 's',				Name);#endif					/* If not a directory file, list					 * its size in bytes, else not.					 * Directory files are always					 * 0000 bytes long and when					 * using the Dverbose mode, they					 * tend to cloud the output.					 */					if (strcmp(Tftypes,"dir"))					    printf("x<%s>%c %04ld byte%c,  %s\n",					    Tftypes,L_recformat,					    ret, ret == 1 ? ' ' : 's', Name);					else					    if (Dverbose) {					    	printf("x<%s>%c              %s",Tftypes,L_recformat,Name); 						if (Dircre)						    printf(" %s\n",DIRCRE);						else						    printf("\n");					    }				}			    }/*E if strcmp(Tftypes .. */			}/*T if Verbose (Func = EXTRACT) */			else {				/* Func == EXTRACT			 	 * not verbose..			 	 */			    if (strcmp(Tftypes,"dir") || Dverbose)				printf("x  %s\n", Name);			}/*F if Verbose (Func = Extract) */			if ((charcnt != ret) && Ultrixvol && !linkflag) 				PERROR "\n%s: %s %s\n%s %ld %s %ld%c\n\n",			  	Progname, BADCNT1, Name, BADCNT2, charcnt, BADCNT3, ret, BELL);			Dircre = FALSE;		}/*F if Func == TABLE *//**//* The following logic was added as a result of a QPR on "rdt".  * It complained that when only 1 distinct file was given for * an extract, the entire tape was searched for all copies. * This was true. VMS tape routines & tar do the same thing however. * But, this loses if you have a large number of files on tape.  * ie. It takes a long time to read 1300 files looking for all copies.  * As the user may specify, via wildcards (* and ?), that all * copies are desired, the following logic was added to stop * the extract on the first instance of the requested file. */	    if (Numrecs) {		cp = fstat->f_src;		while (*cp && *cp != '\n') {	    		if ((*cp == '*') || (*cp == '?')) {				wildc = YES;				break;	    		}	    		cp++;		}/*E while *cp ..*/		if (!wildc && !isdir) {			free((char*)fstat->f_src);			fstat->f_src = (char *) malloc (12);			if (!fstat->f_src) {			    PERROR "\n%s: %s%c\n", Progname,NOMEM,BELL);		    	    exit(FAIL);			}	    		strcpy(fstat->f_src,"1extracted1");	    		fstat->f_numleft =0;			Numrecs--;	    		if (!Numrecs) {				for (fstat = F_head; fstat; fstat = fstat->f_next) {					if (!fstat->f_found) {					    if (!Seqno)					    	PERROR "%s: %s %s\n", Progname,NOTONV, fstat->f_src);					    else					    	PERROR "%s: %s %s\n", Progname,NOTONP, fstat->f_src);					    cat_misc[0] = '\n';					}				}/*E for fstat ..*/				fprintf(stderr,"%c",cat_misc[0]);    	    			if (Seqno && skip <= Seqno) {	    			    PERROR "\n%s: %s %s\n", Progname, CANTFSF, Magtdev);	    			    perror(Magtdev);				    printf("\n");	    			    exit(FAIL);	    			}				printf("\n");				exit(SUCCEED);			}		}/*E if !wildc */	    }/*T if (Numrecs) */	}/*T if (! Numrecs || (!(fstat = Lookup(Name))))*/ 	else {	    /* Getting here implies that the user has specified	     * a list of names to be extracted, or tabled &	     * the current file on the input volume is not one	     * of the ones about which the user is concerned.	     * The fsf (Forward Space File) will skip over the	     * file and its' ANSI label sets (header & trailer)	     * and place a pointer at the next HDR1 or the end.	     */	    fsf(2);	}}/*E FOREVER loop */}/*E scantape() *//**//* * * Function: * *	wbadlab * * Function Description: * *	This function saves a lot of repetative code by *	outputting the common information for all bad *	labels encountered. * * Arguments: * *	None * * Return values: * *	None, the function always exits to system control. * * Side Effects: * *	None *	 */wbadlab(){/* * +--> Local Variables */int i;/*------*\   Code\*------*/	PERROR "\n%s: %s\n", Progname, INVLD);for (i=0; i < BUFSIZE+1; i++) {	if (Labelbuf[i] < ' ' || Labelbuf[i] > '~') Labelbuf[i] = ' ';}(void) filter_to_a(Labelbuf, IGNORE_ERRORS);PERROR "%s", Labelbuf);PERROR "\n%s: %s\n", Progname, EINVLD);exit(FAIL);}/*E wbadlabd() *//**\\**\\**\\**\\**\\**  EOM  scantape.c  **\\**\\**\\**\\**\\*//**\\**\\**\\**\\**\\**  EOM  scantape.c  **\\**\\**\\**\\**\\*/

⌨️ 快捷键说明

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