⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***  Sendmail**  Copyright (c) 1983  Eric P. Allman**  Berkeley, California****  Copyright (c) 1983 Regents of the University of California.**  All rights reserved.  The Berkeley software License Agreement**  specifies the terms and conditions for redistribution.*/# include <stdio.h># include <sys/types.h># include <sys/stat.h># include <sysexits.h># include <errno.h># include <ctype.h># include "sendmail.h"SCCSID(@(#)util.c 1.1 92/07/30 SMI); /* from UCB 5.9 12/17/86 *//***  STRIPQUOTES -- Strip quotes & quote bits from a string.****	Runs through a string and strips off unquoted quote**	characters and quote bits.  This is done in place.****	Parameters:**		s -- the string to strip.**		qf -- if set, remove actual `` " '' characters**			as well as the quote bits.****	Returns:**		none.****	Side Effects:**		none.****	Called By:**		deliver*/stripquotes(s, qf)	char *s;	bool qf;{	register char *p;	register char *q;	register char c;	if (s == NULL)		return;	for (p = q = s; (c = *p++) != '\0'; )	{		if (c != '"' || !qf)			*q++ = c & 0177;	}	*q = '\0';}/***  QSTRLEN -- give me the string length assuming 0200 bits add a char****	Parameters:**		s -- the string to measure.****	Reurns:**		The length of s, including space for backslash escapes.****	Side Effects:**		none.*/qstrlen(s)	register char *s;{	register int l = 0;	register char c;	while ((c = *s++) != '\0')	{		if (bitset(0200, c))			l++;		l++;	}	return (l);}/***  CAPITALIZE -- return a copy of a string, properly capitalized.****	Parameters:**		s -- the string to capitalize.****	Returns:**		a pointer to a properly capitalized string.****	Side Effects:**		none.*/char *capitalize(s)	register char *s;{	static char buf[50];	register char *p;	p = buf;	for (;;)	{		while (!isalpha(*s) && *s != '\0')			*p++ = *s++;		if (*s == '\0')			break;		*p++ = toupper(*s++);		while (isalpha(*s))			*p++ = *s++;	}	*p = '\0';	return (buf);}/***  XALLOC -- Allocate memory and bitch wildly on failure.****	THIS IS A CLUDGE.  This should be made to give a proper**	error -- but after all, what can we do?****	Parameters:**		sz -- size of area to allocate.****	Returns:**		pointer to data region.****	Side Effects:**		Memory is allocated.*/char *xalloc(sz)	register int sz;{	register char *p;	extern char *malloc();	p = malloc((unsigned) sz);	if (p == NULL)	{		syserr("Out of memory!!");		abort();		/* exit(EX_UNAVAILABLE); */	}	return (p);}/***  COPYPLIST -- copy list of pointers.****	This routine is the equivalent of newstr for lists of**	pointers.****	Parameters:**		list -- list of pointers to copy.**			Must be NULL terminated.**		copycont -- if TRUE, copy the contents of the vector**			(which must be a string) also.****	Returns:**		a copy of 'list'.****	Side Effects:**		none.*/char **copyplist(list, copycont)	char **list;	bool copycont;{	register char **vp;	register char **newvp;	for (vp = list; *vp != NULL; vp++)		continue;	vp++;	newvp = (char **) xalloc((int) (vp - list) * sizeof *vp);	bcopy((char *) list, (char *) newvp, (int) (vp - list) * sizeof *vp);	if (copycont)	{		for (vp = newvp; *vp != NULL; vp++)			*vp = newstr(*vp);	}	return (newvp);}/***  PRINTAV -- print argument vector.****	Parameters:**		av -- argument vector.****	Returns:**		none.****	Side Effects:**		prints av.*/printav(av)	register char **av;{	while (*av != NULL)	{		if (tTd(0, 44))			printf("\n\t%08x=", *av);		else			(void) putchar(' ');		xputs(*av++);	}	(void) putchar('\n');}/***  LOWER -- turn letter into lower case.****	Parameters:**		c -- character to turn into lower case.****	Returns:**		c, in lower case.****	Side Effects:**		none.*/charlower(c)	register char c;{	if (isascii(c) && isupper(c))		c = c - 'A' + 'a';	return (c);}/***  XPUTS -- put string doing control escapes.****	Parameters:**		s -- string to put.****	Returns:**		none.****	Side Effects:**		output to stdout*/xputs(s)	register char *s;{#ifdef INTER	register int c;#else	register char c;#endif	register struct metamac *m;	if (s == NULL)	{		printf("<null>");		return;	}	if (s[0] == MATCHREPL && isdigit(s[1]) && s[2] == '\0') {	  printf("$%c", s[1]);	  return;	} else	  for (m = MetaMacros; m->metaname != '\0'; m++)	    if (m->metaval == *s) {	      printf("$%c%s", m->metaname, &s[1]);	      return;	    }	(void) putchar('"');	while ((c = *s++) != '\0')	{#ifdef INTER		if (!isprint(c))		{			(void) putchar('\\');			c &= 0177;		}#else		if (!isascii(c))		{			(void) putchar('\\');			c &= 0177;		}		if (c < 040 || c >= 0177)		{			(void) putchar('^');			c ^= 0100;		}#endif		(void) putchar(c);	}	(void) putchar('"');	(void) fflush(stdout);}/***  MAKELOWER -- Translate a line into lower case****	Parameters:**		p -- the string to translate.  If NULL, return is**			immediate.****	Returns:**		none.****	Side Effects:**		String pointed to by p is translated to lower case.****	Called By:**		parse*/makelower(p)	register char *p;{	register char c;	if (p == NULL)		return;	for (; (c = *p) != '\0'; p++)		if (isascii(c) && isupper(c))			*p = c - 'A' + 'a';}/***  SAMEWORD -- return TRUE if the words are the same****	Ignores case.****	Parameters:**		a, b -- the words to compare.****	Returns:**		TRUE if a & b match exactly (modulo case)**		FALSE otherwise.****	Side Effects:**		none.*/boolsameword(a, b)	register char *a, *b;{	char ca, cb;	do	{		ca = *a++;		cb = *b++;		if (isascii(ca) && isupper(ca))			ca = ca - 'A' + 'a';		if (isascii(cb) && isupper(cb))			cb = cb - 'A' + 'a';	} while (ca != '\0' && ca == cb);	return (ca == cb);}/***  BUILDFNAME -- build full name from gecos style entry.****	This routine interprets the strange entry that would appear**	in the GECOS field of the password file.****	Parameters:**		p -- name to build.**		login -- the login name of this user (for &).**		buf -- place to put the result.****	Returns:**		none.****	Side Effects:**		none.*/buildfname(p, login, buf)	register char *p;	char *login;	char *buf;{	register char *bp = buf;	if (*p == '*')		p++;	while (*p != '\0' && *p != ',' && *p != ';' && *p != '%')	{		if (*p == '&')		{			(void) strcpy(bp, login);			*bp = toupper(*bp);			while (*bp != '\0')				bp++;			p++;		}		else			*bp++ = *p++;	}	*bp = '\0';}/***  SAFEFILE -- return true if a file exists and is safe for a user.****	Parameters:**		fn -- filename to check.**		uid -- uid to compare against.**		mode -- mode bits that must match.****	Returns:**		TRUE if fn exists, is owned by uid, and matches mode.**		FALSE otherwise.****	Side Effects:**		none.*/boolsafefile(fn, uid, mode)	char *fn;	int uid;	int mode;{	struct stat stbuf;	if (stat(fn, &stbuf) >= 0 && stbuf.st_uid == uid &&	    (stbuf.st_mode & mode) == mode)		return (TRUE);	errno = 0;	return (FALSE);}/***  FIXCRLF -- fix <CR><LF> in line.****	Looks for the <CR><LF> combination and turns it into the**	UNIX canonical <NL> character.  It only takes one line,**	i.e., it is assumed that the first <NL> found is the end**	of the line.****	Parameters:**		line -- the line to fix.**		stripnl -- if true, strip the newline also.****	Returns:**		none.****	Side Effects:**		line is changed in place.*/fixcrlf(line, stripnl)	char *line;	bool stripnl;{	register char *p;	p = index(line, '\n');	if (p == NULL)		return;	if (p[-1] == '\r')		p--;	if (!stripnl)		*p++ = '\n';	*p = '\0';}/***  DFOPEN -- determined file open****	This routine has the semantics of fopen, except that it will**	keep trying a few times to make this happen.  The idea is that**	on very loaded systems, we may run out of resources (inodes,**	whatever), so this tries to get around it.*/FILE *dfopen(filename, mode)	char *filename;	char *mode;{	register int tries;

⌨️ 快捷键说明

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