VirtualBox

source: vbox/trunk/include/iprt/parseshell.h@ 106430

Last change on this file since 106430 was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/* $Id: parseshell.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * IPRT - Parser, Bourne-like Shell.
4 */
5
6/*
7 * Copyright (C) 2022-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_parseshell_h
38#define IPRT_INCLUDED_parseshell_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/list.h>
44
45RT_C_DECLS_BEGIN
46
47/** @defgroup grp_rt_parse RTParse - Generic Parser
48 * @{ */
49
50
51/**
52 * IPRT parse node types.
53 */
54typedef enum RTPARSENODETYPE
55{
56 RTPARSENODETYPE_INVALID = 0,
57
58 /** Single quoted (sub-)string. */
59 RTPARSENODETYPE_STRING_SQ,
60 /** Double quoted (sub-)string. */
61 RTPARSENODETYPE_STRING_DQ,
62 /** Unquoted string. */
63 RTPARSENODETYPE_STRING_UQ,
64
65 RTPARSENODETYPE_END
66} RTPARSENODETYPE;
67
68
69/**
70 * Type info for an IPRT parser node.
71 *
72 * This is for simplifying generic processing, dumping and such things. It may
73 * be extended with method pointers if deemed useful/sensible.
74 */
75typedef struct RTPARSENODETYPEINFO
76{
77 /** The node type. */
78 RTPARSENODETYPE enmType;
79 /** Number of child pointers. */
80 uint8_t cChildPtrs;
81 /** The type name. */
82 const char *pszName;
83 /** Pointer to a list of child member names. */
84 const char * const *papszChild;
85} RTPARSENODETYPEINFO;
86/** Pointer (const) to type info for a parser node. */
87typedef RTPARSENODETYPEINFO const *PCRTPARSENODETYPEINFO;
88
89
90/**
91 * Source location for an IPRT parser instance.
92 */
93typedef struct RTPARSESRCLOC
94{
95 /** The line number (0-based). */
96 RT_GCC_EXTENSION uint64_t iLine : 24;
97 /** The line offset (0-based). */
98 RT_GCC_EXTENSION uint64_t offLine : 24;
99 /** The file index (zero is invalid). */
100 RT_GCC_EXTENSION uint64_t idxFile : 16;
101} RTPARSESRCLOC;
102/** Pointer to a source location for an IPRT parser instance. */
103typedef RTPARSESRCLOC *PRTPARSESRCLOC;
104/** Pointer to a const source location for an IPRT parser instance. */
105typedef RTPARSESRCLOC const *PCRTPARSESRCLOC;
106
107
108/** Pointer to a parser base node. */
109typedef struct RTPARSENODE RT_FAR *PRTPARSENODE;
110/** Pointer to a const parser base node. */
111typedef struct RTPARSENODE const RT_FAR *PCRTPARSENODE;
112/**
113 * IPRT parser base node.
114 *
115 * All parse three nodes derive from this one.
116 *
117 * @note If there are children, their list anchors must all follow immediately
118 * after this structure.
119 */
120typedef struct RTPARSENODE
121{
122 /** The node type info. */
123 PCRTPARSENODETYPEINFO pType;
124 /** Node type specific flags. */
125 unsigned fFlags;
126 /** User flags/whatever. */
127 unsigned fUser;
128 /** Pointer to user specified data. */
129 void *pvUser;
130 /** Source location. */
131 RTPARSESRCLOC SrcLoc;
132 /** The parent node. */
133 PRTPARSENODE pParent;
134 /** The sibling list entry (PRTPARSENODE). */
135 RTLISTNODE ListEntry;
136} RTPARSENODE;
137
138
139typedef struct RTPARSENODEBODY
140{
141 /** The common part. */
142 RTPARSENODE Core;
143 /** The children list (PRTPARSENODE). */
144 RTLISTANCHOR Body;
145} RTPARSENODEBODY;
146
147
148typedef struct RTPARSENODEBINARY
149{
150 /** The common part. */
151 RTPARSENODE Core;
152 /** The first child (left side) (PRTPARSENODE). */
153 RTLISTANCHOR Child1;
154 /** The second child (right side) (PRTPARSENODE). */
155 RTLISTANCHOR Child2;
156} RTPARSENODEBINARY;
157
158
159/**
160 * A string node.
161 *
162 * This is used wtih
163 */
164typedef struct RTPARSENODESTRING
165{
166 /** The common part. */
167 RTPARSENODE Core;
168 /** Pointer to the string. */
169 const char *psz;
170 /** String length. */
171 size_t cch;
172} RTPARSENODESTRING;
173
174/** @} */
175
176/** @defgroup grp_rt_parse_shell RTParseShell - Bourne-like Shell Parser
177 * @{ */
178
179struct RTPARSESHELLINT;
180/** Handle to a bourne-like shell parser. */
181typedef struct RTPARSESHELLINT *RTPARSESHELL;
182/** Pointer to a bourne-like shell parser. */
183typedef RTPARSESHELL *PRTPARSESHELL;
184/** NIL handle to a bourne-like shell parser. */
185#define NIL_RTPARSESHELL ((RTPARSESHELL)~(uintptr_t)0)
186
187
188/** @} */
189
190RT_C_DECLS_END
191
192#endif /* !IPRT_INCLUDED_parseshell_h */
193
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette