svn commit: r204984 - user/edwin/ncal

Edwin Groothuis edwin at FreeBSD.org
Wed Mar 10 22:10:36 UTC 2010


Author: edwin
Date: Wed Mar 10 22:10:36 2010
New Revision: 204984
URL: http://svn.freebsd.org/changeset/base/204984

Log:
  Style police - update the comments in the code.

Modified:
  user/edwin/ncal/ncal.c

Modified: user/edwin/ncal/ncal.c
==============================================================================
--- user/edwin/ncal/ncal.c	Wed Mar 10 21:45:40 2010	(r204983)
+++ user/edwin/ncal/ncal.c	Wed Mar 10 22:10:36 2010	(r204984)
@@ -167,21 +167,21 @@ int	highlightdate;
 
 char	*center(char *s, char *t, int w);
 wchar_t *wcenter(wchar_t *s, wchar_t *t, int w);
+int	firstday(int y, int m);
+void	highlight(char *dst, char *src, int len, int *extraletters);
 void	mkmonthr(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);
+void	monthranger(int year, int m, int jd_flag, int before, int after);
+void	monthrangeb(int year, int m, int jd_flag, int before, int after);
 int	parsemonth(const char *s, int *m, int *y);
 void	printcc(void);
 void	printeaster(int year, int julian, int orthodox);
-int	firstday(int y, int m);
 date	*sdater(int ndays, struct date * d);
 date	*sdateb(int ndays, struct date * d);
 int	sndaysr(struct date * d);
 int	sndaysb(struct date * d);
 static void	usage(void);
-void	monthranger(int year, int jd_flag, int m, int before, int after);
-void	monthrangeb(int year, int jd_flag, int m, int before, int after);
-void	highlight(char *dst, char *src, int len, int *extraletters);
 
 int
 main(int argc, char *argv[])
@@ -391,40 +391,53 @@ main(int argc, char *argv[])
 	}
 
 	/*
-	 * What do we support and what do we not support
-	 * flag_3month, flag_before, flag_after
-	 * flag_givenyear, flag_givenmonth
-	 * 
+	 * What is not supported:
+	 * -3 with -A or -B
+	 *	-3 displays 3 months, -A and -B change that behaviour.
+	 * -3 with -y
+	 *	-3 displays 3 months, -y says display a whole year.
+	 * -3 with a given year but no given month or without -m
+	 *	-3 displays 3 months, no month specified doesn't make clear
+	 *      which three months.
+	 * -m with a given month
+	 *	conflicting arguments, both specify the same field.
+	 * -y with -m
+	 *	-y displays the whole year, -m displays a single month.
+	 * -y with a given month
+	 *	-y displays the whole year, the given month displays a single
+	 *	month.
+	 * -y with -A or -B
+	 *	-y displays the whole year, -A and -B display extra months.
 	 */
 
-	/* -3 together with -A or -B */
+	/* -3 together with -A or -B. */
 	if (flag_3months && (flag_after || flag_before))
 		errx(EX_USAGE, "-3 together with -A and -B is not supported.");
-	/* -3 together with -y */
+	/* -3 together with -y. */
 	if (flag_3months && flag_wholeyear)
 		errx(EX_USAGE, "-3 together with -y is not supported.");
-	/* -3 together with givenyear but no givenmonth */
+	/* -3 together with givenyear but no givenmonth. */
 	if (flag_3months && flag_givenyear &&
 	    !(flag_givenmonth || flag_specifiedmonth))
 		errx(EX_USAGE,
 		    "-3 together with a given year but no given month is "
 		    "not supported.");
-	/* -m together with xx xxxx */
+	/* -m together with xx xxxx. */
 	if (flag_specifiedmonth && flag_givenmonth)
 		errx(EX_USAGE,
 		    "-m together with a given month is not supported.");
-	/* -y together with -m */
+	/* -y together with -m. */
 	if (flag_wholeyear && flag_specifiedmonth)
 		errx(EX_USAGE, "-y together with -m is not supported.");
-	/* -y together with xx xxxx */
+	/* -y together with xx xxxx. */
 	if (flag_wholeyear && flag_givenmonth)
 		errx(EX_USAGE, "-y together a given month is not supported.");
-	/* -y together with -A or -B */
+	/* -y together with -A or -B. */
 	if (flag_wholeyear && (flag_before > 0 || flag_after > 0))
 		errx(EX_USAGE, "-y together a -A or -B is not supported.");
-	/* The rest should be fine */
+	/* The rest should be fine. */
 
