1/***********************************************************************
2*                                                                      *
3*               This software is part of the ast package               *
4*          Copyright (c) 1982-2012 AT&T Intellectual Property          *
5*                      and is licensed under the                       *
6*                 Eclipse Public License, Version 1.0                  *
7*                    by AT&T Intellectual Property                     *
8*                                                                      *
9*                A copy of the License is available at                 *
10*          http://www.eclipse.org/org/documents/epl-v10.html           *
11*         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12*                                                                      *
13*              Information and Software Systems Research               *
14*                            AT&T Research                             *
15*                           Florham Park NJ                            *
16*                                                                      *
17*                  David Korn <dgk@research.att.com>                   *
18*                                                                      *
19***********************************************************************/
20#pragma prototyped
21#ifndef PATH_OFFSET
22
23/*
24 *	UNIX shell path handling interface
25 *	Written by David Korn
26 *	These are the definitions for the lexical analyzer
27 */
28
29#include	"FEATURE/options"
30#include	<nval.h>
31#include	"defs.h"
32
33#if !defined(SHOPT_SPAWN)
34#   if _UWIN || _use_spawnveg || !_lib_fork
35#	define  SHOPT_SPAWN  1
36#   endif
37#endif /* !SHOPT_SPAWN */
38
39#define PATH_PATH		0001
40#define PATH_FPATH		0002
41#define PATH_CDPATH		0004
42#define PATH_BFPATH		0010
43#define PATH_SKIP		0020
44#define PATH_BUILTIN_LIB	0040
45#define PATH_STD_DIR		0100	/* directory is on  $(getconf PATH) */
46
47#define PATH_OFFSET	2		/* path offset for path_join */
48#define MAXDEPTH	(sizeof(char*)==2?64:1024) /* maximum recursion depth*/
49
50/*
51 * path component structure for path searching
52 */
53typedef struct pathcomp
54{
55	struct pathcomp *next;
56	int		refcount;
57	dev_t		dev;
58	ino_t		ino;
59	time_t		mtime;
60	char		*name;
61	char		*lib;
62	char		*bbuf;
63	char		*blib;
64	unsigned short	len;
65	unsigned short	flags;
66	Shell_t		*shp;
67} Pathcomp_t;
68
69#ifndef ARG_RAW
70    struct argnod;
71#endif /* !ARG_RAW */
72
73/* pathname handling routines */
74extern void		path_newdir(Shell_t*,Pathcomp_t*);
75extern Pathcomp_t	*path_dirfind(Pathcomp_t*,const char*,int);
76extern Pathcomp_t	*path_unsetfpath(Shell_t*);
77extern Pathcomp_t	*path_addpath(Shell_t*,Pathcomp_t*,const char*,int);
78extern Pathcomp_t	*path_dup(Pathcomp_t*);
79extern void		path_delete(Pathcomp_t*);
80extern void 		path_alias(Namval_t*,Pathcomp_t*);
81extern Pathcomp_t 	*path_absolute(Shell_t*, const char*, Pathcomp_t*);
82extern char 		*path_basename(const char*);
83extern char 		*path_fullname(Shell_t*,const char*);
84extern int 		path_expand(Shell_t*,const char*, struct argnod**);
85extern void 		path_exec(Shell_t*,const char*,char*[],struct argnod*);
86extern pid_t		path_spawn(Shell_t*,const char*,char*[],char*[],Pathcomp_t*,int);
87#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
88#   define extern __EXPORT__
89#endif
90extern int		path_open(Shell_t*,const char*,Pathcomp_t*);
91extern Pathcomp_t 	*path_get(Shell_t*,const char*);
92#undef extern
93extern char 		*path_pwd(Shell_t*,int);
94extern Pathcomp_t	*path_nextcomp(Shell_t*,Pathcomp_t*,const char*,Pathcomp_t*);
95extern int		path_search(Shell_t*,const char*,Pathcomp_t**,int);
96extern char		*path_relative(Shell_t*,const char*);
97extern int		path_complete(Shell_t*,const char*, const char*,struct argnod**);
98#if SHOPT_BRACEPAT
99    extern int 		path_generate(Shell_t*,struct argnod*,struct argnod**);
100#endif /* SHOPT_BRACEPAT */
101    extern int		path_xattr(Shell_t*, const char*, char*);
102
103/* builtin/plugin routines */
104extern int		sh_addlib(Shell_t*,void*,char*,Pathcomp_t*);
105extern Shbltin_f	sh_getlib(Shell_t*,char*,Pathcomp_t*);
106
107/* constant strings needed for whence */
108extern const char e_timeformat[];
109extern const char e_badtformat[];
110extern const char e_dot[];
111extern const char e_funload[];
112extern const char e_pfsh[];
113extern const char e_pwd[];
114extern const char e_logout[];
115extern const char e_alphanum[];
116extern const char e_mailmsg[];
117extern const char e_suidprofile[];
118extern const char e_sysprofile[];
119extern const char e_traceprompt[];
120extern const char e_crondir[];
121#if SHOPT_SUID_EXEC
122    extern const char	e_suidexec[];
123#endif /* SHOPT_SUID_EXEC */
124extern const char is_alias[];
125extern const char is_builtin[];
126extern const char is_spcbuiltin[];
127extern const char is_builtver[];
128extern const char is_reserved[];
129extern const char is_talias[];
130extern const char is_xalias[];
131extern const char is_function[];
132extern const char is_ufunction[];
133#ifdef SHELLMAGIC
134    extern const char e_prohibited[];
135#endif /* SHELLMAGIC */
136
137#if SHOPT_ACCT
138#   include	"FEATURE/acct"
139#   ifdef	_sys_acct
140	extern void sh_accinit(void);
141	extern void sh_accbegin(const char*);
142	extern void sh_accend(void);
143	extern void sh_accsusp(void);
144#   else
145#	undef	SHOPT_ACCT
146#   endif	/* _sys_acct */
147#endif /* SHOPT_ACCT */
148
149#endif /*! PATH_OFFSET */
150