xref: /freebsd/lib/libc/gen/getcap.3 (revision af48594d13b31b2060e2ea8a0b73f4dd0909daac)
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.\" 4. Neither the name of the University nor the names of its contributors
1658f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1758f0484fSRodney W. Grimes.\"    without specific prior written permission.
1858f0484fSRodney W. Grimes.\"
1958f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2058f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2158f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2258f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2358f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2458f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2558f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2658f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2758f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2858f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2958f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3058f0484fSRodney W. Grimes.\"
310014b4c0SPeter Wemm.\"	@(#)getcap.3	8.4 (Berkeley) 5/13/94
327f3dea24SPeter Wemm.\" $FreeBSD$
3358f0484fSRodney W. Grimes.\"
34b0faeb2dSRuslan Ermilov.Dd March 22, 2002
3558f0484fSRodney W. Grimes.Dt GETCAP 3
3658f0484fSRodney W. Grimes.Os
3758f0484fSRodney W. Grimes.Sh NAME
3858f0484fSRodney W. Grimes.Nm cgetent ,
3958f0484fSRodney W. Grimes.Nm cgetset ,
4058f0484fSRodney W. Grimes.Nm cgetmatch ,
4158f0484fSRodney W. Grimes.Nm cgetcap ,
4258f0484fSRodney W. Grimes.Nm cgetnum ,
4358f0484fSRodney W. Grimes.Nm cgetstr ,
4458f0484fSRodney W. Grimes.Nm cgetustr ,
4558f0484fSRodney W. Grimes.Nm cgetfirst ,
4658f0484fSRodney W. Grimes.Nm cgetnext ,
4758f0484fSRodney W. Grimes.Nm cgetclose
4858f0484fSRodney W. Grimes.Nd capability database access routines
4925bb73e0SAlexey Zelkin.Sh LIBRARY
5025bb73e0SAlexey Zelkin.Lb libc
5158f0484fSRodney W. Grimes.Sh SYNOPSIS
5232eef9aeSRuslan Ermilov.In stdlib.h
5358f0484fSRodney W. Grimes.Ft int
54b0faeb2dSRuslan Ermilov.Fn cgetent "char **buf" "char **db_array" "const char *name"
5558f0484fSRodney W. Grimes.Ft int
56b0faeb2dSRuslan Ermilov.Fn cgetset "const char *ent"
5758f0484fSRodney W. Grimes.Ft int
58b0faeb2dSRuslan Ermilov.Fn cgetmatch "const char *buf" "const char *name"
5958f0484fSRodney W. Grimes.Ft char *
60b0faeb2dSRuslan Ermilov.Fn cgetcap "char *buf" "const char *cap" "int type"
6158f0484fSRodney W. Grimes.Ft int
62b0faeb2dSRuslan Ermilov.Fn cgetnum "char *buf" "const char *cap" "long *num"
6358f0484fSRodney W. Grimes.Ft int
64b0faeb2dSRuslan Ermilov.Fn cgetstr "char *buf" "const char *cap" "char **str"
6558f0484fSRodney W. Grimes.Ft int
66b0faeb2dSRuslan Ermilov.Fn cgetustr "char *buf" "const char *cap" "char **str"
6758f0484fSRodney W. Grimes.Ft int
6858f0484fSRodney W. Grimes.Fn cgetfirst "char **buf" "char **db_array"
6958f0484fSRodney W. Grimes.Ft int
7058f0484fSRodney W. Grimes.Fn cgetnext "char **buf" "char **db_array"
7158f0484fSRodney W. Grimes.Ft int
7258f0484fSRodney W. Grimes.Fn cgetclose "void"
7358f0484fSRodney W. Grimes.Sh DESCRIPTION
74beb64fb5SMike PritchardThe
75beb64fb5SMike Pritchard.Fn cgetent
76beb64fb5SMike Pritchardfunction extracts the capability
7758f0484fSRodney W. Grimes.Fa name
7858f0484fSRodney W. Grimesfrom the database specified by the
7958f0484fSRodney W. Grimes.Dv NULL
8058f0484fSRodney W. Grimesterminated file array
8158f0484fSRodney W. Grimes.Fa db_array
8258f0484fSRodney W. Grimesand returns a pointer to a
83d0353b83SRuslan Ermilov.Xr malloc 3 Ns \&'d
8458f0484fSRodney W. Grimescopy of it in
8558f0484fSRodney W. Grimes.Fa buf .
86bf5a138eSMike PritchardThe
87bf5a138eSMike Pritchard.Fn cgetent
88bf5a138eSMike Pritchardfunction will first look for files ending in
89d0353b83SRuslan Ermilov.Pa .db
9058f0484fSRodney W. Grimes(see
9158f0484fSRodney W. Grimes.Xr cap_mkdb 1 )
9258f0484fSRodney W. Grimesbefore accessing the ASCII file.
932efeeba5SRuslan ErmilovThe
942efeeba5SRuslan Ermilov.Fa buf
952efeeba5SRuslan Ermilovargument
9658f0484fSRodney W. Grimesmust be retained through all subsequent calls to
9758f0484fSRodney W. Grimes.Fn cgetmatch ,
9858f0484fSRodney W. Grimes.Fn cgetcap ,
9958f0484fSRodney W. Grimes.Fn cgetnum ,
10058f0484fSRodney W. Grimes.Fn cgetstr ,
10158f0484fSRodney W. Grimesand
10258f0484fSRodney W. Grimes.Fn cgetustr ,
10358f0484fSRodney W. Grimesbut may then be
104374fc79dSWolfram Schneider.Xr free 3 Ns \&'d .
10558f0484fSRodney W. GrimesOn success 0 is returned, 1 if the returned
10658f0484fSRodney W. Grimesrecord contains an unresolved
107b92cc9b8SRuslan Ermilov.Ic tc
10858f0484fSRodney W. Grimesexpansion,
1090227791bSRuslan Ermilov\-1 if the requested record could not be found,
1100227791bSRuslan Ermilov\-2 if a system error was encountered (could not open/read a file, etc.) also
11158f0484fSRodney W. Grimessetting
11258f0484fSRodney W. Grimes.Va errno ,
11358f0484fSRodney W. Grimesand \-3 if a potential reference loop is detected (see
11458f0484fSRodney W. Grimes.Ic tc=
11558f0484fSRodney W. Grimescomments below).
11658f0484fSRodney W. Grimes.Pp
117bf5a138eSMike PritchardThe
118bf5a138eSMike Pritchard.Fn cgetset
119bf5a138eSMike Pritchardfunction enables the addition of a character buffer containing a single capability
12058f0484fSRodney W. Grimesrecord entry
12158f0484fSRodney W. Grimesto the capability database.
12258f0484fSRodney W. GrimesConceptually, the entry is added as the first ``file'' in the database, and
12358f0484fSRodney W. Grimesis therefore searched first on the call to
124bf5a138eSMike Pritchard.Fn cgetent .
12558f0484fSRodney W. GrimesThe entry is passed in
12658f0484fSRodney W. Grimes.Fa ent .
12758f0484fSRodney W. GrimesIf
12858f0484fSRodney W. Grimes.Fa ent
12958f0484fSRodney W. Grimesis
13058f0484fSRodney W. Grimes.Dv NULL ,
13158f0484fSRodney W. Grimesthe current entry is removed from the database.
132bf5a138eSMike PritchardA call to
133bf5a138eSMike Pritchard.Fn cgetset
1341a0a9345SRuslan Ermilovmust precede the database traversal.
1351a0a9345SRuslan ErmilovIt must be called before the
136bf5a138eSMike Pritchard.Fn cgetent
1371a0a9345SRuslan Ermilovcall.
1381a0a9345SRuslan ErmilovIf 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
1671a0a9345SRuslan Ermilovis specified using any single character.
1681a0a9345SRuslan ErmilovIf a colon (`:') is used, an
16958f0484fSRodney W. Grimesuntyped capability will be searched for (see below for explanation of
1701a0a9345SRuslan Ermilovtypes).
1711a0a9345SRuslan ErmilovA pointer to the value of
17258f0484fSRodney W. Grimes.Fa cap
17358f0484fSRodney W. Grimesin
17458f0484fSRodney W. Grimes.Fa buf
17558f0484fSRodney W. Grimesis returned on success,
17658f0484fSRodney W. Grimes.Dv NULL
1770227791bSRuslan Ermilovif the requested capability could not be
1781a0a9345SRuslan Ermilovfound.
1791a0a9345SRuslan ErmilovThe end of the capability value is signaled by a `:' or
18058f0484fSRodney W. Grimes.Tn ASCII
18158f0484fSRodney W. Grimes.Dv NUL
18258f0484fSRodney W. Grimes(see below for capability database syntax).
18358f0484fSRodney W. Grimes.Pp
184bf5a138eSMike PritchardThe
185bf5a138eSMike Pritchard.Fn cgetnum
186bf5a138eSMike Pritchardfunction retrieves the value of the numeric capability
18758f0484fSRodney W. Grimes.Fa cap
18858f0484fSRodney W. Grimesfrom the capability record pointed to by
18958f0484fSRodney W. Grimes.Fa buf .
19058f0484fSRodney W. GrimesThe numeric value is returned in the
19158f0484fSRodney W. Grimes.Ft long
19258f0484fSRodney W. Grimespointed to by
19358f0484fSRodney W. Grimes.Fa num .
1940227791bSRuslan Ermilov0 is returned on success, \-1 if the requested numeric capability could not
19558f0484fSRodney W. Grimesbe found.
19658f0484fSRodney W. Grimes.Pp
197bf5a138eSMike PritchardThe
198bf5a138eSMike Pritchard.Fn cgetstr
199bf5a138eSMike Pritchardfunction retrieves the value of the string capability
20058f0484fSRodney W. Grimes.Fa cap
20158f0484fSRodney W. Grimesfrom the capability record pointed to by
20258f0484fSRodney W. Grimes.Fa buf .
20358f0484fSRodney W. GrimesA pointer to a decoded,
20458f0484fSRodney W. Grimes.Dv NUL
20558f0484fSRodney W. Grimesterminated,
206d0353b83SRuslan Ermilov.Xr malloc 3 Ns \&'d
20758f0484fSRodney W. Grimescopy of the string is returned in the
20858f0484fSRodney W. Grimes.Ft char *
20958f0484fSRodney W. Grimespointed to by
21058f0484fSRodney W. Grimes.Fa str .
21158f0484fSRodney W. GrimesThe number of characters in the decoded string not including the trailing
21258f0484fSRodney W. Grimes.Dv NUL
2130227791bSRuslan Ermilovis returned on success, \-1 if the requested string capability could not
21458f0484fSRodney W. Grimesbe found, \-2 if a system error was encountered (storage allocation
21558f0484fSRodney W. Grimesfailure).
21658f0484fSRodney W. Grimes.Pp
217bf5a138eSMike PritchardThe
218bf5a138eSMike Pritchard.Fn cgetustr
219bf5a138eSMike Pritchardfunction is identical to
220bf5a138eSMike Pritchard.Fn cgetstr
22158f0484fSRodney W. Grimesexcept that it does not expand special characters, but rather returns each
22258f0484fSRodney W. Grimescharacter of the capability string literally.
22358f0484fSRodney W. Grimes.Pp
224bf5a138eSMike PritchardThe
225bf5a138eSMike Pritchard.Fn cgetfirst
226bf5a138eSMike Pritchardand
227bf5a138eSMike Pritchard.Fn cgetnext
228bf5a138eSMike Pritchardfunctions comprise a function group that provides for sequential
22958f0484fSRodney W. Grimesaccess of the
23058f0484fSRodney W. Grimes.Dv NULL
23158f0484fSRodney W. Grimespointer terminated array of file names,
23258f0484fSRodney W. Grimes.Fa db_array .
233bf5a138eSMike PritchardThe
234bf5a138eSMike Pritchard.Fn cgetfirst
235bf5a138eSMike Pritchardfunction returns the first record in the database and resets the access
23658f0484fSRodney W. Grimesto the first record.
237bf5a138eSMike PritchardThe
238bf5a138eSMike Pritchard.Fn cgetnext
239bf5a138eSMike Pritchardfunction returns the next record in the database with respect to the
24058f0484fSRodney W. Grimesrecord returned by the previous
241bf5a138eSMike Pritchard.Fn cgetfirst
24258f0484fSRodney W. Grimesor
243bf5a138eSMike Pritchard.Fn cgetnext
2441a0a9345SRuslan Ermilovcall.
2451a0a9345SRuslan ErmilovIf there is no such previous call, the first record in the database is
24658f0484fSRodney W. Grimesreturned.
24758f0484fSRodney W. GrimesEach record is returned in a
248d0353b83SRuslan Ermilov.Xr malloc 3 Ns \&'d
24958f0484fSRodney W. Grimescopy pointed to by
25058f0484fSRodney W. Grimes.Fa buf .
25158f0484fSRodney W. Grimes.Ic Tc
25258f0484fSRodney W. Grimesexpansion is done (see
25358f0484fSRodney W. Grimes.Ic tc=
25458f0484fSRodney W. Grimescomments below).
25558f0484fSRodney W. GrimesUpon completion of the database 0 is returned, 1 is returned upon successful
2560227791bSRuslan Ermilovreturn of record with possibly more remaining (we have not reached the end of
25758f0484fSRodney W. Grimesthe database yet), 2 is returned if the record contains an unresolved
258b92cc9b8SRuslan Ermilov.Ic tc
259d64ada50SJens Schweikhardtexpansion, \-1 is returned if a system error occurred, and \-2
26058f0484fSRodney W. Grimesis returned if a potential reference loop is detected (see
26158f0484fSRodney W. Grimes.Ic tc=
26258f0484fSRodney W. Grimescomments below).
26358f0484fSRodney W. GrimesUpon completion of database (0 return) the database is closed.
26458f0484fSRodney W. Grimes.Pp
265bf5a138eSMike PritchardThe
266bf5a138eSMike Pritchard.Fn cgetclose
267bf5a138eSMike Pritchardfunction closes the sequential access and frees any memory and file descriptors
2681a0a9345SRuslan Ermilovbeing used.
2691a0a9345SRuslan ErmilovNote that it does not erase the buffer pushed by a call to
270bf5a138eSMike Pritchard.Fn cgetset .
27158f0484fSRodney W. Grimes.Sh CAPABILITY DATABASE SYNTAX
27258f0484fSRodney W. GrimesCapability databases are normally
27358f0484fSRodney W. Grimes.Tn ASCII
27458f0484fSRodney W. Grimesand may be edited with standard
2751a0a9345SRuslan Ermilovtext editors.
2761a0a9345SRuslan ErmilovBlank lines and lines beginning with a `#' are comments
2771a0a9345SRuslan Ermilovand are ignored.
2781a0a9345SRuslan ErmilovLines ending with a `\|\e' indicate that the next line
27958f0484fSRodney W. Grimesis a continuation of the current line; the `\|\e' and following newline
2801a0a9345SRuslan Ermilovare ignored.
2811a0a9345SRuslan ErmilovLong lines are usually continued onto several physical
28258f0484fSRodney W. Grimeslines by ending each line except the last with a `\|\e'.
28358f0484fSRodney W. Grimes.Pp
28458f0484fSRodney W. GrimesCapability databases consist of a series of records, one per logical
2851a0a9345SRuslan Ermilovline.
2861a0a9345SRuslan ErmilovEach record contains a variable number of `:'-separated fields
2871a0a9345SRuslan Ermilov(capabilities).
2881a0a9345SRuslan ErmilovEmpty fields consisting entirely of white space
28958f0484fSRodney W. Grimescharacters (spaces and tabs) are ignored.
29058f0484fSRodney W. Grimes.Pp
29158f0484fSRodney W. GrimesThe first capability of each record specifies its names, separated by `|'
2921a0a9345SRuslan Ermilovcharacters.
2931a0a9345SRuslan ErmilovThese names are used to reference records in the database.
29458f0484fSRodney W. GrimesBy convention, the last name is usually a comment and is not intended as
2951a0a9345SRuslan Ermilova lookup tag.
2961a0a9345SRuslan ErmilovFor example, the
29758f0484fSRodney W. Grimes.Em vt100
29858f0484fSRodney W. Grimesrecord from the
299b92cc9b8SRuslan Ermilov.Xr termcap 5
30058f0484fSRodney W. Grimesdatabase begins:
30158f0484fSRodney W. Grimes.Pp
30258f0484fSRodney W. Grimes.Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:"
30358f0484fSRodney W. Grimes.Pp
30458f0484fSRodney W. Grimesgiving four names that can be used to access the record.
30558f0484fSRodney W. Grimes.Pp
30658f0484fSRodney W. GrimesThe remaining non-empty capabilities describe a set of (name, value)
30712985df3SDima Dorfmanbindings, consisting of a names optionally followed by a typed value:
30858f0484fSRodney W. Grimes.Bl -column "nameTvalue"
30958f0484fSRodney W. Grimes.It name Ta "typeless [boolean] capability"
31058f0484fSRodney W. Grimes.Em name No "is present [true]"
31158f0484fSRodney W. Grimes.It name Ns Em \&T Ns value Ta capability
31258f0484fSRodney W. Grimes.Pq Em name , \&T
31358f0484fSRodney W. Grimeshas value
31458f0484fSRodney W. Grimes.Em value
31558f0484fSRodney W. Grimes.It name@ Ta "no capability" Em name No exists
31658f0484fSRodney W. Grimes.It name Ns Em T Ns \&@ Ta capability
31758f0484fSRodney W. Grimes.Pq Em name , T
31858f0484fSRodney W. Grimesdoes not exist
31958f0484fSRodney W. Grimes.El
32058f0484fSRodney W. Grimes.Pp
3211a0a9345SRuslan ErmilovNames consist of one or more characters.
3221a0a9345SRuslan ErmilovNames may contain any character
32336a142c4SRuslan Ermilovexcept `:', but it is usually best to restrict them to the printable
32430950a21SRuslan Ermilovcharacters and avoid use of graphics like `#', `=', `%', `@', etc.
32530950a21SRuslan ErmilovTypes
32658f0484fSRodney W. Grimesare single characters used to separate capability names from their
3271a0a9345SRuslan Ermilovassociated typed values.
3281a0a9345SRuslan ErmilovTypes may be any character except a `:'.
3291a0a9345SRuslan ErmilovTypically, graphics like `#', `=', `%', etc.\& are used.
3301a0a9345SRuslan ErmilovValues may be any
33158f0484fSRodney W. Grimesnumber of characters and may contain any character except `:'.
33258f0484fSRodney W. Grimes.Sh CAPABILITY DATABASE SEMANTICS
3331a0a9345SRuslan ErmilovCapability records describe a set of (name, value) bindings.
3341a0a9345SRuslan ErmilovNames may
3351a0a9345SRuslan Ermilovhave multiple values bound to them.
3361a0a9345SRuslan ErmilovDifferent values for a name are
33758f0484fSRodney W. Grimesdistinguished by their
33858f0484fSRodney W. Grimes.Fa types .
339bf5a138eSMike PritchardThe
340bf5a138eSMike Pritchard.Fn cgetcap
341bf5a138eSMike Pritchardfunction will return a pointer to a value of a name given the capability
342bf5a138eSMike Pritchardname and the type of the value.
34358f0484fSRodney W. Grimes.Pp
34458f0484fSRodney W. GrimesThe types `#' and `=' are conventionally used to denote numeric and
3451a0a9345SRuslan Ermilovstring typed values, but no restriction on those types is enforced.
3461a0a9345SRuslan ErmilovThe
34758f0484fSRodney W. Grimesfunctions
348bf5a138eSMike Pritchard.Fn cgetnum
34958f0484fSRodney W. Grimesand
350bf5a138eSMike Pritchard.Fn cgetstr
35158f0484fSRodney W. Grimescan be used to implement the traditional syntax and semantics of `#'
35258f0484fSRodney W. Grimesand `='.
35358f0484fSRodney W. GrimesTypeless capabilities are typically used to denote boolean objects with
35458f0484fSRodney W. Grimespresence or absence indicating truth and false values respectively.
35558f0484fSRodney W. GrimesThis interpretation is conveniently represented by:
35658f0484fSRodney W. Grimes.Pp
35758f0484fSRodney W. Grimes.Dl "(getcap(buf, name, ':') != NULL)"
35858f0484fSRodney W. Grimes.Pp
35958f0484fSRodney W. GrimesA special capability,
36058f0484fSRodney W. Grimes.Ic tc= name ,
36158f0484fSRodney W. Grimesis used to indicate that the record specified by
36258f0484fSRodney W. Grimes.Fa name
36358f0484fSRodney W. Grimesshould be substituted for the
36458f0484fSRodney W. Grimes.Ic tc
36558f0484fSRodney W. Grimescapability.
36658f0484fSRodney W. Grimes.Ic Tc
36758f0484fSRodney W. Grimescapabilities may interpolate records which also contain
36858f0484fSRodney W. Grimes.Ic tc
36958f0484fSRodney W. Grimescapabilities and more than one
37058f0484fSRodney W. Grimes.Ic tc
3711a0a9345SRuslan Ermilovcapability may be used in a record.
3721a0a9345SRuslan ErmilovA
37358f0484fSRodney W. Grimes.Ic tc
37458f0484fSRodney W. Grimesexpansion scope (i.e., where the argument is searched for) contains the
37558f0484fSRodney W. Grimesfile in which the
37658f0484fSRodney W. Grimes.Ic tc
37758f0484fSRodney W. Grimesis declared and all subsequent files in the file array.
37858f0484fSRodney W. Grimes.Pp
37958f0484fSRodney W. GrimesWhen a database is searched for a capability record, the first matching
3801a0a9345SRuslan Ermilovrecord in the search is returned.
3811a0a9345SRuslan ErmilovWhen a record is scanned for a
38258f0484fSRodney W. Grimescapability, the first matching capability is returned; the capability
38358f0484fSRodney W. Grimes.Ic :nameT@:
38458f0484fSRodney W. Grimeswill hide any following definition of a value of type
38558f0484fSRodney W. Grimes.Em T
38658f0484fSRodney W. Grimesfor
38758f0484fSRodney W. Grimes.Fa name ;
38858f0484fSRodney W. Grimesand the capability
38958f0484fSRodney W. Grimes.Ic :name@:
39058f0484fSRodney W. Grimeswill prevent any following values of
39158f0484fSRodney W. Grimes.Fa name
39258f0484fSRodney W. Grimesfrom being seen.
39358f0484fSRodney W. Grimes.Pp
39458f0484fSRodney W. GrimesThese features combined with
39558f0484fSRodney W. Grimes.Ic tc
39658f0484fSRodney W. Grimescapabilities can be used to generate variations of other databases and
39758f0484fSRodney W. Grimesrecords by either adding new capabilities, overriding definitions with new
39858f0484fSRodney W. Grimesdefinitions, or hiding following definitions via `@' capabilities.
39958f0484fSRodney W. Grimes.Sh EXAMPLES
40058f0484fSRodney W. Grimes.Bd -unfilled -offset indent
40158f0484fSRodney W. Grimesexample\||\|an example of binding multiple values to names:\e
40258f0484fSRodney W. Grimes	:foo%bar:foo^blah:foo@:\e
40358f0484fSRodney W. Grimes	:abc%xyz:abc^frap:abc$@:\e
40458f0484fSRodney W. Grimes	:tc=more:
40558f0484fSRodney W. Grimes.Ed
40658f0484fSRodney W. Grimes.Pp
40758f0484fSRodney W. GrimesThe capability foo has two values bound to it (bar of type `%' and blah of
4081a0a9345SRuslan Ermilovtype `^') and any other value bindings are hidden.
4091a0a9345SRuslan ErmilovThe capability abc
41058f0484fSRodney W. Grimesalso has two values bound but only a value of type `$' is prevented from
41158f0484fSRodney W. Grimesbeing defined in the capability record more.
41258f0484fSRodney W. Grimes.Pp
41358f0484fSRodney W. Grimes.Bd -unfilled -offset indent
41458f0484fSRodney W. Grimesfile1:
41558f0484fSRodney W. Grimes 	new\||\|new_record\||\|a modification of "old":\e
41658f0484fSRodney W. Grimes		:fript=bar:who-cares@:tc=old:blah:tc=extensions:
41758f0484fSRodney W. Grimesfile2:
41858f0484fSRodney W. Grimes	old\||\|old_record\||\|an old database record:\e
41958f0484fSRodney W. Grimes		:fript=foo:who-cares:glork#200:
42058f0484fSRodney W. Grimes.Ed
42158f0484fSRodney W. Grimes.Pp
42258f0484fSRodney W. GrimesThe records are extracted by calling
423bf5a138eSMike Pritchard.Fn cgetent
42458f0484fSRodney W. Grimeswith file1 preceding file2.
42558f0484fSRodney W. GrimesIn the capability record new in file1, fript=bar overrides the definition
42658f0484fSRodney W. Grimesof fript=foo interpolated from the capability record old in file2,
42758f0484fSRodney W. Grimeswho-cares@ prevents the definition of any who-cares definitions in old
42858f0484fSRodney W. Grimesfrom being seen, glork#200 is inherited from old, and blah and anything
42958f0484fSRodney W. Grimesdefined by the record extensions is added to those definitions in old.
43058f0484fSRodney W. GrimesNote that the position of the fript=bar and who-cares@ definitions before
4311a0a9345SRuslan Ermilovtc=old is important here.
4321a0a9345SRuslan ErmilovIf they were after, the definitions in old
43358f0484fSRodney W. Grimeswould take precedence.
43458f0484fSRodney W. Grimes.Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
43558f0484fSRodney W. GrimesTwo types are predefined by
436bf5a138eSMike Pritchard.Fn cgetnum
43758f0484fSRodney W. Grimesand
438bf5a138eSMike Pritchard.Fn cgetstr :
43958f0484fSRodney W. Grimes.Bl -column "nameXnumber"
44058f0484fSRodney W. Grimes.Sm off
44158f0484fSRodney W. Grimes.It Em name No \&# Em number Ta numeric
442d0353b83SRuslan Ermilov.Sm on
44358f0484fSRodney W. Grimescapability
44458f0484fSRodney W. Grimes.Em name
44558f0484fSRodney W. Grimeshas value
44658f0484fSRodney W. Grimes.Em number
447d0353b83SRuslan Ermilov.Sm off
44858f0484fSRodney W. Grimes.It Em name No = Em string Ta "string capability"
449d0353b83SRuslan Ermilov.Sm on
45058f0484fSRodney W. Grimes.Em name
45158f0484fSRodney W. Grimeshas value
45258f0484fSRodney W. Grimes.Em string
453d0353b83SRuslan Ermilov.Sm off
45458f0484fSRodney W. Grimes.It Em name No \&#@ Ta "the numeric capability"
45542635956SRuslan Ermilov.Sm on
456d0353b83SRuslan Ermilov.Em name
457d0353b83SRuslan Ermilovdoes not exist
458d0353b83SRuslan Ermilov.Sm off
459d0353b83SRuslan Ermilov.It Em name No \&=@ Ta "the string capability"
460d0353b83SRuslan Ermilov.Sm on
461d0353b83SRuslan Ermilov.Em name
462d0353b83SRuslan Ermilovdoes not exist
46358f0484fSRodney W. Grimes.El
46458f0484fSRodney W. Grimes.Pp
46558f0484fSRodney W. GrimesNumeric capability values may be given in one of three numeric bases.
46658f0484fSRodney W. GrimesIf the number starts with either
46758f0484fSRodney W. Grimes.Ql 0x
46858f0484fSRodney W. Grimesor
46958f0484fSRodney W. Grimes.Ql 0X
47058f0484fSRodney W. Grimesit is interpreted as a hexadecimal number (both upper and lower case a-f
47158f0484fSRodney W. Grimesmay be used to denote the extended hexadecimal digits).
47258f0484fSRodney W. GrimesOtherwise, if the number starts with a
47358f0484fSRodney W. Grimes.Ql 0
47458f0484fSRodney W. Grimesit is interpreted as an octal number.
47558f0484fSRodney W. GrimesOtherwise the number is interpreted as a decimal number.
47658f0484fSRodney W. Grimes.Pp
4771a0a9345SRuslan ErmilovString capability values may contain any character.
4781a0a9345SRuslan ErmilovNon-printable
47958f0484fSRodney W. Grimes.Dv ASCII
48058f0484fSRodney W. Grimescodes, new lines, and colons may be conveniently represented by the use
48158f0484fSRodney W. Grimesof escape sequences:
48258f0484fSRodney W. Grimes.Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"
48321ac7f5fSMike Pritchard^X	('X' & 037)	control-X
48458f0484fSRodney W. Grimes\e\|b, \e\|B	(ASCII 010)	backspace
48558f0484fSRodney W. Grimes\e\|t, \e\|T	(ASCII 011)	tab
48658f0484fSRodney W. Grimes\e\|n, \e\|N	(ASCII 012)	line feed (newline)
48758f0484fSRodney W. Grimes\e\|f, \e\|F	(ASCII 014)	form feed
48858f0484fSRodney W. Grimes\e\|r, \e\|R	(ASCII 015)	carriage return
48958f0484fSRodney W. Grimes\e\|e, \e\|E	(ASCII 027)	escape
49058f0484fSRodney W. Grimes\e\|c, \e\|C	(:)	colon
49158f0484fSRodney W. Grimes\e\|\e	(\e\|)	back slash
49258f0484fSRodney W. Grimes\e\|^	(^)	caret
49321ac7f5fSMike Pritchard\e\|nnn	(ASCII octal nnn)
49458f0484fSRodney W. Grimes.El
49558f0484fSRodney W. Grimes.Pp
49658f0484fSRodney W. GrimesA `\|\e' may be followed by up to three octal digits directly specifies
4971a0a9345SRuslan Ermilovthe numeric code for a character.
4981a0a9345SRuslan ErmilovThe use of
49958f0484fSRodney W. Grimes.Tn ASCII
50058f0484fSRodney W. Grimes.Dv NUL Ns s ,
50158f0484fSRodney W. Grimeswhile easily
50258f0484fSRodney W. Grimesencoded, causes all sorts of problems and must be used with care since
50358f0484fSRodney W. Grimes.Dv NUL Ns s
50458f0484fSRodney W. Grimesare typically used to denote the end of strings; many applications
50558f0484fSRodney W. Grimesuse `\e\|200' to represent a
50658f0484fSRodney W. Grimes.Dv NUL .
50758f0484fSRodney W. Grimes.Sh DIAGNOSTICS
508beb64fb5SMike PritchardThe
509beb64fb5SMike Pritchard.Fn cgetent ,
510bf5a138eSMike Pritchard.Fn cgetset ,
511bf5a138eSMike Pritchard.Fn cgetmatch ,
512bf5a138eSMike Pritchard.Fn cgetnum ,
513bf5a138eSMike Pritchard.Fn cgetstr ,
514bf5a138eSMike Pritchard.Fn cgetustr ,
515bf5a138eSMike Pritchard.Fn cgetfirst ,
51658f0484fSRodney W. Grimesand
517bf5a138eSMike Pritchard.Fn cgetnext
518beb64fb5SMike Pritchardfunctions
51958f0484fSRodney W. Grimesreturn a value greater than or equal to 0 on success and a value less
52058f0484fSRodney W. Grimesthan 0 on failure.
521bf5a138eSMike PritchardThe
522bf5a138eSMike Pritchard.Fn cgetcap
523bf5a138eSMike Pritchardfunction returns a character pointer on success and a
52458f0484fSRodney W. Grimes.Dv NULL
52558f0484fSRodney W. Grimeson failure.
52658f0484fSRodney W. Grimes.Pp
527bf5a138eSMike PritchardThe
528bf5a138eSMike Pritchard.Fn cgetent ,
52958f0484fSRodney W. Grimesand
530af48594dSMaxim Konovalov.Fn cgetset
531bf5a138eSMike Pritchardfunctions may fail and set
53258f0484fSRodney W. Grimes.Va errno
53358f0484fSRodney W. Grimesfor any of the errors specified for the library functions:
534b07158f7SChris Costello.Xr fopen 3 ,
535b07158f7SChris Costello.Xr fclose 3 ,
53658f0484fSRodney W. Grimes.Xr open 2 ,
53758f0484fSRodney W. Grimesand
53858f0484fSRodney W. Grimes.Xr close 2 .
53958f0484fSRodney W. Grimes.Pp
540bf5a138eSMike PritchardThe
541bf5a138eSMike Pritchard.Fn cgetent ,
542bf5a138eSMike Pritchard.Fn cgetset ,
543bf5a138eSMike Pritchard.Fn cgetstr ,
54458f0484fSRodney W. Grimesand
545bf5a138eSMike Pritchard.Fn cgetustr
546beb64fb5SMike Pritchardfunctions
54758f0484fSRodney W. Grimesmay fail and set
54858f0484fSRodney W. Grimes.Va errno
54958f0484fSRodney W. Grimesas follows:
55058f0484fSRodney W. Grimes.Bl -tag -width Er
55158f0484fSRodney W. Grimes.It Bq Er ENOMEM
55258f0484fSRodney W. GrimesNo memory to allocate.
55358f0484fSRodney W. Grimes.El
55458f0484fSRodney W. Grimes.Sh SEE ALSO
55558f0484fSRodney W. Grimes.Xr cap_mkdb 1 ,
55658f0484fSRodney W. Grimes.Xr malloc 3
55758f0484fSRodney W. Grimes.Sh BUGS
5580227791bSRuslan ErmilovColons (`:') cannot be used in names, types, or values.
55958f0484fSRodney W. Grimes.Pp
56058f0484fSRodney W. GrimesThere are no checks for
56142635956SRuslan Ermilov.Ic tc Ns = Ns Ic name
56258f0484fSRodney W. Grimesloops in
563bf5a138eSMike Pritchard.Fn cgetent .
56458f0484fSRodney W. Grimes.Pp
56558f0484fSRodney W. GrimesThe buffer added to the database by a call to
566bf5a138eSMike Pritchard.Fn cgetset
56758f0484fSRodney W. Grimesis not unique to the database but is rather prepended to any database used.
568