Author: wollman
Date: Mon Dec 22 21:22:42 2008
New Revision: 186401
URL: http://svn.freebsd.org/changeset/base/186401

Log:
  Implement a new feature for the "-m" option: if the month number is
  followed by 'f' or 'p', use the following or preceding month of that
  number, respectively.  Document this.  Also includes other minor
  grammatical and punctuation fixes to the manual page (capitalize
  Easter, etc.).
  
  MFC after:    1 month

Modified:
  head/usr.bin/ncal/ncal.1
  head/usr.bin/ncal/ncal.c

Modified: head/usr.bin/ncal/ncal.1
==============================================================================
--- head/usr.bin/ncal/ncal.1    Mon Dec 22 20:38:00 2008        (r186400)
+++ head/usr.bin/ncal/ncal.1    Mon Dec 22 21:22:42 2008        (r186401)
@@ -30,7 +30,7 @@
 .Sh NAME
 .Nm cal ,
 .Nm ncal
-.Nd displays a calendar and the date of easter
+.Nd displays a calendar and the date of Easter
 .Sh SYNOPSIS
 .Nm
 .Op Fl jy
@@ -57,7 +57,7 @@ The
 .Nm
 utility displays a simple calendar in traditional format and
 .Nm ncal
-offers an alternative layout, more options and the date of easter.
+offers an alternative layout, more options and the date of Easter.
 The new format is a little cramped but it makes a year fit
 on a 25x80 terminal.
 If arguments are not specified,
@@ -68,16 +68,24 @@ The options are as follows:
 .It Fl J
 Display Julian Calendar, if combined with the
 .Fl e
-option, display date of easter according to the Julian Calendar.
+option, display date of Easter according to the Julian Calendar.
 .It Fl e
-Display date of easter (for western churches).
+Display date of Easter (for western churches).
 .It Fl j
 Display Julian days (days one-based, numbered from January 1).
 .It Fl m Ar month
 Display the specified
 .Ar month .
+If
+.Ar month
+is specified as a decimal number, it may be followed by the letter
+.Ql f
+or
+.Ql p
+to indicate the following or preceding month of that number,
+respectively.
 .It Fl o
-Display date of orthodox easter (Greek and Russian
+Display date of Orthodox Easter (Greek and Russian
 Orthodox Churches).
 .It Fl p
 Print the country codes and switching days from Julian to Gregorian
@@ -101,7 +109,7 @@ Print the number of the week below each 
 Display a calendar for the specified year.
 .El
 .Pp
-A single parameter specifies the year (1 - 9999) to be displayed;
+A single parameter specifies the year (1\(en9999) to be displayed;
 note the year must be fully specified:
 .Dq Li cal 89
 will
@@ -113,7 +121,7 @@ Month and year default to those of the c
 .Dq Li cal -m 8
 will display a calendar for the month of August in the current year).
 .Pp
-A year starts on Jan 1.
+A year starts on January 1.
 .Sh SEE ALSO
 .Xr calendar 3 ,
 .Xr strftime 3
@@ -132,7 +140,7 @@ The
 command and manual were written by
 .An Wolfgang Helbig Aq hel...@freebsd.org .
 .Sh BUGS
-The assignment of Julian\(emGregorian switching dates to
+The assignment of Julian\(enGregorian switching dates to
 country codes is historically naive for many countries.
 .Pp
 The

Modified: head/usr.bin/ncal/ncal.c
==============================================================================
--- head/usr.bin/ncal/ncal.c    Mon Dec 22 20:38:00 2008        (r186400)
+++ head/usr.bin/ncal/ncal.c    Mon Dec 22 21:22:42 2008        (r186401)
@@ -162,7 +162,7 @@ char   *center(char *s, char *t, int w);
 void   mkmonth(int year, int month, int jd_flag, struct monthlines * monthl);
 void    mkmonthb(int year, int month, int jd_flag, struct monthlines * monthl);
 void    mkweekdays(struct weekdays * wds);
-int     parsemonth(const char *s);
+int     parsemonth(const char *s, int *m, int *y);
 void    printcc(void);
 void    printeaster(int year, int julian, int orthodox);
 void    printmonth(int year, int month, int jd_flag);
@@ -322,11 +322,11 @@ main(int argc, char *argv[])
        }
 
        if (flag_month != NULL) {
-               m = parsemonth(flag_month);
-               if (m < 1 || m > 12)
+               if (parsemonth(flag_month, &m, &y)) {
                        errx(EX_USAGE,
                            "%s is neither a month number (1..12) nor a name",
                            flag_month);
+               }
        }
 
        if (flag_easter)
@@ -859,18 +859,34 @@ center(char *s, char *t, int w)
 }
 
 int
-parsemonth(const char *s)
+parsemonth(const char *s, int *m, int *y)
 {
-       int v;
+       int nm, ny;
        char *cp;
        struct tm tm;
 
-       v = (int)strtol(s, &cp, 10);
-       if (cp != s)
-               return (v);
-       if (strptime(s, "%B", &tm) != NULL)
-               return (tm.tm_mon + 1);
-       if (strptime(s, "%b", &tm) != NULL)
-               return (tm.tm_mon + 1);
-       return (0);
+       nm = (int)strtol(s, &cp, 10);
+       if (cp != s) {
+               ny = *y;
+               if (*cp == '\0') {
+                       ;       /* no special action */
+               } else if (*cp == 'f' || *cp == 'F') {
+                       if (nm <= *m)
+                               ny++;
+               } else if (*cp == 'p' || *cp == 'P') {
+                       if (nm >= *m)
+                               ny--;
+               } else
+                       return (1);
+               if (nm < 1 || nm > 12)
+                       return 1;
+               *m = nm;
+               *y = ny;
+               return (0);
+       }
+       if (strptime(s, "%B", &tm) != NULL || strptime(s, "%b", &tm) != NULL) {
+               *m = tm.tm_mon + 1;
+               return (0);
+       }
+       return (1);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to