[Midnightbsd-cvs] src [11889] trunk/games/pom/pom.c: reformat
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Jul 17 20:55:04 EDT 2018
Revision: 11889
http://svnweb.midnightbsd.org/src/?rev=11889
Author: laffer1
Date: 2018-07-17 20:55:03 -0400 (Tue, 17 Jul 2018)
Log Message:
-----------
reformat
Modified Paths:
--------------
trunk/games/pom/Makefile
trunk/games/pom/pom.6
trunk/games/pom/pom.c
Property Changed:
----------------
trunk/games/pom/pom.6
Modified: trunk/games/pom/Makefile
===================================================================
--- trunk/games/pom/Makefile 2018-07-18 00:54:46 UTC (rev 11888)
+++ trunk/games/pom/Makefile 2018-07-18 00:55:03 UTC (rev 11889)
@@ -1,6 +1,6 @@
+# $MidnightBSD$
# @(#)Makefile 8.1 (Berkeley) 5/31/93
-# $FreeBSD: src/games/pom/Makefile,v 1.7 2005/05/01 19:34:22 stefanf Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/games/pom/Makefile 203923 2010-02-15 14:32:00Z uqs $
PROG= pom
MAN= pom.6
@@ -7,6 +7,4 @@
DPADD= ${LIBM}
LDADD= -lm
-WARNS?= 6
-
.include <bsd.prog.mk>
Modified: trunk/games/pom/pom.6
===================================================================
--- trunk/games/pom/pom.6 2018-07-18 00:54:46 UTC (rev 11888)
+++ trunk/games/pom/pom.6 2018-07-18 00:55:03 UTC (rev 11889)
@@ -1,47 +1,67 @@
-." Copyright (c) 1989, 1993
-." The Regents of the University of California. All rights reserved.
-."
-." Redistribution and use in source and binary forms, with or without
-." modification, are permitted provided that the following conditions
-." are met:
-." 1. Redistributions of source code must retain the above copyright
-." notice, this list of conditions and the following disclaimer.
-." 2. Redistributions in binary form must reproduce the above copyright
-." notice, this list of conditions and the following disclaimer in the
-." documentation and/or other materials provided with the distribution.
-." 3. All advertising materials mentioning features or use of this software
-." must display the following acknowledgement:
-." This product includes software developed by the University of
-." California, Berkeley and its contributors.
-." 4. Neither the name of the University nor the names of its contributors
-." may be used to endorse or promote products derived from this software
-." without specific prior written permission.
-."
-." THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-." IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-." ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-." FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-." DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-." OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-." HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-." LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-." OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-." SUCH DAMAGE.
-."
-." @(#)pom.6 8.1 (Berkeley) 5/31/93
-." $FreeBSD: src/games/pom/pom.6,v 1.4 2001/07/15 07:49:21 dd Exp $
-." $MidnightBSD$
-."
-.TH POM 6 "May 31, 1993"
-.UC 7
-.SH NAME
-pom - display the phase of the moon
-.SH SYNOPSIS
-.B pom
-.SH DESCRIPTION
+.\" $MidnightBSD$
+.\" Copyright (c) 1989, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)pom.6 8.1 (Berkeley) 5/31/93
+.\" $FreeBSD: stable/10/games/pom/pom.6 233648 2012-03-29 05:02:12Z eadler $
+.\"
+.Dd July 14, 2010
+.Dt POM 6
+.Os
+.Sh NAME
+.Nm pom
+.Nd display the phase of the moon
+.Sh SYNOPSIS
+.Nm
+.Op Fl p
+.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
+.Fl p
+option to print just the phase as a percentage.
+.Pp
+Use the arguments
+.Fl d
+and
+.Fl t
+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.
Property changes on: trunk/games/pom/pom.6
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/games/pom/pom.c
===================================================================
--- trunk/games/pom/pom.c 2018-07-18 00:54:46 UTC (rev 11888)
+++ trunk/games/pom/pom.c 2018-07-18 00:55:03 UTC (rev 11889)
@@ -1,42 +1,40 @@
+/* $MidnightBSD$ */
/*
-* Copyright (c) 1989, 1993
-* The Regents of the University of California. All rights reserved.
-*
-* This code is derived from software posted to USENET.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions
-* are met:
-* 1. Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* 2. Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* 3. All advertising materials mentioning features or use of this software
-* must display the following acknowledgement:
-* This product includes software developed by the University of
-* California, Berkeley and its contributors.
-* 4. Neither the name of the University nor the names of its contributors
-* may be used to endorse or promote products derived from this software
-* without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
-* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
-* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-* SUCH DAMAGE.
-*/
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software posted to USENET.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
#if 0
#ifndef lint
static const char copyright[] =
-"@(#) Copyright (c) 1989, 1993n The Regents of the University of California. All rights reserved.n";
+"@(#) Copyright (c) 1989, 1993\n\
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
@@ -44,22 +42,25 @@
#endif /* not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/games/pom/pom.c,v 1.13 2005/05/01 19:34:22 stefanf Exp $");
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/games/pom/pom.c 230644 2012-01-28 15:29:43Z maxim $");
/*
-* Phase of the Moon. Calculates the current phase of the moon.
-* Based on routines from `Practical Astronomy with Your Calculator',
-* by Duffett-Smith. Comments give the section from the book that
-* particular piece of code was adapted from.
-*
-* -- Keith E. Brandt VIII 1984
-*
-*/
+ * Phase of the Moon. Calculates the current phase of the moon.
+ * Based on routines from `Practical Astronomy with Your Calculator',
+ * by Duffett-Smith. Comments give the section from the book that
+ * particular piece of code was adapted from.
+ *
+ * -- Keith E. Brandt VIII 1984
+ *
+ */
-#include <time.h>
#include <stdio.h>
+#include <stdlib.h>
#include <math.h>
+#include <string.h>
+#include <sysexits.h>
+#include <time.h>
+#include <unistd.h>
#ifndef PI
#define PI 3.14159265358979323846
@@ -76,105 +77,166 @@
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;
-double days, today, tomorrow;
-int cnt;
+ time_t tt;
+ struct tm GMT, tmd;
+ double days, today, tomorrow;
+ int ch, cnt, pflag = 0;
+ char *odate = NULL, *otime = NULL;
+ char *progname = 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)
-days += isleap(1900 + cnt) ? 366 : 365;
-today = potm(days) + .5;
-(void)printf("The Moon is ");
-if ((int)today == 100)
-(void)printf("Fulln");
-else if (!(int)today)
-(void)printf("Newn");
-else {
-tomorrow = potm(days + 1);
-if ((int)today == 50)
-(void)printf("%sn", tomorrow > today ?
-"at the First Quarter" : "at the Last Quarter");
-else {
-(void)printf("%s ", tomorrow > today ?
-"Waxing" : "Waning");
-if (today > 50)
-(void)printf("Gibbous (%1.0f%% of Full)n",
-today);
-else if (today < 50)
-(void)printf("Crescent (%1.0f%% of Full)n",
-today);
-}
-}
+ while ((ch = getopt(argc, argv, "d:pt:")) != -1)
+ switch (ch) {
+ case 'd':
+ odate = optarg;
+ break;
+ case 'p':
+ pflag = 1;
+ break;
+ case 't':
+ otime = optarg;
+ break;
+ default:
+ usage(progname);
+ }
-return 0;
+ argc -= optind;
+ argv += optind;
+
+ if (argc)
+ usage(progname);
+
+ /* 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;
+ if (pflag) {
+ (void)printf("%1.0f\n", today);
+ return (0);
+ }
+ (void)printf("The Moon is ");
+ if ((int)today == 100)
+ (void)printf("Full\n");
+ else if (!(int)today)
+ (void)printf("New\n");
+ else {
+ tomorrow = potm(days + 1);
+ if ((int)today == 50)
+ (void)printf("%s\n", tomorrow > today ?
+ "at the First Quarter" : "at the Last Quarter");
+ else {
+ (void)printf("%s ", tomorrow > today ?
+ "Waxing" : "Waning");
+ if (today > 50)
+ (void)printf("Gibbous (%1.0f%% of Full)\n",
+ today);
+ else if (today < 50)
+ (void)printf("Crescent (%1.0f%% of Full)\n",
+ today);
+ }
+ }
+
+ return 0;
}
/*
-* potm --
-* return phase of the moon
-*/
+ * potm --
+ * return phase of the moon
+ */
static double
potm(double days)
{
-double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
-double A4, lprime, V, ldprime, D, Nm;
+ double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
+ double A4, lprime, V, ldprime, D, Nm;
-N = 360 * days / 365.2422; /* sec 42 #3 */
-adj360(&N);
-Msol = N + EPSILONg - RHOg; /* sec 42 #4 */
-adj360(&Msol);
-Ec = 360 / PI * ECCEN * sin(dtor(Msol)); /* sec 42 #5 */
-LambdaSol = N + Ec + EPSILONg; /* sec 42 #6 */
-adj360(&LambdaSol);
-l = 13.1763966 * days + lzero; /* sec 61 #4 */
-adj360(&l);
-Mm = l - (0.1114041 * days) - Pzero; /* sec 61 #5 */
-adj360(&Mm);
-Nm = Nzero - (0.0529539 * days); /* sec 61 #6 */
-adj360(&Nm);
-Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm)); /* sec 61 #7 */
-Ac = 0.1858 * sin(dtor(Msol)); /* sec 61 #8 */
-A3 = 0.37 * sin(dtor(Msol));
-Mmprime = Mm + Ev - Ac - A3; /* sec 61 #9 */
-Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 61 #10 */
-A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 61 #11 */
-lprime = l + Ev + Ec - Ac + A4; /* sec 61 #12 */
-V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 61 #13 */
-ldprime = lprime + V; /* sec 61 #14 */
-D = ldprime - LambdaSol; /* sec 63 #2 */
-return(50 * (1 - cos(dtor(D)))); /* sec 63 #3 */
+ N = 360 * days / 365.2422; /* sec 42 #3 */
+ adj360(&N);
+ Msol = N + EPSILONg - RHOg; /* sec 42 #4 */
+ adj360(&Msol);
+ Ec = 360 / PI * ECCEN * sin(dtor(Msol)); /* sec 42 #5 */
+ LambdaSol = N + Ec + EPSILONg; /* sec 42 #6 */
+ adj360(&LambdaSol);
+ l = 13.1763966 * days + lzero; /* sec 61 #4 */
+ adj360(&l);
+ Mm = l - (0.1114041 * days) - Pzero; /* sec 61 #5 */
+ adj360(&Mm);
+ Nm = Nzero - (0.0529539 * days); /* sec 61 #6 */
+ adj360(&Nm);
+ Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm)); /* sec 61 #7 */
+ Ac = 0.1858 * sin(dtor(Msol)); /* sec 61 #8 */
+ A3 = 0.37 * sin(dtor(Msol));
+ Mmprime = Mm + Ev - Ac - A3; /* sec 61 #9 */
+ Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 61 #10 */
+ A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 61 #11 */
+ lprime = l + Ev + Ec - Ac + A4; /* sec 61 #12 */
+ V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 61 #13 */
+ ldprime = lprime + V; /* sec 61 #14 */
+ D = ldprime - LambdaSol; /* sec 63 #2 */
+ return(50 * (1 - cos(dtor(D)))); /* sec 63 #3 */
}
/*
-* dtor --
-* convert degrees to radians
-*/
+ * dtor --
+ * convert degrees to radians
+ */
static double
dtor(double deg)
{
-return(deg * PI / 180);
+
+ return(deg * PI / 180);
}
/*
-* adj360 --
-* adjust value so 0 <= deg <= 360
-*/
+ * adj360 --
+ * adjust value so 0 <= deg <= 360
+ */
static void
adj360(double *deg)
{
-for (;;)
-if (*deg < 0)
-*deg += 360;
-else if (*deg > 360)
-*deg -= 360;
-else
-break;
+
+ for (;;)
+ if (*deg < 0)
+ *deg += 360;
+ else if (*deg > 360)
+ *deg -= 360;
+ else
+ break;
}
+
+static void
+usage(char *progname)
+{
+
+ fprintf(stderr, "Usage: %s [-p] [-d yyyy.mm.dd] [-t hh:mm:ss]\n",
+ progname);
+ exit(EX_USAGE);
+}
More information about the Midnightbsd-cvs
mailing list