filenames.c

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

C
843
字号
fstat = (struct FILESTAT *) malloc(sizeof(*fstat));if (!fstat) {	PERROR "\n%s: %s\n", Progname, TMA);	exit(FAIL);}/*	Link another file name structure to our current list. */fstat->f_next = F_head;/*	Last in, first out que. */F_head = fstat;fstat->f_numleft = 1;fstat->f_found	= 0;fstat->f_flags = dumpflag;/* * Make final version of file name. */make_name(longname, &fstat->f_src);/* Count another file desired. */Numrecs++;return;}/*E rec_args() *//**//* * * Function: * *	rec_file * * Function Description: * *	If the Func = EXTRACT or TABLE, records (saves) argument  *	file names in the linked list FILESTAT structure(s) which  *	were entered from "stdin" or from a specified file. *	If the Func = CREATE, saves one filename in the argument *	crname, and returns to the calling routine. * * Arguments: * *	FILE	*fp		Pointer to an input file, or stdin *	int	iflag		Input flag, -1 = stdin, 1 = file *	char	*crname		Will contain a filename if Func =  *				CREATE * * Return values: * *	EOF	- unsuccessful = 0 *	TRUE	- successful = 1 * * Side Effects: * * 	If errors are encountered, the routine will output a message *	to stderr and exit to system control. ie. No return to caller. *	 */rec_file(fp, iflag, crname)	FILE	*fp;	/* Pointer to file of file names or stdin */	int	iflag;	/* Input flag, -1 = stdin, 1 = file */	char	*crname;/* CREATE filename */{/* * ->	Local variables */int	dumpflag = 0;struct	FILESTAT *fstat;char	*l, line[MAXPATHLEN];/*------*\   Code\*------*/if (Func == CREATE || Func == WRITE) {    /* Test if iflag = -1 for stdin.     */    if (iflag == -1) {	/*	 * Process a list of file names entered from "stdin".	 */	PROMPT "%s: %s ", Progname, ENFNAM);			if (!(fgets(line, sizeof(line), fp)) ||	line[0] == '\n') {	    return(EOF); 	}	/* Remove newline and truncate the string after	 * the first non-white space character.	 */	term_string(line,DELNL,TRUNCATE);	if (strlen(line) < MAXPATHLEN-1)		strcpy(crname, line);	else {		PERROR "\n%s: %s %s", Progname, FNTL, line);		exit(FAIL);		return(EOF);	}	return(TRUE);   }/*F if iflag */   else {	if (fgets((l=line), sizeof(line), fp) != NULL) {	    Dfiletype = 0;	    term_string(l,NULL,TRUNCATE);	    if (strlen(l) < MAXPATHLEN-1)		strcpy(crname,l);	    else {		PERROR "\n%s: %s %s", Progname, FNTL, line);		exit(FAIL);	    }	    if (*crname == 0)		return(EOF);	    else		return(TRUE);	}/* if fgets l=line etc ..*/	else	    return(EOF);    }/* else */}/*E if Func == CREATE || WRITE *//* Func should be either TABLE or EXTRACT to get here. */fstat = (struct FILESTAT *) malloc(sizeof(*fstat));if (!fstat) {	PERROR "\n%s: %s\n", Progname, TMA);	exit(FAIL);}/* * Link another file name arg into the list */fstat->f_next = F_head;F_head = fstat;if (iflag == -1)	printf("\n");for (;;) {    if (iflag == -1) {	PROMPT "%s: %s ", Progname, ENFNAM);	if (!fgets(line, sizeof(line), fp) || line[0] == '\n')	{		F_head = fstat->f_next;		free((char *)fstat);		return(EOF);	}	term_string(line,DELNL,TRUNCATE);	fstat->f_numleft = 1;	make_name(line, &fstat->f_src);    	Numrecs++;    	fstat++;    }/*T if iflag */    else	if (fgets(l=line, sizeof(line), fp) != NULL) {	    term_string(l,DELNL,NULL);	    make_name(l, &fstat->f_src);	    fstat->f_numleft = 1;	    fstat->f_flags = dumpflag;	    Numrecs++;	    fstat++;        }/*T if !fgets ..*/	else	{		F_head = fstat->f_next;		free((char *)fstat);		return(TRUE);	}	fstat = (struct FILESTAT *) malloc(sizeof(*fstat));	if (!fstat) {	    PERROR "\n%s: %s\n", Progname, TMA);	    exit(FAIL);	}	fstat->f_next = F_head;	F_head = fstat;}/*E for ;; */}/*E rec_file() *//**//* * * Function: * *	term_string * * Function Description: * *	This function terminates a given input string according *	to the calling parameters. * * Arguments: * *	char	*string		Pointer to input string *	int	delnl		True is trailing new line to be replaced *				with a NULL *	int	truncate	If true - truncate string after the 1st *				non-white space character * * Return values: * *	The altered in place string. * * Side Effects: * *	none * */term_string(string,delnl,truncate)	char	*string;	int	delnl;	int	truncate;{/*------*\   Code\*------*/if (delnl) {	i = strlen(string) -1;	if (string[i] == '\n')		string[i] = NULL;}/*E if delnl */if (truncate) {	while (*string && !isspace(*string))		string++;	if (isspace(*string))		*string = NULL;}/*E if truncate */}/*E term_string() *//* JSD - expnum() put here from ltf.c *//* * * 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. * *	 */expnum(numstring)	char	*numstring;{/*------*\   Code\*------*/j = 0;error_status = FALSE;if (*numstring == '-') {    j++;    numstring++;}for (i = 0; isdigit(*numstring); numstring++)	i = (10 * i) + (*numstring - '0');switch (*numstring) {	case '\0':		if (!j)		    return(i);		else		    return(0 - i);	case 'b':		return(i * 512);	case 'k':		return(i * 1024);	default:		error_status = TRUE;		return(0);}/*E switch *numstring */}/*E expnum() *//* JSD -  showhelp() put here from ltf.c module *//**//* * * Function: * *	showhelp() * * Function Description: * *	Prints a help message with a description of all functions, *	switches, and qualifiers and their definitions, then exits  * * Arguments: * *	n/a * * Return values: * *	none * * Side Effects: * *	This function never returns to the caller.  *	It always exits to the system. *	 */showhelp(){#ifndef U11PERROR "\n%s: %s\n", Progname, USE1);PERROR "%s: %s\n", Progname, USE2);PERROR "%s: %s\n", Progname, HELP1);PERROR "%s: %s\n", Progname, HELP2);PERROR "%s: %s\n", Progname, HELP3);PERROR "%s: %s\n", Progname, HELP4);PERROR "%s: %s\n", Progname, HELP5);PERROR "%s: %s\n", Progname, HELP6);PERROR "%s: %s\n", Progname, HELP7);PERROR "%s: %s\n", Progname, HELP8);PERROR "%s: %s\n", Progname, HELP9);PERROR "%s: %s\n", Progname, HELP10);PERROR "%s: %s\n", Progname, HELP11);PERROR "%s: %s\n", Progname, HELP12);PERROR "%s: %s\n", Progname, HELP13);PERROR "%s: %s\n\n", Progname, HELP14);PERROR "%s: %s ", Progname, HELP18);response();PERROR "\n%s: %s\n", Progname, USE1);PERROR "%s: %s\n", Progname, USE2);PERROR "%s: %s\n", Progname, HELP15);PERROR "%s: %s\n", Progname, HELP16);PERROR "%s: %s\n", Progname, HELP17);PERROR "%s: %s\n", Progname, HELP19);PERROR "%s: %s\n", Progname, HELP20);PERROR "%s: %s\n", Progname, HELP21);PERROR "%s: %s\n", Progname, HELP22);PERROR "%s: %s\n", Progname, HELP23);PERROR "%s: %s\n", Progname, HELP24);PERROR "%s: %s\n", Progname, HELP25);PERROR "%s: %s\n\n\n\n\n\n\n", Progname, HELP26);#else U11PERROR "\n%s: %s\n", Progname, USE1);PERROR "%s: %s\n\n", Progname, USE2);PERROR "%s: %s\n\n", Progname, TRYHELP);#endif U11exit(FAIL);}/*E showhelp() *//* JSD - usage() function put here from ltf.c *//**//* * * Function: * *	usage() * * Function Description: * *	Prints a summary of the command line format,	 *	allowable functions, qualifiers, etc.. * * Arguments: * *	n/a * * Return values: * *	none * * Side Effects: * *	This function never returns to the caller.  *	It always exits to the system. *	 */usage(){PERROR "\n%s: %s%c", Progname, USE1, BELL);PERROR "\n%s: %s", Progname, USE2);PERROR "\n%s: %s\n\n", Progname, TRYHELP);exit(FAIL);}/*E usage() *//**\\**\\**\\**\\**\\**  EOM  filenames.c  **\\**\\**\\**\\**\\*//**\\**\\**\\**\\**\\**  EOM  filenames.c  **\\**\\**\\**\\**\\*/

⌨️ 快捷键说明

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