summaryrefslogtreecommitdiffstats
path: root/text-utils
diff options
context:
space:
mode:
Diffstat (limited to 'text-utils')
-rw-r--r--text-utils/Makefile8
-rw-r--r--text-utils/col.c42
-rw-r--r--text-utils/colcrt.c26
-rw-r--r--text-utils/colrm.c9
-rw-r--r--text-utils/column.c17
-rw-r--r--text-utils/conv.c11
-rw-r--r--text-utils/display.c66
-rw-r--r--text-utils/hexdump.c5
-rw-r--r--text-utils/hexdump.h16
-rw-r--r--text-utils/hexsyntax.c8
-rw-r--r--text-utils/more.c384
-rw-r--r--text-utils/odsyntax.c19
-rw-r--r--text-utils/parse.c37
-rw-r--r--text-utils/rev.c8
-rw-r--r--text-utils/ul.18
-rw-r--r--text-utils/ul.c109
16 files changed, 406 insertions, 367 deletions
diff --git a/text-utils/Makefile b/text-utils/Makefile
index 834531d29..d5c80b29d 100644
--- a/text-utils/Makefile
+++ b/text-utils/Makefile
@@ -1,6 +1,6 @@
# Makefile -- Makefile for util-linux Linux utilities
# Created: Sat Dec 26 20:09:40 1992
-# Revised: Sat Jun 3 14:11:08 1995 by r.faith@ieee.org
+# Revised: Mon Aug 19 20:11:15 1996 by faith@cs.unc.edu
# Copyright 1992, 1993, 1994, 1995 Rickard E. Faith (faith@cs.unc.edu)
#
@@ -32,12 +32,12 @@ USRLIB= more.help
# Programs requiring special compilation
-NEEDS_TERMCAP= more ul
+NEEDS_NCURSES= more ul
all: $(BIN) $(USRBIN)
-$(NEEDS_TERMCAP):
- $(CC) $(LDFLAGS) $^ -o $@ -ltermcap
+$(NEEDS_NCURSES):
+ $(CC) $(LDFLAGS) $^ -o $@ $(LIBCURSES)
# Rules for hexdump
diff --git a/text-utils/col.c b/text-utils/col.c
index 8be274e03..700e59199 100644
--- a/text-utils/col.c
+++ b/text-utils/col.c
@@ -49,10 +49,13 @@ char copyright[] =
static char sccsid[] = "@(#)col.c 5.3 (Berkeley) 2/2/91";
#endif /* not lint */
+#include <stdlib.h>
+#include <malloc.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
+#include <unistd.h>
#include <locale.h>
#define BS '\b' /* backspace */
@@ -92,8 +95,15 @@ struct line_str {
int l_max_col; /* max column in the line */
};
-LINE *alloc_line();
-void *xmalloc();
+void usage(void);
+void wrerr(void);
+void warn(int);
+void free_line(LINE *l);
+void flush_line(LINE *l);
+void flush_lines(int);
+void flush_blanks(void);
+void *xmalloc(void *p, size_t size);
+LINE *alloc_line(void);
CSET last_set; /* char_set of last char printed */
LINE *lines;
@@ -107,9 +117,7 @@ int no_backspaces; /* if not to output any backspaces */
if (putchar(ch) == EOF) \
wrerr();
-main(argc, argv)
- int argc;
- char **argv;
+int main(int argc, char **argv)
{
extern int optind;
extern char *optarg;
@@ -313,11 +321,10 @@ main(argc, argv)
/* missing a \n on the last line? */
nblank_lines = 2;
flush_blanks();
- exit(0);
+ return 0;
}
-flush_lines(nflush)
- int nflush;
+void flush_lines(int nflush)
{
LINE *l;
@@ -342,7 +349,7 @@ flush_lines(nflush)
* is the number of half line feeds, otherwise it is the number of whole line
* feeds.
*/
-flush_blanks()
+void flush_blanks()
{
int half, i, nb;
@@ -370,8 +377,7 @@ flush_blanks()
* Write a line to stdout taking care of space to tab conversion (-h flag)
* and character set shifts.
*/
-flush_line(l)
- LINE *l;
+void flush_line(LINE *l)
{
CHAR *c, *endc;
int nchars, last_col, this_col;
@@ -489,17 +495,14 @@ alloc_line()
return(l);
}
-free_line(l)
- LINE *l;
+void free_line(LINE *l)
{
l->l_next = line_freelist;
line_freelist = l;
}
void *
-xmalloc(p, size)
- void *p;
- size_t size;
+xmalloc(void *p, size_t size)
{
if (!(p = (void *)realloc(p, size))) {
(void)fprintf(stderr, "col: %s.\n", strerror(ENOMEM));
@@ -508,20 +511,19 @@ xmalloc(p, size)
return(p);
}
-usage()
+void usage()
{
(void)fprintf(stderr, "usage: col [-bfx] [-l nline]\n");
exit(1);
}
-wrerr()
+void wrerr()
{
(void)fprintf(stderr, "col: write error.\n");
exit(1);
}
-warn(line)
- int line;
+void warn(int line)
{
(void)fprintf(stderr,
"col: warning: can't back up %s.\n", line < 0 ?
diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c
index 9e6136b56..544c20de7 100644
--- a/text-utils/colcrt.c
+++ b/text-utils/colcrt.c
@@ -42,6 +42,13 @@ 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>
+
+int plus(char c, char d);
+void move(int l, int m);
+void pflush(int ol);
+
/*
* colcrt - replaces col for crts with new nroff esp. when using tbl.
* Bill Joy UCB July 14, 1977
@@ -67,9 +74,7 @@ char printall;
char *progname;
FILE *f;
-main(argc, argv)
- int argc;
- char *argv[];
+int main(int argc, char **argv)
{
register c;
register char *cp, *dp;
@@ -177,22 +182,20 @@ main(argc, argv)
}
} while (argc > 0);
fflush(stdout);
- exit(0);
+ return 0;
}
-plus(c, d)
- char c, d;
+int plus(char c, char d)
{
- return (c == '|' && d == '-' || d == '_');
+ return (c == '|' && (d == '-' || d == '_'));
}
int first;
-pflush(ol)
- int ol;
+void pflush(int ol)
{
- register int i, j;
+ register int i;
register char *cp;
char lastomit;
int l;
@@ -223,8 +226,7 @@ pflush(ol)
first = 1;
}
-move(l, m)
- int l, m;
+void move(int l, int m)
{
register char *cp, *dp;
diff --git a/text-utils/colrm.c b/text-utils/colrm.c
index 0fcf725b1..1ec5db586 100644
--- a/text-utils/colrm.c
+++ b/text-utils/colrm.c
@@ -47,9 +47,9 @@ COLRM removes unwanted columns from a file
Jeff Schriebman UC Berkeley 11-74
*/
+int getn(char *ap);
-main(argc,argv)
-char **argv;
+int main(int argc, char **argv)
{
register c, ct, first, last;
@@ -109,11 +109,10 @@ loop1:
}
fin:
fflush(stdout);
- exit(0);
+ return 0;
}
-getn(ap)
-char *ap;
+int getn(char *ap)
{
register int n,c;
register char *p;
diff --git a/text-utils/column.c b/text-utils/column.c
index 7536c06d7..463adf5ca 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -48,6 +48,7 @@ static char sccsid[] = "@(#)column.c 8.3 (Berkeley) 4/2/94";
#include <err.h>
#include <limits.h>
#include <stdio.h>
+#include <unistd.h>
#include <stdlib.h>
#include <string.h>
@@ -85,7 +86,7 @@ main(argc, argv)
#endif
if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) {
- if (p = getenv("COLUMNS"))
+ if ((p = getenv("COLUMNS")) != NULL)
termwidth = atoi(p);
} else
termwidth = win.ws_col;
@@ -115,7 +116,7 @@ main(argc, argv)
if (!*argv)
input(stdin);
else for (; *argv; ++argv)
- if (fp = fopen(*argv, "r")) {
+ if ((fp = fopen(*argv, "r")) != NULL) {
input(fp);
(void)fclose(fp);
} else {
@@ -156,7 +157,7 @@ c_columnate()
endcol = maxlength;
putchar('\n');
} else {
- while ((cnt = (chcnt + TAB & ~(TAB - 1))) <= endcol) {
+ while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol) {
(void)putchar('\t');
chcnt = cnt;
}
@@ -173,7 +174,10 @@ r_columnate()
int base, chcnt, cnt, col, endcol, numcols, numrows, row;
maxlength = (maxlength + TAB) & ~(TAB - 1);
+ /* This could be 0 */
numcols = termwidth / maxlength;
+ if (!numcols)
+ numcols = 1;
numrows = entries / numcols;
if (entries % numcols)
++numrows;
@@ -184,7 +188,7 @@ r_columnate()
chcnt += printf("%s", list[base]);
if ((base += numrows) >= entries)
break;
- while ((cnt = (chcnt + TAB & ~(TAB - 1))) <= endcol) {
+ while ((cnt = ((chcnt + TAB) & ~(TAB - 1))) <= endcol) {
(void)putchar('\t');
chcnt = cnt;
}
@@ -224,8 +228,9 @@ maketbl()
cols = emalloc((maxcols = DEFCOLS) * sizeof(char *));
lens = emalloc(maxcols * sizeof(int));
for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
- for (coloff = 0, p = *lp; cols[coloff] = strtok(p, separator);
- p = NULL)
+ for (coloff = 0, p = *lp;
+ (cols[coloff] = strtok(p, separator)) != NULL;
+ p = NULL)
if (++coloff == maxcols) {
if (!(cols = realloc(cols, (u_int)maxcols +
DEFCOLS * sizeof(char *))) ||
diff --git a/text-utils/conv.c b/text-utils/conv.c
index c7a37a2b4..e2e9690af 100644
--- a/text-utils/conv.c
+++ b/text-utils/conv.c
@@ -35,13 +35,12 @@
static char sccsid[] = "@(#)conv.c 5.4 (Berkeley) 6/1/90";
#endif /* not lint */
-#include <sys/types.h>
+#include <stdio.h>
#include <ctype.h>
+#include <sys/types.h>
#include "hexdump.h"
-conv_c(pr, p)
- PR *pr;
- u_char *p;
+void conv_c(PR *pr, u_char *p)
{
extern int deprecated;
char buf[10], *str;
@@ -89,9 +88,7 @@ strpr: *pr->cchar = 's';
}
}
-conv_u(pr, p)
- PR *pr;
- u_char *p;
+void conv_u(PR *pr, u_char *p)
{
extern int deprecated;
static char *list[] = {
diff --git a/text-utils/display.c b/text-utils/display.c
index 12732ee72..d906cfc9d 100644
--- a/text-utils/display.c
+++ b/text-utils/display.c
@@ -45,7 +45,9 @@ static char sccsid[] = "@(#)display.c 5.11 (Berkeley) 3/9/91";
#include <string.h>
#include "hexdump.h"
-#ifdef linux
+static void doskip(char *, int);
+
+#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
@@ -135,7 +137,23 @@ static off_t savaddress; /* saved address/offset in stream */
} \
}
-display()
+void bpad(PR *pr)
+{
+ static char *spec = " -0+#";
+ register char *p1, *p2;
+
+ /*
+ * remove all conversion flags; '-' is the only one valid
+ * with %s, and it's not useful here.
+ */
+ pr->flags = F_BPAD;
+ *pr->cchar = 's';
+ for (p1 = pr->fmt; *p1 != '%'; ++p1);
+ for (p2 = ++p1; *p1 && index(spec, *p1); ++p1);
+ while ((*p2++ = *p1++) != 0) ;
+}
+
+void display()
{
extern FU *endfu;
register FS *fs;
@@ -144,9 +162,9 @@ display()
register int cnt;
register u_char *bp;
off_t saveaddress;
- u_char savech, *savebp, *get();
+ u_char savech = 0, *savebp, *get();
- while (bp = get())
+ while ((bp = get()) != NULL)
for (fs = fshead, savebp = bp, saveaddress = address; fs;
fs = fs->nextfs, bp = savebp, address = saveaddress)
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
@@ -189,23 +207,6 @@ display()
}
}
-bpad(pr)
- PR *pr;
-{
- static char *spec = " -0+#";
- register char *p1, *p2;
-
- /*
- * remove all conversion flags; '-' is the only one valid
- * with %s, and it's not useful here.
- */
- pr->flags = F_BPAD;
- *pr->cchar = 's';
- for (p1 = pr->fmt; *p1 != '%'; ++p1);
- for (p2 = ++p1; *p1 && index(spec, *p1); ++p1);
- while (*p2++ = *p1++);
-}
-
static char **_argv;
u_char *
@@ -234,7 +235,7 @@ get()
* and no other files are available, zero-pad the rest of the
* block and set the end flag.
*/
- if (!length || ateof && !next((char **)NULL)) {
+ if (!length || (ateof && !next((char **)NULL))) {
if (need == blocksize)
return((u_char *)NULL);
if (vflag != ALL && !bcmp(curp, savp, nread)) {
@@ -277,10 +278,7 @@ get()
}
}
-extern off_t skip; /* bytes to skip */
-
-next(argv)
- char **argv;
+int next(char **argv)
{
extern int errno, exitval;
static int done;
@@ -315,9 +313,8 @@ next(argv)
/* NOTREACHED */
}
-doskip(fname, statok)
- char *fname;
- int statok;
+static void
+doskip(char *fname, int statok)
{
extern int errno;
struct stat sbuf;
@@ -328,7 +325,11 @@ doskip(fname, statok)
fname, strerror(errno));
exit(1);
}
- if (skip >= sbuf.st_size) {
+ if ( ( ! (S_ISCHR(sbuf.st_mode) ||
+ S_ISBLK(sbuf.st_mode) ||
+ S_ISFIFO(sbuf.st_mode)) ) &&
+ skip >= sbuf.st_size) {
+ /* If size valid and skip >= size */
skip -= sbuf.st_size;
address += sbuf.st_size;
return;
@@ -344,8 +345,7 @@ doskip(fname, statok)
}
char *
-emalloc(size)
- int size;
+emalloc(int size)
{
char *p;
@@ -355,7 +355,7 @@ emalloc(size)
return(p);
}
-nomem()
+void nomem()
{
extern int errno;
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 4b282427a..7329d119c 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -50,11 +50,10 @@ int blocksize; /* data block size */
int exitval; /* final exit value */
int length = -1; /* max bytes to read */
-main(argc, argv)
+int main(argc, argv)
int argc;
char **argv;
{
- extern int errno;
register FS *tfs;
char *p, *rindex();
@@ -75,5 +74,5 @@ main(argc, argv)
(void)next(argv);
display();
- exit(exitval);
+ return exitval;
}
diff --git a/text-utils/hexdump.h b/text-utils/hexdump.h
index 9def76330..3ca46b910 100644
--- a/text-utils/hexdump.h
+++ b/text-utils/hexdump.h
@@ -70,7 +70,23 @@ typedef struct _fs { /* format strings */
int bcnt;
} FS;
+extern FU *endfu;
extern FS *fshead; /* head of format strings list */
extern int blocksize; /* data block size */
+extern int deprecated;
+extern off_t skip; /* bytes to skip */
enum _vflag { ALL, DUP, FIRST, WAIT }; /* -v values */
+
char *emalloc();
+int size(FS *);
+void add(char *);
+void rewrite(FS *);
+void addfile(char *);
+void display(void);
+void nomem(void);
+void usage(void);
+void conv_c(PR *, u_char *);
+void conv_u(PR *, u_char *);
+int next(char **);
+void oldsyntax(int, char ***);
+void newsyntax(int, char ***);
diff --git a/text-utils/hexsyntax.c b/text-utils/hexsyntax.c
index 3812e979e..4a6638a03 100644
--- a/text-utils/hexsyntax.c
+++ b/text-utils/hexsyntax.c
@@ -36,14 +36,14 @@ static char sccsid[] = "@(#)hexsyntax.c 5.2 (Berkeley) 5/8/90";
#endif /* not lint */
#include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
#include <stdio.h>
#include "hexdump.h"
off_t skip; /* bytes to skip */
-newsyntax(argc, argvp)
- int argc;
- char ***argvp;
+void newsyntax(int argc, char ***argvp)
{
extern enum _vflag vflag;
extern FS *fshead;
@@ -122,7 +122,7 @@ newsyntax(argc, argvp)
*argvp += optind;
}
-usage()
+void usage()
{
(void)fprintf(stderr,
"hexdump: [-bcdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n");
diff --git a/text-utils/more.c b/text-utils/more.c
index 51ddc6430..123ef06ed 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -32,21 +32,33 @@ static char sccsid[] = "@(#)more.c 5.19 (Berkeley) 6/29/88";
**
** modified by Geoff Peck, UCB to add underlining, single spacing
** modified by John Foderaro, UCB to add -c and MORE environment variable
+** modified by Erik Troan <ewt@redhat.com> to be more posix and so compile
+** on linux/axp.
+** modified by Kars de Jong <jongk@cs.utwente.nl> to use terminfo instead
+** of termcap.
*/
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
+#include <stdlib.h> /* for alloca() */
#include <sys/param.h>
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#include <termios.h>
#include <setjmp.h>
+#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/file.h>
+#include <sys/wait.h>
#include <a.out.h>
-#include <varargs.h>
-#include <termcap.h>
+#if NCH
+#include <ncurses.h>
+#else
+#include <curses.h>
+#endif
+#include <term.h>
#define HELPFILE "/usr/lib/more.help"
#define VI "/usr/bin/vi"
@@ -57,25 +69,40 @@ 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,TCSETAF,argp)
+#define stty(fd,argp) ioctl(fd,TCSETSF,argp)
/* some function declarations */
-void initterm();
+void initterm(void);
+void kill_line(void);
+void doclear(void);
+void cleareol(void);
+void clreos(void);
+void home(void);
+void error (char *mess);
+void do_shell (char *filename);
+int colon (char *filename, int cmd, int nlines);
+int expand (char *outbuf, char *inbuf);
void argscan(char *s);
+void rdline (register FILE *f);
void copy_file(register FILE *f);
-void doclear();
-void home();
void search(char buf[], FILE *file, register int n);
+void skipf (register int nskip);
void skiplns(register int n, register FILE *f);
void screen (register FILE *f, register int num_lines);
int command (char *filename, register FILE *f);
-void erase (register int col);
-void cleareol();
-void clreos();
+void erasep (register int col);
+void show (register char ch);
int pr(char *s1);
-void reset_tty();
-int getline(register FILE *f, int *length);
+int printd (int n);
+void set_tty(void);
+void reset_tty(void);
+void ttyin (char buf[], register int nmax, char pchar);
+int number(char *cmd);
+int readch (void);
+int get_line(register FILE *f, int *length);
void prbuf (register char *s, register int n);
+int xprintf (char *fmt, ...);
+void execute (char *filename, char *cmd, ...);
#define TBUFSIZ 1024
#define LINSIZ 256
@@ -84,7 +111,7 @@ void prbuf (register char *s, register int n);
#define ESC '\033'
#define QUIT '\034'
-struct termio otty, savetty;
+struct termios otty, savetty0;
long file_pos, file_size;
int fnum, no_intty, no_tty, slow_tty;
int dum_opt, dlines;
@@ -149,7 +176,7 @@ int main(int argc, char **argv) {
int initopt = 0;
int srchopt = 0;
int clearit = 0;
- int initline;
+ int initline = 0;
char initbuf[80];
FILE *checkf();
@@ -159,7 +186,7 @@ int main(int argc, char **argv) {
nscroll = Lpp/2 - 1;
if (nscroll <= 0)
nscroll = 1;
- if(s = getenv("MORE")) argscan(s);
+ if((s = getenv("MORE")) != NULL) argscan(s);
while (--nfiles > 0) {
if ((ch = (*++fnames)[0]) == '-') {
argscan(*fnames+1);
@@ -279,12 +306,12 @@ int main(int argc, char **argv) {
doclear ();
if (prnames) {
if (bad_so)
- erase (0);
+ erasep (0);
if (clreol)
cleareol ();
pr("::::::::::::::");
if (promptlen > 14)
- erase (14);
+ erasep (14);
xprintf ("\n");
if(clreol) cleareol();
xprintf("%s\n", fnames[fnum]);
@@ -425,23 +452,6 @@ magic(f, fs)
}
/*
-** A real function, for the tputs routine in termlib
-*/
-#ifdef __linux__
-int putch( int ch )
-#else
-void
-putch (ch)
-char ch;
-#endif
-{
- putchar (ch);
-#ifdef __linux__
- return 0;
-#endif
-}
-
-/*
** Print out the contents of the file f, one screenful at a time.
*/
@@ -456,7 +466,7 @@ void screen (register FILE *f, register int num_lines)
for (;;) {
while (num_lines > 0 && !Pause) {
- if ((nchars = getline (f, &length)) == EOF)
+ if ((nchars = get_line (f, &length)) == EOF)
{
if (clreol)
clreos();
@@ -466,7 +476,7 @@ void screen (register FILE *f, register int num_lines)
continue;
prev_len = length;
if (bad_so || ((Senter && *Senter == ' ') && (promptlen > 0)))
- erase (0);
+ erasep (0);
/* must clear before drawing line since tabs on some terminals
* do not erase what they tab over.
*/
@@ -474,7 +484,7 @@ void screen (register FILE *f, register int num_lines)
cleareol ();
prbuf (Line, length);
if (nchars < promptlen)
- erase (nchars); /* erase () sets promptlen to 0 */
+ erasep (nchars); /* erasep () sets promptlen to 0 */
else promptlen = 0;
/* is this needed?
* if (clreol)
@@ -487,7 +497,7 @@ void screen (register FILE *f, register int num_lines)
num_lines--;
}
if (pstate) {
- tputs(ULexit, 1, putch);
+ putp (ULexit);
pstate = 0;
}
fflush(stdout);
@@ -506,7 +516,7 @@ void screen (register FILE *f, register int num_lines)
if ((num_lines = command (NULL, f)) == 0)
return;
if (hard && promptlen > 0)
- erase (0);
+ erasep (0);
if (noscroll && num_lines >= dlines)
{
if (clreol)
@@ -599,16 +609,14 @@ void copy_file(register FILE *f) {
/* Simplified printf function */
-int xprintf (fmt, va_alist)
-register char *fmt;
-va_dcl
+int xprintf (char *fmt, ...)
{
va_list ap;
register char ch;
register int ccount;
ccount = 0;
- va_start(ap);
+ va_start(ap, fmt);
while (*fmt) {
while ((ch = *fmt++) != '%') {
if (ch == '\0')
@@ -643,12 +651,11 @@ va_dcl
** returning the length of the print representation.
*/
-printd (n)
-int n;
+int printd (int n)
{
int a, nchars;
- if (a = n/10)
+ if ((a = n/10) != 0)
nchars = 1 + printd(a);
else
nchars = 1;
@@ -659,25 +666,22 @@ int n;
/* Put the print representation of an integer into a string */
static char *sptr;
-scanstr (n, str)
-int n;
-char *str;
-{
- sptr = str;
- Sprintf (n);
- *sptr = '\0';
-}
-
-Sprintf (n)
-{
+void Sprintf (int n) {
int a;
- if (a = n/10)
+ if ((a = n/10) != 0)
Sprintf (a);
*sptr++ = n % 10 + '0';
}
-static char bell = ctrl('G');
+void scanstr (int n, char *str)
+{
+ sptr = str;
+ Sprintf (n);
+ *sptr = '\0';
+}
+
+static char my_bell = ctrl('G');
#ifdef undef
strlen (s)
@@ -696,7 +700,7 @@ char *s;
** string "string"
*/
-tailequ (path, string)
+int tailequ (path, string)
char *path;
register char *string;
{
@@ -713,7 +717,7 @@ register char *string;
return(0);
}
-prompt (filename)
+void prompt (filename)
char *filename;
{
if (clreol)
@@ -723,7 +727,7 @@ char *filename;
if (!hard) {
promptlen = 8;
if (Senter && Sexit) {
- tputs (Senter, 1, putch);
+ putp (Senter);
promptlen += (2 * soglitch);
}
if (clreol)
@@ -739,13 +743,13 @@ char *filename;
promptlen += pr("[Press space to continue, 'q' to quit.]");
}
if (Senter && Sexit)
- tputs (Sexit, 1, putch);
+ putp (Sexit);
if (clreol)
clreos ();
fflush(stdout);
}
else
- write (2, &bell, 1);
+ write (2, &my_bell, 1);
inwait++;
}
@@ -753,7 +757,7 @@ char *filename;
** Get a logical line
*/
-int getline(register FILE *f, int *length)
+int get_line(register FILE *f, int *length)
{
register int c;
register char *p;
@@ -783,10 +787,10 @@ int getline(register FILE *f, int *length)
}
*p++ = c;
if (c == '\t')
- if (!hardtabs || column < promptlen && !hard) {
+ if (!hardtabs || (column < promptlen && !hard)) {
if (hardtabs && eraseln && !dumb) {
column = 1 + (column | 7);
- tputs (eraseln, 1, putch);
+ putp (eraseln);
promptlen = 0;
}
else {
@@ -837,7 +841,7 @@ int getline(register FILE *f, int *length)
** Erase the rest of the prompt, assuming we are starting at column col.
*/
-void erase (register int col)
+void erasep (register int col)
{
if (promptlen == 0)
@@ -849,7 +853,7 @@ void erase (register int col)
if (col == 0)
putchar ('\r');
if (!dumb && eraseln)
- tputs (eraseln, 1, putch);
+ putp (eraseln);
else
for (col = promptlen - col; col > 0; col--)
putchar (' ');
@@ -861,10 +865,11 @@ void erase (register int col)
** Erase the current line entirely
*/
-kill_line ()
+void kill_line ()
{
- erase (0);
- if (!eraseln || dumb) putchar ('\r');
+ erasep (0);
+ if (!eraseln || dumb)
+ putchar ('\r');
}
/*
@@ -872,12 +877,12 @@ kill_line ()
*/
void cleareol()
{
- tputs(eraseln, 1, putch);
+ putp(eraseln);
}
void clreos()
{
- tputs(EodClr, 1, putch);
+ putp(EodClr);
}
/*
@@ -889,7 +894,7 @@ int pr(char *s1)
register char *s;
register char c;
- for (s = s1; c = *s++; )
+ for (s = s1; (c = *s++) != 0; )
putchar(c);
return (int) (s - s1 - 1);
}
@@ -911,7 +916,7 @@ void prbuf (register char *s, register int n)
s++;
continue;
}
- if (state = wouldul(s, n)) {
+ if ((state = wouldul(s, n)) != 0) {
c = (*s == '_')? s[2] : *s ;
n -= 2;
s += 3;
@@ -921,13 +926,13 @@ void prbuf (register char *s, register int n)
if (c == ' ' && state == 0 && ulglitch && wouldul(s, n-1))
state = 1;
else
- tputs(state ? ULenter : ULexit, 1, putch);
+ putp(state ? ULenter : ULexit);
}
if (c != ' ' || pstate == 0 || state != 0 || ulglitch == 0)
putchar(c);
if (state && *chUL) {
pr(chBS);
- tputs(chUL, 1, putch);
+ putp(chUL);
}
pstate = state;
}
@@ -940,7 +945,7 @@ void
doclear()
{
if (Clear && !hard) {
- tputs(Clear, 1, putch);
+ putp(Clear);
/* Put out carriage return so that system doesn't
** get confused by escape sequences when expanding tabs
@@ -956,7 +961,7 @@ doclear()
void
home()
{
- tputs(Home,1,putch);
+ putp(Home);
}
static int lastcmd, lastarg, lastp;
@@ -973,12 +978,12 @@ char shell_line[132];
int command (char *filename, register FILE *f)
{
register int nlines;
- register int retval;
+ register int retval = 0;
register char c;
char colonch;
FILE *helpf;
int done;
- char comchar, cmdbuf[80], *p;
+ char comchar, cmdbuf[80];
#define ret(val) retval=val;done++;break
@@ -1016,14 +1021,14 @@ int command (char *filename, register FILE *f)
register int initline;
if (no_intty) {
- write(2, &bell, 1);
+ write(2, &my_bell, 1);
return (-1);
}
if (nlines == 0) nlines++;
putchar ('\r');
- erase (0);
+ erasep (0);
xprintf ("\n");
if (clreol)
cleareol ();
@@ -1069,7 +1074,7 @@ int command (char *filename, register FILE *f)
if (comchar == 'f')
nlines *= dlines;
putchar ('\r');
- erase (0);
+ erasep (0);
xprintf ("\n");
if (clreol)
cleareol ();
@@ -1108,7 +1113,7 @@ int command (char *filename, register FILE *f)
ret (dlines);
}
else {
- write (2, &bell, 1);
+ write (2, &my_bell, 1);
break;
}
case '\'':
@@ -1120,7 +1125,7 @@ int command (char *filename, register FILE *f)
ret (dlines);
}
else {
- write (2, &bell, 1);
+ write (2, &my_bell, 1);
break;
}
case '=':
@@ -1141,7 +1146,7 @@ int command (char *filename, register FILE *f)
search (NULL, f, nlines); /* Use previous r.e. */
}
else {
- ttyin (cmdbuf, 78, '/');
+ ttyin (cmdbuf, sizeof(cmdbuf)-2, '/');
write (2, "\r", 1);
search (cmdbuf, f, nlines);
}
@@ -1172,16 +1177,16 @@ int command (char *filename, register FILE *f)
if (dum_opt) {
kill_line ();
if (Senter && Sexit) {
- tputs (Senter, 1, putch);
+ putp (Senter);
promptlen = pr ("[Press 'h' for instructions.]") + (2 * soglitch);
- tputs (Sexit, 1, putch);
+ putp (Sexit);
}
else
promptlen = pr ("[Press 'h' for instructions.]");
fflush (stdout);
}
else
- write (2, &bell, 1);
+ write (2, &my_bell, 1);
break;
}
if (done) break;
@@ -1201,10 +1206,7 @@ char ch;
* more of the file to be printed.
*/
-colon (filename, cmd, nlines)
-char *filename;
-int cmd;
-int nlines;
+int colon (char *filename, int cmd, int nlines)
{
if (cmd == 0)
ch = readch ();
@@ -1227,16 +1229,16 @@ int nlines;
nlines++;
}
putchar ('\r');
- erase (0);
+ erasep (0);
skipf (nlines);
return (0);
case 'p':
if (no_intty) {
- write (2, &bell, 1);
+ write (2, &my_bell, 1);
return (-1);
}
putchar ('\r');
- erase (0);
+ erasep (0);
if (nlines == 0)
nlines++;
skipf (-nlines);
@@ -1248,7 +1250,7 @@ int nlines;
case 'Q':
end_it ();
default:
- write (2, &bell, 1);
+ write (2, &my_bell, 1);
return (-1);
}
}
@@ -1258,8 +1260,7 @@ int nlines;
** terminates the number.
*/
-number(cmd)
-char *cmd;
+int number(char *cmd)
{
register int i;
@@ -1278,8 +1279,7 @@ char *cmd;
return (i);
}
-do_shell (filename)
-char *filename;
+void do_shell (char *filename)
{
char cmdbuf[80];
@@ -1290,7 +1290,7 @@ char *filename;
if (lastp)
pr (shell_line);
else {
- ttyin (cmdbuf, 78, '!');
+ ttyin (cmdbuf, sizeof(cmdbuf)-2, '!');
if (expand (shell_line, cmdbuf)) {
kill_line ();
promptlen = xprintf ("!%s", shell_line);
@@ -1383,14 +1383,14 @@ void search(char buf[], FILE *file, register int n)
}
/*VARARGS2*/
-execute (filename, cmd, va_alist)
-char *filename;
-char *cmd;
-va_dcl
+void execute (char * filename, char * cmd, ...)
{
int id;
int n;
va_list argp;
+ char * arg;
+ char ** args;
+ int argcount;
fflush (stdout);
reset_tty ();
@@ -1401,11 +1401,33 @@ va_dcl
close(0);
open("/dev/tty", 0);
}
- va_start(argp);
- execv (cmd, argp);
+
+ va_start(argp, cmd);
+
+ arg = va_arg(argp, char *);
+ argcount = 0;
+ while (arg) {
+ argcount++;
+ arg = va_arg(argp, char *);
+ }
+ va_end(argp); /* balance {}'s for some UNIX's */
+
+ args = alloca(sizeof(char *) * (argcount + 1));
+ args[argcount] = NULL;
+
+ va_start(argp, cmd);
+ arg = va_arg(argp, char *);
+ argcount = 0;
+ while (arg) {
+ args[argcount] = arg;
+ argcount++;
+ arg = va_arg(argp, char *);
+ }
+ va_end(argp); /* balance {}'s for some UNIX's */
+
+ execv (cmd, args);
write (2, "exec failed\n", 12);
exit (1);
- va_end(argp); /* balance {}'s for some UNIX's */
}
if (id > 0) {
signal (SIGINT, SIG_IGN);
@@ -1445,8 +1467,7 @@ void skiplns (register int n, register FILE *f)
** negative.
*/
-skipf (nskip)
-register int nskip;
+void skipf (register int nskip)
{
if (nskip == 0) return;
if (nskip > 0) {
@@ -1476,70 +1497,74 @@ register int nskip;
void initterm()
{
- char buf[TBUFSIZ];
- static char clearbuf[TBUFSIZ];
- char *clearptr, *padstr;
- int ldisc;
- int lmode;
+ int ret;
+ char *padstr;
char *term;
- int tgrp;
struct winsize win;
+#ifdef do_SIGTTOU
retry:
- no_tty = ioctl(fileno(stdout), TCGETA, &otty);
+#endif
+ no_tty = ioctl(fileno(stdout), TCGETS, &otty);
if (!no_tty) {
docrterase = (otty.c_cc[VERASE] != 255);
docrtkill = (otty.c_cc[VKILL] != 255);
-#ifdef undef
- /*
- * Wait until we're in the foreground before we save the
- * the terminal modes.
- */
- if (ioctl(fileno(stdout), TIOCGPGRP, &tgrp) < 0) {
- perror("TIOCGPGRP");
- exit(1);
- }
- if (tgrp != getpgrp(0)) {
- kill(0, SIGTTOU);
- goto retry;
+#ifdef do_SIGTTOU
+ {
+ int tgrp;
+ /*
+ * Wait until we're in the foreground before we save the
+ * the terminal modes.
+ */
+ if (ioctl(fileno(stdout), TIOCGPGRP, &tgrp) < 0) {
+ perror("TIOCGPGRP");
+ exit(1);
+ }
+ if (tgrp != getpgrp(0)) {
+ kill(0, SIGTTOU);
+ goto retry;
+ }
}
#endif
- if ((term = getenv("TERM")) == 0 || tgetent(buf, term) <= 0) {
+ if ((term = getenv("TERM")) == 0) {
+ dumb++; ul_opt = 0;
+ }
+ setupterm(term, 1, &ret);
+ if (ret <= 0) {
dumb++; ul_opt = 0;
}
else {
#ifdef TIOCGWINSZ
if (ioctl(fileno(stdout), TIOCGWINSZ, &win) < 0) {
#endif
- Lpp = tgetnum("li");
- Mcol = tgetnum("co");
+ Lpp = tigetnum("lines");
+ Mcol = tigetnum("cols");
#ifdef TIOCGWINSZ
} else {
if ((Lpp = win.ws_row) == 0)
- Lpp = tgetnum("li");
+ Lpp = tigetnum("lines");
if ((Mcol = win.ws_col) == 0)
- Mcol = tgetnum("co");
+ Mcol = tigetnum("cols");
}
#endif
- if ((Lpp <= 0) || tgetflag("hc")) {
+ if ((Lpp <= 0) || tigetflag("hc")) {
hard++; /* Hard copy terminal */
Lpp = 24;
}
- if (tgetflag("xn"))
+ if (tigetflag("xenl"))
eatnl++; /* Eat newline at last column + 1; dec, concept */
if (Mcol <= 0)
Mcol = 80;
- if (tailequ (fnames[0], "page") || !hard && tgetflag("ns"))
+ if (tailequ (fnames[0], "page"))
noscroll++;
- Wrap = tgetflag("am");
- bad_so = tgetflag ("xs");
- clearptr = clearbuf;
- eraseln = tgetstr("ce",&clearptr);
- Clear = tgetstr("cl", &clearptr);
- Senter = tgetstr("so", &clearptr);
- Sexit = tgetstr("se", &clearptr);
- if ((soglitch = tgetnum("sg")) < 0)
+ Wrap = tigetflag("am");
+ bad_so = tigetflag ("xhp");
+ eraseln = tigetstr("el");
+ Clear = tigetstr("clear");
+ Senter = tigetstr("smso");
+ Sexit = tigetstr("rmso");
+ if ((soglitch = tigetnum("xmc")) < 0)
soglitch = 0;
/*
@@ -1550,50 +1575,49 @@ retry:
* isn't available, settle for standout sequence.
*/
- if (tgetflag("ul") || tgetflag("os"))
+ if (tigetflag("ul") || tigetflag("os"))
ul_opt = 0;
- if ((chUL = tgetstr("uc", &clearptr)) == NULL )
+ if ((chUL = tigetstr("uc")) == NULL )
chUL = "";
- if (((ULenter = tgetstr("us", &clearptr)) == NULL ||
- (ULexit = tgetstr("ue", &clearptr)) == NULL) && !*chUL) {
+ if (((ULenter = tigetstr("smul")) == NULL ||
+ (ULexit = tigetstr("rmul")) == NULL) && !*chUL) {
if ((ULenter = Senter) == NULL || (ULexit = Sexit) == NULL) {
ULenter = "";
ULexit = "";
} else
ulglitch = soglitch;
} else {
- if ((ulglitch = tgetnum("ug")) < 0)
- ulglitch = 0;
+ ulglitch = 0;
}
- if (padstr = tgetstr("pc", &clearptr))
+ if ((padstr = tigetstr("pad")) != NULL)
PC = *padstr;
- Home = tgetstr("ho",&clearptr);
+ Home = tigetstr("home");
if (Home == 0 || *Home == '\0')
{
- if ((cursorm = tgetstr("cm", &clearptr)) != NULL) {
- strcpy(cursorhome, tgoto(cursorm, 0, 0));
+ if ((cursorm = tigetstr("cup")) != NULL) {
+ strcpy(cursorhome, (const char *)tparm(cursorm, 0, 0));
Home = cursorhome;
}
}
- EodClr = tgetstr("cd", &clearptr);
- if ((chBS = tgetstr("bc", &clearptr)) == NULL)
+ EodClr = tigetstr("ed");
+ if ((chBS = tigetstr("cub1")) == NULL)
chBS = "\b";
}
if ((shell = getenv("SHELL")) == NULL)
shell = "/bin/sh";
}
- no_intty = ioctl(fileno(stdin), TCGETA, &otty);
- ioctl(fileno(stderr), TCGETA, &otty);
- savetty = otty;
+ no_intty = ioctl(fileno(stdin), TCGETS, &otty);
+ ioctl(fileno(stderr), TCGETS, &otty);
+ savetty0 = otty;
slow_tty = (otty.c_cflag & CBAUD) < B1200;
hardtabs = (otty.c_oflag & TABDLY) != XTABS;
if (!no_tty)
otty.c_lflag &= ~(ICANON|ECHO);
}
-readch ()
+int readch ()
{
char ch;
extern int errno;
@@ -1616,10 +1640,7 @@ static char CARAT = '^';
else \
write (2, &BS, sizeof(BS));
-ttyin (buf, nmax, pchar)
-char buf[];
-register int nmax;
-char pchar;
+void ttyin (char buf[], register int nmax, char pchar)
{
register char *sptr;
register char ch;
@@ -1661,7 +1682,7 @@ char pchar;
putchar ('\r');
putchar (pchar);
if (eraseln)
- erase (1);
+ erasep (1);
else if (docrtkill)
while (promptlen-- > 1)
write (2, BSB, sizeof(BSB));
@@ -1697,9 +1718,7 @@ char pchar;
error ("Line too long");
}
-expand (outbuf, inbuf)
-char *outbuf;
-char *inbuf;
+int expand (char *outbuf, char *inbuf)
{
register char *instr;
register char *outstr;
@@ -1740,8 +1759,7 @@ char *inbuf;
return (changed);
}
-show (ch)
-register char ch;
+void show (register char ch)
{
char cbuf;
@@ -1755,8 +1773,7 @@ register char ch;
promptlen++;
}
-error (mess)
-char *mess;
+void error (char *mess)
{
if (clreol)
cleareol ();
@@ -1764,9 +1781,9 @@ char *mess;
kill_line ();
promptlen += strlen (mess);
if (Senter && Sexit) {
- tputs (Senter, 1, putch);
+ putp (Senter);
pr(mess);
- tputs (Sexit, 1, putch);
+ putp (Sexit);
}
else
pr (mess);
@@ -1776,27 +1793,30 @@ char *mess;
}
-set_tty ()
+void set_tty ()
{
otty.c_lflag &= ~(ICANON|ECHO);
stty(fileno(stderr), &otty);
}
+int ourputch(int ch) {
+ return putc(ch, stdout);
+}
+
void reset_tty ()
{
if (no_tty)
return;
if (pstate) {
- tputs(ULexit, 1, putch);
+ tputs(ULexit, 1, ourputch);
fflush(stdout);
pstate = 0;
}
otty.c_lflag |= ICANON|ECHO;
- stty(fileno(stderr), &savetty);
+ stty(fileno(stderr), &savetty0);
}
-rdline (f)
-register FILE *f;
+void rdline (register FILE *f)
{
register char c;
register char *p;
diff --git a/text-utils/odsyntax.c b/text-utils/odsyntax.c
index 2dd5a2a26..120928bf3 100644
--- a/text-utils/odsyntax.c
+++ b/text-utils/odsyntax.c
@@ -38,18 +38,20 @@ static char sccsid[] = "@(#)odsyntax.c 5.4 (Berkeley) 3/8/91";
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
+#include <ctype.h> /* for isdigit() */
+#include <unistd.h> /* for getopt() */
#include "hexdump.h"
+static void odoffset(int, char ***);
+
int deprecated;
-oldsyntax(argc, argvp)
- int argc;
- char ***argvp;
+void
+oldsyntax(int argc, char ***argvp)
{
extern enum _vflag vflag;
extern FS *fshead;
- extern char *optarg;
- extern int length, optind;
+ extern int optind;
int ch;
char **argv;
static void odprecede();
@@ -147,11 +149,10 @@ oldsyntax(argc, argvp)
}
#define ishexdigit(c) \
- (c >= '0' && c <= '9' || c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F')
+ ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))
-odoffset(argc, argvp)
- int argc;
- char ***argvp;
+static void
+odoffset(int argc, char ***argvp)
{
extern off_t skip;
register char *num, *p;
diff --git a/text-utils/parse.c b/text-utils/parse.c
index e0d982e1a..272809826 100644
--- a/text-utils/parse.c
+++ b/text-utils/parse.c
@@ -43,10 +43,15 @@ static char sccsid[] = "@(#)parse.c 5.6 (Berkeley) 3/9/91";
#include <string.h>
#include "hexdump.h"
+static void escape(register char *p1);
+static void badcnt(char *s);
+static void badsfmt(void);
+static void badfmt(char *fmt);
+static void badconv(char *ch);
+
FU *endfu; /* format at end-of-data */
-addfile(name)
- char *name;
+void addfile(char *name)
{
register char *p;
FILE *fp;
@@ -72,8 +77,7 @@ addfile(name)
(void)fclose(fp);
}
-add(fmt)
- char *fmt;
+void add(char *fmt)
{
register char *p;
static FS **nextfs;
@@ -147,8 +151,8 @@ add(fmt)
}
static char *spec = ".#-+ 0123456789";
-size(fs)
- FS *fs;
+
+int size(FS *fs)
{
register FU *fu;
register int bcnt, cursize;
@@ -200,15 +204,14 @@ size(fs)
return(cursize);
}
-rewrite(fs)
- FS *fs;
+void rewrite(FS *fs)
{
enum { NOTOKAY, USEBCNT, USEPREC } sokay;
- register PR *pr, **nextpr;
+ register PR *pr, **nextpr = NULL;
register FU *fu;
register char *p1, *p2;
char savech, *fmtp;
- int nconv, prec;
+ int nconv, prec = 0;
for (fu = fs->nextfu; fu; fu = fu->nextfu) {
/*
@@ -439,8 +442,7 @@ sw2: switch(fu->bcnt) {
}
-escape(p1)
- register char *p1;
+static void escape(register char *p1)
{
register char *p2;
@@ -481,30 +483,27 @@ escape(p1)
}
}
-badcnt(s)
- char *s;
+static void badcnt(char *s)
{
(void)fprintf(stderr,
"hexdump: bad byte count for conversion character %s.\n", s);
exit(1);
}
-badsfmt()
+static void badsfmt()
{
(void)fprintf(stderr,
"hexdump: %%s requires a precision or a byte count.\n");
exit(1);
}
-badfmt(fmt)
- char *fmt;
+static void badfmt(char *fmt)
{
(void)fprintf(stderr, "hexdump: bad format {%s}\n", fmt);
exit(1);
}
-badconv(ch)
- char *ch;
+static void badconv(char *ch)
{
(void)fprintf(stderr, "hexdump: bad conversion character %%%s.\n", ch);
exit(1);
diff --git a/text-utils/rev.c b/text-utils/rev.c
index 1cede0bc3..3b4e42104 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -45,7 +45,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)rev.c 5.2 (Berkeley) 3/21/92";*/
-static char rcsid[] = "$Id: rev.c,v 1.3 1995/10/07 01:32:14 faith Exp $";
+static char rcsid[] = "$Id: rev.c,v 1.4 1996/07/02 20:08:07 janl Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -53,7 +53,7 @@ static char rcsid[] = "$Id: rev.c,v 1.3 1995/10/07 01:32:14 faith Exp $";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef linux
+#ifdef __linux__
#include <unistd.h>
#endif /* linux */
@@ -66,7 +66,7 @@ main(argc, argv)
char *argv[];
{
register char *filename, *t;
-#ifdef linux
+#ifdef __linux__
char p[512];
#else /* linux */
char *p;
@@ -98,7 +98,7 @@ main(argc, argv)
}
filename = *argv++;
}
-#ifndef linux
+#ifndef __linux__
while (p = fgetline(fp, &len)) {
t = p + len - 1;
for (t = p + len - 1; t >= p; --t)
diff --git a/text-utils/ul.1 b/text-utils/ul.1
index 701797ae4..9bd4e8ee3 100644
--- a/text-utils/ul.1
+++ b/text-utils/ul.1
@@ -49,9 +49,9 @@ and translates occurrences of underscores to the sequence
which indicates underlining for the terminal in use, as specified
by the environment variable
.Ev TERM .
-The file
-.Pa /etc/termcap
-is read to determine the appropriate sequences for underlining.
+The
+.Pa terminfo
+database is read to determine the appropriate sequences for underlining.
If the terminal is incapable of underlining, but is capable of
a standout mode then that is used instead.
If the terminal can overstrike,
@@ -81,7 +81,7 @@ The
.Ev TERM
variable is used to relate a tty device
with its device capability description (see
-.Xr termcap 5 ) .
+.Xr terminfo 5 ) .
.Ev TERM
is set at login time, either by the default terminal type
specified in
diff --git a/text-utils/ul.c b/text-utils/ul.c
index 75e6f95cb..4d3cf262e 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -41,7 +41,26 @@ static char copyright[] =
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.
+*/
+
#include <stdio.h>
+#include <unistd.h> /* for getopt(), isatty() */
+#include <string.h> /* for bzero() */
+#include <term.h> /* for setupterm() */
+
+void filter(FILE *f);
+void flushln(void);
+void overstrike(void);
+void iattr(void);
+void initbuf(void);
+void fwd(void);
+void reverse(void);
+void initinfo(void);
+void outc(int c);
+void setmode(int newmode);
#define IESC '\033'
#define SO '\016'
@@ -75,19 +94,15 @@ int halfpos;
int upln;
int iflag;
-int outchar();
-#define PRINT(s) if (s == NULL) /* void */; else tputs(s, 1, outchar)
+#define PRINT(s) if (s == NULL) /* void */; else putp(s)
-main(argc, argv)
- int argc;
- char **argv;
+int main(int argc, char **argv)
{
extern int optind;
extern char *optarg;
- int c;
+ int c, ret;
char *termtype;
FILE *f;
- char termcap[1024];
char *getenv(), *strcpy();
termtype = getenv("TERM");
@@ -110,24 +125,24 @@ main(argc, argv)
argv[0]);
exit(1);
}
-
- switch(tgetent(termcap, termtype)) {
+ setupterm(termtype, 1, &ret);
+ switch(ret) {
case 1:
break;
default:
- fprintf(stderr,"trouble reading termcap");
+ fprintf(stderr,"trouble reading terminfo");
/* fall through to ... */
case 0:
/* No such terminal type - assume dumb */
- (void)strcpy(termcap, "dumb:os:col#80:cr=^M:sf=^J:am:");
+ setupterm("dumb", 1, (int *)0);
break;
}
- initcap();
- if ( (tgetflag("os") && ENTER_BOLD==NULL ) ||
- (tgetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL))
+ initinfo();
+ if ( (tigetflag("os") && ENTER_BOLD==NULL ) ||
+ (tigetflag("ul") && ENTER_UNDERLINE==NULL && UNDER_CHAR==NULL))
must_overstrike = 1;
initbuf();
if (optind == argc)
@@ -140,11 +155,10 @@ main(argc, argv)
} else
filter(f);
}
- exit(0);
+ return 0;
}
-filter(f)
- FILE *f;
+void filter(FILE *f)
{
register c;
@@ -256,7 +270,7 @@ filter(f)
flushln();
}
-flushln()
+void flushln()
{
register lastmode;
register i;
@@ -295,7 +309,7 @@ flushln()
* For terminals that can overstrike, overstrike underlines and bolds.
* We don't do anything with halfline ups and downs, or Greek.
*/
-overstrike()
+void overstrike()
{
register int i;
char lbuf[256];
@@ -332,7 +346,7 @@ overstrike()
}
}
-iattr()
+void iattr()
{
register int i;
char lbuf[256];
@@ -355,7 +369,7 @@ iattr()
putchar('\n');
}
-initbuf()
+void initbuf()
{
bzero((char *)obuf, sizeof (obuf)); /* depends on NORMAL == 0 */
@@ -364,7 +378,7 @@ initbuf()
mode &= ALTSET;
}
-fwd()
+void fwd()
{
register oldcol, oldmax;
@@ -375,7 +389,7 @@ fwd()
maxcol = oldmax;
}
-reverse()
+void reverse()
{
upln++;
fwd();
@@ -384,31 +398,24 @@ reverse()
upln++;
}
-initcap()
+void initinfo()
{
- static char tcapbuf[512];
- char *bp = tcapbuf;
- char *getenv(), *tgetstr();
-
- /* This nonsense attempts to work with both old and new termcap */
- CURS_UP = tgetstr("up", &bp);
- CURS_RIGHT = tgetstr("ri", &bp);
- if (CURS_RIGHT == NULL)
- CURS_RIGHT = tgetstr("nd", &bp);
- CURS_LEFT = tgetstr("le", &bp);
+ char *getenv(), *tigetstr();
+
+ CURS_UP = tigetstr("cuu1");
+ CURS_RIGHT = tigetstr("cuf1");
+ CURS_LEFT = tigetstr("cub1");
if (CURS_LEFT == NULL)
- CURS_LEFT = tgetstr("bc", &bp);
- if (CURS_LEFT == NULL && tgetflag("bs"))
CURS_LEFT = "\b";
- ENTER_STANDOUT = tgetstr("so", &bp);
- EXIT_STANDOUT = tgetstr("se", &bp);
- ENTER_UNDERLINE = tgetstr("us", &bp);
- EXIT_UNDERLINE = tgetstr("ue", &bp);
- ENTER_DIM = tgetstr("mh", &bp);
- ENTER_BOLD = tgetstr("md", &bp);
- ENTER_REVERSE = tgetstr("mr", &bp);
- EXIT_ATTRIBUTES = tgetstr("me", &bp);
+ ENTER_STANDOUT = tigetstr("smso");
+ EXIT_STANDOUT = tigetstr("rmso");
+ ENTER_UNDERLINE = tigetstr("smul");
+ EXIT_UNDERLINE = tigetstr("rmul");
+ ENTER_DIM = tigetstr("dim");
+ ENTER_BOLD = tigetstr("bold");
+ ENTER_REVERSE = tigetstr("rev");
+ EXIT_ATTRIBUTES = tigetstr("sgr0");
if (!ENTER_BOLD && ENTER_REVERSE)
ENTER_BOLD = ENTER_REVERSE;
@@ -433,20 +440,13 @@ initcap()
* letters the 37 has.
*/
- UNDER_CHAR = tgetstr("uc", &bp);
+ UNDER_CHAR = tigetstr("uc");
must_use_uc = (UNDER_CHAR && !ENTER_UNDERLINE);
}
-outchar(c)
- int c;
-{
- putchar(c & 0177);
-}
-
static int curmode = 0;
-outc(c)
- int c;
+void outc(int c)
{
putchar(c);
if (must_use_uc && (curmode&UNDERL)) {
@@ -455,8 +455,7 @@ outc(c)
}
}
-setmode(newmode)
- int newmode;
+void setmode(int newmode)
{
if (!iflag) {
if (curmode != NORMAL && newmode != NORMAL)