1 /***********************************************************************
2  *                                                                      *
3  *               This software is part of the ast package               *
4  *          Copyright (c) 1985-2011 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  *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
18  *                    David Korn <dgkorn@gmail.com>                     *
19  *                     Phong Vo <phongvo@gmail.com>                     *
20  *                                                                      *
21  ***********************************************************************/
22 /*
23  * posix glob interface definitions with gnu extensions
24  */
25 #ifndef _GLOB_H
26 #define _GLOB_H 1
27 
28 // #define GLOB_VERSION 20060717L
29 
30 #include <dirent.h>
31 #include <stdlib.h>
32 
33 #include "ast_regex.h"
34 #include "sfio.h"
35 #include "stk.h"
36 
37 struct stat;
38 
39 struct _glob_;
40 struct _globlist_;
41 
42 typedef struct _glob_ glob_t;
43 typedef struct _globlist_ globlist_t;
44 typedef int (*GL_error_f)(const char *, int);
45 
46 struct _globlist_ {
47     globlist_t *gl_next;
48     char *gl_begin;
49     unsigned char gl_flags;
50     char gl_path[1];
51 };
52 
53 struct _glob_ {
54     size_t gl_pathc;
55     char **gl_pathv;
56     size_t gl_offs;
57     globlist_t *gl_list;
58     int gl_flags;
59 
60     /* GLOB_DISC data -- memset(&gl,0,sizeof(gl)) before using! */
61 
62     const char *gl_fignore;
63     const char *gl_suffix;
64     const unsigned char *gl_intr;
65 
66     int gl_delim;
67 
68     Pathcomp_t *gl_handle;
69     DIR *(*gl_diropen)(glob_t *, const char *);
70     char *(*gl_dirnext)(glob_t *, DIR *);
71     int (*gl_dirclose)(glob_t *, DIR *);
72     int (*gl_type)(glob_t *, const char *, int);
73     int (*gl_attr)(glob_t *, const char *, int);
74 
75     /* gnu extensions -- but how do you synthesize dirent and stat? */
76 
77     DIR *(*gl_opendir)(const char *);
78     struct dirent *(*gl_readdir)(DIR *);
79     int (*gl_closedir)(DIR *);
80     int (*gl_stat)(const char *, struct stat *);
81     int (*gl_lstat)(const char *, struct stat *);
82 
83     /* ast additions */
84 
85     char *(*gl_nextdir)(glob_t *, char *);
86     unsigned long gl_status;
87     unsigned long gl_version;
88     unsigned short gl_extra;
89 
90     GL_error_f gl_errfn;
91     int gl_error;
92     char *gl_nextpath;
93     globlist_t *gl_rescan;
94     globlist_t *gl_match;
95     Sfio_t *gl_stak;
96     int re_flags;
97     int re_first;
98     regex_t *gl_ignore;
99     regex_t *gl_ignorei;
100     regex_t re_ignore;
101     regex_t re_ignorei;
102     unsigned long gl_starstar;
103     char *gl_opt;
104     char *gl_pat;
105     char *gl_pad[4];
106 };
107 
108 /* standard interface */
109 #define GLOB_APPEND 0x0001   /* append to previous              */
110 #define GLOB_DOOFFS 0x0002   /* gl_offs defines argv offset     */
111 #define GLOB_ERR 0x0004      /* abort on error          */
112 #define GLOB_MARK 0x0008     /* append / to directories */
113 #define GLOB_NOCHECK 0x0010  /* nomatch is original pattern     */
114 #define GLOB_NOESCAPE 0x0020 /* don't treat \ specially */
115 #define GLOB_NOSORT 0x0040   /* don't sort the list             */
116 
117 /* extended interface */
118 #define GLOB_STARSTAR 0x0080   /* enable [/]**[/] expansion     */
119 #define GLOB_BRACE 0x0100      /* enable {...} expansion        */
120 #define GLOB_ICASE 0x0200      /* ignore case on match          */
121 #define GLOB_COMPLETE 0x0400   /* shell file completion         */
122 #define GLOB_AUGMENTED 0x0800  /* augmented shell patterns      */
123 #define GLOB_STACK 0x1000      /* allocate on current stack     */
124 #define GLOB_LIST 0x2000       /* just create gl_list           */
125 #define GLOB_ALTDIRFUNC 0x4000 /* gnu discipline functions      */
126 #define GLOB_DISC 0x8000       /* discipline initialized        */
127 
128 #define GLOB_GROUP 0x10000 /* REG_SHELL_GROUP           */
129 
130 /* gl_status */
131 #define GLOB_NOTDIR 0x0001 /* last gl_dirnext() not a dir       */
132 
133 /* gl_type return */
134 #define GLOB_DEV 1 /* exists but not DIR EXE REG        */
135 #define GLOB_DIR 2 /* directory                 */
136 #define GLOB_EXE 3 /* executable regular file   */
137 #define GLOB_REG 4 /* regular file                      */
138 
139 /* error return values */
140 #define GLOB_ABORTED 1
141 #define GLOB_NOMATCH 2
142 #define GLOB_NOSPACE 3
143 #define GLOB_INTR 4
144 #define GLOB_APPERR 5
145 
146 extern int ast_glob(const char *, int, int (*)(const char *, int), glob_t *);
147 
148 #endif  // _GLOB_H
149