From owner-svn-src-head@FreeBSD.ORG Wed Nov 9 01:40:47 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40BC31065676; Wed, 9 Nov 2011 01:40:47 +0000 (UTC) (envelope-from grog@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2FE5F8FC0C; Wed, 9 Nov 2011 01:40:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pA91elb1058501; Wed, 9 Nov 2011 01:40:47 GMT (envelope-from grog@svn.freebsd.org) Received: (from grog@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pA91elaY058496; Wed, 9 Nov 2011 01:40:47 GMT (envelope-from grog@svn.freebsd.org) Message-Id: <201111090140.pA91elaY058496@svn.freebsd.org> From: Greg Lehey Date: Wed, 9 Nov 2011 01:40:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r227370 - head/usr.bin/calendar X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2011 01:40:47 -0000 Author: grog Date: Wed Nov 9 01:40:46 2011 New Revision: 227370 URL: http://svn.freebsd.org/changeset/base/227370 Log: Tidy up command line processing: - Add ? option to optstring. - Sort options alphabetically. - Vertical space. Tidy up usage() function. Bring man page in sync with source. Ensure that debug code is only executed with the -d option. Submitted by: Christiane Yeardley Modified: head/usr.bin/calendar/calendar.1 head/usr.bin/calendar/calendar.c head/usr.bin/calendar/io.c head/usr.bin/calendar/parsedata.c Modified: head/usr.bin/calendar/calendar.1 ============================================================================== --- head/usr.bin/calendar/calendar.1 Tue Nov 8 23:54:39 2011 (r227369) +++ head/usr.bin/calendar/calendar.1 Wed Nov 9 01:40:46 2011 (r227370) @@ -36,11 +36,14 @@ .Nd reminder service .Sh SYNOPSIS .Nm -.Op Fl a .Op Fl A Ar num +.Op Fl a .Op Fl B Ar num +.Op Fl D Ar moon|sun +.Op Fl d .Op Fl F Ar friday .Op Fl f Ar calendarfile +.Op Fl l Ar longitude .Oo .Bk -words .Fl t Ar dd Ns @@ -49,16 +52,14 @@ .Sm on .Ek .Oc -.Op Fl W Ar num .Op Fl U Ar UTC-offset -.Op Fl l Ar longitude +.Op Fl W Ar num .Sh DESCRIPTION The .Nm utility checks the current directory for a file named .Pa calendar -and displays lines that begin with either today's date -or tomorrow's. +and displays lines that fall into the specified date range. On the day before a weekend (normally Friday), events for the next three days are displayed. .Pp @@ -76,6 +77,10 @@ This requires super-user privileges. Print lines from today and the previous .Ar num days (backward, past). +.It Fl D Ar moon|sun +Print UTC offset, longitude and moon or sun information. +.It Fl d +Debug option: print current date information. .It Fl F Ar friday Specify which day of the week is ``Friday'' (the day before the weekend begins). @@ -84,6 +89,11 @@ Default is 5. Use .Pa calendarfile as the default calendar file. +.It Fl l Ar longitude +Perform lunar and solar calculations from this longitude. +If neither longitude nor UTC offset is specified, the calculations will +be based on the difference between UTC time and localtime. +If both are specified, UTC offset overrides longitude. .It Xo Fl t .Sm off .Ar dd @@ -91,12 +101,11 @@ as the default calendar file. .Sm on .Xc For test purposes only: set date directly to argument values. -.It Fl l Ar longitude , Fl U Ar UTC-offset -Only one is needed: -Perform lunar and solar calculations from this longitude or from -this UTC offset. -If neither is specified, the calculations will be based on the -difference between UTC time and localtime. +.It Fl U Ar UTC-offset +Perform lunar and solar calculations from this UTC offset. +If neither UTC offset nor longitude is specified, the calculations +will be based on the difference between UTC time and localtime. +If both are specified, UTC offset overrides longitude. .It Fl W Ar num Print lines from today and the next .Ar num Modified: head/usr.bin/calendar/calendar.c ============================================================================== --- head/usr.bin/calendar/calendar.c Tue Nov 8 23:54:39 2011 (r227369) +++ head/usr.bin/calendar/calendar.c Wed Nov 9 01:40:46 2011 (r227370) @@ -35,7 +35,7 @@ static const char copyright[] = #if 0 #ifndef lint -static char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; +static char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #endif #endif @@ -79,7 +79,7 @@ main(int argc, char *argv[]) (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "-A:aB:dD:F:f:l:t:U:W:")) != -1) + while ((ch = getopt(argc, argv, "-A:aB:D:dF:f:l:t:U:W:?")) != -1) switch (ch) { case '-': /* backward contemptible */ case 'a': @@ -90,10 +90,6 @@ main(int argc, char *argv[]) doall = 1; break; - case 'f': /* other calendar file */ - calendarFile = optarg; - break; - case 'W': /* we don't need no steenking Fridays */ Friday = -1; /* FALLTHROUGH */ @@ -106,26 +102,34 @@ main(int argc, char *argv[]) f_dayBefore = atoi(optarg); break; + case 'D': /* debug output of sun and moon info */ + DEBUG = optarg; + break; + + case 'd': /* debug output of current date */ + debug = 1; + break; + case 'F': /* Change the time: When does weekend start? */ Friday = atoi(optarg); break; + + case 'f': /* other calendar file */ + calendarFile = optarg; + break; + case 'l': /* Change longitudal position */ EastLongitude = strtol(optarg, NULL, 10); break; - case 'U': /* Change UTC offset */ - UTCOffset = strtod(optarg, NULL); - break; - case 'd': - debug = 1; - break; - case 'D': - DEBUG = optarg; - break; - case 't': /* other date, undocumented, for tests */ + case 't': /* other date, for tests */ f_time = Mktime(optarg); break; + case 'U': /* Change UTC offset */ + UTCOffset = strtod(optarg, NULL); + break; + case '?': default: usage(); @@ -216,10 +220,9 @@ usage(void) { fprintf(stderr, "%s\n%s\n%s\n", - "usage: calendar [-a] [-A days] [-B days] [-F friday] " - "[-f calendarfile]", - " [-d] [-t dd[.mm[.year]]] [-W days]", - " [-U utcoffset] [-l longitude]" + "usage: calendar [-A days] [-a] [-B days] [-D sun|moon] [-d]", + " [-F friday] [-f calendarfile] [-l longitude]", + " [-t dd[.mm[.year]]] [-U utcoffset] [-W days]" ); exit(1); } Modified: head/usr.bin/calendar/io.c ============================================================================== --- head/usr.bin/calendar/io.c Tue Nov 8 23:54:39 2011 (r227369) +++ head/usr.bin/calendar/io.c Wed Nov 9 01:40:46 2011 (r227370) @@ -176,7 +176,8 @@ cal(void) *pp = p; if (count < 0) { /* Show error status based on return value */ - fprintf(stderr, "Ignored: %s\n", buf); + if (debug) + fprintf(stderr, "Ignored: %s\n", buf); if (count == -1) continue; count = -count + 1; Modified: head/usr.bin/calendar/parsedata.c ============================================================================== --- head/usr.bin/calendar/parsedata.c Tue Nov 8 23:54:39 2011 (r227369) +++ head/usr.bin/calendar/parsedata.c Wed Nov 9 01:40:46 2011 (r227370) @@ -10,7 +10,7 @@ * 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. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 @@ -22,7 +22,7 @@ * 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. - * + * */ #include @@ -79,7 +79,7 @@ static char *floattotime(double f); * '300' ... '359' | '360' ... '365' * ModifierIndex ::= 'Second' | 'Third' | 'Fourth' | 'Fifth' | * 'First' | 'Last' - * + * * SpecialDay ::= 'Easter' | 'Paskha' | 'ChineseNewYear' * */ @@ -313,7 +313,7 @@ fail: allfine: *p = pold; return (1); - + } static void @@ -407,7 +407,7 @@ parsedaymonth(char *date, int *yearp, in * * Month: 1-12 * Monthname: Jan .. Dec - * Day: 1-31 + * Day: 1-31 * Weekday: Mon .. Sun * */ @@ -754,10 +754,13 @@ parsedaymonth(char *date, int *yearp, in continue; } - printf("Unprocessed:\n"); - debug_determinestyle(2, date, lflags, month, imonth, - dayofmonth, idayofmonth, dayofweek, idayofweek, - modifieroffset, modifierindex, specialday, syear, iyear); + if (debug) { + printf("Unprocessed:\n"); + debug_determinestyle(2, date, lflags, month, imonth, + dayofmonth, idayofmonth, dayofweek, idayofweek, + modifieroffset, modifierindex, specialday, syear, + iyear); + } retvalsign = -1; } @@ -1045,7 +1048,7 @@ dodebug(char *what) printf("\n"); } - + return; }