summaryrefslogtreecommitdiffstats
path: root/text-utils
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:26:12 +0100
committerKarel Zak2006-12-07 00:26:12 +0100
commitdf1dddf9ffcfc1e291de809c0e8b9060bfea02ee (patch)
tree03b712bddec33d05754bf59d31a75d7e2022761e /text-utils
parentImported from util-linux-2.11y tarball. (diff)
downloadkernel-qcow2-util-linux-df1dddf9ffcfc1e291de809c0e8b9060bfea02ee.tar.gz
kernel-qcow2-util-linux-df1dddf9ffcfc1e291de809c0e8b9060bfea02ee.tar.xz
kernel-qcow2-util-linux-df1dddf9ffcfc1e291de809c0e8b9060bfea02ee.zip
Imported from util-linux-2.12 tarball.
Diffstat (limited to 'text-utils')
-rw-r--r--text-utils/Makefile5
-rw-r--r--text-utils/more.c99
-rw-r--r--text-utils/more.help24
-rw-r--r--text-utils/more.help.cs28
-rw-r--r--text-utils/more.help.ja24
-rw-r--r--text-utils/pg.118
-rw-r--r--text-utils/tailf.152
-rw-r--r--text-utils/tailf.c119
8 files changed, 245 insertions, 124 deletions
diff --git a/text-utils/Makefile b/text-utils/Makefile
index 1e86b0ed4..cbe3a5ad2 100644
--- a/text-utils/Makefile
+++ b/text-utils/Makefile
@@ -6,9 +6,9 @@
include ../make_include
include ../MCONFIG
-MAN1= col.1 colcrt.1 colrm.1 column.1 hexdump.1 rev.1 line.1
+MAN1= col.1 colcrt.1 colrm.1 column.1 hexdump.1 rev.1 line.1 tailf.1
-USRBIN= col colcrt colrm column hexdump rev line
+USRBIN= col colcrt colrm column hexdump rev line tailf
BIN=
@@ -72,6 +72,7 @@ column: column.o $(ERR_O)
more.o: more.c $(LIB)/pathnames.h
rev: rev.o
line: line.o
+tailf: tailf.o
colcrt.o colrm.o column.o rev.o ul.o: $(LIB)/widechar.h
diff --git a/text-utils/more.c b/text-utils/more.c
index 7d6de0057..f8fe34760 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -1099,11 +1099,11 @@ void erasep (register int col)
** Erase the current line entirely
*/
-void kill_line ()
+void kill_line()
{
- erasep (0);
+ erasep(0);
if (!eraseln || dumb)
- putchar ('\r');
+ putchar('\r');
}
/*
@@ -1301,6 +1301,7 @@ int command (char *filename, register FILE *f)
end_it (0);
case 's':
case 'f':
+ case ctrl('F'):
if (nlines == 0) nlines++;
if (comchar == 'f')
nlines *= dlines;
@@ -1387,40 +1388,46 @@ int command (char *filename, register FILE *f)
case '?':
case 'h':
if (noscroll) doclear();
- xprintf(_("\nMost commands optionally preceded by integer argument"
- " k. Defaults in brackets.\n"
- "Star (*) indicates argument becomes new default.\n"));
+ xprintf(_("\n"
+"Most commands optionally preceded by integer argument k. "
+"Defaults in brackets.\n"
+"Star (*) indicates argument becomes new default.\n"));
xprintf("---------------------------------------"
"----------------------------------------\n");
- xprintf(_("<space>\t\t\t"
- "Display next k lines of text [current screen size]\n"
- "z\t\t\tDisplay next k lines of text [current screen size]*\n"
- "<return>\t\tDisplay next k lines of text [1]*\n"
- "d or ctrl-D\t\t"
- "Scroll k lines [current scroll size, initially 11]*\n"
- "q or Q or <interrupt>\tExit from more\n"
- "s\t\t\tSkip forward k lines of text [1]\n"
- "f\t\t\tSkip forward k screenfuls of text [1]\n"
- "b or ctrl-B\t\tSkip backwards k screenfuls of text [1]\n"
- "'\t\t\tGo to place where previous search started\n"
- "=\t\t\tDisplay current line number\n"
- "/<regular expression>\t"
- "Search for kth occurrence of regular expression [1]\n"
- "n\t\t\tSearch for kth occurrence of last r.e [1]\n"
- "!<cmd> or :!<cmd>\tExecute <cmd> in a subshell\n"
- "v\t\t\tStart up /usr/bin/vi at current line\n"
- "ctrl-L\t\t\tRedraw screen\n"
- ":n\t\t\tGo to kth next file [1]\n"
- ":p\t\t\tGo to kth previous file [1]\n"
- ":f\t\t\tDisplay current file name and line number\n"
- ".\t\t\tRepeat previous command\n"));
+ xprintf(_(
+"<space> Display next k lines of text [current screen size]\n"
+"z Display next k lines of text [current screen size]*\n"
+"<return> Display next k lines of text [1]*\n"
+"d or ctrl-D Scroll k lines [current scroll size, initially 11]*\n"
+"q or Q or <interrupt> Exit from more\n"
+"s Skip forward k lines of text [1]\n"
+"f Skip forward k screenfuls of text [1]\n"
+"b or ctrl-B Skip backwards k screenfuls of text [1]\n"
+"' Go to place where previous search started\n"
+"= Display current line number\n"
+"/<regular expression> Search for kth occurrence of regular expression [1]\n"
+"n Search for kth occurrence of last r.e [1]\n"
+"!<cmd> or :!<cmd> Execute <cmd> in a subshell\n"
+"v Start up /usr/bin/vi at current line\n"
+"ctrl-L Redraw screen\n"
+":n Go to kth next file [1]\n"
+":p Go to kth previous file [1]\n"
+":f Display current file name and line number\n"
+". Repeat previous command\n"));
xprintf("---------------------------------------"
"----------------------------------------\n");
prompt(filename);
break;
case 'v': /* This case should go right before default */
if (!no_intty) {
- char *editor;
+ /*
+ * Earlier: call vi +n file. This also works for emacs.
+ * POSIX: call vi -c n file (when editor is vi or ex).
+ */
+ char *editor, *p;
+ int n = (Currline - dlines <= 0 ? 1 :
+ Currline - (dlines + 1) / 2);
+ int split = 0;
editor = getenv("VISUAL");
if (editor == NULL || *editor == '\0')
@@ -1428,15 +1435,33 @@ int command (char *filename, register FILE *f)
if (editor == NULL || *editor == '\0')
editor = VI;
- kill_line ();
- cmdbuf[0] = '+';
- scanstr (Currline - dlines <= 0 ? 1
- : Currline - (dlines + 1) / 2, &cmdbuf[1]);
- pr (editor); putchar (' ');
- pr (cmdbuf); putchar (' '); pr (fnames[fnum]);
- execute (filename, editor, editor, cmdbuf, fnames[fnum], 0);
+ p = strrchr(editor, '/');
+ if (p)
+ p++;
+ else
+ p = editor;
+ if (!strcmp(p, "vi") || !strcmp(p, "ex")) {
+ strcpy(cmdbuf, "-c ");
+ scanstr(n, &cmdbuf[3]);
+ split = 1;
+ } else {
+ cmdbuf[0] = '+';
+ scanstr(n, &cmdbuf[1]);
+ }
+
+ kill_line();
+ pr(editor); putchar(' ');
+ pr(cmdbuf); putchar(' '); pr(fnames[fnum]);
+ if (split) {
+ cmdbuf[2] = 0;
+ execute(filename, editor, editor, cmdbuf,
+ cmdbuf+3, fnames[fnum], (char *)0);
+ } else
+ execute(filename, editor, editor,
+ cmdbuf, fnames[fnum], (char *)0);
break;
}
+ /* fall through */
default:
if (dum_opt) {
kill_line ();
@@ -1664,7 +1689,7 @@ void search(char buf[], FILE *file, register int n)
}
/*VARARGS2*/
-void execute (char * filename, char * cmd, ...)
+void execute (char *filename, char *cmd, ...)
{
int id;
int n;
diff --git a/text-utils/more.help b/text-utils/more.help
deleted file mode 100644
index bd415cfb1..000000000
--- a/text-utils/more.help
+++ /dev/null
@@ -1,24 +0,0 @@
-
-Most commands optionally preceded by integer argument k. Defaults in brackets.
-Star (*) indicates argument becomes new default.
--------------------------------------------------------------------------------
-<space> Display next k lines of text [current screen size]
-z Display next k lines of text [current screen size]*
-<return> Display next k lines of text [1]*
-d or ctrl-D Scroll k lines [current scroll size, initially 11]*
-q or Q or <interrupt> Exit from more
-s Skip forward k lines of text [1]
-f Skip forward k screenfuls of text [1]
-b or ctrl-B Skip backwards k screenfuls of text [1]
-' Go to place where previous search started
-= Display current line number
-/<regular expression> Search for kth occurrence of regular expression [1]
-n Search for kth occurrence of last r.e [1]
-!<cmd> or :!<cmd> Execute <cmd> in a subshell
-v Start up /usr/bin/vi at current line
-ctrl-L Redraw screen
-:n Go to kth next file [1]
-:p Go to kth previous file [1]
-:f Display current file name and line number
-. Repeat previous command
--------------------------------------------------------------------------------
diff --git a/text-utils/more.help.cs b/text-utils/more.help.cs
deleted file mode 100644
index 1a69cb365..000000000
--- a/text-utils/more.help.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-
-Vìt¹inì pøíkazù mù¾e jako argument pøedcházet celé èíslo k. Implicitní hodnoty
-jsou v hranatých závorkách. Hvìzdièka (*) znamená, ¾e hodnota argumentu se
-stane implicitní.
--------------------------------------------------------------------------------
-<mezerník> Zobrazí dal¹ích k øádkù textu. [aktuální velikost
- obrazovky]
-z Zobrazí dal¹ích k øádkù textu. [aktuální velikost
- obrazovky]*
-<return> Zobrazí dal¹ích k øádkù textu. [1]*
-d èi ctrl-D Posun o k øádkù [aktuální velikost posunu, po spu¹tìní
- 11]*
-q èi Q èi <interrupt> Ukonèení programu
-s Posun vpøed o k øádkù [1]
-f Posun vpøed o k stran [1]
-b èi ctrl-B Posun vzad o k stran [1]
-' Pøeskoèí na místo, kde bylo zahájeno pøedchozí hledání
-= Zobrazí èíslo aktuálního øádku
-/<regulární výraz> Hledá ktý výskyt regulárního výrazu [1]
-n Hledá ktý výrazu posledního regulárního výrazu [1]
-!<pøíkaz> èi :!<pøíkaz> Spustí <pøíkaz> v podshellu
-v Spustí /usr/bin/vi na aktuálním øádku
-ctrl-L Pøekreslí obrazovku
-:n Pøeskoèí na ktý následující soubor [1]
-:p Pøeskoèí na ktý pøedcházející soubor [1]
-:f Vypí¹e jméno aktuálního souboru a èíslo aktuálního øádku
-. Zopakuje pøedcházející pøíkaz
--------------------------------------------------------------------------------
diff --git a/text-utils/more.help.ja b/text-utils/more.help.ja
deleted file mode 100644
index 3654e89d3..000000000
--- a/text-utils/more.help.ja
+++ /dev/null
@@ -1,24 +0,0 @@
-
-¥³¥Þ¥ó¥É¤Î¿¤¯¤ÏÁ°¤Ë¿ôÃÍ(k)¤òÉÕ¤±¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£[] Æâ¤ÎÃͤ¬¥Ç¥Õ¥©¥ë¥È¤Ç¤¹¡£
-À±°õ(*)¤Ï¥Ç¥Õ¥©¥ë¥È¤¬Êѹ¹¤µ¤ì¤ë¤³¤È¤ò¼¨¤·¤Þ¤¹¡£
--------------------------------------------------------------------------------
-<space> ¼¡¤Î k ¹Ô¤òɽ¼¨¤¹¤ë [¸½ºß¤Î²èÌÌ¥µ¥¤¥º]
-z ¼¡¤Î k ¹Ô¤òɽ¼¨¤¹¤ë [¸½ºß¤Î²èÌÌ¥µ¥¤¥º]*
-<return> ¼¡¤Î k ¹Ô¤òɽ¼¨¤¹¤ë [1]*
-d or ctrl-D k ¹Ô¥¹¥¯¥í¡¼¥ë¤¹¤ë [¸½ºß¤Î¥¹¥¯¥í¡¼¥ë¹Ô¿ô ½é´üÃÍ¤Ï 11]*
-q or Q or <interrupt> more ¤ò½ªÎ»¤¹¤ë
-s ¼¡¤Î k ¹Ô¤òÆɤßÈô¤Ð¤¹ [1]
-f ¼¡¤Î k ²èÌ̤òÆɤßÈô¤Ð¤¹ [1]
-b or ctrl-B k ²èÌÌÌá¤ë [1]
-' Á°²ó¤Î¸¡º÷¤ò³«»Ï¤·¤¿°ÌÃÖ¤ËÌá¤ë
-= ¸½ºß¤Î¹ÔÈÖ¹æ¤òɽ¼¨¤¹¤ë
-/<Àµµ¬É½¸½> Àµµ¬É½¸½¤ò¸¡º÷¤·¡¢k ÈÖÌܤΰÌÃÖ¤ËÈô¤Ö [1]
-n Á°²ó¤Î¸¡º÷¤òºÆ¼Â¹Ô¤·¡¢k ÈÖÌܤΰÌÃÖ¤ËÈô¤Ö [1]
-!<cmd> or :!<cmd> ¥µ¥Ö¥·¥§¥ë¤Ç <cmd> ¤ò¼Â¹Ô¤¹¤ë
-v vi ¤òµ¯Æ°¤¹¤ë
-ctrl-L ²èÌ̤òºÆÉÁ²è¤¹¤ë
-:n ¼¡¤Î k ÈÖÌܤΥե¡¥¤¥ë¤òɽ¼¨¤¹¤ë [1]
-:p Á°¤Î k ÈÖÌܤΥե¡¥¤¥ë¤òɽ¼¨¤¹¤ë [1]
-:f ¸½ºß¤Î¥Õ¥¡¥¤¥ë̾¤È¹ÔÈÖ¹æ¤òɽ¼¨¤¹¤ë
-. ľÁ°¤Î¥³¥Þ¥ó¥É¤ò·«¤êÊÖ¤¹
--------------------------------------------------------------------------------
diff --git a/text-utils/pg.1 b/text-utils/pg.1
index 056be06cf..1f8d5705c 100644
--- a/text-utils/pg.1
+++ b/text-utils/pg.1
@@ -1,19 +1,19 @@
-.\" @(#)pg.1 1.7 (gritter) 4/25/01
-.TH PG 1 "2001-04-25" "Gunnar Ritter" "User Commands"
+.\" @(#)pg.1 1.12 (gritter) 3/12/03
+.TH PG 1 "2003-03-12" "Gunnar Ritter" "User Commands"
.SH NAME
pg \- browse pagewise through text files
.SH SYNOPSIS
.B pg
[
-.I \-number
+.BI \- number
] [
.BI \-p \ string
] [
.B \-cefnrs
] [
-.I +line
+.BI + line
] [
-.I +/pattern/
+.BI +/ pattern /
] [ file . . . ]
.SH DESCRIPTION
.I Pg
@@ -76,7 +76,7 @@ If
.I string
contains
.I %d
-, its first occurence is replaced by the number of the current page.
+, its first occurrence is replaced by the number of the current page.
.TP
.B \-r
Disallow the shell escape.
@@ -91,7 +91,7 @@ if the terminfo entry for the terminal provides this capability.
Start at the given line.
.TP
.BI +/ pattern /
-Start at the line containing the Basic Regular Expression
+Start at the line containing the basic regular expression
.I pattern
given.
.SH USAGE
@@ -137,7 +137,7 @@ Advance to the last line of the input file.
.TP
.IB i / pattern /
Search forward until the first or the \fIi\fR-th
-occurence of the Basic Regular Expression
+occurrence of the basic regular expression
.I pattern
is found. The search starts
after the current page and stops at the end of the file. No wrap-around is
@@ -147,7 +147,7 @@ must be a positive number.
.TP
\fIi\fR\fB?\fR\fIpattern\fR\fB?\fR or \fIi\fR\fB^\fR\fIpattern\fR\fB^\fR
Search backward until the first or the \fIi\fR-th
-occurence of the Basic Regular Expression
+occurrence of the basic regular expression
.I pattern
is found. The search starts
before the current page and stops at the beginning of the file.
diff --git a/text-utils/tailf.1 b/text-utils/tailf.1
new file mode 100644
index 000000000..33a000d13
--- /dev/null
+++ b/text-utils/tailf.1
@@ -0,0 +1,52 @@
+.\" tailf.1 --
+.\" Created: Thu Jan 11 16:43:10 1996 by faith@acm.org
+.\" Copyright 1996, 2003 Rickard E. Faith (faith@acm.org)
+.\"
+.\" Permission is granted to make and distribute verbatim copies of this
+.\" manual provided the copyright notice and this permission notice are
+.\" preserved on all copies.
+.\"
+.\" Permission is granted to copy and distribute modified versions of this
+.\" manual under the conditions for verbatim copying, provided that the
+.\" entire resulting derived work is distributed under the terms of a
+.\" permission notice identical to this one.
+.\"
+.\" Since the Linux kernel and libraries are constantly changing, this
+.\" manual page may be incorrect or out-of-date. The author(s) assume no
+.\" responsibility for errors or omissions, or for damages resulting from
+.\" the use of the information contained herein. The author(s) may not
+.\" have taken the same level of care in the production of this manual,
+.\" which is licensed free of charge, as they might when working
+.\" professionally.
+.\"
+.\" Formatted or processed versions of this manual, if unaccompanied by
+.\" the source, must acknowledge the copyright and authors of this work.
+.\"
+.TH TAILF 1 "13 February 2003" "" "Linux Programmer's Manual"
+.SH NAME
+tailf \- follow the growth of a log file
+.SH SYNOPSIS
+.BI tailf " file"
+.SH DESCRIPTION
+.B tailf
+will print out the last 10 lines of a file and then wait for the file to
+grow. It is similar to
+.B tail -f
+but does not access the file when it is not growing. This has the side
+effect of not updating the access time for the file, so a filesystem flush
+does not occur periodically when no log activity is happening.
+.PP
+.B tailf
+is extremely useful for monitoring log files on a laptop when logging is
+infrequent and the user desires that the hard disk spin down to conserve
+battery life.
+.SH BUGS
+An option could be provided to print out the last
+.I n
+lines instead of the last 10.
+.SH AUTHOR
+This program was written by Rik Faith (faith@acm.org) and may be freely
+distributed under the terms of the X11/MIT License. There is ABSOLUTELY
+NO WARRANTY for this program.
+.SH "SEE ALSO"
+.BR tail "(1), " less "(1)"
diff --git a/text-utils/tailf.c b/text-utils/tailf.c
new file mode 100644
index 000000000..e10243f98
--- /dev/null
+++ b/text-utils/tailf.c
@@ -0,0 +1,119 @@
+/* tailf.c -- tail a log file and then follow it
+ * Created: Tue Jan 9 15:49:21 1996 by faith@acm.org
+ * Copyright 1996, 2003 Rickard E. Faith (faith@acm.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * less -F and tail -f cause a disk access every five seconds. This
+ * program avoids this problem by waiting for the file size to change.
+ * Hence, the file is not accessed, and the access time does not need to be
+ * flushed back to disk. This is sort of a "stealth" tail.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <sys/stat.h>
+#include "nls.h"
+
+static size_t filesize(const char *filename)
+{
+ struct stat sb;
+
+ if (!stat(filename, &sb)) return sb.st_size;
+ return 0;
+}
+
+static void tailf(const char *filename, int lines)
+{
+ char **buffer;
+ int head = 0;
+ int tail = 0;
+ FILE *str;
+ int i;
+
+ if (!(str = fopen(filename, "r"))) {
+ fprintf(stderr, _("Cannot open \"%s\" for read\n"), filename);
+ perror("");
+ exit(1);
+ }
+
+ buffer = malloc(lines * sizeof(*buffer));
+ for (i = 0; i < lines; i++) buffer[i] = malloc(BUFSIZ + 1);
+
+ while (fgets(buffer[tail], BUFSIZ, str)) {
+ if (++tail >= lines) {
+ tail = 0;
+ head = 1;
+ }
+ }
+
+ if (head) {
+ for (i = tail; i < lines; i++) fputs(buffer[i], stdout);
+ for (i = 0; i < tail; i++) fputs(buffer[i], stdout);
+ } else {
+ for (i = head; i < tail; i++) fputs(buffer[i], stdout);
+ }
+ fflush(stdout);
+
+ for (i = 0; i < lines; i++) free(buffer[i]);
+ free(buffer);
+}
+
+int main(int argc, char **argv)
+{
+ char buffer[BUFSIZ];
+ size_t osize, nsize;
+ FILE *str;
+ const char *filename;
+ int count;
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ if (argc != 2) {
+ fprintf(stderr, _("Usage: tailf logfile\n"));
+ exit(1);
+ }
+
+ filename = argv[1];
+
+ tailf(filename, 10);
+
+ for (osize = filesize(filename);;) {
+ nsize = filesize(filename);
+ if (nsize != osize) {
+ if (!(str = fopen(filename, "r"))) {
+ fprintf(stderr, _("Cannot open \"%s\" for read\n"), filename);
+ perror(argv[0]);
+ exit(1);
+ }
+ if (!fseek(str, osize, SEEK_SET))
+ while ((count = fread(buffer, 1, sizeof(buffer), str)) > 0)
+ fwrite(buffer, 1, count, stdout);
+ fflush(stdout);
+ fclose(str);
+ osize = nsize;
+ }
+ usleep(250000); /* 250mS */
+ }
+ return 0;
+}