From 236d2f558312262d86504309292a2358283f626c Mon Sep 17 00:00:00 2001 From: Philippe Charnier Date: Fri, 8 Aug 1997 12:24:49 +0000 Subject: [PATCH] Add usage(). Use err(3) instead of local redefinition. --- usr.bin/script/script.1 | 6 ++--- usr.bin/script/script.c | 60 +++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 42 deletions(-) diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1 index deda037af052..7c1032f0509f 100644 --- a/usr.bin/script/script.1 +++ b/usr.bin/script/script.1 @@ -38,7 +38,7 @@ .Nm script .Nd make typescript of terminal session .Sh SYNOPSIS -.Nm script +.Nm .Op Fl a .Op Ar file .Sh DESCRIPTION @@ -99,7 +99,7 @@ The following environment variable is utilized by If the variable .Ev SHELL exists, the shell forked by -.Nm script +.Nm will be that shell. If .Ev SHELL is not set, the Bourne shell @@ -112,7 +112,7 @@ is assumed. (Most shells set this variable automatically). mechanism). .Sh HISTORY The -.Nm script +.Nm command appeared in .Bx 3.0 . .Sh BUGS diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 6c9ed08f6c22..5952a9b64e6c 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -32,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1980, 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include @@ -47,8 +51,9 @@ static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93"; #include #include -#include +#include #include +#include #include #include #include @@ -68,10 +73,10 @@ struct termios tt; void done __P((void)) __dead2; void dooutput __P((void)); void doshell __P((void)); -void err __P((const char *, ...)); void fail __P((void)); void finish __P((int)); void scriptflush __P((int)); +static void usage __P((void)); int main(argc, argv) @@ -92,8 +97,7 @@ main(argc, argv) break; case '?': default: - (void)fprintf(stderr, "usage: script [-a] [file]\n"); - exit(1); + usage(); } argc -= optind; argv += optind; @@ -104,12 +108,12 @@ main(argc, argv) fname = "typescript"; if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) - err("%s: %s", fname, strerror(errno)); + err(1, "%s", fname); (void)tcgetattr(STDIN_FILENO, &tt); (void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win); if (openpty(&master, &slave, NULL, &tt, &win) == -1) - err("openpty: %s", strerror(errno)); + err(1, "openpty"); (void)printf("Script started, output file is %s\n", fname); rtt = tt; @@ -120,13 +124,13 @@ main(argc, argv) (void)signal(SIGCHLD, finish); child = fork(); if (child < 0) { - perror("fork"); + warn("fork"); fail(); } if (child == 0) { subchild = child = fork(); if (child < 0) { - perror("fork"); + warn("fork"); fail(); } if (child) @@ -141,6 +145,13 @@ main(argc, argv) done(); } +static void +usage() +{ + (void)fprintf(stderr, "usage: script [-a] [file]\n"); + exit(1); +} + void finish(signo) int signo; @@ -208,7 +219,7 @@ doshell() (void)fclose(fscript); login_tty(slave); execl(shell, "sh", "-i", NULL); - perror(shell); + warn(shell); fail(); } @@ -236,32 +247,3 @@ done() } exit(0); } - -#if __STDC__ -#include -#else -#include -#endif - -void -#if __STDC__ -err(const char *fmt, ...) -#else -err(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "script: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - exit(1); - /* NOTREACHED */ -}