scantape.c

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

C
1,286
字号
#ifndef lintstatic char *sccsid = "@(#)scantape.c	4.1	ULTRIX	7/17/90";#endif	lint/**************************************************************** *								* *			Copyright (c) 1985 by			* *		Digital Equipment Corporation, Maynard, MA	* *			All rights reserved.			* *								* *   This software is furnished under a license and may be used * *   and copied  only  in accordance with the terms of such	* *   license and with the  inclusion  of  the  above  copyright * *   notice. This software  or  any  other copies thereof may	* *   not be provided or otherwise made available to any other	* *   person.  No title to and ownership of the software is	* *   hereby transferred.					* *								* *   The information in this software is subject to change	* *   without  notice  and should not be construed as a		* *   commitment by Digital  Equipment Corporation.		* *								* *   Digital assumes  no responsibility   for  the use  or	* *   reliability of its software on equipment which is not	* *   supplied by Digital.					* *								* ****************************************************************//**//* * *	File name: * *		scantape.c * *	Source file description: * *		This module "scans" ( ie.  READS )  the input volume *		when an  eXtract or Table of contents function has *		been requested of the LTF. * *	Functions: * *		date_time()	Fills a given 'sdate' string with *				the appropriate month, day, and *				modification time. * *		date_year()	Fills a given 'sdate' string with *				the appropriate month, day, and *				year. * *		expand_mode()	Expands the uid and gid mode fields *		    expandm()	for print out on TABLE or EXTRACT *				functions. * *		scantape()	Top level logic to read the Volume * *		wbadlab()	Writes out "bad" label data encountered * *	Usage: * *		n/a * *	Compile: * *	    cc -O -c scantape.c		 <- For Ultrix-32/32m * *	    cc CFLAGS=-DU11-O scantape.c <- For Ultrix-11 * * *	Modification history: *	~~~~~~~~~~~~~~~~~~~~ * *	revision			comments *	--------	----------------------------------------------- *	 01.0		20-Apr-85	Ray Glaser *			Create orginal version * *	 01.1		4-Sep-85	Suzanne Logcher *			Add interchange name to TABLE w/o v or V *			Change use of position number to table or  *			   extract files *			Correct use of Noheader3	 *//* * ->	Local Includes */#include "ltfdefs.h"/**//* * * Function: * *	date_time * * Function Description: * *	Fills the string 'sdate' with the appropriate *	month, day, and modification time. * * Arguments: * *	char	*sdate		The string to be filled *	long	*sec		Source of the time.. * * Return values: * *	The string given is date/time filled. * * Side Effects: * *	none	 */date_time(sdate, sec)	char	*sdate;	long	*sec;{/* * +--> Local Variables */int	century;long	clock;char	*ctime();long	rettime;int	thisyear;struct	tm *localtime();struct	tm *ltime;long	time();/*------*\   Code\*------*/rettime = time(&clock);ltime =	localtime(&rettime);thisyear = ltime->tm_year;ltime = localtime(sec);if (ltime->tm_year == thisyear)	sprintf(sdate, "%s %2d %02d:%02d", Months[ltime->tm_mon + 1],		ltime->tm_mday, ltime->tm_hour, ltime->tm_min);else {	cp = ctime(sec);	if (cp[20] == '2' && cp [21] == '0')	    century = 2000;	else {	    if (cp[20] != '1' || cp[21] != '9')		PERROR "\n%s: %s\n", Progname, BADCENT);	    century = 1900;	}	sprintf(sdate, "%s %2d  %4d", Months[ltime->tm_mon + 1],		ltime->tm_mday, ltime->tm_year + century);}}/*E date_time() *//**//* * * Function: * *	date_year * * Function Description: * *	Fills the given string with the appropriate month, *	day, and year. * * Arguments: * *	char	*sdate *	char	*century *	char	*date * * Return values: * *	String is filled with .. etc..  * * * Side Effects: * *	none *	 */date_year(sdate, century, date)	char	*sdate, *century, *date;{/* * +--> Local Variables */int	leap;int	year;int	yearday;int	realyear;/*------*\   Code\*------*/sscanf(date, "%2d%3d", &year, &yearday);if (*century == '0')    i = 2000 + year;else    if (*century != ' ')	PERROR "\n%s: %s\n", Progname, BADCENT);    i = 1900 + year;	realyear = i;leap = i%4 == 0 && i%100 != 0 || i%400 == 0;for (i= 0; yearday > Days[leap][i]; i++)	yearday -= Days[leap][i];sprintf(sdate, "%s %2d  %4d", Months[i], yearday, realyear);}/*E date_year();/**//* * * Function: * *	expand_mode, expandm * * Function Description: * *	These siamese functions expand and print the 9 mode *	fields of an Ultrix  uid / gid  file status. * * Arguments: * *	int	mode	Word containing the  st_mode value * * Return values: * *	The ASCII representation of the uid/gid is printed *	on stdout. * * Side Effects: * *	none	 */expand_mode(mode)int	mode;{/* * +--> Local Variables */register int **mp;/*------*\   Code\*------*/for (mp = &M[0]; mp < &M[9]; )	expandm(*mp++, mode);}/*E expand_mode() *//* * Sub-function: * *  expandm		Determines the status of the next mode field. *			This function is a sub-function used only for *			the above expand_mode function. It was done *			this way for ease of implementation. */expandm(choices, mode)	int	*choices; /* Number of choices for this field */	int	mode;{/* * +--> Local Variables */register int	*ch;/*------*\   Code\*------*/ch = choices;i = *ch++;while (--i >= 0 && (mode & *ch++) == 0)	ch++;printf("%c", *ch);}/*E expandm()/**//* * Function: * *	scantape * * Function Description: * *	This function is the top level logic to read a volume *	for the  TABLE  and  EXTRACT  functions. * * Arguments: * *	No direct arguments are passed. However the logic depends *	on flag variables set by the main-line logic to take the  *	correct actions. * * Return values: * *	This function does not return to the caller.  Wether or not *	the operation was successful, the function exits to system *	control. If an error occurs, a message is output to stderr. * * Side Effects: * *	none */scantape(){/* * ->	Local variables */int	Bufoff;		/* Buffer offset read from HDR2 (51-52) */char	cat_misc[20];	/* misc message buf */long	charcnt;	/* Character count of binary files.			 * A precaution  in case the last character			 * of a binary file is the same as the			 * the padding character. */struct	FILESTAT *fstat;int	getlen();	/* Declare getlen proc. to get length of F 			 * or S record */int	gid;		/* Group id */int	hlink;		/* Field in HDR2, if set, file has hard link */int	linkflag;	/* Set if link() is successful */int	lnk_fseqno;	/* File sequence no. of head link file */char	lnk_msg[30];	/* Used to output Hard/Symbolic link msgs */char	lnk_name[MAXPATHLEN+1];/* File name of head link file */struct	XLINKBUF *lp;char	pathname[MAXPATHLEN+1]; /* temporary variable */int	mode;		/* File mode */long	modtime;	/* Modification time of file. */int	nbytes;long	ret;long	save;char	sdate[13];	/* Creation-date string */int	skip;		/* Position number skip counter */char	sysvol[14];	/* Holds copy of VOL1 L_systemid */int	uid;		/* User id */int	wildc = NO;char	Xname[MAXPATHLEN+1]; /* alternate file name from xtract */long	xtractf();/*------*\   Code\*------*//*** *	READ / PROCESS  +-->  VOL1 ***//* Initialize lp just in case */lp = (struct XLINKBUF *) NULL;if ((i = read(fileno(Magtfp), Labelbuf, BUFSIZE)) <= 0) {	PERROR "\n%s: %s VOL1 (%s)%c\n", Progname, CANTRL, Magtdev, BELL);	perror(Magtdev);	if (i < 0)	    ceot();	exit(FAIL);}	L_labid[0] = 0;sscanf(Labelbuf, "%3c%1d%6c%14c%13c%14c",	L_labid, &L_labno, L_volid, Dummy, L_systemid, L_ownrid);strcpy(sysvol, L_systemid);if (strncmp(L_labid, "VOL",3)) {	PERROR "\n%s: %s VOL1%c\n", Progname, INVLF, BELL); 	/*	 * Go display the bad data and exit.	 */	wbadlab();}/* * First VOLume label number should always be 1. */if (L_labno != 1) {	PERROR "\n%s: %s%d\n", Progname, INVLFW, L_labno, BELL);}/* * Pick up, save, & verify the ANSI version number of this volume. */Ansiv = Labelbuf[79];if (Ansiv != '3' && Ansiv != '4') {	PERROR "\n%s: %s VOL1 %s-> %c%c\n", Progname, INVLF,	  UNSAV, Ansiv, BELL);	wbadlab();}/* Save volume id. */strcpy(Volid, L_volid);/*	*-*  NOTE  *-* *	     ---- * If we see an ANSI version 4 tape, we may have to: *** *	READ +-->  VOL2 - VOL9		(if present) * * For both 3/4 we may have: * *	READ +-->  UVL1 - UVL9		(if present) ***//**//* *	SCAN the TAPE -- and do what is required for an * *		EXTRACT or TABLE  function.. * */skip = 1;FOREVER {    charcnt		= 0L;    linkflag	= FALSE;    modtime		= 0L;    pathname[0]	= 0;

⌨️ 快捷键说明

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