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

📄 compat.c

📁 EPIC IRC客户端。来源于IRCII客户端但做了很多性能和功能的优化。
💻 C
📖 第 1 页 / 共 2 页
字号:
				if (*sp++ != '}' || pushnum(i))					return OOPS;				termcap = 0;				break;			case 'l':				if (termcap || popstring(&s))					return OOPS;				i = strlen(s);				if (pushnum(i))					return OOPS;				sp++;				break;			case '*':				if (termcap || popnum(&j) || popnum(&i))					return OOPS;				i *= j;				if (pushnum(i))					return OOPS;				sp++;				break;			case '/':				if (termcap || popnum(&j) || popnum(&i))					return OOPS;				i /= j;				if (pushnum(i))					return OOPS;				sp++;				break;			case 'm':				if (termcap) {					if (getarg(1, INTEGER, &i))						return OOPS;					arg_list[0].integer ^= 0177;					arg_list[1].integer ^= 0177;					sp++;					break;				}				if (popnum(&j) || popnum(&i))					return OOPS;				i %= j;				if (pushnum(i))					return OOPS;				sp++;				break;			case '&':				if (popnum(&j) || popnum(&i))					return OOPS;				i &= j;				if (pushnum(i))					return OOPS;				sp++;				break;			case '|':				if (popnum(&j) || popnum(&i))					return OOPS;				i |= j;				if (pushnum(i))					return OOPS;				sp++;				break;			case '^':				if (popnum(&j) || popnum(&i))					return OOPS;				i ^= j;				if (pushnum(i))					return OOPS;				sp++;				break;			case '=':				if (popnum(&j) || popnum(&i))					return OOPS;				i = (i == j);				if (pushnum(i))					return OOPS;				sp++;				break;			case '<':				if (popnum(&j) || popnum(&i))					return OOPS;				i = (i < j);				if (pushnum(i))					return OOPS;				sp++;				break;			case 'A':				if (popnum(&j) || popnum(&i))					return OOPS;				i = (i && j);				if (pushnum(i))					return OOPS;				sp++;				break;			case 'O':				if (popnum(&j) || popnum(&i))					return OOPS;				i = (i || j);				if (pushnum(i))					return OOPS;				sp++;				break;			case '!':				if (popnum(&i))					return OOPS;				i = !i;				if (pushnum(i))					return OOPS;				sp++;				break;			case '~':				if (popnum(&i))					return OOPS;				i = ~i;				if (pushnum(i))					return OOPS;				sp++;				break;			case '?':				if (termcap > 1)					return OOPS;				termcap = 0;				if_depth++;				sp++;				break;			case 't':				if (popnum(&i) || if_depth == 0)					return OOPS;				if (!i) {					scan_for = 'e';					scan_depth = if_depth;				}				sp++;				break;			case 'e':				if (if_depth == 0)					return OOPS;				scan_for = ';';				scan_depth = if_depth;				sp++;				break;			case ';':				if (if_depth-- == 0)					return OOPS;				sp++;				break;			case 'b':				if (--termcap < 1)					return OOPS;				sp++;				break;			case 'f':				if (!termcap++)					return OOPS;				sp++;				break;			}			break;		default:			if (scan_for)				sp++;			else				*dp++ = *sp++;			break;		}	}	va_end(tparm_args);	*dp = '\0';	return buf;}#endif/* ----------------------- end of tparm.c ------------------------------- *//**************************************************************************//* ---------------------- start of strtoul.c ---------------------------- */#ifndef HAVE_STRTOUL/* * Copyright (c) 1990 Regents of the University of California. * All rights reserved. * * Licensed under the 3-clause BSD license, see above for text. *//* * Convert a string to an unsigned long integer. * * Ignores `locale' stuff.  Assumes that the upper and lower case * alphabets and digits are each contiguous. */unsigned long strtoul (const char *nptr, char **endptr, int base){	const char *s;	unsigned long acc, cutoff;	int c;	int neg, any, cutlim;	s = nptr;	do		c = *s++;	while (isspace(c));	if (c == '-') 	{		neg = 1;		c = *s++;	} 	else 	{		neg = 0;		if (c == '+')			c = *s++;	}	if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) 	{		c = s[1];		s += 2;		base = 16;	}	if (base == 0)		base = c == '0' ? 8 : 10;#ifndef ULONG_MAX#define ULONG_MAX (unsigned long) -1#endif	cutoff = ULONG_MAX / (unsigned long)base;	cutlim = ULONG_MAX % (unsigned long)base;	for (acc = 0, any = 0;; c = *s++) 	{		if (isdigit(c))			c -= '0';		else if (isalpha(c))			c -= isupper(c) ? 'A' - 10 : 'a' - 10;		else			break;		if (c >= base)			break;		if (any < 0)			continue;		if (acc > cutoff || acc == cutoff && c > cutlim) 		{			any = -1;			acc = ULONG_MAX;			errno = ERANGE;		}		else 		{			any = 1;			acc *= (unsigned long)base;			acc += c;		}	}	if (neg && any > 0)		acc = -acc;	if (endptr != 0)		*endptr = (char *) (any ? s - 1 : nptr);	return (acc);}#endif /* DO NOT HAVE STRTOUL *//* ----------------------- end of strtoul.c ----------------------------- *//**************************************************************************//* ---------------------- strlcpy, strlcat ----------------------------- *//* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */#ifndef HAVE_STRLCPY/*	OpenBSD's strlcpy.c version 1.7 2003/04/12 21:56:39 millert *//* * Copy src to string dst of size siz.  At most siz-1 characters * will be copied.  Always NUL terminates (unless siz == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */size_t	strlcpy (char *dst, const char *src, size_t siz){	char *d = dst;	const char *s = src;	size_t n = siz;	/* Copy as many bytes as will fit */	if (n != 0 && --n != 0) {		do {			if ((*d = *s) == 0)				break;			d++;			s++;		} while (--n != 0);	}	/* Not enough room in dst, add NUL and traverse rest of src */	if (n == 0) {		if (siz != 0)			*d = '\0';		/* NUL-terminate dst */		while (*s)			s++;	}	return(s - src);	/* count does not include NUL */}#endif#ifndef HAVE_STRLCAT/*      OpenBSD's strlcat.c version 1.10 2003/04/12 21:56:39 millert *//* * Appends src to string dst of size siz (unlike strncat, siz is the * full size of dst, not space left).  At most siz-1 characters * will be copied.  Always NUL terminates (unless siz <= strlen(dst)). * Returns strlen(src) + MIN(siz, strlen(initial dst)). * If retval >= siz, truncation occurred. */size_t	strlcat (char *dst, const char *src, size_t siz){        char *d = dst;        const char *s = src;        size_t n = siz;        size_t dlen;        /* Find the end of dst and adjust bytes left but don't go past end */        while (n-- != 0 && *d != '\0')                d++;        dlen = d - dst;        n = siz - dlen;        if (n == 0)                return(dlen + strlen(s));        while (*s != '\0') {                if (n != 1) {                        *d++ = *s;                        n--;                }                s++;        }        *d = '\0';        return(dlen + (s - src));        /* count does not include NUL */}#endif/* --------------------------- start of arc4 stuff -------------------- *//* * Arc4 random number generator for OpenBSD. * Copyright 1996 David Mazieres <dm@lcs.mit.edu>. * * Modification and redistribution in source and binary forms is * permitted provided that due credit is given to the author and the * OpenBSD project (for instance by leaving this copyright notice * intact). *//* * This code is derived from section 17.1 of Applied Cryptography, * second edition, which describes a stream cipher allegedly * compatible with RSA Labs "RC4" cipher (the actual description of * which is a trade secret).  The same algorithm is used as a stream * cipher called "arcfour" in Tatu Ylonen's ssh package. * * Here the stream cipher has been modified always to include the time * when initializing the state.  That makes it impossible to * regenerate the same random sequence twice, so this can't be used * for encryption, but will generate good random numbers. * * RC4 is a registered trademark of RSA Laboratories. */struct bsd_arc4_stream {	u_char	i;	u_char	j;	u_char	s[256];};typedef struct bsd_arc4_stream 	ARC4;static int	rs_initialized = 0;static ARC4	rs;__inline__static void	bsd_arc4_init (ARC4 *as){	int     n;	for (n = 0; n < 256; n++)		as->s[n] = n;	as->i = 0;	as->j = 0;}__inline__static void	bsd_arc4_addrandom (ARC4 *as, u_char *dat, int datlen){	int     n;	u_char	si;	as->i--;	for (n = 0; n < 256; n++) {		as->i = (as->i + 1);		si = as->s[as->i];		as->j = (as->j + si + dat[n % datlen]);		as->s[as->i] = as->s[as->j];		as->s[as->j] = si;	}}static void	bsd_arc4_stir (ARC4 *as){	int     fd;	struct {		Timeval tv;		pid_t 	pid;		u_char	rnd[128 - sizeof(Timeval) - sizeof(pid_t)];	}       rdat;	gettimeofday(&rdat.tv, NULL);	rdat.pid = getpid();	if ((fd = open("/dev/urandom", O_RDONLY, 0)) >= 0) {		read(fd, rdat.rnd, sizeof(rdat.rnd));		close(fd);	}	/* 	 * fd < 0?  Ah, what the heck. We'll just take whatever was on the	 * stack... 	 */	bsd_arc4_addrandom(as, (void *) &rdat, sizeof(rdat));}__inline__static u_char		bsd_arc4_getbyte (ARC4 *as){	u_char si, sj;	as->i = (as->i + 1);	si = as->s[as->i];	as->j = (as->j + si);	sj = as->s[as->j];	as->s[as->i] = sj;	as->s[as->j] = si;	return (as->s[(si + sj) & 0xff]);}__inline__static u_32int_t	bsd_arc4_getword (ARC4 *as){	u_32int_t val;	val = bsd_arc4_getbyte(as) << 24;	val |= bsd_arc4_getbyte(as) << 16;	val |= bsd_arc4_getbyte(as) << 8;	val |= bsd_arc4_getbyte(as);	return val;}void	bsd_arc4random_stir (void){	if (!rs_initialized) {		bsd_arc4_init(&rs);		rs_initialized = 1;	}	bsd_arc4_stir(&rs);}void	bsd_arc4random_addrandom (u_char *dat, int datlen){	if (!rs_initialized)		bsd_arc4random_stir();	bsd_arc4_addrandom(&rs, dat, datlen);}u_32int_t	bsd_arc4random (void){	if (!rs_initialized)		bsd_arc4random_stir();	return bsd_arc4_getword(&rs);}/* --------------------------- start of misc stuff -------------------- *//* This is all written by Jeremy Nelson and is public domain */#ifndef HAVE_VSNPRINTFint vsnprintf (char *str, size_t size, const char *format, va_list ap){	int ret = vsprintf(str, format, ap);	/* If the string ended up overflowing, just give up. */	/* Pre-ansi vsprintf()s return (char *) */	if (ret == (int)str && strlen(str) > size)		panic("Buffer overflow in vsnprintf");	/* ANSI vsprintf()s return (int) */	if (ret != (int)str && ret > size)		panic("Buffer overflow in vsnprintf");	/* We always return (int). */	return ret;}#endif#ifndef HAVE_SNPRINTFint snprintf (char *str, size_t size, const char *format, ...){	int ret;	va_list args;	va_start(args, format);	ret = vsnprintf(str, size, format, args);	va_end(args);	return ret;}#endif#ifndef HAVE_SETSIDint	setsid	(void){	setpgrp(getpid(), getpid());}#endif#ifndef HAVE_SETENVint	setenv (const char *name, const char *value, int overwrite){	static int warning = 0;	char *envvalue;	size_t	len;	if (warning == 0) {		yell("Warning: Your system does not have setenv(3).  Setting the same environment variable multiple times will result in memory leakage.  This is unavoidable and does not represent a bug in EPIC.");		warning = 1;	}	len = strlen(name) + strlen(value) + 2;	envvalue = (char *)malloc(len);	snprintf(envvalue, len, "%s=%s", name, value);	putenv(envvalue);	return 0;}#endif#ifndef HAVE_UNSETENVint	unsetenv (const char *name){	yell("Warning: Your system does not have unsetenv(3) and so it is not possible to unset the [%s] environment variable.", name);	return -1;}#endif#ifdef HAVE_BROKEN_REALPATH# if defined(realpath)#  undef realpath# endifchar *	my_realpath (const char *pathname, char resolved_path[MAXPATHLEN]){	char *mypath;	char *rest;	Stat unused;	size_t	size;	/* If the file exists, just run realpath on it. */	if (stat(pathname, &unused) == 0)		return realpath(pathname, resolved_path);	/* Otherwise, run realpath() on the dirname only */	size = strlen(pathname) + 1;	mypath = alloca(size);	strlcpy(mypath, pathname, size);	if ((rest = strrchr(mypath, '/')))		*rest++ = 0;	else	{		rest = LOCAL_COPY(mypath);		strlcpy(mypath, ".", size);	}	if (realpath(mypath, resolved_path) == NULL)		return NULL;	/* And put the basename back on the result. */	strlcat(resolved_path, "/", MAXPATHLEN);	strlcat(resolved_path, rest, MAXPATHLEN);	return resolved_path;}#endif#ifndef HAVE_ATOLL# ifdef HAVE_LONG_LONG#  ifdef HAVE_STRTOLL#   define HAVE_ATOLL_REPLACEMENTlong long	atoll (const char *str){	return strtoll(str, NULL, 0);}#  else#   ifdef HAVE_ATOQ#    define HAVE_ATOLL_REPLACEMENTlong long	atoll (const char *str){	return (long long)atoq(str);}#   endif#  endif# endif# ifndef HAVE_ATOLL_REPLACEMENT#  ifdef HAVE_LONG_LONGlong long	atoll (const char *str){	return (long long)atol(str);}#  elselong	atoll (const char *str){	return atol(str);}#  endif# endif#endif/**** END MISC PUBLIC DOMAIN STUFF ****/

⌨️ 快捷键说明

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