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 <sys/cdefs.h>
@@ -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;
        }
 
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to