-#include <whoami.h>
+static char *sccsid = "@(#)leave.c 4.1 (Berkeley) 10/1/80";
+#include <stdio.h>
/*
- * leave - reminds you when you have to leave.
- * leave prompts for input and goes away if you hit return.
- * it nags you like a mother hen.
+ * leave [hhmm]
+ *
+ * Reminds you when you have to leave.
+ * Leave prompts for input and goes away if you hit return.
+ * It nags you like a mother hen.
*/
char origlogin[20], thislogin[20];
char *getlogin();
char *ctime();
char buff[100];
-main(argc,argv) char **argv; {
+main(argc,argv)
+char **argv;
+{
long when, tod, now, diff, hours, minutes;
int *nv;
int atoi();
if (argc < 2) {
printf("When do you have to leave? ");
+ fflush(stdout);
buff[read(0,buff,sizeof buff)] = 0;
} else {
strcpy(buff,argv[1]);
}
- if (buff[0] == '\n') exit(0);
+
+ if (buff[0] == '\n')
+ exit(0);
if (buff[0] == '+') {
diff = atoi(buff+1);
doalarm(diff);
tod = atoi(buff);
hours = tod / 100;
- if (hours > 12) hours -= 12;
- if (hours == 12) hours = 0;
+ if (hours > 12)
+ hours -= 12;
+ if (hours == 12)
+ hours = 0;
minutes = tod % 100;
if (hours < 0 || hours > 12 || minutes < 0 || minutes > 59) {
}
-doalarm(nmins) long nmins; {
+doalarm(nmins)
+long nmins;
+{
char *msg1, *msg2, *msg3, *msg4;
register int i;
int slp1, slp2, slp3, slp4;
long daytime;
seconds = 60 * nmins;
- if (seconds <= 0) seconds = 1;
+ if (seconds <= 0)
+ seconds = 1;
gseconds = seconds;
msg1 = "You have to leave in 5 minutes";
daytime += gseconds;
whenleave = ctime(&daytime);
printf("Alarm set for %s\n",whenleave);
- if (fork()) exit(0);
+ if (fork())
+ exit(0);
signal(2,1);
signal(3,1);
- signal(15,1/*nag*/);
+ signal(15,1);
if (slp1)
bother(slp1,msg1);
}
}
-bother(slp,msg) int slp; char *msg; {
+bother(slp,msg)
+int slp;
+char *msg;
+{
delay(slp);
printf("\7\7\7");
if (secs < 0) {
n = n + secs;
}
- if (n > 0) sleep(n);
+ if (n > 0)
+ sleep(n);
strcpy(thislogin,getlogin());
- if (strcmp(origlogin, thislogin)) exit(0);
+ if (strcmp(origlogin, thislogin))
+ exit(0);
}
}
-#ifndef VAX
+#ifdef V6
char *getlogin() {
#include <utmp.h>
+
static struct utmp ubuf;
int ufd;
ufd = open("/etc/utmp",0);
seek(ufd, ttyn(0)*sizeof(ubuf), 0);
read(ufd, &ubuf, sizeof(ubuf));
- ubuf.ut_name[8] = 0;
+ ubuf.ut_name[sizeof(ubuf.ut_name)] = 0;
return(&ubuf.ut_name);
}
#endif