1 /***********************************************************************
2  *                                                                      *
3  *               This software is part of the ast package               *
4  *          Copyright (c) 1982-2013 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 <dgkorn@gmail.com>                     *
18  *                                                                      *
19  ***********************************************************************/
20 //
21 // UNIX shell path handling interface.
22 // Written by David Korn.
23 // These are the definitions for the lexical analyzer.
24 //
25 #ifndef _PATH_H
26 #define _PATH_H 1
27 
28 #include "name.h"
29 #include "shell.h"
30 
31 #define PATH_PATH (1 << 0)
32 #define PATH_FPATH (1 << 1)  // do not change this value; see can_execute() and path_absolute()
33 #define PATH_CDPATH (1 << 2)
34 #define PATH_BFPATH (1 << 3)
35 #define PATH_SKIP (1 << 4)
36 #define PATH_BUILTIN_LIB (1 << 5)
37 #define PATH_STD_DIR (1 << 6)  // directory is on $(getconf PATH)
38 #define PATH_BIN (1 << 7)      // path behaves like /bin for builtins
39 
40 #define PATH_OFFSET 2  // path offset for path_join
41 #define MAXDEPTH 1024  // maximum recursion depth
42 
43 //
44 // Path component structure for path searching.
45 //
46 struct pathcomp {
47     struct pathcomp *next;
48     int refcount;
49     dev_t dev;
50     ino_t ino;
51     time_t mtime;
52     char *name;
53     char *lib;
54     char *bbuf;
55     char *blib;
56     unsigned short len;
57     unsigned short flags;
58     Shell_t *shp;
59 };
60 
61 #ifndef ARG_RAW
62 struct argnod;
63 #endif  // !ARG_RAW
64 
65 // Pathname handling routines.
66 extern void path_newdir(Shell_t *, Pathcomp_t *);
67 extern Pathcomp_t *path_dirfind(Pathcomp_t *, const char *, int);
68 extern Pathcomp_t *path_unsetfpath(Shell_t *);
69 extern Pathcomp_t *path_addpath(Shell_t *, Pathcomp_t *, const char *, int);
70 extern bool path_cmdlib(Shell_t *, const char *, bool);
71 extern Pathcomp_t *path_dup(Pathcomp_t *);
72 extern void path_delete(Pathcomp_t *);
73 extern void path_alias(Namval_t *, Pathcomp_t *);
74 extern Pathcomp_t *path_absolute(Shell_t *, const char *, Pathcomp_t *);
75 extern char *path_basename(const char *);
76 extern char *path_fullname(Shell_t *, const char *);
77 extern int path_expand(Shell_t *, const char *, struct argnod **);
78 extern void path_exec(Shell_t *, const char *, char *[], struct argnod *);
79 extern pid_t path_spawn(Shell_t *, const char *, char *[], char *[], Pathcomp_t *, int);
80 extern int path_open(Shell_t *, const char *, Pathcomp_t *);
81 extern Pathcomp_t *path_get(Shell_t *, const char *);
82 extern char *path_pwd(Shell_t *);
83 extern Pathcomp_t *path_nextcomp(Shell_t *, Pathcomp_t *, const char *, Pathcomp_t *);
84 extern bool path_search(Shell_t *, const char *, Pathcomp_t **, int);
85 extern char *path_relative(Shell_t *, const char *);
86 extern int path_complete(Shell_t *, const char *, const char *, struct argnod **);
87 extern int path_generate(Shell_t *, struct argnod *, struct argnod **);
88 
89 // Builtin/plugin routines.
90 extern int sh_addlib(Shell_t *, void *, char *, Pathcomp_t *);
91 extern Shbltin_f sh_getlib(Shell_t *, char *, Pathcomp_t *);
92 
93 // Constant strings needed for whence.
94 extern const char e_timeformat[];
95 extern const char e_badtformat[];
96 extern const char e_dot[];
97 extern const char e_funload[];
98 extern const char e_pfsh[];
99 extern const char e_pwd[];
100 extern const char e_logout[];
101 extern const char e_alphanum[];
102 extern const char e_mailmsg[];
103 extern const char e_suidprofile[];
104 extern const char e_sysprofile[];
105 extern const char e_traceprompt[];
106 extern const char is_alias[];
107 extern const char is_builtin[];
108 extern const char is_spcbuiltin[];
109 extern const char is_builtver[];
110 extern const char is_reserved[];
111 extern const char is_talias[];
112 extern const char is_xalias[];
113 extern const char is_function[];
114 extern const char is_ufunction[];
115 extern const char e_prohibited[];
116 
117 #endif  // _PATH_H
118