=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/leave/leave.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -r1.2 -r1.3 *** src/usr.bin/leave/leave.c 1996/06/26 05:34:57 1.2 --- src/usr.bin/leave/leave.c 1997/09/08 09:34:44 1.3 *************** *** 1,4 **** ! /* $OpenBSD: leave.c,v 1.2 1996/06/26 05:34:57 deraadt Exp $ */ /* $NetBSD: leave.c,v 1.4 1995/07/03 16:50:13 phil Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: leave.c,v 1.3 1997/09/08 09:34:44 deraadt Exp $ */ /* $NetBSD: leave.c,v 1.4 1995/07/03 16:50:13 phil Exp $ */ /* *************** *** 44,57 **** #if 0 static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93"; #endif ! static char rcsid[] = "$OpenBSD: leave.c,v 1.2 1996/06/26 05:34:57 deraadt Exp $"; #endif /* not lint */ #include #include #include #include /* * leave [[+]hhmm] * --- 44,62 ---- #if 0 static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93"; #endif ! static char rcsid[] = "$OpenBSD: leave.c,v 1.3 1997/09/08 09:34:44 deraadt Exp $"; #endif /* not lint */ #include #include + #include + #include #include #include + void usage __P((void)); + void doalarm __P((u_int secs)); + /* * leave [[+]hhmm] * *************** *** 59,64 **** --- 64,70 ---- * Leave prompts for input and goes away if you hit return. * It nags you like a mother hen. */ + int main(argc, argv) int argc; char **argv; *************** *** 66,79 **** register u_int secs; register int hours, minutes; register char c, *cp; ! struct tm *t, *localtime(); ! time_t now, time(); int plusnow; char buf[50]; if (argc < 2) { #define MSG1 "When do you have to leave? " ! (void)write(1, MSG1, sizeof(MSG1) - 1); cp = fgets(buf, sizeof(buf), stdin); if (cp == NULL || *cp == '\n') exit(0); --- 72,85 ---- register u_int secs; register int hours, minutes; register char c, *cp; ! struct tm *t; ! time_t now; int plusnow; char buf[50]; if (argc < 2) { #define MSG1 "When do you have to leave? " ! (void)write(STDOUT_FILENO, MSG1, sizeof(MSG1) - 1); cp = fgets(buf, sizeof(buf), stdin); if (cp == NULL || *cp == '\n') exit(0); *************** *** 102,110 **** if (plusnow) secs = hours * 60 * 60 + minutes * 60; else { ! if (hours > 23 || t->tm_hour > hours || ! t->tm_hour == hours && minutes <= t->tm_min) usage(); secs = (hours - t->tm_hour) * 60 * 60; secs += (minutes - t->tm_min) * 60; } --- 108,120 ---- if (plusnow) secs = hours * 60 * 60 + minutes * 60; else { ! if (hours > 23) usage(); + if (t->tm_hour >= 12) + t->tm_hour -= 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; } *************** *** 112,126 **** exit(0); } doalarm(secs) u_int secs; { register int bother; ! time_t daytime, time(); int pid; - char *ctime(); ! if (pid = fork()) { (void)time(&daytime); daytime += secs; printf("Alarm set for %.16s. (pid %d)\n", --- 122,136 ---- exit(0); } + void doalarm(secs) u_int secs; { register int bother; ! time_t daytime; int pid; ! if ((pid = fork())) { (void)time(&daytime); daytime += secs; printf("Alarm set for %.16s. (pid %d)\n", *************** *** 137,143 **** #define MSG2 "\07\07You have to leave in 5 minutes.\n" if (secs >= FIVEMIN) { sleep(secs - FIVEMIN); ! if (write(1, MSG2, sizeof(MSG2) - 1) != sizeof(MSG2) - 1) exit(0); secs = FIVEMIN; } --- 147,153 ---- #define MSG2 "\07\07You have to leave in 5 minutes.\n" if (secs >= FIVEMIN) { sleep(secs - FIVEMIN); ! if (write(STDOUT_FILENO, MSG2, sizeof(MSG2) - 1) != sizeof(MSG2) - 1) exit(0); secs = FIVEMIN; } *************** *** 146,167 **** #define MSG3 "\07\07Just one more minute!\n" if (secs >= ONEMIN) { sleep(secs - ONEMIN); ! if (write(1, MSG3, sizeof(MSG3) - 1) != sizeof(MSG3) - 1) exit(0); } #define MSG4 "\07\07Time to leave!\n" for (bother = 10; bother--;) { sleep((u_int)ONEMIN); ! if (write(1, MSG4, sizeof(MSG4) - 1) != sizeof(MSG4) - 1) exit(0); } #define MSG5 "\07\07That was the last time I'll tell you. Bye.\n" ! (void)write(1, MSG5, sizeof(MSG5) - 1); exit(0); } usage() { fprintf(stderr, "usage: leave [[+]hhmm]\n"); --- 156,178 ---- #define MSG3 "\07\07Just one more minute!\n" if (secs >= ONEMIN) { sleep(secs - ONEMIN); ! if (write(STDOUT_FILENO, MSG3, sizeof(MSG3) - 1) != sizeof(MSG3) - 1) exit(0); } #define MSG4 "\07\07Time to leave!\n" for (bother = 10; bother--;) { sleep((u_int)ONEMIN); ! if (write(STDOUT_FILENO, MSG4, sizeof(MSG4) - 1) != sizeof(MSG4) - 1) exit(0); } #define MSG5 "\07\07That was the last time I'll tell you. Bye.\n" ! (void)write(STDOUT_FILENO, MSG5, sizeof(MSG5) - 1); exit(0); } + void usage() { fprintf(stderr, "usage: leave [[+]hhmm]\n");