filenames.c

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

C
843
字号
#ifndef lintstatic char *sccsid = "@(#)filenames.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: * *		filenames.c * *	Source file description: * *		This module contains the various routines that *		deal with file name and character string handling. *		Define "handling" to imply string conversions, *		string filtration, etc.. *		 *		Generally, but not always, this will be done *		on behalf of filenames. One exception is for *		volume label name strings. Other cases may be *		added as development proceeds. * *	Functions: * *		filter_to_a()	Filter a character string to contain *				only "a"characters. *				(see ltfdefs.h -or- filter_to_a() ) * *		Lookup()	Looks up a given ANSI file name *				among user-input file arguments. * *		make_name()	Convert a user file name to correct *				format for FILESTAT structure * *		rec_args()	Records file name command line arguments *				in FILESTAT linked list. * *		rec_file()	Records file name arguments in FILESTAT *				list entered from an input file, *				or line-by-line from stdin. *				 *		term_string()	Terminate a string in the requested *				fashion * *	Usage: * *		n/a * * *	Compile: * *	    cc -O -c filenames.c	 <- For Ultrix-32/32m * *	    cc CFLAGS=-DU11-O filenames.c <- For Ultrix-11 * * *	Modification history: *	~~~~~~~~~~~~~~~~~~~~ * *	revision			comments *	--------	----------------------------------------------- *	  01.0		14-April-85	Ray Glaser *			Create original version. * *	  01.1		22-August-85	Suzanne Logcher *			Debug and fix rec_file. *//* * ->	Local includes */#include	"ltfdefs.h"	/* Common GLOBAL constants & structs *//**//* * * Function: * *	filter_to_a	 * * Function Description: * * 	Function "filter_to_a" is called to filter a *	given string to "a"chracters as defined below. * * * Arguments: * *	char	*string		Pointer to "null-terminated" *				character string to be filtered * *	int	report_errors	BOOLEAN flag (TRUE/FALSE) to *				indicate if the caller wants *				to know if any non-a chctrs *				were found. * *				TRUE implies that the caller *				wants to be notified of the *				occurance of any non-"a"character *				seen in the given string.. * *				FALSE implies the caller does *				not care if non-"a"characters were *				seen but desires the conversion *				to be made regardless. * * Return values: * *	Return values are the BOOLEAN flags TRUE or FALSE. * * Side Effects: * *	If the caller indicates that errors are to be *	returned, invalid non-"a"characters seen in *	the given string will be converted to upper case Z *	for subsequent user level error messages. * *	Normally, all lower case characters will be converted *	to upper case. Lower case letters are not allowable *	"a"characters. However, if the report_errors flag is *	set, the lower to upper case conversion is not made. * */filter_to_a (string,report_errors)	char	*string;	int	report_errors;{/**//* *	"a"characters - Refers to the set of characters consisting of: * *		Uppercase  A-Z,  numerals  0-9, & the following  *		special characters: * *			space  !  "  %  &  '  (  )  *  +  ,  - _ *			. /  :  ;  <  =  >  ? * *//* * ->	Local variables */short	a_flag;short	i;short	non_a = FALSE;	/* Default is a good string */char	*o_string; /*------*\   Code\*------*/o_string = string;	/* Save pointer to orginal string */while (*string) {	if (islower(*string))		;	else if (isdigit(*string))		;	else if (isupper(*string))		;	else { 		a_flag = FALSE; /* Default to not valid chctr */			for (i=0; i < A_SPECIALS; i++) {			if (*string == A_specials[i]) {				a_flag = TRUE;				break;			}		}		if (a_flag == FALSE) {			non_a = TRUE;			*string = 'Z';		}		}/*E if else string*/	string++;}/*E while *string *//* Convert string to upper case. */while (*o_string) {    *o_string = islower(*o_string) ? *o_string-'a'+'A' : *o_string;    o_string++;}/* If invalid chctrs were found, return FALSE */if (non_a && report_errors)	return(FALSE);return(TRUE);}/*E filter_to_a()*//**//* * * Function: * *	Lookup * * Function Description: * *	This function looks up a given ANSI volume file name *	entry among user-input file name arguments * * Arguments: * *	char	*name	Pointer to the name string to be found * * Return values: * *	Returns	a FILESTAT structure pointer if the name is *	found. Else, returns NULL if the name was not found. * * * Side Effects: * *	none	 */struct FILESTAT * Lookup(name)	char	*name;		/* file name */{/* * +--> Local variables */struct	FILESTAT *fstat;char	*d;char	*n;char	*x;char	*y;int	mstrcmp();/*------*\   Code\*------*/for (fstat = F_head; fstat; fstat = fstat->f_next) {	int	i, length;	/* 	 * If this file has been extracted,	 * go to the next entry.	 */	if (!fstat->f_numleft)		continue;	/*	 * If this is the desired file, return a pointer	 * to its' FILESTAT structure.	 */	if (!mstrcmp(name, fstat->f_src))  {		if ((i = strlen(name)) == (length = strlen(fstat->f_src))) {			if (name[i-1] == '/' && fstat->f_src[length-1] == '/') {	    			isdir = 1;				return(fstat);			}		}		fstat->f_found++;		return(fstat);	}	/* ?_?	 * check if the volume entry is a file	 * (recursively) under a requested directory. ?_?	 */	n = name;	d = fstat->f_src;	while (*n == *d) {		n++;	d++;	}	x = n;	y = d;	if (*d == '.'	&& *(d+1) == 0 && (*(d-1) == '/' || *n == '/'))	    return(fstat);	if (*y == 0 && *x == '/' && *(x+1) == 0) {	    isdir = 1;	    return(fstat);	}	if (*y == 0 && isdir) {	    fstat->f_found++;	    return(fstat);	}}/*E for fstat = F_head ..*/if (isdir) {    isdir = 0;}return(NULL);}/*E Lookup() *//**//* * * Function: * *	make_name * * Function Description: * *	Converts a file name from user input to a  *	file name format appropriate to the current function *	& inserts it into a FILESTAT structure. *	Case conversions are performed as required. * * Arguments: * *	char	*file *	char	**dest * * Return values: * *	The converted file name is stored as indicated above *	if successful and a non-zero value is returned, *	else an error message is printed to stderr  &  *	an exit to the system is taken. * * * Side Effects: * *	If an error is detected, no return is made to the caller. * */make_name(file, dest)	char	*file;	char	**dest;{/*------*\   Code\*------*/if (strlen(file) > MAXPATHLEN) {	PERROR "\n%s: %s %s\n", Progname, FNTL, file);	exit(FAIL);}#if 0if (Func == EXTRACT || Func == TABLE)	/* Convert destination filename to lower case.	 */	while(*file) {	    *file = isupper(*file) ? *file-'A'+'a' : *file;	    file++;	}#endif*dest = (char *) malloc (strlen(file) + 1);if (!*dest) {	PERROR "\n%s: %s\n", Progname, TMA);	exit(FAIL);}strcpy(*dest, file);return(TRUE);}/*E make_name() *//**//* * * Function: * *	rec_args * * Function Description: * *	Records (saves) command line argument file names in the *	linked list "FILESTAT" structure(s) for future reference. * * Arguments: * *	int	dumpflag	Flags associated with this command line *	char	*longname	Path name_+_filename * * Return values: * *	none * * Side Effects: * *	If an error is dectected in a filename, a message is output *	to stderr and an exit to the system is taken. *	 */rec_args(longname, dumpflag)	char	*longname;	int	dumpflag;{/* * ->	Local variables */struct	FILESTAT *fstat;/*------*\   Code\*------*/

⌨️ 快捷键说明

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