diff options
author | Karel Zak | 2006-12-07 00:25:35 +0100 |
---|---|---|
committer | Karel Zak | 2006-12-07 00:25:35 +0100 |
commit | 2b6fc908bc368b540845a313c3b8a867c5ad9a42 (patch) | |
tree | 6fad48a239bc90515a5dc4084d6e3c3ee1f41e29 /text-utils | |
parent | Imported from util-linux-2.7.1 tarball. (diff) | |
download | kernel-qcow2-util-linux-2b6fc908bc368b540845a313c3b8a867c5ad9a42.tar.gz kernel-qcow2-util-linux-2b6fc908bc368b540845a313c3b8a867c5ad9a42.tar.xz kernel-qcow2-util-linux-2b6fc908bc368b540845a313c3b8a867c5ad9a42.zip |
Imported from util-linux-2.8 tarball.
Diffstat (limited to 'text-utils')
-rw-r--r-- | text-utils/Makefile | 8 | ||||
-rw-r--r-- | text-utils/col.c | 10 | ||||
-rw-r--r-- | text-utils/colcrt.c | 10 | ||||
-rw-r--r-- | text-utils/colrm.c | 11 | ||||
-rw-r--r-- | text-utils/column.c | 10 | ||||
-rw-r--r-- | text-utils/conv.c | 4 | ||||
-rw-r--r-- | text-utils/display.c | 4 | ||||
-rw-r--r-- | text-utils/hexdump.c | 10 | ||||
-rw-r--r-- | text-utils/hexsyntax.c | 4 | ||||
-rw-r--r-- | text-utils/more.c | 80 | ||||
-rw-r--r-- | text-utils/odsyntax.c | 4 | ||||
-rw-r--r-- | text-utils/parse.c | 4 | ||||
-rw-r--r-- | text-utils/rev.c | 142 | ||||
-rw-r--r-- | text-utils/strings.c | 10 | ||||
-rw-r--r-- | text-utils/ul.c | 12 |
15 files changed, 132 insertions, 191 deletions
diff --git a/text-utils/Makefile b/text-utils/Makefile index d5c80b29d..c657be72b 100644 --- a/text-utils/Makefile +++ b/text-utils/Makefile @@ -37,7 +37,11 @@ NEEDS_NCURSES= more ul all: $(BIN) $(USRBIN) $(NEEDS_NCURSES): +ifeq "$(HAVE_NCURSES)" "yes" $(CC) $(LDFLAGS) $^ -o $@ $(LIBCURSES) +else + @echo $@ not made since it requires ncurses +endif # Rules for hexdump @@ -57,10 +61,12 @@ colcrt: colcrt.o colrm: colrm.o column: column.o $(BSD)/err.o more.o: more.c $(BSD)/pathnames.h -more: more.o rev: rev.o strings: strings.o $(BSD)/getopt.o +ifeq "$(HAVE_NCURSES)" "yes" +more: more.o ul: ul.o +endif install install.shadow install.text-utils: all $(INSTALLDIR) $(BINDIR) $(USRBINDIR) $(USRLIBDIR) $(MAN1DIR) diff --git a/text-utils/col.c b/text-utils/col.c index 700e59199..1cbaeb5b1 100644 --- a/text-utils/col.c +++ b/text-utils/col.c @@ -39,16 +39,6 @@ * (cchris@connected.com) */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1990 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)col.c 5.3 (Berkeley) 2/2/91"; -#endif /* not lint */ - #include <stdlib.h> #include <malloc.h> #include <errno.h> diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c index 544c20de7..a4d19bb5a 100644 --- a/text-utils/colcrt.c +++ b/text-utils/colcrt.c @@ -31,16 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1980, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)colcrt.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ - #include <stdio.h> #include <unistd.h> /* for close() */ #include <string.h> diff --git a/text-utils/colrm.c b/text-utils/colrm.c index 1ec5db586..3051c866c 100644 --- a/text-utils/colrm.c +++ b/text-utils/colrm.c @@ -31,17 +31,8 @@ * SUCH DAMAGE. */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1980 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)colrm.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ - #include <stdio.h> + /* COLRM removes unwanted columns from a file Jeff Schriebman UC Berkeley 11-74 diff --git a/text-utils/column.c b/text-utils/column.c index 463adf5ca..09f52ebba 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -31,16 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1989, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)column.c 8.3 (Berkeley) 4/2/94"; -#endif /* not lint */ - #include <sys/types.h> #include <sys/ioctl.h> diff --git a/text-utils/conv.c b/text-utils/conv.c index e2e9690af..2a256fa23 100644 --- a/text-utils/conv.c +++ b/text-utils/conv.c @@ -31,10 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)conv.c 5.4 (Berkeley) 6/1/90"; -#endif /* not lint */ - #include <stdio.h> #include <ctype.h> #include <sys/types.h> diff --git a/text-utils/display.c b/text-utils/display.c index d906cfc9d..27d4e7245 100644 --- a/text-utils/display.c +++ b/text-utils/display.c @@ -31,10 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)display.c 5.11 (Berkeley) 3/9/91"; -#endif /* not lint */ - #include <sys/param.h> #include <sys/stat.h> #include <unistd.h> diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c index 7329d119c..2b3b1bf70 100644 --- a/text-utils/hexdump.c +++ b/text-utils/hexdump.c @@ -31,16 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1989 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)hexdump.c 5.5 (Berkeley) 6/1/90"; -#endif /* not lint */ - #include <sys/types.h> #include <stdio.h> #include "hexdump.h" diff --git a/text-utils/hexsyntax.c b/text-utils/hexsyntax.c index 4a6638a03..136716011 100644 --- a/text-utils/hexsyntax.c +++ b/text-utils/hexsyntax.c @@ -31,10 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)hexsyntax.c 5.2 (Berkeley) 5/8/90"; -#endif /* not lint */ - #include <sys/types.h> #include <unistd.h> #include <stdlib.h> diff --git a/text-utils/more.c b/text-utils/more.c index 123ef06ed..6e0763169 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -15,16 +15,6 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1980 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)more.c 5.19 (Berkeley) 6/29/88"; -#endif /* not lint */ - /* ** more.c - General purpose tty output filter and file perusal program ** @@ -69,7 +59,7 @@ static char sccsid[] = "@(#)more.c 5.19 (Berkeley) 6/29/88"; #define Getc(f) (++file_pos, getc(f)) #define Ungetc(c,f) (--file_pos, ungetc(c,f)) -#define stty(fd,argp) ioctl(fd,TCSETSF,argp) +#define stty(fd,argp) tcsetattr(fd,TCSANOW,argp) /* some function declarations */ void initterm(void); @@ -165,20 +155,31 @@ struct { } context, screen_start; /* extern */ char PC; /* pad character */ +void +idummy(int *kk) {} + +void +Fdummy(FILE **ff) {} int main(int argc, char **argv) { - register FILE *f; - register char *s; - register char *p; - register char ch; - register int left; - int prnames = 0; - int initopt = 0; - int srchopt = 0; - int clearit = 0; - int initline = 0; - char initbuf[80]; - FILE *checkf(); + FILE *f; + char *s; + char *p; + char ch; + int left; + int prnames = 0; + int initopt = 0; + int srchopt = 0; + int clearit = 0; + int initline = 0; + char initbuf[80]; + FILE *checkf(); + + /* avoid gcc complaints about register variables that + may be clobbered by a longjmp, by forcing our variables here + to be non-register */ + Fdummy(&f); idummy(&left); idummy(&prnames); + idummy(&initopt); idummy(&srchopt); idummy(&initline); nfiles = argc; fnames = argv; @@ -806,8 +807,16 @@ int get_line(register FILE *f, int *length) column = 1 + (column | 7); else if (c == '\b' && column > 0) column--; - else if (c == '\r') + else if (c == '\r') { + int next = Getc(f); + if (next == '\n') { + p--; + Currline++; + break; + } + Ungetc(next,f); column = 0; + } else if (c == '\f' && stop_opt) { p[-1] = '^'; *p++ = 'L'; @@ -1505,7 +1514,7 @@ void initterm() #ifdef do_SIGTTOU retry: #endif - no_tty = ioctl(fileno(stdout), TCGETS, &otty); + no_tty = tcgetattr(fileno(stdout), &otty); if (!no_tty) { docrterase = (otty.c_cc[VERASE] != 255); docrtkill = (otty.c_cc[VKILL] != 255); @@ -1551,6 +1560,7 @@ retry: hard++; /* Hard copy terminal */ Lpp = 24; } + if (tigetflag("xenl")) eatnl++; /* Eat newline at last column + 1; dec, concept */ if (Mcol <= 0) @@ -1608,13 +1618,16 @@ retry: if ((shell = getenv("SHELL")) == NULL) shell = "/bin/sh"; } - no_intty = ioctl(fileno(stdin), TCGETS, &otty); - ioctl(fileno(stderr), TCGETS, &otty); + no_intty = tcgetattr(fileno(stdin), &otty); + tcgetattr(fileno(stderr), &otty); savetty0 = otty; slow_tty = (otty.c_cflag & CBAUD) < B1200; hardtabs = (otty.c_oflag & TABDLY) != XTABS; - if (!no_tty) + if (!no_tty) { otty.c_lflag &= ~(ICANON|ECHO); + otty.c_cc[VMIN] = 1; + otty.c_cc[VTIME] = 0; + } } int readch () @@ -1833,6 +1846,8 @@ void rdline (register FILE *f) void onsusp () { + sigset_t signals, oldmask; + /* ignore SIGTTOU so we don't get stopped if csh grabs the tty */ signal(SIGTTOU, SIG_IGN); reset_tty (); @@ -1840,10 +1855,17 @@ void onsusp () signal(SIGTTOU, SIG_DFL); /* Send the TSTP signal to suspend our process group */ signal(SIGTSTP, SIG_DFL); -/* sigsetmask(0);*/ + + /* unblock SIGTSTP or we won't be able to suspend ourself */ + sigemptyset(&signals); + sigaddset(&signals, SIGTSTP); + sigprocmask(SIG_UNBLOCK, &signals, &oldmask); + kill (0, SIGTSTP); /* Pause for station break */ + sigprocmask(SIG_SETMASK, &oldmask, NULL); + /* We're back */ signal (SIGTSTP, onsusp); set_tty (); diff --git a/text-utils/odsyntax.c b/text-utils/odsyntax.c index 120928bf3..cc543c33c 100644 --- a/text-utils/odsyntax.c +++ b/text-utils/odsyntax.c @@ -31,10 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)odsyntax.c 5.4 (Berkeley) 3/8/91"; -#endif /* not lint */ - #include <sys/types.h> #include <stdlib.h> #include <stdio.h> diff --git a/text-utils/parse.c b/text-utils/parse.c index 272809826..ececd1316 100644 --- a/text-utils/parse.c +++ b/text-utils/parse.c @@ -31,10 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char sccsid[] = "@(#)parse.c 5.6 (Berkeley) 3/9/91"; -#endif /* not lint */ - #include <sys/types.h> #include <sys/file.h> #include <stdio.h> diff --git a/text-utils/rev.c b/text-utils/rev.c index 3b4e42104..5c3a8406d 100644 --- a/text-utils/rev.c +++ b/text-utils/rev.c @@ -35,27 +35,16 @@ * * Wed Sep 14 22:26:00 1994: Patch from bjdouma <bjdouma@xs4all.nl> to handle * last line that has no newline correctly. + * 3-Jun-1998: Patched by Nicolai Langfeldt to work better on Linux: + * Handle any-length-lines. Code copied from util-linux' setpwnam.c */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1987, 1992 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)rev.c 5.2 (Berkeley) 3/21/92";*/ -static char rcsid[] = "$Id: rev.c,v 1.4 1996/07/02 20:08:07 janl Exp $"; -#endif /* not lint */ - #include <sys/types.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef __linux__ #include <unistd.h> -#endif /* linux */ void usage __P((void)); void warn __P((const char *, ...)); @@ -65,63 +54,76 @@ main(argc, argv) int argc; char *argv[]; { - register char *filename, *t; -#ifdef __linux__ - char p[512]; -#else /* linux */ - char *p; -#endif /* linux */ - FILE *fp; - size_t len; - int ch, rval; - - while ((ch = getopt(argc, argv, "")) != EOF) - switch(ch) { - case '?': - default: - usage(); - } - - argc -= optind; - argv += optind; - - fp = stdin; - filename = "stdin"; - rval = 0; - do { - if (*argv) { - if ((fp = fopen(*argv, "r")) == NULL) { - warn("%s: %s", *argv, strerror(errno)); - rval = 1; - ++argv; - continue; - } - filename = *argv++; - } -#ifndef __linux__ - while (p = fgetline(fp, &len)) { - t = p + len - 1; - for (t = p + len - 1; t >= p; --t) - putchar(*t); - } -#else /* linux */ - while (fgets(p, 511, fp)) { - len = strlen(p); - t = p + len - 1 - (*(p+len-1)=='\r' - || *(p+len-1)=='\n'); - for ( ; t >= p; --t) - if(strcmp(t, "\0") != 0) - putchar(*t); -#endif /* linux */ - putchar('\n'); - } - if (ferror(fp)) { - warn("%s: %s", filename, strerror(errno)); - rval = 1; - } - (void)fclose(fp); - } while(*argv); - exit(rval); + register char *filename, *t; + size_t buflen=512; + char *p=malloc(buflen); + size_t len; + FILE *fp; + int ch, rval; + + while ((ch = getopt(argc, argv, "")) != EOF) + switch(ch) { + case '?': + default: + usage(); + } + + argc -= optind; + argv += optind; + + fp = stdin; + filename = "stdin"; + rval = 0; + do { + if (*argv) { + if ((fp = fopen(*argv, "r")) == NULL) { + warn("%s: %s", *argv, strerror(errno)); + rval = 1; + ++argv; + continue; + } + filename = *argv++; + } + + while (fgets(p, buflen, fp)) { + + len = strlen(p); + + /* This is my hack from setpwnam.c -janl */ + while (p[len-1] != '\n' && !feof(fp)) { + /* Extend input buffer if it failed getting the whole line */ + + /* So now we double the buffer size */ + buflen *= 2; + + p = realloc(p, buflen); + if (p == NULL) { + fprintf(stderr,"Unable to allocate bufferspace\n"); + exit(1); + } + + /* And fill the rest of the buffer */ + if (fgets(&p[len], buflen/2, fp) == NULL) break; + + len = strlen(p); + + /* That was a lot of work for nothing. Gimme perl! */ + } + + t = p + len - 1 - (*(p+len-1)=='\r' + || *(p+len-1)=='\n'); + for ( ; t >= p; --t) + if(strcmp(t, "\0") != 0) + putchar(*t); + putchar('\n'); + } + if (ferror(fp)) { + warn("%s: %s", filename, strerror(errno)); + rval = 1; + } + (void)fclose(fp); + } while(*argv); + exit(rval); } #if __STDC__ diff --git a/text-utils/strings.c b/text-utils/strings.c index cbcda818a..6c201a744 100644 --- a/text-utils/strings.c +++ b/text-utils/strings.c @@ -34,16 +34,6 @@ * Added internationalization patches from Vitor Duarte <vad@fct.unl.pt> */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1980, 1987 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)strings.c 5.10 (Berkeley) 5/23/91"; -#endif /* not lint */ - #include <sys/types.h> #include <fcntl.h> #include <errno.h> diff --git a/text-utils/ul.c b/text-utils/ul.c index 4d3cf262e..f10d22456 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -31,16 +31,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1980, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)ul.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ - /* ** modified by Kars de Jong <jongk@cs.utwente.nl> to use terminfo instead ** of termcap. @@ -50,6 +40,7 @@ static char sccsid[] = "@(#)ul.c 8.1 (Berkeley) 6/6/93"; #include <unistd.h> /* for getopt(), isatty() */ #include <string.h> /* for bzero() */ #include <term.h> /* for setupterm() */ +#include <stdlib.h> /* for getenv() */ void filter(FILE *f); void flushln(void); @@ -103,7 +94,6 @@ int main(int argc, char **argv) int c, ret; char *termtype; FILE *f; - char *getenv(), *strcpy(); termtype = getenv("TERM"); if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1))) |