Add -p option to have pom(6) print just the percentage, without extra text.

PR:		bin/51070
Submitted by:	Matt Koivisto mkoivisto sandvine com
MFC after:	1 week
This commit is contained in:
emaste 2010-07-15 00:16:04 +00:00
parent fc51f07699
commit 5cf2e8608d
2 changed files with 17 additions and 4 deletions

View File

@ -32,7 +32,7 @@
.\" @(#)pom.6 8.1 (Berkeley) 5/31/93
.\" $FreeBSD$
.\"
.Dd May 31, 1993
.Dd July 14, 2010
.Dt POM 6
.Os
.Sh NAME
@ -40,6 +40,7 @@
.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
@ -49,6 +50,10 @@ 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

View File

@ -84,14 +84,17 @@ main(int argc, char **argv)
time_t tt;
struct tm GMT, tmd;
double days, today, tomorrow;
int ch, cnt;
int ch, cnt, pflag = 0;
char *odate = NULL, *otime = NULL;
while ((ch = getopt(argc, argv, "d:t:")) != -1)
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;
@ -134,6 +137,10 @@ main(int argc, char **argv)
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");
@ -227,6 +234,7 @@ static void
usage(char *progname)
{
fprintf(stderr, "Usage: %s [-d yyyy.mm.dd] [-t hh:mm:ss]\n", progname);
fprintf(stderr, "Usage: %s [-p] [-d yyyy.mm.dd] [-t hh:mm:ss]\n",
progname);
exit(EX_USAGE);
}