xref: /freebsd/lib/libc/gen/getcap.3 (revision b92cc9b8783fe78fa7d6f4ad6b005d29e28cd99c)
158f0484fSRodney W. Grimes.\" Copyright (c) 1992, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
558f0484fSRodney W. Grimes.\" Casey Leedom of Lawrence Livermore National Laboratory.
658f0484fSRodney W. Grimes.\"
758f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
858f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
958f0484fSRodney W. Grimes.\" are met:
1058f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
1158f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
1258f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1358f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1458f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1558f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
1658f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1758f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1858f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1958f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
2058f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
2158f0484fSRodney W. Grimes.\"    without specific prior written permission.
2258f0484fSRodney W. Grimes.\"
2358f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2458f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2558f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2658f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2758f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2858f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2958f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3058f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3158f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3258f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3358f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3458f0484fSRodney W. Grimes.\"
350014b4c0SPeter Wemm.\"	@(#)getcap.3	8.4 (Berkeley) 5/13/94
367f3dea24SPeter Wemm.\" $FreeBSD$
3758f0484fSRodney W. Grimes.\"
38681e5e7aSSteve Price.Dd May 13, 1994
3958f0484fSRodney W. Grimes.Dt GETCAP 3
4058f0484fSRodney W. Grimes.Os
4158f0484fSRodney W. Grimes.Sh NAME
4258f0484fSRodney W. Grimes.Nm cgetent ,
4358f0484fSRodney W. Grimes.Nm cgetset ,
4458f0484fSRodney W. Grimes.Nm cgetmatch ,
4558f0484fSRodney W. Grimes.Nm cgetcap ,
4658f0484fSRodney W. Grimes.Nm cgetnum ,
4758f0484fSRodney W. Grimes.Nm cgetstr ,
4858f0484fSRodney W. Grimes.Nm cgetustr ,
4958f0484fSRodney W. Grimes.Nm cgetfirst ,
5058f0484fSRodney W. Grimes.Nm cgetnext ,
5158f0484fSRodney W. Grimes.Nm cgetclose
5258f0484fSRodney W. Grimes.Nd capability database access routines
5325bb73e0SAlexey Zelkin.Sh LIBRARY
5425bb73e0SAlexey Zelkin.Lb libc
5558f0484fSRodney W. Grimes.Sh SYNOPSIS
5632eef9aeSRuslan Ermilov.In stdlib.h
5758f0484fSRodney W. Grimes.Ft int
5858f0484fSRodney W. Grimes.Fn cgetent "char **buf" "char **db_array" "char *name"
5958f0484fSRodney W. Grimes.Ft int
6058f0484fSRodney W. Grimes.Fn cgetset "char *ent"
6158f0484fSRodney W. Grimes.Ft int
6258f0484fSRodney W. Grimes.Fn cgetmatch "char *buf" "char *name"
6358f0484fSRodney W. Grimes.Ft char *
6409589ca8SBruce Evans.Fn cgetcap "char *buf" "char *cap" "int type"
6558f0484fSRodney W. Grimes.Ft int
6658f0484fSRodney W. Grimes.Fn cgetnum "char *buf" "char *cap" "long *num"
6758f0484fSRodney W. Grimes.Ft int
6858f0484fSRodney W. Grimes.Fn cgetstr "char *buf" "char *cap" "char **str"
6958f0484fSRodney W. Grimes.Ft int
7058f0484fSRodney W. Grimes.Fn cgetustr "char *buf" "char *cap" "char **str"
7158f0484fSRodney W. Grimes.Ft int
7258f0484fSRodney W. Grimes.Fn cgetfirst "char **buf" "char **db_array"
7358f0484fSRodney W. Grimes.Ft int
7458f0484fSRodney W. Grimes.Fn cgetnext "char **buf" "char **db_array"
7558f0484fSRodney W. Grimes.Ft int
7658f0484fSRodney W. Grimes.Fn cgetclose "void"
7758f0484fSRodney W. Grimes.Sh DESCRIPTION
78beb64fb5SMike PritchardThe
79beb64fb5SMike Pritchard.Fn cgetent
80beb64fb5SMike Pritchardfunction extracts the capability
8158f0484fSRodney W. Grimes.Fa name
8258f0484fSRodney W. Grimesfrom the database specified by the
8358f0484fSRodney W. Grimes.Dv NULL
8458f0484fSRodney W. Grimesterminated file array
8558f0484fSRodney W. Grimes.Fa db_array
8658f0484fSRodney W. Grimesand returns a pointer to a
87d0353b83SRuslan Ermilov.Xr malloc 3 Ns \&'d
8858f0484fSRodney W. Grimescopy of it in
8958f0484fSRodney W. Grimes.Fa buf .
90bf5a138eSMike PritchardThe
91bf5a138eSMike Pritchard.Fn cgetent
92bf5a138eSMike Pritchardfunction will first look for files ending in
93d0353b83SRuslan Ermilov.Pa .db
9458f0484fSRodney W. Grimes(see
9558f0484fSRodney W. Grimes.Xr cap_mkdb 1 )
9658f0484fSRodney W. Grimesbefore accessing the ASCII file.
9758f0484fSRodney W. Grimes.Fa Buf
9858f0484fSRodney W. Grimesmust be retained through all subsequent calls to
9958f0484fSRodney W. Grimes.Fn cgetmatch ,
10058f0484fSRodney W. Grimes.Fn cgetcap ,
10158f0484fSRodney W. Grimes.Fn cgetnum ,
10258f0484fSRodney W. Grimes.Fn cgetstr ,
10358f0484fSRodney W. Grimesand
10458f0484fSRodney W. Grimes.Fn cgetustr ,
10558f0484fSRodney W. Grimesbut may then be
106374fc79dSWolfram Schneider.Xr free 3 Ns \&'d .
10758f0484fSRodney W. GrimesOn success 0 is returned, 1 if the returned
10858f0484fSRodney W. Grimesrecord contains an unresolved
109b92cc9b8SRuslan Ermilov.Ic tc
11058f0484fSRodney W. Grimesexpansion,
11158f0484fSRodney W. Grimes\-1 if the requested record couldn't be found,
11258f0484fSRodney W. Grimes\-2 if a system error was encountered (couldn't open/read a file, etc.) also
11358f0484fSRodney W. Grimessetting
11458f0484fSRodney W. Grimes.Va errno ,
11558f0484fSRodney W. Grimesand \-3 if a potential reference loop is detected (see
11658f0484fSRodney W. Grimes.Ic tc=
11758f0484fSRodney W. Grimescomments below).
11858f0484fSRodney W. Grimes.Pp
119bf5a138eSMike PritchardThe
120bf5a138eSMike Pritchard.Fn cgetset
121bf5a138eSMike Pritchardfunction enables the addition of a character buffer containing a single capability
12258f0484fSRodney W. Grimesrecord entry
12358f0484fSRodney W. Grimesto the capability database.
12458f0484fSRodney W. GrimesConceptually, the entry is added as the first ``file'' in the database, and
12558f0484fSRodney W. Grimesis therefore searched first on the call to
126bf5a138eSMike Pritchard.Fn cgetent .
12758f0484fSRodney W. GrimesThe entry is passed in
12858f0484fSRodney W. Grimes.Fa ent .
12958f0484fSRodney W. GrimesIf
13058f0484fSRodney W. Grimes.Fa ent
13158f0484fSRodney W. Grimesis
13258f0484fSRodney W. Grimes.Dv NULL ,
13358f0484fSRodney W. Grimesthe current entry is removed from the database.
134bf5a138eSMike PritchardA call to
135bf5a138eSMike Pritchard.Fn cgetset
13658f0484fSRodney W. Grimesmust precede the database traversal.  It must be called before the
137bf5a138eSMike Pritchard.Fn cgetent
13858f0484fSRodney W. Grimescall. If a sequential access is being performed (see below), it must be called
139f9eeb822SDima Dorfmanbefore the first sequential access call
140f9eeb822SDima Dorfman.Fn ( cgetfirst
14158f0484fSRodney W. Grimesor
142f9eeb822SDima Dorfman.Fn cgetnext ) ,
143f9eeb822SDima Dorfmanor be directly preceded by a
144bf5a138eSMike Pritchard.Fn cgetclose
14558f0484fSRodney W. Grimescall.
14658f0484fSRodney W. GrimesOn success 0 is returned and \-1 on failure.
14758f0484fSRodney W. Grimes.Pp
148bf5a138eSMike PritchardThe
149bf5a138eSMike Pritchard.Fn cgetmatch
150bf5a138eSMike Pritchardfunction will return 0 if
15158f0484fSRodney W. Grimes.Fa name
15258f0484fSRodney W. Grimesis one of the names of the capability record
15358f0484fSRodney W. Grimes.Fa buf ,
15458f0484fSRodney W. Grimes\-1 if
15558f0484fSRodney W. Grimesnot.
15658f0484fSRodney W. Grimes.Pp
157bf5a138eSMike PritchardThe
158bf5a138eSMike Pritchard.Fn cgetcap
159bf5a138eSMike Pritchardfunction searches the capability record
16058f0484fSRodney W. Grimes.Fa buf
16158f0484fSRodney W. Grimesfor the capability
16258f0484fSRodney W. Grimes.Fa cap
16358f0484fSRodney W. Grimeswith type
16458f0484fSRodney W. Grimes.Fa type .
16558f0484fSRodney W. GrimesA
16658f0484fSRodney W. Grimes.Fa type
16758f0484fSRodney W. Grimesis specified using any single character.  If a colon (`:') is used, an
16858f0484fSRodney W. Grimesuntyped capability will be searched for (see below for explanation of
16958f0484fSRodney W. Grimestypes).  A pointer to the value of
17058f0484fSRodney W. Grimes.Fa cap
17158f0484fSRodney W. Grimesin
17258f0484fSRodney W. Grimes.Fa buf
17358f0484fSRodney W. Grimesis returned on success,
17458f0484fSRodney W. Grimes.Dv NULL
17558f0484fSRodney W. Grimesif the requested capability couldn't be
17658f0484fSRodney W. Grimesfound.  The end of the capability value is signaled by a `:' or
17758f0484fSRodney W. Grimes.Tn ASCII
17858f0484fSRodney W. Grimes.Dv NUL
17958f0484fSRodney W. Grimes(see below for capability database syntax).
18058f0484fSRodney W. Grimes.Pp
181bf5a138eSMike PritchardThe
182bf5a138eSMike Pritchard.Fn cgetnum
183bf5a138eSMike Pritchardfunction retrieves the value of the numeric capability
18458f0484fSRodney W. Grimes.Fa cap
18558f0484fSRodney W. Grimesfrom the capability record pointed to by
18658f0484fSRodney W. Grimes.Fa buf .
18758f0484fSRodney W. GrimesThe numeric value is returned in the
18858f0484fSRodney W. Grimes.Ft long
18958f0484fSRodney W. Grimespointed to by
19058f0484fSRodney W. Grimes.Fa num .
19158f0484fSRodney W. Grimes0 is returned on success, \-1 if the requested numeric capability couldn't
19258f0484fSRodney W. Grimesbe found.
19358f0484fSRodney W. Grimes.Pp
194bf5a138eSMike PritchardThe
195bf5a138eSMike Pritchard.Fn cgetstr
196bf5a138eSMike Pritchardfunction retrieves the value of the string capability
19758f0484fSRodney W. Grimes.Fa cap
19858f0484fSRodney W. Grimesfrom the capability record pointed to by
19958f0484fSRodney W. Grimes.Fa buf .
20058f0484fSRodney W. GrimesA pointer to a decoded,
20158f0484fSRodney W. Grimes.Dv NUL
20258f0484fSRodney W. Grimesterminated,
203d0353b83SRuslan Ermilov.Xr malloc 3 Ns \&'d
20458f0484fSRodney W. Grimescopy of the string is returned in the
20558f0484fSRodney W. Grimes.Ft char *
20658f0484fSRodney W. Grimespointed to by
20758f0484fSRodney W. Grimes.Fa str .
20858f0484fSRodney W. GrimesThe number of characters in the decoded string not including the trailing
20958f0484fSRodney W. Grimes.Dv NUL
21058f0484fSRodney W. Grimesis returned on success, \-1 if the requested string capability couldn't
21158f0484fSRodney W. Grimesbe found, \-2 if a system error was encountered (storage allocation
21258f0484fSRodney W. Grimesfailure).
21358f0484fSRodney W. Grimes.Pp
214bf5a138eSMike PritchardThe
215bf5a138eSMike Pritchard.Fn cgetustr
216bf5a138eSMike Pritchardfunction is identical to
217bf5a138eSMike Pritchard.Fn cgetstr
21858f0484fSRodney W. Grimesexcept that it does not expand special characters, but rather returns each
21958f0484fSRodney W. Grimescharacter of the capability string literally.
22058f0484fSRodney W. Grimes.Pp
221bf5a138eSMike PritchardThe
222bf5a138eSMike Pritchard.Fn cgetfirst
223bf5a138eSMike Pritchardand
224bf5a138eSMike Pritchard.Fn cgetnext
225bf5a138eSMike Pritchardfunctions comprise a function group that provides for sequential
22658f0484fSRodney W. Grimesaccess of the
22758f0484fSRodney W. Grimes.Dv NULL
22858f0484fSRodney W. Grimespointer terminated array of file names,
22958f0484fSRodney W. Grimes.Fa db_array .
230bf5a138eSMike PritchardThe
231bf5a138eSMike Pritchard.Fn cgetfirst
232bf5a138eSMike Pritchardfunction returns the first record in the database and resets the access
23358f0484fSRodney W. Grimesto the first record.
234bf5a138eSMike PritchardThe
235bf5a138eSMike Pritchard.Fn cgetnext
236bf5a138eSMike Pritchardfunction returns the next record in the database with respect to the
23758f0484fSRodney W. Grimesrecord returned by the previous
238bf5a138eSMike Pritchard.Fn cgetfirst
23958f0484fSRodney W. Grimesor
240bf5a138eSMike Pritchard.Fn cgetnext
24158f0484fSRodney W. Grimescall.  If there is no such previous call, the first record in the database is
24258f0484fSRodney W. Grimesreturned.
24358f0484fSRodney W. GrimesEach record is returned in a
244d0353b83SRuslan Ermilov.Xr malloc 3 Ns \&'d
24558f0484fSRodney W. Grimescopy pointed to by
24658f0484fSRodney W. Grimes.Fa buf .
24758f0484fSRodney W. Grimes.Ic Tc
24858f0484fSRodney W. Grimesexpansion is done (see
24958f0484fSRodney W. Grimes.Ic tc=
25058f0484fSRodney W. Grimescomments below).
25158f0484fSRodney W. GrimesUpon completion of the database 0 is returned,  1 is returned upon successful
25258f0484fSRodney W. Grimesreturn of record with possibly more remaining (we haven't reached the end of
25358f0484fSRodney W. Grimesthe database yet), 2 is returned if the record contains an unresolved
254b92cc9b8SRuslan Ermilov.Ic tc
25558f0484fSRodney W. Grimesexpansion, \-1 is returned if an system error occurred, and \-2
25658f0484fSRodney W. Grimesis returned if a potential reference loop is detected (see
25758f0484fSRodney W. Grimes.Ic tc=
25858f0484fSRodney W. Grimescomments below).
25958f0484fSRodney W. GrimesUpon completion of database (0 return) the database is closed.
26058f0484fSRodney W. Grimes.Pp
261bf5a138eSMike PritchardThe
262bf5a138eSMike Pritchard.Fn cgetclose
263bf5a138eSMike Pritchardfunction closes the sequential access and frees any memory and file descriptors
26458f0484fSRodney W. Grimesbeing used.  Note that it does not erase the buffer pushed by a call to
265bf5a138eSMike Pritchard.Fn cgetset .
26658f0484fSRodney W. Grimes.Sh CAPABILITY DATABASE SYNTAX
26758f0484fSRodney W. GrimesCapability databases are normally
26858f0484fSRodney W. Grimes.Tn ASCII
26958f0484fSRodney W. Grimesand may be edited with standard
27058f0484fSRodney W. Grimestext editors.  Blank lines and lines beginning with a `#' are comments
27158f0484fSRodney W. Grimesand are ignored.  Lines ending with a `\|\e' indicate that the next line
27258f0484fSRodney W. Grimesis a continuation of the current line; the `\|\e' and following newline
27358f0484fSRodney W. Grimesare ignored.  Long lines are usually continued onto several physical
27458f0484fSRodney W. Grimeslines by ending each line except the last with a `\|\e'.
27558f0484fSRodney W. Grimes.Pp
27658f0484fSRodney W. GrimesCapability databases consist of a series of records, one per logical
27758f0484fSRodney W. Grimesline.  Each record contains a variable number of `:'-separated fields
27858f0484fSRodney W. Grimes(capabilities).  Empty fields consisting entirely of white space
27958f0484fSRodney W. Grimescharacters (spaces and tabs) are ignored.
28058f0484fSRodney W. Grimes.Pp
28158f0484fSRodney W. GrimesThe first capability of each record specifies its names, separated by `|'
28258f0484fSRodney W. Grimescharacters.  These names are used to reference records in the database.
28358f0484fSRodney W. GrimesBy convention, the last name is usually a comment and is not intended as
28458f0484fSRodney W. Grimesa lookup tag.  For example, the
28558f0484fSRodney W. Grimes.Em vt100
28658f0484fSRodney W. Grimesrecord from the
287b92cc9b8SRuslan Ermilov.Xr termcap 5
28858f0484fSRodney W. Grimesdatabase begins:
28958f0484fSRodney W. Grimes.Pp
29058f0484fSRodney W. Grimes.Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:"
29158f0484fSRodney W. Grimes.Pp
29258f0484fSRodney W. Grimesgiving four names that can be used to access the record.
29358f0484fSRodney W. Grimes.Pp
29458f0484fSRodney W. GrimesThe remaining non-empty capabilities describe a set of (name, value)
29512985df3SDima Dorfmanbindings, consisting of a names optionally followed by a typed value:
29658f0484fSRodney W. Grimes.Bl -column "nameTvalue"
29758f0484fSRodney W. Grimes.It name Ta "typeless [boolean] capability"
29858f0484fSRodney W. Grimes.Em name No "is present [true]"
29958f0484fSRodney W. Grimes.It name Ns Em \&T Ns value Ta capability
30058f0484fSRodney W. Grimes.Pq Em name , \&T
30158f0484fSRodney W. Grimeshas value
30258f0484fSRodney W. Grimes.Em value
30358f0484fSRodney W. Grimes.It name@ Ta "no capability" Em name No exists
30458f0484fSRodney W. Grimes.It name Ns Em T Ns \&@ Ta capability
30558f0484fSRodney W. Grimes.Pq Em name , T
30658f0484fSRodney W. Grimesdoes not exist
30758f0484fSRodney W. Grimes.El
30858f0484fSRodney W. Grimes.Pp
30958f0484fSRodney W. GrimesNames consist of one or more characters.  Names may contain any character
31058f0484fSRodney W. Grimesexcept `:', but it's usually best to restrict them to the printable
31158f0484fSRodney W. Grimescharacters and avoid use of graphics like `#', `=', `%', `@', etc.  Types
31258f0484fSRodney W. Grimesare single characters used to separate capability names from their
31358f0484fSRodney W. Grimesassociated typed values.  Types may be any character except a `:'.
31458f0484fSRodney W. GrimesTypically, graphics like `#', `=', `%', etc. are used.  Values may be any
31558f0484fSRodney W. Grimesnumber of characters and may contain any character except `:'.
31658f0484fSRodney W. Grimes.Sh CAPABILITY DATABASE SEMANTICS
31758f0484fSRodney W. GrimesCapability records describe a set of (name, value) bindings.  Names may
31858f0484fSRodney W. Grimeshave multiple values bound to them.  Different values for a name are
31958f0484fSRodney W. Grimesdistinguished by their
32058f0484fSRodney W. Grimes.Fa types .
321bf5a138eSMike PritchardThe
322bf5a138eSMike Pritchard.Fn cgetcap
323bf5a138eSMike Pritchardfunction will return a pointer to a value of a name given the capability
324bf5a138eSMike Pritchardname and the type of the value.
32558f0484fSRodney W. Grimes.Pp
32658f0484fSRodney W. GrimesThe types `#' and `=' are conventionally used to denote numeric and
32758f0484fSRodney W. Grimesstring typed values, but no restriction on those types is enforced.  The
32858f0484fSRodney W. Grimesfunctions
329bf5a138eSMike Pritchard.Fn cgetnum
33058f0484fSRodney W. Grimesand
331bf5a138eSMike Pritchard.Fn cgetstr
33258f0484fSRodney W. Grimescan be used to implement the traditional syntax and semantics of `#'
33358f0484fSRodney W. Grimesand `='.
33458f0484fSRodney W. GrimesTypeless capabilities are typically used to denote boolean objects with
33558f0484fSRodney W. Grimespresence or absence indicating truth and false values respectively.
33658f0484fSRodney W. GrimesThis interpretation is conveniently represented by:
33758f0484fSRodney W. Grimes.Pp
33858f0484fSRodney W. Grimes.Dl "(getcap(buf, name, ':') != NULL)"
33958f0484fSRodney W. Grimes.Pp
34058f0484fSRodney W. GrimesA special capability,
34158f0484fSRodney W. Grimes.Ic tc= name ,
34258f0484fSRodney W. Grimesis used to indicate that the record specified by
34358f0484fSRodney W. Grimes.Fa name
34458f0484fSRodney W. Grimesshould be substituted for the
34558f0484fSRodney W. Grimes.Ic tc
34658f0484fSRodney W. Grimescapability.
34758f0484fSRodney W. Grimes.Ic Tc
34858f0484fSRodney W. Grimescapabilities may interpolate records which also contain
34958f0484fSRodney W. Grimes.Ic tc
35058f0484fSRodney W. Grimescapabilities and more than one
35158f0484fSRodney W. Grimes.Ic tc
35258f0484fSRodney W. Grimescapability may be used in a record.  A
35358f0484fSRodney W. Grimes.Ic tc
35458f0484fSRodney W. Grimesexpansion scope (i.e., where the argument is searched for) contains the
35558f0484fSRodney W. Grimesfile in which the
35658f0484fSRodney W. Grimes.Ic tc
35758f0484fSRodney W. Grimesis declared and all subsequent files in the file array.
35858f0484fSRodney W. Grimes.Pp
35958f0484fSRodney W. GrimesWhen a database is searched for a capability record, the first matching
36058f0484fSRodney W. Grimesrecord in the search is returned.  When a record is scanned for a
36158f0484fSRodney W. Grimescapability, the first matching capability is returned; the capability
36258f0484fSRodney W. Grimes.Ic :nameT@:
36358f0484fSRodney W. Grimeswill hide any following definition of a value of type
36458f0484fSRodney W. Grimes.Em T
36558f0484fSRodney W. Grimesfor
36658f0484fSRodney W. Grimes.Fa name ;
36758f0484fSRodney W. Grimesand the capability
36858f0484fSRodney W. Grimes.Ic :name@:
36958f0484fSRodney W. Grimeswill prevent any following values of
37058f0484fSRodney W. Grimes.Fa name
37158f0484fSRodney W. Grimesfrom being seen.
37258f0484fSRodney W. Grimes.Pp
37358f0484fSRodney W. GrimesThese features combined with
37458f0484fSRodney W. Grimes.Ic tc
37558f0484fSRodney W. Grimescapabilities can be used to generate variations of other databases and
37658f0484fSRodney W. Grimesrecords by either adding new capabilities, overriding definitions with new
37758f0484fSRodney W. Grimesdefinitions, or hiding following definitions via `@' capabilities.
37858f0484fSRodney W. Grimes.Sh EXAMPLES
37958f0484fSRodney W. Grimes.Bd -unfilled -offset indent
38058f0484fSRodney W. Grimesexample\||\|an example of binding multiple values to names:\e
38158f0484fSRodney W. Grimes	:foo%bar:foo^blah:foo@:\e
38258f0484fSRodney W. Grimes	:abc%xyz:abc^frap:abc$@:\e
38358f0484fSRodney W. Grimes	:tc=more:
38458f0484fSRodney W. Grimes.Ed
38558f0484fSRodney W. Grimes.Pp
38658f0484fSRodney W. GrimesThe capability foo has two values bound to it (bar of type `%' and blah of
38758f0484fSRodney W. Grimestype `^') and any other value bindings are hidden.  The capability abc
38858f0484fSRodney W. Grimesalso has two values bound but only a value of type `$' is prevented from
38958f0484fSRodney W. Grimesbeing defined in the capability record more.
39058f0484fSRodney W. Grimes.Pp
39158f0484fSRodney W. Grimes.Bd -unfilled -offset indent
39258f0484fSRodney W. Grimesfile1:
39358f0484fSRodney W. Grimes 	new\||\|new_record\||\|a modification of "old":\e
39458f0484fSRodney W. Grimes		:fript=bar:who-cares@:tc=old:blah:tc=extensions:
39558f0484fSRodney W. Grimesfile2:
39658f0484fSRodney W. Grimes	old\||\|old_record\||\|an old database record:\e
39758f0484fSRodney W. Grimes		:fript=foo:who-cares:glork#200:
39858f0484fSRodney W. Grimes.Ed
39958f0484fSRodney W. Grimes.Pp
40058f0484fSRodney W. GrimesThe records are extracted by calling
401bf5a138eSMike Pritchard.Fn cgetent
40258f0484fSRodney W. Grimeswith file1 preceding file2.
40358f0484fSRodney W. GrimesIn the capability record new in file1, fript=bar overrides the definition
40458f0484fSRodney W. Grimesof fript=foo interpolated from the capability record old in file2,
40558f0484fSRodney W. Grimeswho-cares@ prevents the definition of any who-cares definitions in old
40658f0484fSRodney W. Grimesfrom being seen, glork#200 is inherited from old, and blah and anything
40758f0484fSRodney W. Grimesdefined by the record extensions is added to those definitions in old.
40858f0484fSRodney W. GrimesNote that the position of the fript=bar and who-cares@ definitions before
40958f0484fSRodney W. Grimestc=old is important here.  If they were after, the definitions in old
41058f0484fSRodney W. Grimeswould take precedence.
41158f0484fSRodney W. Grimes.Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
41258f0484fSRodney W. GrimesTwo types are predefined by
413bf5a138eSMike Pritchard.Fn cgetnum
41458f0484fSRodney W. Grimesand
415bf5a138eSMike Pritchard.Fn cgetstr :
41658f0484fSRodney W. Grimes.Bl -column "nameXnumber"
41758f0484fSRodney W. Grimes.Sm off
41858f0484fSRodney W. Grimes.It Em name No \&# Em number Ta numeric
419d0353b83SRuslan Ermilov.Sm on
42058f0484fSRodney W. Grimescapability
42158f0484fSRodney W. Grimes.Em name
42258f0484fSRodney W. Grimeshas value
42358f0484fSRodney W. Grimes.Em number
424d0353b83SRuslan Ermilov.Sm off
42558f0484fSRodney W. Grimes.It Em name No = Em string Ta "string capability"
426d0353b83SRuslan Ermilov.Sm on
42758f0484fSRodney W. Grimes.Em name
42858f0484fSRodney W. Grimeshas value
42958f0484fSRodney W. Grimes.Em string
430d0353b83SRuslan Ermilov.Sm off
43158f0484fSRodney W. Grimes.It Em name No \&#@ Ta "the numeric capability"
43242635956SRuslan Ermilov.Sm on
433d0353b83SRuslan Ermilov.Em name
434d0353b83SRuslan Ermilovdoes not exist
435d0353b83SRuslan Ermilov.Sm off
436d0353b83SRuslan Ermilov.It Em name No \&=@ Ta "the string capability"
437d0353b83SRuslan Ermilov.Sm on
438d0353b83SRuslan Ermilov.Em name
439d0353b83SRuslan Ermilovdoes not exist
44058f0484fSRodney W. Grimes.El
44158f0484fSRodney W. Grimes.Pp
44258f0484fSRodney W. GrimesNumeric capability values may be given in one of three numeric bases.
44358f0484fSRodney W. GrimesIf the number starts with either
44458f0484fSRodney W. Grimes.Ql 0x
44558f0484fSRodney W. Grimesor
44658f0484fSRodney W. Grimes.Ql 0X
44758f0484fSRodney W. Grimesit is interpreted as a hexadecimal number (both upper and lower case a-f
44858f0484fSRodney W. Grimesmay be used to denote the extended hexadecimal digits).
44958f0484fSRodney W. GrimesOtherwise, if the number starts with a
45058f0484fSRodney W. Grimes.Ql 0
45158f0484fSRodney W. Grimesit is interpreted as an octal number.
45258f0484fSRodney W. GrimesOtherwise the number is interpreted as a decimal number.
45358f0484fSRodney W. Grimes.Pp
45458f0484fSRodney W. GrimesString capability values may contain any character.  Non-printable
45558f0484fSRodney W. Grimes.Dv ASCII
45658f0484fSRodney W. Grimescodes, new lines, and colons may be conveniently represented by the use
45758f0484fSRodney W. Grimesof escape sequences:
45858f0484fSRodney W. Grimes.Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"
45921ac7f5fSMike Pritchard^X	('X' & 037)	control-X
46058f0484fSRodney W. Grimes\e\|b, \e\|B	(ASCII 010)	backspace
46158f0484fSRodney W. Grimes\e\|t, \e\|T	(ASCII 011)	tab
46258f0484fSRodney W. Grimes\e\|n, \e\|N	(ASCII 012)	line feed (newline)
46358f0484fSRodney W. Grimes\e\|f, \e\|F	(ASCII 014)	form feed
46458f0484fSRodney W. Grimes\e\|r, \e\|R	(ASCII 015)	carriage return
46558f0484fSRodney W. Grimes\e\|e, \e\|E	(ASCII 027)	escape
46658f0484fSRodney W. Grimes\e\|c, \e\|C	(:)	colon
46758f0484fSRodney W. Grimes\e\|\e	(\e\|)	back slash
46858f0484fSRodney W. Grimes\e\|^	(^)	caret
46921ac7f5fSMike Pritchard\e\|nnn	(ASCII octal nnn)
47058f0484fSRodney W. Grimes.El
47158f0484fSRodney W. Grimes.Pp
47258f0484fSRodney W. GrimesA `\|\e' may be followed by up to three octal digits directly specifies
47358f0484fSRodney W. Grimesthe numeric code for a character.  The use of
47458f0484fSRodney W. Grimes.Tn ASCII
47558f0484fSRodney W. Grimes.Dv NUL Ns s ,
47658f0484fSRodney W. Grimeswhile easily
47758f0484fSRodney W. Grimesencoded, causes all sorts of problems and must be used with care since
47858f0484fSRodney W. Grimes.Dv NUL Ns s
47958f0484fSRodney W. Grimesare typically used to denote the end of strings; many applications
48058f0484fSRodney W. Grimesuse `\e\|200' to represent a
48158f0484fSRodney W. Grimes.Dv NUL .
48258f0484fSRodney W. Grimes.Sh DIAGNOSTICS
483beb64fb5SMike PritchardThe
484beb64fb5SMike Pritchard.Fn cgetent ,
485bf5a138eSMike Pritchard.Fn cgetset ,
486bf5a138eSMike Pritchard.Fn cgetmatch ,
487bf5a138eSMike Pritchard.Fn cgetnum ,
488bf5a138eSMike Pritchard.Fn cgetstr ,
489bf5a138eSMike Pritchard.Fn cgetustr ,
490bf5a138eSMike Pritchard.Fn cgetfirst ,
49158f0484fSRodney W. Grimesand
492bf5a138eSMike Pritchard.Fn cgetnext
493beb64fb5SMike Pritchardfunctions
49458f0484fSRodney W. Grimesreturn a value greater than or equal to 0 on success and a value less
49558f0484fSRodney W. Grimesthan 0 on failure.
496bf5a138eSMike PritchardThe
497bf5a138eSMike Pritchard.Fn cgetcap
498bf5a138eSMike Pritchardfunction returns a character pointer on success and a
49958f0484fSRodney W. Grimes.Dv NULL
50058f0484fSRodney W. Grimeson failure.
50158f0484fSRodney W. Grimes.Pp
502bf5a138eSMike PritchardThe
503bf5a138eSMike Pritchard.Fn cgetent ,
50458f0484fSRodney W. Grimesand
505bf5a138eSMike Pritchard.Fn cgetseq
506bf5a138eSMike Pritchardfunctions may fail and set
50758f0484fSRodney W. Grimes.Va errno
50858f0484fSRodney W. Grimesfor any of the errors specified for the library functions:
509b07158f7SChris Costello.Xr fopen 3 ,
510b07158f7SChris Costello.Xr fclose 3 ,
51158f0484fSRodney W. Grimes.Xr open 2 ,
51258f0484fSRodney W. Grimesand
51358f0484fSRodney W. Grimes.Xr close 2 .
51458f0484fSRodney W. Grimes.Pp
515bf5a138eSMike PritchardThe
516bf5a138eSMike Pritchard.Fn cgetent ,
517bf5a138eSMike Pritchard.Fn cgetset ,
518bf5a138eSMike Pritchard.Fn cgetstr ,
51958f0484fSRodney W. Grimesand
520bf5a138eSMike Pritchard.Fn cgetustr
521beb64fb5SMike Pritchardfunctions
52258f0484fSRodney W. Grimesmay fail and set
52358f0484fSRodney W. Grimes.Va errno
52458f0484fSRodney W. Grimesas follows:
52558f0484fSRodney W. Grimes.Bl -tag -width Er
52658f0484fSRodney W. Grimes.It Bq Er ENOMEM
52758f0484fSRodney W. GrimesNo memory to allocate.
52858f0484fSRodney W. Grimes.El
52958f0484fSRodney W. Grimes.Sh SEE ALSO
53058f0484fSRodney W. Grimes.Xr cap_mkdb 1 ,
53158f0484fSRodney W. Grimes.Xr malloc 3
53258f0484fSRodney W. Grimes.Sh BUGS
53358f0484fSRodney W. GrimesColons (`:') can't be used in names, types, or values.
53458f0484fSRodney W. Grimes.Pp
53558f0484fSRodney W. GrimesThere are no checks for
53642635956SRuslan Ermilov.Ic tc Ns = Ns Ic name
53758f0484fSRodney W. Grimesloops in
538bf5a138eSMike Pritchard.Fn cgetent .
53958f0484fSRodney W. Grimes.Pp
54058f0484fSRodney W. GrimesThe buffer added to the database by a call to
541bf5a138eSMike Pritchard.Fn cgetset
54258f0484fSRodney W. Grimesis not unique to the database but is rather prepended to any database used.
543