From owner-svn-src-all@FreeBSD.ORG Tue May 4 08:06:54 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 40DF11065672; Tue, 4 May 2010 08:06:54 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 2FF738FC17; Tue, 4 May 2010 08:06:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o4486sfx048826; Tue, 4 May 2010 08:06:54 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o4486sYU048823; Tue, 4 May 2010 08:06:54 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <201005040806.o4486sYU048823@svn.freebsd.org> From: Edwin Groothuis Date: Tue, 4 May 2010 08:06:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207609 - stable/8/games/pom X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 May 2010 08:06:54 -0000 Author: edwin Date: Tue May 4 08:06:53 2010 New Revision: 207609 URL: http://svn.freebsd.org/changeset/base/207609 Log: MFC of r201613, r201627 Be able to specify a certain date and/or time for which to calculate the phase of the moon. While not worlds best improvements, it will help calendar(1) later on. Also closed bin/79008 PR: bin/79008 Modified: stable/8/games/pom/pom.6 stable/8/games/pom/pom.c Directory Properties: stable/8/games/pom/ (props changed) Modified: stable/8/games/pom/pom.6 ============================================================================== --- stable/8/games/pom/pom.6 Tue May 4 06:19:19 2010 (r207608) +++ stable/8/games/pom/pom.6 Tue May 4 08:06:53 2010 (r207609) @@ -32,15 +32,34 @@ .\" @(#)pom.6 8.1 (Berkeley) 5/31/93 .\" $FreeBSD$ .\" -.TH POM 6 "May 31, 1993" +.Dd May 31, 1993 +.Dt POM 6 .UC 7 -.SH NAME -pom \- display the phase of the moon -.SH SYNOPSIS -.B pom -.SH DESCRIPTION +.Sh NAME +.Nm pom +.Nd display the phase of the moon +.Sh SYNOPSIS +.Nm +.Op Fl d Ar yyyy.mm.dd +.Op Fl t Ar hh:mm:ss +.Sh DESCRIPTION The -.I pom +.Nm utility displays the current phase of the moon. Useful for selecting software completion target dates and predicting managerial behavior. +.Pp +Use the arguments +.Fl d +and +.Fl o +to specify a specific date and time for which the phase of the moon +has to be calculated. +If +.Fl d +but not +.Fl t +has been specified, it will calculate the phase of the moon on that +day at midnight. +.Sh SEE ALSO +`Practical Astronomy with Your Calculator' by Duffett-Smith. Modified: stable/8/games/pom/pom.c ============================================================================== --- stable/8/games/pom/pom.c Tue May 4 06:19:19 2010 (r207608) +++ stable/8/games/pom/pom.c Tue May 4 08:06:53 2010 (r207609) @@ -57,9 +57,13 @@ __FBSDID("$FreeBSD$"); * */ -#include #include +#include #include +#include +#include +#include +#include #ifndef PI #define PI 3.14159265358979323846 @@ -76,20 +80,62 @@ __FBSDID("$FreeBSD$"); static void adj360(double *); static double dtor(double); static double potm(double); +static void usage(char *progname); int -main(void) +main(int argc, char **argv) { time_t tt; - struct tm *GMT; + struct tm GMT, tmd; double days, today, tomorrow; - int cnt; + int ch, cnt; + char *odate = NULL, *otime = NULL; + + while ((ch = getopt(argc, argv, "d:t:")) != -1) + switch (ch) { + case 'd': + odate = optarg; + break; + case 't': + otime = optarg; + break; + default: + usage(argv[0]); + } + + argc -= optind; + argv += optind; + + if (argc) + usage(argv[0]); - (void) time(&tt); - GMT = gmtime(&tt); - days = (GMT->tm_yday + 1) + ((GMT->tm_hour + - (GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0); - for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt) + /* Adjust based on users preferences */ + time(&tt); + if (otime != NULL || odate != NULL) { + /* Save today in case -d isn't specified */ + localtime_r(&tt, &tmd); + + if (odate != NULL) { + tmd.tm_year = strtol(odate, NULL, 10) - 1900; + tmd.tm_mon = strtol(odate + 5, NULL, 10) - 1; + tmd.tm_mday = strtol(odate + 8, NULL, 10); + /* Use midnight as the middle of the night */ + tmd.tm_hour = 0; + tmd.tm_min = 0; + tmd.tm_sec = 0; + } + if (otime != NULL) { + tmd.tm_hour = strtol(otime, NULL, 10); + tmd.tm_min = strtol(otime + 3, NULL, 10); + tmd.tm_sec = strtol(otime + 6, NULL, 10); + } + tt = mktime(&tmd); + } + + gmtime_r(&tt, &GMT); + days = (GMT.tm_yday + 1) + ((GMT.tm_hour + + (GMT.tm_min / 60.0) + (GMT.tm_sec / 3600.0)) / 24.0); + for (cnt = EPOCH; cnt < GMT.tm_year; ++cnt) days += isleap(1900 + cnt) ? 366 : 365; today = potm(days) + .5; (void)printf("The Moon is "); @@ -160,6 +206,7 @@ potm(double days) static double dtor(double deg) { + return(deg * PI / 180); } @@ -170,6 +217,7 @@ dtor(double deg) static void adj360(double *deg) { + for (;;) if (*deg < 0) *deg += 360; @@ -178,3 +226,11 @@ adj360(double *deg) else break; } + +static void +usage(char *progname) +{ + + fprintf(stderr, "Usage: %s [-d yyyy.mm.dd] [-t hh:mm:ss]\n", progname); + exit(EX_USAGE); +}