leave.1

2020-01-21 Thread Ted Unangst
Rewrite some of the page to avoid second person.


Index: leave.1
===
RCS file: /home/cvs/src/usr.bin/leave/leave.1,v
retrieving revision 1.16
diff -u -p -r1.16 leave.1
--- leave.1 13 Jul 2018 16:59:46 -  1.16
+++ leave.1 22 Jan 2020 02:08:00 -
@@ -35,17 +35,17 @@
 .Os
 .Sh NAME
 .Nm leave
-.Nd remind you when you have to leave
+.Nd print reminders when it is time to leave
 .Sh SYNOPSIS
 .Nm leave
 .Op Oo Cm + Oc Ns Ar hhmm
 .Sh DESCRIPTION
 .Nm leave
-waits until the specified time, then reminds you that you
-have to leave.
-You are reminded 5 minutes and 1 minute before the actual
+waits until the specified time, then prints a reminder
+that it is time to leave.
+Reminders are printed 5 minutes and 1 minute before the actual
 time, at the time, and every minute thereafter.
-When you log off,
+If the login session ends,
 .Nm leave
 exits just before it would have
 printed the next message.
@@ -72,8 +72,7 @@ from the current time.
 .Pp
 If no argument is given,
 .Nm leave
-prompts with "When do you
-have to leave?".
+prompts with "When do you have to leave?".
 A reply of newline causes
 .Nm leave
 to exit,



Re: leave(1): schedule absolute alarm for start of minute

2018-02-08 Thread Theo Buehler
On Tue, Feb 06, 2018 at 11:22:52AM -0600, Scott Cheloha wrote:
> Hi,
> 
> When I schedule an alarm for an absolute time with minute granularity,
> I expect the alarm to go off at the beginning of that minute.
> 
> So, this:
> 
>   leave 1430
> 
> should go off at 14:30:00.
> 
> The two-second sleep in the child of doalarm() confounds this, but I
> have a subsequent diff that refactors that function to obviate it.
> 
> ok?

I'm fine with your idea but...

> 
> --
> Scott Cheloha
> 
> Index: usr.bin/leave/leave.c
> ===
> RCS file: /cvs/src/usr.bin/leave/leave.c,v
> retrieving revision 1.17
> diff -u -p -r1.17 leave.c
> --- usr.bin/leave/leave.c 9 Oct 2015 01:37:08 -   1.17
> +++ usr.bin/leave/leave.c 6 Feb 2018 16:58:45 -
> @@ -113,6 +113,7 @@ main(int argc, char *argv[])
>  
>   secs = (hours - t->tm_hour) * HOUR;
>   secs += (minutes - t->tm_min) * MINUTE;
> + secs -= now % 60;   /* aim for beginning of minute */

This doesn't work here, it fires at around :39 seconds in NZDT

secs -= t->tm_sec;

probably works better if you're aiming for the beginning of the minute
in the current timezone.


>   }
>   doalarm(secs);
>   exit(0);
> @@ -155,12 +156,16 @@ doalarm(u_int secs)
>   sleep(secs - MINUTE);
>   if (puts("\a\aJust one more minute!") == EOF)
>   exit(0);
> + secs = MINUTE;
>   }
>  
> + sleep(secs);
> +
>   for (bother = 10; bother--;) {
> - sleep(MINUTE);
>   if (puts("\a\aTime to leave!") == EOF)
>   exit(0);
> + if (bother)
> + sleep(MINUTE);
>   }
>  
>   puts("\a\aThat was the last time I'll tell you.  Bye.");
> 



leave(1): schedule absolute alarm for start of minute

2018-02-06 Thread Scott Cheloha
Hi,

When I schedule an alarm for an absolute time with minute granularity,
I expect the alarm to go off at the beginning of that minute.

So, this:

leave 1430

should go off at 14:30:00.

The two-second sleep in the child of doalarm() confounds this, but I
have a subsequent diff that refactors that function to obviate it.

ok?

--
Scott Cheloha

Index: usr.bin/leave/leave.c
===
RCS file: /cvs/src/usr.bin/leave/leave.c,v
retrieving revision 1.17
diff -u -p -r1.17 leave.c
--- usr.bin/leave/leave.c   9 Oct 2015 01:37:08 -   1.17
+++ usr.bin/leave/leave.c   6 Feb 2018 16:58:45 -
@@ -113,6 +113,7 @@ main(int argc, char *argv[])
 
secs = (hours - t->tm_hour) * HOUR;
secs += (minutes - t->tm_min) * MINUTE;
+   secs -= now % 60;   /* aim for beginning of minute */
}
doalarm(secs);
exit(0);
@@ -155,12 +156,16 @@ doalarm(u_int secs)
sleep(secs - MINUTE);
if (puts("\a\aJust one more minute!") == EOF)
exit(0);
+   secs = MINUTE;
}
 
+   sleep(secs);
+
for (bother = 10; bother--;) {
-   sleep(MINUTE);
if (puts("\a\aTime to leave!") == EOF)
exit(0);
+   if (bother)
+   sleep(MINUTE);
}
 
puts("\a\aThat was the last time I'll tell you.  Bye.");