-	/* Select the period to display, in order of increasing priority */
+	/* Select the period to display, in order of increasing priority .*/
 	if (flag_wholeyear ||
 	    (flag_givenyear && !(flag_givenmonth || flag_specifiedmonth))) {
 		m = 1;
@@ -454,7 +467,7 @@ main(int argc, char *argv[])
 	if (before == -1)
 		before = 0;
 
-	/* Highlight a specified day or today */
+	/* Highlight a specified day or today .*/
 	if (flag_highlightdate != NULL) {
 		dt.y = strtol(flag_highlightdate, NULL, 10);
 		dt.m = strtol(flag_highlightdate + 5, NULL, 10);
@@ -471,13 +484,14 @@ main(int argc, char *argv[])
 	}
 	highlightdate = sndaysb(&dt);
 
+	/* And now we finally start to calculate and output calendars. */
 	if (flag_easter)
 		printeaster(y, flag_julian_cal, flag_orthodox);
 	else
 		if (flag_backward)
-			monthrangeb(y, flag_julian_day, m, before, after);
+			monthrangeb(y, m, flag_julian_day, before, after);
 		else
-			monthranger(y, flag_julian_day, m, before, after);
+			monthranger(y, m, flag_julian_day, before, after);
 	return (0);
 }
 
@@ -495,7 +509,7 @@ usage(void)
 	exit(EX_USAGE);
 }
 
-/* print the assumed switches for all countries */
+/* Print the assumed switches for all countries. */
 void
 printcc(void)
 {
@@ -516,7 +530,7 @@ printcc(void)
 		printf(FSTR"\n", FSTRARG(p));
 }
 
