1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*
* tcglob.h -- simple iterator over a path collection expressed through
* glob (7) semantic.
* (C) 2007-2010 - Francesco Romani <fromani -at- gmail -dot- com>
*
* This file is part of transcode, a video stream processing tool.
*
* transcode is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* transcode is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TCGLOB_H
#define TCGLOB_H
/*
* Quick Summary:
* this code iterates over a collection of pathnames expressed through
* glob (7) syntax, in a compact, consolidated and efficient way.
* The intended usage of this code is as iterator/pathname generator.
*
*/
#include <stdint.h>
/* opaque type */
typedef struct tcglob_ TCGlob;
/*
* tc_glob_open:
* create a new TCGlob structure based on a given pathname
* glob expression.
*
* Parameters:
* pattern: glob pattern expression to be expanded
* flags: currently unused (use 0 (zero)).
* Return Value:
* if succesfull, a newly-allocated TCGlob structure ready
* to be used through tc_glob_* functions;
* (use tc_glob_close() to dispose it)
* NULL if failed.
*/
TCGlob *tc_glob_open(const char *pattern, uint32_t flags);
/*
* tc_glob_next:
* get new expanded pathname from given tcglob structure.
*
* Parameters:
* tcg: pointer to TCGlob structure to be used.
* Return Value:
* if succesfull, a constant pointer to the next expanded pathname.
* there is NO NEED to free() it explicitely after usage.
* The returned pointer is guaranteed to be valid AT LEAST until
* next tc_glob_next() call, but not after.
* if failed, returns NULL.
* PLEASE NOTE that this function returns NULL also if all pathnames
* are been expanded, so there is NO MORE pathname to get.
* You can safely think that returning NULL acts as 'guard condition'
* meaning something like 'iteration must end here'.
* (see also tc_glob_has_more)
*/
const char *tc_glob_next(TCGlob *tcg);
/*
* tc_glob_has_more:
* tell if current glob expression has at least one more pathname to
* be expanded (= is terminated) or not.
*
* Parameters:
* tcg: pointer to TCGlob structure to be checked.
* Return Value:
* > 0: pathname expansion not yet ended (= there is at least one more
* pathname to get with tc_glob_next)
* 0: pathname expansion ended.
*/
int tc_glob_has_more(TCGlob *tcg);
/*
* tc_glob_close:
* finalize a TCGlob structure and release all resources acquired via
* tc_glob_open. Subsequent tc_glob_* calls using this TCGlob structure
* will lead to undefined behaviour.
*
* Parameters:
* tcg: pointer to TCGlob structure to be finalized.
* Return Value:
* !0: succesfull.
* 0: otherwise.
*/
int tc_glob_close(TCGlob *tcg);
#endif /* TCGLOB_H */
|