Import Lite2's src/lib, except for non-i386 machine-dependent directories,
libc/db, libc/gen/crypt.* and libtelnet. All affected files except 3 unimportant ones have already left the vendor branch.
This commit is contained in:
parent
25e43cba72
commit
5500fdcd4f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/vendor/CSRG/dist/; revision=27180
25
lib/csu/i386/Makefile
Normal file
25
lib/csu/i386/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/1/93
|
||||
|
||||
CFLAGS= -O -DLIBC_SCCS
|
||||
OBJS= crt0.o gcrt0.o
|
||||
CLEANFILES+= core a.out
|
||||
|
||||
all: ${OBJS}
|
||||
|
||||
crt0.o: crt0.c
|
||||
${CC} ${CFLAGS} -c -DCRT0 ${.ALLSRC}
|
||||
${LD} -x -r ${.TARGET}
|
||||
mv a.out ${.TARGET}
|
||||
|
||||
gcrt0.o: crt0.c
|
||||
${CC} ${CFLAGS} -c -DMCRT0 ${.ALLSRC} -o ${.TARGET}
|
||||
${LD} -x -r ${.TARGET}
|
||||
mv a.out ${.TARGET}
|
||||
|
||||
install:
|
||||
install -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
|
||||
${DESTDIR}/usr/lib
|
||||
|
||||
depend lint tags:
|
||||
|
||||
.include <bsd.prog.mk>
|
130
lib/csu/i386/crt0.c
Normal file
130
lib/csu/i386/crt0.c
Normal file
@ -0,0 +1,130 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* 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 sccsid[] = "@(#)crt0.c 8.1 (Berkeley) 6/1/93";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* C start up routine.
|
||||
* Robert Henry, UCB, 20 Oct 81
|
||||
*
|
||||
* We make the following (true) assumption:
|
||||
* 1) The only register variable that we can trust is ebp,
|
||||
* which points to the base of the kernel calling frame.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char **environ = (char **)0;
|
||||
static char empty[1];
|
||||
char *__progname = empty;
|
||||
static int fd;
|
||||
|
||||
asm(".text");
|
||||
asm(".long 0xc000c000");
|
||||
|
||||
extern unsigned char etext;
|
||||
extern unsigned char eprol asm ("eprol");
|
||||
extern start() asm("start");
|
||||
|
||||
start()
|
||||
{
|
||||
struct kframe {
|
||||
int kargc;
|
||||
char *kargv[1]; /* size depends on kargc */
|
||||
char kargstr[1]; /* size varies */
|
||||
char kenvstr[1]; /* size varies */
|
||||
};
|
||||
/*
|
||||
* ALL REGISTER VARIABLES!!!
|
||||
*/
|
||||
register struct kframe *kfp; /* r10 */
|
||||
register char **targv;
|
||||
register char **argv;
|
||||
extern int errno;
|
||||
extern void _mcleanup();
|
||||
|
||||
#ifdef lint
|
||||
kfp = 0;
|
||||
initcode = initcode = 0;
|
||||
#else
|
||||
asm("lea 4(%ebp),%ebx"); /* catch it quick */
|
||||
#endif
|
||||
for (argv = targv = &kfp->kargv[0]; *targv++; /* void */)
|
||||
/* void */ ;
|
||||
if (targv >= (char **)(*argv))
|
||||
--targv;
|
||||
environ = targv;
|
||||
asm("eprol:");
|
||||
|
||||
#ifdef paranoid
|
||||
/*
|
||||
* The standard I/O library assumes that file descriptors 0, 1, and 2
|
||||
* are open. If one of these descriptors is closed prior to the start
|
||||
* of the process, I/O gets very confused. To avoid this problem, we
|
||||
* insure that the first three file descriptors are open before calling
|
||||
* main(). Normally this is undefined, as it adds two unnecessary
|
||||
* system calls.
|
||||
*/
|
||||
do {
|
||||
fd = open("/dev/null", 2);
|
||||
} while (fd >= 0 && fd < 3);
|
||||
close(fd);
|
||||
#endif
|
||||
|
||||
#ifdef MCRT0
|
||||
atexit(_mcleanup);
|
||||
monstartup(&eprol, &etext);
|
||||
#endif
|
||||
errno = 0;
|
||||
if (argv[0])
|
||||
if ((__progname = strrchr(argv[0], '/')) == NULL)
|
||||
__progname = argv[0];
|
||||
else
|
||||
++__progname;
|
||||
exit(main(kfp->kargc, argv, environ));
|
||||
}
|
||||
|
||||
#ifdef CRT0
|
||||
/*
|
||||
* null moncontrol just in case some routine is compiled for profiling
|
||||
*/
|
||||
moncontrol(val)
|
||||
int val;
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
93
lib/libc/compat-43/setregid.2
Normal file
93
lib/libc/compat-43/setregid.2
Normal file
@ -0,0 +1,93 @@
|
||||
.\" Copyright (c) 1980, 1991, 1993, 1994
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)setregid.2 8.2 (Berkeley) 4/16/94
|
||||
.\"
|
||||
.Dd April 16, 1994
|
||||
.Dt SETREGID 2
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
.Nm setregid
|
||||
.Nd set real and effective group ID
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <unistd.h>
|
||||
.Ft int
|
||||
.Fn setregid "gid_t rgid" "gid_t egid"
|
||||
.Sh DESCRIPTION
|
||||
The real and effective group ID's of the current process
|
||||
are set to the arguments.
|
||||
Unprivileged users may change the real group
|
||||
ID to the effective group ID and vice-versa; only the super-user may
|
||||
make other changes.
|
||||
.Pp
|
||||
Supplying a value of -1 for either the real or effective
|
||||
group ID forces the system to substitute the current
|
||||
ID in place of the -1 parameter.
|
||||
.Pp
|
||||
The
|
||||
.Fn setregid
|
||||
function was intended to allow swapping
|
||||
the real and effective group IDs
|
||||
in set-group-ID programs to temporarily relinquish the set-group-ID value.
|
||||
This function did not work correctly,
|
||||
and its purpose is now better served by the use of the
|
||||
.Fn setegid
|
||||
function (see
|
||||
.Xr setuid 2 ) .
|
||||
.Pp
|
||||
When setting the real and effective group IDs to the same value,
|
||||
the standard
|
||||
.Fn setgid
|
||||
function is preferred.
|
||||
.Sh RETURN VALUES
|
||||
Upon successful completion, a value of 0 is returned. Otherwise,
|
||||
a value of -1 is returned and
|
||||
.Va errno
|
||||
is set to indicate the error.
|
||||
.Sh ERRORS
|
||||
.Bl -tag -width [EPERM]
|
||||
.It Bq Er EPERM
|
||||
The current process is not the super-user and a change
|
||||
other than changing the effective group-id to the real group-id
|
||||
was specified.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr getgid 2 ,
|
||||
.Xr setegid 2 ,
|
||||
.Xr setgid 2 ,
|
||||
.Xr setuid 2
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
function call appeared in
|
||||
.Bx 4.2
|
||||
and was dropped in
|
||||
.Bx 4.4 .
|
62
lib/libc/compat-43/setregid.c
Normal file
62
lib/libc/compat-43/setregid.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)setregid.c 8.1 (Berkeley) 6/2/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
setregid(rgid, egid)
|
||||
gid_t rgid, egid;
|
||||
{
|
||||
static gid_t savedgid = -1;
|
||||
|
||||
if (savedgid == -1)
|
||||
savedgid = getegid();
|
||||
/*
|
||||
* we assume that the intent here is to be able to
|
||||
* get back rgid priviledge. So we make sure that
|
||||
* we will be able to do so, but do not actually
|
||||
* set the rgid.
|
||||
*/
|
||||
if (rgid != -1 && rgid != getgid() && rgid != savedgid) {
|
||||
errno = EPERM;
|
||||
return (-1);
|
||||
}
|
||||
if (egid != -1 && setegid(egid) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
91
lib/libc/compat-43/setreuid.2
Normal file
91
lib/libc/compat-43/setreuid.2
Normal file
@ -0,0 +1,91 @@
|
||||
.\" Copyright (c) 1980, 1991, 1993, 1994
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)setreuid.2 8.2 (Berkeley) 4/16/94
|
||||
.\"
|
||||
.Dd April 16, 1994
|
||||
.Dt SETREUID 2
|
||||
.Os BSD 4
|
||||
.Sh NAME
|
||||
.Nm setreuid
|
||||
.Nd set real and effective user ID's
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <unistd.h>
|
||||
.Ft int
|
||||
.Fn setreuid "uid_t ruid" "uid_t euid"
|
||||
.Sh DESCRIPTION
|
||||
The real and effective user IDs of the
|
||||
current process are set according to the arguments.
|
||||
If
|
||||
.Fa ruid
|
||||
or
|
||||
.Fa euid
|
||||
is -1, the current uid is filled in by the system.
|
||||
Unprivileged users may change the real user
|
||||
ID to the effective user ID and vice-versa; only the super-user may
|
||||
make other changes.
|
||||
.Pp
|
||||
The
|
||||
.Fn setreuid
|
||||
function has been used to swap the real and effective user IDs
|
||||
in set-user-ID programs to temporarily relinquish the set-user-ID value.
|
||||
This purpose is now better served by the use of the
|
||||
.Fn seteuid
|
||||
function (see
|
||||
.Xr setuid 2 ) .
|
||||
.Pp
|
||||
When setting the real and effective user IDs to the same value,
|
||||
the standard
|
||||
.Fn setuid
|
||||
function is preferred.
|
||||
.Sh RETURN VALUES
|
||||
Upon successful completion, a value of 0 is returned. Otherwise,
|
||||
a value of -1 is returned and
|
||||
.Va errno
|
||||
is set to indicate the error.
|
||||
.Sh ERRORS
|
||||
.Bl -tag -width [EPERM]
|
||||
.It Bq Er EPERM
|
||||
The current process is not the super-user and a change
|
||||
other than changing the effective user-id to the real user-id
|
||||
was specified.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr getuid 2 ,
|
||||
.Xr seteuid 2 ,
|
||||
.Xr setuid 2
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
function call appeared in
|
||||
.Bx 4.2
|
||||
and was dropped in
|
||||
.Bx 4.4 .
|
62
lib/libc/compat-43/setreuid.c
Normal file
62
lib/libc/compat-43/setreuid.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)setreuid.c 8.1 (Berkeley) 6/2/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
setreuid(ruid, euid)
|
||||
uid_t ruid, euid;
|
||||
{
|
||||
static uid_t saveduid = -1;
|
||||
|
||||
if (saveduid == -1)
|
||||
saveduid = geteuid();
|
||||
/*
|
||||
* we assume that the intent here is to be able to
|
||||
* get back ruid priviledge. So we make sure that
|
||||
* we will be able to do so, but do not actually
|
||||
* set the ruid.
|
||||
*/
|
||||
if (ruid != -1 && ruid != getuid() && ruid != saveduid) {
|
||||
errno = EPERM;
|
||||
return (-1);
|
||||
}
|
||||
if (euid != -1 && seteuid(euid) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
258
lib/libc/gen/ctime.3
Normal file
258
lib/libc/gen/ctime.3
Normal file
@ -0,0 +1,258 @@
|
||||
.\" Copyright (c) 1989, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Arthur Olson.
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)ctime.3 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt CTIME 3
|
||||
.Os BSD 4.3
|
||||
.Sh NAME
|
||||
.Nm asctime ,
|
||||
.Nm ctime ,
|
||||
.Nm difftime ,
|
||||
.Nm gmtime ,
|
||||
.Nm localtime ,
|
||||
.Nm mktime
|
||||
.Nd transform binary date and time value to
|
||||
.Tn ASCII
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/types.h>
|
||||
.Fd #include <time.h>
|
||||
.Vt extern char *tzname[2];
|
||||
.Ft char *
|
||||
.Fn ctime "const time_t *clock"
|
||||
.Ft double
|
||||
.Fn difftime "time_t time1" "time_t time0"
|
||||
.Ft char *
|
||||
.Fn asctime "const struct tm *tm"
|
||||
.Ft struct tm *
|
||||
.Fn localtime "const time_t *clock"
|
||||
.Ft struct tm *
|
||||
.Fn gmtime "const time_t *clock"
|
||||
.Ft time_t
|
||||
.Fn mktime "struct tm *tm"
|
||||
.Sh DESCRIPTION
|
||||
The functions
|
||||
.Fn ctime ,
|
||||
.Fn gmtime
|
||||
and
|
||||
.Fn localtime
|
||||
all take as an argument a time value representing the time in seconds since
|
||||
the Epoch (00:00:00
|
||||
.Tn UTC ,
|
||||
January 1, 1970; see
|
||||
.Xr time 3 ) .
|
||||
.Pp
|
||||
The function
|
||||
.Fn localtime
|
||||
converts the time value pointed at by
|
||||
.Fa clock ,
|
||||
and returns a pointer to a
|
||||
.Dq Fa struct tm
|
||||
(described below) which contains
|
||||
the broken-out time information for the value after adjusting for the current
|
||||
time zone (and any other factors such as Daylight Saving Time).
|
||||
Time zone adjustments are performed as specified by the
|
||||
.Ev TZ
|
||||
environmental variable (see
|
||||
.Xr tzset 3 ) .
|
||||
The function
|
||||
.Fn localtime
|
||||
uses
|
||||
.Xr tzset
|
||||
to initialize time conversion information if
|
||||
.Xr tzset
|
||||
has not already been called by the process.
|
||||
.Pp
|
||||
After filling in the tm structure,
|
||||
.Fn localtime
|
||||
sets the
|
||||
.Fa tm_isdst Ns 'th
|
||||
element of
|
||||
.Fa tzname
|
||||
to a pointer to an
|
||||
.Tn ASCII
|
||||
string that's the time zone abbreviation to be
|
||||
used with
|
||||
.Fn localtime Ns 's
|
||||
return value.
|
||||
.Pp
|
||||
The function
|
||||
.Fn gmtime
|
||||
similarly converts the time value, but without any time zone adjustment,
|
||||
and returns a pointer to a tm structure (described below).
|
||||
.Pp
|
||||
The
|
||||
.Fn ctime
|
||||
function
|
||||
adjusts the time value for the current time zone in the same manner as
|
||||
.Fn localtime ,
|
||||
and returns a pointer to a 26-character string of the form:
|
||||
.Bd -literal -offset indent
|
||||
Thu Nov 24 18:22:48 1986\en\e0
|
||||
.Ed
|
||||
.Pp
|
||||
All the fields have constant width.
|
||||
.Pp
|
||||
The
|
||||
.Fn asctime
|
||||
function
|
||||
converts the broken down time in the structure
|
||||
.Fa tm
|
||||
pointed at by
|
||||
.Fa *tm
|
||||
to the form
|
||||
shown in the example above.
|
||||
.Pp
|
||||
The function
|
||||
.Fn mktime
|
||||
converts the broken-down time, expressed as local time, in the structure
|
||||
pointed to by tm into a time value with the same encoding as that of the
|
||||
values returned by the
|
||||
.Xr time 3
|
||||
function, that is, seconds from the Epoch,
|
||||
.Tn UTC .
|
||||
.Pp
|
||||
The original values of the
|
||||
.Fa tm_wday
|
||||
and
|
||||
.Fa tm_yday
|
||||
components of the structure are ignored, and the original values of the
|
||||
other components are not restricted to their normal ranges.
|
||||
(A positive or zero value for
|
||||
.Fa tm_isdst
|
||||
causes
|
||||
.Fn mktime
|
||||
to presume initially that summer time (for example, Daylight Saving Time)
|
||||
is or is not in effect for the specified time, respectively.
|
||||
A negative value for
|
||||
.Fa tm_isdst
|
||||
causes the
|
||||
.Fn mktime
|
||||
function to attempt to divine whether summer time is in effect for the
|
||||
specified time.)
|
||||
.Pp
|
||||
On successful completion, the values of the
|
||||
.Fa tm_wday
|
||||
and
|
||||
.Fa tm_yday
|
||||
components of the structure are set appropriately, and the other components
|
||||
are set to represent the specified calendar time, but with their values
|
||||
forced to their normal ranges; the final value of
|
||||
.Fa tm_mday
|
||||
is not set until
|
||||
.Fa tm_mon
|
||||
and
|
||||
.Fa tm_year
|
||||
are determined.
|
||||
.Fn Mktime
|
||||
returns the specified calendar time; if the calendar time cannot be
|
||||
represented, it returns \-1;
|
||||
.Pp
|
||||
The
|
||||
.Fn difftime
|
||||
function
|
||||
returns the difference between two calendar times,
|
||||
.Pf ( Fa time1
|
||||
-
|
||||
.Fa time0 ) ,
|
||||
expressed in seconds.
|
||||
.Pp
|
||||
External declarations as well as the tm structure definition are in the
|
||||
.Aq Pa time.h
|
||||
include file.
|
||||
The tm structure includes at least the following fields:
|
||||
.Bd -literal -offset indent
|
||||
int tm_sec; /\(** seconds (0 - 60) \(**/
|
||||
int tm_min; /\(** minutes (0 - 59) \(**/
|
||||
int tm_hour; /\(** hours (0 - 23) \(**/
|
||||
int tm_mday; /\(** day of month (1 - 31) \(**/
|
||||
int tm_mon; /\(** month of year (0 - 11) \(**/
|
||||
int tm_year; /\(** year \- 1900 \(**/
|
||||
int tm_wday; /\(** day of week (Sunday = 0) \(**/
|
||||
int tm_yday; /\(** day of year (0 - 365) \(**/
|
||||
int tm_isdst; /\(** is summer time in effect? \(**/
|
||||
char \(**tm_zone; /\(** abbreviation of timezone name \(**/
|
||||
long tm_gmtoff; /\(** offset from UTC in seconds \(**/
|
||||
.Ed
|
||||
.Pp
|
||||
The
|
||||
field
|
||||
.Fa tm_isdst
|
||||
is non-zero if summer time is in effect.
|
||||
.Pp
|
||||
The field
|
||||
.Fa tm_gmtoff
|
||||
is the offset (in seconds) of the time represented from
|
||||
.Tn UTC ,
|
||||
with positive
|
||||
values indicating east of the Prime Meridian.
|
||||
.Sh SEE ALSO
|
||||
.Xr date 1 ,
|
||||
.Xr gettimeofday 2 ,
|
||||
.Xr getenv 3 ,
|
||||
.Xr time 3 ,
|
||||
.Xr tzset 3 ,
|
||||
.Xr tzfile 5
|
||||
.Sh HISTORY
|
||||
This manual page is derived from
|
||||
the time package contributed to Berkeley by
|
||||
Arthur Olsen and which appeared in
|
||||
.Bx 4.3 .
|
||||
.Sh BUGS
|
||||
Except for
|
||||
.Fn difftime
|
||||
and
|
||||
.Fn mktime ,
|
||||
these functions leaves their result in an internal static object and return
|
||||
a pointer to that object. Subsequent calls to these
|
||||
function will modify the same object.
|
||||
.Pp
|
||||
The
|
||||
.Fa tm_zone
|
||||
field of a returned tm structure points to a static array of characters,
|
||||
which will also be overwritten by any subsequent calls (as well as by
|
||||
subsequent calls to
|
||||
.Xr tzset 3
|
||||
and
|
||||
.Xr tzsetwall 3 ) .
|
||||
.Pp
|
||||
Use of the external variable
|
||||
.Fa tzname
|
||||
is discouraged; the
|
||||
.Fa tm_zone
|
||||
entry in the tm structure is preferred.
|
||||
.Pp
|
||||
Avoid using out-of-range values with
|
||||
.Fn mktime
|
||||
when setting up lunch with promptness sticklers in Riyadh.
|
1381
lib/libc/gen/ctime.c
Normal file
1381
lib/libc/gen/ctime.c
Normal file
File diff suppressed because it is too large
Load Diff
45
lib/libc/gen/difftime.c
Normal file
45
lib/libc/gen/difftime.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)difftime.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
double
|
||||
difftime(time1, time0)
|
||||
time_t time1, time0;
|
||||
{
|
||||
return(time1 - time0);
|
||||
}
|
78
lib/libc/i386/gen/_setjmp.s
Normal file
78
lib/libc/i386/gen/_setjmp.s
Normal file
@ -0,0 +1,78 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)_setjmp.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* C library -- _setjmp, _longjmp
|
||||
*
|
||||
* _longjmp(a,v)
|
||||
* will generate a "return(v)" from the last call to
|
||||
* _setjmp(a)
|
||||
* by restoring registers from the stack.
|
||||
* The previous signal state is NOT restored.
|
||||
*/
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(_setjmp)
|
||||
movl 4(%esp),%eax
|
||||
movl 0(%esp),%edx
|
||||
movl %edx, 0(%eax) /* rta */
|
||||
movl %ebx, 4(%eax)
|
||||
movl %esp, 8(%eax)
|
||||
movl %ebp,12(%eax)
|
||||
movl %esi,16(%eax)
|
||||
movl %edi,20(%eax)
|
||||
movl $0,%eax
|
||||
ret
|
||||
|
||||
ENTRY(_longjmp)
|
||||
movl 4(%esp),%edx
|
||||
movl 8(%esp),%eax
|
||||
movl 0(%edx),%ecx
|
||||
movl 4(%edx),%ebx
|
||||
movl 8(%edx),%esp
|
||||
movl 12(%edx),%ebp
|
||||
movl 16(%edx),%esi
|
||||
movl 20(%edx),%edi
|
||||
cmpl $0,%eax
|
||||
jne 1f
|
||||
movl $1,%eax
|
||||
1: movl %ecx,0(%esp)
|
||||
ret
|
57
lib/libc/i386/gen/alloca.s
Normal file
57
lib/libc/i386/gen/alloca.s
Normal file
@ -0,0 +1,57 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)alloca.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* like alloc, but automatic automatic free in return */
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(alloca)
|
||||
popl %edx /* pop return addr */
|
||||
popl %eax /* pop amount to allocate */
|
||||
movl %esp,%ecx
|
||||
addl $3,%eax /* round up to next word */
|
||||
andl $0xfffffffc,%eax
|
||||
subl %eax,%esp
|
||||
movl %esp,%eax /* base of newly allocated space */
|
||||
pushl 8(%ecx) /* copy possible saved registers */
|
||||
pushl 4(%ecx)
|
||||
pushl 0(%ecx)
|
||||
pushl %eax /* dummy to pop at callsite */
|
||||
jmp %edx /* "return" */
|
46
lib/libc/i386/gen/divsi3.s
Normal file
46
lib/libc/i386/gen/divsi3.s
Normal file
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)divsi3.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
.globl ___divsi3
|
||||
___divsi3:
|
||||
movl 4(%esp),%eax
|
||||
cltd
|
||||
idivl 8(%esp)
|
||||
ret
|
46
lib/libc/i386/gen/fabs.s
Normal file
46
lib/libc/i386/gen/fabs.s
Normal file
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)fabs.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(fabs)
|
||||
fldl 4(%esp)
|
||||
fabs
|
||||
ret
|
46
lib/libc/i386/gen/fixdfsi.s
Normal file
46
lib/libc/i386/gen/fixdfsi.s
Normal file
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)fixdfsi.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
.globl ___fixdfsi
|
||||
___fixdfsi:
|
||||
fldl 4(%esp)
|
||||
fistpl 4(%esp)
|
||||
movl 4(%esp),%eax
|
||||
ret
|
60
lib/libc/i386/gen/fixunsdfsi.s
Normal file
60
lib/libc/i386/gen/fixunsdfsi.s
Normal file
@ -0,0 +1,60 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)fixunsdfsi.s 8.1 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
.globl ___fixunsdfsi
|
||||
___fixunsdfsi:
|
||||
fldl 4(%esp) /* argument double to accum stack */
|
||||
frndint /* create integer */
|
||||
fcoml fbiggestsigned /* bigger than biggest signed? */
|
||||
fstsw %ax
|
||||
sahf
|
||||
jnb 1f
|
||||
|
||||
fistpl 4(%esp)
|
||||
movl 4(%esp),%eax
|
||||
ret
|
||||
|
||||
1: fsubl fbiggestsigned /* reduce for proper conversion */
|
||||
fistpl 4(%esp) /* convert */
|
||||
movl 4(%esp),%eax
|
||||
orl $0x80000000,%eax /* restore bias */
|
||||
ret
|
||||
|
||||
fbiggestsigned: .double 0r2147483648.0
|
75
lib/libc/i386/gen/modf.s
Normal file
75
lib/libc/i386/gen/modf.s
Normal file
@ -0,0 +1,75 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Sean Eric Fagan.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)modf.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* modf(value, iptr): return fractional part of value, and stores the
|
||||
* integral part into iptr (a pointer to double).
|
||||
*
|
||||
* Written by Sean Eric Fagan (sef@kithrup.COM)
|
||||
* Sun Mar 11 20:27:30 PST 1990
|
||||
*/
|
||||
|
||||
/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */
|
||||
.text
|
||||
.globl _modf
|
||||
_modf:
|
||||
pushl %ebp
|
||||
movl %esp,%ebp
|
||||
subl $16,%esp
|
||||
fnstcw -12(%ebp)
|
||||
movw -12(%ebp),%dx
|
||||
orw $3072,%dx
|
||||
movw %dx,-16(%ebp)
|
||||
fldcw -16(%ebp)
|
||||
fldl 8(%ebp)
|
||||
frndint
|
||||
fstpl -8(%ebp)
|
||||
fldcw -12(%ebp)
|
||||
movl 16(%ebp),%eax
|
||||
movl -8(%ebp),%edx
|
||||
movl -4(%ebp),%ecx
|
||||
movl %edx,(%eax)
|
||||
movl %ecx,4(%eax)
|
||||
fldl 8(%ebp)
|
||||
fsubl -8(%ebp)
|
||||
jmp L1
|
||||
L1:
|
||||
leave
|
||||
ret
|
86
lib/libc/i386/gen/setjmp.s
Normal file
86
lib/libc/i386/gen/setjmp.s
Normal file
@ -0,0 +1,86 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)setjmp.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* C library -- _setjmp, _longjmp
|
||||
*
|
||||
* longjmp(a,v)
|
||||
* will generate a "return(v)" from the last call to
|
||||
* setjmp(a)
|
||||
* by restoring registers from the stack.
|
||||
* The previous signal state is restored.
|
||||
*/
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(setjmp)
|
||||
pushl $0
|
||||
call _sigblock
|
||||
popl %edx
|
||||
movl 4(%esp),%ecx
|
||||
movl 0(%esp),%edx
|
||||
movl %edx, 0(%ecx)
|
||||
movl %ebx, 4(%ecx)
|
||||
movl %esp, 8(%ecx)
|
||||
movl %ebp,12(%ecx)
|
||||
movl %esi,16(%ecx)
|
||||
movl %edi,20(%ecx)
|
||||
movl %eax,24(%ecx)
|
||||
movl $0,%eax
|
||||
ret
|
||||
|
||||
ENTRY(longjmp)
|
||||
movl 4(%esp),%edx
|
||||
pushl 24(%edx)
|
||||
call _sigsetmask
|
||||
popl %eax
|
||||
movl 4(%esp),%edx
|
||||
movl 8(%esp),%eax
|
||||
movl 0(%edx),%ecx
|
||||
movl 4(%edx),%ebx
|
||||
movl 8(%edx),%esp
|
||||
movl 12(%edx),%ebp
|
||||
movl 16(%edx),%esi
|
||||
movl 20(%edx),%edi
|
||||
cmpl $0,%eax
|
||||
jne 1f
|
||||
movl $1,%eax
|
||||
1: movl %ecx,0(%esp)
|
||||
ret
|
46
lib/libc/i386/gen/udivsi3.s
Normal file
46
lib/libc/i386/gen/udivsi3.s
Normal file
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)udivsi3.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
.globl ___udivsi3
|
||||
___udivsi3:
|
||||
movl 4(%esp),%eax
|
||||
xorl %edx,%edx
|
||||
divl 8(%esp)
|
||||
ret
|
50
lib/libc/i386/net/htonl.s
Normal file
50
lib/libc/i386/net/htonl.s
Normal file
@ -0,0 +1,50 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)htonl.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* netorder = htonl(hostorder) */
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(htonl)
|
||||
movl 4(%esp),%eax
|
||||
xchgb %al,%ah
|
||||
roll $16,%eax
|
||||
xchgb %al,%ah
|
||||
ret
|
48
lib/libc/i386/net/htons.s
Normal file
48
lib/libc/i386/net/htons.s
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)htons.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* netorder = htons(hostorder) */
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(htons)
|
||||
movzwl 4(%esp),%eax
|
||||
xchgb %al,%ah
|
||||
ret
|
50
lib/libc/i386/net/ntohl.s
Normal file
50
lib/libc/i386/net/ntohl.s
Normal file
@ -0,0 +1,50 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)ntohl.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* hostorder = ntohl(netorder) */
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(ntohl)
|
||||
movl 4(%esp),%eax
|
||||
xchgb %al,%ah
|
||||
roll $16,%eax
|
||||
xchgb %al,%ah
|
||||
ret
|
48
lib/libc/i386/net/ntohs.s
Normal file
48
lib/libc/i386/net/ntohs.s
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)ntohs.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* hostorder = ntohs(netorder) */
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(ntohs)
|
||||
movzwl 4(%esp),%eax
|
||||
xchgb %al,%ah
|
||||
ret
|
48
lib/libc/i386/stdlib/abs.s
Normal file
48
lib/libc/i386/stdlib/abs.s
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)abs.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "DEFS.h"
|
||||
|
||||
ENTRY(abs)
|
||||
movl 4(%esp),%eax
|
||||
cmpl $0,%eax
|
||||
jge 1f
|
||||
negl %eax
|
||||
1: ret
|
53
lib/libc/i386/string/bzero.s
Normal file
53
lib/libc/i386/string/bzero.s
Normal file
@ -0,0 +1,53 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)bzero.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/* bzero (base,cnt) */
|
||||
|
||||
.globl _bzero
|
||||
_bzero:
|
||||
pushl %edi
|
||||
movl 8(%esp),%edi
|
||||
movl 12(%esp),%ecx
|
||||
movb $0x00,%al
|
||||
cld
|
||||
rep
|
||||
stosb
|
||||
popl %edi
|
||||
ret
|
70
lib/libc/i386/sys/Ovfork.s
Normal file
70
lib/libc/i386/sys/Ovfork.s
Normal file
@ -0,0 +1,70 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)Ovfork.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
/*
|
||||
* pid = vfork();
|
||||
*
|
||||
* %edx == 0 in parent process, %edx == 1 in child process.
|
||||
* %eax == pid of child in parent, %eax == pid of parent in child.
|
||||
*
|
||||
*/
|
||||
.set vfork,66
|
||||
.globl _vfork
|
||||
|
||||
_vfork:
|
||||
popl %ecx /* my rta into ecx */
|
||||
movl $vfork, %eax
|
||||
LCALL(7,0)
|
||||
jb verror
|
||||
vforkok:
|
||||
cmpl $0,%edx /* child process? */
|
||||
jne child /* yes */
|
||||
jmp parent
|
||||
.globl _errno
|
||||
verror:
|
||||
movl %eax,_errno
|
||||
movl $-1,%eax
|
||||
jmp %ecx
|
||||
child:
|
||||
movl $0,%eax
|
||||
parent:
|
||||
jmp %ecx
|
65
lib/libc/i386/sys/brk.s
Normal file
65
lib/libc/i386/sys/brk.s
Normal file
@ -0,0 +1,65 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)brk.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
#define SYS_brk 17
|
||||
|
||||
.globl curbrk
|
||||
.globl minbrk
|
||||
ENTRY(_brk)
|
||||
jmp ok
|
||||
|
||||
ENTRY(brk)
|
||||
movl 4(%esp),%eax
|
||||
cmpl %eax,minbrk
|
||||
jl ok
|
||||
movl minbrk,%eax
|
||||
movl %eax,4(%esp)
|
||||
ok:
|
||||
lea SYS_brk,%eax
|
||||
LCALL(7,0)
|
||||
jb err
|
||||
movl 4(%esp),%eax
|
||||
movl %eax,curbrk
|
||||
movl $0,%eax
|
||||
ret
|
||||
err:
|
||||
jmp cerror
|
47
lib/libc/i386/sys/cerror.s
Normal file
47
lib/libc/i386/sys/cerror.s
Normal file
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)cerror.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
.globl _errno
|
||||
cerror:
|
||||
movl %eax,_errno
|
||||
movl $-1,%eax
|
||||
ret
|
52
lib/libc/i386/sys/exect.s
Normal file
52
lib/libc/i386/sys/exect.s
Normal file
@ -0,0 +1,52 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)exect.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
#include <machine/psl.h>
|
||||
|
||||
ENTRY(exect)
|
||||
lea SYS_execve,%eax
|
||||
pushf
|
||||
popl %edx
|
||||
orl $ PSL_T,%edx
|
||||
pushl %edx
|
||||
popf
|
||||
LCALL(7,0)
|
||||
jmp cerror /* exect(file, argv, env); */
|
48
lib/libc/i386/sys/fork.s
Normal file
48
lib/libc/i386/sys/fork.s
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)fork.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
SYSCALL(fork)
|
||||
cmpl $0,%edx /* parent, since %edx == 0 in parent, 1 in child */
|
||||
je 1f
|
||||
movl $0,%eax
|
||||
1:
|
||||
ret /* pid = fork(); */
|
45
lib/libc/i386/sys/mount.s
Normal file
45
lib/libc/i386/sys/mount.s
Normal file
@ -0,0 +1,45 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)mount.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
SYSCALL(mount)
|
||||
movl $0,%eax
|
||||
ret
|
48
lib/libc/i386/sys/pipe.s
Normal file
48
lib/libc/i386/sys/pipe.s
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)pipe.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
SYSCALL(pipe)
|
||||
movl 4(%esp),%ecx
|
||||
movl %eax,(%ecx)
|
||||
movl %edx,4(%ecx)
|
||||
movl $0,%eax
|
||||
ret
|
51
lib/libc/i386/sys/ptrace.s
Normal file
51
lib/libc/i386/sys/ptrace.s
Normal file
@ -0,0 +1,51 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)ptrace.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
ENTRY(ptrace)
|
||||
xorl %eax,%eax
|
||||
movl %eax,_errno
|
||||
lea SYS_ptrace,%eax
|
||||
LCALL(7,0)
|
||||
jb err
|
||||
ret
|
||||
err:
|
||||
jmp cerror
|
44
lib/libc/i386/sys/reboot.s
Normal file
44
lib/libc/i386/sys/reboot.s
Normal file
@ -0,0 +1,44 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)reboot.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
SYSCALL(reboot)
|
||||
iret
|
65
lib/libc/i386/sys/sbrk.s
Normal file
65
lib/libc/i386/sys/sbrk.s
Normal file
@ -0,0 +1,65 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)sbrk.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
#define SYS_brk 17
|
||||
|
||||
.globl _end
|
||||
.globl minbrk
|
||||
.globl curbrk
|
||||
|
||||
.data
|
||||
minbrk: .long _end
|
||||
curbrk: .long _end
|
||||
.text
|
||||
|
||||
ENTRY(sbrk)
|
||||
movl 4(%esp),%ecx
|
||||
movl curbrk,%eax
|
||||
addl %eax,4(%esp)
|
||||
lea SYS_brk,%eax
|
||||
LCALL(7,0)
|
||||
jb err
|
||||
movl curbrk,%eax
|
||||
addl %ecx,curbrk
|
||||
ret
|
||||
err:
|
||||
jmp cerror
|
47
lib/libc/i386/sys/setlogin.s
Normal file
47
lib/libc/i386/sys/setlogin.s
Normal file
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)setlogin.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
.globl __logname_valid /* in getlogin() */
|
||||
|
||||
SYSCALL(setlogin)
|
||||
movl $0,__logname_valid
|
||||
ret /* setlogin(name) */
|
47
lib/libc/i386/sys/sigpending.s
Normal file
47
lib/libc/i386/sys/sigpending.s
Normal file
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)sigpending.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
SYSCALL(sigpending)
|
||||
movl 4(%esp),%ecx # fetch pointer to...
|
||||
movl %eax,(%ecx) # store old mask
|
||||
xorl %eax,%eax
|
||||
ret
|
64
lib/libc/i386/sys/sigprocmask.s
Normal file
64
lib/libc/i386/sys/sigprocmask.s
Normal file
@ -0,0 +1,64 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)sigprocmask.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
err:
|
||||
jmp cerror
|
||||
|
||||
ENTRY(sigprocmask)
|
||||
movl 8(%esp),%ecx # fetch new sigset pointer
|
||||
cmpl $0,%ecx # check new sigset pointer
|
||||
jne 1f # if not null, indirect
|
||||
/* movl $0,8(%esp) # null mask pointer: block empty set */
|
||||
movl $1,4(%esp) # SIG_BLOCK
|
||||
jmp 2f
|
||||
1: movl (%ecx),%ecx # fetch indirect ...
|
||||
movl %ecx,8(%esp) # to new mask arg
|
||||
2: movl $ SYS_sigprocmask , %eax
|
||||
LCALL(0x7,0)
|
||||
jb err
|
||||
movl 12(%esp),%ecx # fetch old mask requested
|
||||
cmpl $0,%ecx # test if old mask requested
|
||||
je out
|
||||
movl %eax,(%ecx) # store old mask
|
||||
out:
|
||||
xorl %eax,%eax
|
||||
ret
|
54
lib/libc/i386/sys/sigreturn.s
Normal file
54
lib/libc/i386/sys/sigreturn.s
Normal file
@ -0,0 +1,54 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)sigreturn.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
/*
|
||||
* We must preserve the state of the registers as the user has set them up.
|
||||
*/
|
||||
#ifdef PROF
|
||||
#undef ENTRY
|
||||
#define ENTRY(x) \
|
||||
.globl _/**/x; .align 2; _/**/x: pusha ; \
|
||||
.data; 1:; .long 0; .text; movl $1b,%eax; call mcount; popa ; nop
|
||||
#endif /* PROF */
|
||||
|
||||
SYSCALL(sigreturn)
|
||||
ret
|
54
lib/libc/i386/sys/sigsuspend.s
Normal file
54
lib/libc/i386/sys/sigsuspend.s
Normal file
@ -0,0 +1,54 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)sigsuspend.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
err:
|
||||
jmp cerror
|
||||
|
||||
ENTRY(sigsuspend)
|
||||
movl 4(%esp),%eax # fetch mask arg
|
||||
movl (%eax),%eax # indirect to mask arg
|
||||
movl %eax,4(%esp)
|
||||
movl $ SYS_sigsuspend ,%eax
|
||||
LCALL(0x7,0)
|
||||
jb err
|
||||
xorl %eax,%eax # shouldn t happen
|
||||
ret
|
51
lib/libc/i386/sys/syscall.s
Normal file
51
lib/libc/i386/sys/syscall.s
Normal file
@ -0,0 +1,51 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(SYSLIBC_SCCS) && !defined(lint)
|
||||
.asciz "@(#)syscall.s 8.1 (Berkeley) 6/4/93"
|
||||
#endif /* SYSLIBC_SCCS and not lint */
|
||||
|
||||
#include "SYS.h"
|
||||
|
||||
ENTRY(syscall)
|
||||
pop %ecx /* rta */
|
||||
pop %eax /* syscall number */
|
||||
push %ecx
|
||||
LCALL(7,0)
|
||||
jb 1f
|
||||
ret
|
||||
1:
|
||||
jmp cerror
|
62
lib/libc/net/getnetbyname.c
Normal file
62
lib/libc/net/getnetbyname.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getnetbyname.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <netdb.h>
|
||||
#include <string.h>
|
||||
|
||||
extern int _net_stayopen;
|
||||
|
||||
struct netent *
|
||||
getnetbyname(name)
|
||||
register const char *name;
|
||||
{
|
||||
register struct netent *p;
|
||||
register char **cp;
|
||||
|
||||
setnetent(_net_stayopen);
|
||||
while (p = getnetent()) {
|
||||
if (strcmp(p->n_name, name) == 0)
|
||||
break;
|
||||
for (cp = p->n_aliases; *cp != 0; cp++)
|
||||
if (strcmp(*cp, name) == 0)
|
||||
goto found;
|
||||
}
|
||||
found:
|
||||
if (!_net_stayopen)
|
||||
endnetent();
|
||||
return (p);
|
||||
}
|
121
lib/libc/net/getnetent.c
Normal file
121
lib/libc/net/getnetent.c
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 1983, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAXALIASES 35
|
||||
|
||||
static FILE *netf;
|
||||
static char line[BUFSIZ+1];
|
||||
static struct netent net;
|
||||
static char *net_aliases[MAXALIASES];
|
||||
int _net_stayopen;
|
||||
|
||||
void
|
||||
setnetent(f)
|
||||
int f;
|
||||
{
|
||||
if (netf == NULL)
|
||||
netf = fopen(_PATH_NETWORKS, "r" );
|
||||
else
|
||||
rewind(netf);
|
||||
_net_stayopen |= f;
|
||||
}
|
||||
|
||||
void
|
||||
endnetent()
|
||||
{
|
||||
if (netf) {
|
||||
fclose(netf);
|
||||
netf = NULL;
|
||||
}
|
||||
_net_stayopen = 0;
|
||||
}
|
||||
|
||||
struct netent *
|
||||
getnetent()
|
||||
{
|
||||
char *p;
|
||||
register char *cp, **q;
|
||||
|
||||
if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
|
||||
return (NULL);
|
||||
again:
|
||||
p = fgets(line, BUFSIZ, netf);
|
||||
if (p == NULL)
|
||||
return (NULL);
|
||||
if (*p == '#')
|
||||
goto again;
|
||||
cp = strpbrk(p, "#\n");
|
||||
if (cp == NULL)
|
||||
goto again;
|
||||
*cp = '\0';
|
||||
net.n_name = p;
|
||||
cp = strpbrk(p, " \t");
|
||||
if (cp == NULL)
|
||||
goto again;
|
||||
*cp++ = '\0';
|
||||
while (*cp == ' ' || *cp == '\t')
|
||||
cp++;
|
||||
p = strpbrk(cp, " \t");
|
||||
if (p != NULL)
|
||||
*p++ = '\0';
|
||||
net.n_net = inet_network(cp);
|
||||
net.n_addrtype = AF_INET;
|
||||
q = net.n_aliases = net_aliases;
|
||||
if (p != NULL)
|
||||
cp = p;
|
||||
while (cp && *cp) {
|
||||
if (*cp == ' ' || *cp == '\t') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (q < &net_aliases[MAXALIASES - 1])
|
||||
*q++ = cp;
|
||||
cp = strpbrk(cp, " \t");
|
||||
if (cp != NULL)
|
||||
*cp++ = '\0';
|
||||
}
|
||||
*q = NULL;
|
||||
return (&net);
|
||||
}
|
155
lib/libc/net/getservent.3
Normal file
155
lib/libc/net/getservent.3
Normal file
@ -0,0 +1,155 @@
|
||||
.\" Copyright (c) 1983, 1991, 1993
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)getservent.3 8.4 (Berkeley) 5/25/95
|
||||
.\"
|
||||
.Dd May 25, 1995
|
||||
.Dt GETSERVENT 3
|
||||
.Os BSD 4.2
|
||||
.Sh NAME
|
||||
.Nm getservent ,
|
||||
.Nm getservbyport ,
|
||||
.Nm getservbyname ,
|
||||
.Nm setservent ,
|
||||
.Nm endservent
|
||||
.Nd get service entry
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <netdb.h>
|
||||
.Ft struct servent *
|
||||
.Fn getservent
|
||||
.Ft struct servent *
|
||||
.Fn getservbyname "char *name" "char *proto"
|
||||
.Ft struct servent *
|
||||
.Fn getservbyport "int port" proto
|
||||
.Ft void
|
||||
.Fn setservent "int stayopen"
|
||||
.Ft void
|
||||
.Fn endservent void
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn getservent ,
|
||||
.Fn getservbyname ,
|
||||
and
|
||||
.Fn getservbyport
|
||||
functions
|
||||
each return a pointer to an object with the
|
||||
following structure
|
||||
containing the broken-out
|
||||
fields of a line in the network services data base,
|
||||
.Pa /etc/services .
|
||||
.Bd -literal -offset indent
|
||||
struct servent {
|
||||
char *s_name; /* official name of service */
|
||||
char **s_aliases; /* alias list */
|
||||
int s_port; /* port service resides at */
|
||||
char *s_proto; /* protocol to use */
|
||||
};
|
||||
.Ed
|
||||
.Pp
|
||||
The members of this structure are:
|
||||
.Bl -tag -width s_aliases
|
||||
.It Fa s_name
|
||||
The official name of the service.
|
||||
.It Fa s_aliases
|
||||
A NULL-terminated list of alternate names for the service.
|
||||
.It Fa s_port
|
||||
The port number at which the service resides.
|
||||
Port numbers are returned in network byte order.
|
||||
.It Fa s_proto
|
||||
The name of the protocol to use when contacting the
|
||||
service.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Fn getservent
|
||||
function
|
||||
reads the next line of the file, opening the file if necessary.
|
||||
.Pp
|
||||
The
|
||||
.Fn setservent
|
||||
function
|
||||
opens and rewinds the file. If the
|
||||
.Fa stayopen
|
||||
flag is non-zero,
|
||||
the net data base will not be closed after each call to
|
||||
.Fn getservbyname
|
||||
or
|
||||
.Fn getservbyport .
|
||||
.Pp
|
||||
The
|
||||
.Fn endservent
|
||||
function
|
||||
closes the file.
|
||||
.Pp
|
||||
The
|
||||
.Fn getservbyname
|
||||
and
|
||||
.Fn getservbyport
|
||||
functions
|
||||
sequentially search from the beginning
|
||||
of the file until a matching
|
||||
protocol name or
|
||||
port number is found,
|
||||
or until
|
||||
.Dv EOF
|
||||
is encountered.
|
||||
If a protocol name is also supplied (non-\c
|
||||
.Dv NULL ) ,
|
||||
searches must also match the protocol.
|
||||
.ne 1i
|
||||
.Sh FILES
|
||||
.Bl -tag -width /etc/services -compact
|
||||
.It Pa /etc/services
|
||||
.El
|
||||
.Sh DIAGNOSTICS
|
||||
Null pointer
|
||||
(0) returned on
|
||||
.Dv EOF
|
||||
or error.
|
||||
.Sh SEE ALSO
|
||||
.Xr getprotoent 3 ,
|
||||
.Xr services 5
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn getservent ,
|
||||
.Fn getservbyport ,
|
||||
.Fn getservbyname ,
|
||||
.Fn setservent ,
|
||||
and
|
||||
.Fn endservent
|
||||
functions appeared in
|
||||
.Bx 4.2 .
|
||||
.Sh BUGS
|
||||
These functions use static data storage;
|
||||
if the data is needed for future use, it should be
|
||||
copied before any subsequent calls overwrite it.
|
||||
Expecting port numbers to fit in a 32 bit
|
||||
quantity is probably naive.
|
355
lib/libc/net/res_comp.c
Normal file
355
lib/libc/net/res_comp.c
Normal file
@ -0,0 +1,355 @@
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993
|
||||
* 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.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
|
||||
static char rcsid[] = "$Id: res_comp.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int dn_find();
|
||||
|
||||
/*
|
||||
* Expand compressed domain name 'comp_dn' to full domain name.
|
||||
* 'msg' is a pointer to the begining of the message,
|
||||
* 'eomorig' points to the first location after the message,
|
||||
* 'exp_dn' is a pointer to a buffer of size 'length' for the result.
|
||||
* Return size of compressed name or -1 if there was an error.
|
||||
*/
|
||||
dn_expand(msg, eomorig, comp_dn, exp_dn, length)
|
||||
const u_char *msg, *eomorig, *comp_dn;
|
||||
u_char *exp_dn;
|
||||
int length;
|
||||
{
|
||||
register u_char *cp, *dn;
|
||||
register int n, c;
|
||||
u_char *eom;
|
||||
int len = -1, checked = 0;
|
||||
|
||||
dn = exp_dn;
|
||||
cp = (u_char *)comp_dn;
|
||||
eom = exp_dn + length;
|
||||
/*
|
||||
* fetch next label in domain name
|
||||
*/
|
||||
while (n = *cp++) {
|
||||
/*
|
||||
* Check for indirection
|
||||
*/
|
||||
switch (n & INDIR_MASK) {
|
||||
case 0:
|
||||
if (dn != exp_dn) {
|
||||
if (dn >= eom)
|
||||
return (-1);
|
||||
*dn++ = '.';
|
||||
}
|
||||
if (dn+n >= eom)
|
||||
return (-1);
|
||||
checked += n + 1;
|
||||
while (--n >= 0) {
|
||||
if ((c = *cp++) == '.') {
|
||||
if (dn + n + 2 >= eom)
|
||||
return (-1);
|
||||
*dn++ = '\\';
|
||||
}
|
||||
*dn++ = c;
|
||||
if (cp >= eomorig) /* out of range */
|
||||
return(-1);
|
||||
}
|
||||
break;
|
||||
|
||||
case INDIR_MASK:
|
||||
if (len < 0)
|
||||
len = cp - comp_dn + 1;
|
||||
cp = (u_char *)msg + (((n & 0x3f) << 8) | (*cp & 0xff));
|
||||
if (cp < msg || cp >= eomorig) /* out of range */
|
||||
return(-1);
|
||||
checked += 2;
|
||||
/*
|
||||
* Check for loops in the compressed name;
|
||||
* if we've looked at the whole message,
|
||||
* there must be a loop.
|
||||
*/
|
||||
if (checked >= eomorig - msg)
|
||||
return (-1);
|
||||
break;
|
||||
|
||||
default:
|
||||
return (-1); /* flag error */
|
||||
}
|
||||
}
|
||||
*dn = '\0';
|
||||
if (len < 0)
|
||||
len = cp - comp_dn;
|
||||
return (len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compress domain name 'exp_dn' into 'comp_dn'.
|
||||
* Return the size of the compressed name or -1.
|
||||
* 'length' is the size of the array pointed to by 'comp_dn'.
|
||||
* 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0]
|
||||
* is a pointer to the beginning of the message. The list ends with NULL.
|
||||
* 'lastdnptr' is a pointer to the end of the arrary pointed to
|
||||
* by 'dnptrs'. Side effect is to update the list of pointers for
|
||||
* labels inserted into the message as we compress the name.
|
||||
* If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
|
||||
* is NULL, we don't update the list.
|
||||
*/
|
||||
dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
|
||||
const u_char *exp_dn;
|
||||
u_char *comp_dn, **dnptrs, **lastdnptr;
|
||||
int length;
|
||||
{
|
||||
register u_char *cp, *dn;
|
||||
register int c, l;
|
||||
u_char **cpp, **lpp, *sp, *eob;
|
||||
u_char *msg;
|
||||
|
||||
dn = (u_char *)exp_dn;
|
||||
cp = comp_dn;
|
||||
eob = cp + length;
|
||||
if (dnptrs != NULL) {
|
||||
if ((msg = *dnptrs++) != NULL) {
|
||||
for (cpp = dnptrs; *cpp != NULL; cpp++)
|
||||
;
|
||||
lpp = cpp; /* end of list to search */
|
||||
}
|
||||
} else
|
||||
msg = NULL;
|
||||
for (c = *dn++; c != '\0'; ) {
|
||||
/* look to see if we can use pointers */
|
||||
if (msg != NULL) {
|
||||
if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) {
|
||||
if (cp+1 >= eob)
|
||||
return (-1);
|
||||
*cp++ = (l >> 8) | INDIR_MASK;
|
||||
*cp++ = l % 256;
|
||||
return (cp - comp_dn);
|
||||
}
|
||||
/* not found, save it */
|
||||
if (lastdnptr != NULL && cpp < lastdnptr-1) {
|
||||
*cpp++ = cp;
|
||||
*cpp = NULL;
|
||||
}
|
||||
}
|
||||
sp = cp++; /* save ptr to length byte */
|
||||
do {
|
||||
if (c == '.') {
|
||||
c = *dn++;
|
||||
break;
|
||||
}
|
||||
if (c == '\\') {
|
||||
if ((c = *dn++) == '\0')
|
||||
break;
|
||||
}
|
||||
if (cp >= eob) {
|
||||
if (msg != NULL)
|
||||
*lpp = NULL;
|
||||
return (-1);
|
||||
}
|
||||
*cp++ = c;
|
||||
} while ((c = *dn++) != '\0');
|
||||
/* catch trailing '.'s but not '..' */
|
||||
if ((l = cp - sp - 1) == 0 && c == '\0') {
|
||||
cp--;
|
||||
break;
|
||||
}
|
||||
if (l <= 0 || l > MAXLABEL) {
|
||||
if (msg != NULL)
|
||||
*lpp = NULL;
|
||||
return (-1);
|
||||
}
|
||||
*sp = l;
|
||||
}
|
||||
if (cp >= eob) {
|
||||
if (msg != NULL)
|
||||
*lpp = NULL;
|
||||
return (-1);
|
||||
}
|
||||
*cp++ = '\0';
|
||||
return (cp - comp_dn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip over a compressed domain name. Return the size or -1.
|
||||
*/
|
||||
__dn_skipname(comp_dn, eom)
|
||||
const u_char *comp_dn, *eom;
|
||||
{
|
||||
register u_char *cp;
|
||||
register int n;
|
||||
|
||||
cp = (u_char *)comp_dn;
|
||||
while (cp < eom && (n = *cp++)) {
|
||||
/*
|
||||
* check for indirection
|
||||
*/
|
||||
switch (n & INDIR_MASK) {
|
||||
case 0: /* normal case, n == len */
|
||||
cp += n;
|
||||
continue;
|
||||
default: /* illegal type */
|
||||
return (-1);
|
||||
case INDIR_MASK: /* indirection */
|
||||
cp++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (cp - comp_dn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Search for expanded name from a list of previously compressed names.
|
||||
* Return the offset from msg if found or -1.
|
||||
* dnptrs is the pointer to the first name on the list,
|
||||
* not the pointer to the start of the message.
|
||||
*/
|
||||
static int
|
||||
dn_find(exp_dn, msg, dnptrs, lastdnptr)
|
||||
u_char *exp_dn, *msg;
|
||||
u_char **dnptrs, **lastdnptr;
|
||||
{
|
||||
register u_char *dn, *cp, **cpp;
|
||||
register int n;
|
||||
u_char *sp;
|
||||
|
||||
for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
|
||||
dn = exp_dn;
|
||||
sp = cp = *cpp;
|
||||
while (n = *cp++) {
|
||||
/*
|
||||
* check for indirection
|
||||
*/
|
||||
switch (n & INDIR_MASK) {
|
||||
case 0: /* normal case, n == len */
|
||||
while (--n >= 0) {
|
||||
if (*dn == '.')
|
||||
goto next;
|
||||
if (*dn == '\\')
|
||||
dn++;
|
||||
if (*dn++ != *cp++)
|
||||
goto next;
|
||||
}
|
||||
if ((n = *dn++) == '\0' && *cp == '\0')
|
||||
return (sp - msg);
|
||||
if (n == '.')
|
||||
continue;
|
||||
goto next;
|
||||
|
||||
default: /* illegal type */
|
||||
return (-1);
|
||||
|
||||
case INDIR_MASK: /* indirection */
|
||||
cp = msg + (((n & 0x3f) << 8) | *cp);
|
||||
}
|
||||
}
|
||||
if (*dn == '\0')
|
||||
return (sp - msg);
|
||||
next: ;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Routines to insert/extract short/long's. Must account for byte
|
||||
* order and non-alignment problems. This code at least has the
|
||||
* advantage of being portable.
|
||||
*
|
||||
* used by sendmail.
|
||||
*/
|
||||
|
||||
u_short
|
||||
_getshort(msgp)
|
||||
register u_char *msgp;
|
||||
{
|
||||
register u_int16_t u;
|
||||
|
||||
GETSHORT(u, msgp);
|
||||
return (u);
|
||||
}
|
||||
|
||||
u_int32_t
|
||||
_getlong(msgp)
|
||||
register u_char *msgp;
|
||||
{
|
||||
register u_int32_t u;
|
||||
|
||||
GETLONG(u, msgp);
|
||||
return (u);
|
||||
}
|
||||
|
||||
void
|
||||
#if defined(__STDC__) || defined(__cplusplus)
|
||||
__putshort(register u_short s, register u_char *msgp)
|
||||
#else
|
||||
__putshort(s, msgp)
|
||||
register u_int16_t s;
|
||||
register u_char *msgp;
|
||||
#endif
|
||||
{
|
||||
PUTSHORT(s, msgp);
|
||||
}
|
||||
|
||||
void
|
||||
__putlong(l, msgp)
|
||||
register u_int32_t l;
|
||||
register u_char *msgp;
|
||||
{
|
||||
PUTLONG(l, msgp);
|
||||
}
|
739
lib/libc/net/res_debug.c
Normal file
739
lib/libc/net/res_debug.c
Normal file
@ -0,0 +1,739 @@
|
||||
/*-
|
||||
* Copyright (c) 1985, 1990, 1993
|
||||
* 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.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void __fp_query();
|
||||
char *__p_class(), *__p_time(), *__p_type();
|
||||
char *p_cdname(), *p_fqname(), *p_rr();
|
||||
static char *p_option __P((u_int32_t));
|
||||
|
||||
char *_res_opcodes[] = {
|
||||
"QUERY",
|
||||
"IQUERY",
|
||||
"CQUERYM",
|
||||
"CQUERYU",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"UPDATEA",
|
||||
"UPDATED",
|
||||
"UPDATEDA",
|
||||
"UPDATEM",
|
||||
"UPDATEMA",
|
||||
"ZONEINIT",
|
||||
"ZONEREF",
|
||||
};
|
||||
|
||||
char *_res_resultcodes[] = {
|
||||
"NOERROR",
|
||||
"FORMERR",
|
||||
"SERVFAIL",
|
||||
"NXDOMAIN",
|
||||
"NOTIMP",
|
||||
"REFUSED",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
"NOCHANGE",
|
||||
};
|
||||
|
||||
static char retbuf[16];
|
||||
|
||||
static char *
|
||||
dewks(wks)
|
||||
int wks;
|
||||
{
|
||||
switch (wks) {
|
||||
case 5: return("rje");
|
||||
case 7: return("echo");
|
||||
case 9: return("discard");
|
||||
case 11: return("systat");
|
||||
case 13: return("daytime");
|
||||
case 15: return("netstat");
|
||||
case 17: return("qotd");
|
||||
case 19: return("chargen");
|
||||
case 20: return("ftp-data");
|
||||
case 21: return("ftp");
|
||||
case 23: return("telnet");
|
||||
case 25: return("smtp");
|
||||
case 37: return("time");
|
||||
case 39: return("rlp");
|
||||
case 42: return("name");
|
||||
case 43: return("whois");
|
||||
case 53: return("domain");
|
||||
case 57: return("apts");
|
||||
case 59: return("apfs");
|
||||
case 67: return("bootps");
|
||||
case 68: return("bootpc");
|
||||
case 69: return("tftp");
|
||||
case 77: return("rje");
|
||||
case 79: return("finger");
|
||||
case 87: return("link");
|
||||
case 95: return("supdup");
|
||||
case 100: return("newacct");
|
||||
case 101: return("hostnames");
|
||||
case 102: return("iso-tsap");
|
||||
case 103: return("x400");
|
||||
case 104: return("x400-snd");
|
||||
case 105: return("csnet-ns");
|
||||
case 109: return("pop-2");
|
||||
case 111: return("sunrpc");
|
||||
case 113: return("auth");
|
||||
case 115: return("sftp");
|
||||
case 117: return("uucp-path");
|
||||
case 119: return("nntp");
|
||||
case 121: return("erpc");
|
||||
case 123: return("ntp");
|
||||
case 133: return("statsrv");
|
||||
case 136: return("profile");
|
||||
case 144: return("NeWS");
|
||||
case 161: return("snmp");
|
||||
case 162: return("snmp-trap");
|
||||
case 170: return("print-srv");
|
||||
default: (void) sprintf(retbuf, "%d", wks); return(retbuf);
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
deproto(protonum)
|
||||
int protonum;
|
||||
{
|
||||
switch (protonum) {
|
||||
case 1: return("icmp");
|
||||
case 2: return("igmp");
|
||||
case 3: return("ggp");
|
||||
case 5: return("st");
|
||||
case 6: return("tcp");
|
||||
case 7: return("ucl");
|
||||
case 8: return("egp");
|
||||
case 9: return("igp");
|
||||
case 11: return("nvp-II");
|
||||
case 12: return("pup");
|
||||
case 16: return("chaos");
|
||||
case 17: return("udp");
|
||||
default: (void) sprintf(retbuf, "%d", protonum); return(retbuf);
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
do_rrset(msg, cp, cnt, pflag, file, hs)
|
||||
int cnt, pflag;
|
||||
char *cp,*msg, *hs;
|
||||
FILE *file;
|
||||
{
|
||||
int n;
|
||||
int sflag;
|
||||
/*
|
||||
* Print answer records
|
||||
*/
|
||||
sflag = (_res.pfcode & pflag);
|
||||
if (n = ntohs(cnt)) {
|
||||
if ((!_res.pfcode) || ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
|
||||
fprintf(file, hs);
|
||||
while (--n >= 0) {
|
||||
cp = p_rr(cp, msg, file);
|
||||
if ((cp-msg) > PACKETSZ)
|
||||
return (NULL);
|
||||
}
|
||||
if ((!_res.pfcode) || ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
|
||||
putc('\n', file);
|
||||
}
|
||||
return(cp);
|
||||
}
|
||||
|
||||
__p_query(msg)
|
||||
char *msg;
|
||||
{
|
||||
__fp_query(msg, stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the current options.
|
||||
* This is intended to be primarily a debugging routine.
|
||||
*/
|
||||
void
|
||||
__fp_resstat(statp, file)
|
||||
struct __res_state *statp;
|
||||
FILE *file;
|
||||
{
|
||||
int bit;
|
||||
|
||||
fprintf(file, ";; res options:");
|
||||
if (!statp)
|
||||
statp = &_res;
|
||||
for (bit = 0; bit < 32; bit++) { /* XXX 32 - bad assumption! */
|
||||
if (statp->options & (1<<bit))
|
||||
fprintf(file, " %s", p_option(1<<bit));
|
||||
}
|
||||
putc('\n', file);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the contents of a query.
|
||||
* This is intended to be primarily a debugging routine.
|
||||
*/
|
||||
void
|
||||
__fp_query(msg,file)
|
||||
char *msg;
|
||||
FILE *file;
|
||||
{
|
||||
register char *cp;
|
||||
register HEADER *hp;
|
||||
register int n;
|
||||
|
||||
/*
|
||||
* Print header fields.
|
||||
*/
|
||||
hp = (HEADER *)msg;
|
||||
cp = msg + sizeof(HEADER);
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || hp->rcode) {
|
||||
fprintf(file,";; ->>HEADER<<- opcode: %s, status: %s, id: %d",
|
||||
_res_opcodes[hp->opcode],
|
||||
_res_resultcodes[hp->rcode],
|
||||
ntohs(hp->id));
|
||||
putc('\n', file);
|
||||
}
|
||||
putc(';', file);
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
|
||||
fprintf(file,"; flags:");
|
||||
if (hp->qr)
|
||||
fprintf(file," qr");
|
||||
if (hp->aa)
|
||||
fprintf(file," aa");
|
||||
if (hp->tc)
|
||||
fprintf(file," tc");
|
||||
if (hp->rd)
|
||||
fprintf(file," rd");
|
||||
if (hp->ra)
|
||||
fprintf(file," ra");
|
||||
if (hp->pr)
|
||||
fprintf(file," pr");
|
||||
}
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
|
||||
fprintf(file,"; Ques: %d", ntohs(hp->qdcount));
|
||||
fprintf(file,", Ans: %d", ntohs(hp->ancount));
|
||||
fprintf(file,", Auth: %d", ntohs(hp->nscount));
|
||||
fprintf(file,", Addit: %d\n", ntohs(hp->arcount));
|
||||
}
|
||||
#if 0
|
||||
if (_res.pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1)) {
|
||||
putc('\n',file);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* Print question records.
|
||||
*/
|
||||
if (n = ntohs(hp->qdcount)) {
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
|
||||
fprintf(file,";; QUESTIONS:\n");
|
||||
while (--n >= 0) {
|
||||
fprintf(file,";;\t");
|
||||
cp = p_cdname(cp, msg, file);
|
||||
if (cp == NULL)
|
||||
return;
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
|
||||
fprintf(file, ", type = %s",
|
||||
__p_type(_getshort(cp)));
|
||||
cp += sizeof(u_int16_t);
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
|
||||
fprintf(file, ", class = %s\n\n",
|
||||
__p_class(_getshort(cp)));
|
||||
cp += sizeof(u_int16_t);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Print authoritative answer records
|
||||
*/
|
||||
cp = do_rrset(msg, cp, hp->ancount, RES_PRF_ANS, file,
|
||||
";; ANSWERS:\n");
|
||||
if (cp == NULL)
|
||||
return;
|
||||
|
||||
/*
|
||||
* print name server records
|
||||
*/
|
||||
cp = do_rrset(msg, cp, hp->nscount, RES_PRF_AUTH, file,
|
||||
";; AUTHORITY RECORDS:\n");
|
||||
if (!cp)
|
||||
return;
|
||||
|
||||
/*
|
||||
* print additional records
|
||||
*/
|
||||
cp = do_rrset(msg, cp, hp->arcount, RES_PRF_ADD, file,
|
||||
";; ADDITIONAL RECORDS:\n");
|
||||
if (!cp)
|
||||
return;
|
||||
}
|
||||
|
||||
char *
|
||||
p_cdname(cp, msg, file)
|
||||
char *cp, *msg;
|
||||
FILE *file;
|
||||
{
|
||||
char name[MAXDNAME];
|
||||
int n;
|
||||
|
||||
if ((n = dn_expand((u_char *)msg, (u_char *)msg + MAXCDNAME,
|
||||
(u_char *)cp, (u_char *)name, sizeof(name))) < 0)
|
||||
return (NULL);
|
||||
if (name[0] == '\0')
|
||||
putc('.', file);
|
||||
else
|
||||
fputs(name, file);
|
||||
return (cp + n);
|
||||
}
|
||||
|
||||
char *
|
||||
p_fqname(cp, msg, file)
|
||||
char *cp, *msg;
|
||||
FILE *file;
|
||||
{
|
||||
char name[MAXDNAME];
|
||||
int n, len;
|
||||
|
||||
if ((n = dn_expand((u_char *)msg, (u_char *)msg + MAXCDNAME,
|
||||
(u_char *)cp, (u_char *)name, sizeof(name))) < 0)
|
||||
return (NULL);
|
||||
if (name[0] == '\0') {
|
||||
putc('.', file);
|
||||
} else {
|
||||
fputs(name, file);
|
||||
if (name[strlen(name) - 1] != '.')
|
||||
putc('.', file);
|
||||
}
|
||||
return (cp + n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print resource record fields in human readable form.
|
||||
*/
|
||||
char *
|
||||
p_rr(cp, msg, file)
|
||||
char *cp, *msg;
|
||||
FILE *file;
|
||||
{
|
||||
int type, class, dlen, n, c;
|
||||
struct in_addr inaddr;
|
||||
char *cp1, *cp2;
|
||||
u_int32_t tmpttl, t;
|
||||
int lcnt;
|
||||
|
||||
if ((cp = p_fqname(cp, msg, file)) == NULL)
|
||||
return (NULL); /* compression error */
|
||||
type = _getshort(cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
class = _getshort(cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
tmpttl = _getlong(cp);
|
||||
cp += sizeof(u_int32_t);
|
||||
dlen = _getshort(cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
cp1 = cp;
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID))
|
||||
fprintf(file, "\t%lu", tmpttl);
|
||||
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS))
|
||||
fprintf(file, "\t%s", __p_class(class));
|
||||
fprintf(file, "\t%s", __p_type(type));
|
||||
/*
|
||||
* Print type specific data, if appropriate
|
||||
*/
|
||||
switch (type) {
|
||||
case T_A:
|
||||
switch (class) {
|
||||
case C_IN:
|
||||
case C_HS:
|
||||
bcopy(cp, (char *)&inaddr, sizeof(inaddr));
|
||||
if (dlen == 4) {
|
||||
fprintf(file,"\t%s", inet_ntoa(inaddr));
|
||||
cp += dlen;
|
||||
} else if (dlen == 7) {
|
||||
char *address;
|
||||
u_char protocol;
|
||||
u_short port;
|
||||
|
||||
address = inet_ntoa(inaddr);
|
||||
cp += sizeof(inaddr);
|
||||
protocol = *(u_char*)cp;
|
||||
cp += sizeof(u_char);
|
||||
port = _getshort(cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
fprintf(file, "\t%s\t; proto %d, port %d",
|
||||
address, protocol, port);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cp += dlen;
|
||||
}
|
||||
break;
|
||||
case T_CNAME:
|
||||
case T_MB:
|
||||
case T_MG:
|
||||
case T_MR:
|
||||
case T_NS:
|
||||
case T_PTR:
|
||||
putc('\t', file);
|
||||
cp = p_fqname(cp, msg, file);
|
||||
break;
|
||||
|
||||
case T_HINFO:
|
||||
if (n = *cp++) {
|
||||
fprintf(file,"\t%.*s", n, cp);
|
||||
cp += n;
|
||||
}
|
||||
if (n = *cp++) {
|
||||
fprintf(file,"\t%.*s", n, cp);
|
||||
cp += n;
|
||||
}
|
||||
break;
|
||||
|
||||
case T_SOA:
|
||||
putc('\t', file);
|
||||
cp = p_fqname(cp, msg, file); /* origin */
|
||||
putc(' ', file);
|
||||
cp = p_fqname(cp, msg, file); /* mail addr */
|
||||
fputs(" (\n", file);
|
||||
t = _getlong(cp); cp += sizeof(u_int32_t);
|
||||
fprintf(file,"\t\t\t%lu\t; serial\n", t);
|
||||
t = _getlong(cp); cp += sizeof(u_int32_t);
|
||||
fprintf(file,"\t\t\t%lu\t; refresh (%s)\n", t, __p_time(t));
|
||||
t = _getlong(cp); cp += sizeof(u_int32_t);
|
||||
fprintf(file,"\t\t\t%lu\t; retry (%s)\n", t, __p_time(t));
|
||||
t = _getlong(cp); cp += sizeof(u_int32_t);
|
||||
fprintf(file,"\t\t\t%lu\t; expire (%s)\n", t, __p_time(t));
|
||||
t = _getlong(cp); cp += sizeof(u_int32_t);
|
||||
fprintf(file,"\t\t\t%lu )\t; minimum (%s)", t, __p_time(t));
|
||||
break;
|
||||
|
||||
case T_MX:
|
||||
fprintf(file,"\t%d ", _getshort(cp));
|
||||
cp += sizeof(u_int16_t);
|
||||
cp = p_fqname(cp, msg, file);
|
||||
break;
|
||||
|
||||
case T_TXT:
|
||||
(void) fputs("\t\"", file);
|
||||
cp2 = cp1 + dlen;
|
||||
while (cp < cp2) {
|
||||
if (n = (unsigned char) *cp++) {
|
||||
for (c = n; c > 0 && cp < cp2; c--)
|
||||
if (*cp == '\n') {
|
||||
(void) putc('\\', file);
|
||||
(void) putc(*cp++, file);
|
||||
} else
|
||||
(void) putc(*cp++, file);
|
||||
}
|
||||
}
|
||||
putc('"', file);
|
||||
break;
|
||||
|
||||
case T_MINFO:
|
||||
case T_RP:
|
||||
putc('\t', file);
|
||||
cp = p_fqname(cp, msg, file);
|
||||
putc(' ', file);
|
||||
cp = p_fqname(cp, msg, file);
|
||||
break;
|
||||
|
||||
case T_UINFO:
|
||||
putc('\t', file);
|
||||
fputs(cp, file);
|
||||
cp += dlen;
|
||||
break;
|
||||
|
||||
case T_UID:
|
||||
case T_GID:
|
||||
if (dlen == 4) {
|
||||
fprintf(file,"\t%u", _getlong(cp));
|
||||
cp += sizeof(int32_t);
|
||||
}
|
||||
break;
|
||||
|
||||
case T_WKS:
|
||||
if (dlen < sizeof(u_int32_t) + 1)
|
||||
break;
|
||||
bcopy(cp, (char *)&inaddr, sizeof(inaddr));
|
||||
cp += sizeof(u_int32_t);
|
||||
fprintf(file, "\t%s %s ( ",
|
||||
inet_ntoa(inaddr),
|
||||
deproto((int) *cp));
|
||||
cp += sizeof(u_char);
|
||||
n = 0;
|
||||
lcnt = 0;
|
||||
while (cp < cp1 + dlen) {
|
||||
c = *cp++;
|
||||
do {
|
||||
if (c & 0200) {
|
||||
if (lcnt == 0) {
|
||||
fputs("\n\t\t\t", file);
|
||||
lcnt = 5;
|
||||
}
|
||||
fputs(dewks(n), file);
|
||||
putc(' ', file);
|
||||
lcnt--;
|
||||
}
|
||||
c <<= 1;
|
||||
} while (++n & 07);
|
||||
}
|
||||
putc(')', file);
|
||||
break;
|
||||
|
||||
#ifdef ALLOW_T_UNSPEC
|
||||
case T_UNSPEC:
|
||||
{
|
||||
int NumBytes = 8;
|
||||
char *DataPtr;
|
||||
int i;
|
||||
|
||||
if (dlen < NumBytes) NumBytes = dlen;
|
||||
fprintf(file, "\tFirst %d bytes of hex data:",
|
||||
NumBytes);
|
||||
for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++)
|
||||
fprintf(file, " %x", *DataPtr);
|
||||
cp += dlen;
|
||||
}
|
||||
break;
|
||||
#endif /* ALLOW_T_UNSPEC */
|
||||
|
||||
default:
|
||||
fprintf(file,"\t?%d?", type);
|
||||
cp += dlen;
|
||||
}
|
||||
#if 0
|
||||
fprintf(file, "\t; dlen=%d, ttl %s\n", dlen, __p_time(tmpttl));
|
||||
#else
|
||||
putc('\n', file);
|
||||
#endif
|
||||
if (cp - cp1 != dlen) {
|
||||
fprintf(file,";; packet size error (found %d, dlen was %d)\n",
|
||||
cp - cp1, dlen);
|
||||
cp = NULL;
|
||||
}
|
||||
return (cp);
|
||||
}
|
||||
|
||||
static char nbuf[40];
|
||||
|
||||
/*
|
||||
* Return a string for the type
|
||||
*/
|
||||
char *
|
||||
__p_type(type)
|
||||
int type;
|
||||
{
|
||||
switch (type) {
|
||||
case T_A:
|
||||
return("A");
|
||||
case T_NS: /* authoritative server */
|
||||
return("NS");
|
||||
case T_CNAME: /* canonical name */
|
||||
return("CNAME");
|
||||
case T_SOA: /* start of authority zone */
|
||||
return("SOA");
|
||||
case T_MB: /* mailbox domain name */
|
||||
return("MB");
|
||||
case T_MG: /* mail group member */
|
||||
return("MG");
|
||||
case T_MR: /* mail rename name */
|
||||
return("MR");
|
||||
case T_NULL: /* null resource record */
|
||||
return("NULL");
|
||||
case T_WKS: /* well known service */
|
||||
return("WKS");
|
||||
case T_PTR: /* domain name pointer */
|
||||
return("PTR");
|
||||
case T_HINFO: /* host information */
|
||||
return("HINFO");
|
||||
case T_MINFO: /* mailbox information */
|
||||
return("MINFO");
|
||||
case T_MX: /* mail routing info */
|
||||
return("MX");
|
||||
case T_TXT: /* text */
|
||||
return("TXT");
|
||||
case T_RP: /* responsible person */
|
||||
return("RP");
|
||||
case T_AXFR: /* zone transfer */
|
||||
return("AXFR");
|
||||
case T_MAILB: /* mail box */
|
||||
return("MAILB");
|
||||
case T_MAILA: /* mail address */
|
||||
return("MAILA");
|
||||
case T_ANY: /* matches any type */
|
||||
return("ANY");
|
||||
case T_UINFO:
|
||||
return("UINFO");
|
||||
case T_UID:
|
||||
return("UID");
|
||||
case T_GID:
|
||||
return("GID");
|
||||
#ifdef ALLOW_T_UNSPEC
|
||||
case T_UNSPEC:
|
||||
return("UNSPEC");
|
||||
#endif /* ALLOW_T_UNSPEC */
|
||||
default:
|
||||
(void)sprintf(nbuf, "%d", type);
|
||||
return(nbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a mnemonic for class
|
||||
*/
|
||||
char *
|
||||
__p_class(class)
|
||||
int class;
|
||||
{
|
||||
|
||||
switch (class) {
|
||||
case C_IN: /* internet class */
|
||||
return("IN");
|
||||
case C_HS: /* hesiod class */
|
||||
return("HS");
|
||||
case C_ANY: /* matches any class */
|
||||
return("ANY");
|
||||
default:
|
||||
(void)sprintf(nbuf, "%d", class);
|
||||
return(nbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a mnemonic for an option
|
||||
*/
|
||||
static char *
|
||||
p_option(option)
|
||||
u_int32_t option;
|
||||
{
|
||||
switch (option) {
|
||||
case RES_INIT: return "init";
|
||||
case RES_DEBUG: return "debug";
|
||||
case RES_AAONLY: return "aaonly";
|
||||
case RES_USEVC: return "usevc";
|
||||
case RES_PRIMARY: return "primry";
|
||||
case RES_IGNTC: return "igntc";
|
||||
case RES_RECURSE: return "recurs";
|
||||
case RES_DEFNAMES: return "defnam";
|
||||
case RES_STAYOPEN: return "styopn";
|
||||
case RES_DNSRCH: return "dnsrch";
|
||||
default: sprintf(nbuf, "?0x%x?", option); return nbuf;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a mnemonic for a time to live
|
||||
*/
|
||||
char *
|
||||
__p_time(value)
|
||||
u_int32_t value;
|
||||
{
|
||||
int secs, mins, hours, days;
|
||||
register char *p;
|
||||
|
||||
if (value == 0) {
|
||||
strcpy(nbuf, "0 secs");
|
||||
return(nbuf);
|
||||
}
|
||||
|
||||
secs = value % 60;
|
||||
value /= 60;
|
||||
mins = value % 60;
|
||||
value /= 60;
|
||||
hours = value % 24;
|
||||
value /= 24;
|
||||
days = value;
|
||||
value = 0;
|
||||
|
||||
#define PLURALIZE(x) x, (x == 1) ? "" : "s"
|
||||
p = nbuf;
|
||||
if (days) {
|
||||
(void)sprintf(p, "%d day%s", PLURALIZE(days));
|
||||
while (*++p);
|
||||
}
|
||||
if (hours) {
|
||||
if (days)
|
||||
*p++ = ' ';
|
||||
(void)sprintf(p, "%d hour%s", PLURALIZE(hours));
|
||||
while (*++p);
|
||||
}
|
||||
if (mins) {
|
||||
if (days || hours)
|
||||
*p++ = ' ';
|
||||
(void)sprintf(p, "%d min%s", PLURALIZE(mins));
|
||||
while (*++p);
|
||||
}
|
||||
if (secs || ! (days || hours || mins)) {
|
||||
if (days || hours || mins)
|
||||
*p++ = ' ';
|
||||
(void)sprintf(p, "%d sec%s", PLURALIZE(secs));
|
||||
}
|
||||
return(nbuf);
|
||||
}
|
223
lib/libc/net/res_init.c
Normal file
223
lib/libc/net/res_init.c
Normal file
@ -0,0 +1,223 @@
|
||||
/*-
|
||||
* Copyright (c) 1985, 1989, 1993
|
||||
* 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.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
|
||||
static char rcsid[] = "$Id: res_init.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Resolver state default settings
|
||||
*/
|
||||
|
||||
struct __res_state _res = {
|
||||
RES_TIMEOUT, /* retransmition time interval */
|
||||
4, /* number of times to retransmit */
|
||||
RES_DEFAULT, /* options flags */
|
||||
1, /* number of name servers */
|
||||
};
|
||||
|
||||
/*
|
||||
* Set up default settings. If the configuration file exist, the values
|
||||
* there will have precedence. Otherwise, the server address is set to
|
||||
* INADDR_ANY and the default domain name comes from the gethostname().
|
||||
*
|
||||
* The configuration file should only be used if you want to redefine your
|
||||
* domain or run without a server on your machine.
|
||||
*
|
||||
* Return 0 if completes successfully, -1 on error
|
||||
*/
|
||||
res_init()
|
||||
{
|
||||
register FILE *fp;
|
||||
register char *cp, **pp;
|
||||
register int n;
|
||||
char buf[BUFSIZ];
|
||||
int nserv = 0; /* number of nameserver records read from file */
|
||||
int haveenv = 0;
|
||||
int havesearch = 0;
|
||||
|
||||
#ifdef USELOOPBACK
|
||||
_res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
|
||||
#else
|
||||
_res.nsaddr.sin_addr.s_addr = INADDR_ANY;
|
||||
#endif
|
||||
_res.nsaddr.sin_family = AF_INET;
|
||||
_res.nsaddr.sin_port = htons(NAMESERVER_PORT);
|
||||
_res.nscount = 1;
|
||||
_res.pfcode = 0;
|
||||
|
||||
/* Allow user to override the local domain definition */
|
||||
if ((cp = getenv("LOCALDOMAIN")) != NULL) {
|
||||
(void)strncpy(_res.defdname, cp, sizeof(_res.defdname));
|
||||
if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
|
||||
*cp = '\0';
|
||||
haveenv++;
|
||||
}
|
||||
|
||||
if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
|
||||
/* read the config file */
|
||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||
/* skip comments */
|
||||
if ((*buf == ';') || (*buf == '#'))
|
||||
continue;
|
||||
/* read default domain name */
|
||||
if (!strncmp(buf, "domain", sizeof("domain") - 1)) {
|
||||
if (haveenv) /* skip if have from environ */
|
||||
continue;
|
||||
cp = buf + sizeof("domain") - 1;
|
||||
while (*cp == ' ' || *cp == '\t')
|
||||
cp++;
|
||||
if ((*cp == '\0') || (*cp == '\n'))
|
||||
continue;
|
||||
(void)strncpy(_res.defdname, cp,
|
||||
sizeof(_res.defdname) - 1);
|
||||
if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
|
||||
*cp = '\0';
|
||||
havesearch = 0;
|
||||
continue;
|
||||
}
|
||||
/* set search list */
|
||||
if (!strncmp(buf, "search", sizeof("search") - 1)) {
|
||||
if (haveenv) /* skip if have from environ */
|
||||
continue;
|
||||
cp = buf + sizeof("search") - 1;
|
||||
while (*cp == ' ' || *cp == '\t')
|
||||
cp++;
|
||||
if ((*cp == '\0') || (*cp == '\n'))
|
||||
continue;
|
||||
(void)strncpy(_res.defdname, cp,
|
||||
sizeof(_res.defdname) - 1);
|
||||
if ((cp = strchr(_res.defdname, '\n')) != NULL)
|
||||
*cp = '\0';
|
||||
/*
|
||||
* Set search list to be blank-separated strings
|
||||
* on rest of line.
|
||||
*/
|
||||
cp = _res.defdname;
|
||||
pp = _res.dnsrch;
|
||||
*pp++ = cp;
|
||||
for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
|
||||
if (*cp == ' ' || *cp == '\t') {
|
||||
*cp = 0;
|
||||
n = 1;
|
||||
} else if (n) {
|
||||
*pp++ = cp;
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
/* null terminate last domain if there are excess */
|
||||
while (*cp != '\0' && *cp != ' ' && *cp != '\t')
|
||||
cp++;
|
||||
*cp = '\0';
|
||||
*pp++ = 0;
|
||||
havesearch = 1;
|
||||
continue;
|
||||
}
|
||||
/* read nameservers to query */
|
||||
if (!strncmp(buf, "nameserver", sizeof("nameserver") - 1) &&
|
||||
nserv < MAXNS) {
|
||||
struct in_addr a;
|
||||
|
||||
cp = buf + sizeof("nameserver") - 1;
|
||||
while (*cp == ' ' || *cp == '\t')
|
||||
cp++;
|
||||
if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
|
||||
_res.nsaddr_list[nserv].sin_addr = a;
|
||||
_res.nsaddr_list[nserv].sin_family = AF_INET;
|
||||
_res.nsaddr_list[nserv].sin_port =
|
||||
htons(NAMESERVER_PORT);
|
||||
nserv++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (nserv > 1)
|
||||
_res.nscount = nserv;
|
||||
(void) fclose(fp);
|
||||
}
|
||||
if (_res.defdname[0] == 0) {
|
||||
if (gethostname(buf, sizeof(_res.defdname)) == 0 &&
|
||||
(cp = strchr(buf, '.')))
|
||||
(void)strcpy(_res.defdname, cp + 1);
|
||||
}
|
||||
|
||||
/* find components of local domain that might be searched */
|
||||
if (havesearch == 0) {
|
||||
pp = _res.dnsrch;
|
||||
*pp++ = _res.defdname;
|
||||
for (cp = _res.defdname, n = 0; *cp; cp++)
|
||||
if (*cp == '.')
|
||||
n++;
|
||||
cp = _res.defdname;
|
||||
for (; n >= LOCALDOMAINPARTS && pp < _res.dnsrch + MAXDFLSRCH;
|
||||
n--) {
|
||||
cp = strchr(cp, '.');
|
||||
*pp++ = ++cp;
|
||||
}
|
||||
*pp++ = 0;
|
||||
}
|
||||
_res.options |= RES_INIT;
|
||||
return (0);
|
||||
}
|
230
lib/libc/net/res_mkquery.c
Normal file
230
lib/libc/net/res_mkquery.c
Normal file
@ -0,0 +1,230 @@
|
||||
/*-
|
||||
* Copyright (c) 1985, 1993
|
||||
* 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.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
|
||||
static char rcsid[] = "$Id: res_mkquery.c,v 4.9.1.2 1993/05/17 10:00:01 vixie Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Form all types of queries.
|
||||
* Returns the size of the result or -1.
|
||||
*/
|
||||
res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
|
||||
int op; /* opcode of query */
|
||||
const char *dname; /* domain name */
|
||||
int class, type; /* class and type of query */
|
||||
const char *data; /* resource record data */
|
||||
int datalen; /* length of data */
|
||||
const char *newrr_in; /* new rr for modify or append */
|
||||
char *buf; /* buffer to put query */
|
||||
int buflen; /* size of buffer */
|
||||
{
|
||||
register HEADER *hp;
|
||||
register char *cp;
|
||||
register int n;
|
||||
struct rrec *newrr = (struct rrec *) newrr_in;
|
||||
char *dnptrs[10], **dpp, **lastdnptr;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; res_mkquery(%d, %s, %d, %d)\n",
|
||||
op, dname, class, type);
|
||||
#endif
|
||||
/*
|
||||
* Initialize header fields.
|
||||
*/
|
||||
if ((buf == NULL) || (buflen < sizeof(HEADER)))
|
||||
return(-1);
|
||||
bzero(buf, sizeof(HEADER));
|
||||
hp = (HEADER *) buf;
|
||||
hp->id = htons(++_res.id);
|
||||
hp->opcode = op;
|
||||
hp->pr = (_res.options & RES_PRIMARY) != 0;
|
||||
hp->rd = (_res.options & RES_RECURSE) != 0;
|
||||
hp->rcode = NOERROR;
|
||||
cp = buf + sizeof(HEADER);
|
||||
buflen -= sizeof(HEADER);
|
||||
dpp = dnptrs;
|
||||
*dpp++ = buf;
|
||||
*dpp++ = NULL;
|
||||
lastdnptr = dnptrs + sizeof(dnptrs)/sizeof(dnptrs[0]);
|
||||
/*
|
||||
* perform opcode specific processing
|
||||
*/
|
||||
switch (op) {
|
||||
case QUERY:
|
||||
if ((buflen -= QFIXEDSZ) < 0)
|
||||
return(-1);
|
||||
if ((n = dn_comp((u_char *)dname, (u_char *)cp, buflen,
|
||||
(u_char **)dnptrs, (u_char **)lastdnptr)) < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
buflen -= n;
|
||||
__putshort(type, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putshort(class, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
hp->qdcount = htons(1);
|
||||
if (op == QUERY || data == NULL)
|
||||
break;
|
||||
/*
|
||||
* Make an additional record for completion domain.
|
||||
*/
|
||||
buflen -= RRFIXEDSZ;
|
||||
if ((n = dn_comp((u_char *)data, (u_char *)cp, buflen,
|
||||
(u_char **)dnptrs, (u_char **)lastdnptr)) < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
buflen -= n;
|
||||
__putshort(T_NULL, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putshort(class, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putlong(0, (u_char *)cp);
|
||||
cp += sizeof(u_int32_t);
|
||||
__putshort(0, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
hp->arcount = htons(1);
|
||||
break;
|
||||
|
||||
case IQUERY:
|
||||
/*
|
||||
* Initialize answer section
|
||||
*/
|
||||
if (buflen < 1 + RRFIXEDSZ + datalen)
|
||||
return (-1);
|
||||
*cp++ = '\0'; /* no domain name */
|
||||
__putshort(type, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putshort(class, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putlong(0, (u_char *)cp);
|
||||
cp += sizeof(u_int32_t);
|
||||
__putshort(datalen, (u_char *)cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
if (datalen) {
|
||||
bcopy(data, cp, datalen);
|
||||
cp += datalen;
|
||||
}
|
||||
hp->ancount = htons(1);
|
||||
break;
|
||||
|
||||
#ifdef ALLOW_UPDATES
|
||||
/*
|
||||
* For UPDATEM/UPDATEMA, do UPDATED/UPDATEDA followed by UPDATEA
|
||||
* (Record to be modified is followed by its replacement in msg.)
|
||||
*/
|
||||
case UPDATEM:
|
||||
case UPDATEMA:
|
||||
|
||||
case UPDATED:
|
||||
/*
|
||||
* The res code for UPDATED and UPDATEDA is the same; user
|
||||
* calls them differently: specifies data for UPDATED; server
|
||||
* ignores data if specified for UPDATEDA.
|
||||
*/
|
||||
case UPDATEDA:
|
||||
buflen -= RRFIXEDSZ + datalen;
|
||||
if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
__putshort(type, cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putshort(class, cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putlong(0, cp);
|
||||
cp += sizeof(u_int32_t);
|
||||
__putshort(datalen, cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
if (datalen) {
|
||||
bcopy(data, cp, datalen);
|
||||
cp += datalen;
|
||||
}
|
||||
if ( (op == UPDATED) || (op == UPDATEDA) ) {
|
||||
hp->ancount = htons(0);
|
||||
break;
|
||||
}
|
||||
/* Else UPDATEM/UPDATEMA, so drop into code for UPDATEA */
|
||||
|
||||
case UPDATEA: /* Add new resource record */
|
||||
buflen -= RRFIXEDSZ + datalen;
|
||||
if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
|
||||
return (-1);
|
||||
cp += n;
|
||||
__putshort(newrr->r_type, cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putshort(newrr->r_class, cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
__putlong(0, cp);
|
||||
cp += sizeof(u_int32_t);
|
||||
__putshort(newrr->r_size, cp);
|
||||
cp += sizeof(u_int16_t);
|
||||
if (newrr->r_size) {
|
||||
bcopy(newrr->r_data, cp, newrr->r_size);
|
||||
cp += newrr->r_size;
|
||||
}
|
||||
hp->ancount = htons(0);
|
||||
break;
|
||||
|
||||
#endif /* ALLOW_UPDATES */
|
||||
}
|
||||
return (cp - buf);
|
||||
}
|
303
lib/libc/net/res_query.c
Normal file
303
lib/libc/net/res_query.c
Normal file
@ -0,0 +1,303 @@
|
||||
/*-
|
||||
* Copyright (c) 1988, 1993
|
||||
* 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.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
|
||||
static char rcsid[] = "$Id: res_query.c,v 1.1 1993/06/01 09:42:14 vixie Exp vixie $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if PACKETSZ > 1024
|
||||
#define MAXPACKET PACKETSZ
|
||||
#else
|
||||
#define MAXPACKET 1024
|
||||
#endif
|
||||
|
||||
int h_errno;
|
||||
|
||||
/*
|
||||
* Formulate a normal query, send, and await answer.
|
||||
* Returned answer is placed in supplied buffer "answer".
|
||||
* Perform preliminary check of answer, returning success only
|
||||
* if no error is indicated and the answer count is nonzero.
|
||||
* Return the size of the response on success, -1 on error.
|
||||
* Error number is left in h_errno.
|
||||
* Caller must parse answer and determine whether it answers the question.
|
||||
*/
|
||||
res_query(name, class, type, answer, anslen)
|
||||
char *name; /* domain name */
|
||||
int class, type; /* class and type of query */
|
||||
u_char *answer; /* buffer to put answer */
|
||||
int anslen; /* size of answer buffer */
|
||||
{
|
||||
char buf[MAXPACKET];
|
||||
HEADER *hp;
|
||||
int n;
|
||||
|
||||
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
|
||||
return (-1);
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; res_query(%s, %d, %d)\n", name, class, type);
|
||||
#endif
|
||||
n = res_mkquery(QUERY, name, class, type, (char *)NULL, 0, NULL,
|
||||
buf, sizeof(buf));
|
||||
|
||||
if (n <= 0) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; res_query: mkquery failed\n");
|
||||
#endif
|
||||
h_errno = NO_RECOVERY;
|
||||
return (n);
|
||||
}
|
||||
n = res_send(buf, n, (char *)answer, anslen);
|
||||
if (n < 0) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; res_query: send error\n");
|
||||
#endif
|
||||
h_errno = TRY_AGAIN;
|
||||
return(n);
|
||||
}
|
||||
|
||||
hp = (HEADER *) answer;
|
||||
if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; rcode = %d, ancount=%d\n", hp->rcode,
|
||||
ntohs(hp->ancount));
|
||||
#endif
|
||||
switch (hp->rcode) {
|
||||
case NXDOMAIN:
|
||||
h_errno = HOST_NOT_FOUND;
|
||||
break;
|
||||
case SERVFAIL:
|
||||
h_errno = TRY_AGAIN;
|
||||
break;
|
||||
case NOERROR:
|
||||
h_errno = NO_DATA;
|
||||
break;
|
||||
case FORMERR:
|
||||
case NOTIMP:
|
||||
case REFUSED:
|
||||
default:
|
||||
h_errno = NO_RECOVERY;
|
||||
break;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
/*
|
||||
* Formulate a normal query, send, and retrieve answer in supplied buffer.
|
||||
* Return the size of the response on success, -1 on error.
|
||||
* If enabled, implement search rules until answer or unrecoverable failure
|
||||
* is detected. Error number is left in h_errno.
|
||||
* Only useful for queries in the same name hierarchy as the local host
|
||||
* (not, for example, for host address-to-name lookups in domain in-addr.arpa).
|
||||
*/
|
||||
int
|
||||
res_search(name, class, type, answer, anslen)
|
||||
char *name; /* domain name */
|
||||
int class, type; /* class and type of query */
|
||||
u_char *answer; /* buffer to put answer */
|
||||
int anslen; /* size of answer */
|
||||
{
|
||||
register char *cp, **domain;
|
||||
int n, ret, got_nodata = 0;
|
||||
char *__hostalias();
|
||||
|
||||
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
|
||||
return (-1);
|
||||
|
||||
errno = 0;
|
||||
h_errno = HOST_NOT_FOUND; /* default, if we never query */
|
||||
for (cp = name, n = 0; *cp; cp++)
|
||||
if (*cp == '.')
|
||||
n++;
|
||||
if (n == 0 && (cp = __hostalias(name)))
|
||||
return (res_query(cp, class, type, answer, anslen));
|
||||
|
||||
/*
|
||||
* We do at least one level of search if
|
||||
* - there is no dot and RES_DEFNAME is set, or
|
||||
* - there is at least one dot, there is no trailing dot,
|
||||
* and RES_DNSRCH is set.
|
||||
*/
|
||||
if ((n == 0 && _res.options & RES_DEFNAMES) ||
|
||||
(n != 0 && *--cp != '.' && _res.options & RES_DNSRCH))
|
||||
for (domain = _res.dnsrch; *domain; domain++) {
|
||||
ret = res_querydomain(name, *domain, class, type,
|
||||
answer, anslen);
|
||||
if (ret > 0)
|
||||
return (ret);
|
||||
/*
|
||||
* If no server present, give up.
|
||||
* If name isn't found in this domain,
|
||||
* keep trying higher domains in the search list
|
||||
* (if that's enabled).
|
||||
* On a NO_DATA error, keep trying, otherwise
|
||||
* a wildcard entry of another type could keep us
|
||||
* from finding this entry higher in the domain.
|
||||
* If we get some other error (negative answer or
|
||||
* server failure), then stop searching up,
|
||||
* but try the input name below in case it's fully-qualified.
|
||||
*/
|
||||
if (errno == ECONNREFUSED) {
|
||||
h_errno = TRY_AGAIN;
|
||||
return (-1);
|
||||
}
|
||||
if (h_errno == NO_DATA)
|
||||
got_nodata++;
|
||||
if ((h_errno != HOST_NOT_FOUND && h_errno != NO_DATA) ||
|
||||
(_res.options & RES_DNSRCH) == 0)
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* If the search/default failed, try the name as fully-qualified,
|
||||
* but only if it contained at least one dot (even trailing).
|
||||
* This is purely a heuristic; we assume that any reasonable query
|
||||
* about a top-level domain (for servers, SOA, etc) will not use
|
||||
* res_search.
|
||||
*/
|
||||
if (n && (ret = res_querydomain(name, (char *)NULL, class, type,
|
||||
answer, anslen)) > 0)
|
||||
return (ret);
|
||||
if (got_nodata)
|
||||
h_errno = NO_DATA;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform a call on res_query on the concatenation of name and domain,
|
||||
* removing a trailing dot from name if domain is NULL.
|
||||
*/
|
||||
res_querydomain(name, domain, class, type, answer, anslen)
|
||||
char *name, *domain;
|
||||
int class, type; /* class and type of query */
|
||||
u_char *answer; /* buffer to put answer */
|
||||
int anslen; /* size of answer */
|
||||
{
|
||||
char nbuf[2*MAXDNAME+2];
|
||||
char *longname = nbuf;
|
||||
int n;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; res_querydomain(%s, %s, %d, %d)\n",
|
||||
name, domain, class, type);
|
||||
#endif
|
||||
if (domain == NULL) {
|
||||
/*
|
||||
* Check for trailing '.';
|
||||
* copy without '.' if present.
|
||||
*/
|
||||
n = strlen(name) - 1;
|
||||
if (name[n] == '.' && n < sizeof(nbuf) - 1) {
|
||||
bcopy(name, nbuf, n);
|
||||
nbuf[n] = '\0';
|
||||
} else
|
||||
longname = name;
|
||||
} else
|
||||
(void)sprintf(nbuf, "%.*s.%.*s",
|
||||
MAXDNAME, name, MAXDNAME, domain);
|
||||
|
||||
return (res_query(longname, class, type, answer, anslen));
|
||||
}
|
||||
|
||||
char *
|
||||
__hostalias(name)
|
||||
register const char *name;
|
||||
{
|
||||
register char *C1, *C2;
|
||||
FILE *fp;
|
||||
char *file, *getenv(), *strcpy(), *strncpy();
|
||||
char buf[BUFSIZ];
|
||||
static char abuf[MAXDNAME];
|
||||
|
||||
file = getenv("HOSTALIASES");
|
||||
if (file == NULL || (fp = fopen(file, "r")) == NULL)
|
||||
return (NULL);
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
while (fgets(buf, sizeof(buf), fp)) {
|
||||
for (C1 = buf; *C1 && !isspace(*C1); ++C1);
|
||||
if (!*C1)
|
||||
break;
|
||||
*C1 = '\0';
|
||||
if (!strcasecmp(buf, name)) {
|
||||
while (isspace(*++C1));
|
||||
if (!*C1)
|
||||
break;
|
||||
for (C2 = C1 + 1; *C2 && !isspace(*C2); ++C2);
|
||||
abuf[sizeof(abuf) - 1] = *C2 = '\0';
|
||||
(void)strncpy(abuf, C1, sizeof(abuf) - 1);
|
||||
fclose(fp);
|
||||
return (abuf);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
return (NULL);
|
||||
}
|
468
lib/libc/net/res_send.c
Normal file
468
lib/libc/net/res_send.c
Normal file
@ -0,0 +1,468 @@
|
||||
/*-
|
||||
* Copyright (c) 1985, 1989, 1993
|
||||
* 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.
|
||||
* -
|
||||
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies, and that
|
||||
* the name of Digital Equipment Corporation not be used in advertising or
|
||||
* publicity pertaining to distribution of the document or software without
|
||||
* specific, written prior permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
* SOFTWARE.
|
||||
* -
|
||||
* --Copyright--
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
|
||||
static char rcsid[] = "$Id: res_send.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
/*
|
||||
* Send query to name server and wait for reply.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <resolv.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
static int s = -1; /* socket used for communications */
|
||||
static struct sockaddr no_addr;
|
||||
|
||||
#ifndef FD_SET
|
||||
#define NFDBITS 32
|
||||
#define FD_SETSIZE 32
|
||||
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
|
||||
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
|
||||
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
|
||||
#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
|
||||
#endif
|
||||
|
||||
res_send(buf, buflen, answer, anslen)
|
||||
const char *buf;
|
||||
int buflen;
|
||||
char *answer;
|
||||
int anslen;
|
||||
{
|
||||
register int n;
|
||||
int try, v_circuit, resplen, ns;
|
||||
int gotsomewhere = 0, connected = 0;
|
||||
int connreset = 0;
|
||||
u_short id, len;
|
||||
char *cp;
|
||||
fd_set dsmask;
|
||||
struct timeval timeout;
|
||||
HEADER *hp = (HEADER *) buf;
|
||||
HEADER *anhp = (HEADER *) answer;
|
||||
u_int badns; /* XXX NSMAX can't exceed #/bits per this */
|
||||
struct iovec iov[2];
|
||||
int terrno = ETIMEDOUT;
|
||||
char junk[512];
|
||||
|
||||
#ifdef DEBUG
|
||||
if ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY)) {
|
||||
printf(";; res_send()\n");
|
||||
__p_query(buf);
|
||||
}
|
||||
#endif
|
||||
if (!(_res.options & RES_INIT))
|
||||
if (res_init() == -1) {
|
||||
return(-1);
|
||||
}
|
||||
v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
|
||||
id = hp->id;
|
||||
badns = 0;
|
||||
/*
|
||||
* Send request, RETRY times, or until successful
|
||||
*/
|
||||
for (try = 0; try < _res.retry; try++) {
|
||||
for (ns = 0; ns < _res.nscount; ns++) {
|
||||
if (badns & (1<<ns))
|
||||
continue;
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; Querying server (# %d) address = %s\n",
|
||||
ns+1,
|
||||
inet_ntoa(_res.nsaddr_list[ns].sin_addr));
|
||||
#endif
|
||||
usevc:
|
||||
if (v_circuit) {
|
||||
int truncated = 0;
|
||||
|
||||
/*
|
||||
* Use virtual circuit;
|
||||
* at most one attempt per server.
|
||||
*/
|
||||
try = _res.retry;
|
||||
if (s < 0) {
|
||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
terrno = errno;
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("socket (vc) failed");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
if (connect(s,
|
||||
(struct sockaddr *)&(_res.nsaddr_list[ns]),
|
||||
sizeof(struct sockaddr)) < 0) {
|
||||
terrno = errno;
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("connect failed");
|
||||
#endif
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Send length & message
|
||||
*/
|
||||
len = htons((u_short)buflen);
|
||||
iov[0].iov_base = (caddr_t)&len;
|
||||
iov[0].iov_len = sizeof(len);
|
||||
iov[1].iov_base = (char *)buf;
|
||||
iov[1].iov_len = buflen;
|
||||
if (writev(s, iov, 2) != sizeof(len) + buflen) {
|
||||
terrno = errno;
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("write failed");
|
||||
#endif
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* Receive length & response
|
||||
*/
|
||||
cp = answer;
|
||||
len = sizeof(short);
|
||||
while (len != 0 &&
|
||||
(n = read(s, (char *)cp, (int)len)) > 0) {
|
||||
cp += n;
|
||||
len -= n;
|
||||
}
|
||||
if (n <= 0) {
|
||||
terrno = errno;
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("read failed");
|
||||
#endif
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
/*
|
||||
* A long running process might get its TCP
|
||||
* connection reset if the remote server was
|
||||
* restarted. Requery the server instead of
|
||||
* trying a new one. When there is only one
|
||||
* server, this means that a query might work
|
||||
* instead of failing. We only allow one reset
|
||||
* per query to prevent looping.
|
||||
*/
|
||||
if (terrno == ECONNRESET && !connreset) {
|
||||
connreset = 1;
|
||||
ns--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
cp = answer;
|
||||
if ((resplen = ntohs(*(u_short *)cp)) > anslen) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
fprintf(stderr,
|
||||
";; response truncated\n");
|
||||
#endif
|
||||
len = anslen;
|
||||
truncated = 1;
|
||||
} else
|
||||
len = resplen;
|
||||
while (len != 0 &&
|
||||
(n = read(s, (char *)cp, (int)len)) > 0) {
|
||||
cp += n;
|
||||
len -= n;
|
||||
}
|
||||
if (n <= 0) {
|
||||
terrno = errno;
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("read failed");
|
||||
#endif
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
continue;
|
||||
}
|
||||
if (truncated) {
|
||||
/*
|
||||
* Flush rest of answer
|
||||
* so connection stays in synch.
|
||||
*/
|
||||
anhp->tc = 1;
|
||||
len = resplen - anslen;
|
||||
while (len != 0) {
|
||||
n = (len > sizeof(junk) ?
|
||||
sizeof(junk) : len);
|
||||
if ((n = read(s, junk, n)) > 0)
|
||||
len -= n;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Use datagrams.
|
||||
*/
|
||||
if (s < 0) {
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
terrno = errno;
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("socket (dg) failed");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* I'm tired of answering this question, so:
|
||||
* On a 4.3BSD+ machine (client and server,
|
||||
* actually), sending to a nameserver datagram
|
||||
* port with no nameserver will cause an
|
||||
* ICMP port unreachable message to be returned.
|
||||
* If our datagram socket is "connected" to the
|
||||
* server, we get an ECONNREFUSED error on the next
|
||||
* socket operation, and select returns if the
|
||||
* error message is received. We can thus detect
|
||||
* the absence of a nameserver without timing out.
|
||||
* If we have sent queries to at least two servers,
|
||||
* however, we don't want to remain connected,
|
||||
* as we wish to receive answers from the first
|
||||
* server to respond.
|
||||
*/
|
||||
if (_res.nscount == 1 || (try == 0 && ns == 0)) {
|
||||
/*
|
||||
* Don't use connect if we might
|
||||
* still receive a response
|
||||
* from another server.
|
||||
*/
|
||||
if (connected == 0) {
|
||||
if (connect(s,
|
||||
(struct sockaddr *)
|
||||
&_res.nsaddr_list[ns],
|
||||
sizeof(struct sockaddr)) < 0) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("connect");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
connected = 1;
|
||||
}
|
||||
if (send(s, buf, buflen, 0) != buflen) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("send");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Disconnect if we want to listen
|
||||
* for responses from more than one server.
|
||||
*/
|
||||
if (connected) {
|
||||
(void) connect(s, &no_addr,
|
||||
sizeof(no_addr));
|
||||
connected = 0;
|
||||
}
|
||||
if (sendto(s, buf, buflen, 0,
|
||||
(struct sockaddr *)&_res.nsaddr_list[ns],
|
||||
sizeof(struct sockaddr)) != buflen) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("sendto");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for reply
|
||||
*/
|
||||
timeout.tv_sec = (_res.retrans << try);
|
||||
if (try > 0)
|
||||
timeout.tv_sec /= _res.nscount;
|
||||
if ((long) timeout.tv_sec <= 0)
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
wait:
|
||||
FD_ZERO(&dsmask);
|
||||
FD_SET(s, &dsmask);
|
||||
n = select(s+1, &dsmask, (fd_set *)NULL,
|
||||
(fd_set *)NULL, &timeout);
|
||||
if (n < 0) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("select");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
if (n == 0) {
|
||||
/*
|
||||
* timeout
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; timeout\n");
|
||||
#endif
|
||||
gotsomewhere = 1;
|
||||
continue;
|
||||
}
|
||||
if ((resplen = recv(s, answer, anslen, 0)) <= 0) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
perror("recvfrom");
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
gotsomewhere = 1;
|
||||
if (id != anhp->id) {
|
||||
/*
|
||||
* response from old query, ignore it
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
if ((_res.options & RES_DEBUG) ||
|
||||
(_res.pfcode & RES_PRF_REPLY)) {
|
||||
printf(";; old answer:\n");
|
||||
__p_query(answer);
|
||||
}
|
||||
#endif
|
||||
goto wait;
|
||||
}
|
||||
if (anhp->rcode == SERVFAIL || anhp->rcode == NOTIMP ||
|
||||
anhp->rcode == REFUSED) {
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG) {
|
||||
printf("server rejected query:\n");
|
||||
__p_query(answer);
|
||||
}
|
||||
#endif
|
||||
badns |= (1<<ns);
|
||||
continue;
|
||||
}
|
||||
if (!(_res.options & RES_IGNTC) && anhp->tc) {
|
||||
/*
|
||||
* get rest of answer;
|
||||
* use TCP with same server.
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; truncated answer\n");
|
||||
#endif
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
v_circuit = 1;
|
||||
goto usevc;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (_res.options & RES_DEBUG)
|
||||
printf(";; got answer:\n");
|
||||
if ((_res.options & RES_DEBUG) ||
|
||||
(_res.pfcode & RES_PRF_REPLY))
|
||||
__p_query(answer);
|
||||
#endif
|
||||
/*
|
||||
* If using virtual circuits, we assume that the first server
|
||||
* is preferred * over the rest (i.e. it is on the local
|
||||
* machine) and only keep that one open.
|
||||
* If we have temporarily opened a virtual circuit,
|
||||
* or if we haven't been asked to keep a socket open,
|
||||
* close the socket.
|
||||
*/
|
||||
if ((v_circuit &&
|
||||
((_res.options & RES_USEVC) == 0 || ns != 0)) ||
|
||||
(_res.options & RES_STAYOPEN) == 0) {
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
}
|
||||
return (resplen);
|
||||
}
|
||||
}
|
||||
if (s >= 0) {
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
}
|
||||
if (v_circuit == 0)
|
||||
if (gotsomewhere == 0)
|
||||
errno = ECONNREFUSED; /* no nameservers found */
|
||||
else
|
||||
errno = ETIMEDOUT; /* no answer obtained */
|
||||
else
|
||||
errno = terrno;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine is for closing the socket if a virtual circuit is used and
|
||||
* the program wants to close it. This provides support for endhostent()
|
||||
* which expects to close the socket.
|
||||
*
|
||||
* This routine is not expected to be user visible.
|
||||
*/
|
||||
_res_close()
|
||||
{
|
||||
if (s != -1) {
|
||||
(void) close(s);
|
||||
s = -1;
|
||||
}
|
||||
}
|
56
lib/libc/net/sethostent.c
Normal file
56
lib/libc/net/sethostent.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 1985, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)sethostent.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <netdb.h>
|
||||
#include <resolv.h>
|
||||
|
||||
void
|
||||
sethostent(stayopen)
|
||||
{
|
||||
if (stayopen)
|
||||
_res.options |= RES_STAYOPEN | RES_USEVC;
|
||||
}
|
||||
|
||||
void
|
||||
endhostent()
|
||||
{
|
||||
_res.options &= ~(RES_STAYOPEN | RES_USEVC);
|
||||
_res_close();
|
||||
}
|
81
lib/libc/stdlib/free.3
Normal file
81
lib/libc/stdlib/free.3
Normal file
@ -0,0 +1,81 @@
|
||||
.\" Copyright (c) 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the American National Standards Committee X3, on Information
|
||||
.\" Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)free.3 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt FREE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm free
|
||||
.Nd free up memory allocated with malloc, calloc or realloc
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <stdlib.h>
|
||||
.Ft void
|
||||
.Fn free "void *ptr"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn free
|
||||
function causes the space pointed to by
|
||||
.Fa ptr
|
||||
to be deallocated, that is, made available
|
||||
for further allocation.
|
||||
If
|
||||
.Fa ptr
|
||||
is a null pointer, no action occurs.
|
||||
Otherwise, if the argument does not match a pointer earlier
|
||||
returned by the
|
||||
.Xr calloc ,
|
||||
.Xr malloc ,
|
||||
or
|
||||
.Xr realloc
|
||||
function, or if the space has been deallocated by a call to
|
||||
.Fn free
|
||||
or
|
||||
.Xr realloc ,
|
||||
general havoc may occur.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn free
|
||||
function returns no value.
|
||||
.Sh SEE ALSO
|
||||
.Xr calloc 3 ,
|
||||
.Xr malloc 3 ,
|
||||
.Xr realloc 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn free
|
||||
function conforms to
|
||||
.St -ansiC .
|
99
lib/libc/stdlib/realloc.3
Normal file
99
lib/libc/stdlib/realloc.3
Normal file
@ -0,0 +1,99 @@
|
||||
.\" Copyright (c) 1991, 1993
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)realloc.3 8.2 (Berkeley) 4/19/94
|
||||
.\"
|
||||
.Dd April 19, 1994
|
||||
.Dt REALLOC 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm realloc
|
||||
.Nd reallocation of memory function
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <stdlib.h>
|
||||
.Ft void *
|
||||
.Fn realloc "void *ptr" "size_t size"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn realloc
|
||||
function changes the size of the object pointed to by
|
||||
.Fa ptr
|
||||
to the size specified by
|
||||
.Fa size .
|
||||
The contents of the object are unchanged up to the lesser
|
||||
of the new and old sizes.
|
||||
If the new size is larger, the value of the newly allocated portion
|
||||
of the object is indeterminate.
|
||||
If
|
||||
.Fa ptr
|
||||
is a null pointer, the
|
||||
.Fn realloc
|
||||
function behaves like the
|
||||
.Xr malloc 3
|
||||
function for the specified size.
|
||||
Otherwise, if
|
||||
.Fa ptr
|
||||
does not match a pointer earlier returned by the
|
||||
.Xr calloc 3 ,
|
||||
.Xr malloc 3 ,
|
||||
or
|
||||
.Fn realloc
|
||||
function, or if the space has been deallocated
|
||||
by a call to the
|
||||
.Xr free
|
||||
or
|
||||
.Fn realloc
|
||||
function, unpredictable and usually detrimental
|
||||
behavior will occur.
|
||||
If the space cannot be allocated, the object
|
||||
pointed to by
|
||||
.Fa ptr
|
||||
is unchanged.
|
||||
If
|
||||
.Fa size
|
||||
is zero and
|
||||
.Fa ptr
|
||||
is not a null pointer, the object it points to is freed.
|
||||
.Pp
|
||||
The
|
||||
.Fn realloc
|
||||
function returns either a null pointer or a pointer
|
||||
to the possibly moved allocated space.
|
||||
.Sh SEE ALSO
|
||||
.Xr alloca 3 ,
|
||||
.Xr calloc 3 ,
|
||||
.Xr free 3 ,
|
||||
.Xr malloc 3 ,
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn realloc
|
||||
function conforms to
|
||||
.St -ansiC .
|
186
lib/libc/string/strftime.3
Normal file
186
lib/libc/string/strftime.3
Normal file
@ -0,0 +1,186 @@
|
||||
.\" Copyright (c) 1989, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the American National Standards Committee X3, on Information
|
||||
.\" Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt STRFTIME 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strftime
|
||||
.Nd format date and time
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <sys/types.h>
|
||||
.Fd #include <time.h>
|
||||
.Fd #include <string.h>
|
||||
.Ft size_t
|
||||
.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strftime
|
||||
function formats the information from
|
||||
.Fa timeptr
|
||||
into the buffer
|
||||
.Fa buf
|
||||
according to the string pointed to by
|
||||
.Fa format .
|
||||
.Pp
|
||||
The
|
||||
.Fa format
|
||||
string consists of zero or more conversion specifications and
|
||||
ordinary characters.
|
||||
All ordinary characters are copied directly into the buffer.
|
||||
A conversion specification consists of a percent sign
|
||||
.Dq Ql %
|
||||
and one other character.
|
||||
.Pp
|
||||
No more than
|
||||
.Fa maxsize
|
||||
characters will be placed into the array.
|
||||
If the total number of resulting characters, including the terminating
|
||||
null character, is not more than
|
||||
.Fa maxsize ,
|
||||
.Fn strftime
|
||||
returns the number of characters in the array, not counting the
|
||||
terminating null.
|
||||
Otherwise, zero is returned.
|
||||
.Pp
|
||||
Each conversion specification is replaced by the characters as
|
||||
follows which are then copied into the buffer.
|
||||
.Bl -tag -width "xxxx"
|
||||
.It Cm \&%A
|
||||
is replaced by the full weekday name.
|
||||
.It Cm %a
|
||||
is replaced by the abbreviated weekday name, where the abbreviation
|
||||
is the first three characters.
|
||||
.It Cm \&%B
|
||||
is replaced by the full month name.
|
||||
.It Cm %b or %h
|
||||
is replaced by the abbreviated month name, where the abbreviation is
|
||||
the first three characters.
|
||||
.It Cm \&%C
|
||||
is equivalent to
|
||||
.Dq Li %a %b %e %H:%M:%S %Y
|
||||
(the format produced by
|
||||
.Xr asctime 3 .
|
||||
.It Cm %c
|
||||
is equivalent to
|
||||
.Dq Li %m/%d/%y .
|
||||
.It Cm \&%D
|
||||
is replaced by the date in the format
|
||||
.Dq Ql mm/dd/yy .
|
||||
.It Cm %d
|
||||
is replaced by the day of the month as a decimal number (01-31).
|
||||
.It Cm %e
|
||||
is replaced by the day of month as a decimal number (1-31); single
|
||||
digits are preceded by a blank.
|
||||
.It Cm \&%H
|
||||
is replaced by the hour (24-hour clock) as a decimal number (00-23).
|
||||
.It Cm \&%I
|
||||
is replaced by the hour (12-hour clock) as a decimal number (01-12).
|
||||
.It Cm %j
|
||||
is replaced by the day of the year as a decimal number (001-366).
|
||||
.It Cm %k
|
||||
is replaced by the hour (24-hour clock) as a decimal number (0-23);
|
||||
single digits are preceded by a blank.
|
||||
.It Cm %l
|
||||
is replaced by the hour (12-hour clock) as a decimal number (1-12);
|
||||
single digits are preceded by a blank.
|
||||
.It Cm \&%M
|
||||
is replaced by the minute as a decimal number (00-59).
|
||||
.It Cm %m
|
||||
is replaced by the month as a decimal number (01-12).
|
||||
.It Cm %n
|
||||
is replaced by a newline.
|
||||
.It Cm %p
|
||||
is replaced by either
|
||||
.Dq Tn AM
|
||||
or
|
||||
.Dq Tn PM
|
||||
as appropriate.
|
||||
.It Cm \&%R
|
||||
is equivalent to
|
||||
.Dq Li %H:%M
|
||||
.It Cm %r
|
||||
is equivalent to
|
||||
.Dq Li %I:%M:%S %p .
|
||||
.It Cm %t
|
||||
is replaced by a tab.
|
||||
.It Cm \&%S
|
||||
is replaced by the second as a decimal number (00-60).
|
||||
.It Cm %s
|
||||
is replaced by the number of seconds since the Epoch, UCT (see
|
||||
.Xr mktime 3 ) .
|
||||
.It Cm \&%T No or Cm \&%X
|
||||
is equivalent to
|
||||
.Dq Li %H:%M:%S .
|
||||
.It Cm \&%U
|
||||
is replaced by the week number of the year (Sunday as the first day of
|
||||
the week) as a decimal number (00-53).
|
||||
.It Cm \&%W
|
||||
is replaced by the week number of the year (Monday as the first day of
|
||||
the week) as a decimal number (00-53).
|
||||
.It Cm %w
|
||||
is replaced by the weekday (Sunday as the first day of the week)
|
||||
as a decimal number (0-6).
|
||||
.It Cm %x
|
||||
is equivalent to
|
||||
.Dq Li %m/%d/%y %H:%M:%S .
|
||||
.It Cm \&%Y
|
||||
is replaced by the year with century as a decimal number.
|
||||
.It Cm %y
|
||||
is replaced by the year without century as a decimal number (00-99).
|
||||
.It Cm \&%Z
|
||||
is replaced by the time zone name.
|
||||
.It Cm %%
|
||||
is replaced by
|
||||
.Ql % .
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr date 1 ,
|
||||
.Xr ctime 3 ,
|
||||
.Xr printf 1 ,
|
||||
.Xr printf 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strftime
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
The
|
||||
.Ql %s
|
||||
conversion specification is an extension.
|
||||
.Sh BUGS
|
||||
There is no conversion specification for the phase of the moon.
|
292
lib/libc/string/strftime.c
Normal file
292
lib/libc/string/strftime.c
Normal file
@ -0,0 +1,292 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)strftime.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <tzfile.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *afmt[] = {
|
||||
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
|
||||
};
|
||||
static char *Afmt[] = {
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
|
||||
"Saturday",
|
||||
};
|
||||
static char *bfmt[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
|
||||
"Oct", "Nov", "Dec",
|
||||
};
|
||||
static char *Bfmt[] = {
|
||||
"January", "February", "March", "April", "May", "June", "July",
|
||||
"August", "September", "October", "November", "December",
|
||||
};
|
||||
|
||||
static size_t gsize;
|
||||
static char *pt;
|
||||
static int _add __P((char *));
|
||||
static int _conv __P((int, int, int));
|
||||
static int _secs __P((const struct tm *));
|
||||
static size_t _fmt __P((const char *, const struct tm *));
|
||||
|
||||
size_t
|
||||
strftime(s, maxsize, format, t)
|
||||
char *s;
|
||||
size_t maxsize;
|
||||
const char *format;
|
||||
const struct tm *t;
|
||||
{
|
||||
|
||||
pt = s;
|
||||
if ((gsize = maxsize) < 1)
|
||||
return(0);
|
||||
if (_fmt(format, t)) {
|
||||
*pt = '\0';
|
||||
return(maxsize - gsize);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
static size_t
|
||||
_fmt(format, t)
|
||||
register const char *format;
|
||||
const struct tm *t;
|
||||
{
|
||||
for (; *format; ++format) {
|
||||
if (*format == '%')
|
||||
switch(*++format) {
|
||||
case '\0':
|
||||
--format;
|
||||
break;
|
||||
case 'A':
|
||||
if (t->tm_wday < 0 || t->tm_wday > 6)
|
||||
return(0);
|
||||
if (!_add(Afmt[t->tm_wday]))
|
||||
return(0);
|
||||
continue;
|
||||
case 'a':
|
||||
if (t->tm_wday < 0 || t->tm_wday > 6)
|
||||
return(0);
|
||||
if (!_add(afmt[t->tm_wday]))
|
||||
return(0);
|
||||
continue;
|
||||
case 'B':
|
||||
if (t->tm_mon < 0 || t->tm_mon > 11)
|
||||
return(0);
|
||||
if (!_add(Bfmt[t->tm_mon]))
|
||||
return(0);
|
||||
continue;
|
||||
case 'b':
|
||||
case 'h':
|
||||
if (t->tm_mon < 0 || t->tm_mon > 11)
|
||||
return(0);
|
||||
if (!_add(bfmt[t->tm_mon]))
|
||||
return(0);
|
||||
continue;
|
||||
case 'C':
|
||||
if (!_fmt("%a %b %e %H:%M:%S %Y", t))
|
||||
return(0);
|
||||
continue;
|
||||
case 'c':
|
||||
if (!_fmt("%m/%d/%y %H:%M:%S", t))
|
||||
return(0);
|
||||
continue;
|
||||
case 'D':
|
||||
if (!_fmt("%m/%d/%y", t))
|
||||
return(0);
|
||||
continue;
|
||||
case 'd':
|
||||
if (!_conv(t->tm_mday, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'e':
|
||||
if (!_conv(t->tm_mday, 2, ' '))
|
||||
return(0);
|
||||
continue;
|
||||
case 'H':
|
||||
if (!_conv(t->tm_hour, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'I':
|
||||
if (!_conv(t->tm_hour % 12 ?
|
||||
t->tm_hour % 12 : 12, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'j':
|
||||
if (!_conv(t->tm_yday + 1, 3, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'k':
|
||||
if (!_conv(t->tm_hour, 2, ' '))
|
||||
return(0);
|
||||
continue;
|
||||
case 'l':
|
||||
if (!_conv(t->tm_hour % 12 ?
|
||||
t->tm_hour % 12 : 12, 2, ' '))
|
||||
return(0);
|
||||
continue;
|
||||
case 'M':
|
||||
if (!_conv(t->tm_min, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'm':
|
||||
if (!_conv(t->tm_mon + 1, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'n':
|
||||
if (!_add("\n"))
|
||||
return(0);
|
||||
continue;
|
||||
case 'p':
|
||||
if (!_add(t->tm_hour >= 12 ? "PM" : "AM"))
|
||||
return(0);
|
||||
continue;
|
||||
case 'R':
|
||||
if (!_fmt("%H:%M", t))
|
||||
return(0);
|
||||
continue;
|
||||
case 'r':
|
||||
if (!_fmt("%I:%M:%S %p", t))
|
||||
return(0);
|
||||
continue;
|
||||
case 'S':
|
||||
if (!_conv(t->tm_sec, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 's':
|
||||
if (!_secs(t))
|
||||
return(0);
|
||||
continue;
|
||||
case 'T':
|
||||
case 'X':
|
||||
if (!_fmt("%H:%M:%S", t))
|
||||
return(0);
|
||||
continue;
|
||||
case 't':
|
||||
if (!_add("\t"))
|
||||
return(0);
|
||||
continue;
|
||||
case 'U':
|
||||
if (!_conv((t->tm_yday + 7 - t->tm_wday) / 7,
|
||||
2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'W':
|
||||
if (!_conv((t->tm_yday + 7 -
|
||||
(t->tm_wday ? (t->tm_wday - 1) : 6))
|
||||
/ 7, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'w':
|
||||
if (!_conv(t->tm_wday, 1, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'x':
|
||||
if (!_fmt("%m/%d/%y", t))
|
||||
return(0);
|
||||
continue;
|
||||
case 'y':
|
||||
if (!_conv((t->tm_year + TM_YEAR_BASE)
|
||||
% 100, 2, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'Y':
|
||||
if (!_conv(t->tm_year + TM_YEAR_BASE, 4, '0'))
|
||||
return(0);
|
||||
continue;
|
||||
case 'Z':
|
||||
if (!t->tm_zone || !_add(t->tm_zone))
|
||||
return(0);
|
||||
continue;
|
||||
case '%':
|
||||
/*
|
||||
* X311J/88-090 (4.12.3.5): if conversion char is
|
||||
* undefined, behavior is undefined. Print out the
|
||||
* character itself as printf(3) does.
|
||||
*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!gsize--)
|
||||
return(0);
|
||||
*pt++ = *format;
|
||||
}
|
||||
return(gsize);
|
||||
}
|
||||
|
||||
static int
|
||||
_secs(t)
|
||||
const struct tm *t;
|
||||
{
|
||||
static char buf[15];
|
||||
register time_t s;
|
||||
register char *p;
|
||||
struct tm tmp;
|
||||
|
||||
/* Make a copy, mktime(3) modifies the tm struct. */
|
||||
tmp = *t;
|
||||
s = mktime(&tmp);
|
||||
for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10)
|
||||
*p-- = s % 10 + '0';
|
||||
return(_add(++p));
|
||||
}
|
||||
|
||||
static int
|
||||
_conv(n, digits, pad)
|
||||
int n, digits, pad;
|
||||
{
|
||||
static char buf[10];
|
||||
register char *p;
|
||||
|
||||
for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits)
|
||||
*p-- = n % 10 + '0';
|
||||
while (p > buf && digits-- > 0)
|
||||
*p-- = pad;
|
||||
return(_add(++p));
|
||||
}
|
||||
|
||||
static int
|
||||
_add(str)
|
||||
register char *str;
|
||||
{
|
||||
for (;; ++pt, --gsize) {
|
||||
if (!gsize)
|
||||
return(0);
|
||||
if (!(*pt = *str++))
|
||||
return(1);
|
||||
}
|
||||
}
|
21
lib/libcompat/regexp/regexp.h
Normal file
21
lib/libcompat/regexp/regexp.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Definitions etc. for regexp(3) routines.
|
||||
*
|
||||
* Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
|
||||
* not the System V one.
|
||||
*/
|
||||
#define NSUBEXP 10
|
||||
typedef struct regexp {
|
||||
char *startp[NSUBEXP];
|
||||
char *endp[NSUBEXP];
|
||||
char regstart; /* Internal use only. */
|
||||
char reganch; /* Internal use only. */
|
||||
char *regmust; /* Internal use only. */
|
||||
int regmlen; /* Internal use only. */
|
||||
char program[1]; /* Unwarranted chumminess with compiler. */
|
||||
} regexp;
|
||||
|
||||
extern regexp *regcomp();
|
||||
extern int regexec();
|
||||
extern void regsub();
|
||||
extern void regerror();
|
35
lib/libcurses/PSD.doc/Makefile
Normal file
35
lib/libcurses/PSD.doc/Makefile
Normal file
@ -0,0 +1,35 @@
|
||||
# @(#)Makefile 8.2 (Berkeley) 5/23/94
|
||||
|
||||
DIR= psd/19.curses
|
||||
SRCS= Master
|
||||
MACROS= -me
|
||||
|
||||
CLEANFILES+=win_st.gr twinkle1.gr twinkle2.gr life.gr intro.2.tbl appen.A.tbl \
|
||||
ex1.gr ex2.gr
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .gr
|
||||
|
||||
#
|
||||
# this section formats C input source into nice troffable (or nroffable)
|
||||
# versions. It uses the capabilites of "vgrind", which sets keywords in
|
||||
# bold font, and comments in italics.
|
||||
#
|
||||
|
||||
# Don't re-run vgrind unless you want to patch the output files.
|
||||
VFONT= /usr/libexec/vfontedpr
|
||||
.c.gr:
|
||||
${VFONT} $*.c | grep -v "^'wh" > $*.gr
|
||||
|
||||
paper.ps: ${SRCS}
|
||||
soelim ${SRCS} | ${ROFF} > ${.TARGET}
|
||||
|
||||
Master: twinkle1.gr ex1.gr ex2.gr fns.doc intro.5 intro.2.tbl intro.0 intro.1 \
|
||||
intro.3 intro.4 intro.6 macros c_macros
|
||||
|
||||
intro.2.tbl: intro.2
|
||||
${TBL} intro.2 > intro.2.tbl
|
||||
|
||||
.include <bsd.doc.mk>
|
||||
|
||||
|
54
lib/libcurses/PSD.doc/Master
Normal file
54
lib/libcurses/PSD.doc/Master
Normal file
@ -0,0 +1,54 @@
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)Master 8.2 (Berkeley) 5/24/94
|
||||
.\"
|
||||
.ds Ln Screen Package
|
||||
.so macros
|
||||
.so c_macros
|
||||
.so intro.0
|
||||
.pn 3
|
||||
.bp
|
||||
.so intro.1
|
||||
.so intro.2.tbl
|
||||
.so intro.3
|
||||
.so intro.4
|
||||
.so intro.5
|
||||
.so intro.6
|
||||
.bp
|
||||
.so appen.A
|
||||
.pn 2
|
||||
.oh '\*(Ln''PSD:19-%'
|
||||
.eh 'PSD:19-%''\*(Ln'
|
||||
.bp
|
||||
.bi Contents
|
||||
.sp
|
||||
.xp
|
799
lib/libcurses/PSD.doc/fns.doc
Normal file
799
lib/libcurses/PSD.doc/fns.doc
Normal file
@ -0,0 +1,799 @@
|
||||
.\" Copyright (c) 1992, 1993
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)fns.doc 8.2 (Berkeley) 6/1/94
|
||||
.\"
|
||||
.Ds
|
||||
.Fn addch "char ch" \(dg
|
||||
.De
|
||||
Add the character
|
||||
.Vn ch
|
||||
on the window
|
||||
at the current \*y.
|
||||
If the character is a newline
|
||||
(\'\en\')
|
||||
the line will be cleared to the end,
|
||||
and the current \*y will be changed to the
|
||||
beginning off the next line
|
||||
if newline mapping is on,
|
||||
or to the next line at the same x co-ordinate
|
||||
if it is off.
|
||||
A return
|
||||
(\'\er\')
|
||||
will move to the beginning of the line on the window.
|
||||
Tabs
|
||||
(\'\et\')
|
||||
will be expanded into spaces
|
||||
in the normal tabstop positions of
|
||||
every eight characters.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fn addstr "char *str" \(dg
|
||||
.De
|
||||
Add the string pointed to by
|
||||
.Vn str
|
||||
on the window at the current \*y.
|
||||
\*(Es
|
||||
In this case, it will put on as much as it can.
|
||||
.Ds
|
||||
.Fn baudrate "" \(dg
|
||||
.De
|
||||
Returns the output baud rate of the terminal.
|
||||
This is a system dependent constant
|
||||
(defined in
|
||||
.b <sys/tty.h>
|
||||
on BSD systems,
|
||||
which is included by
|
||||
.b <curses.h> ).
|
||||
.Ds
|
||||
.Fn box "WINDOW win" "char vert" "char hor"
|
||||
.De
|
||||
.Pp
|
||||
Draws a box around the window using
|
||||
.Vn vert
|
||||
as the character for drawing the vertical sides, and
|
||||
.Vn hor
|
||||
for drawing the horizontal lines.
|
||||
If scrolling is not allowed,
|
||||
and the window encompasses the lower right-hand corner of the terminal,
|
||||
the corners are left blank to avoid a scroll.
|
||||
.Ds
|
||||
.Fn cbreak "" \(dg
|
||||
.De
|
||||
Set or the terminal to cbreak mode.
|
||||
.Ds
|
||||
.Fn clear "" \(dg
|
||||
.De
|
||||
Resets the entire window to blanks.
|
||||
If
|
||||
.Vn win
|
||||
is a screen,
|
||||
this sets the clear flag,
|
||||
which will cause a clear-screen sequence to be sent
|
||||
on the next
|
||||
.Fn refresh
|
||||
call.
|
||||
This also moves the current \*y
|
||||
to (0\*,0).
|
||||
.Ds
|
||||
.Fn clearok "WINDOW *scr" "int boolf" \(dg
|
||||
.De
|
||||
Sets the clear flag for the screen
|
||||
.Vn scr .
|
||||
If
|
||||
.Vn boolf
|
||||
is non-zero,
|
||||
this will force a clear-screen to be printed on the next
|
||||
.Fn refresh ,
|
||||
or stop it from doing so if
|
||||
.Vn boolf
|
||||
is 0.
|
||||
This only works on screens,
|
||||
and,
|
||||
unlike
|
||||
.Fn clear ,
|
||||
does not alter the contents of the screen.
|
||||
If
|
||||
.Vn scr
|
||||
is
|
||||
.Vn curscr ,
|
||||
the next
|
||||
.Fn refresh
|
||||
call will cause a clear-screen,
|
||||
even if the window passed to
|
||||
.Fn refresh
|
||||
is not a screen.
|
||||
.Ds
|
||||
.Fn clrtobot "" \(dg
|
||||
.De
|
||||
Wipes the window clear from the current \*y to the bottom.
|
||||
This does not force a clear-screen sequence on the next refresh
|
||||
under any circumstances.
|
||||
\*(Nm
|
||||
.Ds
|
||||
.Fn clrtoeol "" \(dg
|
||||
.De
|
||||
Wipes the window clear from the current \*y to the end of the line.
|
||||
\*(Nm
|
||||
.Ds
|
||||
.Fn crmode "" \(dg
|
||||
.De
|
||||
Identical to
|
||||
.Fn cbreak .
|
||||
The misnamed macro
|
||||
.Fn crmode
|
||||
and
|
||||
.Fn nocrmode
|
||||
is retained for backwards compatibility
|
||||
with ealier versions of the library.
|
||||
.Ds
|
||||
.Fn delch ""
|
||||
.De
|
||||
Delete the character at the current \*y.
|
||||
Each character after it on the line shifts to the left,
|
||||
and the last character becomes blank.
|
||||
.Ds
|
||||
.Fn deleteln ""
|
||||
.De
|
||||
Delete the current line.
|
||||
Every line below the current one will move up,
|
||||
and the bottom line will become blank.
|
||||
The current \*y will remain unchanged.
|
||||
.Ds
|
||||
.Fn delwin "WINDOW *win"
|
||||
.De
|
||||
Deletes the window from existence.
|
||||
All resources are freed for future use by
|
||||
.b calloc (3).
|
||||
If a window has a
|
||||
.Fn subwin
|
||||
allocated window inside of it,
|
||||
deleting the outer window
|
||||
the subwindow is not affected,
|
||||
even though this does invalidate it.
|
||||
Therefore,
|
||||
subwindows should be deleted before their
|
||||
outer windows are.
|
||||
.Ds
|
||||
.Fn echo "" \(dg
|
||||
.De
|
||||
Sets the terminal to echo characters.
|
||||
.Ds
|
||||
.Fn endwin ""
|
||||
.De
|
||||
Finish up window routines before exit.
|
||||
This restores the terminal to the state it was before
|
||||
.Fn initscr
|
||||
(or
|
||||
.Fn gettmode
|
||||
and
|
||||
.Fn setterm )
|
||||
was called.
|
||||
It should always be called before exiting and before the final calls to
|
||||
.Fn delwin .
|
||||
It does not exit.
|
||||
This is especially useful for resetting tty stats
|
||||
when trapping rubouts via
|
||||
.b signal (2).
|
||||
.Ds
|
||||
.Fn erase "" \(dg
|
||||
.De
|
||||
Erases the window to blanks without setting the clear flag.
|
||||
This is analagous to
|
||||
.Fn clear ,
|
||||
except that it never causes a clear-screen sequence to be generated
|
||||
on a
|
||||
.Fn refresh .
|
||||
\*(Nm
|
||||
.Ds
|
||||
.Fn erasechar "" \(dg
|
||||
.De
|
||||
Returns the erase character
|
||||
for the terminal,
|
||||
.i i.e. ,
|
||||
the character used by the user to erase a single character from the input.
|
||||
.Ds
|
||||
.Fn flushok "WINDOW *win" "int boolf"
|
||||
.De
|
||||
Normally,
|
||||
.Fn refresh
|
||||
.Fn fflush 's
|
||||
.Vn stdout
|
||||
when it is finished.
|
||||
.Fn flushok
|
||||
allows you to control this.
|
||||
if
|
||||
.Vn boolf
|
||||
is non-zero
|
||||
(\c
|
||||
.i i.e. ,
|
||||
non-zero)
|
||||
it will do the
|
||||
.Fn fflush ,
|
||||
otherwise it will not.
|
||||
.Ds
|
||||
.Fn getch "" \(dg
|
||||
.De
|
||||
Gets a character from the terminal and (if necessary)
|
||||
echos it on the window.
|
||||
\*(Es
|
||||
Otherwise, the character gotten is returned.
|
||||
If
|
||||
.i noecho
|
||||
has been set, then the window is left unaltered.
|
||||
In order to retain control of the terminal,
|
||||
it is necessary to have one of
|
||||
.i noecho ,
|
||||
.i cbreak ,
|
||||
or
|
||||
.i rawmode
|
||||
set.
|
||||
If you do not set one,
|
||||
whatever routine you call to read characters will set
|
||||
.i cbreak
|
||||
for you,
|
||||
and then reset to the original mode when finished.
|
||||
.Ds
|
||||
.Fn getstr "char *str" \(dg
|
||||
.De
|
||||
Get a string through the window
|
||||
and put it in the location pointed to by
|
||||
.Vn str ,
|
||||
which is assumed to be large enough to handle it.
|
||||
It sets tty modes if necessary,
|
||||
and then calls
|
||||
.Fn getch
|
||||
(or
|
||||
.Fn wgetch )
|
||||
to get the characters needed to fill in the string
|
||||
until a newline or EOF is encountered.
|
||||
The newline stripped off the string.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fn gettmode ""
|
||||
.De
|
||||
Get the tty stats.
|
||||
This is normally called by
|
||||
.Fn initscr .
|
||||
.Ds
|
||||
.Fn getyx "WINDOW *win" "int y" "int x"
|
||||
.De
|
||||
Puts the current \*y of
|
||||
.Vn win
|
||||
in the variables
|
||||
.Vn y
|
||||
and
|
||||
.Vn x .
|
||||
Since it is a macro,
|
||||
not a function,
|
||||
you do not pass the address
|
||||
of
|
||||
.Vn y
|
||||
and
|
||||
.Vn x .
|
||||
.Ds
|
||||
.Fn idlok "WINDOW *win" "int boolf"
|
||||
.De
|
||||
Reserved for future use.
|
||||
This will eventually signal to
|
||||
.Fn refresh
|
||||
that it is all right to use the insert and delete line sequences
|
||||
when updating the window.
|
||||
.ne 1i
|
||||
.Ds
|
||||
.Fn inch "" \(dg
|
||||
.De
|
||||
Returns the character at the current position on the given window.
|
||||
This does not make any changes to the window.
|
||||
.Ds
|
||||
.Fn initscr ""
|
||||
.De
|
||||
Initialize the screen routines.
|
||||
This must be called before any of the screen routines are used.
|
||||
It initializes the terminal-type data and such,
|
||||
and without it none of the routines can operate.
|
||||
If standard input is not a tty,
|
||||
it sets the specifications to the terminal
|
||||
whose name is pointed to by
|
||||
.Vn Def\*_term
|
||||
(initially "dumb").
|
||||
If the boolean
|
||||
.Vn My\*_term
|
||||
is non-zero,
|
||||
.Vn Def\*_term
|
||||
is always used.
|
||||
If the system supports the
|
||||
.b TIOCGWINSZ
|
||||
.i ioctl(2)
|
||||
call,
|
||||
it is used to get the number of lines and columns for the terminal,
|
||||
otherwise it is taken from the
|
||||
.b termcap
|
||||
description.
|
||||
.Ds
|
||||
.Fn insch "char c"
|
||||
.De
|
||||
Insert
|
||||
.Vn c
|
||||
at the current \*y
|
||||
Each character after it shifts to the right,
|
||||
and the last character disappears.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fn insertln ""
|
||||
.De
|
||||
Insert a line above the current one.
|
||||
Every line below the current line
|
||||
will be shifted down,
|
||||
and the bottom line will disappear.
|
||||
The current line will become blank,
|
||||
and the current \*y will remain unchanged.
|
||||
.Ds
|
||||
.Fn killchar "" \(dg
|
||||
.De
|
||||
Returns the line kill character
|
||||
for the terminal,
|
||||
.i i.e. ,
|
||||
the character used by the user to erase an entire line from the input.
|
||||
.Ds
|
||||
.Fn leaveok "WINDOW *win" "int boolf" \(dg
|
||||
.De
|
||||
Sets the boolean flag for leaving the cursor after the last change.
|
||||
If
|
||||
.Vn boolf
|
||||
is non-zero,
|
||||
the cursor will be left after the last update on the terminal,
|
||||
and the current \*y for
|
||||
.Vn win
|
||||
will be changed accordingly.
|
||||
If
|
||||
.Vn boolf
|
||||
is 0 the cursor will be moved to the current \*y.
|
||||
This flag
|
||||
(initially 0)
|
||||
retains its value until changed by the user.
|
||||
.Ds
|
||||
.Fn move "int y" "int x"
|
||||
.De
|
||||
Change the current \*y of the window to
|
||||
.Vn y\*,x ). (
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fn mvcur "int lasty" "int lastx" "int newy" "int newx"
|
||||
.De
|
||||
Moves the terminal's cursor from
|
||||
.Vn lasty\*,lastx ) (
|
||||
to
|
||||
.Vn newy\*,newx ) (
|
||||
in an approximation of optimal fashion.
|
||||
This routine uses the functions borrowed from
|
||||
.i ex
|
||||
version 2.6.
|
||||
It is possible to use this optimization
|
||||
without the benefit of the screen routines.
|
||||
With the screen routines, this should not be called by the user.
|
||||
.Fn move
|
||||
and
|
||||
.Fn refresh
|
||||
should be used to move the cursor position,
|
||||
so that the routines know what's going on.
|
||||
.Ds
|
||||
.Fn mvprintw "int y" "int x" "const char *fmt" "..."
|
||||
.De
|
||||
Equivalent to:
|
||||
.(l
|
||||
move(y, x);
|
||||
printw(fmt, ...);
|
||||
.)l
|
||||
.Ds
|
||||
.Fn mvscanw "int y" "int x" "const char *fmt" "..."
|
||||
.De
|
||||
Equivalent to:
|
||||
.(l
|
||||
move(y, x);
|
||||
scanw(fmt, ...);
|
||||
.)l
|
||||
.Ds
|
||||
.Fn mvwin "WINDOW *win" "int y" "int x"
|
||||
.De
|
||||
Move the home position of the window
|
||||
.Vn win
|
||||
from its current starting coordinates
|
||||
to
|
||||
.Vn y\*,x ). (
|
||||
If that would put part or all of the window
|
||||
off the edge of the terminal screen,
|
||||
.Fn mvwin
|
||||
returns ERR and does not change anything.
|
||||
For subwindows,
|
||||
.Fn mvwin
|
||||
also returns ERR if you attempt to move it off its main window.
|
||||
If you move a main window,
|
||||
all subwindows are moved along with it.
|
||||
.Ds
|
||||
.Fn mvwprintw "WINDOW *win" "int y" "int x" "const char *fmt" "..."
|
||||
.De
|
||||
Equivalent to:
|
||||
.(l
|
||||
wmove(win, y, x);
|
||||
printw(fmt, ...);
|
||||
.)l
|
||||
.Ds
|
||||
.Fn mvwscanw "WINDOW *win" "int y" "int x" "const char *fmt" "..."
|
||||
.De
|
||||
Equivalent to:
|
||||
.(l
|
||||
wmove(win, y, x);
|
||||
scanw(fmt, ...);
|
||||
.)l
|
||||
.Ds
|
||||
.Ft "WINDOW *"
|
||||
.Fn newwin "int lines" "int cols" "int begin_y" "int begin_x"
|
||||
.De
|
||||
Create a new window with
|
||||
.Vn lines
|
||||
lines and
|
||||
.Vn cols
|
||||
columns starting at position
|
||||
.Vn begin\*_y\*,begin\*_x ). (
|
||||
If either
|
||||
.Vn lines
|
||||
or
|
||||
.Vn cols
|
||||
is 0 (zero),
|
||||
that dimension will be set to
|
||||
.Vn "LINES \- begin\*_y" ) (
|
||||
or
|
||||
.Vn "COLS \- begin\*_x" ) (
|
||||
respectively.
|
||||
Thus, to get a new window of dimensions
|
||||
.Vn LINES
|
||||
\(mu
|
||||
.Vn COLS ,
|
||||
use
|
||||
.Fn newwin 0 0 0 0 .
|
||||
.Ds
|
||||
.Fn nl "" \(dg
|
||||
.De
|
||||
Set the terminal to nl mode,
|
||||
.i i.e. ,
|
||||
start/stop the system from mapping
|
||||
.b <RETURN>
|
||||
to
|
||||
.b <LINE-FEED> .
|
||||
If the mapping is not done,
|
||||
.Fn refresh
|
||||
can do more optimization,
|
||||
so it is recommended, but not required, to turn it off.
|
||||
.Ds
|
||||
.Fn nocbreak "" \(dg
|
||||
.De
|
||||
Unset the terminal from cbreak mode.
|
||||
.Ds
|
||||
.Fn nocrmode "" \(dg
|
||||
.De
|
||||
Identical to
|
||||
.Fn nocbreak .
|
||||
The misnamed macro
|
||||
.Fn nocrmode
|
||||
is retained for backwards compatibility
|
||||
with ealier versions of the library.
|
||||
.Ds
|
||||
.Fn noecho "" \(dg
|
||||
.De
|
||||
Turn echoing of characters off.
|
||||
.Ds
|
||||
.Fn nonl "" \(dg
|
||||
.De
|
||||
Unset the terminal to from nl mode. See
|
||||
.Fn nl .
|
||||
.ne 1i
|
||||
.Ds
|
||||
.Fn noraw "" \(dg
|
||||
.De
|
||||
Unset the terminal from raw mode. See
|
||||
.Fn raw .
|
||||
.Ds
|
||||
.Fn overlay "WINDOW *win1" "WINDOW *win2"
|
||||
.De
|
||||
Overlay
|
||||
.Vn win1
|
||||
on
|
||||
.Vn win2 .
|
||||
The contents of
|
||||
.Vn win1 ,
|
||||
insofar as they fit,
|
||||
are placed on
|
||||
.Vn win2
|
||||
at their starting \*y.
|
||||
This is done non-destructively,
|
||||
i.e., blanks on
|
||||
.Vn win1
|
||||
leave the contents of the space on
|
||||
.Vn win2
|
||||
untouched. Note that all non-blank characters are overwritten
|
||||
destructively in the overlay.
|
||||
.Ds
|
||||
.Fn overwrite "WINDOW *win1" "WINDOW *win2"
|
||||
.De
|
||||
Overwrite
|
||||
.Vn win1
|
||||
on
|
||||
.Vn win2 .
|
||||
The contents of
|
||||
.Vn win1 ,
|
||||
insofar as they fit,
|
||||
are placed on
|
||||
.Vn win2
|
||||
at their starting \*y.
|
||||
This is done destructively,
|
||||
.i i.e. ,
|
||||
blanks on
|
||||
.Vn win1
|
||||
become blank on
|
||||
.Vn win2 .
|
||||
.Ds
|
||||
.Fn printw "char *fmt" "..."
|
||||
.De
|
||||
Performs a
|
||||
.Fn printf
|
||||
on the window starting at the current \*y.
|
||||
It uses
|
||||
.Fn addstr
|
||||
to add the string on the window.
|
||||
It is often advisable to use the field width options of
|
||||
.Fn printf
|
||||
to avoid leaving things on the window from earlier calls.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fn raw "" \(dg
|
||||
.De
|
||||
Set the terminal to raw mode.
|
||||
On version 7
|
||||
.Un \**
|
||||
.(f
|
||||
\**
|
||||
.Un
|
||||
is a trademark of Unix System Laboratories.
|
||||
.)f
|
||||
this also turns off newline mapping
|
||||
(see
|
||||
.Fn nl ).
|
||||
.Ds
|
||||
.Fn refresh "" \(dg
|
||||
.De
|
||||
Synchronize the terminal screen with the desired window.
|
||||
If the window is not a screen,
|
||||
only that part covered by it is updated.
|
||||
\*(Es
|
||||
In this case, it will update whatever it can
|
||||
without causing the scroll.
|
||||
.sp
|
||||
As a special case,
|
||||
if
|
||||
.Fn wrefresh
|
||||
is called with the window
|
||||
.Vn curscr
|
||||
the screen is cleared
|
||||
and repainted as it is currently.
|
||||
This is very useful for allowing the redrawing of the screen
|
||||
when the user has garbage dumped on his terminal.
|
||||
.Ds
|
||||
.Fn resetty "" \(dg
|
||||
.De
|
||||
.Fn resetty
|
||||
restores them to what
|
||||
.Fn savetty
|
||||
stored.
|
||||
These functions are performed automatically by
|
||||
.Fn initscr
|
||||
and
|
||||
.Fn endwin .
|
||||
This function should not be used by the user.
|
||||
.Ds
|
||||
.Fn savetty "" \(dg
|
||||
.De
|
||||
.Fn savetty
|
||||
saves the current tty characteristic flags. See
|
||||
.Fn resetty .
|
||||
This function should not be used by the user.
|
||||
.Ds
|
||||
.Fn scanw "char *fmt" "..."
|
||||
.De
|
||||
Perform a
|
||||
.Fn scanf
|
||||
through the window using
|
||||
.Vn fmt .
|
||||
It does this using consecutive calls to
|
||||
.Fn getch
|
||||
(or
|
||||
.Fn wgetch ).
|
||||
\*(Es
|
||||
.ne 1i
|
||||
.Ds
|
||||
.Fn scroll "WINDOW *win"
|
||||
.De
|
||||
Scroll the window upward one line.
|
||||
This is normally not used by the user.
|
||||
.Ds
|
||||
.Fn scrollok "WINDOW *win" "int boolf" \(dg
|
||||
.De
|
||||
Set the scroll flag for the given window.
|
||||
If
|
||||
.Vn boolf
|
||||
is 0, scrolling is not allowed.
|
||||
This is its default setting.
|
||||
.Ds
|
||||
.Fn standend "" \(dg
|
||||
.De
|
||||
End standout mode initiated by
|
||||
.Fn standout .
|
||||
.Ds
|
||||
.Fn standout "" \(dg
|
||||
.De
|
||||
Causes any characters added to the window
|
||||
to be put in standout mode on the terminal
|
||||
(if it has that capability).
|
||||
.Ds
|
||||
.Ft "WINDOW *"
|
||||
.Fn subwin "WINDOW *win" "int lines" "int cols" "int begin_y" "int begin_x"
|
||||
.De
|
||||
Create a new window with
|
||||
.Vn lines
|
||||
lines and
|
||||
.Vn cols
|
||||
columns starting at position
|
||||
.Vn begin\*_y\*,begin\*_x ) (
|
||||
inside the window
|
||||
.i win .
|
||||
This means that any change made to either window
|
||||
in the area covered
|
||||
by the subwindow will be made on both windows.
|
||||
.Vn begin\*_y\*,begin\*_x
|
||||
are specified relative to the overall screen,
|
||||
not the relative (0\*,0) of
|
||||
.Vn win .
|
||||
If either
|
||||
.Vn lines
|
||||
or
|
||||
.Vn cols
|
||||
is 0 (zero),
|
||||
that dimension will be set to
|
||||
.Vn "LINES \- begin\*_y" ) (
|
||||
or
|
||||
.Vn "COLS \- begin\*_x" ) (
|
||||
respectively.
|
||||
.Ds
|
||||
.Fn touchline "WINDOW *win" "int y" "int startx" "int endx"
|
||||
.De
|
||||
This function performs a function similar to
|
||||
.Fn touchwin
|
||||
on a single line.
|
||||
It marks the first change for the given line
|
||||
to be
|
||||
.Vn startx ,
|
||||
if it is before the current first change mark,
|
||||
and
|
||||
the last change mark is set to be
|
||||
.Vn endx
|
||||
if it is currently less than
|
||||
.Vn endx .
|
||||
.Ds
|
||||
.Fn touchoverlap "WINDOW *win1" "WINDOW *win2"
|
||||
.De
|
||||
Touch the window
|
||||
.Vn win2
|
||||
in the area which overlaps with
|
||||
.Vn win1 .
|
||||
If they do not overlap,
|
||||
no changes are made.
|
||||
.Ds
|
||||
.Fn touchwin "WINDOW *win"
|
||||
.De
|
||||
Make it appear that the every location on the window
|
||||
has been changed.
|
||||
This is usually only needed for refreshes with overlapping windows.
|
||||
.Ds
|
||||
.Fn tstp
|
||||
.De
|
||||
This function
|
||||
will save the current tty state
|
||||
and then put the process to sleep.
|
||||
When the process gets restarted,
|
||||
it restores the saved tty state
|
||||
and then calls
|
||||
.Fn wrefresh "curscr"
|
||||
to redraw the screen.
|
||||
.Fn Initscr
|
||||
sets the signal
|
||||
SIGTSTP
|
||||
to trap to this routine.
|
||||
.Ds
|
||||
.Fn unctrl "char *ch" \(dg
|
||||
.De
|
||||
Returns a string which is an ASCII representation of
|
||||
.Vn ch .
|
||||
Characters are 8 bits long.
|
||||
.Ds
|
||||
.Fn unctrllen "char *ch" \(dg
|
||||
.De
|
||||
Returns the length of the ASCII representation of
|
||||
.Vn ch .
|
||||
.ne 1i
|
||||
.Ds
|
||||
.Fn vwprintw "WINDOW *win" "const char *fmt" "va_list ap"
|
||||
.De
|
||||
Identical to
|
||||
.Fn printw
|
||||
except that it takes both a window specification and a pointer to a variable
|
||||
length argument list.
|
||||
.Ds
|
||||
.Fn vwscanw "WINDOW *win" "const char *fmt" "va_list ap"
|
||||
.De
|
||||
Identical to
|
||||
.Fn scanw
|
||||
except that it takes both a window specification and a pointer to a variable
|
||||
length argument list.
|
||||
.Ds
|
||||
.Fn waddbytes "WINDOW *win" "char *str" "int len"
|
||||
.De
|
||||
This function is the low level character output function.
|
||||
.Vn Len
|
||||
characters of the string
|
||||
.Vn str
|
||||
are output to the current \*y position of the window specified by
|
||||
.Vn win.
|
||||
.sp 2
|
||||
.pp
|
||||
\fIThe following functions differ from the standard functions only in their
|
||||
specification of a window, rather than the use of the default
|
||||
.Vn stdscr.\fP
|
||||
.Ds
|
||||
.Fn waddch "WINDOW *win" "char ch"
|
||||
.Fn waddstr "WINDOW *win" "char *str"
|
||||
.Fn wclear "WINDOW *win"
|
||||
.Fn wclrtobot "WINDOW *win"
|
||||
.Fn wclrtoeol "WINDOW *win"
|
||||
.Fn wdelch "WINDOW *win"
|
||||
.Fn wdeleteln "WINDOW *win"
|
||||
.Fn werase "WINDOW *win"
|
||||
.Fn wgetch "WINDOW *win"
|
||||
.Fn wgetstr "WINDOW *win" "char *str"
|
||||
.Fn winch "WINDOW *win" \(dg
|
||||
.Fn winsch "WINDOW *win" "char c"
|
||||
.Fn winsertln "WINDOW *win"
|
||||
.Fn wmove "WINDOW *win" "int y" int x"
|
||||
.Fn wprintw "WINDOW *win" "char *fmt" "..."
|
||||
.Fn wrefresh "WINDOW *win"
|
||||
.Fn wscanw "WINDOW *win" "char *fmt" "..."
|
||||
.Fn wstandend "WINDOW *win"
|
||||
.Fn wstandout "WINDOW *win"
|
||||
.Dg
|
157
lib/libcurses/addbytes.c
Normal file
157
lib/libcurses/addbytes.c
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 1987, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
#define SYNCH_IN {y = win->cury; x = win->curx;}
|
||||
#define SYNCH_OUT {win->cury = y; win->curx = x;}
|
||||
|
||||
/*
|
||||
* waddbytes --
|
||||
* Add the character to the current position in the given window.
|
||||
*/
|
||||
int
|
||||
__waddbytes(win, bytes, count, so)
|
||||
register WINDOW *win;
|
||||
register const char *bytes;
|
||||
register int count;
|
||||
int so;
|
||||
{
|
||||
static char blanks[] = " ";
|
||||
register int c, newx, x, y;
|
||||
char stand;
|
||||
__LINE *lp;
|
||||
|
||||
SYNCH_IN;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("ADDBYTES('%c') at (%d, %d)\n", c, y, x);
|
||||
#endif
|
||||
while (count--) {
|
||||
c = *bytes++;
|
||||
switch (c) {
|
||||
case '\t':
|
||||
SYNCH_OUT;
|
||||
if (waddbytes(win, blanks, 8 - (x % 8)) == ERR)
|
||||
return (ERR);
|
||||
SYNCH_IN;
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef DEBUG
|
||||
__CTRACE("ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
|
||||
#endif
|
||||
|
||||
lp = win->lines[y];
|
||||
if (lp->flags & __ISPASTEOL) {
|
||||
lp->flags &= ~__ISPASTEOL;
|
||||
newline: if (y == win->maxy - 1) {
|
||||
if (win->flags & __SCROLLOK) {
|
||||
SYNCH_OUT;
|
||||
scroll(win);
|
||||
SYNCH_IN;
|
||||
lp = win->lines[y];
|
||||
x = 0;
|
||||
} else
|
||||
return (ERR);
|
||||
} else {
|
||||
y++;
|
||||
lp = win->lines[y];
|
||||
x = 0;
|
||||
}
|
||||
if (c == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
stand = '\0';
|
||||
if (win->flags & __WSTANDOUT || so)
|
||||
stand |= __STANDOUT;
|
||||
#ifdef DEBUG
|
||||
__CTRACE("ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n",
|
||||
y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
|
||||
#endif
|
||||
if (lp->line[x].ch != c ||
|
||||
!(lp->line[x].attr & stand)) {
|
||||
newx = x + win->ch_off;
|
||||
if (!(lp->flags & __ISDIRTY)) {
|
||||
lp->flags |= __ISDIRTY;
|
||||
*lp->firstchp = *lp->lastchp = newx;
|
||||
}
|
||||
else if (newx < *lp->firstchp)
|
||||
*lp->firstchp = newx;
|
||||
else if (newx > *lp->lastchp)
|
||||
*lp->lastchp = newx;
|
||||
#ifdef DEBUG
|
||||
__CTRACE("ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
|
||||
*lp->firstchp, *lp->lastchp,
|
||||
*lp->firstchp - win->ch_off,
|
||||
*lp->lastchp - win->ch_off);
|
||||
#endif
|
||||
}
|
||||
lp->line[x].ch = c;
|
||||
if (stand)
|
||||
lp->line[x].attr |= __STANDOUT;
|
||||
else
|
||||
lp->line[x].attr &= ~__STANDOUT;
|
||||
if (x == win->maxx - 1)
|
||||
lp->flags |= __ISPASTEOL;
|
||||
else
|
||||
x++;
|
||||
#ifdef DEBUG
|
||||
__CTRACE("ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n",
|
||||
y, x, *win->lines[y]->firstchp, *win->lines[y]->lastchp);
|
||||
#endif
|
||||
break;
|
||||
case '\n':
|
||||
SYNCH_OUT;
|
||||
wclrtoeol(win);
|
||||
SYNCH_IN;
|
||||
if (!NONL)
|
||||
x = 0;
|
||||
goto newline;
|
||||
case '\r':
|
||||
x = 0;
|
||||
break;
|
||||
case '\b':
|
||||
if (--x < 0)
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SYNCH_OUT;
|
||||
return (OK);
|
||||
}
|
66
lib/libcurses/addch.c
Normal file
66
lib/libcurses/addch.c
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)addch.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* waddch --
|
||||
* Add the character to the current position in the given window.
|
||||
*
|
||||
*/
|
||||
int
|
||||
waddch(win, ch)
|
||||
WINDOW *win;
|
||||
int ch;
|
||||
{
|
||||
__LDATA buf;
|
||||
|
||||
buf.ch = ch;
|
||||
buf.attr = 0;
|
||||
return (__waddch(win, &buf));
|
||||
}
|
||||
|
||||
int
|
||||
__waddch(win, dp)
|
||||
WINDOW *win;
|
||||
__LDATA *dp;
|
||||
{
|
||||
char buf[2];
|
||||
|
||||
buf[0] = dp->ch;
|
||||
return (__waddbytes(win, buf, 1, dp->attr & __STANDOUT));
|
||||
}
|
62
lib/libcurses/addnstr.c
Normal file
62
lib/libcurses/addnstr.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1993, 1994
|
||||
* 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 sccsid[] = "@(#)addnstr.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* waddnstr --
|
||||
* Add a string (at most n characters) to the given window
|
||||
* starting at (_cury, _curx). If n is negative, add the
|
||||
* entire string.
|
||||
*/
|
||||
int
|
||||
waddnstr(win, s, n)
|
||||
WINDOW *win;
|
||||
const char *s;
|
||||
int n;
|
||||
{
|
||||
size_t len;
|
||||
const char *p;
|
||||
|
||||
if (n > 0)
|
||||
for (p = s, len = 0; n-- && *p++; ++len);
|
||||
else
|
||||
len = strlen(s);
|
||||
return (waddbytes(win, s, len));
|
||||
}
|
78
lib/libcurses/box.c
Normal file
78
lib/libcurses/box.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)box.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* box --
|
||||
* Draw a box around the given window with "vert" as the vertical
|
||||
* delimiting char, and "hor", as the horizontal one.
|
||||
*/
|
||||
int
|
||||
box(win, vert, hor)
|
||||
register WINDOW *win;
|
||||
int vert, hor;
|
||||
{
|
||||
register int endy, endx, i;
|
||||
register __LDATA *fp, *lp;
|
||||
|
||||
endx = win->maxx;
|
||||
endy = win->maxy - 1;
|
||||
fp = win->lines[0]->line;
|
||||
lp = win->lines[endy]->line;
|
||||
for (i = 0; i < endx; i++) {
|
||||
fp[i].ch = lp[i].ch = hor;
|
||||
fp[i].attr &= ~__STANDOUT;
|
||||
lp[i].attr &= ~__STANDOUT;
|
||||
}
|
||||
endx--;
|
||||
for (i = 0; i <= endy; i++) {
|
||||
win->lines[i]->line[0].ch = vert;
|
||||
win->lines[i]->line[endx].ch = vert;
|
||||
win->lines[i]->line[0].attr &= ~__STANDOUT;
|
||||
win->lines[i]->line[endx].attr &= ~__STANDOUT;
|
||||
}
|
||||
if (!(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN)) {
|
||||
fp[0].ch = fp[endx].ch = lp[0].ch = lp[endx].ch = ' ';
|
||||
fp[0].attr &= ~__STANDOUT;
|
||||
fp[endx].attr &= ~__STANDOUT;
|
||||
lp[0].attr &= ~__STANDOUT;
|
||||
lp[endx].attr &= ~__STANDOUT;
|
||||
}
|
||||
__touchwin(win);
|
||||
return (OK);
|
||||
}
|
53
lib/libcurses/clear.c
Normal file
53
lib/libcurses/clear.c
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)clear.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wclear --
|
||||
* Clear the window.
|
||||
*/
|
||||
int
|
||||
wclear(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
if (werase(win) == OK) {
|
||||
win->flags |= __CLEAROK;
|
||||
return (OK);
|
||||
}
|
||||
return (ERR);
|
||||
}
|
75
lib/libcurses/clrtobot.c
Normal file
75
lib/libcurses/clrtobot.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)clrtobot.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wclrtobot --
|
||||
* Erase everything on the window.
|
||||
*/
|
||||
int
|
||||
wclrtobot(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int minx, startx, starty, y;
|
||||
register __LDATA *sp, *end, *maxx;
|
||||
|
||||
if (win->lines[win->cury]->flags & __ISPASTEOL) {
|
||||
starty = win->cury + 1;
|
||||
startx = 0;
|
||||
} else {
|
||||
starty = win->cury;
|
||||
startx = win->curx;
|
||||
}
|
||||
for (y = starty; y < win->maxy; y++) {
|
||||
minx = -1;
|
||||
end = &win->lines[y]->line[win->maxx];
|
||||
for (sp = &win->lines[y]->line[startx]; sp < end; sp++)
|
||||
if (sp->ch != ' ' || sp->attr != 0) {
|
||||
maxx = sp;
|
||||
if (minx == -1)
|
||||
minx = sp - win->lines[y]->line;
|
||||
sp->ch = ' ';
|
||||
sp->attr = 0;
|
||||
}
|
||||
if (minx != -1)
|
||||
__touchline(win, y, minx, maxx - win->lines[y]->line,
|
||||
0);
|
||||
startx = 0;
|
||||
}
|
||||
return (OK);
|
||||
}
|
83
lib/libcurses/clrtoeol.c
Normal file
83
lib/libcurses/clrtoeol.c
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)clrtoeol.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wclrtoeol --
|
||||
* Clear up to the end of line.
|
||||
*/
|
||||
int
|
||||
wclrtoeol(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int minx, x, y;
|
||||
register __LDATA *end, *maxx, *sp;
|
||||
|
||||
y = win->cury;
|
||||
x = win->curx;
|
||||
if (win->lines[y]->flags & __ISPASTEOL) {
|
||||
if (y < win->maxy - 1) {
|
||||
y++;
|
||||
x = 0;
|
||||
} else
|
||||
return (OK);
|
||||
}
|
||||
end = &win->lines[y]->line[win->maxx];
|
||||
minx = -1;
|
||||
maxx = &win->lines[y]->line[x];
|
||||
for (sp = maxx; sp < end; sp++)
|
||||
if (sp->ch != ' ' || sp->attr != 0) {
|
||||
maxx = sp;
|
||||
if (minx == -1)
|
||||
minx = sp - win->lines[y]->line;
|
||||
sp->ch = ' ';
|
||||
sp->attr = 0;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("CLRTOEOL: minx = %d, maxx = %d, firstch = %d, lastch = %d\n",
|
||||
minx, maxx - win->lines[y]->line, *win->lines[y]->firstchp,
|
||||
*win->lines[y]->lastchp);
|
||||
#endif
|
||||
/* Update firstch and lastch for the line. */
|
||||
return (__touchline(win, y, x, win->maxx - 1, 0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
432
lib/libcurses/cr_put.c
Normal file
432
lib/libcurses/cr_put.c
Normal file
@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)cr_put.c 8.3 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
#define HARDTABS 8
|
||||
|
||||
/*
|
||||
* Terminal driving and line formatting routines. Basic motion optimizations
|
||||
* are done here as well as formatting lines (printing of control characters,
|
||||
* line numbering and the like).
|
||||
*/
|
||||
|
||||
/* Stub function for the users. */
|
||||
int
|
||||
mvcur(ly, lx, y, x)
|
||||
int ly, lx, y, x;
|
||||
{
|
||||
return (__mvcur(ly, lx, y, x, 0));
|
||||
}
|
||||
|
||||
static void fgoto __P((int));
|
||||
static int plod __P((int, int));
|
||||
static void plodput __P((int));
|
||||
static int tabcol __P((int, int));
|
||||
|
||||
static int outcol, outline, destcol, destline;
|
||||
|
||||
/*
|
||||
* Sync the position of the output cursor. Most work here is rounding for
|
||||
* terminal boundaries getting the column position implied by wraparound or
|
||||
* the lack thereof and rolling up the screen to get destline on the screen.
|
||||
*/
|
||||
int
|
||||
__mvcur(ly, lx, y, x, in_refresh)
|
||||
int ly, lx, y, x, in_refresh;
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE("mvcur: moving cursor from (%d, %d) to (%d, %d)\n",
|
||||
ly, lx, y, x);
|
||||
#endif
|
||||
destcol = x;
|
||||
destline = y;
|
||||
outcol = lx;
|
||||
outline = ly;
|
||||
fgoto(in_refresh);
|
||||
return (OK);
|
||||
}
|
||||
|
||||
static void
|
||||
fgoto(in_refresh)
|
||||
int in_refresh;
|
||||
{
|
||||
register int c, l;
|
||||
register char *cgp;
|
||||
|
||||
if (destcol >= COLS) {
|
||||
destline += destcol / COLS;
|
||||
destcol %= COLS;
|
||||
}
|
||||
if (outcol >= COLS) {
|
||||
l = (outcol + 1) / COLS;
|
||||
outline += l;
|
||||
outcol %= COLS;
|
||||
if (AM == 0) {
|
||||
while (l > 0) {
|
||||
if (__pfast)
|
||||
if (CR)
|
||||
tputs(CR, 0, __cputchar);
|
||||
else
|
||||
putchar('\r');
|
||||
if (NL)
|
||||
tputs(NL, 0, __cputchar);
|
||||
else
|
||||
putchar('\n');
|
||||
l--;
|
||||
}
|
||||
outcol = 0;
|
||||
}
|
||||
if (outline > LINES - 1) {
|
||||
destline -= outline - (LINES - 1);
|
||||
outline = LINES - 1;
|
||||
}
|
||||
}
|
||||
if (destline >= LINES) {
|
||||
l = destline;
|
||||
destline = LINES - 1;
|
||||
if (outline < LINES - 1) {
|
||||
c = destcol;
|
||||
if (__pfast == 0 && !CA)
|
||||
destcol = 0;
|
||||
fgoto(in_refresh);
|
||||
destcol = c;
|
||||
}
|
||||
while (l >= LINES) {
|
||||
/* The following linefeed (or simulation thereof) is
|
||||
* supposed to scroll up the screen, since we are on
|
||||
* the bottom line. We make the assumption that
|
||||
* linefeed will scroll. If ns is in the capability
|
||||
* list this won't work. We should probably have an
|
||||
* sc capability but sf will generally take the place
|
||||
* if it works.
|
||||
*
|
||||
* Superbee glitch: in the middle of the screen have
|
||||
* to use esc B (down) because linefeed screws up in
|
||||
* "Efficient Paging" (what a joke) mode (which is
|
||||
* essential in some SB's because CRLF mode puts
|
||||
* garbage in at end of memory), but you must use
|
||||
* linefeed to scroll since down arrow won't go past
|
||||
* memory end. I turned this off after recieving Paul
|
||||
* Eggert's Superbee description which wins better.
|
||||
*/
|
||||
if (NL /* && !XB */ && __pfast)
|
||||
tputs(NL, 0, __cputchar);
|
||||
else
|
||||
putchar('\n');
|
||||
l--;
|
||||
if (__pfast == 0)
|
||||
outcol = 0;
|
||||
}
|
||||
}
|
||||
if (destline < outline && !(CA || UP))
|
||||
destline = outline;
|
||||
if (CA) {
|
||||
cgp = tgoto(CM, destcol, destline);
|
||||
|
||||
/*
|
||||
* Need this condition due to inconsistent behavior
|
||||
* of backspace on the last column.
|
||||
*/
|
||||
if (outcol != COLS - 1 && plod(strlen(cgp), in_refresh) > 0)
|
||||
plod(0, in_refresh);
|
||||
else
|
||||
tputs(cgp, 0, __cputchar);
|
||||
} else
|
||||
plod(0, in_refresh);
|
||||
outline = destline;
|
||||
outcol = destcol;
|
||||
}
|
||||
/*
|
||||
* Move (slowly) to destination.
|
||||
* Hard thing here is using home cursor on really deficient terminals.
|
||||
* Otherwise just use cursor motions, hacking use of tabs and overtabbing
|
||||
* and backspace.
|
||||
*/
|
||||
|
||||
static int plodcnt, plodflg;
|
||||
|
||||
static void
|
||||
plodput(c)
|
||||
int c;
|
||||
{
|
||||
if (plodflg)
|
||||
--plodcnt;
|
||||
else
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
static int
|
||||
plod(cnt, in_refresh)
|
||||
int cnt, in_refresh;
|
||||
{
|
||||
register int i, j, k, soutcol, soutline;
|
||||
|
||||
plodcnt = plodflg = cnt;
|
||||
soutcol = outcol;
|
||||
soutline = outline;
|
||||
/*
|
||||
* Consider homing and moving down/right from there, vs. moving
|
||||
* directly with local motions to the right spot.
|
||||
*/
|
||||
if (HO) {
|
||||
/*
|
||||
* i is the cost to home and tab/space to the right to get to
|
||||
* the proper column. This assumes ND space costs 1 char. So
|
||||
* i + destcol is cost of motion with home.
|
||||
*/
|
||||
if (GT)
|
||||
i = (destcol / HARDTABS) + (destcol % HARDTABS);
|
||||
else
|
||||
i = destcol;
|
||||
|
||||
/* j is cost to move locally without homing. */
|
||||
if (destcol >= outcol) { /* if motion is to the right */
|
||||
j = destcol / HARDTABS - outcol / HARDTABS;
|
||||
if (GT && j)
|
||||
j += destcol % HARDTABS;
|
||||
else
|
||||
j = destcol - outcol;
|
||||
} else
|
||||
/* leftward motion only works if we can backspace. */
|
||||
if (outcol - destcol <= i && (BS || BC))
|
||||
/* Cheaper to backspace. */
|
||||
i = j = outcol - destcol;
|
||||
else
|
||||
/* Impossibly expensive. */
|
||||
j = i + 1;
|
||||
|
||||
/* k is the absolute value of vertical distance. */
|
||||
k = outline - destline;
|
||||
if (k < 0)
|
||||
k = -k;
|
||||
j += k;
|
||||
|
||||
/* Decision. We may not have a choice if no UP. */
|
||||
if (i + destline < j || (!UP && destline < outline)) {
|
||||
/*
|
||||
* Cheaper to home. Do it now and pretend it's a
|
||||
* regular local motion.
|
||||
*/
|
||||
tputs(HO, 0, plodput);
|
||||
outcol = outline = 0;
|
||||
} else if (LL) {
|
||||
/*
|
||||
* Quickly consider homing down and moving from there.
|
||||
* Assume cost of LL is 2.
|
||||
*/
|
||||
k = (LINES - 1) - destline;
|
||||
if (i + k + 2 < j && (k <= 0 || UP)) {
|
||||
tputs(LL, 0, plodput);
|
||||
outcol = 0;
|
||||
outline = LINES - 1;
|
||||
}
|
||||
}
|
||||
} else
|
||||
/* No home and no up means it's impossible. */
|
||||
if (!UP && destline < outline)
|
||||
return (-1);
|
||||
if (GT)
|
||||
i = destcol % HARDTABS + destcol / HARDTABS;
|
||||
else
|
||||
i = destcol;
|
||||
#ifdef notdef
|
||||
if (BT && outcol > destcol &&
|
||||
(j = (((outcol+7) & ~7) - destcol - 1) >> 3)) {
|
||||
j *= (k = strlen(BT));
|
||||
if ((k += (destcol&7)) > 4)
|
||||
j += 8 - (destcol&7);
|
||||
else
|
||||
j += k;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
j = outcol - destcol;
|
||||
|
||||
/*
|
||||
* If we will later need a \n which will turn into a \r\n by the
|
||||
* system or the terminal, then don't bother to try to \r.
|
||||
*/
|
||||
if ((NONL || !__pfast) && outline < destline)
|
||||
goto dontcr;
|
||||
|
||||
/*
|
||||
* If the terminal will do a \r\n and there isn't room for it, then
|
||||
* we can't afford a \r.
|
||||
*/
|
||||
if (NC && outline >= destline)
|
||||
goto dontcr;
|
||||
|
||||
/*
|
||||
* If it will be cheaper, or if we can't back up, then send a return
|
||||
* preliminarily.
|
||||
*/
|
||||
if (j > i + 1 || outcol > destcol && !BS && !BC) {
|
||||
/*
|
||||
* BUG: this doesn't take the (possibly long) length of CR
|
||||
* into account.
|
||||
*/
|
||||
if (CR)
|
||||
tputs(CR, 0, plodput);
|
||||
else
|
||||
plodput('\r');
|
||||
if (NC) {
|
||||
if (NL)
|
||||
tputs(NL, 0, plodput);
|
||||
else
|
||||
plodput('\n');
|
||||
outline++;
|
||||
}
|
||||
outcol = 0;
|
||||
}
|
||||
|
||||
dontcr: while (outline < destline) {
|
||||
outline++;
|
||||
if (NL)
|
||||
tputs(NL, 0, plodput);
|
||||
else
|
||||
plodput('\n');
|
||||
if (plodcnt < 0)
|
||||
goto out;
|
||||
if (NONL || __pfast == 0)
|
||||
outcol = 0;
|
||||
}
|
||||
if (BT)
|
||||
k = strlen(BT);
|
||||
while (outcol > destcol) {
|
||||
if (plodcnt < 0)
|
||||
goto out;
|
||||
#ifdef notdef
|
||||
if (BT && outcol - destcol > k + 4) {
|
||||
tputs(BT, 0, plodput);
|
||||
outcol--;
|
||||
outcol &= ~7;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
outcol--;
|
||||
if (BC)
|
||||
tputs(BC, 0, plodput);
|
||||
else
|
||||
plodput('\b');
|
||||
}
|
||||
while (outline > destline) {
|
||||
outline--;
|
||||
tputs(UP, 0, plodput);
|
||||
if (plodcnt < 0)
|
||||
goto out;
|
||||
}
|
||||
if (GT && destcol - outcol > 1) {
|
||||
for (;;) {
|
||||
i = tabcol(outcol, HARDTABS);
|
||||
if (i > destcol)
|
||||
break;
|
||||
if (TA)
|
||||
tputs(TA, 0, plodput);
|
||||
else
|
||||
plodput('\t');
|
||||
outcol = i;
|
||||
}
|
||||
if (destcol - outcol > 4 && i < COLS && (BC || BS)) {
|
||||
if (TA)
|
||||
tputs(TA, 0, plodput);
|
||||
else
|
||||
plodput('\t');
|
||||
outcol = i;
|
||||
while (outcol > destcol) {
|
||||
outcol--;
|
||||
if (BC)
|
||||
tputs(BC, 0, plodput);
|
||||
else
|
||||
plodput('\b');
|
||||
}
|
||||
}
|
||||
}
|
||||
while (outcol < destcol) {
|
||||
/*
|
||||
* Move one char to the right. We don't use ND space because
|
||||
* it's better to just print the char we are moving over.
|
||||
*/
|
||||
if (in_refresh)
|
||||
if (plodflg) /* Avoid a complex calculation. */
|
||||
plodcnt--;
|
||||
else {
|
||||
i = curscr->lines[outline]->line[outcol].ch;
|
||||
if ((curscr->lines[outline]->line[outcol].attr
|
||||
& __STANDOUT) ==
|
||||
(curscr->flags & __WSTANDOUT))
|
||||
putchar(i);
|
||||
else
|
||||
goto nondes;
|
||||
}
|
||||
else
|
||||
nondes: if (ND)
|
||||
tputs(ND, 0, plodput);
|
||||
else
|
||||
plodput(' ');
|
||||
outcol++;
|
||||
if (plodcnt < 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
out: if (plodflg) {
|
||||
outcol = soutcol;
|
||||
outline = soutline;
|
||||
}
|
||||
return (plodcnt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the column number that results from being in column col and
|
||||
* hitting a tab, where tabs are set every ts columns. Work right for
|
||||
* the case where col > COLS, even if ts does not divide COLS.
|
||||
*/
|
||||
static int
|
||||
tabcol(col, ts)
|
||||
int col, ts;
|
||||
{
|
||||
int offset;
|
||||
|
||||
if (col >= COLS) {
|
||||
offset = COLS * (col / COLS);
|
||||
col -= offset;
|
||||
} else
|
||||
offset = 0;
|
||||
return (col + ts - (col % ts) + offset);
|
||||
}
|
74
lib/libcurses/curses.c
Normal file
74
lib/libcurses/curses.c
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)curses.c 8.3 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/* Private. */
|
||||
int __echoit = 1; /* If stty indicates ECHO. */
|
||||
int __pfast;
|
||||
int __rawmode = 0; /* If stty indicates RAW mode. */
|
||||
int __noqch = 0; /*
|
||||
* If terminal doesn't have
|
||||
* insert/delete line capabilities
|
||||
* for quick change on refresh.
|
||||
*/
|
||||
char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS, PC,
|
||||
UL, XB, XN, XT, XS, XX;
|
||||
char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
|
||||
*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
|
||||
*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
|
||||
*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
|
||||
*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
|
||||
*VE, *al, *dl, *sf, *sr,
|
||||
*AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
|
||||
*RIGHT_PARM;
|
||||
/*
|
||||
* Public.
|
||||
*
|
||||
* XXX
|
||||
* UPPERCASE isn't used by libcurses, and is left for backward
|
||||
* compatibility only.
|
||||
*/
|
||||
WINDOW *curscr; /* Current screen. */
|
||||
WINDOW *stdscr; /* Standard screen. */
|
||||
int COLS; /* Columns on the screen. */
|
||||
int LINES; /* Lines on the screen. */
|
||||
int My_term = 0; /* Use Def_term regardless. */
|
||||
char *Def_term = "unknown"; /* Default terminal type. */
|
||||
char GT; /* Gtty indicates tabs. */
|
||||
char NONL; /* Term can't hack LF doing a CR. */
|
||||
char UPPERCASE; /* Terminal is uppercase only. */
|
336
lib/libcurses/curses.h
Normal file
336
lib/libcurses/curses.h
Normal file
@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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.
|
||||
*
|
||||
* @(#)curses.h 8.5 (Berkeley) 4/29/95
|
||||
*/
|
||||
|
||||
#ifndef _CURSES_H_
|
||||
#define _CURSES_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* The following #defines and #includes are present for backward
|
||||
* compatibility only. They should not be used in future code.
|
||||
*
|
||||
* START BACKWARD COMPATIBILITY ONLY.
|
||||
*/
|
||||
#ifndef _CURSES_PRIVATE
|
||||
#ifndef __cplusplus
|
||||
#define bool char
|
||||
#endif
|
||||
#define reg register
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (1)
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
|
||||
#define _puts(s) tputs(s, 0, __cputchar)
|
||||
#define _putchar(c) __cputchar(c)
|
||||
|
||||
/* Old-style terminal modes access. */
|
||||
#define baudrate() (cfgetospeed(&__baset))
|
||||
#define crmode() cbreak()
|
||||
#define erasechar() (__baset.c_cc[VERASE])
|
||||
#define killchar() (__baset.c_cc[VKILL])
|
||||
#define nocrmode() nocbreak()
|
||||
#define ospeed (cfgetospeed(&__baset))
|
||||
#endif /* _CURSES_PRIVATE */
|
||||
|
||||
extern char GT; /* Gtty indicates tabs. */
|
||||
extern char NONL; /* Term can't hack LF doing a CR. */
|
||||
extern char UPPERCASE; /* Terminal is uppercase only. */
|
||||
|
||||
extern int My_term; /* Use Def_term regardless. */
|
||||
extern char *Def_term; /* Default terminal type. */
|
||||
|
||||
/* Termcap capabilities. */
|
||||
extern char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS,
|
||||
PC, UL, XB, XN, XT, XS, XX;
|
||||
extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
|
||||
*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
|
||||
*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
|
||||
*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
|
||||
*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
|
||||
*VE, *al, *dl, *sf, *sr,
|
||||
*AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
|
||||
*RIGHT_PARM;
|
||||
|
||||
/* END BACKWARD COMPATIBILITY ONLY. */
|
||||
|
||||
/* 8-bit ASCII characters. */
|
||||
#define unctrl(c) __unctrl[(c) & 0xff]
|
||||
#define unctrllen(ch) __unctrllen[(ch) & 0xff]
|
||||
|
||||
extern char *__unctrl[256]; /* Control strings. */
|
||||
extern char __unctrllen[256]; /* Control strings length. */
|
||||
|
||||
/*
|
||||
* A window an array of __LINE structures pointed to by the 'lines' pointer.
|
||||
* A line is an array of __LDATA structures pointed to by the 'line' pointer.
|
||||
*
|
||||
* IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
|
||||
* fields are added -- padding fields with *constant values* should ensure
|
||||
* that the compiler will not generate any padding when storing an array of
|
||||
* __LDATA structures. This is to enable consistent use of memcmp, and memcpy
|
||||
* for comparing and copying arrays.
|
||||
*/
|
||||
typedef struct {
|
||||
char ch; /* the actual character */
|
||||
|
||||
#define __STANDOUT 0x01 /* Added characters are standout. */
|
||||
char attr; /* attributes of character */
|
||||
} __LDATA;
|
||||
|
||||
#define __LDATASIZE (sizeof(__LDATA))
|
||||
|
||||
typedef struct {
|
||||
#define __ISDIRTY 0x01 /* Line is dirty. */
|
||||
#define __ISPASTEOL 0x02 /* Cursor is past end of line */
|
||||
#define __FORCEPAINT 0x04 /* Force a repaint of the line */
|
||||
u_int flags;
|
||||
u_int hash; /* Hash value for the line. */
|
||||
size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */
|
||||
size_t firstch, lastch; /* First and last changed columns. */
|
||||
__LDATA *line; /* Pointer to the line text. */
|
||||
} __LINE;
|
||||
|
||||
typedef struct __window { /* Window structure. */
|
||||
struct __window *nextp, *orig; /* Subwindows list and parent. */
|
||||
size_t begy, begx; /* Window home. */
|
||||
size_t cury, curx; /* Current x, y coordinates. */
|
||||
size_t maxy, maxx; /* Maximum values for curx, cury. */
|
||||
short ch_off; /* x offset for firstch/lastch. */
|
||||
__LINE **lines; /* Array of pointers to the lines */
|
||||
__LINE *lspace; /* line space (for cleanup) */
|
||||
__LDATA *wspace; /* window space (for cleanup) */
|
||||
|
||||
#define __ENDLINE 0x001 /* End of screen. */
|
||||
#define __FLUSH 0x002 /* Fflush(stdout) after refresh. */
|
||||
#define __FULLWIN 0x004 /* Window is a screen. */
|
||||
#define __IDLINE 0x008 /* Insert/delete sequences. */
|
||||
#define __SCROLLWIN 0x010 /* Last char will scroll window. */
|
||||
#define __SCROLLOK 0x020 /* Scrolling ok. */
|
||||
#define __CLEAROK 0x040 /* Clear on next refresh. */
|
||||
#define __WSTANDOUT 0x080 /* Standout window */
|
||||
#define __LEAVEOK 0x100 /* If curser left */
|
||||
u_int flags;
|
||||
} WINDOW;
|
||||
|
||||
/* Curses external declarations. */
|
||||
extern WINDOW *curscr; /* Current screen. */
|
||||
extern WINDOW *stdscr; /* Standard screen. */
|
||||
|
||||
extern struct termios __orig_termios; /* Terminal state before curses */
|
||||
extern struct termios __baset; /* Our base terminal state */
|
||||
extern int __tcaction; /* If terminal hardware set. */
|
||||
|
||||
extern int COLS; /* Columns on the screen. */
|
||||
extern int LINES; /* Lines on the screen. */
|
||||
|
||||
extern char *ttytype; /* Full name of current terminal. */
|
||||
|
||||
#define ERR (0) /* Error return. */
|
||||
#define OK (1) /* Success return. */
|
||||
|
||||
/* Standard screen pseudo functions. */
|
||||
#define addbytes(s, n) __waddbytes(stdscr, s, n, 0)
|
||||
#define addch(ch) waddch(stdscr, ch)
|
||||
#define addnstr(s, n) waddnstr(stdscr, s, n)
|
||||
#define addstr(s) __waddbytes(stdscr, s, strlen(s), 0)
|
||||
#define clear() wclear(stdscr)
|
||||
#define clrtobot() wclrtobot(stdscr)
|
||||
#define clrtoeol() wclrtoeol(stdscr)
|
||||
#define delch() wdelch(stdscr)
|
||||
#define deleteln() wdeleteln(stdscr)
|
||||
#define erase() werase(stdscr)
|
||||
#define getch() wgetch(stdscr)
|
||||
#define getstr(s) wgetstr(stdscr, s)
|
||||
#define inch() winch(stdscr)
|
||||
#define insch(ch) winsch(stdscr, ch)
|
||||
#define insertln() winsertln(stdscr)
|
||||
#define move(y, x) wmove(stdscr, y, x)
|
||||
#define refresh() wrefresh(stdscr)
|
||||
#define standend() wstandend(stdscr)
|
||||
#define standout() wstandout(stdscr)
|
||||
#define waddbytes(w, s, n) __waddbytes(w, s, n, 0)
|
||||
#define waddstr(w, s) __waddbytes(w, s, strlen(s), 0)
|
||||
|
||||
/* Standard screen plus movement pseudo functions. */
|
||||
#define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n)
|
||||
#define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch)
|
||||
#define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n)
|
||||
#define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s)
|
||||
#define mvdelch(y, x) mvwdelch(stdscr, y, x)
|
||||
#define mvgetch(y, x) mvwgetch(stdscr, y, x)
|
||||
#define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s)
|
||||
#define mvinch(y, x) mvwinch(stdscr, y, x)
|
||||
#define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c)
|
||||
#define mvwaddbytes(w, y, x, s, n) \
|
||||
(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0))
|
||||
#define mvwaddch(w, y, x, ch) \
|
||||
(wmove(w, y, x) == ERR ? ERR : waddch(w, ch))
|
||||
#define mvwaddnstr(w, y, x, s, n) \
|
||||
(wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n))
|
||||
#define mvwaddstr(w, y, x, s) \
|
||||
(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0))
|
||||
#define mvwdelch(w, y, x) \
|
||||
(wmove(w, y, x) == ERR ? ERR : wdelch(w))
|
||||
#define mvwgetch(w, y, x) \
|
||||
(wmove(w, y, x) == ERR ? ERR : wgetch(w))
|
||||
#define mvwgetstr(w, y, x, s) \
|
||||
(wmove(w, y, x) == ERR ? ERR : wgetstr(w, s))
|
||||
#define mvwinch(w, y, x) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winch(w))
|
||||
#define mvwinsch(w, y, x, c) \
|
||||
(wmove(w, y, x) == ERR ? ERR : winsch(w, c))
|
||||
|
||||
/* Psuedo functions. */
|
||||
#define clearok(w, bf) \
|
||||
((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK))
|
||||
#define flushok(w, bf) \
|
||||
((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH))
|
||||
#define getyx(w, y, x) \
|
||||
(y) = (w)->cury, (x) = (w)->curx
|
||||
#define leaveok(w, bf) \
|
||||
((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK))
|
||||
#define scrollok(w, bf) \
|
||||
((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK))
|
||||
#define winch(w) \
|
||||
((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177)
|
||||
|
||||
/* Public function prototypes. */
|
||||
int box __P((WINDOW *, int, int));
|
||||
int cbreak __P((void));
|
||||
int delwin __P((WINDOW *));
|
||||
int echo __P((void));
|
||||
int endwin __P((void));
|
||||
char *fullname __P((char *, char *));
|
||||
char *getcap __P((char *));
|
||||
int gettmode __P((void));
|
||||
void idlok __P((WINDOW *, int));
|
||||
WINDOW *initscr __P((void));
|
||||
char *longname __P((char *, char *));
|
||||
int mvcur __P((int, int, int, int));
|
||||
int mvprintw __P((int, int, const char *, ...));
|
||||
int mvscanw __P((int, int, const char *, ...));
|
||||
int mvwin __P((WINDOW *, int, int));
|
||||
int mvwprintw __P((WINDOW *, int, int, const char *, ...));
|
||||
int mvwscanw __P((WINDOW *, int, int, const char *, ...));
|
||||
WINDOW *newwin __P((int, int, int, int));
|
||||
int nl __P((void));
|
||||
int nocbreak __P((void));
|
||||
int noecho __P((void));
|
||||
int nonl __P((void));
|
||||
int noraw __P((void));
|
||||
int overlay __P((WINDOW *, WINDOW *));
|
||||
int overwrite __P((WINDOW *, WINDOW *));
|
||||
int printw __P((const char *, ...));
|
||||
int raw __P((void));
|
||||
int resetty __P((void));
|
||||
int savetty __P((void));
|
||||
int scanw __P((const char *, ...));
|
||||
int scroll __P((WINDOW *));
|
||||
int setterm __P((char *));
|
||||
int sscans __P((WINDOW *, const char *, ...));
|
||||
WINDOW *subwin __P((WINDOW *, int, int, int, int));
|
||||
int suspendwin __P((void));
|
||||
int touchline __P((WINDOW *, int, int, int));
|
||||
int touchoverlap __P((WINDOW *, WINDOW *));
|
||||
int touchwin __P((WINDOW *));
|
||||
int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
|
||||
int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_));
|
||||
int waddch __P((WINDOW *, int));
|
||||
int waddnstr __P((WINDOW *, const char *, int));
|
||||
int wclear __P((WINDOW *));
|
||||
int wclrtobot __P((WINDOW *));
|
||||
int wclrtoeol __P((WINDOW *));
|
||||
int wdelch __P((WINDOW *));
|
||||
int wdeleteln __P((WINDOW *));
|
||||
int werase __P((WINDOW *));
|
||||
int wgetch __P((WINDOW *));
|
||||
int wgetstr __P((WINDOW *, char *));
|
||||
int winsch __P((WINDOW *, int));
|
||||
int winsertln __P((WINDOW *));
|
||||
int wmove __P((WINDOW *, int, int));
|
||||
int wprintw __P((WINDOW *, const char *, ...));
|
||||
int wrefresh __P((WINDOW *));
|
||||
int wscanw __P((WINDOW *, const char *, ...));
|
||||
int wstandend __P((WINDOW *));
|
||||
int wstandout __P((WINDOW *));
|
||||
int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
|
||||
|
||||
/* Private functions that are needed for user programs prototypes. */
|
||||
void __cputchar __P((int));
|
||||
int __waddbytes __P((WINDOW *, const char *, int, int));
|
||||
|
||||
/* Private functions. */
|
||||
#ifdef _CURSES_PRIVATE
|
||||
void __CTRACE __P((const char *, ...));
|
||||
u_int __hash __P((char *, int));
|
||||
void __id_subwins __P((WINDOW *));
|
||||
int __mvcur __P((int, int, int, int, int));
|
||||
void __restore_stophandler __P((void));
|
||||
void __set_stophandler __P((void));
|
||||
void __set_subwin __P((WINDOW *, WINDOW *));
|
||||
void __startwin __P((void));
|
||||
void __stop_signal_handler __P((int));
|
||||
void __swflags __P((WINDOW *));
|
||||
int __touchline __P((WINDOW *, int, int, int, int));
|
||||
int __touchwin __P((WINDOW *));
|
||||
char *__tscroll __P((const char *, int, int));
|
||||
int __waddch __P((WINDOW *, __LDATA *));
|
||||
|
||||
/* Private #defines. */
|
||||
#define min(a,b) (a < b ? a : b)
|
||||
#define max(a,b) (a > b ? a : b)
|
||||
|
||||
/* Private externs. */
|
||||
extern int __echoit;
|
||||
extern int __endwin;
|
||||
extern int __pfast;
|
||||
extern int __rawmode;
|
||||
extern int __noqch;
|
||||
#endif
|
||||
|
||||
/* Termcap functions. */
|
||||
int tgetent __P((char *, char *));
|
||||
int tgetnum __P((char *));
|
||||
int tgetflag __P((char *));
|
||||
char *tgetstr __P((char *, char **));
|
||||
char *tgoto __P((char *, int, int));
|
||||
int tputs __P((char *, int, void (*)(int)));
|
||||
|
||||
#endif /* !_CURSES_H_ */
|
63
lib/libcurses/delch.c
Normal file
63
lib/libcurses/delch.c
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)delch.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wdelch --
|
||||
* Do an insert-char on the line, leaving (cury, curx) unchanged.
|
||||
*/
|
||||
int
|
||||
wdelch(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register __LDATA *end, *temp1, *temp2;
|
||||
|
||||
end = &win->lines[win->cury]->line[win->maxx - 1];
|
||||
temp1 = &win->lines[win->cury]->line[win->curx];
|
||||
temp2 = temp1 + 1;
|
||||
while (temp1 < end) {
|
||||
(void)memcpy(temp1, temp2, sizeof(__LDATA));
|
||||
temp1++, temp2++;
|
||||
}
|
||||
temp1->ch = ' ';
|
||||
temp1->attr = 0;
|
||||
__touchline(win, win->cury, win->curx, win->maxx - 1, 0);
|
||||
return (OK);
|
||||
}
|
82
lib/libcurses/deleteln.c
Normal file
82
lib/libcurses/deleteln.c
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)deleteln.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wdeleteln --
|
||||
* Delete a line from the screen. It leaves (cury, curx) unchanged.
|
||||
*/
|
||||
int
|
||||
wdeleteln(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int y, i;
|
||||
register __LINE *temp;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("deleteln: (%0.2o)\n", win);
|
||||
#endif
|
||||
temp = win->lines[win->cury];
|
||||
for (y = win->cury; y < win->maxy - 1; y++) {
|
||||
win->lines[y]->flags &= ~__ISPASTEOL;
|
||||
win->lines[y + 1]->flags &= ~__ISPASTEOL;
|
||||
if (win->orig == NULL)
|
||||
win->lines[y] = win->lines[y + 1];
|
||||
else
|
||||
(void) memcpy(win->lines[y]->line,
|
||||
win->lines[y + 1]->line,
|
||||
win->maxx * __LDATASIZE);
|
||||
__touchline(win, y, 0, win->maxx - 1, 0);
|
||||
}
|
||||
|
||||
if (win->orig == NULL)
|
||||
win->lines[y] = temp;
|
||||
else
|
||||
temp = win->lines[y];
|
||||
|
||||
for(i = 0; i < win->maxx; i++) {
|
||||
temp->line[i].ch = ' ';
|
||||
temp->line[i].attr = 0;
|
||||
}
|
||||
__touchline(win, y, 0, win->maxx - 1, 0);
|
||||
if (win->orig == NULL)
|
||||
__id_subwins(win);
|
||||
return (OK);
|
||||
}
|
80
lib/libcurses/delwin.c
Normal file
80
lib/libcurses/delwin.c
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)delwin.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* delwin --
|
||||
* Delete a window and release it back to the system.
|
||||
*/
|
||||
int
|
||||
delwin(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
|
||||
register WINDOW *wp, *np;
|
||||
|
||||
if (win->orig == NULL) {
|
||||
/*
|
||||
* If we are the original window, delete the space for all
|
||||
* the subwindows, the line space and the window space.
|
||||
*/
|
||||
free(win->lspace);
|
||||
free(win->wspace);
|
||||
free(win->lines);
|
||||
wp = win->nextp;
|
||||
while (wp != win) {
|
||||
np = wp->nextp;
|
||||
delwin(wp);
|
||||
wp = np;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* If we are a subwindow, take ourselves out of the list.
|
||||
* NOTE: if we are a subwindow, the minimum list is orig
|
||||
* followed by this subwindow, so there are always at least
|
||||
* two windows in the list.
|
||||
*/
|
||||
for (wp = win->nextp; wp->nextp != win; wp = wp->nextp)
|
||||
continue;
|
||||
wp->nextp = win->nextp;
|
||||
}
|
||||
free(win);
|
||||
return (OK);
|
||||
}
|
72
lib/libcurses/erase.c
Normal file
72
lib/libcurses/erase.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)erase.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* werase --
|
||||
* Erases everything on the window.
|
||||
*/
|
||||
int
|
||||
werase(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
|
||||
register int minx, y;
|
||||
register __LDATA *sp, *end, *start, *maxx;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("werase: (%0.2o)\n", win);
|
||||
#endif
|
||||
for (y = 0; y < win->maxy; y++) {
|
||||
minx = -1;
|
||||
start = win->lines[y]->line;
|
||||
end = &start[win->maxx];
|
||||
for (sp = start; sp < end; sp++)
|
||||
if (sp->ch != ' ' || sp->attr != 0) {
|
||||
maxx = sp;
|
||||
if (minx == -1)
|
||||
minx = sp - start;
|
||||
sp->ch = ' ';
|
||||
sp->attr = 0;
|
||||
}
|
||||
if (minx != -1)
|
||||
__touchline(win, y, minx, maxx - win->lines[y]->line,
|
||||
0);
|
||||
}
|
||||
return (OK);
|
||||
}
|
75
lib/libcurses/getch.c
Normal file
75
lib/libcurses/getch.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wgetch --
|
||||
* Read in a character from the window.
|
||||
*/
|
||||
int
|
||||
wgetch(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int inp, weset;
|
||||
|
||||
if (!(win->flags & __SCROLLOK) && (win->flags & __FULLWIN)
|
||||
&& win->curx == win->maxx - 1 && win->cury == win->maxy - 1)
|
||||
return (ERR);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("wgetch: __echoit = %d, __rawmode = %d\n",
|
||||
__echoit, __rawmode);
|
||||
#endif
|
||||
if (__echoit && !__rawmode) {
|
||||
cbreak();
|
||||
weset = 1;
|
||||
} else
|
||||
weset = 0;
|
||||
|
||||
inp = getchar();
|
||||
#ifdef DEBUG
|
||||
__CTRACE("wgetch got '%s'\n", unctrl(inp));
|
||||
#endif
|
||||
if (__echoit) {
|
||||
mvwaddch(curscr,
|
||||
win->cury + win->begy, win->curx + win->begx, inp);
|
||||
waddch(win, inp);
|
||||
}
|
||||
if (weset)
|
||||
nocbreak();
|
||||
return (inp);
|
||||
}
|
57
lib/libcurses/getstr.c
Normal file
57
lib/libcurses/getstr.c
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)getstr.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wgetstr --
|
||||
* Get a string starting at (cury, curx).
|
||||
*/
|
||||
int
|
||||
wgetstr(win, str)
|
||||
register WINDOW *win;
|
||||
register char *str;
|
||||
{
|
||||
while ((*str = wgetch(win)) != ERR && *str != '\n')
|
||||
str++;
|
||||
if (*str == ERR) {
|
||||
*str = '\0';
|
||||
return (ERR);
|
||||
}
|
||||
*str = '\0';
|
||||
return (OK);
|
||||
}
|
65
lib/libcurses/id_subwins.c
Normal file
65
lib/libcurses/id_subwins.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)id_subwins.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* __id_subwins --
|
||||
* Re-sync the pointers to lines for all the subwindows.
|
||||
*/
|
||||
void
|
||||
__id_subwins(orig)
|
||||
register WINDOW *orig;
|
||||
{
|
||||
register WINDOW *win;
|
||||
register int oy, realy, y;
|
||||
|
||||
realy = orig->begy + orig->cury;
|
||||
for (win = orig->nextp; win != orig; win = win->nextp) {
|
||||
/*
|
||||
* If the window ends before our current position, don't need
|
||||
* to do anything.
|
||||
*/
|
||||
if (win->begy + win->maxy <= realy)
|
||||
continue;
|
||||
|
||||
oy = orig->cury;
|
||||
for (y = realy - win->begy; y < win->maxy; y++, oy++)
|
||||
win->lines[y]->line =
|
||||
&orig->lines[oy]->line[win->ch_off];
|
||||
}
|
||||
}
|
54
lib/libcurses/idlok.c
Normal file
54
lib/libcurses/idlok.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)idlok.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* idlok --
|
||||
* Turn on and off using insert/deleteln sequences for the
|
||||
* given window.
|
||||
*/
|
||||
void
|
||||
idlok(win, bf)
|
||||
WINDOW *win;
|
||||
int bf;
|
||||
{
|
||||
if (bf)
|
||||
win->flags |= __IDLINE;
|
||||
else
|
||||
win->flags &= ~__IDLINE;
|
||||
}
|
95
lib/libcurses/initscr.c
Normal file
95
lib/libcurses/initscr.c
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)initscr.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* initscr --
|
||||
* Initialize the current and standard screen.
|
||||
*/
|
||||
WINDOW *
|
||||
initscr()
|
||||
{
|
||||
register char *sp;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("initscr\n");
|
||||
#endif
|
||||
__echoit = 1;
|
||||
__pfast = __rawmode = __noqch = 0;
|
||||
|
||||
if (gettmode() == ERR)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* If My_term is set, or can't find a terminal in the environment,
|
||||
* use Def_term.
|
||||
*/
|
||||
if (My_term || (sp = getenv("TERM")) == NULL)
|
||||
sp = Def_term;
|
||||
if (setterm(sp) == ERR)
|
||||
return (NULL);
|
||||
|
||||
/* Need either homing or cursor motion for refreshes */
|
||||
if (!HO && !CM)
|
||||
return (NULL);
|
||||
|
||||
if (curscr != NULL)
|
||||
delwin(curscr);
|
||||
if ((curscr = newwin(LINES, COLS, 0, 0)) == ERR)
|
||||
return (NULL);
|
||||
clearok(curscr, 1);
|
||||
|
||||
if (stdscr != NULL)
|
||||
delwin(stdscr);
|
||||
if ((stdscr = newwin(LINES, COLS, 0, 0)) == ERR) {
|
||||
delwin(curscr);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
__set_stophandler();
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
|
||||
#endif
|
||||
__startwin();
|
||||
|
||||
return (stdscr);
|
||||
}
|
74
lib/libcurses/insch.c
Normal file
74
lib/libcurses/insch.c
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)insch.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* winsch --
|
||||
* Do an insert-char on the line, leaving (cury, curx) unchanged.
|
||||
*/
|
||||
int
|
||||
winsch(win, ch)
|
||||
register WINDOW *win;
|
||||
int ch;
|
||||
{
|
||||
|
||||
register __LDATA *end, *temp1, *temp2;
|
||||
|
||||
end = &win->lines[win->cury]->line[win->curx];
|
||||
temp1 = &win->lines[win->cury]->line[win->maxx - 1];
|
||||
temp2 = temp1 - 1;
|
||||
while (temp1 > end) {
|
||||
(void)memcpy(temp1, temp2, sizeof(__LDATA));
|
||||
temp1--, temp2--;
|
||||
}
|
||||
temp1->ch = ch;
|
||||
temp1->attr &= ~__STANDOUT;
|
||||
__touchline(win, win->cury, win->curx, win->maxx - 1, 0);
|
||||
if (win->cury == LINES - 1 &&
|
||||
(win->lines[LINES - 1]->line[COLS - 1].ch != ' ' ||
|
||||
win->lines[LINES -1]->line[COLS - 1].attr != 0))
|
||||
if (win->flags & __SCROLLOK) {
|
||||
wrefresh(win);
|
||||
scroll(win);
|
||||
win->cury--;
|
||||
} else
|
||||
return (ERR);
|
||||
return (OK);
|
||||
}
|
82
lib/libcurses/insertln.c
Normal file
82
lib/libcurses/insertln.c
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)insertln.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* winsertln --
|
||||
* Do an insert-line on the window, leaving (cury, curx) unchanged.
|
||||
*/
|
||||
int
|
||||
winsertln(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
|
||||
register int y, i;
|
||||
register __LINE *temp;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("insertln: (%0.2o)\n", win);
|
||||
#endif
|
||||
if (win->orig == NULL)
|
||||
temp = win->lines[win->maxy - 1];
|
||||
for (y = win->maxy - 1; y > win->cury; --y) {
|
||||
win->lines[y]->flags &= ~__ISPASTEOL;
|
||||
win->lines[y - 1]->flags &= ~__ISPASTEOL;
|
||||
if (win->orig == NULL)
|
||||
win->lines[y] = win->lines[y - 1];
|
||||
else
|
||||
(void)memcpy(win->lines[y]->line,
|
||||
win->lines[y - 1]->line,
|
||||
win->maxx * __LDATASIZE);
|
||||
__touchline(win, y, 0, win->maxx - 1, 0);
|
||||
}
|
||||
if (win->orig == NULL)
|
||||
win->lines[y] = temp;
|
||||
else
|
||||
temp = win->lines[y];
|
||||
for(i = 0; i < win->maxx; i++) {
|
||||
temp->line[i].ch = ' ';
|
||||
temp->line[i].attr = 0;
|
||||
}
|
||||
__touchline(win, y, 0, win->maxx - 1, 0);
|
||||
if (win->orig == NULL)
|
||||
__id_subwins(win);
|
||||
return (OK);
|
||||
}
|
62
lib/libcurses/move.c
Normal file
62
lib/libcurses/move.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)move.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wmove --
|
||||
* Moves the cursor to the given point.
|
||||
*/
|
||||
int
|
||||
wmove(win, y, x)
|
||||
register WINDOW *win;
|
||||
register int y, x;
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("wmove: (%d, %d)\n", y, x);
|
||||
#endif
|
||||
if (x < 0 || y < 0)
|
||||
return (ERR);
|
||||
if (x >= win->maxx || y >= win->maxy)
|
||||
return (ERR);
|
||||
win->curx = x;
|
||||
win->lines[win->cury]->flags &= ~__ISPASTEOL;
|
||||
win->cury = y;
|
||||
win->lines[y]->flags &= ~__ISPASTEOL;
|
||||
return (OK);
|
||||
}
|
77
lib/libcurses/mvwin.c
Normal file
77
lib/libcurses/mvwin.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)mvwin.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* mvwin --
|
||||
* Relocate the starting position of a window.
|
||||
*/
|
||||
int
|
||||
mvwin(win, by, bx)
|
||||
register WINDOW *win;
|
||||
register int by, bx;
|
||||
{
|
||||
register WINDOW *orig;
|
||||
register int dy, dx;
|
||||
|
||||
if (by + win->maxy > LINES || bx + win->maxx > COLS)
|
||||
return (ERR);
|
||||
dy = by - win->begy;
|
||||
dx = bx - win->begx;
|
||||
orig = win->orig;
|
||||
if (orig == NULL) {
|
||||
orig = win;
|
||||
do {
|
||||
win->begy += dy;
|
||||
win->begx += dx;
|
||||
__swflags(win);
|
||||
win = win->nextp;
|
||||
} while (win != orig);
|
||||
} else {
|
||||
if (by < orig->begy || win->maxy + dy > orig->maxy)
|
||||
return (ERR);
|
||||
if (bx < orig->begx || win->maxx + dx > orig->maxx)
|
||||
return (ERR);
|
||||
win->begy = by;
|
||||
win->begx = bx;
|
||||
__swflags(win);
|
||||
__set_subwin(orig, win);
|
||||
}
|
||||
__touchwin(win);
|
||||
return (OK);
|
||||
}
|
244
lib/libcurses/newwin.c
Normal file
244
lib/libcurses/newwin.c
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
#undef nl /* Don't need it here, and it interferes. */
|
||||
|
||||
static WINDOW *__makenew __P((int, int, int, int, int));
|
||||
|
||||
void __set_subwin __P((WINDOW *, WINDOW *));
|
||||
|
||||
/*
|
||||
* newwin --
|
||||
* Allocate space for and set up defaults for a new window.
|
||||
*/
|
||||
WINDOW *
|
||||
newwin(nl, nc, by, bx)
|
||||
register int nl, nc, by, bx;
|
||||
{
|
||||
register WINDOW *win;
|
||||
register __LINE *lp;
|
||||
register int i, j;
|
||||
register __LDATA *sp;
|
||||
|
||||
if (nl == 0)
|
||||
nl = LINES - by;
|
||||
if (nc == 0)
|
||||
nc = COLS - bx;
|
||||
|
||||
if ((win = __makenew(nl, nc, by, bx, 0)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
win->nextp = win;
|
||||
win->ch_off = 0;
|
||||
win->orig = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("newwin: win->ch_off = %d\n", win->ch_off);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < nl; i++) {
|
||||
lp = win->lines[i];
|
||||
lp->flags = 0;
|
||||
for (sp = lp->line, j = 0; j < nc; j++, sp++) {
|
||||
sp->ch = ' ';
|
||||
sp->attr = 0;
|
||||
}
|
||||
lp->hash = __hash((char *) lp->line, nc * __LDATASIZE);
|
||||
}
|
||||
return (win);
|
||||
}
|
||||
|
||||
WINDOW *
|
||||
subwin(orig, nl, nc, by, bx)
|
||||
register WINDOW *orig;
|
||||
register int by, bx, nl, nc;
|
||||
{
|
||||
int i;
|
||||
__LINE *lp;
|
||||
register WINDOW *win;
|
||||
|
||||
/* Make sure window fits inside the original one. */
|
||||
#ifdef DEBUG
|
||||
__CTRACE("subwin: (%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
|
||||
#endif
|
||||
if (by < orig->begy || bx < orig->begx
|
||||
|| by + nl > orig->maxy + orig->begy
|
||||
|| bx + nc > orig->maxx + orig->begx)
|
||||
return (NULL);
|
||||
if (nl == 0)
|
||||
nl = orig->maxy + orig->begy - by;
|
||||
if (nc == 0)
|
||||
nc = orig->maxx + orig->begx - bx;
|
||||
if ((win = __makenew(nl, nc, by, bx, 1)) == NULL)
|
||||
return (NULL);
|
||||
win->nextp = orig->nextp;
|
||||
orig->nextp = win;
|
||||
win->orig = orig;
|
||||
|
||||
/* Initialize flags here so that refresh can also use __set_subwin. */
|
||||
for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++)
|
||||
lp->flags = 0;
|
||||
__set_subwin(orig, win);
|
||||
return (win);
|
||||
}
|
||||
|
||||
/*
|
||||
* This code is shared with mvwin().
|
||||
*/
|
||||
void
|
||||
__set_subwin(orig, win)
|
||||
register WINDOW *orig, *win;
|
||||
{
|
||||
int i;
|
||||
__LINE *lp, *olp;
|
||||
|
||||
win->ch_off = win->begx - orig->begx;
|
||||
/* Point line pointers to line space. */
|
||||
for (lp = win->lspace, i = 0; i < win->maxy; i++, lp++) {
|
||||
win->lines[i] = lp;
|
||||
olp = orig->lines[i + win->begy];
|
||||
lp->line = &olp->line[win->begx];
|
||||
lp->firstchp = &olp->firstch;
|
||||
lp->lastchp = &olp->lastch;
|
||||
lp->hash = __hash((char *) lp->line, win->maxx * __LDATASIZE);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("__set_subwin: win->ch_off = %d\n", win->ch_off);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* __makenew --
|
||||
* Set up a window buffer and returns a pointer to it.
|
||||
*/
|
||||
static WINDOW *
|
||||
__makenew(nl, nc, by, bx, sub)
|
||||
register int by, bx, nl, nc;
|
||||
int sub;
|
||||
{
|
||||
register WINDOW *win;
|
||||
register __LINE *lp;
|
||||
int i;
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makenew: (%d, %d, %d, %d)\n", nl, nc, by, bx);
|
||||
#endif
|
||||
if ((win = malloc(sizeof(*win))) == NULL)
|
||||
return (NULL);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makenew: nl = %d\n", nl);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set up line pointer array and line space.
|
||||
*/
|
||||
if ((win->lines = malloc (nl * sizeof(__LINE *))) == NULL) {
|
||||
free(win);
|
||||
return NULL;
|
||||
}
|
||||
if ((win->lspace = malloc (nl * sizeof(__LINE))) == NULL) {
|
||||
free (win);
|
||||
free (win->lines);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Don't allocate window and line space if it's a subwindow */
|
||||
if (!sub) {
|
||||
/*
|
||||
* Allocate window space in one chunk.
|
||||
*/
|
||||
if ((win->wspace =
|
||||
malloc(nc * nl * sizeof(__LDATA))) == NULL) {
|
||||
free(win->lines);
|
||||
free(win->lspace);
|
||||
free(win);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Point line pointers to line space, and lines themselves into
|
||||
* window space.
|
||||
*/
|
||||
for (lp = win->lspace, i = 0; i < nl; i++, lp++) {
|
||||
win->lines[i] = lp;
|
||||
lp->line = &win->wspace[i * nc];
|
||||
lp->firstchp = &lp->firstch;
|
||||
lp->lastchp = &lp->lastch;
|
||||
lp->firstch = 0;
|
||||
lp->lastch = 0;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makenew: nc = %d\n", nc);
|
||||
#endif
|
||||
win->cury = win->curx = 0;
|
||||
win->maxy = nl;
|
||||
win->maxx = nc;
|
||||
|
||||
win->begy = by;
|
||||
win->begx = bx;
|
||||
win->flags = 0;
|
||||
__swflags(win);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makenew: win->flags = %0.2o\n", win->flags);
|
||||
__CTRACE("makenew: win->maxy = %d\n", win->maxy);
|
||||
__CTRACE("makenew: win->maxx = %d\n", win->maxx);
|
||||
__CTRACE("makenew: win->begy = %d\n", win->begy);
|
||||
__CTRACE("makenew: win->begx = %d\n", win->begx);
|
||||
#endif
|
||||
return (win);
|
||||
}
|
||||
|
||||
void
|
||||
__swflags(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
win->flags &= ~(__ENDLINE | __FULLWIN | __SCROLLWIN | __LEAVEOK);
|
||||
if (win->begx + win->maxx == COLS) {
|
||||
win->flags |= __ENDLINE;
|
||||
if (win->begx == 0 && win->maxy == LINES && win->begy == 0)
|
||||
win->flags |= __FULLWIN;
|
||||
if (win->begy + win->maxy == LINES)
|
||||
win->flags |= __SCROLLWIN;
|
||||
}
|
||||
}
|
82
lib/libcurses/overlay.c
Normal file
82
lib/libcurses/overlay.c
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)overlay.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* overlay --
|
||||
* Writes win1 on win2 non-destructively.
|
||||
*/
|
||||
int
|
||||
overlay(win1, win2)
|
||||
register WINDOW *win1, *win2;
|
||||
{
|
||||
|
||||
register int x, y, y1, y2, endy, endx, starty, startx;
|
||||
register __LDATA *sp, *end;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("overlay: (%0.2o, %0.2o);\n", win1, win2);
|
||||
#endif
|
||||
starty = max(win1->begy, win2->begy);
|
||||
startx = max(win1->begx, win2->begx);
|
||||
endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
|
||||
endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("overlay: from (%d,%d) to (%d,%d)\n",
|
||||
starty, startx, endy, endx);
|
||||
#endif
|
||||
if (starty >= endy || startx >= endx)
|
||||
return (OK);
|
||||
y1 = starty - win1->begy;
|
||||
y2 = starty - win2->begy;
|
||||
for (y = starty; y < endy; y++, y1++, y2++) {
|
||||
end = &win1->lines[y1]->line[endx - win1->begx];
|
||||
x = startx - win2->begx;
|
||||
for (sp = &win1->lines[y1]->line[startx - win1->begx];
|
||||
sp < end; sp++) {
|
||||
if (!isspace(sp->ch)) {
|
||||
wmove(win2, y2, x);
|
||||
__waddch(win2, sp);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
return (OK);
|
||||
}
|
76
lib/libcurses/overwrite.c
Normal file
76
lib/libcurses/overwrite.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)overwrite.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* overwrite --
|
||||
* Writes win1 on win2 destructively.
|
||||
*/
|
||||
int
|
||||
overwrite(win1, win2)
|
||||
register WINDOW *win1, *win2;
|
||||
{
|
||||
register int x, y, endy, endx, starty, startx;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("overwrite: (%0.2o, %0.2o);\n", win1, win2);
|
||||
#endif
|
||||
starty = max(win1->begy, win2->begy);
|
||||
startx = max(win1->begx, win2->begx);
|
||||
endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
|
||||
endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
|
||||
if (starty >= endy || startx >= endx)
|
||||
return (OK);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("overwrite: from (%d, %d) to (%d, %d)\n",
|
||||
starty, startx, endy, endx);
|
||||
#endif
|
||||
x = endx - startx;
|
||||
for (y = starty; y < endy; y++) {
|
||||
(void)memcpy(
|
||||
&win2->lines[y - win2->begy]->line[startx - win2->begx],
|
||||
&win1->lines[y - win1->begy]->line[startx - win1->begx],
|
||||
x * __LDATASIZE);
|
||||
__touchline(win2, y, startx - win2->begx, endx - win2->begx,
|
||||
0);
|
||||
}
|
||||
return (OK);
|
||||
}
|
200
lib/libcurses/printw.c
Normal file
200
lib/libcurses/printw.c
Normal file
@ -0,0 +1,200 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)printw.c 8.3 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* printw and friends.
|
||||
*
|
||||
* These routines make nonportable assumptions about varargs if __STDC__
|
||||
* is not in effect.
|
||||
*/
|
||||
|
||||
static int __winwrite __P((void *, const char *, int));
|
||||
|
||||
/*
|
||||
* printw --
|
||||
* Printf on the standard screen.
|
||||
*/
|
||||
int
|
||||
#ifdef __STDC__
|
||||
printw(const char *fmt, ...)
|
||||
#else
|
||||
printw(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
ret = vwprintw(stdscr, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* wprintw --
|
||||
* Printf on the given window.
|
||||
*/
|
||||
int
|
||||
#ifdef __STDC__
|
||||
wprintw(WINDOW * win, const char *fmt, ...)
|
||||
#else
|
||||
wprintw(win, fmt, va_alist)
|
||||
WINDOW *win;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
ret = vwprintw(win, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvprintw, mvwprintw --
|
||||
* Implement the mvprintw commands. Due to the variable number of
|
||||
* arguments, they cannot be macros. Sigh....
|
||||
*/
|
||||
int
|
||||
#ifdef __STDC__
|
||||
mvprintw(register int y, register int x, const char *fmt, ...)
|
||||
#else
|
||||
mvprintw(y, x, fmt, va_alist)
|
||||
register int y, x;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
if (move(y, x) != OK)
|
||||
return (ERR);
|
||||
ret = vwprintw(stdscr, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
#ifdef __STDC__
|
||||
mvwprintw(register WINDOW * win, register int y, register int x,
|
||||
const char *fmt, ...)
|
||||
#else
|
||||
mvwprintw(win, y, x, fmt, va_alist)
|
||||
register WINDOW *win;
|
||||
register int y, x;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
if (wmove(win, y, x) != OK)
|
||||
return (ERR);
|
||||
|
||||
ret = vwprintw(win, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal write-buffer-to-window function.
|
||||
*/
|
||||
static int
|
||||
__winwrite(cookie, buf, n)
|
||||
void *cookie;
|
||||
register const char *buf;
|
||||
int n;
|
||||
{
|
||||
register WINDOW *win;
|
||||
register int c;
|
||||
|
||||
for (c = n, win = cookie; --c >= 0;)
|
||||
if (waddch(win, *buf++) == ERR)
|
||||
return (-1);
|
||||
return (n);
|
||||
}
|
||||
|
||||
/*
|
||||
* vwprintw --
|
||||
* This routine actually executes the printf and adds it to the window.
|
||||
*/
|
||||
int
|
||||
vwprintw(win, fmt, ap)
|
||||
WINDOW *win;
|
||||
const char *fmt;
|
||||
va_list ap;
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL)
|
||||
return (ERR);
|
||||
(void)vfprintf(f, fmt, ap);
|
||||
return (fclose(f) ? ERR : OK);
|
||||
}
|
49
lib/libcurses/putchar.c
Normal file
49
lib/libcurses/putchar.c
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)putchar.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
void
|
||||
__cputchar(ch)
|
||||
int ch;
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("__cputchar: %s\n", unctrl(ch));
|
||||
#endif
|
||||
(void)putchar(ch);
|
||||
}
|
827
lib/libcurses/refresh.c
Normal file
827
lib/libcurses/refresh.c
Normal file
@ -0,0 +1,827 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
static int curwin;
|
||||
static short ly, lx;
|
||||
|
||||
static void domvcur __P((int, int, int, int));
|
||||
static int makech __P((WINDOW *, int));
|
||||
static void quickch __P((WINDOW *));
|
||||
static void scrolln __P((WINDOW *, int, int, int, int, int));
|
||||
|
||||
/*
|
||||
* wrefresh --
|
||||
* Make the current screen look like "win" over the area coverd by
|
||||
* win.
|
||||
*/
|
||||
int
|
||||
wrefresh(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register __LINE *wlp;
|
||||
register int retval;
|
||||
register short wy;
|
||||
int dnum;
|
||||
|
||||
/* Initialize loop parameters. */
|
||||
ly = curscr->cury;
|
||||
lx = curscr->curx;
|
||||
wy = 0;
|
||||
curwin = (win == curscr);
|
||||
|
||||
if (!curwin)
|
||||
for (wy = 0; wy < win->maxy; wy++) {
|
||||
wlp = win->lines[wy];
|
||||
if (wlp->flags & __ISDIRTY)
|
||||
wlp->hash = __hash((char *)wlp->line,
|
||||
win->maxx * __LDATASIZE);
|
||||
}
|
||||
|
||||
if (win->flags & __CLEAROK || curscr->flags & __CLEAROK || curwin) {
|
||||
if ((win->flags & __FULLWIN) || curscr->flags & __CLEAROK) {
|
||||
tputs(CL, 0, __cputchar);
|
||||
ly = 0;
|
||||
lx = 0;
|
||||
if (!curwin) {
|
||||
curscr->flags &= ~__CLEAROK;
|
||||
curscr->cury = 0;
|
||||
curscr->curx = 0;
|
||||
werase(curscr);
|
||||
}
|
||||
__touchwin(win);
|
||||
}
|
||||
win->flags &= ~__CLEAROK;
|
||||
}
|
||||
if (!CA) {
|
||||
if (win->curx != 0)
|
||||
putchar('\n');
|
||||
if (!curwin)
|
||||
werase(curscr);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("wrefresh: (%0.2o): curwin = %d\n", win, curwin);
|
||||
__CTRACE("wrefresh: \tfirstch\tlastch\n");
|
||||
#endif
|
||||
|
||||
#ifndef NOQCH
|
||||
if ((win->flags & __FULLWIN) && !curwin) {
|
||||
/*
|
||||
* Invoke quickch() only if more than a quarter of the lines
|
||||
* in the window are dirty.
|
||||
*/
|
||||
for (wy = 0, dnum = 0; wy < win->maxy; wy++)
|
||||
if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT))
|
||||
dnum++;
|
||||
if (!__noqch && dnum > (int) win->maxy / 4)
|
||||
quickch(win);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
{ int i, j;
|
||||
__CTRACE("#####################################\n");
|
||||
for (i = 0; i < curscr->maxy; i++) {
|
||||
__CTRACE("C: %d:", i);
|
||||
__CTRACE(" 0x%x \n", curscr->lines[i]->hash);
|
||||
for (j = 0; j < curscr->maxx; j++)
|
||||
__CTRACE("%c",
|
||||
curscr->lines[i]->line[j].ch);
|
||||
__CTRACE("\n");
|
||||
for (j = 0; j < curscr->maxx; j++)
|
||||
__CTRACE("%x",
|
||||
curscr->lines[i]->line[j].attr);
|
||||
__CTRACE("\n");
|
||||
__CTRACE("W: %d:", i);
|
||||
__CTRACE(" 0x%x \n", win->lines[i]->hash);
|
||||
__CTRACE(" 0x%x ", win->lines[i]->flags);
|
||||
for (j = 0; j < win->maxx; j++)
|
||||
__CTRACE("%c",
|
||||
win->lines[i]->line[j].ch);
|
||||
__CTRACE("\n");
|
||||
for (j = 0; j < win->maxx; j++)
|
||||
__CTRACE("%x",
|
||||
win->lines[i]->line[j].attr);
|
||||
__CTRACE("\n");
|
||||
}
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
for (wy = 0; wy < win->maxy; wy++) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE("%d\t%d\t%d\n",
|
||||
wy, *win->lines[wy]->firstchp, *win->lines[wy]->lastchp);
|
||||
#endif
|
||||
if (!curwin)
|
||||
curscr->lines[wy]->hash = win->lines[wy]->hash;
|
||||
if (win->lines[wy]->flags & (__ISDIRTY | __FORCEPAINT)) {
|
||||
if (makech(win, wy) == ERR)
|
||||
return (ERR);
|
||||
else {
|
||||
if (*win->lines[wy]->firstchp >= win->ch_off)
|
||||
*win->lines[wy]->firstchp = win->maxx +
|
||||
win->ch_off;
|
||||
if (*win->lines[wy]->lastchp < win->maxx +
|
||||
win->ch_off)
|
||||
*win->lines[wy]->lastchp = win->ch_off;
|
||||
if (*win->lines[wy]->lastchp <
|
||||
*win->lines[wy]->firstchp) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE("wrefresh: line %d notdirty \n", wy);
|
||||
#endif
|
||||
win->lines[wy]->flags &= ~__ISDIRTY;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("\t%d\t%d\n", *win->lines[wy]->firstchp,
|
||||
*win->lines[wy]->lastchp);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("refresh: ly=%d, lx=%d\n", ly, lx);
|
||||
#endif
|
||||
|
||||
if (win == curscr)
|
||||
domvcur(ly, lx, win->cury, win->curx);
|
||||
else {
|
||||
if (win->flags & __LEAVEOK) {
|
||||
curscr->cury = ly;
|
||||
curscr->curx = lx;
|
||||
ly -= win->begy;
|
||||
lx -= win->begx;
|
||||
if (ly >= 0 && ly < win->maxy && lx >= 0 &&
|
||||
lx < win->maxx) {
|
||||
win->cury = ly;
|
||||
win->curx = lx;
|
||||
} else
|
||||
win->cury = win->curx = 0;
|
||||
} else {
|
||||
domvcur(ly, lx, win->cury + win->begy,
|
||||
win->curx + win->begx);
|
||||
curscr->cury = win->cury + win->begy;
|
||||
curscr->curx = win->curx + win->begx;
|
||||
}
|
||||
}
|
||||
retval = OK;
|
||||
|
||||
(void)fflush(stdout);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
/*
|
||||
* makech --
|
||||
* Make a change on the screen.
|
||||
*/
|
||||
static int
|
||||
makech(win, wy)
|
||||
register WINDOW *win;
|
||||
int wy;
|
||||
{
|
||||
static __LDATA blank = {' ', 0};
|
||||
__LDATA *nsp, *csp, *cp, *cep;
|
||||
u_int force;
|
||||
int clsp, nlsp; /* Last space in lines. */
|
||||
int lch, wx, y;
|
||||
char *ce;
|
||||
|
||||
/* Is the cursor still on the end of the last line? */
|
||||
if (wy > 0 && win->lines[wy - 1]->flags & __ISPASTEOL) {
|
||||
domvcur(ly, lx, ly + 1, 0);
|
||||
ly++;
|
||||
lx = 0;
|
||||
}
|
||||
wx = *win->lines[wy]->firstchp - win->ch_off;
|
||||
if (wx < 0)
|
||||
wx = 0;
|
||||
else if (wx >= win->maxx)
|
||||
return (OK);
|
||||
lch = *win->lines[wy]->lastchp - win->ch_off;
|
||||
if (lch < 0)
|
||||
return (OK);
|
||||
else if (lch >= (int) win->maxx)
|
||||
lch = win->maxx - 1;
|
||||
y = wy + win->begy;
|
||||
|
||||
if (curwin)
|
||||
csp = ␣
|
||||
else
|
||||
csp = &curscr->lines[wy + win->begy]->line[wx + win->begx];
|
||||
|
||||
nsp = &win->lines[wy]->line[wx];
|
||||
force = win->lines[wy]->flags & __FORCEPAINT;
|
||||
win->lines[wy]->flags &= ~__FORCEPAINT;
|
||||
if (CE && !curwin) {
|
||||
for (cp = &win->lines[wy]->line[win->maxx - 1];
|
||||
cp->ch == ' ' && cp->attr == 0; cp--)
|
||||
if (cp <= win->lines[wy]->line)
|
||||
break;
|
||||
nlsp = cp - win->lines[wy]->line;
|
||||
}
|
||||
if (!curwin)
|
||||
ce = CE;
|
||||
else
|
||||
ce = NULL;
|
||||
|
||||
if (force) {
|
||||
if (CM)
|
||||
tputs(tgoto(CM, lx, ly), 0, __cputchar);
|
||||
else {
|
||||
tputs(HO, 0, __cputchar);
|
||||
__mvcur(0, 0, ly, lx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
while (wx <= lch) {
|
||||
if (!force && memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
|
||||
if (wx <= lch) {
|
||||
while (wx <= lch &&
|
||||
memcmp(nsp, csp, sizeof(__LDATA)) == 0) {
|
||||
nsp++;
|
||||
if (!curwin)
|
||||
++csp;
|
||||
++wx;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
domvcur(ly, lx, y, wx + win->begx);
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makech: 1: wx = %d, ly= %d, lx = %d, newy = %d, newx = %d, force =%d\n",
|
||||
wx, ly, lx, y, wx + win->begx, force);
|
||||
#endif
|
||||
ly = y;
|
||||
lx = wx + win->begx;
|
||||
while ((force || memcmp(nsp, csp, sizeof(__LDATA)) != 0)
|
||||
&& wx <= lch) {
|
||||
|
||||
if (ce != NULL &&
|
||||
win->maxx + win->begx == curscr->maxx &&
|
||||
wx >= nlsp && nsp->ch == ' ' && nsp->attr == 0) {
|
||||
/* Check for clear to end-of-line. */
|
||||
cep = &curscr->lines[wy]->line[win->maxx - 1];
|
||||
while (cep->ch == ' ' && cep->attr == 0)
|
||||
if (cep-- <= csp)
|
||||
break;
|
||||
clsp = cep - curscr->lines[wy]->line -
|
||||
win->begx * __LDATASIZE;
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makech: clsp = %d, nlsp = %d\n", clsp, nlsp);
|
||||
#endif
|
||||
if ((clsp - nlsp >= strlen(CE)
|
||||
&& clsp < win->maxx * __LDATASIZE) ||
|
||||
wy == win->maxy - 1) {
|
||||
if (curscr->flags & __WSTANDOUT) {
|
||||
tputs(SE, 0, __cputchar);
|
||||
curscr->flags &= ~__WSTANDOUT;
|
||||
}
|
||||
tputs(CE, 0, __cputchar);
|
||||
lx = wx + win->begx;
|
||||
while (wx++ <= clsp) {
|
||||
csp->ch = ' ';
|
||||
csp->attr = 0;
|
||||
csp++;
|
||||
}
|
||||
return (OK);
|
||||
}
|
||||
ce = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enter/exit standout mode as appropriate.
|
||||
* XXX
|
||||
* Should use UC if SO/SE not available.
|
||||
*/
|
||||
if (nsp->attr & __STANDOUT) {
|
||||
if (!(curscr->flags & __WSTANDOUT) &&
|
||||
SO != NULL && SE != NULL) {
|
||||
tputs(SO, 0, __cputchar);
|
||||
curscr->flags |= __WSTANDOUT;
|
||||
}
|
||||
} else
|
||||
if (curscr->flags & __WSTANDOUT &&
|
||||
SE != NULL) {
|
||||
tputs(SE, 0, __cputchar);
|
||||
curscr->flags &= ~__WSTANDOUT;
|
||||
}
|
||||
|
||||
wx++;
|
||||
if (wx >= win->maxx && wy == win->maxy - 1 && !curwin)
|
||||
if (win->flags & __SCROLLOK) {
|
||||
if (curscr->flags & __WSTANDOUT
|
||||
&& win->flags & __ENDLINE)
|
||||
if (!MS) {
|
||||
tputs(SE, 0,
|
||||
__cputchar);
|
||||
curscr->flags &=
|
||||
~__WSTANDOUT;
|
||||
}
|
||||
if (!(win->flags & __SCROLLWIN)) {
|
||||
if (!curwin) {
|
||||
csp->attr = nsp->attr;
|
||||
putchar(csp->ch = nsp->ch);
|
||||
} else
|
||||
putchar(nsp->ch);
|
||||
}
|
||||
if (wx + win->begx < curscr->maxx) {
|
||||
domvcur(ly, wx + win->begx,
|
||||
win->begy + win->maxy - 1,
|
||||
win->begx + win->maxx - 1);
|
||||
}
|
||||
ly = win->begy + win->maxy - 1;
|
||||
lx = win->begx + win->maxx - 1;
|
||||
return (OK);
|
||||
}
|
||||
if (wx < win->maxx || wy < win->maxy - 1 ||
|
||||
!(win->flags & __SCROLLWIN)) {
|
||||
if (!curwin) {
|
||||
csp->attr = nsp->attr;
|
||||
putchar(csp->ch = nsp->ch);
|
||||
csp++;
|
||||
} else
|
||||
putchar(nsp->ch);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makech: putchar(%c)\n", nsp->ch & 0177);
|
||||
#endif
|
||||
if (UC && (nsp->attr & __STANDOUT)) {
|
||||
putchar('\b');
|
||||
tputs(UC, 0, __cputchar);
|
||||
}
|
||||
nsp++;
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makech: 2: wx = %d, lx = %d\n", wx, lx);
|
||||
#endif
|
||||
}
|
||||
if (lx == wx + win->begx) /* If no change. */
|
||||
break;
|
||||
lx = wx + win->begx;
|
||||
if (lx >= COLS && AM)
|
||||
lx = COLS - 1;
|
||||
else if (wx >= win->maxx) {
|
||||
domvcur(ly, lx, ly, win->maxx + win->begx - 1);
|
||||
lx = win->maxx + win->begx - 1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("makech: 3: wx = %d, lx = %d\n", wx, lx);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Don't leave the screen in standout mode. */
|
||||
if (curscr->flags & __WSTANDOUT) {
|
||||
tputs(SE, 0, __cputchar);
|
||||
curscr->flags &= ~__WSTANDOUT;
|
||||
}
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* domvcur --
|
||||
* Do a mvcur, leaving standout mode if necessary.
|
||||
*/
|
||||
static void
|
||||
domvcur(oy, ox, ny, nx)
|
||||
int oy, ox, ny, nx;
|
||||
{
|
||||
if (curscr->flags & __WSTANDOUT && !MS) {
|
||||
tputs(SE, 0, __cputchar);
|
||||
curscr->flags &= ~__WSTANDOUT;
|
||||
}
|
||||
|
||||
__mvcur(oy, ox, ny, nx, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Quickch() attempts to detect a pattern in the change of the window
|
||||
* in order to optimize the change, e.g., scroll n lines as opposed to
|
||||
* repainting the screen line by line.
|
||||
*/
|
||||
|
||||
static void
|
||||
quickch(win)
|
||||
WINDOW *win;
|
||||
{
|
||||
#define THRESH (int) win->maxy / 4
|
||||
|
||||
register __LINE *clp, *tmp1, *tmp2;
|
||||
register int bsize, curs, curw, starts, startw, i, j;
|
||||
int n, target, cur_period, bot, top, sc_region;
|
||||
__LDATA buf[1024];
|
||||
u_int blank_hash;
|
||||
|
||||
/*
|
||||
* Find how many lines from the top of the screen are unchanged.
|
||||
*/
|
||||
for (top = 0; top < win->maxy; top++)
|
||||
if (win->lines[top]->flags & __FORCEPAINT ||
|
||||
win->lines[top]->hash != curscr->lines[top]->hash
|
||||
|| memcmp(win->lines[top]->line,
|
||||
curscr->lines[top]->line,
|
||||
win->maxx * __LDATASIZE) != 0)
|
||||
break;
|
||||
else
|
||||
win->lines[top]->flags &= ~__ISDIRTY;
|
||||
/*
|
||||
* Find how many lines from bottom of screen are unchanged.
|
||||
*/
|
||||
for (bot = win->maxy - 1; bot >= 0; bot--)
|
||||
if (win->lines[bot]->flags & __FORCEPAINT ||
|
||||
win->lines[bot]->hash != curscr->lines[bot]->hash
|
||||
|| memcmp(win->lines[bot]->line,
|
||||
curscr->lines[bot]->line,
|
||||
win->maxx * __LDATASIZE) != 0)
|
||||
break;
|
||||
else
|
||||
win->lines[bot]->flags &= ~__ISDIRTY;
|
||||
|
||||
#ifdef NO_JERKINESS
|
||||
/*
|
||||
* If we have a bottom unchanged region return. Scrolling the
|
||||
* bottom region up and then back down causes a screen jitter.
|
||||
* This will increase the number of characters sent to the screen
|
||||
* but it looks better.
|
||||
*/
|
||||
if (bot < win->maxy - 1)
|
||||
return;
|
||||
#endif /* NO_JERKINESS */
|
||||
|
||||
/*
|
||||
* Search for the largest block of text not changed.
|
||||
* Invariants of the loop:
|
||||
* - Startw is the index of the beginning of the examined block in win.
|
||||
* - Starts is the index of the beginning of the examined block in
|
||||
* curscr.
|
||||
* - Curs is the index of one past the end of the exmined block in win.
|
||||
* - Curw is the index of one past the end of the exmined block in
|
||||
* curscr.
|
||||
* - bsize is the current size of the examined block.
|
||||
*/
|
||||
for (bsize = bot - top; bsize >= THRESH; bsize--) {
|
||||
for (startw = top; startw <= bot - bsize; startw++)
|
||||
for (starts = top; starts <= bot - bsize;
|
||||
starts++) {
|
||||
for (curw = startw, curs = starts;
|
||||
curs < starts + bsize; curw++, curs++)
|
||||
if (win->lines[curw]->flags &
|
||||
__FORCEPAINT ||
|
||||
(win->lines[curw]->hash !=
|
||||
curscr->lines[curs]->hash ||
|
||||
memcmp(win->lines[curw]->line,
|
||||
curscr->lines[curs]->line,
|
||||
win->maxx * __LDATASIZE) != 0))
|
||||
break;
|
||||
if (curs == starts + bsize)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
done:
|
||||
/* Did not find anything */
|
||||
if (bsize < THRESH)
|
||||
return;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("quickch:bsize=%d,starts=%d,startw=%d,curw=%d,curs=%d,top=%d,bot=%d\n",
|
||||
bsize, starts, startw, curw, curs, top, bot);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Make sure that there is no overlap between the bottom and top
|
||||
* regions and the middle scrolled block.
|
||||
*/
|
||||
if (bot < curs)
|
||||
bot = curs - 1;
|
||||
if (top > starts)
|
||||
top = starts;
|
||||
|
||||
n = startw - starts;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("#####################################\n");
|
||||
for (i = 0; i < curscr->maxy; i++) {
|
||||
__CTRACE("C: %d:", i);
|
||||
__CTRACE(" 0x%x \n", curscr->lines[i]->hash);
|
||||
for (j = 0; j < curscr->maxx; j++)
|
||||
__CTRACE("%c",
|
||||
curscr->lines[i]->line[j].ch);
|
||||
__CTRACE("\n");
|
||||
for (j = 0; j < curscr->maxx; j++)
|
||||
__CTRACE("%x",
|
||||
curscr->lines[i]->line[j].attr);
|
||||
__CTRACE("\n");
|
||||
__CTRACE("W: %d:", i);
|
||||
__CTRACE(" 0x%x \n", win->lines[i]->hash);
|
||||
__CTRACE(" 0x%x ", win->lines[i]->flags);
|
||||
for (j = 0; j < win->maxx; j++)
|
||||
__CTRACE("%c",
|
||||
win->lines[i]->line[j].ch);
|
||||
__CTRACE("\n");
|
||||
for (j = 0; j < win->maxx; j++)
|
||||
__CTRACE("%x",
|
||||
win->lines[i]->line[j].attr);
|
||||
__CTRACE("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* So we don't have to call __hash() each time */
|
||||
for (i = 0; i < win->maxx; i++) {
|
||||
buf[i].ch = ' ';
|
||||
buf[i].attr = 0;
|
||||
}
|
||||
blank_hash = __hash((char *) buf, win->maxx * __LDATASIZE);
|
||||
|
||||
/*
|
||||
* Perform the rotation to maintain the consistency of curscr.
|
||||
* This is hairy since we are doing an *in place* rotation.
|
||||
* Invariants of the loop:
|
||||
* - I is the index of the current line.
|
||||
* - Target is the index of the target of line i.
|
||||
* - Tmp1 points to current line (i).
|
||||
* - Tmp2 and points to target line (target);
|
||||
* - Cur_period is the index of the end of the current period.
|
||||
* (see below).
|
||||
*
|
||||
* There are 2 major issues here that make this rotation non-trivial:
|
||||
* 1. Scrolling in a scrolling region bounded by the top
|
||||
* and bottom regions determined (whose size is sc_region).
|
||||
* 2. As a result of the use of the mod function, there may be a
|
||||
* period introduced, i.e., 2 maps to 4, 4 to 6, n-2 to 0, and
|
||||
* 0 to 2, which then causes all odd lines not to be rotated.
|
||||
* To remedy this, an index of the end ( = beginning) of the
|
||||
* current 'period' is kept, cur_period, and when it is reached,
|
||||
* the next period is started from cur_period + 1 which is
|
||||
* guaranteed not to have been reached since that would mean that
|
||||
* all records would have been reached. (think about it...).
|
||||
*
|
||||
* Lines in the rotation can have 3 attributes which are marked on the
|
||||
* line so that curscr is consistent with the visual screen.
|
||||
* 1. Not dirty -- lines inside the scrolled block, top region or
|
||||
* bottom region.
|
||||
* 2. Blank lines -- lines in the differential of the scrolling
|
||||
* region adjacent to top and bot regions
|
||||
* depending on scrolling direction.
|
||||
* 3. Dirty line -- all other lines are marked dirty.
|
||||
*/
|
||||
sc_region = bot - top + 1;
|
||||
i = top;
|
||||
tmp1 = curscr->lines[top];
|
||||
cur_period = top;
|
||||
for (j = top; j <= bot; j++) {
|
||||
target = (i - top + n + sc_region) % sc_region + top;
|
||||
tmp2 = curscr->lines[target];
|
||||
curscr->lines[target] = tmp1;
|
||||
/* Mark block as clean and blank out scrolled lines. */
|
||||
clp = curscr->lines[target];
|
||||
#ifdef DEBUG
|
||||
__CTRACE("quickch: n=%d startw=%d curw=%d i = %d target=%d ",
|
||||
n, startw, curw, i, target);
|
||||
#endif
|
||||
if ((target >= startw && target < curw) || target < top
|
||||
|| target > bot) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE("-- notdirty");
|
||||
#endif
|
||||
win->lines[target]->flags &= ~__ISDIRTY;
|
||||
} else if ((n > 0 && target >= top && target < top + n) ||
|
||||
(n < 0 && target <= bot && target > bot + n)) {
|
||||
if (clp->hash != blank_hash || memcmp(clp->line,
|
||||
buf, win->maxx * __LDATASIZE) !=0) {
|
||||
(void)memcpy(clp->line, buf,
|
||||
win->maxx * __LDATASIZE);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("-- blanked out: dirty");
|
||||
#endif
|
||||
clp->hash = blank_hash;
|
||||
__touchline(win, target, 0, win->maxx - 1, 0);
|
||||
} else {
|
||||
__touchline(win, target, 0, win->maxx - 1, 0);
|
||||
#ifdef DEBUG
|
||||
__CTRACE(" -- blank line already: dirty");
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(" -- dirty");
|
||||
#endif
|
||||
__touchline(win, target, 0, win->maxx - 1, 0);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("\n");
|
||||
#endif
|
||||
if (target == cur_period) {
|
||||
i = target + 1;
|
||||
tmp1 = curscr->lines[i];
|
||||
cur_period = i;
|
||||
} else {
|
||||
tmp1 = tmp2;
|
||||
i = target;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
|
||||
for (i = 0; i < curscr->maxy; i++) {
|
||||
__CTRACE("C: %d:", i);
|
||||
for (j = 0; j < curscr->maxx; j++)
|
||||
__CTRACE("%c",
|
||||
curscr->lines[i]->line[j].ch);
|
||||
__CTRACE("\n");
|
||||
__CTRACE("W: %d:", i);
|
||||
for (j = 0; j < win->maxx; j++)
|
||||
__CTRACE("%c", win->lines[i]->line[j].ch);
|
||||
__CTRACE("\n");
|
||||
}
|
||||
#endif
|
||||
if (n != 0) {
|
||||
WINDOW *wp;
|
||||
scrolln(win, starts, startw, curs, bot, top);
|
||||
/*
|
||||
* Need to repoint any subwindow lines to the rotated
|
||||
* line structured.
|
||||
*/
|
||||
for (wp = win->nextp; wp != win; wp = wp->nextp)
|
||||
__set_subwin(win, wp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* scrolln --
|
||||
* Scroll n lines, where n is starts - startw.
|
||||
*/
|
||||
static void
|
||||
scrolln(win, starts, startw, curs, bot, top)
|
||||
WINDOW *win;
|
||||
int starts, startw, curs, bot, top;
|
||||
{
|
||||
int i, oy, ox, n;
|
||||
|
||||
oy = curscr->cury;
|
||||
ox = curscr->curx;
|
||||
n = starts - startw;
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* The initial tests that set __noqch don't let us reach here unless
|
||||
* we have either CS + HO + SF/sf/SR/sr, or AL + DL. SF/sf and SR/sr
|
||||
* scrolling can only shift the entire scrolling region, not just a
|
||||
* part of it, which means that the quickch() routine is going to be
|
||||
* sadly disappointed in us if we don't have CS as well.
|
||||
*
|
||||
* If CS, HO and SF/sf are set, can use the scrolling region. Because
|
||||
* the cursor position after CS is undefined, we need HO which gives us
|
||||
* the ability to move to somewhere without knowledge of the current
|
||||
* location of the cursor. Still call __mvcur() anyway, to update its
|
||||
* idea of where the cursor is.
|
||||
*
|
||||
* When the scrolling region has been set, the cursor has to be at the
|
||||
* last line of the region to make the scroll happen.
|
||||
*
|
||||
* Doing SF/SR or AL/DL appears faster on the screen than either sf/sr
|
||||
* or al/dl, and, some terminals have AL/DL, sf/sr, and CS, but not
|
||||
* SF/SR. So, if we're scrolling almost all of the screen, try and use
|
||||
* AL/DL, otherwise use the scrolling region. The "almost all" is a
|
||||
* shameless hack for vi.
|
||||
*/
|
||||
if (n > 0) {
|
||||
if (CS != NULL && HO != NULL && (SF != NULL ||
|
||||
(AL == NULL || DL == NULL ||
|
||||
top > 3 || bot + 3 < win->maxy) && sf != NULL)) {
|
||||
tputs(__tscroll(CS, top, bot + 1), 0, __cputchar);
|
||||
__mvcur(oy, ox, 0, 0, 1);
|
||||
tputs(HO, 0, __cputchar);
|
||||
__mvcur(0, 0, bot, 0, 1);
|
||||
if (SF != NULL)
|
||||
tputs(__tscroll(SF, n, 0), 0, __cputchar);
|
||||
else
|
||||
for (i = 0; i < n; i++)
|
||||
tputs(sf, 0, __cputchar);
|
||||
tputs(__tscroll(CS, 0, win->maxy), 0, __cputchar);
|
||||
__mvcur(bot, 0, 0, 0, 1);
|
||||
tputs(HO, 0, __cputchar);
|
||||
__mvcur(0, 0, oy, ox, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Scroll up the block. */
|
||||
if (SF != NULL && top == 0) {
|
||||
__mvcur(oy, ox, bot, 0, 1);
|
||||
tputs(__tscroll(SF, n, 0), 0, __cputchar);
|
||||
} else if (DL != NULL) {
|
||||
__mvcur(oy, ox, top, 0, 1);
|
||||
tputs(__tscroll(DL, n, 0), 0, __cputchar);
|
||||
} else if (dl != NULL) {
|
||||
__mvcur(oy, ox, top, 0, 1);
|
||||
for (i = 0; i < n; i++)
|
||||
tputs(dl, 0, __cputchar);
|
||||
} else if (sf != NULL && top == 0) {
|
||||
__mvcur(oy, ox, bot, 0, 1);
|
||||
for (i = 0; i < n; i++)
|
||||
tputs(sf, 0, __cputchar);
|
||||
} else
|
||||
abort();
|
||||
|
||||
/* Push down the bottom region. */
|
||||
__mvcur(top, 0, bot - n + 1, 0, 1);
|
||||
if (AL != NULL)
|
||||
tputs(__tscroll(AL, n, 0), 0, __cputchar);
|
||||
else if (al != NULL)
|
||||
for (i = 0; i < n; i++)
|
||||
tputs(al, 0, __cputchar);
|
||||
else
|
||||
abort();
|
||||
__mvcur(bot - n + 1, 0, oy, ox, 1);
|
||||
} else {
|
||||
/*
|
||||
* !!!
|
||||
* n < 0
|
||||
*
|
||||
* If CS, HO and SR/sr are set, can use the scrolling region.
|
||||
* See the above comments for details.
|
||||
*/
|
||||
if (CS != NULL && HO != NULL && (SR != NULL ||
|
||||
(AL == NULL || DL == NULL ||
|
||||
top > 3 || bot + 3 < win->maxy) && sr != NULL)) {
|
||||
tputs(__tscroll(CS, top, bot + 1), 0, __cputchar);
|
||||
__mvcur(oy, ox, 0, 0, 1);
|
||||
tputs(HO, 0, __cputchar);
|
||||
__mvcur(0, 0, top, 0, 1);
|
||||
|
||||
if (SR != NULL)
|
||||
tputs(__tscroll(SR, -n, 0), 0, __cputchar);
|
||||
else
|
||||
for (i = n; i < 0; i++)
|
||||
tputs(sr, 0, __cputchar);
|
||||
tputs(__tscroll(CS, 0, win->maxy), 0, __cputchar);
|
||||
__mvcur(top, 0, 0, 0, 1);
|
||||
tputs(HO, 0, __cputchar);
|
||||
__mvcur(0, 0, oy, ox, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Preserve the bottom lines. */
|
||||
__mvcur(oy, ox, bot + n + 1, 0, 1);
|
||||
if (SR != NULL && bot == win->maxy)
|
||||
tputs(__tscroll(SR, -n, 0), 0, __cputchar);
|
||||
else if (DL != NULL)
|
||||
tputs(__tscroll(DL, -n, 0), 0, __cputchar);
|
||||
else if (dl != NULL)
|
||||
for (i = n; i < 0; i++)
|
||||
tputs(dl, 0, __cputchar);
|
||||
else if (sr != NULL && bot == win->maxy)
|
||||
for (i = n; i < 0; i++)
|
||||
tputs(sr, 0, __cputchar);
|
||||
else
|
||||
abort();
|
||||
|
||||
/* Scroll the block down. */
|
||||
__mvcur(bot + n + 1, 0, top, 0, 1);
|
||||
if (AL != NULL)
|
||||
tputs(__tscroll(AL, -n, 0), 0, __cputchar);
|
||||
else if (al != NULL)
|
||||
for (i = n; i < 0; i++)
|
||||
tputs(al, 0, __cputchar);
|
||||
else
|
||||
abort();
|
||||
__mvcur(top, 0, oy, ox, 1);
|
||||
}
|
||||
}
|
175
lib/libcurses/scanw.c
Normal file
175
lib/libcurses/scanw.c
Normal file
@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)scanw.c 8.3 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* scanw and friends.
|
||||
*/
|
||||
|
||||
#ifdef __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* scanw --
|
||||
* Implement a scanf on the standard screen.
|
||||
*/
|
||||
int
|
||||
#ifdef __STDC__
|
||||
scanw(const char *fmt, ...)
|
||||
#else
|
||||
scanw(fmt, va_alist)
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
ret = vwscanw(stdscr, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* wscanw --
|
||||
* Implements a scanf on the given window.
|
||||
*/
|
||||
int
|
||||
#ifdef __STDC__
|
||||
wscanw(WINDOW *win, const char *fmt, ...)
|
||||
#else
|
||||
wscanw(win, fmt, va_alist)
|
||||
WINDOW *win;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
ret = vwscanw(win, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvscanw, mvwscanw --
|
||||
* Implement the mvscanw commands. Due to the variable number of
|
||||
* arguments, they cannot be macros. Another sigh....
|
||||
*/
|
||||
int
|
||||
#ifdef __STDC__
|
||||
mvscanw(register int y, register int x, const char *fmt,...)
|
||||
#else
|
||||
mvscanw(y, x, fmt, va_alist)
|
||||
register int y, x;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
if (move(y, x) != OK)
|
||||
return (ERR);
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
ret = vwscanw(stdscr, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int
|
||||
#ifdef __STDC__
|
||||
mvwscanw(register WINDOW * win, register int y, register int x,
|
||||
const char *fmt, ...)
|
||||
#else
|
||||
mvwscanw(win, y, x, fmt, va_alist)
|
||||
register WINDOW *win;
|
||||
register int y, x;
|
||||
char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
if (move(y, x) != OK)
|
||||
return (ERR);
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
ret = vwscanw(win, fmt, ap);
|
||||
va_end(ap);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* vwscanw --
|
||||
* This routine actually executes the scanf from the window.
|
||||
*/
|
||||
int
|
||||
vwscanw(win, fmt, ap)
|
||||
WINDOW *win;
|
||||
const char *fmt;
|
||||
va_list ap;
|
||||
{
|
||||
|
||||
char buf[1024];
|
||||
|
||||
return (wgetstr(win, buf) == OK ?
|
||||
vsscanf(buf, fmt, ap) : ERR);
|
||||
}
|
71
lib/libcurses/scroll.c
Normal file
71
lib/libcurses/scroll.c
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)scroll.c 8.3 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* scroll --
|
||||
* Scroll the window up a line.
|
||||
*/
|
||||
int
|
||||
scroll(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int oy, ox;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("scroll: (%0.2o)\n", win);
|
||||
#endif
|
||||
|
||||
if (!(win->flags & __SCROLLOK))
|
||||
return (ERR);
|
||||
|
||||
getyx(win, oy, ox);
|
||||
wmove(win, 0, 0);
|
||||
wdeleteln(win);
|
||||
wmove(win, oy, ox);
|
||||
|
||||
if (win == curscr) {
|
||||
putchar('\n');
|
||||
if (!NONL)
|
||||
win->curx = 0;
|
||||
#ifdef DEBUG
|
||||
__CTRACE("scroll: win == curscr\n");
|
||||
#endif
|
||||
}
|
||||
return (OK);
|
||||
}
|
233
lib/libcurses/setterm.c
Normal file
233
lib/libcurses/setterm.c
Normal file
@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)setterm.c 8.8 (Berkeley) 10/25/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/ioctl.h> /* TIOCGWINSZ on old systems. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
static void zap __P((void));
|
||||
|
||||
static char *sflags[] = {
|
||||
/* am bs da eo hc in mi ms */
|
||||
&AM, &BS, &DA, &EO, &HC, &IN, &MI, &MS,
|
||||
/* nc ns os ul xb xn xt xs xx */
|
||||
&NC, &NS, &OS, &UL, &XB, &XN, &XT, &XS, &XX
|
||||
};
|
||||
|
||||
static char *_PC,
|
||||
**sstrs[] = {
|
||||
/* AL bc bt cd ce cl cm cr cs */
|
||||
&AL, &BC, &BT, &CD, &CE, &CL, &CM, &CR, &CS,
|
||||
/* dc DL dm do ed ei k0 k1 k2 */
|
||||
&DC, &DL, &DM, &DO, &ED, &EI, &K0, &K1, &K2,
|
||||
/* k3 k4 k5 k6 k7 k8 k9 ho ic */
|
||||
&K3, &K4, &K5, &K6, &K7, &K8, &K9, &HO, &IC,
|
||||
/* im ip kd ke kh kl kr ks ku */
|
||||
&IM, &IP, &KD, &KE, &KH, &KL, &KR, &KS, &KU,
|
||||
/* ll ma nd nl pc rc sc se SF */
|
||||
&LL, &MA, &ND, &NL, &_PC, &RC, &SC, &SE, &SF,
|
||||
/* so SR ta te ti uc ue up us */
|
||||
&SO, &SR, &TA, &TE, &TI, &UC, &UE, &UP, &US,
|
||||
/* vb vs ve al dl sf sr AL */
|
||||
&VB, &VS, &VE, &al, &dl, &sf, &sr, &AL_PARM,
|
||||
/* DL UP DO LE */
|
||||
&DL_PARM, &UP_PARM, &DOWN_PARM, &LEFT_PARM,
|
||||
/* RI */
|
||||
&RIGHT_PARM,
|
||||
};
|
||||
|
||||
static char *aoftspace; /* Address of _tspace for relocation */
|
||||
static char tspace[2048]; /* Space for capability strings */
|
||||
|
||||
char *ttytype;
|
||||
|
||||
int
|
||||
setterm(type)
|
||||
register char *type;
|
||||
{
|
||||
static char genbuf[1024];
|
||||
static char __ttytype[1024];
|
||||
register int unknown;
|
||||
struct winsize win;
|
||||
char *p;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("setterm: (\"%s\")\nLINES = %d, COLS = %d\n",
|
||||
type, LINES, COLS);
|
||||
#endif
|
||||
if (type[0] == '\0')
|
||||
type = "xx";
|
||||
unknown = 0;
|
||||
if (tgetent(genbuf, type) != 1) {
|
||||
unknown++;
|
||||
strcpy(genbuf, "xx|dumb:");
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("setterm: tty = %s\n", type);
|
||||
#endif
|
||||
|
||||
/* Try TIOCGWINSZ, and, if it fails, the termcap entry. */
|
||||
if (ioctl(STDERR_FILENO, TIOCGWINSZ, &win) != -1 &&
|
||||
win.ws_row != 0 && win.ws_col != 0) {
|
||||
LINES = win.ws_row;
|
||||
COLS = win.ws_col;
|
||||
} else {
|
||||
LINES = tgetnum("li");
|
||||
COLS = tgetnum("co");
|
||||
}
|
||||
|
||||
/* POSIX 1003.2 requires that the environment override. */
|
||||
if ((p = getenv("LINES")) != NULL)
|
||||
LINES = strtol(p, NULL, 10);
|
||||
if ((p = getenv("COLUMNS")) != NULL)
|
||||
COLS = strtol(p, NULL, 10);
|
||||
|
||||
/*
|
||||
* Want cols > 4, otherwise things will fail.
|
||||
*/
|
||||
if (COLS <= 4)
|
||||
return (ERR);
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("setterm: LINES = %d, COLS = %d\n", LINES, COLS);
|
||||
#endif
|
||||
aoftspace = tspace;
|
||||
zap(); /* Get terminal description. */
|
||||
|
||||
/* If we can't tab, we can't backtab, either. */
|
||||
if (!GT)
|
||||
BT = NULL;
|
||||
|
||||
/*
|
||||
* Test for cursor motion capbility.
|
||||
*
|
||||
* XXX
|
||||
* This is truly stupid -- historically, tgoto returns "OOPS" if it
|
||||
* can't do cursor motions. Some systems have been fixed to return
|
||||
* a NULL pointer.
|
||||
*/
|
||||
if ((p = tgoto(CM, 0, 0)) == NULL || *p == 'O') {
|
||||
CA = 0;
|
||||
CM = 0;
|
||||
} else
|
||||
CA = 1;
|
||||
|
||||
PC = _PC ? _PC[0] : 0;
|
||||
aoftspace = tspace;
|
||||
ttytype = longname(genbuf, __ttytype);
|
||||
|
||||
/* If no scrolling commands, no quick change. */
|
||||
__noqch =
|
||||
(CS == NULL || HO == NULL ||
|
||||
SF == NULL && sf == NULL || SR == NULL && sr == NULL) &&
|
||||
(AL == NULL && al == NULL || DL == NULL && dl == NULL);
|
||||
|
||||
return (unknown ? ERR : OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* zap --
|
||||
* Gets all the terminal flags from the termcap database.
|
||||
*/
|
||||
static void
|
||||
zap()
|
||||
{
|
||||
register char *namp, ***sp;
|
||||
register char **fp;
|
||||
char tmp[3];
|
||||
#ifdef DEBUG
|
||||
register char *cp;
|
||||
#endif
|
||||
tmp[2] = '\0';
|
||||
|
||||
namp = "ambsdaeohcinmimsncnsosulxbxnxtxsxx";
|
||||
fp = sflags;
|
||||
do {
|
||||
*tmp = *namp;
|
||||
*(tmp + 1) = *(namp + 1);
|
||||
*(*fp++) = tgetflag(tmp);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
|
||||
#endif
|
||||
namp += 2;
|
||||
|
||||
} while (*namp);
|
||||
namp = "ALbcbtcdceclcmcrcsdcDLdmdoedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmandnlpcrcscseSFsoSRtatetiucueupusvbvsvealdlsfsrALDLUPDOLERI";
|
||||
sp = sstrs;
|
||||
do {
|
||||
*tmp = *namp;
|
||||
*(tmp + 1) = *(namp + 1);
|
||||
*(*sp++) = tgetstr(tmp, &aoftspace);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
|
||||
if (*sp[-1] != NULL) {
|
||||
for (cp = *sp[-1]; *cp; cp++)
|
||||
__CTRACE("%s", unctrl(*cp));
|
||||
__CTRACE("\"\n");
|
||||
}
|
||||
#endif
|
||||
namp += 2;
|
||||
} while (*namp);
|
||||
if (XS)
|
||||
SO = SE = NULL;
|
||||
else {
|
||||
if (tgetnum("sg") > 0)
|
||||
SO = NULL;
|
||||
if (tgetnum("ug") > 0)
|
||||
US = NULL;
|
||||
if (!SO && US) {
|
||||
SO = US;
|
||||
SE = UE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* getcap --
|
||||
* Return a capability from termcap.
|
||||
*/
|
||||
char *
|
||||
getcap(name)
|
||||
char *name;
|
||||
{
|
||||
return (tgetstr(name, &aoftspace));
|
||||
}
|
67
lib/libcurses/standout.c
Normal file
67
lib/libcurses/standout.c
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)standout.c 8.3 (Berkeley) 8/10/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* wstandout
|
||||
* Enter standout mode.
|
||||
*/
|
||||
int
|
||||
wstandout(win)
|
||||
WINDOW *win;
|
||||
{
|
||||
/*
|
||||
* If standout/standend strings, or can underline, set the
|
||||
* screen standout bit.
|
||||
*/
|
||||
if (SO != NULL && SE != NULL || UC != NULL)
|
||||
win->flags |= __WSTANDOUT;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* wstandend --
|
||||
* Exit standout mode.
|
||||
*/
|
||||
int
|
||||
wstandend(win)
|
||||
WINDOW *win;
|
||||
{
|
||||
win->flags &= ~__WSTANDOUT;
|
||||
return (1);
|
||||
}
|
77
lib/libcurses/toucholap.c
Normal file
77
lib/libcurses/toucholap.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)toucholap.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* touchoverlap --
|
||||
* Touch, on win2, the part that overlaps with win1.
|
||||
*/
|
||||
int
|
||||
touchoverlap(win1, win2)
|
||||
register WINDOW *win1, *win2;
|
||||
{
|
||||
register int y, endy, endx, starty, startx;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("touchoverlap: (%0.2o, %0.2o);\n", win1, win2);
|
||||
#endif
|
||||
starty = max(win1->begy, win2->begy);
|
||||
startx = max(win1->begx, win2->begx);
|
||||
endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
|
||||
endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
|
||||
#ifdef DEBUG
|
||||
__CTRACE("touchoverlap: from (%d,%d) to (%d,%d)\n",
|
||||
starty, startx, endy, endx);
|
||||
__CTRACE("touchoverlap: win1 (%d,%d) to (%d,%d)\n",
|
||||
win1->begy, win1->begx, win1->begy + win1->maxy,
|
||||
win1->begx + win1->maxx);
|
||||
__CTRACE("touchoverlap: win2 (%d,%d) to (%d,%d)\n",
|
||||
win2->begy, win2->begx, win2->begy + win2->maxy,
|
||||
win2->begx + win2->maxx);
|
||||
#endif
|
||||
if (starty >= endy || startx >= endx)
|
||||
return (OK);
|
||||
starty -= win2->begy;
|
||||
startx -= win2->begx;
|
||||
endy -= win2->begy;
|
||||
endx -= win2->begx;
|
||||
for (--endx, y = starty; y < endy; y++)
|
||||
__touchline(win2, y, startx, endx, 0);
|
||||
return (OK);
|
||||
}
|
||||
|
120
lib/libcurses/touchwin.c
Normal file
120
lib/libcurses/touchwin.c
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)touchwin.c 8.2 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* touchline --
|
||||
* Touch a given line.
|
||||
*/
|
||||
int
|
||||
touchline(win, y, sx, ex)
|
||||
WINDOW *win;
|
||||
register int y, sx, ex;
|
||||
{
|
||||
return (__touchline(win, y, sx, ex, 1));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* touchwin --
|
||||
* Make it look like the whole window has been changed.
|
||||
*/
|
||||
int
|
||||
touchwin(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int y, maxy;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("touchwin: (%0.2o)\n", win);
|
||||
#endif
|
||||
maxy = win->maxy;
|
||||
for (y = 0; y < maxy; y++)
|
||||
__touchline(win, y, 0, win->maxx - 1, 1);
|
||||
return (OK);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
__touchwin(win)
|
||||
register WINDOW *win;
|
||||
{
|
||||
register int y, maxy;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE("touchwin: (%0.2o)\n", win);
|
||||
#endif
|
||||
maxy = win->maxy;
|
||||
for (y = 0; y < maxy; y++)
|
||||
__touchline(win, y, 0, win->maxx - 1, 0);
|
||||
return (OK);
|
||||
}
|
||||
|
||||
int
|
||||
__touchline(win, y, sx, ex, force)
|
||||
register WINDOW *win;
|
||||
register int y, sx, ex;
|
||||
int force;
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE("touchline: (%0.2o, %d, %d, %d, %d)\n", win, y, sx, ex, force);
|
||||
__CTRACE("touchline: first = %d, last = %d\n",
|
||||
*win->lines[y]->firstchp, *win->lines[y]->lastchp);
|
||||
#endif
|
||||
if (force)
|
||||
win->lines[y]->flags |= __FORCEPAINT;
|
||||
sx += win->ch_off;
|
||||
ex += win->ch_off;
|
||||
if (!(win->lines[y]->flags & __ISDIRTY)) {
|
||||
win->lines[y]->flags |= __ISDIRTY;
|
||||
*win->lines[y]->firstchp = sx;
|
||||
*win->lines[y]->lastchp = ex;
|
||||
} else {
|
||||
if (*win->lines[y]->firstchp > sx)
|
||||
*win->lines[y]->firstchp = sx;
|
||||
if (*win->lines[y]->lastchp < ex)
|
||||
*win->lines[y]->lastchp = ex;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE("touchline: first = %d, last = %d\n",
|
||||
*win->lines[y]->firstchp, *win->lines[y]->lastchp);
|
||||
#endif
|
||||
return (OK);
|
||||
}
|
||||
|
||||
|
139
lib/libcurses/tscroll.c
Normal file
139
lib/libcurses/tscroll.c
Normal file
@ -0,0 +1,139 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)tscroll.c 8.4 (Berkeley) 7/27/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
#define MAXRETURNSIZE 64
|
||||
|
||||
/*
|
||||
* Routine to perform scrolling. Derived from tgoto.c in tercamp(3)
|
||||
* library. Cap is a string containing printf type escapes to allow
|
||||
* scrolling. The following escapes are defined for substituting n:
|
||||
*
|
||||
* %d as in printf
|
||||
* %2 like %2d
|
||||
* %3 like %3d
|
||||
* %. gives %c hacking special case characters
|
||||
* %+x like %c but adding x first
|
||||
*
|
||||
* The codes below affect the state but don't use up a value.
|
||||
*
|
||||
* %>xy if value > x add y
|
||||
* %i increments n
|
||||
* %% gives %
|
||||
* %B BCD (2 decimal digits encoded in one byte)
|
||||
* %D Delta Data (backwards bcd)
|
||||
*
|
||||
* all other characters are ``self-inserting''.
|
||||
*/
|
||||
char *
|
||||
__tscroll(cap, n1, n2)
|
||||
const char *cap;
|
||||
int n1, n2;
|
||||
{
|
||||
static char result[MAXRETURNSIZE];
|
||||
int c, n;
|
||||
char *dp;
|
||||
|
||||
if (cap == NULL)
|
||||
goto err;
|
||||
for (n = n1, dp = result; (c = *cap++) != '\0';) {
|
||||
if (c != '%') {
|
||||
*dp++ = c;
|
||||
continue;
|
||||
}
|
||||
switch (c = *cap++) {
|
||||
case 'n':
|
||||
n ^= 0140;
|
||||
continue;
|
||||
case 'd':
|
||||
if (n < 10)
|
||||
goto one;
|
||||
if (n < 100)
|
||||
goto two;
|
||||
/* FALLTHROUGH */
|
||||
case '3':
|
||||
*dp++ = (n / 100) | '0';
|
||||
n %= 100;
|
||||
/* FALLTHROUGH */
|
||||
case '2':
|
||||
two: *dp++ = n / 10 | '0';
|
||||
one: *dp++ = n % 10 | '0';
|
||||
n = n2;
|
||||
continue;
|
||||
case '>':
|
||||
if (n > *cap++)
|
||||
n += *cap++;
|
||||
else
|
||||
cap++;
|
||||
continue;
|
||||
case '+':
|
||||
n += *cap++;
|
||||
/* FALLTHROUGH */
|
||||
case '.':
|
||||
*dp++ = n;
|
||||
continue;
|
||||
case 'i':
|
||||
n++;
|
||||
continue;
|
||||
case '%':
|
||||
*dp++ = c;
|
||||
continue;
|
||||
case 'B':
|
||||
n = (n / 10 << 4) + n % 10;
|
||||
continue;
|
||||
case 'D':
|
||||
n = n - 2 * (n % 16);
|
||||
continue;
|
||||
/*
|
||||
* XXX
|
||||
* System V terminfo files have lots of extra gunk.
|
||||
* The only one we've seen in scrolling strings is
|
||||
* %pN, and it seems to work okay if we ignore it.
|
||||
*/
|
||||
case 'p':
|
||||
++cap;
|
||||
continue;
|
||||
default:
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
*dp = '\0';
|
||||
return (result);
|
||||
|
||||
err: return("curses: __tscroll failed");
|
||||
}
|
124
lib/libcurses/tstp.c
Normal file
124
lib/libcurses/tstp.c
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)tstp.c 8.3 (Berkeley) 5/4/94";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* stop_signal_handler --
|
||||
* Handle stop signals.
|
||||
*/
|
||||
void
|
||||
__stop_signal_handler(signo)
|
||||
int signo;
|
||||
{
|
||||
struct termios save;
|
||||
sigset_t oset, set;
|
||||
|
||||
/* Get the current terminal state (which the user may have changed). */
|
||||
if (tcgetattr(STDIN_FILENO, &save))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Block window change and timer signals. The latter is because
|
||||
* applications use timers to decide when to repaint the screen.
|
||||
*/
|
||||
(void)sigemptyset(&set);
|
||||
(void)sigaddset(&set, SIGALRM);
|
||||
(void)sigaddset(&set, SIGWINCH);
|
||||
(void)sigprocmask(SIG_BLOCK, &set, &oset);
|
||||
|
||||
/*
|
||||
* End the window, which also resets the terminal state to the
|
||||
* original modes.
|
||||
*/
|
||||
endwin();
|
||||
|
||||
/* Unblock SIGTSTP. */
|
||||
(void)sigemptyset(&set);
|
||||
(void)sigaddset(&set, SIGTSTP);
|
||||
(void)sigprocmask(SIG_UNBLOCK, &set, NULL);
|
||||
|
||||
/* Stop ourselves. */
|
||||
__restore_stophandler();
|
||||
(void)kill(0, SIGTSTP);
|
||||
|
||||
/* Time passes ... */
|
||||
|
||||
/* Reset the curses SIGTSTP signal handler. */
|
||||
__set_stophandler();
|
||||
|
||||
/* save the new "default" terminal state */
|
||||
(void)tcgetattr(STDIN_FILENO, &__orig_termios);
|
||||
|
||||
/* Reset the terminal state to the mode just before we stopped. */
|
||||
(void)tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, &save);
|
||||
|
||||
/* Restart the screen. */
|
||||
__startwin();
|
||||
|
||||
/* Repaint the screen. */
|
||||
wrefresh(curscr);
|
||||
|
||||
/* Reset the signals. */
|
||||
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
}
|
||||
|
||||
static void (*otstpfn)() = SIG_DFL;
|
||||
|
||||
/*
|
||||
* Set the TSTP handler.
|
||||
*/
|
||||
void
|
||||
__set_stophandler()
|
||||
{
|
||||
otstpfn = signal(SIGTSTP, __stop_signal_handler);
|
||||
}
|
||||
|
||||
/*
|
||||
* Restore the TSTP handler.
|
||||
*/
|
||||
void
|
||||
__restore_stophandler()
|
||||
{
|
||||
(void)signal(SIGTSTP, otstpfn);
|
||||
}
|
281
lib/libcurses/tty.c
Normal file
281
lib/libcurses/tty.c
Normal file
@ -0,0 +1,281 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* 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 sccsid[] = "@(#)tty.c 8.6 (Berkeley) 1/10/95";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* In general, curses should leave tty hardware settings alone (speed, parity,
|
||||
* word size). This is most easily done in BSD by using TCSASOFT on all
|
||||
* tcsetattr calls. On other systems, it would be better to get and restore
|
||||
* those attributes at each change, or at least when stopped and restarted.
|
||||
* See also the comments in getterm().
|
||||
*/
|
||||
#ifdef TCSASOFT
|
||||
int __tcaction = 1; /* Ignore hardware settings. */
|
||||
#else
|
||||
int __tcaction = 0;
|
||||
#endif
|
||||
|
||||
struct termios __orig_termios, __baset;
|
||||
static struct termios cbreakt, rawt, *curt;
|
||||
static int useraw;
|
||||
|
||||
#ifndef OXTABS
|
||||
#ifdef XTABS /* SMI uses XTABS. */
|
||||
#define OXTABS XTABS
|
||||
#else
|
||||
#define OXTABS 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* gettmode --
|
||||
* Do terminal type initialization.
|
||||
*/
|
||||
int
|
||||
gettmode()
|
||||
{
|
||||
useraw = 0;
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &__orig_termios))
|
||||
return (ERR);
|
||||
|
||||
__baset = __orig_termios;
|
||||
__baset.c_oflag &= ~OXTABS;
|
||||
|
||||
GT = 0; /* historical. was used before we wired OXTABS off */
|
||||
NONL = (__baset.c_oflag & ONLCR) == 0;
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* System V and SMI systems overload VMIN and VTIME, such that
|
||||
* VMIN is the same as the VEOF element, and VTIME is the same
|
||||
* as the VEOL element. This means that, if VEOF was ^D, the
|
||||
* default VMIN is 4. Majorly stupid.
|
||||
*/
|
||||
cbreakt = __baset;
|
||||
cbreakt.c_lflag &= ~ICANON;
|
||||
cbreakt.c_cc[VMIN] = 1;
|
||||
cbreakt.c_cc[VTIME] = 0;
|
||||
|
||||
rawt = cbreakt;
|
||||
rawt.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INLCR|IGNCR|ICRNL|IXON);
|
||||
rawt.c_oflag &= ~OPOST;
|
||||
rawt.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
||||
|
||||
/*
|
||||
* In general, curses should leave hardware-related settings alone.
|
||||
* This includes parity and word size. Older versions set the tty
|
||||
* to 8 bits, no parity in raw(), but this is considered to be an
|
||||
* artifact of the old tty interface. If it's desired to change
|
||||
* parity and word size, the TCSASOFT bit has to be removed from the
|
||||
* calls that switch to/from "raw" mode.
|
||||
*/
|
||||
if (!__tcaction) {
|
||||
rawt.c_iflag &= ~ISTRIP;
|
||||
rawt.c_cflag &= ~(CSIZE|PARENB);
|
||||
rawt.c_cflag |= CS8;
|
||||
}
|
||||
|
||||
curt = &__baset;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
raw()
|
||||
{
|
||||
useraw = __pfast = __rawmode = 1;
|
||||
curt = &rawt;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
noraw()
|
||||
{
|
||||
useraw = __pfast = __rawmode = 0;
|
||||
curt = &__baset;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
cbreak()
|
||||
{
|
||||
|
||||
__rawmode = 1;
|
||||
curt = useraw ? &rawt : &cbreakt;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
nocbreak()
|
||||
{
|
||||
|
||||
__rawmode = 0;
|
||||
curt = useraw ? &rawt : &__baset;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
echo()
|
||||
{
|
||||
rawt.c_lflag |= ECHO;
|
||||
cbreakt.c_lflag |= ECHO;
|
||||
__baset.c_lflag |= ECHO;
|
||||
|
||||
__echoit = 1;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
noecho()
|
||||
{
|
||||
rawt.c_lflag &= ~ECHO;
|
||||
cbreakt.c_lflag &= ~ECHO;
|
||||
__baset.c_lflag &= ~ECHO;
|
||||
|
||||
__echoit = 0;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
nl()
|
||||
{
|
||||
rawt.c_iflag |= ICRNL;
|
||||
rawt.c_oflag |= ONLCR;
|
||||
cbreakt.c_iflag |= ICRNL;
|
||||
cbreakt.c_oflag |= ONLCR;
|
||||
__baset.c_iflag |= ICRNL;
|
||||
__baset.c_oflag |= ONLCR;
|
||||
|
||||
__pfast = __rawmode;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
nonl()
|
||||
{
|
||||
rawt.c_iflag &= ~ICRNL;
|
||||
rawt.c_oflag &= ~ONLCR;
|
||||
cbreakt.c_iflag &= ~ICRNL;
|
||||
cbreakt.c_oflag &= ~ONLCR;
|
||||
__baset.c_iflag &= ~ICRNL;
|
||||
__baset.c_oflag &= ~ONLCR;
|
||||
|
||||
__pfast = 1;
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, curt) ? ERR : OK);
|
||||
}
|
||||
|
||||
void
|
||||
__startwin()
|
||||
{
|
||||
static char *stdbuf;
|
||||
static size_t len;
|
||||
|
||||
(void)fflush(stdout);
|
||||
|
||||
/*
|
||||
* Some C libraries default to a 1K buffer when talking to a tty.
|
||||
* With a larger screen, especially across a network, we'd like
|
||||
* to get it to all flush in a single write. Make it twice as big
|
||||
* as just the characters (so that we have room for cursor motions
|
||||
* and standout information) but no more than 8K.
|
||||
*/
|
||||
if (stdbuf == NULL) {
|
||||
if ((len = LINES * COLS * 2) > 8192)
|
||||
len = 8192;
|
||||
if ((stdbuf = malloc(len)) == NULL)
|
||||
len = 0;
|
||||
}
|
||||
(void)setvbuf(stdout, stdbuf, _IOFBF, len);
|
||||
|
||||
tputs(TI, 0, __cputchar);
|
||||
tputs(VS, 0, __cputchar);
|
||||
}
|
||||
|
||||
int
|
||||
endwin()
|
||||
{
|
||||
__restore_stophandler();
|
||||
|
||||
if (curscr != NULL) {
|
||||
if (curscr->flags & __WSTANDOUT) {
|
||||
tputs(SE, 0, __cputchar);
|
||||
curscr->flags &= ~__WSTANDOUT;
|
||||
}
|
||||
__mvcur(curscr->cury, curscr->curx, curscr->maxy - 1, 0, 0);
|
||||
}
|
||||
|
||||
(void)tputs(VE, 0, __cputchar);
|
||||
(void)tputs(TE, 0, __cputchar);
|
||||
(void)fflush(stdout);
|
||||
(void)setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, &__orig_termios) ? ERR : OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* The following routines, savetty and resetty are completely useless and
|
||||
* are left in only as stubs. If people actually use them they will almost
|
||||
* certainly screw up the state of the world.
|
||||
*/
|
||||
static struct termios savedtty;
|
||||
int
|
||||
savetty()
|
||||
{
|
||||
return (tcgetattr(STDIN_FILENO, &savedtty) ? ERR : OK);
|
||||
}
|
||||
|
||||
int
|
||||
resetty()
|
||||
{
|
||||
return (tcsetattr(STDIN_FILENO, __tcaction ?
|
||||
TCSASOFT | TCSADRAIN : TCSADRAIN, &savedtty) ? ERR : OK);
|
||||
}
|
172
lib/libedit/histedit.h
Normal file
172
lib/libedit/histedit.h
Normal file
@ -0,0 +1,172 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Christos Zoulas of Cornell University.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)histedit.h 8.2 (Berkeley) 1/3/94
|
||||
*/
|
||||
|
||||
/*
|
||||
* histedit.h: Line editor and history interface.
|
||||
*/
|
||||
#ifndef _h_editline
|
||||
#define _h_editline
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* ==== Editing ====
|
||||
*/
|
||||
typedef struct editline EditLine;
|
||||
|
||||
/*
|
||||
* For user-defined function interface
|
||||
*/
|
||||
typedef struct lineinfo {
|
||||
__const char *buffer;
|
||||
__const char *cursor;
|
||||
__const char *lastchar;
|
||||
} LineInfo;
|
||||
|
||||
|
||||
/*
|
||||
* EditLine editor function return codes.
|
||||
* For user-defined function interface
|
||||
*/
|
||||
#define CC_NORM 0
|
||||
#define CC_NEWLINE 1
|
||||
#define CC_EOF 2
|
||||
#define CC_ARGHACK 3
|
||||
#define CC_REFRESH 4
|
||||
#define CC_CURSOR 5
|
||||
#define CC_ERROR 6
|
||||
#define CC_FATAL 7
|
||||
|
||||
/*
|
||||
* Initialization, cleanup, and resetting
|
||||
*/
|
||||
EditLine *el_init __P((const char *, FILE *, FILE *));
|
||||
void el_reset __P((EditLine *));
|
||||
void el_end __P((EditLine *));
|
||||
|
||||
|
||||
/*
|
||||
* Get a line, a character or push a string back in the input queue
|
||||
*/
|
||||
__const char *el_gets __P((EditLine *, int *));
|
||||
int el_getc __P((EditLine *, char *));
|
||||
void el_push __P((EditLine *, const char *));
|
||||
|
||||
/*
|
||||
* High level function internals control
|
||||
* Parses argc, argv array and executes builtin editline commands
|
||||
*/
|
||||
int el_parse __P((EditLine *, int, char **));
|
||||
|
||||
/*
|
||||
* Low level editline access function
|
||||
*/
|
||||
int el_set __P((EditLine *, int, ...));
|
||||
|
||||
/*
|
||||
* el_set/el_get parameters
|
||||
*/
|
||||
#define EL_PROMPT 0 /* , el_pfunc_t); */
|
||||
#define EL_TERMINAL 1 /* , const char *); */
|
||||
#define EL_EDITOR 2 /* , const char *); */
|
||||
#define EL_SIGNAL 3 /* , int); */
|
||||
#define EL_BIND 4 /* , const char *, ..., NULL); */
|
||||
#define EL_TELLTC 5 /* , const char *, ..., NULL); */
|
||||
#define EL_SETTC 6 /* , const char *, ..., NULL); */
|
||||
#define EL_ECHOTC 7 /* , const char *, ..., NULL); */
|
||||
#define EL_SETTY 8 /* , const char *, ..., NULL); */
|
||||
#define EL_ADDFN 9 /* , const char *, const char * */
|
||||
/* , el_func_t); */
|
||||
#define EL_HIST 10 /* , hist_fun_t, const char *); */
|
||||
|
||||
/*
|
||||
* Source named file or $PWD/.editrc or $HOME/.editrc
|
||||
*/
|
||||
int el_source __P((EditLine *, const char *));
|
||||
|
||||
/*
|
||||
* Must be called when the terminal changes size; If EL_SIGNAL
|
||||
* is set this is done automatically otherwise it is the responsibility
|
||||
* of the application
|
||||
*/
|
||||
void el_resize __P((EditLine *));
|
||||
|
||||
|
||||
/*
|
||||
* User-defined function interface.
|
||||
*/
|
||||
__const LineInfo *el_line __P((EditLine *));
|
||||
int el_insertstr __P((EditLine *, char *));
|
||||
void el_deletestr __P((EditLine *, int));
|
||||
|
||||
/*
|
||||
* ==== History ====
|
||||
*/
|
||||
|
||||
typedef struct history History;
|
||||
|
||||
typedef struct HistEvent {
|
||||
int num;
|
||||
__const char *str;
|
||||
} HistEvent;
|
||||
|
||||
/*
|
||||
* History access functions.
|
||||
*/
|
||||
History * history_init __P((void));
|
||||
void history_end __P((History *));
|
||||
|
||||
__const HistEvent * history __P((History *, int, ...));
|
||||
|
||||
#define H_FUNC 0 /* , UTSL */
|
||||
#define H_EVENT 1 /* , const int); */
|
||||
#define H_FIRST 2 /* , void); */
|
||||
#define H_LAST 3 /* , void); */
|
||||
#define H_PREV 4 /* , void); */
|
||||
#define H_NEXT 5 /* , void); */
|
||||
#define H_CURR 6 /* , void); */
|
||||
#define H_ADD 7 /* , const char*); */
|
||||
#define H_ENTER 8 /* , const char*); */
|
||||
#define H_END 9 /* , void); */
|
||||
#define H_NEXT_STR 10 /* , const char*); */
|
||||
#define H_PREV_STR 11 /* , const char*); */
|
||||
#define H_NEXT_EVENT 12 /* , const int); */
|
||||
#define H_PREV_EVENT 13 /* , const int); */
|
||||
|
||||
#endif /* _h_editline */
|
1451
lib/libedit/term.c
Normal file
1451
lib/libedit/term.c
Normal file
File diff suppressed because it is too large
Load Diff
52
lib/libedit/termcap.h
Normal file
52
lib/libedit/termcap.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Christos Zoulas of Cornell University.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @(#)termcap.h 8.1 (Berkeley) 6/4/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* termcap.h: I cannot find those in any include files...
|
||||
*/
|
||||
#ifndef _h_termcap
|
||||
#define _h_termcap
|
||||
|
||||
int tgetent __P((char *, char *));
|
||||
char *tgetstr __P((char *, char **));
|
||||
int tgetflag __P((char *));
|
||||
int tgetnum __P((char *));
|
||||
char *tgoto __P((char *, int, int));
|
||||
char *tputs __P((char *, int, void (*)(int)));
|
||||
|
||||
#endif /* _h_termcap */
|
14
lib/libkvm/Makefile
Normal file
14
lib/libkvm/Makefile
Normal file
@ -0,0 +1,14 @@
|
||||
# @(#)Makefile 8.3 (Berkeley) 5/4/95
|
||||
|
||||
LIB= kvm
|
||||
CFLAGS+=-DLIBC_SCCS -I/sys
|
||||
SRCS= kvm.c kvm_${MACHINE}.c kvm_file.c kvm_getloadavg.c kvm_proc.c
|
||||
|
||||
MAN3= kvm.0 kvm_geterr.0 kvm_getfiles.0 kvm_getloadavg.0 kvm_getprocs.0 \
|
||||
kvm_nlist.0 kvm_open.0 kvm_read.0
|
||||
|
||||
MLINKS+=kvm_getprocs.3 kvm_getargv.3 kvm_getprocs.3 kvm_getenvv.3
|
||||
MLINKS+=kvm_open.3 kvm_openfiles.3 kvm_open.3 kvm_close.3
|
||||
MLINKS+=kvm_read.3 kvm_write.3
|
||||
|
||||
.include <bsd.lib.mk>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user