ltf.c

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

C
817
字号
				 * volume				 */			case 'o':				Nodir = TRUE;				break;				/* No HDR3 switch will not output				 * optional headers 3 thru 9				 */			case 'O':				Noheader3 = TRUE;				break;				/* Permission flag, set when extracting				 * files and super user, will change				 * owner and mode to info on tape volume				 */			case 'p':				permission = TRUE;				break;				/* Verbose - give the user more				 * information about what is going				 * to/from a volume, not including				 * directories.				 */			case 'v':				Verbose = YES;				break;				/* Big Verbose also provides information				 * about directory files on the volume				 * as well as the normal Verbose				 * information about files.				 */			case 'V':				Verbose = Dverbose = YES;				break;				/* Set warning on if a file of the same				 * name exists				 */			case 'w':				Warning = YES;				break;				/* Select an alternate unit number.		 		 */			case '0':			case '1':			case '2':			case '3':			case '4':			case '5':			case '6':			case '7':			case '8':			case '9':#ifdef U11				unit = *a;#else				if (unit_nums < 2) {				    unit[unit_nums] = *a;				    unit_nums++;				}				else {				    PERROR "\n%s: %s\n\n", Progname, INVUNIT);				    exit(FAIL);				}#endif				break;				/* Set new blocksize by input				 */				case 'B': 				if (*argv == 0) {					PERROR "\n%s: %s\n", Progname, NOBLK);					usage();				}				nmbr1 = *argv;				Blocksize = expnum(nmbr1);				if (error_status) {					PERROR "\n%s: %s %s\n\n", Progname, INVNF, nmbr1);					exit(FAIL);				}				if (Blocksize > MAXBLKWRT || Blocksize < MINBLKSIZE) {					PERROR "\n%s: %s %d%s\n\n", Progname, INVBS, MAXBLKWRT, BYTES);					exit(FAIL);				}				*argv++;				argc--;				break;					/* Get devicefilename argument				 */			case 'f': 				if (*argv == 0) {					PERROR "\n%s: %s\n", Progname, NOFIL);					usage();				}				else				    /*				     * The name following 'f' is used				     * literally as the tape device name				     */				    if (strlen(*argv) < MAXNAMLEN)				   	strcpy(magtape, *argv++);				    else {					    	PERROR "\n%s: %s %s\n\n", Progname, FNTL, a);				    	exit(FAIL);				    }				mag = 2;				argc--;				break;				/* Get filename of list of files to 				 * be operated on or by STDIN				 */				case 'I': 				if (*argv == 0) {					PERROR "\n%s: %s\n", Progname, NOINP);					usage();				}				if (strlen(*argv) < MAXNAMLEN)					strcpy(inputfile, *argv++);				else {				   	PERROR "\n%s: %s %s\n\n", Progname, FNTL, a);				    	exit(FAIL);				}				if (*inputfile == '-')					iflag = -1;				else {					iflag = 1;					if (!(ifp = fopen(inputfile, "r"))) {					    PERROR "\n%s: %s %s\n\n", Progname,						CANTOPEN, inputfile);					    exit(FAIL);					}				    }/*F if *inputfile == '-'  */				argc--;				break;					/* Get new volume identification 				 */			case 'L': 				if (*argv == 0) {					PERROR "\n%s: %s\n", Progname, NOVOL);					usage();				}				/* Make sure it is not too long				*/				if (strlen(*argv) > 6) {					PERROR "\n%s: %s\n\n", Progname, VOLIDTL);				        exit(FAIL);				}				strcpy(Volid,*argv++);					if (!filter_to_a(Volid,REPORT_ERRORS)) {					PERROR "\n%s: %s", Progname, INVVID1);					PERROR "\n%s: %s %s\n\n", Progname, INVVID2, Volid);					exit(FAIL);				}				argc--;				break;					/* Position to an ANSI file sequence 				 * number before beginning requested 				 * operations.				 */			case 'P': 				if (*argv == 0) {					PERROR "\n%s: %s\n", Progname, NOPOS);					usage();				}				nmbr1 = *argv;				while ((isdigit(*nmbr1)) || (*nmbr1 == ',') || (*nmbr1 == '-'))				    nmbr1++;				if (*nmbr1 != '\0') {					PERROR "\n%s: %s %s\n\n", Progname, INVNF, *argv);					exit(FAIL);				}				sscanf(*argv++, "%d,%d", &Seqno, &Secno);				if (Seqno <= 0) {					PERROR "\n%s: %s %d\n\n", Progname, INVPN, Seqno);					exit(FAIL);				}				if (Secno <= 0) {					PERROR "\n%s: %s %d\n\n", Progname, INVPS, Secno);					exit(FAIL);				}				++pflag;				argc--;				break;	#ifdef U11				/* Set new record length				 */			case 'R': 				if (*argv == 0) {					PERROR "\n%s: %s\n", Progname, NOREC);					usage();				}				nmbr1 = *argv;				Reclength = expnum(nmbr1);				if (error_status) {					PERROR "\n%s: %s %s\n\n", Progname, INVNF, nmbr1);					exit(FAIL);				}				if (Reclength > MAXRECSIZE || Reclength < 1) {					PERROR "\n%s: %s %d%s\n\n", Progname, INVRS, MAXRECSIZE, BYTES);					exit(FAIL);				}				*argv++;				argc--;				break;#endif				/* Else error				 */				default:				PERROR "\n%s: %s %c\n", Progname, UNQ, *a);				usage();	}/*E switch *a */    }/* for */}/*T if --argc > 0 *//**//* +-->	Begin processing the requested function(s) ..*/if (Func == NO) {    PERROR "\n%s: %s\n", Progname, NOFUNC);    usage();}if (permission) {    if ((i = getuid()) > 0) {	PERROR "\n%s: %s %d\n", Progname, NOTSU, i);	permission = FALSE;    }    else	if (Func != EXTRACT) {	    PERROR "\n%s: %s\n", Progname, CANTPER);	    permission = FALSE;	}}if (mag > 0) {    strcpy(Magtdev, magtape);#ifdef U11    if (mag == 1 && unit != -1)	Magtdev[8] = unit;}#else}if (mag == 0 && unit_nums != 0) {	unit_int = expnum(unit);	if (error_status) {		PERROR "\n%s: %s %s\n\n", Progname, INVNF, unit_int);		exit(FAIL);	}	if (unit_int > 31 || unit_int < 0) {		PERROR "\n%s: %s\n\n", Progname, INVUNIT);		exit(FAIL);	}	Magtdev[8] = unit[0];	if (unit_nums == 2) {	    Magtdev[10] = Magtdev[9];	    Magtdev[9] = unit[1];	}}#endifTape = tape(Magtdev);	/* Decide if using tape and set flag */rew(0);if (Func == TABLE || Func == EXTRACT) {    if (Nodir)	Dverbose = NO;    dumpflag = 0;    for ( ; argc > 0; argc--, argv++)	rec_args(*argv, dumpflag);    if (iflag == 1)	ret = rec_file(ifp, iflag, "");    else	if (iflag == -1)	    ret = rec_file(stdin, iflag, "");    if (ret)	scantape();    else	printf("\n");}/*T if Func == TABLE || Func == EXTRACT  */else { /* if Func == CREATE */    /* If we are to create a new volume, Magtdev will be opened     * for writing in initvol().     */    if (pflag != 0) {	PERROR "\n%s: %s\n\n", Progname, INVPNUSE);    }    if (iflag == 0 && argc == 0) {	PERROR "\n%s: %s\n", Progname, NOARGS);	usage();    }    if (Func == WRITE) {	if (iflag == 1)	    fclose(ifp);#if 0	writetp(argc, argv, iflag, inputfile);#endif    }/*E if Func = WRITE */    else	if (Func == CREATE) {	    if (iflag == 1)		fclose(ifp);	   /* Go initialize the "volume" on the output	    * device of choice. We won't be coming back.	    */	    printf("\n");	    initvol(argc, argv, iflag, inputfile);	}/*T if Func == CREATE */}/*F if Func == TABLE || Func == EXTRACT  */}/*E main() *//**//* * * Function: * *	expnum * * Function Description: * *	Expand a numeric character string into an integer *	multiple of the format expressed. ie.. Allow the user *	to input a value in blocks (or k) and we convert it *	to the real number of bytes implied. * *	For example ->	10b = ten 512 byte blocks *	  -or-		3k  = three 1024 byte blocks * * Arguments: * *	char	*numstring	Pointer to the null terminated numeric *				character string. *	int	error_status	TRUE indicates invalid numeric string *				FALSE indicates no error * * Return values: * *	Returns a numeric value if the conversion was valid. * * *	 *//* JSD: moved expnum() into filenames.c so can fit for overlay version *//* JSD: moved usage() into filenames.c so can fit for overlay version *//* JSD: moved showhelp() into filenames.c so can fit for overlay version *//**//* * * Function: * *	response() * * Function Description: * *	Waits for a response of RETURN until exiting * * Arguments: * *	n/a * * Return values: * *	none * * Side Effects: * *	none *	 */response(){/*------*\   Code\*------*/ch = getchar();if (ch != '\n')    while (getchar() != '\n')	;else    ch = 'n';return(ch);}/* E response *//**\\**\\**\\**\\**\\**  EOM  ltf.c  **\\**\\**\\**\\**\\*//**\\**\\**\\**\\**\\**  EOM  ltf.c  **\\**\\**\\**\\**\\*/

⌨️ 快捷键说明

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