Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/usr.bin/leave Pull up revisions 1.9-1.10 (requested by ...
details: https://anonhg.NetBSD.org/src/rev/dc99fdd222a8
branches: netbsd-1-5
changeset: 492592:dc99fdd222a8
user: he <he%NetBSD.org@localhost>
date: Tue Jan 22 19:38:52 2002 +0000
description:
Pull up revisions 1.9-1.10 (requested by fair):
Handle 24-hour time format better, and also document limitations.
Also include <stdlib.h>.
diffstat:
usr.bin/leave/leave.c | 21 ++++++++++++++-------
1 files changed, 14 insertions(+), 7 deletions(-)
diffs (74 lines):
diff -r 2e8bb9bc874f -r dc99fdd222a8 usr.bin/leave/leave.c
--- a/usr.bin/leave/leave.c Tue Jan 22 19:32:48 2002 +0000
+++ b/usr.bin/leave/leave.c Tue Jan 22 19:38:52 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: leave.c,v 1.8 1998/12/19 17:44:22 christos Exp $ */
+/* $NetBSD: leave.c,v 1.8.10.1 2002/01/22 19:38:52 he Exp $ */
/*
* Copyright (c) 1980, 1988, 1993
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: leave.c,v 1.8 1998/12/19 17:44:22 christos Exp $");
+__RCSID("$NetBSD: leave.c,v 1.8.10.1 2002/01/22 19:38:52 he Exp $");
#endif
#endif /* not lint */
@@ -51,9 +51,14 @@
#include <sys/time.h>
#include <ctype.h>
#include <stdio.h>
+#include <stdlib.h>
#include <time.h>
#include <unistd.h>
+#define SECOND 1
+#define MINUTE (SECOND * 60)
+#define HOUR (MINUTE * 60)
+
/*
* leave [[+]hhmm]
*
@@ -112,17 +117,19 @@
if (minutes < 0 || minutes > 59)
usage();
if (plusnow)
- secs = hours * 60 * 60 + minutes * 60;
+ secs = (hours * HOUR) + (minutes * MINUTE);
else {
if (hours > 23)
usage();
if (t->tm_hour >= 12)
t->tm_hour -= 12;
+ if (hours >= 12)
+ hours -= 12;
if (t->tm_hour > hours ||
(t->tm_hour == hours && minutes <= t->tm_min))
hours += 12;
- secs = (hours - t->tm_hour) * 60 * 60;
- secs += (minutes - t->tm_min) * 60;
+ secs = (hours - t->tm_hour) * HOUR;
+ secs += (minutes - t->tm_min) * MINUTE;
}
doalarm(secs);
exit(0);
@@ -149,7 +156,7 @@
* if write fails, we've lost the terminal through someone else
* causing a vhangup by logging in.
*/
-#define FIVEMIN (5 * 60)
+#define FIVEMIN (5 * MINUTE)
#define MSG2 "\07\07You have to leave in 5 minutes.\n"
if (secs >= FIVEMIN) {
sleep(secs - FIVEMIN);
@@ -159,7 +166,7 @@
secs = FIVEMIN;
}
-#define ONEMIN (60)
+#define ONEMIN (MINUTE)
#define MSG3 "\07\07Just one more minute!\n"
if (secs >= ONEMIN) {
sleep(secs - ONEMIN);
Home |
Main Index |
Thread Index |
Old Index