bring in getcap routines, supplied by CSRG, from 4.4...
This commit is contained in:
parent
24c005f7ee
commit
7886a059b7
|
@ -5,10 +5,10 @@
|
|||
|
||||
SRCS+= alarm.c clock.c closedir.c crypt.c ctermid.c ctime.c ctype_.c \
|
||||
difftime.c disklabel.c err.c errlst.c exec.c fnmatch.c frexp.c \
|
||||
fstab.c fts.c getcwd.c getgrent.c getlogin.c getmntinfo.c getpass.c \
|
||||
getpwent.c getsubopt.c getttyent.c getusershell.c glob.c initgroups.c \
|
||||
isatty.c isctype.c isinf.c mktemp.c nice.c nlist.c opendir.c \
|
||||
pause.c popen.c psignal.c raise.c readdir.c \
|
||||
fstab.c fts.c getcap.c getcwd.c getgrent.c getlogin.c getmntinfo.c \
|
||||
getpass.c getpwent.c getsubopt.c getttyent.c getusershell.c glob.c \
|
||||
initgroups.c isatty.c isctype.c isinf.c mktemp.c nice.c nlist.c \
|
||||
opendir.c pause.c popen.c psignal.c raise.c readdir.c \
|
||||
rewinddir.c scandir.c seekdir.c setjmperr.c \
|
||||
setmode.c setrgid.c setruid.c siginterrupt.c \
|
||||
siglist.c signal.c sigsetops.c sleep.c syslog.c telldir.c \
|
||||
|
@ -39,8 +39,8 @@ SRCS+= udiv.s urem.s
|
|||
.endif
|
||||
|
||||
MAN3+= alarm.0 clock.0 crypt.0 ctermid.0 ctime.0 ctype.0 directory.0 err.0 \
|
||||
exec.0 fnmatch.0 frexp.0 fts.0 getcwd.0 getdiskbyname.0 getfsent.0 \
|
||||
getgrent.0 getmntinfo.0 getpass.0 getpwent.0 getsubopt.0 \
|
||||
exec.0 fnmatch.0 frexp.0 fts.0 getcap.0 getcwd.0 getdiskbyname.0 \
|
||||
getfsent.0 getgrent.0 getmntinfo.0 getpass.0 getpwent.0 getsubopt.0 \
|
||||
getttyent.0 getusershell.0 glob.0 initgroups.0 isalnum.0 \
|
||||
isalpha.0 isascii.0 iscntrl.0 isdigit.0 isgraph.0 isinf.0 \
|
||||
islower.0 isprint.0 ispunct.0 isspace.0 isupper.0 isxdigit.0 \
|
||||
|
@ -61,6 +61,10 @@ MLINKS+=err.3 verr.3 err.3 errx.3 err.3 verrx.3 err.3 warn.3 err.3 vwarn.3 \
|
|||
MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \
|
||||
exec.3 execvp.3
|
||||
MLINKS+=isinf.3 isnan.3
|
||||
MLINKS+=getcap.3 cgetcap.3 getcap.3 cgetclose.3 getcap.3 cgetent.3 \
|
||||
getcap.3 cgetfirst.3 getcap.3 cgetmatch.3 getcap.3 cgetnext.3 \
|
||||
getcap.3 cgetnum.3 getcap.3 cgetset.3 getcap.3 cgetstr.3 \
|
||||
getcap.3 cgetustr.3
|
||||
MLINKS+=getcwd.3 getwd.3
|
||||
MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \
|
||||
getfsent.3 getfstype.3 getfsent.3 setfsent.3
|
||||
|
|
|
@ -0,0 +1,511 @@
|
|||
.\" Copyright (c) 1992 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Casey Leedom of Lawrence Livermore National Laboratory.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)getcap.3 5.4 (Berkeley) 8/11/92
|
||||
.\"
|
||||
.Dd "August 11, 1992"
|
||||
.Dt GETCAP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm cgetent ,
|
||||
.Nm cgetset ,
|
||||
.Nm cgetmatch ,
|
||||
.Nm cgetcap ,
|
||||
.Nm cgetnum ,
|
||||
.Nm cgetstr ,
|
||||
.Nm cgetustr ,
|
||||
.Nm cgetfirst ,
|
||||
.Nm cgetnext ,
|
||||
.Nm cgetclose
|
||||
.Nd capability database access routines
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <stdlib.h>
|
||||
.Ft int
|
||||
.Fn cgetent "char **buf" "char **db_array" "char *name"
|
||||
.Ft int
|
||||
.Fn cgetset "char *ent"
|
||||
.Ft int
|
||||
.Fn cgetmatch "char *buf" "char *name"
|
||||
.Ft char *
|
||||
.Fn cgetcap "char *buf" "char *cap" "char type"
|
||||
.Ft int
|
||||
.Fn cgetnum "char *buf" "char *cap" "long *num"
|
||||
.Ft int
|
||||
.Fn cgetstr "char *buf" "char *cap" "char **str"
|
||||
.Ft int
|
||||
.Fn cgetustr "char *buf" "char *cap" "char **str"
|
||||
.Ft int
|
||||
.Fn cgetfirst "char **buf" "char **db_array"
|
||||
.Ft int
|
||||
.Fn cgetnext "char **buf" "char **db_array"
|
||||
.Ft int
|
||||
.Fn cgetclose "void"
|
||||
.Sh DESCRIPTION
|
||||
.Fn Cgetent
|
||||
extracts the capability rec
|
||||
.Fa name
|
||||
from the database specified by the
|
||||
.Dv NULL
|
||||
terminated file array
|
||||
.Fa db_array
|
||||
and returns a pointer to a
|
||||
.Xr malloc Ns \&'d
|
||||
copy of it in
|
||||
.Fa buf .
|
||||
.Nm Cgetent
|
||||
will first look for files ending in
|
||||
.Nm .db
|
||||
(see
|
||||
.Xr cap_mkdb 1)
|
||||
before accessing the ASCII file.
|
||||
.Fa Buf
|
||||
must be retained through all subsequent calls to
|
||||
.Fn cgetmatch ,
|
||||
.Fn cgetcap ,
|
||||
.Fn cgetnum ,
|
||||
.Fn cgetstr ,
|
||||
and
|
||||
.Fn cgetustr ,
|
||||
but may then be
|
||||
.Xr free Ns \&'d.
|
||||
On success 0 is returned, 1 if the returned
|
||||
record contains an unresolved
|
||||
.Nm tc
|
||||
expansion,
|
||||
\-1 if the requested record couldn't be found,
|
||||
\-2 if a system error was encountered (couldn't open/read a file, etc.) also
|
||||
setting
|
||||
.Va errno ,
|
||||
and \-3 if a potential reference loop is detected (see
|
||||
.Ic tc=
|
||||
comments below).
|
||||
.Pp
|
||||
.Nm Cgetset
|
||||
enables the addition of a character buffer containing a single capability
|
||||
record entry
|
||||
to the capability database.
|
||||
Conceptually, the entry is added as the first ``file'' in the database, and
|
||||
is therefore searched first on the call to
|
||||
.Nm cgetent .
|
||||
The entry is passed in
|
||||
.Fa ent .
|
||||
If
|
||||
.Fa ent
|
||||
is
|
||||
.Dv NULL ,
|
||||
the current entry is removed from the database.
|
||||
.Nm Cgetset
|
||||
must precede the database traversal. It must be called before the
|
||||
.Nm cgetent
|
||||
call. If a sequential access is being performed (see below), it must be called
|
||||
before the first sequential access call (
|
||||
.Nm cgetfirst
|
||||
or
|
||||
.Nm cgetnext
|
||||
), or be directly preceded by a
|
||||
.Nm cgetclose
|
||||
call.
|
||||
On success 0 is returned and \-1 on failure.
|
||||
.Pp
|
||||
.Nm Cgetmatch
|
||||
will return 0 if
|
||||
.Fa name
|
||||
is one of the names of the capability record
|
||||
.Fa buf ,
|
||||
\-1 if
|
||||
not.
|
||||
.Pp
|
||||
.Nm Cgetcap
|
||||
searches the capability record
|
||||
.Fa buf
|
||||
for the capability
|
||||
.Fa cap
|
||||
with type
|
||||
.Fa type .
|
||||
A
|
||||
.Fa type
|
||||
is specified using any single character. If a colon (`:') is used, an
|
||||
untyped capability will be searched for (see below for explanation of
|
||||
types). A pointer to the value of
|
||||
.Fa cap
|
||||
in
|
||||
.Fa buf
|
||||
is returned on success,
|
||||
.Dv NULL
|
||||
if the requested capability couldn't be
|
||||
found. The end of the capability value is signaled by a `:' or
|
||||
.Tn ASCII
|
||||
.Dv NUL
|
||||
(see below for capability database syntax).
|
||||
.Pp
|
||||
.Nm Cgetnum
|
||||
retrieves the value of the numeric capability
|
||||
.Fa cap
|
||||
from the capability record pointed to by
|
||||
.Fa buf .
|
||||
The numeric value is returned in the
|
||||
.Ft long
|
||||
pointed to by
|
||||
.Fa num .
|
||||
0 is returned on success, \-1 if the requested numeric capability couldn't
|
||||
be found.
|
||||
.Pp
|
||||
.Nm Cgetstr
|
||||
retrieves the value of the string capability
|
||||
.Fa cap
|
||||
from the capability record pointed to by
|
||||
.Fa buf .
|
||||
A pointer to a decoded,
|
||||
.Dv NUL
|
||||
terminated,
|
||||
.Xr malloc Ns \&'d
|
||||
copy of the string is returned in the
|
||||
.Ft char *
|
||||
pointed to by
|
||||
.Fa str .
|
||||
The number of characters in the decoded string not including the trailing
|
||||
.Dv NUL
|
||||
is returned on success, \-1 if the requested string capability couldn't
|
||||
be found, \-2 if a system error was encountered (storage allocation
|
||||
failure).
|
||||
.Pp
|
||||
.Nm Cgetustr
|
||||
is identical to
|
||||
.Nm cgetstr
|
||||
except that it does not expand special characters, but rather returns each
|
||||
character of the capability string literally.
|
||||
.Pp
|
||||
.Nm Cgetfirst ,
|
||||
.Nm cgetnext ,
|
||||
comprise a function group that provides for sequential
|
||||
access of the
|
||||
.Dv NULL
|
||||
pointer terminated array of file names,
|
||||
.Fa db_array .
|
||||
.Nm Cgetfirst
|
||||
returns the first record in the database and resets the access
|
||||
to the first record.
|
||||
.Nm Cgetnext
|
||||
returns the next record in the database with respect to the
|
||||
record returned by the previous
|
||||
.Nm cgetfirst
|
||||
or
|
||||
.Nm cgetnext
|
||||
call. If there is no such previous call, the first record in the database is
|
||||
returned.
|
||||
Each record is returned in a
|
||||
.Xr malloc Ns \&'d
|
||||
copy pointed to by
|
||||
.Fa buf .
|
||||
.Ic Tc
|
||||
expansion is done (see
|
||||
.Ic tc=
|
||||
comments below).
|
||||
Upon completion of the database 0 is returned, 1 is returned upon successful
|
||||
return of record with possibly more remaining (we haven't reached the end of
|
||||
the database yet), 2 is returned if the record contains an unresolved
|
||||
.Nm tc
|
||||
expansion, \-1 is returned if an system error occured, and \-2
|
||||
is returned if a potential reference loop is detected (see
|
||||
.Ic tc=
|
||||
comments below).
|
||||
Upon completion of database (0 return) the database is closed.
|
||||
.Pp
|
||||
.Nm Cgetclose
|
||||
closes the sequential access and frees any memory and file descriptors
|
||||
being used. Note that it does not erase the buffer pushed by a call to
|
||||
.Nm cgetset .
|
||||
.Sh CAPABILITY DATABASE SYNTAX
|
||||
Capability databases are normally
|
||||
.Tn ASCII
|
||||
and may be edited with standard
|
||||
text editors. Blank lines and lines beginning with a `#' are comments
|
||||
and are ignored. Lines ending with a `\|\e' indicate that the next line
|
||||
is a continuation of the current line; the `\|\e' and following newline
|
||||
are ignored. Long lines are usually continued onto several physical
|
||||
lines by ending each line except the last with a `\|\e'.
|
||||
.Pp
|
||||
Capability databases consist of a series of records, one per logical
|
||||
line. Each record contains a variable number of `:'-separated fields
|
||||
(capabilities). Empty fields consisting entirely of white space
|
||||
characters (spaces and tabs) are ignored.
|
||||
.Pp
|
||||
The first capability of each record specifies its names, separated by `|'
|
||||
characters. These names are used to reference records in the database.
|
||||
By convention, the last name is usually a comment and is not intended as
|
||||
a lookup tag. For example, the
|
||||
.Em vt100
|
||||
record from the
|
||||
.Nm termcap
|
||||
database begins:
|
||||
.Pp
|
||||
.Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:"
|
||||
.Pp
|
||||
giving four names that can be used to access the record.
|
||||
.Pp
|
||||
The remaining non-empty capabilities describe a set of (name, value)
|
||||
bindings, consisting of a names optionally followed by a typed values:
|
||||
.Bl -column "nameTvalue"
|
||||
.It name Ta "typeless [boolean] capability"
|
||||
.Em name No "is present [true]"
|
||||
.It name Ns Em \&T Ns value Ta capability
|
||||
.Pq Em name , \&T
|
||||
has value
|
||||
.Em value
|
||||
.It name@ Ta "no capability" Em name No exists
|
||||
.It name Ns Em T Ns \&@ Ta capability
|
||||
.Pq Em name , T
|
||||
does not exist
|
||||
.El
|
||||
.Pp
|
||||
Names consist of one or more characters. Names may contain any character
|
||||
except `:', but it's usually best to restrict them to the printable
|
||||
characters and avoid use of graphics like `#', `=', `%', `@', etc. Types
|
||||
are single characters used to separate capability names from their
|
||||
associated typed values. Types may be any character except a `:'.
|
||||
Typically, graphics like `#', `=', `%', etc. are used. Values may be any
|
||||
number of characters and may contain any character except `:'.
|
||||
.Sh CAPABILITY DATABASE SEMANTICS
|
||||
Capability records describe a set of (name, value) bindings. Names may
|
||||
have multiple values bound to them. Different values for a name are
|
||||
distinguished by their
|
||||
.Fa types .
|
||||
.Nm Cgetcap
|
||||
will return a pointer to a value of a name given the capability name and
|
||||
the type of the value.
|
||||
.Pp
|
||||
The types `#' and `=' are conventionally used to denote numeric and
|
||||
string typed values, but no restriction on those types is enforced. The
|
||||
functions
|
||||
.Nm cgetnum
|
||||
and
|
||||
.Nm cgetstr
|
||||
can be used to implement the traditional syntax and semantics of `#'
|
||||
and `='.
|
||||
Typeless capabilities are typically used to denote boolean objects with
|
||||
presence or absence indicating truth and false values respectively.
|
||||
This interpretation is conveniently represented by:
|
||||
.Pp
|
||||
.Dl "(getcap(buf, name, ':') != NULL)"
|
||||
.Pp
|
||||
A special capability,
|
||||
.Ic tc= name ,
|
||||
is used to indicate that the record specified by
|
||||
.Fa name
|
||||
should be substituted for the
|
||||
.Ic tc
|
||||
capability.
|
||||
.Ic Tc
|
||||
capabilities may interpolate records which also contain
|
||||
.Ic tc
|
||||
capabilities and more than one
|
||||
.Ic tc
|
||||
capability may be used in a record. A
|
||||
.Ic tc
|
||||
expansion scope (i.e., where the argument is searched for) contains the
|
||||
file in which the
|
||||
.Ic tc
|
||||
is declared and all subsequent files in the file array.
|
||||
.Pp
|
||||
When a database is searched for a capability record, the first matching
|
||||
record in the search is returned. When an record is scanned for a
|
||||
capability, the first matching capability is returned; the capability
|
||||
.Ic :nameT@:
|
||||
will hide any following definition of a value of type
|
||||
.Em T
|
||||
for
|
||||
.Fa name ;
|
||||
and the capability
|
||||
.Ic :name@:
|
||||
will prevent any following values of
|
||||
.Fa name
|
||||
from being seen.
|
||||
.Pp
|
||||
These features combined with
|
||||
.Ic tc
|
||||
capabilities can be used to generate variations of other databases and
|
||||
records by either adding new capabilities, overriding definitions with new
|
||||
definitions, or hiding following definitions via `@' capabilities.
|
||||
.Sh EXAMPLES
|
||||
.Bd -unfilled -offset indent
|
||||
example\||\|an example of binding multiple values to names:\e
|
||||
:foo%bar:foo^blah:foo@:\e
|
||||
:abc%xyz:abc^frap:abc$@:\e
|
||||
:tc=more:
|
||||
.Ed
|
||||
.Pp
|
||||
The capability foo has two values bound to it (bar of type `%' and blah of
|
||||
type `^') and any other value bindings are hidden. The capability abc
|
||||
also has two values bound but only a value of type `$' is prevented from
|
||||
being defined in the capability record more.
|
||||
.Pp
|
||||
.Bd -unfilled -offset indent
|
||||
file1:
|
||||
new\||\|new_record\||\|a modification of "old":\e
|
||||
:fript=bar:who-cares@:tc=old:blah:tc=extensions:
|
||||
file2:
|
||||
old\||\|old_record\||\|an old database record:\e
|
||||
:fript=foo:who-cares:glork#200:
|
||||
.Ed
|
||||
.Pp
|
||||
The records are extracted by calling
|
||||
.Nm cgetent
|
||||
with file1 preceding file2.
|
||||
In the capability record new in file1, fript=bar overrides the definition
|
||||
of fript=foo interpolated from the capability record old in file2,
|
||||
who-cares@ prevents the definition of any who-cares definitions in old
|
||||
from being seen, glork#200 is inherited from old, and blah and anything
|
||||
defined by the record extensions is added to those definitions in old.
|
||||
Note that the position of the fript=bar and who-cares@ definitions before
|
||||
tc=old is important here. If they were after, the definitions in old
|
||||
would take precedence.
|
||||
.Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
|
||||
Two types are predefined by
|
||||
.Nm cgetnum
|
||||
and
|
||||
.Nm cgetstr :
|
||||
.Bl -column "nameXnumber"
|
||||
.Sm off
|
||||
.It Em name No \&# Em number Ta numeric
|
||||
capability
|
||||
.Em name
|
||||
has value
|
||||
.Em number
|
||||
.It Em name No = Em string Ta "string capability"
|
||||
.Em name
|
||||
has value
|
||||
.Em string
|
||||
.It Em name No \&#@ Ta "the numeric capability"
|
||||
.Em name
|
||||
does not exist
|
||||
.It Em name No \&=@ Ta "the string capability"
|
||||
.Em name
|
||||
does not exist
|
||||
.El
|
||||
.Pp
|
||||
Numeric capability values may be given in one of three numeric bases.
|
||||
If the number starts with either
|
||||
.Ql 0x
|
||||
or
|
||||
.Ql 0X
|
||||
it is interpreted as a hexadecimal number (both upper and lower case a-f
|
||||
may be used to denote the extended hexadecimal digits).
|
||||
Otherwise, if the number starts with a
|
||||
.Ql 0
|
||||
it is interpreted as an octal number.
|
||||
Otherwise the number is interpreted as a decimal number.
|
||||
.Pp
|
||||
String capability values may contain any character. Non-printable
|
||||
.Dv ASCII
|
||||
codes, new lines, and colons may be conveniently represented by the use
|
||||
of escape sequences:
|
||||
.Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"
|
||||
^X ('\fIX\fP' & 037) control-\fIX\fP
|
||||
\e\|b, \e\|B (ASCII 010) backspace
|
||||
\e\|t, \e\|T (ASCII 011) tab
|
||||
\e\|n, \e\|N (ASCII 012) line feed (newline)
|
||||
\e\|f, \e\|F (ASCII 014) form feed
|
||||
\e\|r, \e\|R (ASCII 015) carriage return
|
||||
\e\|e, \e\|E (ASCII 027) escape
|
||||
\e\|c, \e\|C (:) colon
|
||||
\e\|\e (\e\|) back slash
|
||||
\e\|^ (^) caret
|
||||
\e\|\fInnn\fP (ASCII octal \fInnn\fP)
|
||||
.El
|
||||
.Pp
|
||||
A `\|\e' may be followed by up to three octal digits directly specifies
|
||||
the numeric code for a character. The use of
|
||||
.Tn ASCII
|
||||
.Dv NUL Ns s ,
|
||||
while easily
|
||||
encoded, causes all sorts of problems and must be used with care since
|
||||
.Dv NUL Ns s
|
||||
are typically used to denote the end of strings; many applications
|
||||
use `\e\|200' to represent a
|
||||
.Dv NUL .
|
||||
.Sh DIAGNOSTICS
|
||||
.Nm Cgetent ,
|
||||
.Nm cgetset ,
|
||||
.Nm cgetmatch ,
|
||||
.Nm cgetnum ,
|
||||
.Nm cgetstr ,
|
||||
.Nm cgetustr ,
|
||||
.Nm cgetfirst ,
|
||||
and
|
||||
.Nm cgetnext
|
||||
return a a value greater than or equal to 0 on success and a value less
|
||||
than 0 on failure.
|
||||
.Nm Cgetcap
|
||||
returns a character pointer on success and a
|
||||
.Dv NULL
|
||||
on failure.
|
||||
.Pp
|
||||
.Nm Cgetent ,
|
||||
and
|
||||
.Nm cgetseq
|
||||
may fail and set
|
||||
.Va errno
|
||||
for any of the errors specified for the library functions:
|
||||
.Xr fopen 2 ,
|
||||
.Xr fclose 2 ,
|
||||
.Xr open 2 ,
|
||||
and
|
||||
.Xr close 2 .
|
||||
.Pp
|
||||
.Nm Cgetent ,
|
||||
.Nm cgetset ,
|
||||
.Nm cgetstr ,
|
||||
and
|
||||
.Nm cgetustr
|
||||
may fail and set
|
||||
.Va errno
|
||||
as follows:
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er ENOMEM
|
||||
No memory to allocate.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr cap_mkdb 1 ,
|
||||
.Xr malloc 3
|
||||
.Sh BUGS
|
||||
Colons (`:') can't be used in names, types, or values.
|
||||
.Pp
|
||||
There are no checks for
|
||||
.Ic tc= name
|
||||
loops in
|
||||
.Nm cgetent .
|
||||
.Pp
|
||||
The buffer added to the database by a call to
|
||||
.Nm cgetset
|
||||
is not unique to the database but is rather prepended to any database used.
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
# @(#)Makefile 5.12 (Berkeley) 7/1/90
|
||||
# @(#)Makefile 5.14 (Berkeley) 9/15/92
|
||||
|
||||
# reorder gives an editor command for most common terminals
|
||||
# (in reverse order from n'th to 1'st most commonly used)
|
||||
|
@ -6,27 +6,36 @@
|
|||
#
|
||||
MAN5= termcap.0
|
||||
|
||||
all: termcap
|
||||
all: termcap termcap.db ${MAN5}
|
||||
|
||||
termcap: reorder termcap.src
|
||||
# ex - ${.CURDIR}/termcap.src < ${.CURDIR}/reorder > /dev/null
|
||||
-ex - ${.CURDIR}/termcap.src < ${.CURDIR}/reorder > /dev/null
|
||||
|
||||
clean cleandir:
|
||||
rm -f termcap
|
||||
termcap.db: termcap
|
||||
cap_mkdb termcap
|
||||
|
||||
clean:
|
||||
rm -f termcap termcap.db
|
||||
|
||||
cleandir: clean
|
||||
rm -f ${MAN5}
|
||||
|
||||
beforeinstall:
|
||||
@if [ ! -d ${DESTDIR}${BINDIR}/misc ]; then \
|
||||
/bin/rm -f ${DESTDIR}${BINDIR}/misc ; \
|
||||
mkdir -p ${DESTDIR}${BINDIR}/misc ; \
|
||||
chown root.wheel ${DESTDIR}${BINDIR}/misc ; \
|
||||
chmod 755 ${DESTDIR}${BINDIR}/misc ; \
|
||||
else \
|
||||
true ; \
|
||||
fi
|
||||
install -c -o ${BINOWN} -g ${BINGRP} -m 444 termcap \
|
||||
/bin/rm -f ${DESTDIR}${BINDIR}/misc ; \
|
||||
mkdir -p ${DESTDIR}${BINDIR}/misc ; \
|
||||
chown root.wheel ${DESTDIR}${BINDIR}/misc ; \
|
||||
chmod 755 ${DESTDIR}${BINDIR}/misc ; \
|
||||
else \
|
||||
true ; \
|
||||
fi
|
||||
install -o ${BINOWN} -g ${BINGRP} -m 444 termcap \
|
||||
${DESTDIR}${BINDIR}/misc
|
||||
install -o ${BINOWN} -g ${BINGRP} -m 444 termcap.db \
|
||||
${DESTDIR}${BINDIR}/misc
|
||||
install -c -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/map3270 \
|
||||
${DESTDIR}${BINDIR}/misc
|
||||
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
@ -1,61 +1,61 @@
|
|||
/# << EOH -/k a
|
||||
/|adm12|/;.,/^[^ ]/-m'a
|
||||
/|pcplot/;.,/^[^ ]/-m'a
|
||||
/|c100|/;.,/^[^ ]/-m'a
|
||||
/|c100-rv|/;.,/^[^ ]/-m'a
|
||||
/|c100-rv-pp|/;.,/^[^ ]/-m'a
|
||||
/|c108-4p|/;.,/^[^ ]/-m'a
|
||||
/|c108-rv-4p|/;.,/^[^ ]/-m'a
|
||||
/|c108-8p|/;.,/^[^ ]/-m'a
|
||||
/|c108-rv-8p|/;.,/^[^ ]/-m'a
|
||||
/|avt|/;.,/^[^ ]/-m'a
|
||||
/|avt-rv|/;.,/^[^ ]/-m'a
|
||||
/|avt-4p-s|/;.,/^[^ ]/-m'a
|
||||
/|avt-8p-s|/;.,/^[^ ]/-m'a
|
||||
/|ansi.sys|/;.,/^[^ ]/-m'a
|
||||
/|ansi.sysk|/;.,/^[^ ]/-m'a
|
||||
/|nansi.sys|/;.,/^[^ ]/-m'a
|
||||
/|nansi.sysk|/;.,/^[^ ]/-m'a
|
||||
/|h19kermit|/;.,/^[^ ]/-m'a
|
||||
/|mskermit22714|/;.,/^[^ ]/-m'a
|
||||
/|mskermit227am|/;.,/^[^ ]/-m'a
|
||||
/|mskermit227|/;.,/^[^ ]/-m'a
|
||||
/|pckermit120|/;.,/^[^ ]/-m'a
|
||||
/|pckermit|/;.,/^[^ ]/-m'a
|
||||
/|kermitam|/;.,/^[^ ]/-m'a
|
||||
/|kermit|/;.,/^[^ ]/-m'a
|
||||
/|sun-17|/;.,/^[^ ]/-m'a
|
||||
/|sun-24|/;.,/^[^ ]/-m'a
|
||||
/|sun-34|/;.,/^[^ ]/-m'a
|
||||
/|sun-48|/;.,/^[^ ]/-m'a
|
||||
/|sun-s-e|/;.,/^[^ ]/-m'a
|
||||
/|sun-s|/;.,/^[^ ]/-m'a
|
||||
/|sun-e|/;.,/^[^ ]/-m'a
|
||||
/|sun|/;.,/^[^ ]/-m'a
|
||||
/|xterms|/;.,/^[^ ]/-m'a
|
||||
/|xterm|/;.,/^[^ ]/-m'a
|
||||
/|adm3|/;.,/^[^ ]/-m'a
|
||||
/|adm31|/;.,/^[^ ]/-m'a
|
||||
/|adm3a|/;.,/^[^ ]/-m'a
|
||||
/|tvi924vb|/;.,/^[^ ]/-m'a
|
||||
/|tvi924|/;.,/^[^ ]/-m'a
|
||||
/|tvi920|/;.,/^[^ ]/-m'a
|
||||
/|tvi920c|/;.,/^[^ ]/-m'a
|
||||
/|tvi925vb|/;.,/^[^ ]/-m'a
|
||||
/|tvi925|/;.,/^[^ ]/-m'a
|
||||
/|vt100|/;.,/^[^ ]/-m'a
|
||||
/|vt220|/;.,/^[^ ]/-m'a
|
||||
/|hp|/;.,/^[^ ]/-m'a
|
||||
/|2645|/;.,/^[^ ]/-m'a
|
||||
/|2621-nl|/;.,/^[^ ]/-m'a
|
||||
/|2621|/;.,/^[^ ]/-m'a
|
||||
/|h29|/;.,/^[^ ]/-m'a
|
||||
/|h19|/;.,/^[^ ]/-m'a
|
||||
/|h19-u|/;.,/^[^ ]/-m'a
|
||||
/|h19-us|/;.,/^[^ ]/-m'a
|
||||
/|h19-e|/;.,/^[^ ]/-m'a
|
||||
/|h19-g|/;.,/^[^ ]/-m'a
|
||||
/|5620|/;.,/^[^ ]/-m'a
|
||||
/^adm12|/;.,/^[^ ]/-m'a
|
||||
/^pcplot/;.,/^[^ ]/-m'a
|
||||
/^c100|/;.,/^[^ ]/-m'a
|
||||
/^c100-rv|/;.,/^[^ ]/-m'a
|
||||
/^c100-rv-pp|/;.,/^[^ ]/-m'a
|
||||
/^c108-4p|/;.,/^[^ ]/-m'a
|
||||
/^c108-rv-4p|/;.,/^[^ ]/-m'a
|
||||
/^c108|/;.,/^[^ ]/-m'a
|
||||
/^c108-rv-8p|/;.,/^[^ ]/-m'a
|
||||
/^avt|/;.,/^[^ ]/-m'a
|
||||
/^avt-rv|/;.,/^[^ ]/-m'a
|
||||
/^avt-4p-s|/;.,/^[^ ]/-m'a
|
||||
/^avt-8p-s|/;.,/^[^ ]/-m'a
|
||||
/^ansi.sys|/;.,/^[^ ]/-m'a
|
||||
/^ansi.sysk|/;.,/^[^ ]/-m'a
|
||||
/^nansi.sys|/;.,/^[^ ]/-m'a
|
||||
/^nansi.sysk|/;.,/^[^ ]/-m'a
|
||||
/^h19k|/;.,/^[^ ]/-m'a
|
||||
/^msk22714|/;.,/^[^ ]/-m'a
|
||||
/^msk227am|/;.,/^[^ ]/-m'a
|
||||
/^msk227|/;.,/^[^ ]/-m'a
|
||||
/^pckermit120|/;.,/^[^ ]/-m'a
|
||||
/^pckermit|/;.,/^[^ ]/-m'a
|
||||
/^kermitam|/;.,/^[^ ]/-m'a
|
||||
/^kermit|/;.,/^[^ ]/-m'a
|
||||
/^sun-17|/;.,/^[^ ]/-m'a
|
||||
/^sun-24|/;.,/^[^ ]/-m'a
|
||||
/^sun-34|/;.,/^[^ ]/-m'a
|
||||
/^sun-48|/;.,/^[^ ]/-m'a
|
||||
/^sun-e-s|/;.,/^[^ ]/-m'a
|
||||
/^sun-s|/;.,/^[^ ]/-m'a
|
||||
/^sun-e|/;.,/^[^ ]/-m'a
|
||||
/^sun|/;.,/^[^ ]/-m'a
|
||||
/^xterms|/;.,/^[^ ]/-m'a
|
||||
/^xterm|/;.,/^[^ ]/-m'a
|
||||
/^adm3|/;.,/^[^ ]/-m'a
|
||||
/^adm31|/;.,/^[^ ]/-m'a
|
||||
/^adm3a|/;.,/^[^ ]/-m'a
|
||||
/^tvi924vb|/;.,/^[^ ]/-m'a
|
||||
/^tvi924|/;.,/^[^ ]/-m'a
|
||||
/^tvi912|/;.,/^[^ ]/-m'a
|
||||
/^920b|/;.,/^[^ ]/-m'a
|
||||
/^tvi925vb|/;.,/^[^ ]/-m'a
|
||||
/^tvi925|/;.,/^[^ ]/-m'a
|
||||
/^vt100|/;.,/^[^ ]/-m'a
|
||||
/^vt200|/;.,/^[^ ]/-m'a
|
||||
/^hp|/;.,/^[^ ]/-m'a
|
||||
/^hp2645|/;.,/^[^ ]/-m'a
|
||||
/^2621-nl|/;.,/^[^ ]/-m'a
|
||||
/^2621|/;.,/^[^ ]/-m'a
|
||||
/^h29|/;.,/^[^ ]/-m'a
|
||||
/^h19|/;.,/^[^ ]/-m'a
|
||||
/^h19-u|/;.,/^[^ ]/-m'a
|
||||
/^h19-us|/;.,/^[^ ]/-m'a
|
||||
/^h19-e|/;.,/^[^ ]/-m'a
|
||||
/^h19-g|/;.,/^[^ ]/-m'a
|
||||
/^dmd|/;.,/^[^ ]/-m'a
|
||||
/^s/;.,/^#/-m'a
|
||||
'ad
|
||||
w! termcap
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)termcap.5 6.9 (Berkeley) 5/10/91
|
||||
.\" @(#)termcap.5 6.11 (Berkeley) 3/6/93
|
||||
.\"
|
||||
.Dd May 10, 1991
|
||||
.Dd March 6, 1993
|
||||
.Dt TERMCAP 5
|
||||
.Os BSD 3
|
||||
.Sh NAME
|
||||
|
@ -63,16 +63,12 @@ Entries in
|
|||
consist of a number of `:'-separated fields.
|
||||
The first entry for each terminal gives the names that are known for the
|
||||
terminal, separated by `|' characters.
|
||||
The first name is always two characters
|
||||
long and is used by older systems which store the terminal type
|
||||
in a 16-bit word in a system-wide data base.
|
||||
The second name given is the most common abbreviation for the terminal,
|
||||
the last name given should be a long name fully identifying the terminal,
|
||||
The first name given is the most common abbreviation for the terminal.
|
||||
The last name given should be a long name fully identifying the terminal,
|
||||
and all others are understood as synonyms for the terminal name.
|
||||
All names but the first and last
|
||||
should be in lower case and contain no blanks;
|
||||
the last name may well contain
|
||||
upper case and blanks for readability.
|
||||
All names but the last should be in lower case and contain no blanks;
|
||||
the last name may well contain upper case characters and blanks for
|
||||
readability.
|
||||
.Pp
|
||||
Terminal names (except for the last, verbose entry)
|
||||
should be chosen using the following conventions.
|
||||
|
@ -1796,12 +1792,16 @@ hence does not turn on the function key labels when in visual mode.
|
|||
This is useful for different modes for a terminal, or for different
|
||||
user preferences.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /usr/share/misc/termcap -compact
|
||||
.Bl -tag -width /usr/share/misc/termcap.db -compact
|
||||
.It Pa /usr/share/misc/termcap
|
||||
File containing terminal descriptions.
|
||||
.It Pa /usr/share/misc/termcap.db
|
||||
Hash database file containing terminal descriptions (see
|
||||
.Xr cap_mkdb 1 ) .
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr \&ex 1 ,
|
||||
.Xr cap_mkdb 1 ,
|
||||
.Xr more 1 ,
|
||||
.Xr tset 1 ,
|
||||
.Xr \&ul 1 ,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,5 @@
|
|||
# @(#)Makefile 5.1 (Berkeley) 9/2/92
|
||||
|
||||
PROG= cap_mkdb
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,101 @@
|
|||
.\" Copyright (c) 1992 The Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)cap_mkdb.1 5.4 (Berkeley) 3/6/93
|
||||
.\"
|
||||
.Dd "March 6, 1993"
|
||||
.Dt CAP_MKDB 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm cap_mkdb
|
||||
.Nd create capability database
|
||||
.Pp
|
||||
.Sh SYNOPSIS
|
||||
.Nm cap_mkdb
|
||||
.Op Fl v
|
||||
.Op Fl f Ar outfile
|
||||
.Ar file1
|
||||
.Op Ar file2 ...
|
||||
.Pp
|
||||
.Sh DESCRIPTION
|
||||
.Nm Cap_mkdb
|
||||
builds a hashed database out of the
|
||||
.Xr getcap 3
|
||||
logical database constructed by the concatenation of the specified
|
||||
files .
|
||||
.Pp
|
||||
The database is named by the basename of the first file argument and
|
||||
the string
|
||||
.Dq .db .
|
||||
The
|
||||
.Xr getcap 3
|
||||
routines can access the database in this form much more quickly
|
||||
than they can the original text file(s).
|
||||
.Pp
|
||||
The ``tc'' capabilities of the records are expanded before the
|
||||
record is stored into the database.
|
||||
.Pp
|
||||
The options as as follows:
|
||||
.Bl -tag -width XXXXXX -indent
|
||||
.It Fl f Ar outfile
|
||||
Specify a different database basename.
|
||||
.It Fl v
|
||||
Print out the number of capability records in the database.
|
||||
.El
|
||||
.Pp
|
||||
.Sh FORMAT
|
||||
Each record is stored in the database using two different types of keys.
|
||||
.Pp
|
||||
The first type is a key which consists of the first capability of
|
||||
the record (not including the trailing colon (``:'')) with a data
|
||||
field consisting of a special byte followed by the rest of the record.
|
||||
The special byte is either a 0 or 1, where a 0 means that the record
|
||||
is okay, and a 1 means that there was a ``tc'' capability in the record
|
||||
that couldn't be expanded.
|
||||
.Pp
|
||||
The second type is a key which consists of one of the names from the
|
||||
first capability of the record with a data field consisting a special
|
||||
byte followed by the the first capability of the record.
|
||||
The special byte is a 2.
|
||||
.Pp
|
||||
In normal operation names are looked up in the database, resulting
|
||||
in a key/data pair of the second type.
|
||||
The data field of this key/data pair is used to look up a key/data
|
||||
pair of the first type which has the real data associated with the
|
||||
name.
|
||||
.Sh RETURN VALUE
|
||||
The
|
||||
.Nm cap_mkdb
|
||||
utility exits 0 on success and >0 if an error occurs.
|
||||
.Sh SEE ALSO
|
||||
.Xr dbopen 3 ,
|
||||
.Xr getcap 3 ,
|
||||
.Xr termcap 5
|
|
@ -0,0 +1,250 @@
|
|||
/*-
|
||||
* Copyright (c) 1992 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1992 The Regents of the University of California.\n\
|
||||
All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)cap_mkdb.c 5.6 (Berkeley) 3/8/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <db.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void db_build __P((char **));
|
||||
void dounlink __P((void));
|
||||
void usage __P((void));
|
||||
|
||||
DB *capdbp;
|
||||
int verbose;
|
||||
char *capdb, *capname, buf[8 * 1024];
|
||||
|
||||
/*
|
||||
* Mkcapdb creates a capability hash database for quick retrieval of capability
|
||||
* records. The database contains 2 types of entries: records and references
|
||||
* marked by the first byte in the data. A record entry contains the actual
|
||||
* capability record whereas a reference contains the name (key) under which
|
||||
* the correct record is stored.
|
||||
*/
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int c;
|
||||
|
||||
capname = NULL;
|
||||
while ((c = getopt(argc, argv, "f:v")) != EOF) {
|
||||
switch(c) {
|
||||
case 'f':
|
||||
capname = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (*argv == NULL)
|
||||
usage();
|
||||
|
||||
/*
|
||||
* The database file is the first argument if no name is specified.
|
||||
* Make arrangements to unlink it if exit badly.
|
||||
*/
|
||||
(void)snprintf(buf, sizeof(buf), "%s.db", capname ? capname : *argv);
|
||||
if ((capname = strdup(buf)) == NULL)
|
||||
err(1, "");
|
||||
if ((capdbp = dbopen(capname,
|
||||
O_CREAT | O_TRUNC | O_RDWR, DEFFILEMODE, DB_HASH, NULL)) == NULL)
|
||||
err(1, "%s", buf);
|
||||
|
||||
if (atexit(dounlink))
|
||||
err(1, "atexit");
|
||||
|
||||
db_build(argv);
|
||||
|
||||
if (capdbp->close(capdbp) < 0)
|
||||
err(1, "%s", capname);
|
||||
capname = NULL;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
dounlink()
|
||||
{
|
||||
if (capname != NULL)
|
||||
(void)unlink(capname);
|
||||
}
|
||||
|
||||
/*
|
||||
* Any changes to these definitions should be made also in the getcap(3)
|
||||
* library routines.
|
||||
*/
|
||||
#define RECOK (char)0
|
||||
#define TCERR (char)1
|
||||
#define SHADOW (char)2
|
||||
|
||||
/*
|
||||
* Db_build() builds the name and capabilty databases according to the
|
||||
* details above.
|
||||
*/
|
||||
void
|
||||
db_build(ifiles)
|
||||
char **ifiles;
|
||||
{
|
||||
DBT key, data;
|
||||
recno_t reccnt;
|
||||
size_t len, bplen;
|
||||
int st;
|
||||
char *bp, *p, *t;
|
||||
|
||||
data.data = NULL;
|
||||
key.data = NULL;
|
||||
for (reccnt = 0, bplen = 0; (st = cgetnext(&bp, ifiles)) > 0;) {
|
||||
|
||||
/*
|
||||
* Allocate enough memory to store record, terminating
|
||||
* NULL and one extra byte.
|
||||
*/
|
||||
len = strlen(bp);
|
||||
if (bplen <= len + 2) {
|
||||
bplen += MAX(256, len + 2);
|
||||
if ((data.data = realloc(data.data, bplen)) == NULL)
|
||||
err(1, "");
|
||||
}
|
||||
|
||||
/* Find the end of the name field. */
|
||||
if ((p = strchr(bp, ':')) == NULL) {
|
||||
warnx("no name field: %.*s", MIN(len, 20), bp);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* First byte of stored record indicates status. */
|
||||
switch(st) {
|
||||
case 1:
|
||||
((char *)(data.data))[0] = RECOK;
|
||||
break;
|
||||
case 2:
|
||||
((char *)(data.data))[0] = TCERR;
|
||||
warnx("Record not tc expanded: %.*s", p - bp, bp);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Create the stored record. */
|
||||
memmove(&((u_char *)(data.data))[1], bp, len + 1);
|
||||
data.size = len + 2;
|
||||
|
||||
/* Store the record under the name field. */
|
||||
key.data = bp;
|
||||
key.size = p - bp;
|
||||
|
||||
switch(capdbp->put(capdbp, &key, &data, R_NOOVERWRITE)) {
|
||||
case -1:
|
||||
err(1, "put");
|
||||
/* NOTREACHED */
|
||||
case 1:
|
||||
warnx("ignored duplicate: %.*s",
|
||||
key.size, (char *)key.data);
|
||||
continue;
|
||||
}
|
||||
++reccnt;
|
||||
|
||||
/* If only one name, ignore the rest. */
|
||||
if ((p = strchr(bp, '|')) == NULL)
|
||||
continue;
|
||||
|
||||
/* The rest of the names reference the entire name. */
|
||||
((char *)(data.data))[0] = SHADOW;
|
||||
memmove(&((u_char *)(data.data))[1], key.data, key.size);
|
||||
data.size = key.size + 1;
|
||||
|
||||
/* Store references for other names. */
|
||||
for (p = t = bp;; ++p) {
|
||||
if (p > t && (*p == ':' || *p == '|')) {
|
||||
key.size = p - t;
|
||||
key.data = t;
|
||||
switch(capdbp->put(capdbp,
|
||||
&key, &data, R_NOOVERWRITE)) {
|
||||
case -1:
|
||||
err(1, "put");
|
||||
/* NOTREACHED */
|
||||
case 1:
|
||||
warnx("ignored duplicate: %.*s",
|
||||
key.size, (char *)key.data);
|
||||
}
|
||||
t = p + 1;
|
||||
}
|
||||
if (*p == ':')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(st) {
|
||||
case -1:
|
||||
err(1, "file argument");
|
||||
/* NOTREACHED */
|
||||
case -2:
|
||||
errx(1, "potential reference loop detected");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
(void)printf("cap_mkdb: %d capability records\n", reccnt);
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: cap_mkdb [-v] [-f outfile] file1 [file2 ...]\n");
|
||||
exit(1);
|
||||
}
|
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)set.c 5.2 (Berkeley) 12/24/91";
|
||||
static char sccsid[] = "@(#)set.c 5.3 (Berkeley) 12/1/92";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <termios.h>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)term.c 5.1 (Berkeley) 12/22/91";
|
||||
static char sccsid[] = "@(#)term.c 5.5 (Berkeley) 5/11/92";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -59,7 +59,7 @@ get_termcap_entry(userarg, tcapbufp)
|
|||
{
|
||||
struct ttyent *t;
|
||||
int rval;
|
||||
char *base, *ttype, *ttypath;
|
||||
char *p, *ttype, *ttypath;
|
||||
|
||||
if (userarg) {
|
||||
ttype = userarg;
|
||||
|
@ -72,11 +72,11 @@ get_termcap_entry(userarg, tcapbufp)
|
|||
|
||||
/* Try ttyname(3); check for dialup or other mapping. */
|
||||
if (ttypath = ttyname(STDERR_FILENO)) {
|
||||
if (base = rindex(ttypath, '/'))
|
||||
++base;
|
||||
if (p = rindex(ttypath, '/'))
|
||||
++p;
|
||||
else
|
||||
base = ttypath;
|
||||
if ((t = getttynam(base))) {
|
||||
p = ttypath;
|
||||
if ((t = getttynam(p))) {
|
||||
ttype = t->ty_type;
|
||||
goto map;
|
||||
}
|
||||
|
@ -88,18 +88,22 @@ get_termcap_entry(userarg, tcapbufp)
|
|||
map: ttype = mapped(ttype);
|
||||
|
||||
/*
|
||||
* Remove TERMCAP from the environment so we get a real entry from
|
||||
* /etc/termcap. This prevents us from being fooled by out of date
|
||||
* stuff in the environment.
|
||||
* If not a path, remove TERMCAP from the environment so we get a
|
||||
* real entry from /etc/termcap. This prevents us from being fooled
|
||||
* by out of date stuff in the environment.
|
||||
*/
|
||||
found: unsetenv("TERMCAP");
|
||||
found: if ((p = getenv("TERMCAP")) != NULL && *p != '/')
|
||||
unsetenv("TERMCAP");
|
||||
|
||||
/*
|
||||
* ttype now contains a pointer to the type of the terminal.
|
||||
* If the first character is '?', ask the user.
|
||||
*/
|
||||
if (ttype[0] == '?')
|
||||
ttype = askuser(ttype + 1);
|
||||
if (ttype[1] != '\0')
|
||||
ttype = askuser(ttype + 1);
|
||||
else
|
||||
ttype = askuser(NULL);
|
||||
|
||||
/* Find the termcap entry. If it doesn't exist, ask the user. */
|
||||
while ((rval = tgetent(tbuf, ttype)) == 0) {
|
||||
|
@ -121,6 +125,11 @@ askuser(dflt)
|
|||
static char answer[256];
|
||||
char *p;
|
||||
|
||||
/* We can get recalled; if so, don't continue uselessly. */
|
||||
if (feof(stdin) || ferror(stdin)) {
|
||||
(void)fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
for (;;) {
|
||||
if (dflt)
|
||||
(void)fprintf(stderr, "Terminal type? [%s] ", dflt);
|
||||
|
@ -129,17 +138,18 @@ askuser(dflt)
|
|||
(void)fflush(stderr);
|
||||
|
||||
if (fgets(answer, sizeof(answer), stdin) == NULL) {
|
||||
if (feof(stdin))
|
||||
clearerr(stdin);
|
||||
continue;
|
||||
if (dflt == NULL) {
|
||||
(void)fprintf(stderr, "\n");
|
||||
exit(1);
|
||||
}
|
||||
return (dflt);
|
||||
}
|
||||
|
||||
if (p = index(answer, '\n'))
|
||||
*p = '\0';
|
||||
|
||||
if (!answer[0] && !dflt)
|
||||
continue;
|
||||
|
||||
return (answer[0] ? answer : dflt);
|
||||
if (answer[0])
|
||||
return (answer);
|
||||
if (dflt != NULL)
|
||||
return (dflt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)tset.1 6.10 (Berkeley) 12/24/91
|
||||
.\" @(#)tset.1 6.11 (Berkeley) 12/28/91
|
||||
.\"
|
||||
.Dd December 24, 1991
|
||||
.Dd December 28, 1991
|
||||
.Dt TSET 1
|
||||
.Os BSD 4
|
||||
.Sh NAME
|
||||
|
@ -39,7 +39,7 @@
|
|||
.Nd terminal initialization
|
||||
.Sh SYNOPSIS
|
||||
.Nm tset
|
||||
.Op Fl IQrs
|
||||
.Op Fl IQrSs
|
||||
.Op Fl
|
||||
.Op Fl e Ar ch
|
||||
.Op Fl i Ar ch
|
||||
|
@ -48,7 +48,7 @@
|
|||
.Op Ar terminal
|
||||
.br
|
||||
.Nm reset
|
||||
.Op Fl IQrs
|
||||
.Op Fl IQrSs
|
||||
.Op Fl
|
||||
.Op Fl e Ar ch
|
||||
.Op Fl i Ar ch
|
||||
|
@ -130,16 +130,20 @@ Set the line kill character to
|
|||
.It Fl m
|
||||
Specify a mapping from a port type to a terminal.
|
||||
See below for more information.
|
||||
.It Fl Q
|
||||
Don't display any values for the erase, interrupt and line kill characters.
|
||||
.It Fl r
|
||||
Print the terminal type to the standard error output.
|
||||
.It Fl S
|
||||
Print the terminal type and the termcap entry to the standard output.
|
||||
See the section below on setting the environment for details.
|
||||
.It Fl s
|
||||
Print the sequence of shell commands to initialize the environment variables
|
||||
.Ev TERM
|
||||
and
|
||||
.Ev TERMCAP
|
||||
to the standard output.
|
||||
.It Fl Q
|
||||
Don't display any values for the erase, interrupt and line kill characters.
|
||||
See the section below on setting the environment for details.
|
||||
.El
|
||||
.Pp
|
||||
The arguments for the
|
||||
|
@ -154,22 +158,40 @@ notation, i.e. control-h may be specified as
|
|||
or
|
||||
.Dq Li ^h .
|
||||
.Sh SETTING THE ENVIRONMENT
|
||||
It is often desirable to set the terminal type and information about the
|
||||
terminal's capabilities in the shell's environment.
|
||||
This is done with the
|
||||
It is often desirable to enter the terminal type and information about
|
||||
the terminal's capabilities into the shell's environment.
|
||||
This is done using the
|
||||
.Fl S
|
||||
and
|
||||
.Fl s
|
||||
option; when this option is specified, the commands to enter the information
|
||||
into the shell's environment are output to the standard output.
|
||||
options.
|
||||
.Pp
|
||||
When the
|
||||
.Fl S
|
||||
option is specified, the terminal type and the termcap entry are written
|
||||
to the standard output, separated by a space and without a terminating
|
||||
newline.
|
||||
This can be assigned to an array by
|
||||
.Nm csh
|
||||
and
|
||||
.Nm ksh
|
||||
users and then used like any other shell array.
|
||||
.Pp
|
||||
When the
|
||||
.Fl s
|
||||
option is specified, the commands to enter the information into the
|
||||
shell's environment are written to the standard output.
|
||||
If the
|
||||
.Ev SHELL
|
||||
environmental variable ends in ``csh'', the output commands are for the
|
||||
.Xr csh 1 ,
|
||||
environmental variable ends in ``csh'', the commands are for the
|
||||
.Nm csh ,
|
||||
otherwise, they are for
|
||||
.Xr sh 1 .
|
||||
Note, the output commands for the
|
||||
.Xr sh .
|
||||
Note, the
|
||||
.Nm csh
|
||||
set and unset the shell variable
|
||||
.Dq noglob .
|
||||
commands set and unset the shell variable
|
||||
.Dq noglob ,
|
||||
leaving it unset.
|
||||
The following line in the
|
||||
.Pa .login
|
||||
or
|
||||
|
@ -178,6 +200,20 @@ files will initialize the environment correctly:
|
|||
.Bd -literal -offset indent
|
||||
eval \`tset -s options ... \`
|
||||
.Ed
|
||||
.Pp
|
||||
To demonstrate a simple use of the
|
||||
.Fl S
|
||||
option, the following lines in the
|
||||
.Pa .login
|
||||
file have an equivalent effect:
|
||||
.Bd -literal -offset indent
|
||||
set noglob
|
||||
set term=(`tset -S options ...`)
|
||||
setenv TERM $term[1]
|
||||
setenv TERMCAP "$term[2]"
|
||||
unset term
|
||||
unset noglob
|
||||
.Ed
|
||||
.Sh TERMINAL TYPE MAPPING
|
||||
When the terminal is not hardwired into the system (or the current system
|
||||
information is incorrect) the terminal type derived from the
|
||||
|
@ -244,7 +280,7 @@ If the port type and baud rate match the mapping, the terminal type specified
|
|||
in the mapping replaces the current type.
|
||||
If more than one mapping is specified, the first applicable mapping is used.
|
||||
.Pp
|
||||
For example, consider the following:
|
||||
For example, consider the following mapping:
|
||||
.Dq Li dialup>9600:vt100 .
|
||||
The port type is
|
||||
.Dq Li dialup ,
|
||||
|
@ -315,7 +351,6 @@ The
|
|||
.Fl A ,
|
||||
.Fl E ,
|
||||
.Fl h ,
|
||||
.Fl S ,
|
||||
.Fl u
|
||||
and
|
||||
.Fl v
|
||||
|
|
|
@ -38,10 +38,11 @@ char copyright[] =
|
|||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
static char sccsid[] = "@(#)tset.c 5.19 (Berkeley) 12/24/91";
|
||||
static char sccsid[] = "@(#)tset.c 5.22 (Berkeley) 2/11/93";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
@ -57,16 +58,10 @@ void usage __P((void));
|
|||
|
||||
struct termios mode, oldmode;
|
||||
|
||||
int dosetenv; /* output TERMCAP strings */
|
||||
int erasechar; /* new erase character */
|
||||
int intrchar; /* new interrupt character */
|
||||
int isreset; /* invoked as reset */
|
||||
int killchar; /* new kill character */
|
||||
int noinit; /* don't output initialization string */
|
||||
int noset; /* only report term type */
|
||||
int quiet; /* don't display ctrl key settings */
|
||||
int showterm; /* display term on stderr */
|
||||
|
||||
int lines, columns; /* window size */
|
||||
|
||||
int
|
||||
|
@ -77,7 +72,7 @@ main(argc, argv)
|
|||
#ifdef TIOCGWINSZ
|
||||
struct winsize win;
|
||||
#endif
|
||||
int ch, csh, usingupper;
|
||||
int ch, noinit, noset, quiet, Sflag, sflag, showterm, usingupper;
|
||||
char savech, *p, *t, *tcapbuf, *ttype;
|
||||
|
||||
if (tcgetattr(STDERR_FILENO, &mode) < 0)
|
||||
|
@ -97,9 +92,10 @@ main(argc, argv)
|
|||
}
|
||||
|
||||
obsolete(argv);
|
||||
while ((ch = getopt(argc, argv, "-a:d:e:Ii:k:m:np:Qrs")) != EOF) {
|
||||
noinit = noset = quiet = Sflag = sflag = showterm = 0;
|
||||
while ((ch = getopt(argc, argv, "-a:d:e:Ii:k:m:np:QSrs")) != EOF) {
|
||||
switch (ch) {
|
||||
case '-': /* OBSOLETE: display term only */
|
||||
case '-': /* display term only */
|
||||
noset = 1;
|
||||
break;
|
||||
case 'a': /* OBSOLETE: map identifier to type */
|
||||
|
@ -113,7 +109,7 @@ main(argc, argv)
|
|||
optarg[1] == '?' ? '\177' : CTRL(optarg[1]) :
|
||||
optarg[0];
|
||||
break;
|
||||
case 'I': /* no initialization */
|
||||
case 'I': /* no initialization strings */
|
||||
noinit = 1;
|
||||
break;
|
||||
case 'i': /* interrupt character */
|
||||
|
@ -134,14 +130,17 @@ main(argc, argv)
|
|||
case 'p': /* OBSOLETE: map identifier to type */
|
||||
add_mapping("plugboard", optarg);
|
||||
break;
|
||||
case 'Q': /* be quiet */
|
||||
case 'Q': /* don't output control key settings */
|
||||
quiet = 1;
|
||||
break;
|
||||
case 'S': /* output TERM/TERMCAP strings */
|
||||
Sflag = 1;
|
||||
break;
|
||||
case 'r': /* display term on stderr */
|
||||
showterm = 1;
|
||||
break;
|
||||
case 's': /* print commands to set environment */
|
||||
dosetenv = 1;
|
||||
case 's': /* output TERM/TERMCAP strings */
|
||||
sflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
|
@ -181,15 +180,10 @@ main(argc, argv)
|
|||
tcsetattr(STDERR_FILENO, TCSADRAIN, &mode);
|
||||
}
|
||||
|
||||
/*
|
||||
* The termcap file generally has a two-character name first in each
|
||||
* entry followed by more descriptive names. If we ended up with the
|
||||
* first one, we switch to the second one for setting or reporting
|
||||
* information.
|
||||
*/
|
||||
p = strpbrk(tcapbuf, "|:");
|
||||
if (p && *p != ':' && !strncmp(ttype, tcapbuf, p - tcapbuf)) {
|
||||
t = ++p;
|
||||
/* Get the terminal name from the entry. */
|
||||
p = tcapbuf;
|
||||
if (p != NULL && *p != ':') {
|
||||
t = p;
|
||||
if (p = strpbrk(p, "|:")) {
|
||||
savech = *p;
|
||||
*p = '\0';
|
||||
|
@ -215,24 +209,29 @@ main(argc, argv)
|
|||
}
|
||||
}
|
||||
|
||||
if (!dosetenv)
|
||||
exit(0);
|
||||
if (Sflag) {
|
||||
(void)printf("%s ", ttype);
|
||||
wrtermcap(tcapbuf);
|
||||
}
|
||||
|
||||
if (sflag) {
|
||||
/*
|
||||
* Figure out what shell we're using. A hack, we look for an
|
||||
* environmental variable SHELL ending in "csh".
|
||||
*/
|
||||
if ((p = getenv("SHELL")) &&
|
||||
!strcmp(p + strlen(p) - 3, "csh")) {
|
||||
p = "set noglob;\nsetenv TERM %s;\nsetenv TERMCAP '";
|
||||
t = "';\nunset noglob;\n";
|
||||
} else {
|
||||
p = "TERM=%s;\nTERMCAP='";
|
||||
t = "';\nexport TERMCAP TERM;\n";
|
||||
}
|
||||
(void)printf(p, ttype);
|
||||
wrtermcap(tcapbuf);
|
||||
(void)printf(t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Figure out what shell we're using. A hack, we look for a $SHELL
|
||||
* ending in "csh".
|
||||
*/
|
||||
csh = (p = getenv("SHELL")) && !strcmp(p + strlen(p) - 3, "csh");
|
||||
if (csh)
|
||||
(void)printf("set noglob;\nsetenv TERM %s;\nsetenv TERMCAP '",
|
||||
ttype);
|
||||
else
|
||||
(void)printf("TERM=%s;\nTERMCAP='", ttype);
|
||||
wrtermcap(tcapbuf);
|
||||
if (csh)
|
||||
(void)printf("';\nunset noglob;\n");
|
||||
else
|
||||
(void)printf("';\nexport TERMCAP TERM;\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -299,6 +298,6 @@ void
|
|||
usage()
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: tset [-IQrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n");
|
||||
"usage: tset [-IQrSs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue