summaryrefslogtreecommitdiffstats
path: root/misc-utils
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:46 +0100
committerKarel Zak2006-12-07 00:25:46 +0100
commitc07ebfa1e02d208ab12430e6791ea147bcfaf9c0 (patch)
treed44a755098286f5d553c7aea1a73d98c2995d6ec /misc-utils
parentImported from util-linux-2.10s tarball. (diff)
downloadkernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.tar.gz
kernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.tar.xz
kernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.zip
Imported from util-linux-2.11b tarball.
Diffstat (limited to 'misc-utils')
-rw-r--r--misc-utils/Makefile7
-rw-r--r--misc-utils/cal.c2
-rw-r--r--misc-utils/ddate.c2
-rw-r--r--misc-utils/flushb.c5
-rw-r--r--misc-utils/kill.179
-rw-r--r--misc-utils/kill.c25
-rw-r--r--misc-utils/logger.c2
-rw-r--r--misc-utils/look.c2
-rw-r--r--misc-utils/mcookie.c2
-rw-r--r--misc-utils/namei.c2
-rw-r--r--misc-utils/script.c2
-rw-r--r--misc-utils/setterm.c11
-rw-r--r--misc-utils/tsort.174
-rw-r--r--misc-utils/tsort.c376
-rw-r--r--misc-utils/whereis.c2
-rw-r--r--misc-utils/write.c13
16 files changed, 81 insertions, 525 deletions
diff --git a/misc-utils/Makefile b/misc-utils/Makefile
index 5b74dd39e..9fedca66d 100644
--- a/misc-utils/Makefile
+++ b/misc-utils/Makefile
@@ -21,7 +21,7 @@ BIN= kill
USRBIN= cal chkdupexe ddate logger look mcookie \
namei rename script whereis write
-MAYBE= reset setterm tsort
+MAYBE= reset setterm
ifeq "$(HAVE_RESET)" "no"
USRBIN:=$(USRBIN) reset
@@ -33,11 +33,6 @@ USRBIN:=$(USRBIN) setterm
MAN1:=$(MAN1) setterm.1
endif
-ifeq "$(HAVE_TSORT)" "no"
-USRBIN:=$(USRBIN) tsort
-MAN1:=$(MAN1) tsort.1
-endif
-
# For script only
LIBPTY=
ifeq "$(HAVE_OPENPTY)" "yes"
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index aba1b6f06..768b0a510 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -36,7 +36,7 @@
/* 1999-02-01 Jean-Francois Bignolles: added option '-m' to display
* monday as the first day of the week.
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
* 2000-09-01 Michael Charles Pruznick <dummy@netwiz.net>
diff --git a/misc-utils/ddate.c b/misc-utils/ddate.c
index bf7a37f28..c36f9be3d 100644
--- a/misc-utils/ddate.c
+++ b/misc-utils/ddate.c
@@ -26,7 +26,7 @@
59 Bcy, 3161: PRAISE_BOB and KILL_BOB options split, other minor
changes.
- 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
2000-03-17 Burt Holzman <bnh@iname.com>
diff --git a/misc-utils/flushb.c b/misc-utils/flushb.c
new file mode 100644
index 000000000..34ef9cf63
--- /dev/null
+++ b/misc-utils/flushb.c
@@ -0,0 +1,5 @@
+/*
+ * Some people submit a utility flushb.c.
+ * However, it is useless, BLKFLSBUF is already part of blockdev,
+ * so that "flushb device" is the same as "blockdev --flushbufs device".
+ */
diff --git a/misc-utils/kill.1 b/misc-utils/kill.1
index f4fd6436d..78fd8bbc6 100644
--- a/misc-utils/kill.1
+++ b/misc-utils/kill.1
@@ -5,64 +5,83 @@
.SH NAME
kill \- terminate a process
.SH SYNOPSIS
-.BR "kill" " [ \-s signal | \-p ] " " [ -a ] " "pid ..."
+.BI "kill [ \-s " signal " | \-p ] [ \-a ] [ \-\- ] " "pid ..."
.br
-.B "kill -l [ signal ]"
+.BI "kill -l [ " signal " ]"
.SH DESCRIPTION
+The command
.B kill
-sends the specified signal to the specified process. If no signal is
-specified, the TERM signal is sent. The TERM signal will kill processes
-which do not catch this signal. For other processes, if may be necessary
-to use the KILL (9) signal, since this signal cannot be caught.
-
-Most modern shells have a builtin kill function.
+sends the specified signal to the specified process or process group.
+If no signal is specified, the TERM signal is sent. The TERM signal
+will kill processes which do not catch this signal. For other processes,
+it may be necessary to use the KILL (9) signal, since this signal cannot
+be caught.
+.PP
+Most modern shells have a builtin kill function, with a usage rather similar
+to that of the command described here. The `-a' and `-p' options,
+and the possibility to specify pids by command name is a local extension.
.SH OPTIONS
.TP
-.BR "pid ..."
+.IR pid ...
Specify the list of processes that
.B kill
should signal. Each
.I pid
-can be one of four things. A
-.I "process name"
-in which case processes called that will be signaled.
+can be one of five things:
+
+.RS
+.TP
.I n
where
.I n
is larger than 0. The process with pid
.I n
will be signaled.
-.I -1
-in which case all processes from MAX_INT to 2 will be signaled,
-as allowed by the issuing user.
-.I -n
+.TP
+.B 0
+All processes in the current process group are signaled.
+.TP
+.B -1
+All processes with pid larger than 1 will be signaled.
+.TP
+.BI - n
where
.I n
-is larger than 1, in which case processes in process group
+is larger than 1.
+All processes in process group
.I n
-are signaled. IFF a negative argument is given the signal
-.I must
-be specified first, otherwise it will be taken as the signal to send.
+are signaled. When an argument of the form `-n' is given,
+and it is meant to denote a process group,
+either the signal must be specified first, or the argument must be preceded
+by a `--' option, otherwise it will be taken as the signal to send.
+.TP
+.I commandname
+All processes invoked using that name will be signaled.
+.RE
.TP
-.BR \-s
+.BI \-s " signal"
Specify the signal to send.
The signal may be given as a signal name or number.
.TP
-.BR \-p
-Specify that
-.B kill
-should only print the process id
-.I (pid)
-of the named process, and should not send it a signal.
-.TP
-.BR \-l
+.B \-l
Print a list of signal names. These are found in
.I /usr/include/linux/signal.h
+.TP
+.B \-a
+Do not restrict the commandname-to-pid conversion to processes
+with the same uid as the present process.
+.TP
+.B \-p
+Specify that
+.B kill
+should only print the process id (pid)
+of the named processes, and not send any signals.
.SH "SEE ALSO"
.BR bash (1),
.BR tcsh (1),
.BR kill (2),
-.BR sigvec (2)
+.BR sigvec (2),
+.BR signal (7)
.SH AUTHOR
Taken from BSD 4.4. The ability to translate process names to process
ids was added by Salvatore Valente <svalente@mit.edu>.
diff --git a/misc-utils/kill.c b/misc-utils/kill.c
index ea4e4682d..65100236c 100644
--- a/misc-utils/kill.c
+++ b/misc-utils/kill.c
@@ -35,7 +35,7 @@
* modifications (c) salvatore valente <svalente@mit.edu>
* may be used / modified / distributed under the same terms as the original.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
* 1999-11-13 aeb Accept signal numers 128+s.
@@ -149,12 +149,12 @@ int kill_verbose (char *procname, int pid, int sig);
extern int *get_pids (char *, int);
-char *whoami;
+static char *progname;
int main (int argc, char *argv[])
{
int errors, numsig, pid;
- char *ep, *arg, *progname, *p;
+ char *ep, *arg, *p;
int do_pid, do_kill, check_all;
int *pids, *ip;
@@ -166,9 +166,8 @@ int main (int argc, char *argv[])
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- whoami = mybasename (*argv);
numsig = SIGTERM;
- do_pid = (! strcmp (whoami, "pid"));
+ do_pid = (! strcmp (progname, "pid")); /* Yecch */
do_kill = 0;
check_all = 0;
@@ -184,9 +183,6 @@ int main (int argc, char *argv[])
argc--, argv++;
break;
}
- if (! strcmp (arg, "-u")) {
- return usage (0);
- }
if (! strcmp (arg, "-v") || ! strcmp (arg, "-V") ||
! strcmp (arg, "--version")) {
printf(_("%s from %s\n"), progname, util_linux_version);
@@ -207,7 +203,7 @@ int main (int argc, char *argv[])
/* argc == 2, accept "kill -l $?" */
arg = argv[1];
if ((numsig = arg_to_signum (arg, 1)) < 0) {
- fprintf (stderr, _("%s: unknown signal %s\n"), whoami, arg);
+ fprintf (stderr, _("%s: unknown signal %s\n"), progname, arg);
return 1;
}
printsig (numsig);
@@ -238,6 +234,7 @@ int main (int argc, char *argv[])
so it's probably something like -HUP, or -1/-n
try to deal with it.
-n could be signal n, or pid -n (i.e. process group n).
+ In case of doubt POSIX tells us to assume a signal.
If a signal has been parsed, assume it's a pid, break */
if (do_kill)
break;
@@ -270,7 +267,7 @@ int main (int argc, char *argv[])
if (! pids) {
errors++;
fprintf (stderr, _("%s: can't find process \"%s\"\n"),
- whoami, arg);
+ progname, arg);
continue;
}
for (ip = pids; *ip >= 0; ip++)
@@ -313,7 +310,7 @@ int arg_to_signum (char *arg, int maskbit)
void nosig (char *name)
{
- fprintf (stderr, _("%s: unknown signal %s; valid signals:\n"), whoami, name);
+ fprintf (stderr, _("%s: unknown signal %s; valid signals:\n"), progname, name);
printsignals (stderr);
}
@@ -353,8 +350,8 @@ int usage (int status)
FILE *fp;
fp = (status == 0 ? stdout : stderr);
- fprintf (fp, _("usage: %s [ -s signal | -p ] [ -a ] pid ...\n"), whoami);
- fprintf (fp, _(" %s -l [ signal ]\n"), whoami);
+ fprintf (fp, _("usage: %s [ -s signal | -p ] [ -a ] pid ...\n"), progname);
+ fprintf (fp, _(" %s -l [ signal ]\n"), progname);
return status;
}
@@ -365,7 +362,7 @@ int kill_verbose (char *procname, int pid, int sig)
return 0;
}
if (kill (pid, sig) < 0) {
- fprintf (stderr, "%s ", whoami);
+ fprintf (stderr, "%s ", progname);
perror (procname);
return 1;
}
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index ae0ebec00..e00578735 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
* Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* - fixed strerr(errno) in gettext calls
diff --git a/misc-utils/look.c b/misc-utils/look.c
index d601e1c97..f3b4ba517 100644
--- a/misc-utils/look.c
+++ b/misc-utils/look.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*/
- /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*/
diff --git a/misc-utils/mcookie.c b/misc-utils/mcookie.c
index 9f13b49d1..6930745b2 100644
--- a/misc-utils/mcookie.c
+++ b/misc-utils/mcookie.c
@@ -14,7 +14,7 @@
* gather 128 bits of random information, so the magic cookie generated
* will be considerably easier to guess than one might expect.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
* 1999-03-21 aeb: Added some fragments of code from Colin Plumb.
*
diff --git a/misc-utils/namei.c b/misc-utils/namei.c
index f77d501c4..783c5b9b6 100644
--- a/misc-utils/namei.c
+++ b/misc-utils/namei.c
@@ -39,7 +39,7 @@ the maximum number of symbolic links this system can have.
The program exits with a 1 status ONLY if it finds it cannot
chdir to /, or if it encounters an unknown file type.
-1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
-------------------------------------------------------------*/
diff --git a/misc-utils/script.c b/misc-utils/script.c
index c3bf142e6..951fc763d 100644
--- a/misc-utils/script.c
+++ b/misc-utils/script.c
@@ -32,7 +32,7 @@
*/
/*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
* 2000-07-30 Per Andreas Buer <per@linpro.no> - added "q"-option
diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c
index 92161d01c..2e265fc51 100644
--- a/misc-utils/setterm.c
+++ b/misc-utils/setterm.c
@@ -16,7 +16,7 @@
*
* Converted to terminfo by Kars de Jong (jongk@cs.utwente.nl)
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
*
@@ -859,17 +859,17 @@ perform_sequence(int vcterm) {
/* -snow [on|off]. Vc only. */
if (opt_snow && vcterm) {
if (opt_sn_on)
- printf("%s%s%s", DCS, _("snow.on"), ST);
+ printf("%s%s%s", DCS, "snow.on", ST);
else
- printf("%s%s%s", DCS, _("snow.off"), ST);
+ printf("%s%s%s", DCS, "snow.off", ST);
}
/* -softscroll [on|off]. Vc only. */
if (opt_softscroll && vcterm) {
if (opt_so_on)
- printf("%s%s%s", DCS, _("softscroll.on"), ST);
+ printf("%s%s%s", DCS, "softscroll.on", ST);
else
- printf("%s%s%s", DCS, _("softscroll.off"), ST);
+ printf("%s%s%s", DCS, "softscroll.off", ST);
}
#endif
@@ -1165,6 +1165,7 @@ try_ioctl:
}
rows = screenbuf[0];
cols = screenbuf[1];
+
for (i=0; i<rows; i++) {
strncpy(buf, screenbuf+2+(cols*i), cols);
buf[cols] = '\0';
diff --git a/misc-utils/tsort.1 b/misc-utils/tsort.1
deleted file mode 100644
index 72ea964a9..000000000
--- a/misc-utils/tsort.1
+++ /dev/null
@@ -1,74 +0,0 @@
-.\" Copyright (c) 1990 The Regents of the University of California.
-.\" All rights reserved.
-.\"
-.\" This manual is derived from one contributed to Berkeley by
-.\" Michael Rendell of Memorial University of Newfoundland.
-.\" 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.
-.\"
-.\" @(#)tsort.1 6.3 (Berkeley) 4/23/91
-.\"
-.Dd April 23, 1991
-.Dt TSORT 1
-.Os
-.Sh NAME
-.Nm tsort
-.Nd topological sort of a directed graph
-.Sh SYNOPSIS
-.Nm tsort
-.Op Ar file
-.Sh DESCRIPTION
-.Nm Tsort
-takes a list of pairs of node names representing directed arcs in
-a graph and prints the nodes in topological order on standard output.
-Input is taken from the named
-.Ar file ,
-or from standard input if no file
-is given.
-.Pp
-Node names in the input are separated by white space and there must be an
-even number of nodes.
-.Pp
-Presence of a node in a graph can be represented by an arc from the node
-to itself.
-This is useful when a node is not connected to any other nodes.
-.Pp
-If the graph contains a cycle (and therefore cannot be properly sorted),
-one of the arcs in the cycle is ignored and the sort continues.
-Cycles are reported on standard error.
-.Sh SEE ALSO
-.Xr ar 1
-.Sh HISTORY
-A
-.Nm
-command appeared in
-.At v7 .
-This
-.Nm tsort
-command and manual page are derived from sources contributed to Berkeley by
-Michael Rendell of Memorial University of Newfoundland.
diff --git a/misc-utils/tsort.c b/misc-utils/tsort.c
deleted file mode 100644
index b97b1a03b..000000000
--- a/misc-utils/tsort.c
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Rendell of Memorial University of Newfoundland.
- *
- * 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.
- */
-
- /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
- * - added Native Language Support
- */
-
-#include <sys/types.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include "nls.h"
-
-/*
- * Topological sort. Input is a list of pairs of strings seperated by
- * white space (spaces, tabs, and/or newlines); strings are written to
- * standard output in sorted order, one per line.
- *
- * usage:
- * tsort [inputfile]
- * If no input file is specified, standard input is read.
- *
- * Should be compatable with AT&T tsort HOWEVER the output is not identical
- * (i.e. for most graphs there is more than one sorted order, and this tsort
- * usually generates a different one then the AT&T tsort). Also, cycle
- * reporting seems to be more accurate in this version (the AT&T tsort
- * sometimes says a node is in a cycle when it isn't).
- *
- * Michael Rendell, michael@stretch.cs.mun.ca - Feb 26, '90
- */
-#define HASHSIZE 53 /* doesn't need to be big */
-#define NF_MARK 0x1 /* marker for cycle detection */
-#define NF_ACYCLIC 0x2 /* this node is cycle free */
-
-typedef struct node_str NODE;
-
-struct node_str {
- char *n_name; /* name of this node */
- NODE **n_prevp; /* pointer to previous node's n_next */
- NODE *n_next; /* next node in graph */
- NODE *n_hash; /* next node in hash table */
- int n_narcs; /* number of arcs in n_arcs[] */
- int n_arcsize; /* size of n_arcs[] array */
- NODE **n_arcs; /* array of arcs to other nodes */
- int n_refcnt; /* # of arcs pointing to this node */
- int n_flags; /* NF_* */
-};
-
-typedef struct _buf {
- char *b_buf;
- int b_bsize;
-} BUF;
-
-NODE *add_node(char *), *find_node(char *);
-void add_arc(char *, char *), no_memory(void);
-void remove_node(NODE *), tsort(void);
-char *grow_buf(char *, int);
-int find_cycle(NODE *, NODE *, int, int);
-
-NODE *graph;
-NODE *hashtable[HASHSIZE];
-NODE **cycle_buf;
-NODE **longest_cycle;
-
-int
-main(int argc, char **argv) {
- BUF *b;
- int c, n;
- FILE *fp;
- int bsize, nused;
- BUF bufs[2];
-
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-
- if (argc < 2)
- fp = stdin;
- /* == becomes > in next line per Volker Meyer_zu_Bexten
- <vmzb@ims.fhg.de> -- faith@cs.unc.edu, Sat Feb 4 21:25:09 1995 */
- else if (argc > 2) {
- (void)fprintf(stderr, _("usage: tsort [ inputfile ]\n"));
- exit(1);
- } else if (!(fp = fopen(argv[1], "r"))) {
- (void)fprintf(stderr, "tsort: %s.\n", strerror(errno));
- exit(1);
- }
-
- for (b = bufs, n = 2; --n >= 0; b++)
- b->b_buf = grow_buf((char *)NULL, b->b_bsize = 1024);
-
- /* parse input and build the graph */
- for (n = 0, c = getc(fp);;) {
- while (c != EOF && isspace(c))
- c = getc(fp);
- if (c == EOF)
- break;
-
- nused = 0;
- b = &bufs[n];
- bsize = b->b_bsize;
- do {
- b->b_buf[nused++] = c;
- if (nused == bsize) {
- bsize *= 2;
- b->b_buf = grow_buf(b->b_buf, bsize);
- }
- c = getc(fp);
- } while (c != EOF && !isspace(c));
-
- b->b_buf[nused] = '\0';
- b->b_bsize = bsize;
- if (n)
- add_arc(bufs[0].b_buf, bufs[1].b_buf);
- n = !n;
- }
- (void)fclose(fp);
- if (n) {
- (void)fprintf(stderr, _("tsort: odd data count.\n"));
- exit(1);
- }
-
- /* do the sort */
- tsort();
- return 0;
-}
-
-/* double the size of oldbuf and return a pointer to the new buffer. */
-char *
-grow_buf(char *bp, int size) {
- if (!(bp = realloc(bp, (u_int)size)))
- no_memory();
- return(bp);
-}
-
-/*
- * add an arc from node s1 to node s2 in the graph. If s1 or s2 are not in
- * the graph, then add them.
- */
-void
-add_arc(char *s1, char *s2) {
- NODE *n1;
- NODE *n2;
- int bsize;
-
- n1 = find_node(s1);
- if (!n1)
- n1 = add_node(s1);
-
- if (!strcmp(s1, s2))
- return;
-
- n2 = find_node(s2);
- if (!n2)
- n2 = add_node(s2);
-
- /*
- * could check to see if this arc is here already, but it isn't
- * worth the bother -- there usually isn't and it doesn't hurt if
- * there is (I think :-).
- */
- if (n1->n_narcs == n1->n_arcsize) {
- if (!n1->n_arcsize)
- n1->n_arcsize = 10;
- bsize = n1->n_arcsize * sizeof(*n1->n_arcs) * 2;
- n1->n_arcs = (NODE **)grow_buf((char *)n1->n_arcs, bsize);
- n1->n_arcsize = bsize / sizeof(*n1->n_arcs);
- }
- n1->n_arcs[n1->n_narcs++] = n2;
- ++n2->n_refcnt;
-}
-
-static int
-hash_string(char *s) {
- int hash, i;
-
- for (hash = 0, i = 1; *s; s++, i++)
- hash += *s * i;
- return(hash % HASHSIZE);
-}
-
-/*
- * find a node in the graph and return a pointer to it - returns null if not
- * found.
- */
-NODE *
-find_node(char *name) {
- NODE *n;
-
- for (n = hashtable[hash_string(name)]; n; n = n->n_hash)
- if (!strcmp(n->n_name, name))
- return(n);
- return((NODE *)NULL);
-}
-
-/* Add a node to the graph and return a pointer to it. */
-NODE *
-add_node(char *name) {
- NODE *n;
- int hash;
-
- if (!(n = (NODE *)malloc(sizeof(NODE))) || !(n->n_name = strdup(name)))
- no_memory();
-
- n->n_narcs = 0;
- n->n_arcsize = 0;
- n->n_arcs = (NODE **)NULL;
- n->n_refcnt = 0;
- n->n_flags = 0;
-
- /* add to linked list */
- if ((n->n_next = graph) != NULL)
- graph->n_prevp = &n->n_next;
- n->n_prevp = &graph;
- graph = n;
-
- /* add to hash table */
- hash = hash_string(name);
- n->n_hash = hashtable[hash];
- hashtable[hash] = n;
- return(n);
-}
-
-/* do topological sort on graph */
-void
-tsort(void) {
- NODE *n, *next;
- int cnt;
-
- while (graph) {
- /*
- * keep getting rid of simple cases until there are none left,
- * if there are any nodes still in the graph, then there is
- * a cycle in it.
- */
- do {
- for (cnt = 0, n = graph; n; n = next) {
- next = n->n_next;
- if (n->n_refcnt == 0) {
- remove_node(n);
- ++cnt;
- }
- }
- } while (graph && cnt);
-
- if (!graph)
- break;
-
- if (!cycle_buf) {
- /*
- * allocate space for two cycle logs - one to be used
- * as scratch space, the other to save the longest
- * cycle.
- */
- for (cnt = 0, n = graph; n; n = n->n_next)
- ++cnt;
- cycle_buf =
- (NODE **)malloc((u_int)sizeof(NODE *) * cnt);
- longest_cycle =
- (NODE **)malloc((u_int)sizeof(NODE *) * cnt);
- if (!cycle_buf || !longest_cycle)
- no_memory();
- }
- for (n = graph; n; n = n->n_next)
- if (!(n->n_flags & NF_ACYCLIC)) {
- if ((cnt = find_cycle(n, n, 0, 0)) != 0) {
- int i;
-
- (void)fprintf(stderr,
- _("tsort: cycle in data.\n"));
- for (i = 0; i < cnt; i++)
- (void)fprintf(stderr,
- "tsort: %s.\n", longest_cycle[i]->n_name);
- remove_node(n);
- break;
- } else
- /* to avoid further checks */
- n->n_flags = NF_ACYCLIC;
- }
-
- if (!n) {
- (void)fprintf(stderr,
- _("tsort: internal error -- could not find cycle.\n"));
- exit(1);
- }
- }
-}
-
-/* print node and remove from graph (does not actually free node) */
-void
-remove_node(NODE *n) {
- NODE **np;
- int i;
-
- (void)printf("%s\n", n->n_name);
- for (np = n->n_arcs, i = n->n_narcs; --i >= 0; np++)
- --(*np)->n_refcnt;
- n->n_narcs = 0;
- *n->n_prevp = n->n_next;
- if (n->n_next)
- n->n_next->n_prevp = n->n_prevp;
-}
-
-/* look for the longest cycle from node from to node to. */
-int
-find_cycle(NODE *from, NODE *to, int longest_len, int depth) {
- NODE **np;
- int i, len;
-
- /*
- * avoid infinite loops and ignore portions of the graph known
- * to be acyclic
- */
- if (from->n_flags & (NF_MARK|NF_ACYCLIC))
- return(0);
- from->n_flags = NF_MARK;
-
- for (np = from->n_arcs, i = from->n_narcs; --i >= 0; np++) {
- cycle_buf[depth] = *np;
- if (*np == to) {
- if (depth + 1 > longest_len) {
- longest_len = depth + 1;
- (void)memcpy((char *)longest_cycle,
- (char *)cycle_buf,
- longest_len * sizeof(NODE *));
- }
- } else {
- len = find_cycle(*np, to, longest_len, depth + 1);
- if (len > longest_len)
- longest_len = len;
- }
- }
- from->n_flags &= ~NF_MARK;
- return(longest_len);
-}
-
-void
-no_memory(void) {
- (void)fprintf(stderr, "tsort: %s.\n", strerror(ENOMEM));
- exit(1);
-}
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 239b1f4ae..385cbf41b 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -33,7 +33,7 @@
/* *:aeb */
-/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*/
diff --git a/misc-utils/write.c b/misc-utils/write.c
index e794a4eee..b3c96d14c 100644
--- a/misc-utils/write.c
+++ b/misc-utils/write.c
@@ -40,7 +40,7 @@
* - Added fix from David.Chapell@mail.trincoll.edu enabeling daemons
* to use write.
* - ANSIed it since I was working on it anyway.
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
*/
@@ -197,11 +197,7 @@ void search_utmp(char *user, char *tty, char *mytty, uid_t myuid)
struct utmp *uptr;
time_t bestatime, atime;
int nloggedttys, nttys, msgsok, user_is_me;
-#ifdef __linux__
char atty[sizeof(u.ut_line) + 1];
-#else
- char atty[UT_LINESIZE + 1];
-#endif
utmpname(_PATH_UTMP);
setutent();
@@ -213,13 +209,8 @@ void search_utmp(char *user, char *tty, char *mytty, uid_t myuid)
memcpy(&u, uptr, sizeof(u));
if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
++nloggedttys;
-#ifdef __linux__
(void)strncpy(atty, u.ut_line, sizeof(u.ut_line));
atty[sizeof(u.ut_line)] = '\0';
-#else
- (void)strncpy(atty, u.ut_line, UT_LINESIZE);
- atty[UT_LINESIZE] = '\0';
-#endif
if (term_chk(atty, &msgsok, &atime, 0))
continue; /* bad term? skip */
if (myuid && !msgsok)
@@ -228,10 +219,8 @@ void search_utmp(char *user, char *tty, char *mytty, uid_t myuid)
user_is_me = 1;
continue; /* don't write to yourself */
}
-#ifdef __linux__
if (u.ut_type != USER_PROCESS)
continue; /* it's not a valid entry */
-#endif
++nttys;
if (atime > bestatime) {
bestatime = atime;