summaryrefslogtreecommitdiff
path: root/usr.bin/talk
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-08-18 04:02:27 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-08-18 04:02:27 +0000
commit0fdee9fc4c513111890cb276e3050734c0e8b8c9 (patch)
tree5cab468ea847a2637773683e95a786710b7383b8 /usr.bin/talk
parent8a60a215e4534c61e81ad6fe5e0b4833e1664a95 (diff)
Some changes inspired by FreeBSD...
o Kill annoying spaces at the end of lines o sigaction, not sigvec o warn/err where sensible o hstrerror() not herror() o defaults for erase, kill, and werase if not set o kill a needless refresh() after the beeps that was messing up the screen
Diffstat (limited to 'usr.bin/talk')
-rw-r--r--usr.bin/talk/ctl.c6
-rw-r--r--usr.bin/talk/ctl_transact.c6
-rw-r--r--usr.bin/talk/get_addrs.c26
-rw-r--r--usr.bin/talk/get_names.c20
-rw-r--r--usr.bin/talk/init_disp.c31
-rw-r--r--usr.bin/talk/invite.c12
-rw-r--r--usr.bin/talk/io.c13
-rw-r--r--usr.bin/talk/look_up.c10
-rw-r--r--usr.bin/talk/msgs.c6
-rw-r--r--usr.bin/talk/talk.c10
-rw-r--r--usr.bin/talk/talk.h3
11 files changed, 64 insertions, 79 deletions
diff --git a/usr.bin/talk/ctl.c b/usr.bin/talk/ctl.c
index dda08855694..2ef77d20f1d 100644
--- a/usr.bin/talk/ctl.c
+++ b/usr.bin/talk/ctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ctl.c,v 1.3 1998/04/28 22:13:20 pjanzen Exp $ */
+/* $OpenBSD: ctl.c,v 1.4 1998/08/18 04:02:09 millert Exp $ */
/* $NetBSD: ctl.c,v 1.3 1994/12/09 02:14:10 jtc Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ctl.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: ctl.c,v 1.3 1998/04/28 22:13:20 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: ctl.c,v 1.4 1998/08/18 04:02:09 millert Exp $";
#endif /* not lint */
/*
@@ -86,7 +86,7 @@ open_sockt()
/* open the ctl socket */
void
-open_ctl()
+open_ctl()
{
int length;
diff --git a/usr.bin/talk/ctl_transact.c b/usr.bin/talk/ctl_transact.c
index a2dc4607fb5..6fb08f5709c 100644
--- a/usr.bin/talk/ctl_transact.c
+++ b/usr.bin/talk/ctl_transact.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ctl_transact.c,v 1.4 1998/04/28 22:13:21 pjanzen Exp $ */
+/* $OpenBSD: ctl_transact.c,v 1.5 1998/08/18 04:02:10 millert Exp $ */
/* $NetBSD: ctl_transact.c,v 1.3 1994/12/09 02:14:12 jtc Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ctl_transact.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: ctl_transact.c,v 1.4 1998/04/28 22:13:21 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: ctl_transact.c,v 1.5 1998/08/18 04:02:10 millert Exp $";
#endif /* not lint */
#include "talk.h"
@@ -97,7 +97,7 @@ ctl_transact(target, msg, type, rp)
}
} while (nready == 0);
/*
- * Keep reading while there are queued messages
+ * Keep reading while there are queued messages
* (this is not necessary, it just saves extra
* request/acknowledgements being sent)
*/
diff --git a/usr.bin/talk/get_addrs.c b/usr.bin/talk/get_addrs.c
index e21eedcdc78..d0286ece990 100644
--- a/usr.bin/talk/get_addrs.c
+++ b/usr.bin/talk/get_addrs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: get_addrs.c,v 1.3 1998/04/28 22:13:23 pjanzen Exp $ */
+/* $OpenBSD: get_addrs.c,v 1.4 1998/08/18 04:02:11 millert Exp $ */
/* $NetBSD: get_addrs.c,v 1.3 1994/12/09 02:14:14 jtc Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)get_addrs.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: get_addrs.c,v 1.3 1998/04/28 22:13:23 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: get_addrs.c,v 1.4 1998/08/18 04:02:11 millert Exp $";
#endif /* not lint */
#include "talk.h"
@@ -53,15 +53,13 @@ get_addrs(my_machine_name, his_machine_name)
{
struct hostent *hp;
struct servent *sp;
+ extern int h_errno;
msg.pid = htonl(getpid());
/* look up the address of the local host */
hp = gethostbyname(my_machine_name);
- if (hp == NULL) {
- fprintf(stderr, "talk: %s: ", my_machine_name);
- herror((char *)NULL);
- exit(-1);
- }
+ if (hp == NULL)
+ errx(1, "%s: %s", my_machine_name, hstrerror(h_errno));
bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
/*
* If the callee is on-machine, just copy the
@@ -69,20 +67,14 @@ get_addrs(my_machine_name, his_machine_name)
*/
if (strcmp(his_machine_name, my_machine_name)) {
hp = gethostbyname(his_machine_name);
- if (hp == NULL) {
- fprintf(stderr, "talk: %s: ", his_machine_name);
- herror((char *)NULL);
- exit(-1);
- }
+ if (hp == NULL)
+ errx(1, "%s: %s", his_machine_name, hstrerror(h_errno));
bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
} else
his_machine_addr = my_machine_addr;
/* find the server's port */
sp = getservbyname("ntalk", "udp");
- if (sp == 0) {
- fprintf(stderr, "talk: %s/%s: service is not registered.\n",
- "ntalk", "udp");
- exit(-1);
- }
+ if (sp == NULL)
+ errx(1, "ntalk/udp: service is not registered.");
daemon_port = sp->s_port;
}
diff --git a/usr.bin/talk/get_names.c b/usr.bin/talk/get_names.c
index ed9188515a3..8f7ec926983 100644
--- a/usr.bin/talk/get_names.c
+++ b/usr.bin/talk/get_names.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: get_names.c,v 1.5 1998/04/28 22:13:25 pjanzen Exp $ */
+/* $OpenBSD: get_names.c,v 1.6 1998/08/18 04:02:13 millert Exp $ */
/* $NetBSD: get_names.c,v 1.4 1994/12/09 02:14:16 jtc Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)get_names.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: get_names.c,v 1.5 1998/04/28 22:13:25 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: get_names.c,v 1.6 1998/08/18 04:02:13 millert Exp $";
#endif /* not lint */
#include "talk.h"
@@ -64,22 +64,18 @@ get_names(argc, argv)
char *names;
if ((argc < 2 ) || ('@' == argv[1][0])) {
- printf("Usage: talk user [ttyname]\n");
- printf(" talk user@hostname [ttyname]\n");
- exit(-1);
- }
- if (!isatty(0)) {
- printf("Standard input must be a tty, not a pipe or a file\n");
+ fprintf(stderr, "usage: talk user [ttyname]\n"
+ " talk user@hostname [ttyname]\n");
exit(-1);
}
+ if (!isatty(0))
+ errx(1, "standard input must be a tty, not a pipe or a file");
if ((my_name = getlogin()) == NULL) {
struct passwd *pw;
- if ((pw = getpwuid(getuid())) == NULL) {
- printf("You don't exist. Go away.\n");
- exit(-1);
- }
+ if ((pw = getpwuid(getuid())) == NULL)
+ errx(1, "you don't exist in the passwd file.");
my_name = pw->pw_name;
}
gethostname(hostname, sizeof (hostname));
diff --git a/usr.bin/talk/init_disp.c b/usr.bin/talk/init_disp.c
index 99414a34537..c14ee00edda 100644
--- a/usr.bin/talk/init_disp.c
+++ b/usr.bin/talk/init_disp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_disp.c,v 1.4 1998/04/28 22:13:26 pjanzen Exp $ */
+/* $OpenBSD: init_disp.c,v 1.5 1998/08/18 04:02:14 millert Exp $ */
/* $NetBSD: init_disp.c,v 1.6 1994/12/09 02:14:17 jtc Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)init_disp.c 8.2 (Berkeley) 2/16/94";
#endif
-static char rcsid[] = "$OpenBSD: init_disp.c,v 1.4 1998/04/28 22:13:26 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: init_disp.c,v 1.5 1998/08/18 04:02:14 millert Exp $";
#endif /* not lint */
/*
@@ -54,20 +54,20 @@ static char rcsid[] = "$OpenBSD: init_disp.c,v 1.4 1998/04/28 22:13:26 pjanzen E
#include <termios.h>
#include <unistd.h>
-/*
+/*
* Set up curses, catch the appropriate signals,
* and build the various windows.
*/
void
init_display()
{
- struct sigvec sigv;
+ struct sigaction sa;
if (initscr() == NULL)
errx(1, "Terminal type unset or lacking necessary features.");
- (void) sigvec(SIGTSTP, (struct sigvec *)0, &sigv);
- sigv.sv_mask |= sigmask(SIGALRM);
- (void) sigvec(SIGTSTP, &sigv, (struct sigvec *)0);
+ (void) sigaction(SIGTSTP, NULL, &sa);
+ sigaddset(&sa.sa_mask, SIGALRM);
+ (void) sigaction(SIGTSTP, &sa, NULL);
curses_initialized = 1;
clear();
refresh();
@@ -90,7 +90,7 @@ init_display()
wclear(his_win.x_win);
line_win = newwin(1, COLS, my_win.x_nlines, 0);
-#ifdef NCURSES_VERSION
+#if defined(NCURSES_VERSION) || defined(whline)
whline(line_win, '-', COLS);
#else
box(line_win, '-', '-');
@@ -113,15 +113,12 @@ set_edit_chars()
struct termios tty;
tcgetattr(0, &tty);
- my_win.cerase = tty.c_cc[VERASE];
- my_win.kill = tty.c_cc[VKILL];
- if (tty.c_cc[VWERASE] == (unsigned char) -1)
- my_win.werase = '\027'; /* control W */
- else
- my_win.werase = tty.c_cc[VWERASE];
- buf[0] = my_win.cerase;
- buf[1] = my_win.kill;
- buf[2] = my_win.werase;
+ buf[0] = my_win.cerase = tty.c_cc[VERASE] == (u_char)_POSIX_VDISABLE
+ ? CERASE : tty.c_cc[VERASE];
+ buf[1] = my_win.kill = tty.c_cc[VKILL] == (u_char)_POSIX_VDISABLE
+ ? CKILL : tty.c_cc[CKILL];
+ buf[2] = my_win.werase = tty.c_cc[VWERASE] == (u_char)_POSIX_VDISABLE
+ ? CWERASE : tty.c_cc[VWERASE];
cc = write(sockt, buf, sizeof(buf));
if (cc != sizeof(buf) )
p_error("Lost the connection");
diff --git a/usr.bin/talk/invite.c b/usr.bin/talk/invite.c
index 4f3a4a77ad9..4bf49412099 100644
--- a/usr.bin/talk/invite.c
+++ b/usr.bin/talk/invite.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: invite.c,v 1.5 1998/04/28 22:13:27 pjanzen Exp $ */
+/* $OpenBSD: invite.c,v 1.6 1998/08/18 04:02:15 millert Exp $ */
/* $NetBSD: invite.c,v 1.3 1994/12/09 02:14:18 jtc Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)invite.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: invite.c,v 1.5 1998/04/28 22:13:27 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: invite.c,v 1.6 1998/08/18 04:02:15 millert Exp $";
#endif /* not lint */
#include "talk.h"
@@ -56,13 +56,13 @@ static char rcsid[] = "$OpenBSD: invite.c,v 1.5 1998/04/28 22:13:27 pjanzen Exp
/*
* There wasn't an invitation waiting, so send a request containing
* our sockt address to the remote talk daemon so it can invite
- * him
+ * him
*/
/*
* The msg.id's for the invitations
* on the local and remote machines.
- * These are used to delete the
+ * These are used to delete the
* invitations.
*/
int local_id, remote_id;
@@ -209,11 +209,11 @@ send_delete()
if (sendto(ctl_sockt, &msg, sizeof (msg), 0,
(struct sockaddr *)&daemon_addr,
sizeof (daemon_addr)) != sizeof(msg))
- perror("send_delete (remote)");
+ warn("send_delete (remote)");
msg.id_num = htonl(local_id);
daemon_addr.sin_addr = my_machine_addr;
if (sendto(ctl_sockt, &msg, sizeof (msg), 0,
(struct sockaddr *)&daemon_addr,
sizeof (daemon_addr)) != sizeof (msg))
- perror("send_delete (local)");
+ warn("send_delete (local)");
}
diff --git a/usr.bin/talk/io.c b/usr.bin/talk/io.c
index fd5aa8a80eb..752eb103a88 100644
--- a/usr.bin/talk/io.c
+++ b/usr.bin/talk/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.6 1998/08/18 02:54:23 millert Exp $ */
+/* $OpenBSD: io.c,v 1.7 1998/08/18 04:02:16 millert Exp $ */
/* $NetBSD: io.c,v 1.4 1994/12/09 02:14:20 jtc Exp $ */
/*
@@ -38,11 +38,11 @@
#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: io.c,v 1.6 1998/08/18 02:54:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: io.c,v 1.7 1998/08/18 04:02:16 millert Exp $";
#endif /* not lint */
/*
- * This file contains the I/O handling and the exchange of
+ * This file contains the I/O handling and the exchange of
* edit characters. This connection itself is established in
* ctl.c
*/
@@ -67,7 +67,7 @@ talk()
char buf[BUFSIZ];
struct timeval wait;
-#ifdef NCURSES_VERSION
+#if defined(NCURSES_VERSION) || defined(beep)
message("Connection established");
/*
* beep() doesn't flush output on its own.
@@ -75,14 +75,13 @@ talk()
beep();
beep();
beep();
- refresh();
#else
message("Connection established\007\007\007");
#endif
current_line = 0;
/*
- * Wait on both the other process (sockt_mask) and
+ * Wait on both the other process (sockt_mask) and
* standard input ( STDIN_MASK )
*/
FD_ZERO(&read_template);
@@ -130,7 +129,7 @@ talk()
* on the screen and then exits. (i.e. a curses version of perror)
*/
void
-p_error(string)
+p_error(string)
char *string;
{
wmove(my_win.x_win, current_line%my_win.x_nlines, 0);
diff --git a/usr.bin/talk/look_up.c b/usr.bin/talk/look_up.c
index 9550026f8fb..114ed88c4fe 100644
--- a/usr.bin/talk/look_up.c
+++ b/usr.bin/talk/look_up.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: look_up.c,v 1.4 1998/04/28 22:13:29 pjanzen Exp $ */
+/* $OpenBSD: look_up.c,v 1.5 1998/08/18 04:02:18 millert Exp $ */
/* $NetBSD: look_up.c,v 1.3 1994/12/09 02:14:21 jtc Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)look_up.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: look_up.c,v 1.4 1998/04/28 22:13:29 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: look_up.c,v 1.5 1998/08/18 04:02:18 millert Exp $";
#endif /* not lint */
#include "talk.h"
@@ -66,8 +66,8 @@ check_local()
if (!look_for_invite(&response))
return (0);
/*
- * There was an invitation waiting for us,
- * so connect with the other (hopefully waiting) party
+ * There was an invitation waiting for us,
+ * so connect with the other (hopefully waiting) party
*/
current_state = "Waiting to connect with caller";
do {
@@ -81,7 +81,7 @@ check_local()
if (errno == ECONNREFUSED) {
/*
* The caller gave up, but his invitation somehow
- * was not cleared. Clear it and initiate an
+ * was not cleared. Clear it and initiate an
* invitation. (We know there are no newer invitations,
* the talkd works LIFO.)
*/
diff --git a/usr.bin/talk/msgs.c b/usr.bin/talk/msgs.c
index 3a7086deab0..75028b4afdf 100644
--- a/usr.bin/talk/msgs.c
+++ b/usr.bin/talk/msgs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: msgs.c,v 1.3 1998/04/28 22:13:30 pjanzen Exp $ */
+/* $OpenBSD: msgs.c,v 1.4 1998/08/18 04:02:23 millert Exp $ */
/* $NetBSD: msgs.c,v 1.3 1994/12/09 02:14:22 jtc Exp $ */
/*
@@ -38,10 +38,10 @@
#if 0
static char sccsid[] = "@(#)msgs.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: msgs.c,v 1.3 1998/04/28 22:13:30 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: msgs.c,v 1.4 1998/08/18 04:02:23 millert Exp $";
#endif /* not lint */
-/*
+/*
* A package to display what is happening every MSG_INTERVAL seconds
* if we are slow connecting.
*/
diff --git a/usr.bin/talk/talk.c b/usr.bin/talk/talk.c
index f7be4c67dfe..c662ef5511c 100644
--- a/usr.bin/talk/talk.c
+++ b/usr.bin/talk/talk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: talk.c,v 1.3 1998/04/28 22:13:31 pjanzen Exp $ */
+/* $OpenBSD: talk.c,v 1.4 1998/08/18 04:02:24 millert Exp $ */
/* $NetBSD: talk.c,v 1.3 1994/12/09 02:14:25 jtc Exp $ */
/*
@@ -44,15 +44,15 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)talk.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: talk.c,v 1.3 1998/04/28 22:13:31 pjanzen Exp $";
+static char rcsid[] = "$OpenBSD: talk.c,v 1.4 1998/08/18 04:02:24 millert Exp $";
#endif /* not lint */
#include "talk.h"
/*
- * talk: A visual form of write. Using sockets, a two way
- * connection is set up between the two people talking.
- * With the aid of curses, the screen is split into two
+ * talk: A visual form of write. Using sockets, a two way
+ * connection is set up between the two people talking.
+ * With the aid of curses, the screen is split into two
* windows, and each users text is added to the window,
* one character at a time...
*
diff --git a/usr.bin/talk/talk.h b/usr.bin/talk/talk.h
index cb173917fbe..ecff149cb76 100644
--- a/usr.bin/talk/talk.h
+++ b/usr.bin/talk/talk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: talk.h,v 1.3 1998/04/28 22:13:32 pjanzen Exp $ */
+/* $OpenBSD: talk.h,v 1.4 1998/08/18 04:02:26 millert Exp $ */
/* $NetBSD: talk.h,v 1.3 1994/12/09 02:14:27 jtc Exp $ */
/*
@@ -42,6 +42,7 @@
#include <protocols/talkd.h>
#include <curses.h>
#include <string.h>
+#include <err.h>
extern int sockt;
extern int curses_initialized;