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

📄 test.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
字号:
#ifndef lintstatic CHTYPE *sccsid = "@(#)test.c	4.1      7/17/90";#endif lint/************************************************************************ *									* *			Copyright (c) 1986 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.			* *									* *   This software is  derived  from  software  received  from  the	* *   University    of   California,   Berkeley,   and   from   Bell	* *   Laboratories.  Use, duplication, or disclosure is  subject  to	* *   restrictions  under  license  agreements  with  University  of	* *   California and with AT&T.						* *									* *   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.	* *									* ************************************************************************//* * *   Modification History: * * 001 - Gary Gaudet for Andy Gadsby 09-mar-88 *	i18n version of csh * * * *//* *      test expression *      [ expression ] */#include	"defs.h"#include <sys/types.h>#include <sys/stat.h>int	ap, ac;CHTYPE	**av;test(argn, com)CHTYPE	*com[];int	argn;{	ac = argn;	av = com;	ap = 1;	if (eq(com[0],"["))	{		if (!eq(com[--ac], "]"))			failed("test", "] missing");	}	com[ac] = 0;	if (ac <= 1)		return(1);	return(exp() ? 0 : 1);}CHTYPE *nxtarg(mt){	if (ap >= ac)	{		if (mt)		{			ap++;			return(0);		}		failed("test", "argument expected");	}	return(av[ap++]);}exp(){	int	p1;	CHTYPE	*p2;	p1 = e1();	p2 = nxtarg(1);	if (p2 != 0)	{		if (eq(p2, "-o"))			return(p1 | exp());		if (eq(p2, "]") && !eq(p2, ")"))			failed("test", synmsg);	}	ap--;	return(p1);}e1(){	int	p1;	CHTYPE	*p2;	p1 = e2();	p2 = nxtarg(1);	if ((p2 != 0) && eq(p2, "-a"))		return(p1 & e1());	ap--;	return(p1);}e2(){	if (eq(nxtarg(0), "!"))		return(!e3());	ap--;	return(e3());}e3(){	int	p1;	register CHTYPE	*a;	CHTYPE	*p2;	long	atol();	long	int1, int2;	a = nxtarg(0);	if (eq(a, "("))	{		p1 = exp();		if (!eq(nxtarg(0), ")"))			failed("test",") expected");		return(p1);	}	p2 = nxtarg(1);	ap--;	if ((p2 == 0) || (!eq(p2, "=") && !eq(p2, "!=")))	{		if (eq(a, "-r"))			return(tio(nxtarg(0), 4));		if (eq(a, "-w"))			return(tio(nxtarg(0), 2));		if (eq(a, "-x"))			return(tio(nxtarg(0), 1));		if (eq(a, "-d"))			return(filtyp(nxtarg(0), S_IFDIR));		if (eq(a, "-c"))			return(filtyp(nxtarg(0), S_IFCHR));		if (eq(a, "-b"))			return(filtyp(nxtarg(0), S_IFBLK));		if (eq(a, "-f"))			return(filtyp(nxtarg(0), S_IFREG));		if (eq(a, "-u"))			return(ftype(nxtarg(0), S_ISUID));		if (eq(a, "-g"))			return(ftype(nxtarg(0), S_ISGID));		if (eq(a, "-k"))			return(ftype(nxtarg(0), S_ISVTX));		if (eq(a, "-p"))			return(filtyp(nxtarg(0),S_IFIFO));   		if (eq(a, "-s"))			return(fsizep(nxtarg(0)));		if (eq(a, "-t"))		{			if (ap >= ac)		/* no args */				return(isatty(1));			else if (eq((a = nxtarg(0)), "-a") || eq(a, "-o"))			{				ap--;				return(isatty(1));			}			else				return(isatty(atoi(wtoc(a))));		}		if (eq(a, "-n"))			return(!eq(nxtarg(0), ""));		if (eq(a, "-z"))			return(eq(nxtarg(0), ""));	}	p2 = nxtarg(1);	if (p2 == 0)		return(!eq(a, ""));	if (eq(p2, "-a") || eq(p2, "-o"))	{		ap--;		return(!eq(a, ""));	}	if (eq(p2, "="))		return(eq(nxtarg(0), a));	if (eq(p2, "!="))		return(!eq(nxtarg(0), a));	int1 = atol(wtoc(a));	int2 = atol(wtoc(nxtarg(0)));	if (eq(p2, "-eq"))		return(int1 == int2);	if (eq(p2, "-ne"))		return(int1 != int2);	if (eq(p2, "-gt"))		return(int1 > int2);	if (eq(p2, "-lt"))		return(int1 < int2);	if (eq(p2, "-ge"))		return(int1 >= int2);	if (eq(p2, "-le"))		return(int1 <= int2);	bfailed(btest, badop, p2);/* NOTREACHED */}tio(a, f)CHTYPE	*a;int	f;{	if (access(wtoc(a), f) == 0)		return(1);	else		return(0);}ftype(f, field)CHTYPE	*f;int	field;{	struct stat statb;	if (stat(wtoc(f), &statb) < 0)		return(0);	if ((statb.st_mode & field) == field)		return(1);	return(0);}filtyp(f,field)CHTYPE	*f;int field;{	struct stat statb;	if (stat(wtoc(f), &statb) < 0)		return(0);	if ((statb.st_mode & S_IFMT) == field)		return(1);	else		return(0);}fsizep(f)CHTYPE	*f;{	struct stat statb;	if (stat(wtoc(f), &statb) < 0)		return(0);	return(statb.st_size > 0);}/* * fake diagnostics to continue to look like original * test(1) diagnostics */bfailed(s1, s2, s3) CHTYPE	*s1;CHTYPE	*s2;CHTYPE	*s3;{	prp();	prs(s1);	if (s2)	{		prs(colon);		prs(s2);		prs(s3);	}	newline();	exitsh(ERROR);}

⌨️ 快捷键说明

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