-/* print the date of easter sunday */
+/* Print the date of easter sunday. */
 void
 printeaster(int y, int julian, int orthodox)
 {
@@ -561,8 +575,9 @@ printeaster(int y, int julian, int ortho
 #define	M2Y(m)	((m) / 12)
 #define	M2M(m)	(1 + (m) % 12) 
 
+/* Print all months for the period in the range [ before .. y-m .. after ]. */
 void
-monthrangeb(int y, int jd_flag, int m, int before, int after)
+monthrangeb(int y, int m, int jd_flag, int before, int after)
 {
 	struct monthlines year[12];
 	struct weekdays wds;
@@ -609,14 +624,14 @@ monthrangeb(int y, int jd_flag, int m, i
 		if (m != m1)
 			printf("\n");
 
-		/* Year at the top */
+		/* Year at the top. */
 		if (printyearheader && M2Y(m) != prevyear) {
 			sprintf(s, "%d", M2Y(m));
 			printf("%s\n", center(t, s, mpl * mw));
 			prevyear = M2Y(m);
 		}
 
-		/* Month names */
+		/* Month names. */
 		for (i = 0; i < count; i++)
 			if (printyearheader)
 				wprintf(L"%-*ls  ",
@@ -628,7 +643,7 @@ monthrangeb(int y, int jd_flag, int m, i
 			}
 		printf("\n");
 
-		/* Day of the week names */
+		/* Day of the week names. */
 		for (i = 0; i < count; i++) {
 			wprintf(L"%s%ls%s%ls%s%ls%s%ls%s%ls%s%ls%s%ls ",
 				wdss, wds.names[6], wdss, wds.names[0],
@@ -638,6 +653,7 @@ monthrangeb(int y, int jd_flag, int m, i
 		}
 		printf("\n");
 
+		/* And the days of the month. */
 		for (i = 0; i != 6; i++) {
 			for (j = 0; j < count; j++)
 				printf("%-*s  ",
@@ -651,7 +667,7 @@ monthrangeb(int y, int jd_flag, int m, i
 }
 
 void
-monthranger(int y, int jd_flag, int m, int before, int after)
+monthranger(int y, int m, int jd_flag, int before, int after)
 {
 	struct monthlines year[12];
 	struct weekdays wds;
@@ -691,18 +707,18 @@ monthranger(int y, int jd_flag, int m, i
 			count++;
 		}
 
-		/* Empty line between two rows of months */
+		/* Empty line between two rows of months. */
 		if (m != m1)
 			printf("\n");
 
-		/* Year at the top */
+		/* Year at the top. */
 		if (printyearheader && M2Y(m) != prevyear) {
 			sprintf(s, "%d", M2Y(m));
 			printf("%s\n", center(t, s, mpl * mw));
 			prevyear = M2Y(m);
 		}
 
-		/* Month names */
+		/* Month names. */
 		wprintf(L"    ");
 		for (i = 0; i < count; i++)
 			if (printyearheader)
@@ -712,6 +728,7 @@ monthranger(int y, int jd_flag, int m, i
 				    mw - wcslen(year[i].name) - 1, M2Y(m + i));
 		printf("\n");
 
+		/* And the days of the month. */
 		for (i = 0; i != 7; i++) {
 			/* Week day */
 			wprintf(L"%.2ls", wds.names[i]);
@@ -724,6 +741,7 @@ monthranger(int y, int jd_flag, int m, i
 			printf("\n");
 		}
 
+		/* Week numbers. */
 		if (flag_weeks) {
 			printf("  ");
 			for (i = 0; i < count; i++)
@@ -779,7 +797,7 @@ mkmonthr(int y, int m, int jd_flag, stru
 	 */
 	firstm = first - weekday(first);
 
-	/* Set ds (daystring) and dw (daywidth) according to the jd_flag */
+	/* Set ds (daystring) and dw (daywidth) according to the jd_flag. */
 	if (jd_flag) {
 		ds = jdaystr;
 		dw = 4;
@@ -814,7 +832,7 @@ mkmonthr(int y, int m, int jd_flag, stru
 		mlines->extralen[i] = l;
 	}
 
-	/* fill the weeknumbers */
+	/* fill the weeknumbers. */
 	if (flag_weeks) {
 		for (j = firstm, k = 0; j < last;  k += dw, j += 7)
 			if (j <= nswitch)
@@ -851,7 +869,7 @@ mkmonthb(int y, int m, int jd_flag, stru
 		dw = 3;
 	}
 
-	/* Set name of month centered */
+	/* Set name of month centered. */
 	memset(&tm, 0, sizeof(tm));
 	tm.tm_mon = m;
 	wcsftime(mlines->name, sizeof(mlines->name) / sizeof(mlines->name[0]),
@@ -922,7 +940,7 @@ mkmonthb(int y, int m, int jd_flag, stru
 	}
 }
 
-/* Put the local names of weekdays into the wds */
+/* Put the local names of weekdays into the wds. */
 void
 mkweekdays(struct weekdays *wds)
 {
@@ -948,9 +966,8 @@ mkweekdays(struct weekdays *wds)
 }
 
 /*
- * Compute the day number of the first
- * existing date after the first day in month.
- * (the first day in month and even the month might not exist!)
+ * Compute the day number of the first existing date after the first day in
+ * month. (the first day in month and even the month might not exist!)
  */
 int
 firstday(int y, int m)
@@ -1003,7 +1020,7 @@ sndaysb(struct date *d)
 		return (ndaysj(d));
 }
 
-/* Inverse of sndays */
+/* Inverse of sndays. */
 struct date *
 sdater(int nd, struct date *d)
 {
@@ -1014,7 +1031,7 @@ sdater(int nd, struct date *d)
 		return (jdate(nd, d));
 }
 
-/* Inverse of sndaysb */
+/* Inverse of sndaysb. */
 struct date *
 sdateb(int nd, struct date *d)
 {
@@ -1025,7 +1042,7 @@ sdateb(int nd, struct date *d)
 		return (jdate(nd, d));
 }
 
-/* Center string t in string s of length w by putting enough leading blanks */
+/* Center string t in string s of length w by putting enough leading blanks. */
 char *
 center(char *s, char *t, int w)
 {
@@ -1036,7 +1053,7 @@ center(char *s, char *t, int w)
 	return (s);
 }
 
-/* Center string t in string s of length w by putting enough leading blanks */
+/* Center string t in string s of length w by putting enough leading blanks. */
 wchar_t *
 wcenter(wchar_t *s, wchar_t *t, int w)
 {
@@ -1091,7 +1108,7 @@ highlight(char *dst, char *src, int len,
 
 		term_se = term_so = NULL;
 
-		/* On how to highlight on this type of terminal (if any) */
+		/* On how to highlight on this type of terminal (if any). */
 		if (isatty(STDOUT_FILENO) && tgetent(tbuf, NULL) == 1) {
 			b = cbuf;
 			term_so = tgetstr("so", &b);
@@ -1110,42 +1127,45 @@ highlight(char *dst, char *src, int len,
 		return;
 	}
 
-	/* If it is a real terminal, use the data from the termcap database. */
+	/*
+	 * If it is a real terminal, use the data from the termcap database.
+	 */
 	if (term_so != NULL && term_se != NULL) {
-		/* separator */
+		/* separator. */
 		dst[0] = ' ';
 		dst++;
-		/* highlight on */
+		/* highlight on. */
 		memcpy(dst, term_so, strlen(term_so));
 		dst += strlen(term_so);
-		/* the actual text (minus leading space) */
+		/* the actual text. (minus leading space) */
 		len--;
 		src++;
 		memcpy(dst, src, len);
 		dst += len;
-		/* highlight off */
+		/* highlight off. */
 		memcpy(dst, term_se, strlen(term_se));
 		*extralen = strlen(term_so) + strlen(term_se);
 		return;
 	}
 
 	/*
-	 * Otherwise, print a _, backspace and the letter
+	 * Otherwise, print a _, backspace and the letter.
 	 */
 	*extralen = 0;
-	/* skip leading space */
+	/* skip leading space. */
 	src++;
 	len--;
-	/* separator */
+	/* separator. */
 	dst[0] = ' ';
 	dst++;
 	while (len > 0) {
-		/* _ and backspace */
+		/* _ and backspace. */
 		memcpy(dst, "_\010", 2);
 		dst += 2;
 		*extralen += 2;
-		/* the character */
+		/* the character. */
 		*dst++ = *src++;
 		len--;
 	}
+	return;
 }


More information about the svn-src-user mailing list