From owner-p4-projects@FreeBSD.ORG Sun Dec 9 23:21:00 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 516E916A418; Sun, 9 Dec 2007 23:21:00 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F230116A41B for ; Sun, 9 Dec 2007 23:20:59 +0000 (UTC) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id E13D313C455 for ; Sun, 9 Dec 2007 23:20:59 +0000 (UTC) (envelope-from peter@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lB9NKxA3044367 for ; Sun, 9 Dec 2007 23:20:59 GMT (envelope-from peter@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lB9NKx1F044364 for perforce@freebsd.org; Sun, 9 Dec 2007 23:20:59 GMT (envelope-from peter@freebsd.org) Date: Sun, 9 Dec 2007 23:20:59 GMT Message-Id: <200712092320.lB9NKx1F044364@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to peter@freebsd.org using -f From: Peter Wemm To: Perforce Change Reviews Cc: Subject: PERFORCE change 130569 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Dec 2007 23:21:00 -0000 http://perforce.freebsd.org/chv.cgi?CH=130569 Change 130569 by peter@peter_overcee on 2007/12/09 23:20:12 Teach at(1) about "sunrise" and "sunset". eg: "at sunrise + 30 minutes" -> 30 min after sunrise Also, allow the "+" modifier to be negative. eg: "at sunset + -10 minutes" --> 10 min before sunset Affected files ... .. //depot/projects/hammer/usr.bin/at/Makefile#2 edit .. //depot/projects/hammer/usr.bin/at/parsetime.c#4 edit .. //depot/projects/hammer/usr.bin/at/parsetime.h#2 edit .. //depot/projects/hammer/usr.bin/at/suntime.c#1 add Differences ... ==== //depot/projects/hammer/usr.bin/at/Makefile#2 (text+ko) ==== @@ -3,7 +3,7 @@ .include "${.CURDIR}/Makefile.inc" PROG= at -SRCS= at.c panic.c parsetime.c perm.c +SRCS= at.c panic.c parsetime.c perm.c suntime.c LINKS= ${BINDIR}/at ${BINDIR}/atq \ ${BINDIR}/at ${BINDIR}/atrm \ ${BINDIR}/at ${BINDIR}/batch @@ -14,6 +14,8 @@ BINOWN= root BINMODE= 4555 CLEANFILES+= at.1 +LDADD+= -lm +DPADD+= ${LIBM} at.1: at.man @${ECHO} Making ${.TARGET:T} from ${.ALLSRC:T}; \ ==== //depot/projects/hammer/usr.bin/at/parsetime.c#4 (text+ko) ==== @@ -61,7 +61,7 @@ /* Structures and unions */ enum { /* symbols */ - MIDNIGHT, NOON, TEATIME, + MIDNIGHT, NOON, TEATIME, SUNRISE, SUNSET, PM, AM, TOMORROW, TODAY, NOW, MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS, NUMBER, PLUS, DOT, SLASH, ID, JUNK, @@ -80,6 +80,8 @@ { "midnight", MIDNIGHT,0 }, /* 00:00:00 of today or tomorrow */ { "noon", NOON,0 }, /* 12:00:00 of today or tomorrow */ { "teatime", TEATIME,0 }, /* 16:00:00 of today or tomorrow */ + { "sunrise", SUNRISE, 0 }, /* Sunrise */ + { "sunset", SUNSET, 0 }, /* Sunset */ { "am", AM,0 }, /* morning times for 0-12 clock */ { "pm", PM,0 }, /* evening times for 0-12 clock */ { "tomorrow", TOMORROW,0 }, /* execute 24 hours from time */ @@ -230,7 +232,8 @@ /* then see what it is */ - if (isdigit(sc_token[0])) { + if (isdigit(sc_token[0]) || sc_token[0] == '-') { + sc_token[++idx] = *sct++; while (isdigit(*sct)) sc_token[++idx] = *sct++; sc_token[++idx] = 0; @@ -564,6 +567,11 @@ struct tm nowtime, runtime; int hr = 0; /* this MUST be initialized to zero for midnight/noon/teatime */ + int mn, r; + double lat, lon; + + lat = 37.798325; /* where I live, so there. */ + lon = -121.970223; nowtimer = time(NULL); nowtime = *localtime(&nowtimer); @@ -593,6 +601,26 @@ month(&runtime); break; + case SUNRISE: + r = sun_time(1, lat, lon, nowtime.tm_gmtoff / 3600, nowtime.tm_yday + 1, &hr, &mn); + if (r == -1) + panic("no sunrise!"); + runtime.tm_hour = hr; + runtime.tm_min = mn; + token(); + month(&runtime); + break; + + case SUNSET: + r = sun_time(0, lat, lon, nowtime.tm_gmtoff / 3600, nowtime.tm_yday + 1, &hr, &mn); + if (r == -1) + panic("no sunrise!"); + runtime.tm_hour = hr; + runtime.tm_min = mn; + token(); + month(&runtime); + break; + /* evil coding for TEATIME|NOON|MIDNIGHT - we've initialised * hr to zero up above, then fall into this case in such a * way so we add +12 +4 hours to it for teatime, +12 hours ==== //depot/projects/hammer/usr.bin/at/parsetime.h#2 (text+ko) ==== @@ -24,3 +24,4 @@ */ time_t parsetime(int argc, char **argv); +int sun_time(int rise, double lat, double lon, int tz, int yday, int *hr, int *mn);