xref: /netbsd-src/common/lib/libppath/ppath.3 (revision 5bbd2a12505d72a8177929a37b5cee489d0a1cfd)
1.\"	$NetBSD: ppath.3,v 1.2 2011/08/25 15:12:38 wiz Exp $
2.\"	$Id: ppath.3,v 1.2 2011/08/25 15:12:38 wiz Exp $
3.\"
4.\" Copyright (c) 2011 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by David Young <dyoung@NetBSD.org>.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY EXPRESS
20.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL David Young BE LIABLE FOR ANY
23.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd August 24, 2011
32.Dt PPATH 3
33.Os
34.Sh NAME
35.Nm ppath ,
36.Nm ppath_idx ,
37.Nm ppath_key ,
38.\" ,
39.Nm ppath_component_retain ,
40.Nm ppath_component_release ,
41.\" ,
42.Nm ppath_create ,
43.Nm ppath_length ,
44.Nm ppath_component_idx ,
45.Nm ppath_component_key ,
46.Nm ppath_pop ,
47.Nm ppath_push ,
48.Nm ppath_component_at ,
49.Nm ppath_subpath ,
50.Nm ppath_push_idx ,
51.Nm ppath_push_key ,
52.Nm ppath_replace_idx ,
53.Nm ppath_replace_key ,
54.\" ,
55.Nm ppath_copy ,
56.Nm ppath_retain ,
57.Nm ppath_release ,
58.\" ,
59.Nm ppath_lookup ,
60.\" ,
61.Nd property container path library
62.Sh LIBRARY
63.Lb libppath
64.Sh SYNOPSIS
65.In ppath/ppath.h
66.\"
67.Ft "ppath_component_t *"
68.Fn ppath_idx "unsigned int index"
69.Ft "ppath_component_t *"
70.Fn ppath_key "const char *key"
71.\"
72.Ft "ppath_component_t *"
73.Fn ppath_component_retain "ppath_component_t *pc"
74.Ft void
75.Fn ppath_component_release "ppath_component_t *pc"
76.\"
77.Ft "ppath_t *"
78.Fn ppath_create "void"
79.Ft "unsigned int"
80.Fn ppath_length "const ppath_t *p"
81.Ft int
82.Fn ppath_component_idx "const ppath_component_t *"
83.Ft const char *
84.Fn ppath_component_key "const ppath_component_t *"
85.Ft "ppath_t *"
86.Fn ppath_pop "ppath_t *" "ppath_component_t **"
87.Ft ppath_t *
88.Fn ppath_push "ppath_t *" "ppath_component_t *"
89.Ft ppath_component_t *
90.Fn ppath_component_at "const ppath_t *" "unsigned int"
91.Ft ppath_t *
92.Fn ppath_subpath "const ppath_t *" "unsigned int" "unsigned int"
93.Ft ppath_t *
94.Fn ppath_push_idx "ppath_t *" "unsigned int"
95.Ft ppath_t *
96.Fn ppath_push_key "ppath_t *" "const char *"
97.Ft ppath_t *
98.Fn ppath_replace_idx "ppath_t *" "unsigned int"
99.Ft ppath_t *
100.Fn ppath_replace_key "ppath_t *" "const char *"
101.\"
102.Ft ppath_t *
103.Fn ppath_copy "const ppath_t *"
104.Ft ppath_t *
105.Fn ppath_retain "ppath_t *"
106.Ft void
107.Fn ppath_release "ppath_t *"
108.\"
109.Ft prop_object_t
110.Fn ppath_lookup "prop_object_t" "const ppath_t *"
111.\"
112.Sh DESCRIPTION
113The
114.Nm
115library provides functions to read, write, or delete objects in a
116property list.
117A property-list
118.Dq path
119names the object in a property list to read, write, or delete.
120.Pp
121A property-list path is an ordered array of zero or more array
122indices and dictionary keys that names at most one
123.Vt prop_object_t
124in a property list.
125The abstract function
126.Fn E
127evaluates
128a property-list path against a
129.Vt prop_object_t ,
130.Va o ,
131to yield a
132.Vt prop_object_t
133result according to the following recursive definition, where
134.Fa empty
135indicates the empty
136.Pq zero-length
137path and the operator
138.Dq |
139indicates the concatenation of the path on the left-hand side with
140the key or index on the right-hand side:
141.Bl -tag -width "E(o, p | index)"
142.It Fn E "o" "empty"
143Evaluates to
144.Fa o .
145.It Fn E "o" "p | index"
146If
147.Fn E "o" "p"
148evaluates to a
149.Vt prop_array_t ,
150then
151.Fn E "o" "p | index"
152evaluates to the
153.Fa index 'th
154element of that array.
155Otherwise, an error occurs.
156.It Fn E "o" "p | key"
157If
158.Fn E "o" "p"
159evaluates to a
160.Vt prop_dictionary_t ,
161then
162.Fn E "o" "p | key"
163evaluates to the dictionary value stored under
164.Fa key .
165Otherwise, an error occurs.
166.El
167.Pp
168The programmer may think of property-list paths as working similarly
169to paths in a file system, where property arrays and dictionaries
170correspond to directories, and all other property types correspond
171to files.
172.Sh DATA TYPES
173.Nm
174provides two opaque types:
175.Bl -tag -width ppath_component
176.It Vt ppath_component_t
177A property-list path component: a single key or index.
178.Nm
179counts references to a
180.Vt ppath_component_t
181and reclaims its storage when there are no more references.
182.It Vt ppath_t
183An array of zero or more property-list path components.
184.Nm
185counts references to a
186.Vt ppath_t
187and reclaims its storage when there are no more references.
188.El
189.Sh FUNCTIONS
190.Nm
191provides these functions for manipulating property-list paths
192and their components:
193.Bl -tag -width ppath
194.It Fn ppath_idx "unsigned int index"
195Allocate a new
196.Vt ppath_component_t
197for the given array index and return it.
198Its reference count is initially one.
199.Pp
200If there is not sufficient memory to complete the request, return
201.Dv NULL .
202.It Fn ppath_key "const char *key"
203Allocate a new
204.Vt ppath_component_t
205for the given dictionary key and return it.
206Its reference count is initially one.
207.Pp
208If there is not sufficient memory to complete the request, return
209.Dv NULL .
210.\"
211.It Fn ppath_component_retain "ppath_component_t *pc"
212Increase the reference count on
213.Fa pc
214by one.
215.It Fn ppath_component_release "ppath_component_t *pc"
216Decrease the reference count on
217.Fa pc
218by one.
219If the reference count reaches zero, reclaim the storage
220for
221.Fa pc .
222.\"
223.It Fn ppath_create "void"
224Create a new property-list path and return it.
225Its reference count is initially one.
226The path's length is initially zero.
227.Pp
228If there is not sufficient memory to complete the request, return
229.Dv NULL .
230.It Fn ppath_length "const ppath_t *p"
231Return the number of components in path
232.Fa p .
233.It Fn ppath_component_idx "const ppath_component_t *pc"
234Return the array index represented by the component
235.Fa pc ,
236or \-1 if
237.Fa pc
238does not represent an array index.
239.It Fn ppath_component_key "const ppath_component_t *pc"
240Return the dictionary key represented by the component
241.Fa pc ,
242or
243.Dv NULL
244if
245.Fa pc
246does not represent a dictionary key.
247.It Fn ppath_pop "ppath_t *p" "ppath_component_t **pcp"
248If
249.Fa p
250is the empty path or
251.Dv NULL ,
252return
253.Dv NULL .
254Otherwise, remove the last component from
255.Fa p
256and return
257.Fa p ,
258and if
259.Fa pcp
260is not
261.Dv NULL ,
262write the removed component to
263.Fa "*pcp" .
264.It Fn ppath_push "ppath_t *p" "ppath_component_t *pc"
265If
266either
267.Fa p
268is
269.Dv NULL
270or no more components can be added to
271.Fa p ,
272return
273.Dv NULL .
274Otherwise, append
275.Fa pc
276to the end of the component array
277.Fa p
278and return
279.Fa p .
280.It Fn ppath_component_at "const ppath_t *p" "unsigned int i"
281If
282either
283.Fa p
284is
285.Dv NULL
286or there is no
287.Fa ith
288component to
289.Fa p ,
290return
291.Dv NULL .
292Otherwise, return the
293.Fa ith
294component of
295.Fa p .
296Before returning a component,
297.Fn ppath_component_at
298increases its reference count.
299.Po
300The first component is 0.
301.Pc
302.It Fn ppath_subpath "const ppath_t *p" "unsigned int first" "unsigned int exclast"
303Create a new
304.Vt ppath_t
305and fill it with components
306.Fa first
307to
308.Fa exclast
309.Pq exclusive
310of
311.Fa p .
312If there are no such components as those in
313.Fa p ,
314.Fn ppath_subpath
315returns an empty
316.Vt ppath_t .
317If there is insufficient memory to create the new path, or if
318.Fa p
319is
320.Dv NULL ,
321return
322.Dv NULL .
323Otherwise, return the new path.
324.It Fn ppath_push_idx "ppath_t *p" "unsigned int idx"
325Append an array index,
326.Fa idx ,
327to the end of path
328.Fa p .
329If
330.Fa p
331is
332.Dv NULL ,
333or if there is insufficient memory to complete the operation,
334return
335.Dv NULL .
336Otherwise, return
337.Fa p .
338.It Fn ppath_push_key "ppath_t *" "const char *key"
339Append a dictionary key,
340.Fa key ,
341to the end of path
342.Fa p .
343If
344.Fa p
345is
346.Dv NULL ,
347or if there is insufficient memory to complete the operation,
348return
349.Dv NULL .
350Otherwise, return
351.Fa p .
352.It Fn ppath_replace_idx "ppath_t *p" "unsigned int idx"
353Replace the array index at the end of path
354.Fa p
355with the array index
356.Fa idx .
357If
358.Fa p
359is
360.Dv NULL ,
361if the last component of
362.Fa p
363is not an array index,
364or if there is insufficient memory to complete the operation,
365return
366.Dv NULL .
367Otherwise, return
368.Fa p .
369.It Fn ppath_replace_key "ppath_t *p" "const char *key"
370Replace the dictionary key at the end of path
371.Fa p
372with the dictionary key
373.Fa idx .
374If
375.Fa p
376is
377.Dv NULL ,
378if the last component of
379.Fa p
380is not a dictionary key,
381or if there is insufficient memory to complete the operation,
382return
383.Dv NULL .
384Otherwise, return
385.Fa p .
386.\"
387.It Fn ppath_copy "const ppath_t *p"
388Create a copy of path
389.Fa p .
390If
391.Fa p
392is
393.Dv NULL ,
394or if there is insufficient memory to complete the operation,
395return
396.Dv NULL .
397Otherwise, return the copy, whose reference count will be one.
398.It Fn ppath_retain "ppath_t *p"
399Increase the reference count on
400.Fa p
401and return
402.Fa p .
403.It Fn ppath_release "ppath_t *p"
404Decrease the reference count on
405.Fa p .
406Reclaim the storage for
407.Fa p
408if the reference count reaches zero.
409.\"
410.It Fn ppath_lookup "prop_object_t o" "const ppath_t *p"
411Return the
412.Vt prop_object_t
413under
414.Fa o
415named by
416.Fa p ,
417or return
418.Dv NULL
419if no such
420.Vt prop_object_t
421is under
422.Fa o .
423.El
424.Sh SEE ALSO
425.\" Cross-references should be ordered by section (low to high), then in
426.\"     alphabetical order.
427.Xr ppath_bool 3 ,
428.Xr ppath_data 3 ,
429.Xr ppath_number 3 ,
430.Xr ppath_object 3 ,
431.Xr ppath_string 3 ,
432.Xr proplib 3
433.Sh HISTORY
434The
435.Nm
436property container path library first appeared in
437.Nx 6.0 .
438.Sh AUTHORS
439.An David Young
440.Aq dyoung@pobox.com
441.\" .Sh CAVEATS
442.\" .Sh BUGS
443.\" .Sh SECURITY CONSIDERATIONS
444