Imported from util-linux-2.9i tarball.

This commit is contained in:
Karel Zak 2006-12-07 00:25:37 +01:00
parent 2b6fc908bc
commit 5c36a0eb7c
162 changed files with 5996 additions and 8724 deletions

View file

@ -31,9 +31,10 @@ USRBIN:=$(USRBIN) reset
MAN1:=$(MAN1) reset.1
endif
# ifeq "$(HAVE_SYSVINIT)" "no"
# USRBIN:=$(USRBIN) pidof
# endif
# For script only
ifeq "$(HAVE_OPENPTY)" "yes"
CFLAGS:=$(CFLAGS) -DHAVE_OPENPTY
endif
# Programs requiring special compilation
@ -58,16 +59,16 @@ endif
# Rules for everything else
cal: cal.o $(BSD)/getopt.o $(BSD)/err.o
cal: cal.o $(ERR_O)
chkdupexe: chkdupexe.pl
clear: clear.sh
kill: kill.o procs.o
logger: logger.o $(BSD)/getopt.o
logger: logger.o
mcookie: mcookie.o md5.o
mcookie.o: mcookie.c md5.h
md5.o: md5.c md5.h
reset: reset.sh
# pidof: pidof.o procs.o
ifeq "$(HAVE_NCURSES)" "yes"
setterm: setterm.o
endif

View file

@ -42,7 +42,7 @@
.Nd displays a calendar
.Sh SYNOPSIS
.Nm cal
.Op Fl jy
.Op Fl mjy
.Op Ar month Op Ar year
.Sh DESCRIPTION
.Nm Cal
@ -51,6 +51,8 @@ If arguments are not specified,
the current month is displayed.
The options are as follows:
.Bl -tag -width Ds
.It Fl m
Display monday as the first day of the week.
.It Fl j
Display julian dates (days one-based, numbered from January 1).
.It Fl y

View file

