From owner-freebsd-bugs Sun Apr 14 19:40:14 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 5546037B419 for ; Sun, 14 Apr 2002 19:40:01 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g3F2e1t70059; Sun, 14 Apr 2002 19:40:01 -0700 (PDT) (envelope-from gnats) Received: from snark.rinet.ru (snark.rinet.ru [195.54.192.73]) by hub.freebsd.org (Postfix) with ESMTP id F385037B405 for ; Sun, 14 Apr 2002 19:31:43 -0700 (PDT) Received: (from glebius@localhost) by snark.rinet.ru (8.11.6/8.11.6) id g3F2VfJ04676; Mon, 15 Apr 2002 06:31:41 +0400 (MSD) (envelope-from glebius) Message-Id: <200204150231.g3F2VfJ04676@snark.rinet.ru> Date: Mon, 15 Apr 2002 06:31:41 +0400 (MSD) From: Gleb Smirnoff Reply-To: Gleb Smirnoff To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/37083: small improvement to talk(1): add clocks Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 37083 >Category: bin >Synopsis: small improvement to talk(1): add clocks >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Apr 14 19:40:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Gleb Smirnoff >Release: FreeBSD 4.5-STABLE i386 >Organization: Rinet ISP >Environment: System: FreeBSD snark.rinet.ru 4.5-STABLE FreeBSD 4.5-STABLE #2: Wed Jan 30 12:00:01 MSK 2002 root@snark.rinet.ru:/usr/obj/usr/src/sys/SNARK i386 >Description: The following patch adds to clocks to the middle line in talk. The right one shows current time, the left one shows time spent talking. The patch was made just for fun, for a person who wastes a lot of time in talk(1). May be someone will look at it and find it useful, but I doubt :) >How-To-Repeat: >Fix: Here is the patch: diff -ur /usr/src/usr.bin/talk/display.c talk/display.c --- /usr/src/usr.bin/talk/display.c Sat Aug 28 05:06:11 1999 +++ talk/display.c Mon Apr 15 06:25:05 2002 @@ -181,3 +181,30 @@ wmove(win, oldline, oldcol); return (c); } + +void +drawline(tod) + time_t *tod; +{ + time_t uptime; + int hrs, mins, secs; + char str[COLS]; + + if (tod == NULL) { + snprintf(str,(time_t ) COLS, + "[ ]%s[ ]",line); + } else { + uptime = *tod - st_time; + uptime %= 86400; + hrs = uptime / 3600; + uptime %= 3600; + mins = uptime / 60; + secs = uptime % 60; + snprintf(str,(time_t ) COLS, + "[%02d:%02d:%02d]%s[%-8.8s]", + hrs, mins, secs, line, &(ctime(tod)[11])); + } + wmove(line_win, 0, 0); + wprintw(line_win, "%s", str); + wrefresh(line_win); +} diff -ur /usr/src/usr.bin/talk/init_disp.c talk/init_disp.c --- /usr/src/usr.bin/talk/init_disp.c Mon Jul 30 14:31:29 2001 +++ talk/init_disp.c Mon Apr 15 06:17:11 2002 @@ -52,6 +52,10 @@ #include #include "talk.h" +#define CLOCKLEN 10 + +char *line; + /* * Make sure the callee can write to the screen */ @@ -106,12 +110,10 @@ scrollok(his_win.x_win, TRUE); wclear(his_win.x_win); + line = (char *)malloc(COLS - (CLOCKLEN * 2) - 1); + memset((void *)line,'-',(COLS - (CLOCKLEN * 2) - 1)); line_win = newwin(1, COLS, my_win.x_nlines, 0); -#if defined(hline) || defined(whline) || defined(NCURSES_VERSION) - whline(line_win, 0, COLS); -#else - box(line_win, '-', '-'); -#endif + drawline(NULL); wrefresh(line_win); /* let them know we are working on it */ current_state = "No connection yet"; diff -ur /usr/src/usr.bin/talk/io.c talk/io.c --- /usr/src/usr.bin/talk/io.c Wed Oct 17 03:14:09 2001 +++ talk/io.c Mon Apr 15 06:15:27 2002 @@ -55,6 +55,8 @@ #define A_LONG_TIME 10000000 +time_t st_time; + /* * The routine to do the actual talking */ @@ -66,6 +68,7 @@ fd_set read_set, read_template; char buf[BUFSIZ], **addr, *his_machine_name; struct timeval wait; + time_t curr_time; his_machine_name = NULL; hp = gethostbyaddr((const char *)&his_machine_addr.s_addr, @@ -88,6 +91,7 @@ free(his_machine_name); message(buf); write(STDOUT_FILENO, "\007\007\007", 3); + time(&st_time); current_line = 0; @@ -103,6 +107,7 @@ wait.tv_sec = A_LONG_TIME; wait.tv_usec = 0; nb = select(32, &read_set, 0, 0, &wait); + time(&curr_time); if (nb <= 0) { if (errno == EINTR) { read_set = read_template; @@ -119,6 +124,7 @@ message("Connection closed. Exiting"); quit(); } + drawline(&curr_time); display(&his_win, buf, nb); } if (FD_ISSET(fileno(stdin), &read_set)) { @@ -129,6 +135,7 @@ int i; ioctl(0, FIONREAD, (struct sgttyb *) &nb); nb = read(0, buf, nb); + drawline(&curr_time); display(&my_win, buf, nb); /* might lose data here because sockt is non-blocking */ for (i = 0; i < nb; ++i) Only in talk/: talk.cat1 diff -ur /usr/src/usr.bin/talk/talk.h talk/talk.h --- /usr/src/usr.bin/talk/talk.h Sat Mar 9 22:23:01 1996 +++ talk/talk.h Mon Apr 15 06:03:30 2002 @@ -49,6 +49,8 @@ extern char *current_state; extern int current_line; +extern char *line; +extern time_t st_time; typedef struct xwin { WINDOW *x_win; @@ -71,6 +73,7 @@ extern void ctl_transact __P((struct in_addr,CTL_MSG,int,CTL_RESPONSE *)); extern void disp_msg __P((int)); extern void display __P((xwin_t *, char *, int)); +extern void drawline __P((time_t *)); extern void end_msgs __P((void)); extern void get_addrs __P((char *, char *)); extern int get_iface __P((struct in_addr *, struct in_addr *)); >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message