BSD 3 development
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 23 Nov 1979 11:28:42 +0000 (03:28 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Fri, 23 Nov 1979 11:28:42 +0000 (03:28 -0800)
Work on file usr/src/cmd/calendar/calendar.sh
Work on file usr/src/cmd/calendar/Makefile
Work on file usr/src/cmd/calendar/calendar.c

Synthesized-from: 3bsd

usr/src/cmd/calendar/Makefile [new file with mode: 0644]
usr/src/cmd/calendar/calendar.c [new file with mode: 0644]
usr/src/cmd/calendar/calendar.sh [new file with mode: 0755]

diff --git a/usr/src/cmd/calendar/Makefile b/usr/src/cmd/calendar/Makefile
new file mode 100644 (file)
index 0000000..3fd2e00
--- /dev/null
@@ -0,0 +1,8 @@
+calendar:
+       cc -O -o calendar calendar.c
+install:
+       install -s calendar $(DESTDIR)/usr/lib
+       install -c calendar.sh $(DESTDIR)/usr/bin/calendar
+
+clean:
+       rm -f calendar
diff --git a/usr/src/cmd/calendar/calendar.c b/usr/src/cmd/calendar/calendar.c
new file mode 100644 (file)
index 0000000..35ca4e3
--- /dev/null
@@ -0,0 +1,52 @@
+/* /usr/lib/calendar produces an egrep -f file
+   that will select today's and tomorrow's
+   calendar entries, with special weekend provisions
+
+   used by calendar command
+*/
+#include <time.h>
+
+#define DAY (3600*24L)
+
+char *month[] = {
+       "[Jj]an",
+       "[Ff]eb",
+       "[Mm]ar",
+       "[Aa]pr",
+       "[Mm]ay",
+       "[Jj]un",
+       "[Jj]ul",
+       "[Aa]ug",
+       "[Ss]ep",
+       "[Oo]ct",
+       "[Nn]ov",
+       "[Dd]ec"
+};
+struct tm *localtime();
+
+tprint(t)
+long t;
+{
+       struct tm *tm;
+       tm = localtime(&t);
+       printf("(^|[ (,;])((%s[^ ]* *|%d/)0*%d)([^0123456789]|$)\n",
+               month[tm->tm_mon], tm->tm_mon + 1, tm->tm_mday);
+}
+
+main()
+{
+       long t;
+       time(&t);
+       tprint(t);
+       switch(localtime(&t)->tm_wday) {
+       case 5:
+               t += DAY;
+               tprint(t);
+       case 6:
+               t += DAY;
+               tprint(t);
+       default:
+               t += DAY;
+               tprint(t);
+       }
+}
diff --git a/usr/src/cmd/calendar/calendar.sh b/usr/src/cmd/calendar/calendar.sh
new file mode 100755 (executable)
index 0000000..606a6cb
--- /dev/null
@@ -0,0 +1,19 @@
+PATH=/bin:/usr/bin
+tmp=/tmp/cal$$
+trap "rm $tmp; exit" 0 1 2 13 15
+/usr/lib/calendar >$tmp
+case $# in
+0)
+       egrep -f $tmp calendar;;
+*)
+       sed '
+               s/\([^:]*\):.*:\(.*\):[^:]*$/y=\2 z=\1/
+       ' /etc/passwd \
+       | while read x
+       do
+               eval $x
+               if test -r $y/calendar; then
+                       egrep -f $tmp $y/calendar 2>/dev/null  | mail $z
+               fi
+       done
+esac