@ -34,6 +34,10 @@
* SUCH DAMAGE.
*/
/* 1999-02-01 Jean-Francois Bignolles: added option '-m' to display
* monday as the first day of the week.
*/
/* This defines _LINUX_C_LIB_VERSION_MAJOR, dunno about gnulibc. We
don't want it to read /usr/i586-unknown-linux/include/_G_config.h
so we specify fill path. Were we got /usr/i586-unknown-linux from?
@ -72,7 +76,7 @@
#define FIRST_MISSING_DAY 639787 /* 3 Sep 1752 */
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
#define MAXDAYS 42 /* max slots in a month array */
#define MAXDAYS 43 /* max slots in a month array */
#define SPACE -1 /* used in day array */
static int days_in_month[2][13] = {
@ -87,6 +91,7 @@ int sep1752[MAXDAYS] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE
}, j_sep1752[MAXDAYS] = {
SPACE, SPACE, 245, 246, 258, 259, 260,
261, 262, 263, 264, 265, 266, 267,
@ -94,6 +99,7 @@ int sep1752[MAXDAYS] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE
}, empty[MAXDAYS] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
@ -101,10 +107,13 @@ int sep1752[MAXDAYS] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE
};
char day_headings[] = " S M Tu W Th F S ";
/* week1stday = 1 => " M Tu W Th F S S " */
char j_day_headings[] = " S M Tu W Th F S ";
/* week1stday = 1 => " M Tu W Th F S S " */
const char *full_month[12];
/* leap year -- account for gregorian reformation in 1752 */
@ -124,6 +133,8 @@ const char *full_month[12];
#define leap_years_since_year_1(yr) \
((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
/* 0 => sunday (default), 1 => monday */
int week1stday;
int julian;
void ascii_day __P((char *, int));
@ -153,10 +164,12 @@ main(argc, argv)
#endif
setlocale(LC_ALL,"");
headers_init();
yflag = 0;
while ((ch = getopt(argc, argv, "jy")) != EOF)
while ((ch = getopt(argc, argv, "mjy")) != EOF)
switch(ch) {
case 'm':
week1stday = 1;
break;
case 'j':
julian = 1;
break;
@ -190,6 +203,7 @@ main(argc, argv)
default:
usage();
}
headers_init();
if (month)
monthly(month, year);
@ -209,22 +223,28 @@ main(argc, argv)
void headers_init(void)
{
int i;
int i, wd;
strcpy(day_headings,"");
strcpy(j_day_headings,"");
#if defined(__linux__) && (_LINUX_C_LIB_VERSION_MAJOR > 4 || __GNU_LIBRARY__ > 1)
# define weekday(wd) nl_langinfo(ABDAY_1+wd)
#else
# define weekday(wd) _time_info->abbrev_wkday[wd]
#endif
for(i = 0 ; i < 7 ; i++ ) {
#if defined(__linux__) && (_LINUX_C_LIB_VERSION_MAJOR > 4 || __GNU_LIBRARY__ > 1)
strncat(day_headings,nl_langinfo(ABDAY_1+i),2);
strcat(j_day_headings,nl_langinfo(ABDAY_1+i));
#else
strncat(day_headings,_time_info->abbrev_wkday[i],2);
strcat(j_day_headings,_time_info->abbrev_wkday[i]);
#endif
wd = (i + week1stday) % 7;
strncat(day_headings,weekday(wd),2);
strcat(j_day_headings,weekday(wd));
if (strlen(weekday(wd)) == 2)
strcat(j_day_headings," ");
strcat(day_headings," ");
strcat(j_day_headings," ");
}
#undef weekday
for (i = 0; i < 12; i++) {
#if defined(__linux__) && (_LINUX_C_LIB_VERSION_MAJOR > 4 || __GNU_LIBRARY__ > 1)
@ -341,15 +361,16 @@ day_array(month, year, days)
int *days;
{
int day, dw, dm;
int *d_sep1752;
if (month == 9 && year == 1752) {
memmove(days,
julian ? j_sep1752 : sep1752, MAXDAYS * sizeof(int));
d_sep1752 = julian ? j_sep1752 : sep1752;
memcpy(days, d_sep1752 + week1stday, MAXDAYS * sizeof(int));
return;
}
memmove(days, empty, MAXDAYS * sizeof(int));
memcpy(days, empty, MAXDAYS * sizeof(int));
dm = days_in_month[leap_year(year)][month];
dw = day_in_week(1, month, year);
dw = (day_in_week(1, month, year) - week1stday + 7) % 7;
day = julian ? day_in_year(1, month, year) : 1;
while (dm--)
days[dw++] = day++;
@ -466,6 +487,6 @@ void
usage()
{
(void)fprintf(stderr, "usage: cal [-jy] [[month] year]\n");
(void)fprintf(stderr, "usage: cal [-mjy] [[month] year]\n");
exit(1);
}

8
misc-utils/chkdupexe.pl Normal file → Executable file
View file

@ -1,4 +1,4 @@
#!/usr/bin/perl5 -w
#!/usr/bin/perl -w
#
# chkdupexe version 2.1.1
#
@ -27,7 +27,7 @@
$execdirs='/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin '.
'/usr/X11/bin /usr/bin/X11 /usr/local/X11/bin '.
'/usr/TeX/bin /usr/tex/bin /usr/games '.
'/usr/local/games /usr/intervies/bin/LINUX';
'/usr/local/games';
# Values from /usr/include/linux/errno.h. Existence of linux/errno.ph is not
# something to count on... :-(
@ -96,6 +96,8 @@ while (($prog,$paths)=each %progs) {
}
close(LS);
exit 0;
@unchecked=();
# Check if the users PATH contains something I've not checked. The site admin
# might want to know about inconsistencies in user PATHs and chkdupexec
@ -108,6 +110,6 @@ foreach $dir (split(/:/,$ENV{'PATH'})) {
$didthis{$device,$inode}=1;
}
print "Warning: Your path contanis these directories which chkdupexe have not checked:\n",join(',',@unchecked),
print "Warning: Your path contains these directories which chkdupexe has not checked:\n",join(',',@unchecked),
".\nPlease review the execdirs list in chkdupexe.\n"
if ($#unchecked>=$[);

View file

@ -43,8 +43,8 @@ Newline
.IP %t
Tab
.IP %X
Number of days remaining until X-Day. (Not valid if the SubGenius options are not
compiled in.)
Number of days remaining until X-Day. (Not valid if the SubGenius options
are not compiled in.)
.IP %{
.IP %}
Used to enclose the part of the string which is to be replaced with the
@ -80,6 +80,12 @@ will produce undefined behaviour if asked to produce the date for St. Tib's
day and its format string does not contain the St. Tib's Day delimiters
%{ and %}.
.SH NOTE
After `X-Day' passed without incident, the Church of the SubGenius
declared that it had got the year upside down - X-Day is actually in 8661 AD
rather than 1998 AD. Thus, the True X-Day is Cfn 40, 9827.
.SH AUTHOR
.nh
Original program by Druel the Chaotic aka Jeremy Johnson (mpython@gnu.ai.mit.edu)
@ -96,6 +102,8 @@ Public domain. All rites reversed.
date(1),
.br
http://www.subgenius.com/
.br
Malaclypse the Younger,
.I "Principia Discordia, Or How I Found Goddess And What I Did To Her When I Found Her"

View file

@ -307,12 +307,20 @@ struct disc_time convert(int nday, int nyear)
#ifdef KILL_BOB
/* Code for counting down to X-Day, X-Day being Cfn 40, 3164 */
/* Code for counting down to X-Day, X-Day being Cfn 40, 3164
*
* After `X-Day' passed without incident, the CoSG declared that it had
* got the year upside down --- X-Day is actually in 8661 AD rather than
* 1998 AD.
*
* Thus, the True X-Day is Cfn 40, 9827.
*
*/
int xday_countdown(int yday, int year) {
int r=(185-yday)+(((yday<59)&&(leapp(year)))?1:0);
while(year<3164) r+=(leapp(++year)?366:365);
while(year>3164) r-=(leapp(year--)?366:365);
while(year<9827) r+=(leapp(++year)?366:365);
while(year>9827) r-=(leapp(year--)?366:365);
return r;
}

View file

@ -1,187 +0,0 @@
/* hostname -- set the host name or show the host/domain name
Copyright (C) 1994 Peter Tobias
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <sys/param.h>
#define NO_OPT -1
static char *program_name;
static const char *version_string = "hostname 1.5";
static void sethname(char *);
static void showhname(char *, int);
static void usage(void);
static void sethname(char *hname)
{
if(sethostname(hname, strlen(hname))) {
switch(errno) {
case EPERM:
fprintf(stderr,"%s: you must be root to change the host name\n", program_name);
break;
case EINVAL:
fprintf(stderr,"%s: name too long\n", program_name);
break;
default:
}
exit(1);
};
}
static void showhname(char *hname, int c)
{
struct hostent *hp;
register char *p;
if (!(hp = gethostbyname(hname))) {
herror(program_name);
exit(1);
}
if (!(p = strchr(hp->h_name, '.'))) {
fprintf(stderr,"%s: can't find a FQDN for the host name `%s'\n", program_name, hname);
exit(1);
}
switch(c) {
case 'd':
printf("%s\n", ++p);
break;
case 'f':
printf("%s\n", hp->h_name);
break;
case 's':
*p = '\0';
printf("%s\n", hp->h_name);
break;
default:
}
}
static void usage(void)
{
printf("Usage: %s [OPTION]... [hostname]\n\n\
-d, --domain display the DNS domain name\n\
-F, --file filename read the host name from file\n\
-f, --fqdn, --long display the long host name (FQDN)\n\
-s, --short display the short host name\n\
-h, --help display this help and exit\n\
-v, --version output version information and exit\n\
\n\
When the program is called without any arguments, it displays the\n\
current host name as set by the hostname command. If an argument\n\
is given, the program will set the value of the host name to the\n\
value specified.\n\
Unless you are using bind or NIS for host lookups you can change the\n\
FQDN (Fully Qualified Domain Name) and the DNS domain name (which is\n\
part of the FQDN) in the /etc/hosts file.\n", program_name);
}
int main(int argc, char **argv)
{
int c;
int option_index = 0;
char myname[MAXHOSTNAMELEN+1];
static const struct option long_options[] =
{
{"domain", no_argument, 0, 'd'},
{"file", required_argument, 0, 'F'},
{"fqdn", no_argument, 0, 'f'},
{"help", no_argument, 0, 'h'},
{"long", no_argument, 0, 'f'},
{"short", no_argument, 0, 's'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
program_name = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0];
if (strcmp(program_name, "dnsdomainname") == 0) {
if (argc > 1) {
fprintf(stderr,"%s: You can't change the DNS domainname with this command\n", program_name);
fprintf(stderr,"\nUnless you are using bind or NIS for host lookups you can change the DNS\n");
fprintf(stderr,"domain name (which is part of the FQDN) in the /etc/hosts file.\n");
exit(1);
}
c = 'd';
} else
c = getopt_long(argc, argv, "dfF:hsv", long_options, &option_index);
gethostname(myname, sizeof(myname));
switch(c)
{
case 'd':
case 'f':
case 's':
showhname(myname, c);
break;
case 'F':
{
register FILE *fd;
register char *p;
char fline[MAXHOSTNAMELEN];
if ((fd = fopen(optarg, "r")) != NULL) {
while (fgets(fline, sizeof(fline), fd) != NULL)
if ((p = index(fline, '\n')) != NULL) {
*p = '\0';
if (fline[0] == '#')
continue;
sethname(fline);
}
(void) fclose(fd);
} else {
fprintf(stderr,"%s: can't open `%s'\n",
program_name, optarg);
exit(1);
}
}
break;
case 'h':
usage();
break;
case 'v':
printf("%s\n", version_string);
break;
case '?':
fprintf(stderr,"Try `%s --help' for more information.\n", program_name);
exit(1);
break;
case NO_OPT:
if (optind < argc) {
sethname(argv[optind]);
exit(0);
}
default:
printf("%s\n", myname);
};
exit(0);
}

View file

@ -43,20 +43,91 @@
#include <unistd.h>
#include <signal.h>
#ifdef __linux__
/*
* sys_signame -- an ordered list of signals.
* lifted from /usr/include/linux/signal.h
* this particular order is only correct for linux.
* this is _not_ portable.
*/
char *sys_signame[NSIG] = {
"zero", "HUP", "INT", "QUIT", "ILL", "TRAP", "IOT", "UNUSED",
"FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM",
"STKFLT","CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "IO",
"XCPU", "XFSZ", "VTALRM","PROF", "WINCH", NULL
};
#define SIZE(a) (sizeof(a)/sizeof(a[0]))
struct signv {
char *name;
int val;
} sys_signame[] = {
/* POSIX signals */
{ "HUP", SIGHUP }, /* 1 */
{ "INT", SIGINT }, /* 2 */
{ "QUIT", SIGQUIT }, /* 3 */
{ "ILL", SIGILL }, /* 4 */
{ "ABRT", SIGABRT }, /* 6 */
{ "FPE", SIGFPE }, /* 8 */
{ "KILL", SIGKILL }, /* 9 */
{ "SEGV", SIGSEGV }, /* 11 */
{ "PIPE", SIGPIPE }, /* 13 */
{ "ALRM", SIGALRM }, /* 14 */
{ "TERM", SIGTERM }, /* 15 */
{ "USR1", SIGUSR1 }, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */
{ "USR2", SIGUSR2 }, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */
{ "CHLD", SIGCHLD }, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */
{ "CONT", SIGCONT }, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */
{ "STOP", SIGSTOP }, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */
{ "TSTP", SIGTSTP }, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */
{ "TTIN", SIGTTIN }, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */
{ "TTOU", SIGTTOU }, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */
/* Miscellaneous other signals */
#ifdef SIGTRAP
{ "TRAP", SIGTRAP }, /* 5 */
#endif
#ifdef SIGIOT
{ "IOT", SIGIOT }, /* 6, same as SIGABRT */
#endif
#ifdef SIGEMT
{ "EMT", SIGEMT }, /* 7 (mips,alpha,sparc*) */
#endif
#ifdef SIGBUS
{ "BUS", SIGBUS }, /* 7 (arm,i386,m68k,ppc), 10 (mips,alpha,sparc*) */
#endif
#ifdef SIGSYS
{ "SYS", SIGSYS }, /* 12 (mips,alpha,sparc*) */
#endif
#ifdef SIGSTKFLT
{ "STKFLT", SIGSTKFLT }, /* 16 (arm,i386,m68k,ppc) */
#endif
#ifdef SIGURG
{ "URG", SIGURG }, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */
#endif
#ifdef SIGIO
{ "IO", SIGIO }, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */
#endif
#ifdef SIGPOLL
{ "POLL", SIGPOLL }, /* same as SIGIO */
#endif
#ifdef SIGCLD
{ "CLD", SIGCLD }, /* same as SIGCHLD (mips) */
#endif
#ifdef SIGXCPU
{ "XCPU", SIGXCPU }, /* 24 (arm,i386,m68k,ppc,alpha,sparc*), 30 (mips) */
#endif
#ifdef SIGXFSZ
{ "XFSZ", SIGXFSZ }, /* 25 (arm,i386,m68k,ppc,alpha,sparc*), 31 (mips) */
#endif
#ifdef SIGVTALRM
{ "VTALRM", SIGVTALRM }, /* 26 (arm,i386,m68k,ppc,alpha,sparc*), 28 (mips) */
#endif
#ifdef SIGPROF
{ "PROF", SIGPROF }, /* 27 (arm,i386,m68k,ppc,alpha,sparc*), 29 (mips) */
#endif
#ifdef SIGPWR
{ "PWR", SIGPWR }, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */
#endif
#ifdef SIGINFO
{ "INFO", SIGINFO }, /* 29 (alpha) */
#endif
#ifdef SIGLOST
{ "LOST", SIGLOST }, /* 29 (arm,i386,m68k,ppc,sparc*) */
#endif
#ifdef SIGWINCH
{ "WINCH", SIGWINCH }, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */
#endif
#ifdef SIGUNUSED
{ "UNUSED", SIGUNUSED }, /* 31 (arm,i386,m68k,ppc) */
#endif
};
int main (int argc, char *argv[]);
extern char *mybasename(char *);
@ -197,9 +268,9 @@ int signame_to_signum (char *sig)
if (! strncasecmp (sig, "sig", 3))
sig += 3;
for (n = 1; (n < NSIG) && (sys_signame[n] != NULL); n++) {
if (! strcasecmp (sys_signame[n], sig))
return n;
for (n = 0; n < SIZE(sys_signame); n++) {
if (! strcasecmp (sys_signame[n].name, sig))
return sys_signame[n].val;
}
return (-1);
}
@ -226,22 +297,33 @@ void nosig (char *name)
void printsig (int sig)
{
printf ("%s\n", sys_signame[sig]);
int n;
for (n = 0; n < SIZE(sys_signame); n++) {
if (sys_signame[n].val == sig) {
printf ("%s\n", sys_signame[n].name);
return;
}
}
printf("%d\n", sig);
}
void printsignals (FILE *fp)
{
int n;
int n, lth;
int lpos = 0;
for (n = 1; (n < NSIG) && (sys_signame[n] != NULL); n++) {
fputs (sys_signame[n], fp);
if (n == (NSIG / 2) || n == (NSIG - 1))
for (n = 0; n < SIZE(sys_signame); n++) {
lth = 1+strlen(sys_signame[n].name);
if (lpos+lth > 72) {
fputc ('\n', fp);
else
lpos = 0;
} else if (lpos)
fputc (' ', fp);
lpos += lth;
fputs (sys_signame[n].name, fp);
}
if (n < (NSIG - 1))
fputc ('\n', fp);
fputc ('\n', fp);
}
int usage (int status)

View file

@ -54,42 +54,36 @@
#include <string.h>
#include <ctype.h>
#include <getopt.h>
#include <locale.h>
#include "pathnames.h"
/*
* FOLD and DICT convert characters to a normal form for comparison,
* according to the user specified flags.
*
* DICT expects integers because it uses a non-character value to
* indicate a character which should not participate in comparisons.
*/
#define EQUAL 0
#define GREATER 1
#define LESS (-1)
#define NO_COMPARE (-2)
#define FOLD(c) (isascii(c) && isupper(c) ? tolower(c) : (c))
#define DICT(c) (isascii(c) && isalnum(c) ? (c) : NO_COMPARE)
int dflag, fflag;
/* uglified the source a bit with globals, so that we only need
to allocate comparbuf once */
int stringlen;
char *string;
char *comparbuf;
char *binary_search __P((char *, char *, char *));
int compare __P((char *, char *, char *));
void err __P((const char *fmt, ...));
char *linear_search __P((char *, char *, char *));
int look __P((char *, char *, char *));
void print_from __P((char *, char *, char *));
static char *binary_search (char *, char *);
static int compare (char *, char *, int);
static void err (const char *fmt, ...);
static char *linear_search (char *, char *);
static int look (char *, char *);
static void print_from (char *, char *);
static void usage (void);
static void usage __P((void));
void
main(argc, argv)
int argc;
char *argv[];
int
main(int argc, char *argv[])
{
struct stat sb;
int ch, fd, termchar;
char *back, *file, *front, *string, *p;
char *back, *file, *front, *p;
setlocale(LC_ALL, "");
file = _PATH_WORDS;
termchar = '\0';
@ -142,32 +136,35 @@ main(argc, argv)
(off_t)0)) <= (void *)0)
err("%s: %s", file, strerror(errno));
back = front + sb.st_size;
exit(look(string, front, back));
return look(front, back);
}
int
look(string, front, back)
char *string, *front, *back;
look(char *front, char *back)
{
register int ch;
register char *readp, *writep;
int ch;
char *readp, *writep;
/* Reformat string string to avoid doing it multiple times later. */
for (readp = writep = string; (ch = *readp++) != 0;) {
if (fflag)
ch = FOLD(ch);
if (dflag)
ch = DICT(ch);
if (ch != NO_COMPARE)
*(writep++) = ch;
}
*writep = '\0';
if (dflag) {
for (readp = writep = string; (ch = *readp++) != 0;) {
if (isalnum(ch))
*(writep++) = ch;
}
*writep = '\0';
stringlen = writep - string;
} else
stringlen = strlen(string);
front = binary_search(string, front, back);
front = linear_search(string, front, back);
comparbuf = malloc(stringlen+1);
if (comparbuf == NULL)
err("Out of memory");
front = binary_search(front, back);
front = linear_search(front, back);
if (front)
print_from(string, front, back);
print_from(front, back);
return (front ? 0 : 1);
}
@ -214,10 +211,9 @@ look(string, front, back)
while (p < back && *p++ != '\n');
char *
binary_search(string, front, back)
register char *string, *front, *back;
binary_search(char *front, char *back)
{
register char *p;
char *p;
p = front + (back - front) / 2;
SKIP_PAST_NEWLINE(p, back);
@ -227,7 +223,7 @@ binary_search(string, front, back)
* infinitely loop.
*/
while (p < back && back > front) {
if (compare(string, p, back) == GREATER)
if (compare(p, back, 1) == GREATER)
front = p;
else
back = p;
@ -249,11 +245,10 @@ binary_search(string, front, back)
* o front is before or at the first line to be printed.
*/
char *
linear_search(string, front, back)
char *string, *front, *back;
linear_search(char *front, char *back)
{
while (front < back) {
switch (compare(string, front, back)) {
switch (compare(front, back, 1)) {
case EQUAL: /* Found it. */
return (front);
break;
@ -272,20 +267,26 @@ linear_search(string, front, back)
* Print as many lines as match string, starting at front.
*/
void
print_from(string, front, back)
register char *string, *front, *back;
print_from(char *front, char *back)
{
for (; front < back && compare(string, front, back) == EQUAL; ++front) {
for (; front < back && *front != '\n'; ++front)
if (putchar(*front) == EOF)
err("stdout: %s", strerror(errno));
if (putchar('\n') == EOF)
err("stdout: %s", strerror(errno));
int eol;
while (front < back && compare(front, back, 1) == EQUAL) {
if (compare(front, back, fflag) == EQUAL) {
eol = 0;
while (front < back && !eol) {
if (putchar(*front) == EOF)
err("stdout: %s", strerror(errno));
if (*front++ == '\n')
eol = 1;
}
} else
SKIP_PAST_NEWLINE(front, back);
}
}
/*
* Return LESS, GREATER, or EQUAL depending on how the string1 compares with
* Return LESS, GREATER, or EQUAL depending on how string compares with
* string2 (s1 ??? s2).
*
* o Matches up to len(s1) are EQUAL.
@ -294,32 +295,34 @@ print_from(string, front, back)
* Compare understands about the -f and -d flags, and treats comparisons
* appropriately.
*
* The string "s1" is null terminated. The string s2 is '\n' terminated (or
* "back" terminated).
* The string "string" is null terminated. The string "s2" is '\n' terminated
* (or "s2end" terminated).
*
* We use strcasecmp etc, since it knows how to ignore case also
* in other locales.
*/
int
compare(s1, s2, back)
register char *s1, *s2, *back;
{
register int ch;
compare(char *s2, char *s2end, int nocase) {
int i;
char *p;
for (; *s1 && s2 < back && *s2 != '\n';) {
ch = *s2;
if (fflag)
ch = FOLD(ch);
if (dflag)
ch = DICT(ch);
if (ch == NO_COMPARE) {
++s2; /* Ignore character in comparison. */
continue;
}
if (*s1 != ch)
return (*s1 < ch ? LESS : GREATER);
++s1;
++s2;
/* copy, ignoring things that should be ignored */
p = comparbuf;
i = stringlen;
while(s2 < s2end && *s2 != '\n' && i--) {
if (!dflag || isalnum(*s2))
*p++ = *s2;
s2++;
}
return (*s1 ? GREATER : EQUAL);
*p = 0;
/* and compare */
if (nocase)
i = strncasecmp(comparbuf, string, stringlen);
else
i = strncmp(comparbuf, string, stringlen);
return ((i > 0) ? LESS : (i < 0) ? GREATER : EQUAL);
}
static void

View file

@ -19,10 +19,11 @@ process id, the parent process id, the contents of an input file (if
.B \-f
is specified), and several bytes of information from the first of the
following devices which is present:
.IR /dev/urandom ", " /dev/random ", " /dev/audio .
Other files in
.I /proc
may be used as a last resort.
.IR /dev/random ,
.IR /dev/urandom ,
files in
.IR /proc ,
.IR /dev/audio .
.SH BUGS
The entropy in the generated 128-bit is probably quite small (and,
therefore, vulnerable to attack) unless a non-pseudorandom number generator

View file

@ -101,9 +101,12 @@ int main( int argc, char **argv )
}
for (i = 0; i < RNGS; i++) {
if ((fd = open( rngs[i].path, O_RDONLY )) >= 0) {
if ((fd = open( rngs[i].path, O_RDONLY|O_NONBLOCK )) >= 0) {
r = read( fd, buf, sizeof( buf ) );
MD5Update( &ctx, buf, r );
if (r > 0)
MD5Update( &ctx, buf, r );
else
r = 0;
close( fd );
if (Verbose)
fprintf( stderr, "Got %d bytes from %s\n", r, rngs[i].path );

View file

@ -6,9 +6,9 @@
* modify it under the terms of the gnu general public license.
* there is no warranty.
*
* $Author: janl $
* $Revision: 1.5 $
* $Date: 1996/11/11 22:40:03 $
* faith
* 1.2
* 1995/02/23 01:20:40
*
*/
@ -112,7 +112,6 @@ static char *parse_parens (char *buf)
return cp;
}
char *mybasename (char *path)
{
char *cp;
@ -120,3 +119,4 @@ char *mybasename (char *path)
cp = strrchr (path, '/');
return (cp ? cp + 1 : path);
}

View file

@ -49,6 +49,10 @@
#include <string.h>
#endif
#ifdef HAVE_OPENPTY
#include <pty.h>
#endif
void done(void);
void fail(void);
void fixtty(void);
@ -70,10 +74,12 @@ struct termios tt;
struct winsize win;
int lb;
int l;
#ifndef HAVE_OPENPTY
char line[] = "/dev/ptyXX";
#endif
int aflg;
void
int
main(argc, argv)
int argc;
char *argv[];
@ -131,6 +137,8 @@ main(argc, argv)
doshell();
}
doinput();
return 0;
}
void
@ -140,6 +148,9 @@ doinput()
char ibuf[BUFSIZ];
(void) fclose(fscript);
#ifdef HAVE_OPENPTY
(void) close(slave);
#endif
while ((cc = read(0, ibuf, BUFSIZ)) > 0)
(void) write(master, ibuf, cc);
done();
@ -170,6 +181,9 @@ dooutput()
char obuf[BUFSIZ], *ctime();
(void) close(0);
#ifdef HAVE_OPENPTY
(void) close(slave);
#endif
tvec = time((time_t *)NULL);
fprintf(fscript, "Script started on %s", ctime(&tvec));
for (;;) {
@ -250,6 +264,14 @@ done()
void
getmaster()
{
#ifdef HAVE_OPENPTY
(void) tcgetattr(0, &tt);
(void) ioctl(0, TIOCGWINSZ, (char *)&win);
if (openpty(&master, &slave, NULL, &tt, &win) < 0) {
fprintf(stderr, "openpty failed\n");
fail();
}
#else
char *pty, *bank, *cp;
struct stat stb;
@ -282,12 +304,13 @@ getmaster()
}
fprintf(stderr, "Out of pty's\n");
fail();
#endif /* not HAVE_OPENPTY */
}
void
getslave()
{
#ifndef HAVE_OPENPTY
line[strlen("/dev/")] = 't';
slave = open(line, O_RDWR);
if (slave < 0) {
@ -296,6 +319,7 @@ getslave()
}
(void) tcsetattr(slave, TCSAFLUSH, &tt);
(void) ioctl(slave, TIOCSWINSZ, (char *)&win);
#endif
(void) setsid();
(void) ioctl(slave, TIOCSCTTY, 0);
}

View file

@ -95,6 +95,9 @@
#include <termios.h>
#include <string.h>
#include <fcntl.h>
#ifndef NCURSES_CONST
#define NCURSES_CONST const /* define before including term.h */
#endif
#include <term.h>
#if NCH
#include <ncurses.h>
@ -928,11 +931,12 @@ int vcterm; /* Set if terminal is a virtual console. */
/* -inversescreen [on|off]. Vc only (vt102).
*/
if (opt_inversescreen) {
if (vcterm)
if (vcterm) {
if (opt_invsc_on)
printf("\033[?5h");
else
printf("\033[?5l");
}
}
/* -bold [on|off]. Vc behaves as expected, otherwise off turns off

View file

@ -99,6 +99,8 @@ static char *bindirs[] = {
"/usr/libexec",
"/usr/share",
"/opt/*/bin",
0
};

View file

@ -48,6 +48,7 @@
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <sys/param.h>
#include <sys/signal.h>
#include <sys/stat.h>
@ -56,7 +57,6 @@
#ifdef __linux__
#include <paths.h>
#include "pathnames.h"
#include <locale.h>
#endif
void search_utmp(char *, char *, char *, uid_t);
@ -67,7 +67,7 @@ int utmp_chk(char *, char *);
extern int errno;
void
int
main(int argc, char **argv)
{
register char *cp;
@ -77,9 +77,7 @@ main(int argc, char **argv)
char tty[MAXPATHLEN], *mytty, *ttyname();
void done();
#ifdef __linux__
setlocale(LC_CTYPE,"");
#endif
/* check that sender has write enabled */
if (isatty(fileno(stdin)))
@ -143,6 +141,7 @@ main(int argc, char **argv)
}
done();
/* NOTREACHED */
return 0;
}
@ -291,11 +290,12 @@ void do_write(char *tty, char *mytty, uid_t myuid)
void done();
/* Determine our login name before the we reopen() stdout */
if ((login = getlogin()) == NULL)
if ((login = getlogin()) == NULL) {
if ((pwd = getpwuid(myuid)) != NULL)
login = pwd->pw_name;
else
login = "???";
}
if (strlen(tty) + 6 > sizeof(path))
exit(1);
@ -347,8 +347,13 @@ void wr_fputs(char *s)
PUTC('\r');
PUTC('\n');
} else if (!isprint(c) && !isspace(c) && c != '\007') {
PUTC('^');
PUTC(c^0x40); /* DEL to ?, others to alpha */
if (c & 0x80) {
/* use some fallback? */
(void)printf("\\%3o", (unsigned char) c);
} else {
PUTC('^');
PUTC(c^0x40); /* DEL to ?, others to alpha */
}
} else
PUTC(c);
}