1 /*
2 ** cdecl -- C gibberish translator
3 ** src/c_sglob.h
4 **
5 ** Copyright (C) 2021 Paul J. Lucas
6 **
7 ** This program is free software: you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation, either version 3 of the License, or
10 ** (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef cdecl_c_sglob_H
22 #define cdecl_c_sglob_H
23
24 /**
25 * @file
26 * Declares functions for dealing with "sglob" (C++ scoped name glob) objects,
27 * e.g., `S::T::*`, that are used to match snames (C++ scoped names).
28 *
29 * As a special case, the first glob may be `**` that is used to match any
30 * scope.
31 *
32 * @note For C, an sglob is simply a single glob, e.g., `x*`.
33 * @sa c_sname_match()
34 */
35
36 // local
37 #include "pjl_config.h" /* must go first */
38 #include "types.h"
39 #include "util.h"
40
41 /// @cond DOXYGEN_IGNORE
42
43 // standard
44 #include <stdbool.h>
45 #include <stddef.h> /* for size_t */
46
47 _GL_INLINE_HEADER_BEGIN
48 #ifndef C_SGLOB_INLINE
49 # define C_SGLOB_INLINE _GL_INLINE
50 #endif /* C_SGLOB_INLINE */
51
52 /// @endcond
53
54 /**
55 * @defgroup sglob-group Scoped Globs
56 * Functions for accessing and manipulating C++ scoped globs.
57 * @{
58 */
59
60 ///////////////////////////////////////////////////////////////////////////////
61
62 /**
63 * C++ scoped name glob, e.g., `S::T::x*`.
64 */
65 struct c_sglob {
66 size_t count; ///< Number of scopes.
67 char **pattern; ///< Array[count] of glob patterns.
68 bool match_in_any_scope; ///< Match in any scope?
69 };
70
71 ////////// extern functions ///////////////////////////////////////////////////
72
73 /**
74 * Cleans-up all memory associated with \a sglob but does _not_ free \a sglob
75 * itself.
76 *
77 * @param sglob The scoped glob to clean up. If NULL, does nothing.
78 *
79 * @sa c_sglob_init()
80 */
81 void c_sglob_cleanup( c_sglob_t *sglob );
82
83 /**
84 * Initializes \a sglob.
85 *
86 * @param sglob The scoped glob to initialize.
87 *
88 * @note This need not be called for either global or `static` scoped names.
89 *
90 * @sa c_sglob_cleanup()
91 */
92 C_SGLOB_INLINE
c_sglob_init(c_sglob_t * sglob)93 void c_sglob_init( c_sglob_t *sglob ) {
94 MEM_ZERO( sglob );
95 }
96
97 /**
98 * Parses the glob string \a s into \a sglob.
99 *
100 * @param s The glob string to parse. May be NULL. If not, it _must_ be a
101 * valid glob string.
102 * @param sglob The scoped glob to parse into. The caller is responsible for
103 * calling c_glob_cleanup().
104 *
105 * @sa c_sglob_cleanup()
106 */
107 void c_sglob_parse( char const *s, c_sglob_t *sglob );
108
109 ///////////////////////////////////////////////////////////////////////////////
110
111 /** @} */
112
113 _GL_INLINE_HEADER_END
114
115 #endif /* cdecl_c_sglob_H */
116 /* vim:set et sw=2 ts=2: */
117