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

📄 sh.h

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * Public Domain Bourne/Korn shell *//* $Id: sh.h,v 1.2 1994/05/19 18:32:40 michael Exp michael $ */#include "config.h"	/* system and option configuration info */#ifdef HAVE_PROTOTYPES# define	ARGS(args)	args	/* prototype declaration */#else# define	ARGS(args)	()	/* K&R declaration */#endif/* Start of common headers */#include <stdio.h>#include <sys/types.h>#include <setjmp.h>#ifdef HAVE_STDDEF_H# include <stddef.h>#endif#ifdef HAVE_STDLIB_H# include <stdlib.h>#else/* just a useful subset of what stdlib.h would have */extern char * getenv  ARGS((const char *));extern void * malloc  ARGS((size_t));extern void * realloc ARGS((void *, size_t));extern int    free    ARGS((void *));extern int    exit    ARGS((int));extern int    rand    ARGS((void));extern void   srand   ARGS((unsigned int));extern int    atoi    ARGS((const char *));#endif /* HAVE_STDLIB_H */#ifdef HAVE_UNISTD_H# include <unistd.h>#else/* just a useful subset of what unistd.h would have */extern int access ARGS((const char *, int));extern int open ARGS((const char *, int, ...));extern int creat ARGS((const char *, mode_t));extern int read ARGS((int, char *, unsigned));extern int write ARGS((int, const char *, unsigned));extern off_t lseek ARGS((int, off_t, int));extern int close ARGS((int));extern int pipe ARGS((int []));extern int dup2 ARGS((int, int));extern int unlink ARGS((const char *));extern int fork ARGS((void));extern int execve ARGS((const char *, char * const[], char * const[]));extern int chdir ARGS((const char *));extern int kill ARGS((pid_t, int));extern char *getcwd();	/* no ARGS here - differs on different machines */extern int geteuid ARGS((void));extern int readlink ARGS((const char *, char *, int));extern int getegid ARGS((void));extern int getpid ARGS((void));extern int getppid ARGS((void));extern unsigned int sleep ARGS((unsigned int));extern int isatty ARGS((int));# ifdef POSIX_PGRPextern int getpgrp ARGS((void));extern int setpgid ARGS((pid_t, pid_t));# endif /* POSIX_PGRP */# ifdef BSD_PGRPextern int getpgrp ARGS((pid_t));extern int setpgrp ARGS((pid_t, pid_t));# endif /* BSD_PGRP */# ifdef SYSV_PGRPextern int getpgrp ARGS((void));extern int setpgrp ARGS((void));# endif /* SYSV_PGRP */#endif /* HAVE_UNISTD_H */#ifdef HAVE_STRING_H# include <string.h>#else# include <strings.h># define strchr index# define strrchr rindex#endif /* HAVE_STRING_H */#ifndef HAVE_STRSTRchar *strstr ARGS((const char *s, const char *p));#endif /* HAVE_STRSTR */#ifndef HAVE_STRCASECMPint strcasecmp ARGS((const char *s1, const char *s2));int strncasecmp ARGS((const char *s1, const char *s2, int n));#endif /* HAVE_STRCASECMP */#ifdef HAVE_MEMORY_H# include <memory.h>#endif#ifndef HAVE_MEMSET# define memcpy(d, s, n)	bcopy(s, d, n)# define memcmp(s1, s2, n)	bcmp(s1, s2, n)void *memset ARGS((void *d, int c, size_t n));#endif /* HAVE_MEMSET */#ifndef HAVE_MEMMOVE# ifdef HAVE_BCOPY#  define memmove(d, s, n)	bcopy(s, d, n)# elsevoid *memmove ARGS((void *d, const void *s, size_t n));# endif#endif /* HAVE_MEMMOVE */#ifdef HAVE_PROTOTYPES# include <stdarg.h># define SH_VA_START(va, argn) va_start(va, argn)#else# include <varargs.h># define SH_VA_START(va, argn) va_start(va)#endif /* HAVE_PROTOTYPES */#include <errno.h>extern int errno;#ifdef HAVE_FCNTL_H# include <fcntl.h>#else# include <sys/file.h>#endif /* HAVE_FCNTL_H */#ifndef O_ACCMODE# define O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)#endif /* !O_ACCMODE */#ifndef F_OK 	/* access() arguments */# define F_OK 0# define X_OK 1# define W_OK 2# define R_OK 4#endif /* !F_OK */#ifndef SEEK_SET# ifdef L_SET#  define SEEK_SET L_SET#  define SEEK_CUR L_INCR#  define SEEK_END L_XTND# else /* L_SET */#  define SEEK_SET 0#  define SEEK_CUR 1#  define SEEK_END 2# endif /* L_SET */#endif /* !SEEK_SET *//* Some machines (eg, FreeBSD 1.1.5) define CLK_TCK in limits.h * (ksh_limval.h assumes limits has been included, if available) */#ifdef HAVE_LIMITS_H# include <limits.h>#endif /* HAVE_LIMITS_H */#include <signal.h>#ifdef	NSIG# define SIGNALS	NSIG#else# ifdef	_MINIX#  define SIGNALS	(_NSIG+1) /* _NSIG is # of signals used, excluding 0. */# else#  ifdef _SIGMAX	/* QNX */#   define SIGNALS	_SIGMAX#  else /* _SIGMAX */#   define SIGNALS	32#  endif /* _SIGMAX */# endif	/* _MINIX */#endif	/* NSIG */#ifndef SIGCHLD# define SIGCHLD SIGCLD#endif/* struct sigaction.sa_flags is set to KSH_SA_FLAGS.  Used to ensure * system calls are interrupted */#ifdef SA_INTERRUPT# define KSH_SA_FLAGS	SA_INTERRUPT#else /* SA_INTERRUPT */# define KSH_SA_FLAGS	0#endif /* SA_INTERRUPT */typedef	RETSIGTYPE (*handler_t) ARGS((int));	/* signal handler */#ifdef USE_FAKE_SIGACT# include "sigact.h"			/* use sjg's fake sigaction() */#endif#ifdef HAVE_PATHS_H# include <paths.h>#endif /* HAVE_PATHS_H */#ifdef _PATH_DEFPATH# define DEFAULT__PATH _PATH_DEFPATH#else /* _PATH_DEFPATH */# define DEFAULT__PATH DEFAULT_PATH#endif /* _PATH_DEFPATH */#ifndef offsetof# define offsetof(type,id) ((size_t)&((type*)NULL)->id)#endif#ifndef HAVE_KILLPG# define killpg(p, s)	kill(-(p), (s))#endif /* !HAVE_KILLPG *//* Special cases for execve(2) */#ifdef OS2extern int ksh_execve(char *cmd, char **args, char **env, int flags);#else /* OS2 */# if defined(OS_ISC) && defined(_POSIX_SOURCE)/* Kludge for ISC 3.2 (and other versions?) so programs will run correctly.  */#  define ksh_execve(p, av, ev, flags) \				do { \					__setostype(0); \					execve(p, av, ev); \					__setostype(1); \				} while (0)# else /* OS_ISC && _POSIX */#  define ksh_execve(p, av, ev, flags)	execve(p, av, ev)# endif /* OS_ISC && _POSIX */#endif /* OS2 *//* this is a hang-over from older versions of the os2 port */#define ksh_dupbase(fd, base) fcntl(fd, F_DUPFD, base)#ifdef HAVE_SIGSETJMP# define ksh_sigsetjmp(env,sm)	sigsetjmp((env), (sm))# define ksh_siglongjmp(env,v)	siglongjmp((env), (v))# define ksh_jmp_buf		sigjmp_buf#else /* HAVE_SIGSETJMP */# ifdef HAVE__SETJMP#  define ksh_sigsetjmp(env,sm)	_setjmp(env)#  define ksh_siglongjmp(env,v)	_longjmp((env), (v))# else /* HAVE__SETJMP */#  define ksh_sigsetjmp(env,sm)	setjmp(env)#  define ksh_siglongjmp(env,v)	longjmp((env), (v))# endif /* HAVE__SETJMP */# define ksh_jmp_buf		jmp_buf#endif /* HAVE_SIGSETJMP */#ifndef HAVE_DUP2extern int dup2 ARGS((int, int));#endif /* !HAVE_DUP2 *//* Find a integer type that is at least 32 bits (or die) - SIZEOF_* defined * by autoconf (assumes an 8 bit byte, but I'm not concerned). * NOTE: INT32 may end up being more than 32 bits. */#ifdef __OLD__#if SIZEOF_INT >= 4# define INT32	long/* #else SIZEOF_INT */# if SIZEOF_LONG >= 4#  define INT32	long# else /* SIZEOF_LONG */   #error cannot find 32 bit type...# endif /* SIZEOF_LONG */#endif /* SIZEOF_INT */#endif#define INT32 long/* end of common headers *//* Stop gcc and lint from complaining about possibly uninitialized variables */#if defined(__GNUC__) || defined(lint)# define UNINITIALIZED(var)	var = 0#else# define UNINITIALIZED(var)	var#endif /* GNUC || lint *//* some useful #defines */#ifdef EXTERN# define I__(i) = i#else# define I__(i)# define EXTERN extern# define EXTERN_DEFINED#endif#ifdef OS2# define inDOS() (!(_emx_env & 0x200))#endif#ifndef EXECSHELL/* shell to exec scripts (see also $SHELL initialization in main.c) */# ifdef OS2#  define EXECSHELL	(inDOS() ? "c:\\command.com" : "c:\\os2\\cmd.exe")#  define EXECSHELL_STR	(inDOS() ? "COMSPEC" : "OS2_SHELL")# else /* OS2 */#  define EXECSHELL	"/bin/sh"#  define EXECSHELL_STR	"EXECSHELL"# endif /* OS2 */#endif/* ISABSPATH() means path is fully and completely specified, * ISROOTEDPATH() means a .. as the first component is a no-op, * ISRELPATH() means $PWD can be tacked on to get an absolute path. * * OS		Path		ISABSPATH	ISROOTEDPATH	ISRELPATH * unix		/foo		yes		yes		no * unix		foo		no		no		yes * unix		../foo		no		no		yes * os2+cyg	a:/foo		yes		yes		no * os2+cyg	a:foo		no		no		no * os2+cyg	/foo		no		yes		no * os2+cyg	foo		no		no		yes * os2+cyg	../foo		no		no		yes * cyg 		//foo		yes		yes		no */#ifdef OS2# define PATHSEP        ';'# define DIRSEP         '/'	/* even though \ is native */# define DIRSEPSTR      "\\"# define ISDIRSEP(c)    ((c) == '\\' || (c) == '/')# define ISABSPATH(s)	(((s)[0] && (s)[1] == ':' && ISDIRSEP((s)[2])))# define ISROOTEDPATH(s) (ISDIRSEP((s)[0]) || ISABSPATH(s))# define ISRELPATH(s)	(!(s)[0] || ((s)[1] != ':' && !ISDIRSEP((s)[0])))# define FILECHCONV(c)	(isascii(c) && isupper(c) ? tolower(c) : c)# define FILECMP(s1, s2) stricmp(s1, s2)# define FILENCMP(s1, s2, n) strnicmp(s1, s2, n)extern char *ksh_strchr_dirsep(const char *path);extern char *ksh_strrchr_dirsep(const char *path);# define chdir          _chdir2# define getcwd         _getcwd2#else# define PATHSEP        ':'# define DIRSEP         '/'# define DIRSEPSTR      "/"# define ISDIRSEP(c)    ((c) == '/')#ifdef __CYGWIN__#  define ISABSPATH(s) \       (((s)[0] && (s)[1] == ':' && ISDIRSEP((s)[2])) || ISDIRSEP((s)[0]))#  define ISRELPATH(s) (!(s)[0] || ((s)[1] != ':' && !ISDIRSEP((s)[0])))#else /* __CYGWIN__ */# define ISABSPATH(s)	ISDIRSEP((s)[0])# define ISRELPATH(s)	(!ISABSPATH(s))#endif /* __CYGWIN__ */# define ISROOTEDPATH(s) ISABSPATH(s)# define FILECHCONV(c)	c# define FILECMP(s1, s2) strcmp(s1, s2)# define FILENCMP(s1, s2, n) strncmp(s1, s2, n)# define ksh_strchr_dirsep(p)   strchr(p, DIRSEP)# define ksh_strrchr_dirsep(p)  strrchr(p, DIRSEP)#endiftypedef int bool_t;#define	FALSE	0#define	TRUE	1#define	NELEM(a) (sizeof(a) / sizeof((a)[0]))#define	sizeofN(type, n) (sizeof(type) * (n))#define	BIT(i)	(1<<(i))	/* define bit in flag *//* Table flag type - needs > 16 and < 32 bits */typedef INT32 Tflag;#define	NUFILE	10		/* Number of user-accessible files */#define	FDBASE	10		/* First file usable by Shell *//* you're not going to run setuid shell scripts, are you? */#define	eaccess(path, mode)	access(path, mode)/* Make MAGIC a char that might be printed to make bugs more obvious, but * not a char that is used often.  Also, can't use the high bit as it causes * portability problems (calling strchr(x, 0x80|'x') is error prone). */#define	MAGIC		(7)/* prefix for *?[!{,} during expand */#define ISMAGIC(c)	((unsigned char)(c) == MAGIC)#define	NOT		'!'	/* might use ^ (ie, [!...] vs [^..]) */#define	LINE	1024		/* input line size */#define	PATH	1024		/* pathname size (todo: PATH_MAX/pathconf()) */#define ARRAYMAX 1023		/* max array index */EXTERN	const char *kshname;	/* $0 */

⌨️ 快捷键说明

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