* [PATCH 00/16]: [pull] cal: second review round
@ 2013-05-02 18:51 Sami Kerola
2013-05-02 18:51 ` [PATCH 01/16] cal: fix preprocessor directive indendation Sami Kerola
` (15 more replies)
0 siblings, 16 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 2861 bytes --]
Hello all,
Here comes cal(1) patch series II. There is a lot of similarities, and
some changes since last submission. The previous patch series is still
available in my git (branch 2013wk16), which should make comparing every
single small detail quite trivial. IMHO the most significant changes in
between the two submissions are:
o Copy argmatch.h and argmatch.c from gnulib to util-linux.
o Add --highlight={never,auto,always} option.
o Add new option to usage(), and clean it up.
o Remove trailing space trimming.
All the changes are based on feedback from Pádraig, Thomas, Dave, and
Karel. Thank you for pointing me to correct direction, and please have
look if I'm still a bit lost.
The following changes since commit a48c321dd175d043fb4572bab625631b2055075e:
textual: fixing typos in a warning and an error message (2013-04-26 13:55:29 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git cal-new
for you to fetch changes up to 2b491019173dc2eda3a0d014e9adb3dec54e41bc:
cal: simplify day_in_week() (2013-05-02 19:30:16 +0100)
----------------------------------------------------------------
Sami Kerola (16):
cal: fix preprocessor directive indendation
cal: convert function like definitions to functions
cal: clean up use of constants
tests: add calendar reformation check
cal: simplify calendar reformat calculations
cal: remove unnecessary initializations
cal: de-duplicate julian specific functions
lib: copy argmatch from gnulib
cal: add --highligth option which uses argmatch
cal: add --highlight to usage()
docs: cal: add --highlight option description
tests: add cal day highlight corner cases
cal: stop trimming whitespaces
cal: move global variables to local scope
cal: mark all functions static
cal: simplify day_in_week()
include/Makemodule.am | 1 +
include/argmatch.h | 100 ++++++++
lib/Makemodule.am | 1 +
lib/argmatch.c | 272 ++++++++++++++++++++
misc-utils/Makemodule.am | 2 +-
misc-utils/cal.1 | 13 +
misc-utils/cal.c | 597 ++++++++++++++++++++++---------------------
tests/expected/cal/1m | 48 ++--
tests/expected/cal/3m | 48 ++--
tests/expected/cal/highlight | 55 ++++
tests/expected/cal/sep1752 | 198 ++++++++++++++
tests/expected/cal/year | 240 ++++++++---------
tests/ts/cal/highlight | 70 +++++
tests/ts/cal/sep1752 | 95 +++++++
14 files changed, 1274 insertions(+), 466 deletions(-)
create mode 100644 include/argmatch.h
create mode 100644 lib/argmatch.c
create mode 100644 tests/expected/cal/highlight
create mode 100644 tests/expected/cal/sep1752
create mode 100755 tests/ts/cal/highlight
create mode 100755 tests/ts/cal/sep1752
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH 01/16] cal: fix preprocessor directive indendation
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 02/16] cal: convert function like definitions to functions Sami Kerola
` (14 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
And code within the blocks selected by preprocessor to be live code.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 81 +++++++++++++++++++++++++++-----------------------------
1 file changed, 39 insertions(+), 42 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 276148d..13830de 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -73,69 +73,66 @@
#include "strutils.h"
#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW)
-
-#ifdef HAVE_NCURSES_H
-#include <ncurses.h>
-#elif defined(HAVE_NCURSES_NCURSES_H)
-#include <ncurses/ncurses.h>
-#endif
-
-#include <term.h> /* include after <curses.h> */
-
-static void
-my_setupterm(const char *term, int fildes, int *errret) {
- setupterm((char*)term, fildes, errret);
+# ifdef HAVE_NCURSES_H
+# include <ncurses.h>
+# elif defined(HAVE_NCURSES_NCURSES_H)
+# include <ncurses/ncurses.h>
+# endif
+# include <term.h>
+
+static void my_setupterm(const char *term, int fildes, int *errret)
+{
+ setupterm((char *)term, fildes, errret);
}
-static void
-my_putstring(char *s) {
- putp(s);
+static void my_putstring(char *s)
+{
+ putp(s);
}
-static const char *
-my_tgetstr(char *s __attribute__ ((__unused__)), char *ss) {
- const char* ret = tigetstr(ss);
- if (!ret || ret==(char*)-1)
- return "";
- else
- return ret;
+static const char *my_tgetstr(char *s __attribute__((__unused__)), char *ss)
+{
+ const char *ret = tigetstr(ss);
+ if (!ret || ret == (char *)-1)
+ return "";
+ else
+ return ret;
}
#elif defined(HAVE_LIBTERMCAP)
-
-#include <termcap.h>
+# include <termcap.h>
char termbuffer[4096];
char tcbuffer[4096];
char *strbuf = termbuffer;
-static void
-my_setupterm(const char *term, int fildes, int *errret) {
- *errret = tgetent(tcbuffer, term);
+static void my_setupterm(const char *term, int fildes, int *errret)
+{
+ *errret = tgetent(tcbuffer, term);
}
-static void
-my_putstring(char *s) {
- tputs (s, 1, putchar);
+static void my_putstring(char *s)
+{
+ tputs(s, 1, putchar);
}
-static const char *
-my_tgetstr(char *s, char *ss __attribute__ ((__unused__))) {
- const char* ret = tgetstr(s, &strbuf);
- if (!ret)
- return "";
- else
- return ret;
+static const char *my_tgetstr(char *s, char *ss __attribute__((__unused__)))
+{
+ const char *ret = tgetstr(s, &strbuf);
+ if (!ret)
+ return "";
+ else
+ return ret;
}
-#else /* ! (HAVE_LIBTERMCAP || HAVE_LIBNCURSES || HAVE_LIBNCURSESW) */
+#else /* ! (HAVE_LIBTERMCAP || HAVE_LIBNCURSES || HAVE_LIBNCURSESW) */
-static void
-my_putstring(char *s) {
- fputs(s, stdout);
+static void my_putstring(char *s)
+{
+ fputs(s, stdout);
}
-#endif
+#endif /* end of LIBTERMCAP / NCURSES */
const char *term="";
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 02/16] cal: convert function like definitions to functions
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
2013-05-02 18:51 ` [PATCH 01/16] cal: fix preprocessor directive indendation Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 03/16] cal: clean up use of constants Sami Kerola
` (13 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Reviewed-by: Thomas Bächler <thomas@archlinux.org>
Reviewed-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 45 ++++++++++++++++++++++++++++-----------------
1 file changed, 28 insertions(+), 17 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 13830de..e6dd92f 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -209,23 +209,6 @@ char j_day_headings[J_WEEK_LEN*6+1];
/* weekstart = 1 => " M Tu W Th F S S " */
const char *full_month[12];
-/* leap year -- account for gregorian reformation in 1752 */
-#define leap_year(yr) \
- ((yr) <= 1752 ? !((yr) % 4) : \
- (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400))
-
-/* number of centuries since 1700, not inclusive */
-#define centuries_since_1700(yr) \
- ((yr) > 1700 ? (yr) / 100 - 17 : 0)
-
-/* number of centuries since 1700 whose modulo of 400 is 0 */
-#define quad_centuries_since_1700(yr) \
- ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
-
-/* number of leap years between year 1 and this year, not inclusive */
-#define leap_years_since_year_1(yr) \
- ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
-
/* 0 => sunday, 1 => monday */
int weekstart=0;
int julian;
@@ -239,6 +222,9 @@ struct fmt_st
char s[FMT_ST_LINES][FMT_ST_CHARS];
};
+static int leap_year(int year);
+static int centuries_since_1700(int year, int centuries);
+static int leap_years_since_year_1(int year);
char * ascii_day(char *, int);
int center_str(const char* src, char* dest, size_t dest_size, size_t width);
void center(const char *, size_t, int);
@@ -413,6 +399,31 @@ main(int argc, char **argv) {
return EXIT_SUCCESS;
}
+/* leap year -- account for gregorian reformation in 1752 */
+static int leap_year(int year)
+{
+ if (year <= 1752)
+ return !(year % 4);
+ else
+ return ( !(year % 4) && (year % 100) ) || !(year % 400);
+}
+
+/* number of centuries since 1700 */
+static int centuries_since_1700(int year, int n)
+{
+ if (year < 1700)
+ return 0;
+ else
+ return ((year / (100 * n)) - (17 / n));
+}
+
+/* number of leap years between year 1 and this year, not inclusive */
+static int leap_years_since_year_1(int year)
+{
+ return (year / 4 - centuries_since_1700(year, 1) +
+ centuries_since_1700(year, 4));
+}
+
void headers_init(void)
{
int i, wd;
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 03/16] cal: clean up use of constants
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
2013-05-02 18:51 ` [PATCH 01/16] cal: fix preprocessor directive indendation Sami Kerola
2013-05-02 18:51 ` [PATCH 02/16] cal: convert function like definitions to functions Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 04/16] tests: add calendar reformation check Sami Kerola
` (12 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The commit also adds few new symbolic names, such as DAYS_IN_WEEK. While
these definitions may look a little too trivial to have I am sure they
ease understanding what is going on in code where they are used.
Reviewed-by: Thomas Bächler <thomas@archlinux.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 141 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 81 insertions(+), 60 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index e6dd92f..433db72 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -151,15 +151,50 @@ char *Hrow; /* pointer to highlighted row in month */
#error NUM_MONTHS must be 1 or 3
#endif
-#define THURSDAY 4 /* for reformation */
-#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
+enum {
+ SUNDAY = 0,
+ MONDAY,
+ TUESDAY,
+ WEDNESDAY,
+ THURSDAY,
+ FRIDAY,
+ SATURDAY,
+ DAYS_IN_WEEK
+};
+#define FIRST_WEEKDAY SATURDAY /* Jan 1st, 1 was a Saturday */
+#define REFORMATION_WEEKDAY THURSDAY /* after reformation it was Thursday */
+#define REFORMATION_YEAR 1752 /* Signed-off-by: Lord Chesterfield */
+#define REFORMATION_MONTH 9 /* September */
#define FIRST_MISSING_DAY 639799 /* 3 Sep 1752 */
#define NUMBER_MISSING_DAYS 11 /* 11 day correction */
+#define DAYS_IN_YEAR 365 /* the common case, leap years are calculated */
+#define MONTHS_IN_YEAR 12
+#define DAYS_IN_MONTH 31
#define MAXDAYS 42 /* slots in a month array */
#define SPACE -1 /* used in day array */
+#define SMALLEST_YEAR 1
+#define GREATEST_YEAR 9999
+
+#define DAY_LEN 3 /* 3 spaces per day */
+#define WEEK_LEN (DAYS_IN_WEEK * DAY_LEN)
+#define HEAD_SEP 2
+
+#define J_DAY_LEN 4 /* 4 spaces per day */
+#define J_WEEK_LEN (DAYS_IN_WEEK * J_DAY_LEN)
+#define J_HEAD_SEP 2
+
+#define TODAY_FLAG 0x400 /* flag day for highlighting */
+
+#define FMT_ST_LINES 8
+#define FMT_ST_CHARS 300 /* 90 suffices in most locales */
+struct fmt_st
+{
+ char s[FMT_ST_LINES][FMT_ST_CHARS];
+};
+
static int days_in_month[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
@@ -195,33 +230,19 @@ int sep1752[MAXDAYS+6] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE
};
-#define DAY_LEN 3 /* 3 spaces per day */
-#define J_DAY_LEN 4 /* 4 spaces per day */
-#define WEEK_LEN 21 /* 7 days * 3 characters */
-#define J_WEEK_LEN 28 /* 7 days * 4 characters */
-#define HEAD_SEP 2 /* spaces between day headings */
-#define J_HEAD_SEP 2
/* utf-8 can have up to 6 bytes per char; and an extra byte for ending \0 */
char day_headings[WEEK_LEN*6+1];
/* weekstart = 1 => " M Tu W Th F S S " */
char j_day_headings[J_WEEK_LEN*6+1];
/* weekstart = 1 => " M Tu W Th F S S " */
-const char *full_month[12];
+const char *full_month[MONTHS_IN_YEAR];
/* 0 => sunday, 1 => monday */
-int weekstart=0;
+int weekstart = SUNDAY;
int julian;
-#define TODAY_FLAG 0x400 /* flag day for highlighting */
-
-#define FMT_ST_LINES 8
-#define FMT_ST_CHARS 300 /* 90 suffices in most locales */
-struct fmt_st
-{
- char s[FMT_ST_LINES][FMT_ST_CHARS];
-};
-
+/* function prototypes */
static int leap_year(int year);
static int centuries_since_1700(int year, int centuries);
static int leap_years_since_year_1(int year);
@@ -244,7 +265,7 @@ int
main(int argc, char **argv) {
struct tm *local_time;
time_t now;
- int ch, day, month, year, yflag;
+ int ch, day = 0, month = 0, year = 0, yflag = 0;
int num_months = NUM_MONTHS;
static const struct option longopts[] = {
@@ -267,7 +288,7 @@ main(int argc, char **argv) {
#if defined(HAVE_LIBNCURSES) || defined(HAVE_LIBNCURSESW) || defined(HAVE_LIBTERMCAP)
if ((term = getenv("TERM"))) {
int ret;
- my_setupterm(term, 1, &ret);
+ my_setupterm(term, STDOUT_FILENO, &ret);
if (ret > 0) {
Senter = my_tgetstr("so","smso");
Sexit = my_tgetstr("se","rmso");
@@ -307,11 +328,10 @@ main(int argc, char **argv) {
wfd = val.word;
wfd = day_in_week(wfd % 100, (wfd / 100) % 100, wfd / (100 * 100));
- weekstart = (wfd + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % 7;
+ weekstart = (wfd + *nl_langinfo(_NL_TIME_FIRST_WEEKDAY) - 1) % DAYS_IN_WEEK;
}
#endif
- yflag = 0;
while ((ch = getopt_long(argc, argv, "13mjsyVh", longopts, NULL)) != -1)
switch(ch) {
case '1':
@@ -321,10 +341,10 @@ main(int argc, char **argv) {
num_months = 3;
break;
case 's':
- weekstart = 0; /* default */
+ weekstart = SUNDAY; /* default */
break;
case 'm':
- weekstart = 1;
+ weekstart = MONDAY;
break;
case 'j':
julian = 1;
@@ -347,21 +367,20 @@ main(int argc, char **argv) {
time(&now);
local_time = localtime(&now);
- day = month = year = 0;
switch(argc) {
case 3:
day = strtos32_or_err(*argv++, _("illegal day value"));
- if (day < 1 || 31 < day)
- errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), 31);
+ if (day < 1 || DAYS_IN_MONTH < day)
+ errx(EXIT_FAILURE, _("illegal day value: use 1-%d"), DAYS_IN_MONTH);
/* FALLTHROUGH */
case 2:
month = strtos32_or_err(*argv++, _("illegal month value: use 1-12"));
- if (month < 1 || 12 < month)
+ if (month < 1 || MONTHS_IN_YEAR < month)
errx(EXIT_FAILURE, _("illegal month value: use 1-12"));
/* FALLTHROUGH */
case 1:
year = strtos32_or_err(*argv++, _("illegal year value: use 1-9999"));
- if (year < 1 || 9999 < year)
+ if (year < SMALLEST_YEAR || GREATEST_YEAR < year)
errx(EXIT_FAILURE, _("illegal year value: use 1-9999"));
if (day) {
int dm = days_in_month[leap_year(year)][month];
@@ -384,7 +403,7 @@ main(int argc, char **argv) {
}
headers_init();
- if (!isatty(1))
+ if (!isatty(STDOUT_FILENO))
day = 0; /* don't highlight */
if (yflag && julian)
@@ -402,7 +421,7 @@ main(int argc, char **argv) {
/* leap year -- account for gregorian reformation in 1752 */
static int leap_year(int year)
{
- if (year <= 1752)
+ if (year <= REFORMATION_YEAR)
return !(year % 4);
else
return ( !(year % 4) && (year % 100) ) || !(year % 400);
@@ -411,10 +430,10 @@ static int leap_year(int year)
/* number of centuries since 1700 */
static int centuries_since_1700(int year, int n)
{
- if (year < 1700)
+ if (year < REFORMATION_YEAR)
return 0;
else
- return ((year / (100 * n)) - (17 / n));
+ return ((year / (100 * n)) - ((REFORMATION_YEAR / 100) / n));
}
/* number of leap years between year 1 and this year, not inclusive */
@@ -432,9 +451,9 @@ void headers_init(void)
strcpy(day_headings, "");
strcpy(j_day_headings, "");
- for (i = 0; i < 7; i++) {
+ for (i = 0; i < DAYS_IN_WEEK; i++) {
ssize_t space_left;
- wd = (i + weekstart) % 7;
+ wd = (i + weekstart) % DAYS_IN_WEEK;
if (i)
strcat(cur_dh++, " ");
@@ -457,7 +476,7 @@ void headers_init(void)
space_left, 3);
}
- for (i = 0; i < 12; i++)
+ for (i = 0; i < MONTHS_IN_YEAR; i++)
full_month[i] = nl_langinfo(MON_1 + i);
}
@@ -481,10 +500,10 @@ do_monthly(int day, int month, int year, struct fmt_st *out) {
snprintf(out->s[1], FMT_ST_CHARS, "%s",
julian ? j_day_headings : day_headings);
- for (row = 0; row < 6; row++) {
+ for (row = 0; row < DAYS_IN_WEEK - 1; row++) {
int has_hl = 0;
- for (col = 0, p = lineout; col < 7; col++) {
- int xd = days[row * 7 + col];
+ for (col = 0, p = lineout; col < DAYS_IN_WEEK; col++) {
+ int xd = days[row * DAYS_IN_WEEK + col];
if (xd != SPACE && (xd & TODAY_FLAG))
has_hl = 1;
p = ascii_day(p, xd);
@@ -521,13 +540,13 @@ monthly3(int day, int month, int year) {
int next_month, next_year;
if (month == 1) {
- prev_month = 12;
+ prev_month = MONTHS_IN_YEAR;
prev_year = year - 1;
} else {
prev_month = month - 1;
prev_year = year;
}
- if (month == 12) {
+ if (month == MONTHS_IN_YEAR) {
next_month = 1;
next_year = year + 1;
} else {
@@ -567,29 +586,29 @@ monthly3(int day, int month, int year) {
void
j_yearly(int day, int year) {
int col, *dp, i, month, row, which_cal;
- int days[12][MAXDAYS];
+ int days[MONTHS_IN_YEAR][MAXDAYS];
char *p, lineout[80];
snprintf(lineout, sizeof(lineout), "%d", year);
center(lineout, J_WEEK_LEN*2 + J_HEAD_SEP - 1, 0);
my_putstring("\n\n");
- for (i = 0; i < 12; i++)
+ for (i = 0; i < MONTHS_IN_YEAR; i++)
day_array(day, i + 1, year, days[i]);
memset(lineout, ' ', sizeof(lineout) - 1);
lineout[sizeof(lineout) - 1] = '\0';
- for (month = 0; month < 12; month += 2) {
+ for (month = 0; month < MONTHS_IN_YEAR; month += 2) {
center(full_month[month], J_WEEK_LEN-1, J_HEAD_SEP+1);
center(full_month[month + 1], J_WEEK_LEN-1, 0);
snprintf(lineout, sizeof(lineout),
"\n%s%*s %s\n", j_day_headings, J_HEAD_SEP, "",
j_day_headings);
my_putstring(lineout);
- for (row = 0; row < 6; row++) {
+ for (row = 0; row < DAYS_IN_WEEK - 1; row++) {
p = lineout;
for (which_cal = 0; which_cal < 2; which_cal++) {
- dp = &days[month + which_cal][row * 7];
- for (col = 0; col < 7; col++)
+ dp = &days[month + which_cal][row * DAYS_IN_WEEK];
+ for (col = 0; col < DAYS_IN_WEEK; col++)
p = ascii_day(p, *dp++);
p += sprintf(p, " ");
}
@@ -605,18 +624,18 @@ j_yearly(int day, int year) {
void
yearly(int day, int year) {
int col, *dp, i, month, row, which_cal;
- int days[12][MAXDAYS];
+ int days[MONTHS_IN_YEAR][MAXDAYS];
char *p, lineout[100];
snprintf(lineout, sizeof(lineout), "%d", year);
center(lineout, WEEK_LEN*3 + HEAD_SEP*2 - 1, 0);
my_putstring("\n\n");
- for (i = 0; i < 12; i++)
+ for (i = 0; i < MONTHS_IN_YEAR; i++)
day_array(day, i + 1, year, days[i]);
memset(lineout, ' ', sizeof(lineout) - 1);
lineout[sizeof(lineout) - 1] = '\0';
- for (month = 0; month < 12; month += 3) {
+ for (month = 0; month < MONTHS_IN_YEAR; month += 3) {
center(full_month[month], WEEK_LEN-1, HEAD_SEP+1);
center(full_month[month + 1], WEEK_LEN-1, HEAD_SEP+1);
center(full_month[month + 2], WEEK_LEN-1, 0);
@@ -624,11 +643,11 @@ yearly(int day, int year) {
"\n%s%*s %s%*s %s\n", day_headings, HEAD_SEP,
"", day_headings, HEAD_SEP, "", day_headings);
my_putstring(lineout);
- for (row = 0; row < 6; row++) {
+ for (row = 0; row < DAYS_IN_WEEK - 1; row++) {
p = lineout;
for (which_cal = 0; which_cal < 3; which_cal++) {
- dp = &days[month + which_cal][row * 7];
- for (col = 0; col < 7; col++)
+ dp = &days[month + which_cal][row * DAYS_IN_WEEK];
+ for (col = 0; col < DAYS_IN_WEEK; col++)
p = ascii_day(p, *dp++);
p += sprintf(p, " ");
}
@@ -653,7 +672,7 @@ day_array(int day, int month, int year, int *days) {
int julday, daynum, dw, dm;
int *d_sep1752;
- if (month == 9 && year == 1752) {
+ if (month == REFORMATION_MONTH && year == REFORMATION_YEAR) {
int sep1752_ofs = (weekstart + SEP1752_OFS) % 7;
d_sep1752 = julian ? j_sep1752 : sep1752;
memcpy(days, d_sep1752 + sep1752_ofs, MAXDAYS * sizeof(int));
@@ -664,7 +683,7 @@ day_array(int day, int month, int year, int *days) {
}
memcpy(days, empty, MAXDAYS * sizeof(int));
dm = days_in_month[leap_year(year)][month];
- dw = (day_in_week(1, month, year) - weekstart + 7) % 7;
+ dw = (day_in_week(1, month, year) - weekstart + DAYS_IN_WEEK) % DAYS_IN_WEEK;
julday = day_in_year(1, month, year);
daynum = julian ? julday : 1;
while (dm--) {
@@ -700,13 +719,15 @@ int
day_in_week(int day, int month, int year) {
long temp;
- temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
+ temp =
+ (long)(year - SMALLEST_YEAR) * DAYS_IN_YEAR +
+ leap_years_since_year_1(year - SMALLEST_YEAR)
+ day_in_year(day, month, year);
if (temp < FIRST_MISSING_DAY)
- return ((temp - 1 + SATURDAY) % 7);
+ return ((temp - 1 + FIRST_WEEKDAY) % DAYS_IN_WEEK);
if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
- return (((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
- return (THURSDAY);
+ return (((temp - 1 + FIRST_WEEKDAY) - NUMBER_MISSING_DAYS) % DAYS_IN_WEEK);
+ return(REFORMATION_WEEKDAY);
}
char *
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 04/16] tests: add calendar reformation check
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (2 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 03/16] cal: clean up use of constants Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 05/16] cal: simplify calendar reformat calculations Sami Kerola
` (11 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
tests/expected/cal/sep1752 | 198 +++++++++++++++++++++++++++++++++++++++++++++
tests/ts/cal/sep1752 | 95 ++++++++++++++++++++++
2 files changed, 293 insertions(+)
create mode 100644 tests/expected/cal/sep1752
create mode 100755 tests/ts/cal/sep1752
diff --git a/tests/expected/cal/sep1752 b/tests/expected/cal/sep1752
new file mode 100644
index 0000000..b718fa0
--- /dev/null
+++ b/tests/expected/cal/sep1752
@@ -0,0 +1,198 @@
+
+Gregorian - Monday-based month
+ September 1752
+Mo Tu We Th Fr Sa Su
+ 1 2 14 15 16 17
+18 19 20 21 22 23 24
+25 26 27 28 29 30
+
+
+
+Gregorian - Sunday-based month
+ September 1752
+Su Mo Tu We Th Fr Sa
+ 1 2 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
+Julian - Monday-based month
+ September 1752
+Mon Tue Wed Thu Fri Sat Sun
+ 245 246 258 259 260 261
+262 263 264 265 266 267 268
+269 270 271 272 273 274
+
+
+
+Julian - Sunday-based month
+ September 1752
+Sun Mon Tue Wed Thu Fri Sat
+ 245 246 258 259 260
+261 262 263 264 265 266 267
+268 269 270 271 272 273 274
+
+
+
+Gregorian - Monday-based three months
+ August 1752 September 1752 October 1752
+Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
+ 1 2 1 2 14 15 16 17 1
+ 3 4 5 6 7 8 9 18 19 20 21 22 23 24 2 3 4 5 6 7 8
+10 11 12 13 14 15 16 25 26 27 28 29 30 9 10 11 12 13 14 15
+17 18 19 20 21 22 23 16 17 18 19 20 21 22
+24 25 26 27 28 29 30 23 24 25 26 27 28 29
+31 30 31
+Gregorian - Sunday-based three months
+ August 1752 September 1752 October 1752
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 1 2 14 15 16 1 2 3 4 5 6 7
+ 2 3 4 5 6 7 8 17 18 19 20 21 22 23 8 9 10 11 12 13 14
+ 9 10 11 12 13 14 15 24 25 26 27 28 29 30 15 16 17 18 19 20 21
+16 17 18 19 20 21 22 22 23 24 25 26 27 28
+23 24 25 26 27 28 29 29 30 31
+30 31
+Julian - Monday-based three months
+ August 1752 September 1752 October 1752
+Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
+ 214 215 245 246 258 259 260 261 275
+216 217 218 219 220 221 222 262 263 264 265 266 267 268 276 277 278 279 280 281 282
+223 224 225 226 227 228 229 269 270 271 272 273 274 283 284 285 286 287 288 289
+230 231 232 233 234 235 236 290 291 292 293 294 295 296
+237 238 239 240 241 242 243 297 298 299 300 301 302 303
+244 304 305
+Julian - Sunday-based three months
+ August 1752 September 1752 October 1752
+Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
+ 214 245 246 258 259 260 275 276 277 278 279 280 281
+215 216 217 218 219 220 221 261 262 263 264 265 266 267 282 283 284 285 286 287 288
+222 223 224 225 226 227 228 268 269 270 271 272 273 274 289 290 291 292 293 294 295
+229 230 231 232 233 234 235 296 297 298 299 300 301 302
+236 237 238 239 240 241 242 303 304 305
+243 244
+Gregorian - Monday-based year
+ 1752
+
+ January February March
+Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
+ 1 2 3 4 5 1 2 1
+ 6 7 8 9 10 11 12 3 4 5 6 7 8 9 2 3 4 5 6 7 8
+13 14 15 16 17 18 19 10 11 12 13 14 15 16 9 10 11 12 13 14 15
+20 21 22 23 24 25 26 17 18 19 20 21 22 23 16 17 18 19 20 21 22
+27 28 29 30 31 24 25 26 27 28 29 23 24 25 26 27 28 29
+ 30 31
+ April May June
+Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
+ 1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
+ 6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
+13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
+20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
+27 28 29 30 25 26 27 28 29 30 31 29 30
+
+ July August September
+Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
+ 1 2 3 4 5 1 2 1 2 14 15 16 17
+ 6 7 8 9 10 11 12 3 4 5 6 7 8 9 18 19 20 21 22 23 24
+13 14 15 16 17 18 19 10 11 12 13 14 15 16 25 26 27 28 29 30
+20 21 22 23 24 25 26 17 18 19 20 21 22 23
+27 28 29 30 31 24 25 26 27 28 29 30
+ 31
+ October November December
+Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
+ 1 1 2 3 4 5 1 2 3
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
+16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
+23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
+30 31
+
+Gregorian - Sunday-based year
+ 1752
+
+ January February March
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 1 1 2 3 4 5 6 7
+ 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
+12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
+19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
+26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
+
+ April May June
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 1 2 1 2 3 4 5 6
+ 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
+12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
+19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
+26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
+ 31
+ July August September
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 1 1 2 14 15 16
+ 5 6 7 8 9 10 11 2 3 4 5 6 7 8 17 18 19 20 21 22 23
+12 13 14 15 16 17 18 9 10 11 12 13 14 15 24 25 26 27 28 29 30
+19 20 21 22 23 24 25 16 17 18 19 20 21 22
+26 27 28 29 30 31 23 24 25 26 27 28 29
+ 30 31
+ October November December
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5 6 7 1 2 3 4 1 2
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
+29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
+ 31
+
+Julian - Monday-based year
+ 1752
+
+ January February
+Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
+ 1 2 3 4 5 32 33
+ 6 7 8 9 10 11 12 34 35 36 37 38 39 40
+ 13 14 15 16 17 18 19 41 42 43 44 45 46 47
+ 20 21 22 23 24 25 26 48 49 50 51 52 53 54
+ 27 28 29 30 31 55 56 57 58 59 60
+
+ March April
+Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
+ 61 92 93 94 95 96
+ 62 63 64 65 66 67 68 97 98 99 100 101 102 103
+ 69 70 71 72 73 74 75 104 105 106 107 108 109 110
+ 76 77 78 79 80 81 82 111 112 113 114 115 116 117
+ 83 84 85 86 87 88 89 118 119 120 121
+ 90 91
+ May June
+Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
+ 122 123 124 153 154 155 156 157 158 159
+125 126 127 128 129 130 131 160 161 162 163 164 165 166
+132 133 134 135 136 137 138 167 168 169 170 171 172 173
+139 140 141 142 143 144 145 174 175 176 177 178 179 180
+146 147 148 149 150 151 152 181 182
+
+ July August
+Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
+ 183 184 185 186 187 214 215
+188 189 190 191 192 193 194 216 217 218 219 220 221 222
+195 196 197 198 199 200 201 223 224 225 226 227 228 229
+202 203 204 205 206 207 208 230 231 232 233 234 235 236
+209 210 211 212 213 237 238 239 240 241 242 243
+ 244
+ September October
+Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
+ 245 246 258 259 260 261 275
+262 263 264 265 266 267 268 276 277 278 279 280 281 282
+269 270 271 272 273 274 283 284 285 286 287 288 289
+ 290 291 292 293 294 295 296
+ 297 298 299 300 301 302 303
+ 304 305
+ November December
+Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
+ 306 307 308 309 310 336 337 338
+311 312 313 314 315 316 317 339 340 341 342 343 344 345
+318 319 320 321 322 323 324 346 347 348 349 350 351 352
+325 326 327 328 329 330 331 353 354 355 356 357 358 359
+332 333 334 335 360 361 362 363 364 365 366
+
+
+Julian - Sunday-based year
diff --git a/tests/ts/cal/sep1752 b/tests/ts/cal/sep1752
new file mode 100755
index 0000000..68ea342
--- /dev/null
+++ b/tests/ts/cal/sep1752
@@ -0,0 +1,95 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="$(dirname $0)/../.."
+TS_DESC="September 1752"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+set -o pipefail
+
+USETERM=$( ts_has_option "useterm" "$*" )
+MYMONTH="09 1752"
+MYYEAR="1752"
+
+[ "$USETERM" == "yes" ] && TS_VERBOSE="yes"
+ts_log ""
+
+
+ts_log "Gregorian - Monday-based month"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1m
+fi
+$TS_CMD_CAL -1m $MYMONTH >> $TS_OUTPUT
+ts_log "Gregorian - Sunday-based month"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1s $MYMONTH
+fi
+$TS_CMD_CAL -1s $MYMONTH >> $TS_OUTPUT
+ts_log "Julian - Monday-based month"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1mj $MYMONTH
+fi
+$TS_CMD_CAL -1mj $MYMONTH >> $TS_OUTPUT
+ts_log "Julian - Sunday-based month"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1sj $MYMONTH
+fi
+$TS_CMD_CAL -1sj $MYMONTH >> $TS_OUTPUT
+
+
+ts_log "Gregorian - Monday-based three months"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -3m
+fi
+$TS_CMD_CAL -3m $MYMONTH >> $TS_OUTPUT
+ts_log "Gregorian - Sunday-based three months"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -3s $MYMONTH
+fi
+$TS_CMD_CAL -3s $MYMONTH >> $TS_OUTPUT
+ts_log "Julian - Monday-based three months"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -3mj $MYMONTH
+fi
+$TS_CMD_CAL -3mj $MYMONTH >> $TS_OUTPUT
+ts_log "Julian - Sunday-based three months"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -3sj $MYMONTH
+fi
+$TS_CMD_CAL -3sj $MYMONTH >> $TS_OUTPUT
+
+
+ts_log "Gregorian - Monday-based year"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1m $MYYEAR
+fi
+$TS_CMD_CAL -1m $MYYEAR >> $TS_OUTPUT
+ts_log "Gregorian - Sunday-based year"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1s $MYYEAR
+fi
+$TS_CMD_CAL -1s $MYYEAR >> $TS_OUTPUT
+ts_log "Julian - Monday-based year"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1mj $MYYEAR
+fi
+$TS_CMD_CAL -1mj $MYYEAR >> $TS_OUTPUT
+ts_log "Julian - Sunday-based year"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL -1sj $MYYEAR
+fi
+
+ts_finalize
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 05/16] cal: simplify calendar reformat calculations
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (3 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 04/16] tests: add calendar reformation check Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 06/16] cal: remove unnecessary initializations Sami Kerola
` (10 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The only September 1752 offset calculation that is necessary is whether
Sun or Mon is the first day of the week.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 41 +++++++++++++++--------------------------
1 file changed, 15 insertions(+), 26 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 433db72..a89ca76 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -200,27 +200,16 @@ static int days_in_month[2][13] = {
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
};
-#define SEP1752_OFS 4 /* sep1752[4] is a Sunday */
-
-/* 1 Sep 1752 is represented by sep1752[6] and j_sep1752[6] */
-int sep1752[MAXDAYS+6] = {
- SPACE, SPACE, SPACE, SPACE,
+/* September 1752 is special, and has static assignments for both date
+ * and Julian representations. */
+ int d_sep1752[MAXDAYS / 2] = {
SPACE, SPACE, 1, 2, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE
-}, j_sep1752[MAXDAYS+6] = {
- SPACE, SPACE, SPACE, SPACE,
+ 24, 25, 26, 27, 28, 29, 30
+}, j_sep1752[MAXDAYS / 2] = {
SPACE, SPACE, 245, 246, 258, 259, 260,
261, 262, 263, 264, 265, 266, 267,
- 268, 269, 270, 271, 272, 273, 274,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
- SPACE, SPACE
+ 268, 269, 270, 271, 272, 273, 274
}, empty[MAXDAYS] = {
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE,
@@ -670,18 +659,18 @@ yearly(int day, int year) {
void
day_array(int day, int month, int year, int *days) {
int julday, daynum, dw, dm;
- int *d_sep1752;
-
- if (month == REFORMATION_MONTH && year == REFORMATION_YEAR) {
- int sep1752_ofs = (weekstart + SEP1752_OFS) % 7;
- d_sep1752 = julian ? j_sep1752 : sep1752;
- memcpy(days, d_sep1752 + sep1752_ofs, MAXDAYS * sizeof(int));
- for (dm=0; dm<MAXDAYS; dm++)
- if (j_sep1752[dm + sep1752_ofs] == day)
+ int *sep1752;
+
+ memcpy(days, empty, MAXDAYS * sizeof(int));
+ if (year == REFORMATION_YEAR && month == REFORMATION_MONTH) {
+ sep1752 = julian ? j_sep1752 : d_sep1752;
+ memcpy(days, sep1752 + weekstart,
+ ((MAXDAYS / 2) - weekstart) * sizeof(int));
+ for (dm = 0; dm < MAXDAYS / 2; dm++)
+ if (j_sep1752[dm] == day)
days[dm] |= TODAY_FLAG;
return;
}
- memcpy(days, empty, MAXDAYS * sizeof(int));
dm = days_in_month[leap_year(year)][month];
dw = (day_in_week(1, month, year) - weekstart + DAYS_IN_WEEK) % DAYS_IN_WEEK;
julday = day_in_year(1, month, year);
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 06/16] cal: remove unnecessary initializations
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (4 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 05/16] cal: simplify calendar reformat calculations Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 07/16] cal: de-duplicate julian specific functions Sami Kerola
` (9 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 7 -------
1 file changed, 7 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index a89ca76..03f6265 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -437,9 +437,6 @@ void headers_init(void)
int i, wd;
char *cur_dh = day_headings, *cur_j_dh = j_day_headings;
- strcpy(day_headings, "");
- strcpy(j_day_headings, "");
-
for (i = 0; i < DAYS_IN_WEEK; i++) {
ssize_t space_left;
wd = (i + weekstart) % DAYS_IN_WEEK;
@@ -584,8 +581,6 @@ j_yearly(int day, int year) {
for (i = 0; i < MONTHS_IN_YEAR; i++)
day_array(day, i + 1, year, days[i]);
- memset(lineout, ' ', sizeof(lineout) - 1);
- lineout[sizeof(lineout) - 1] = '\0';
for (month = 0; month < MONTHS_IN_YEAR; month += 2) {
center(full_month[month], J_WEEK_LEN-1, J_HEAD_SEP+1);
center(full_month[month + 1], J_WEEK_LEN-1, 0);
@@ -622,8 +617,6 @@ yearly(int day, int year) {
for (i = 0; i < MONTHS_IN_YEAR; i++)
day_array(day, i + 1, year, days[i]);
- memset(lineout, ' ', sizeof(lineout) - 1);
- lineout[sizeof(lineout) - 1] = '\0';
for (month = 0; month < MONTHS_IN_YEAR; month += 3) {
center(full_month[month], WEEK_LEN-1, HEAD_SEP+1);
center(full_month[month + 1], WEEK_LEN-1, HEAD_SEP+1);
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 07/16] cal: de-duplicate julian specific functions
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (5 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 06/16] cal: remove unnecessary initializations Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 08/16] lib: copy argmatch from gnulib Sami Kerola
` (8 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The cost is a little bit more complex functions, while the benefit is
couple data flows fewer to mind about.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 119 +++++++++++++++++++++----------------------------------
1 file changed, 45 insertions(+), 74 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 03f6265..665dbcd 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -181,10 +181,12 @@ enum {
#define DAY_LEN 3 /* 3 spaces per day */
#define WEEK_LEN (DAYS_IN_WEEK * DAY_LEN)
#define HEAD_SEP 2
+#define MONTH_COLS 3 /* month columns in year view */
#define J_DAY_LEN 4 /* 4 spaces per day */
#define J_WEEK_LEN (DAYS_IN_WEEK * J_DAY_LEN)
#define J_HEAD_SEP 2
+#define J_MONTH_COLS 2
#define TODAY_FLAG 0x400 /* flag day for highlighting */
@@ -221,9 +223,7 @@ static int days_in_month[2][13] = {
/* utf-8 can have up to 6 bytes per char; and an extra byte for ending \0 */
-char day_headings[WEEK_LEN*6+1];
-/* weekstart = 1 => " M Tu W Th F S S " */
-char j_day_headings[J_WEEK_LEN*6+1];
+char day_headings[J_WEEK_LEN * 6 + 1];
/* weekstart = 1 => " M Tu W Th F S S " */
const char *full_month[MONTHS_IN_YEAR];
@@ -241,14 +241,13 @@ void center(const char *, size_t, int);
void day_array(int, int, int, int *);
int day_in_week(int, int, int);
int day_in_year(int, int, int);
-void yearly(int, int);
-void j_yearly(int, int);
+void yearly(int, int, int);
void do_monthly(int, int, int, struct fmt_st*);
void monthly(int, int, int);
void monthly3(int, int, int);
void trim_trailing_spaces(char *);
static void __attribute__ ((__noreturn__)) usage(FILE * out);
-void headers_init(void);
+void headers_init(int);
int
main(int argc, char **argv) {
@@ -390,15 +389,13 @@ main(int argc, char **argv) {
default:
usage(stderr);
}
- headers_init();
+ headers_init(julian);
if (!isatty(STDOUT_FILENO))
day = 0; /* don't highlight */
- if (yflag && julian)
- j_yearly(day, year);
- else if (yflag)
- yearly(day, year);
+ if (yflag)
+ yearly(day, year, julian);
else if (num_months == 1)
monthly(day, month, year);
else if (num_months == 3)
@@ -432,10 +429,10 @@ static int leap_years_since_year_1(int year)
centuries_since_1700(year, 4));
}
-void headers_init(void)
+void headers_init(int julian)
{
- int i, wd;
- char *cur_dh = day_headings, *cur_j_dh = j_day_headings;
+ int i, wd, spaces = julian ? J_DAY_LEN - 1 : DAY_LEN - 1;
+ char *cur_dh = day_headings;
for (i = 0; i < DAYS_IN_WEEK; i++) {
ssize_t space_left;
@@ -445,21 +442,11 @@ void headers_init(void)
strcat(cur_dh++, " ");
space_left =
sizeof(day_headings) - (cur_dh - day_headings);
- if (space_left <= 2)
+ if (space_left <= spaces)
break;
cur_dh +=
center_str(nl_langinfo(ABDAY_1 + wd), cur_dh,
- space_left, 2);
-
- if (i)
- strcat(cur_j_dh++, " ");
- space_left =
- sizeof(j_day_headings) - (cur_j_dh - j_day_headings);
- if (space_left <= 3)
- break;
- cur_j_dh +=
- center_str(nl_langinfo(ABDAY_1 + wd), cur_j_dh,
- space_left, 3);
+ space_left, spaces);
}
for (i = 0; i < MONTHS_IN_YEAR; i++)
@@ -484,8 +471,7 @@ do_monthly(int day, int month, int year, struct fmt_st *out) {
full_month[month - 1], year);
center_str(lineout, out->s[0], ARRAY_SIZE(out->s[0]), width);
- snprintf(out->s[1], FMT_ST_CHARS, "%s",
- julian ? j_day_headings : day_headings);
+ snprintf(out->s[1], FMT_ST_CHARS, "%s", day_headings);
for (row = 0; row < DAYS_IN_WEEK - 1; row++) {
int has_hl = 0;
for (col = 0, p = lineout; col < DAYS_IN_WEEK; col++) {
@@ -570,64 +556,49 @@ monthly3(int day, int month, int year) {
}
void
-j_yearly(int day, int year) {
- int col, *dp, i, month, row, which_cal;
- int days[MONTHS_IN_YEAR][MAXDAYS];
- char *p, lineout[80];
-
- snprintf(lineout, sizeof(lineout), "%d", year);
- center(lineout, J_WEEK_LEN*2 + J_HEAD_SEP - 1, 0);
- my_putstring("\n\n");
-
- for (i = 0; i < MONTHS_IN_YEAR; i++)
- day_array(day, i + 1, year, days[i]);
- for (month = 0; month < MONTHS_IN_YEAR; month += 2) {
- center(full_month[month], J_WEEK_LEN-1, J_HEAD_SEP+1);
- center(full_month[month + 1], J_WEEK_LEN-1, 0);
- snprintf(lineout, sizeof(lineout),
- "\n%s%*s %s\n", j_day_headings, J_HEAD_SEP, "",
- j_day_headings);
- my_putstring(lineout);
- for (row = 0; row < DAYS_IN_WEEK - 1; row++) {
- p = lineout;
- for (which_cal = 0; which_cal < 2; which_cal++) {
- dp = &days[month + which_cal][row * DAYS_IN_WEEK];
- for (col = 0; col < DAYS_IN_WEEK; col++)
- p = ascii_day(p, *dp++);
- p += sprintf(p, " ");
- }
- *p = '\0';
- trim_trailing_spaces(lineout);
- my_putstring(lineout);
- my_putstring("\n");
- }
- }
- my_putstring("\n");
-}
-
-void
-yearly(int day, int year) {
+yearly(int day, int year, int julian) {
int col, *dp, i, month, row, which_cal;
+ int maxrow, sep_len, week_len;
int days[MONTHS_IN_YEAR][MAXDAYS];
char *p, lineout[100];
+ if (julian) {
+ maxrow = J_MONTH_COLS;
+ sep_len = J_HEAD_SEP;
+ week_len = J_WEEK_LEN;
+ } else {
+ maxrow = MONTH_COLS;
+ sep_len = HEAD_SEP;
+ week_len = WEEK_LEN;
+ }
snprintf(lineout, sizeof(lineout), "%d", year);
- center(lineout, WEEK_LEN*3 + HEAD_SEP*2 - 1, 0);
+ /* 2013-04-28: The -1 near sep_len makes year header to be
+ * aligned exactly how it has been aligned for long time, but it
+ * is unexplainable. */
+ center(lineout, (week_len + sep_len) * maxrow - sep_len - 1, 0);
my_putstring("\n\n");
for (i = 0; i < MONTHS_IN_YEAR; i++)
day_array(day, i + 1, year, days[i]);
- for (month = 0; month < MONTHS_IN_YEAR; month += 3) {
- center(full_month[month], WEEK_LEN-1, HEAD_SEP+1);
- center(full_month[month + 1], WEEK_LEN-1, HEAD_SEP+1);
- center(full_month[month + 2], WEEK_LEN-1, 0);
- snprintf(lineout, sizeof(lineout),
- "\n%s%*s %s%*s %s\n", day_headings, HEAD_SEP,
- "", day_headings, HEAD_SEP, "", day_headings);
+ for (month = 0; month < MONTHS_IN_YEAR; month += maxrow) {
+ center(full_month[month], week_len - 1, sep_len + 1);
+ if (julian) {
+ center(full_month[month + 1], week_len - 1, 0);
+ } else {
+ center(full_month[month + 1], week_len - 1, sep_len + 1);
+ center(full_month[month + 2], week_len - 1, 0);
+ }
+ if (julian)
+ snprintf(lineout, sizeof(lineout),
+ "\n%s%*s %s\n", day_headings, sep_len, "", day_headings);
+ else
+ snprintf(lineout, sizeof(lineout),
+ "\n%s%*s %s%*s %s\n", day_headings, sep_len,
+ "", day_headings, sep_len, "", day_headings);
my_putstring(lineout);
for (row = 0; row < DAYS_IN_WEEK - 1; row++) {
p = lineout;
- for (which_cal = 0; which_cal < 3; which_cal++) {
+ for (which_cal = 0; which_cal < maxrow; which_cal++) {
dp = &days[month + which_cal][row * DAYS_IN_WEEK];
for (col = 0; col < DAYS_IN_WEEK; col++)
p = ascii_day(p, *dp++);
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 08/16] lib: copy argmatch from gnulib
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (6 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 07/16] cal: de-duplicate julian specific functions Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-06 17:16 ` Karel Zak
2013-05-02 18:51 ` [PATCH 09/16] cal: add --highligth option which uses argmatch Sami Kerola
` (7 subsequent siblings)
15 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Both argmatch.h and argmatch.c are copied from gnulib. Biggest
difference is that messaging does not use same quoting as the gnulib
does. Other than that code is nearly untouched.
gnulib-commit: 92f3a4c8e52e64c233e260431d095dbf88554c14
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
include/Makemodule.am | 1 +
include/argmatch.h | 100 +++++++++++++++++++
lib/Makemodule.am | 1 +
lib/argmatch.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 374 insertions(+)
create mode 100644 include/argmatch.h
create mode 100644 lib/argmatch.c
diff --git a/include/Makemodule.am b/include/Makemodule.am
index 7ba4593..f27d67e 100644
--- a/include/Makemodule.am
+++ b/include/Makemodule.am
@@ -1,6 +1,7 @@
dist_noinst_HEADERS += \
include/all-io.h \
+ include/argmatch.h \
include/at.h \
include/bitops.h \
include/blkdev.h \
diff --git a/include/argmatch.h b/include/argmatch.h
new file mode 100644
index 0000000..57dcb6d
--- /dev/null
+++ b/include/argmatch.h
@@ -0,0 +1,100 @@
+/* argmatch.h -- definitions and prototypes for argmatch.c
+
+ Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by David MacKenzie <djm@ai.mit.edu>
+ Modified by Akim Demaille <demaille@inf.enst.fr> */
+
+#ifndef ARGMATCH_H_
+# define ARGMATCH_H_ 1
+
+# include <stddef.h>
+
+# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
+
+/* Assert there are as many real arguments as there are values
+ (argument list ends with a NULL guard). */
+
+# define ARGMATCH_VERIFY(Arglist, Vallist) \
+ verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
+
+/* Return the index of the element of ARGLIST (NULL terminated) that
+ matches with ARG. If VALLIST is not NULL, then use it to resolve
+ false ambiguities (i.e., different matches of ARG but corresponding
+ to the same values in VALLIST). */
+
+ptrdiff_t argmatch (char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH(Arg, Arglist, Vallist) \
+ argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+/* xargmatch calls this function when it fails. This function should not
+ return. By default, this is a function that calls ARGMATCH_DIE which
+ in turn defaults to 'exit (exit_failure)'. */
+typedef void (*argmatch_exit_fn) (void);
+extern argmatch_exit_fn argmatch_die;
+
+/* Report on stderr why argmatch failed. Report correct values. */
+
+void argmatch_invalid (char const *context, char const *value,
+ ptrdiff_t problem);
+
+/* Left for compatibility with the old name invalid_arg */
+
+# define invalid_arg(Context, Value, Problem) \
+ argmatch_invalid (Context, Value, Problem)
+
+
+
+/* Report on stderr the list of possible arguments. */
+
+void argmatch_valid (char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH_VALID(Arglist, Vallist) \
+ argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+
+
+/* Same as argmatch, but upon failure, report an explanation of the
+ failure, and exit using the function EXIT_FN. */
+
+ptrdiff_t __xargmatch_internal (char const *context,
+ char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn);
+
+/* Programmer friendly interface to __xargmatch_internal. */
+
+# define XARGMATCH(Context, Arg, Arglist, Vallist) \
+ ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
+ (char const *) (Vallist), \
+ sizeof *(Vallist), \
+ argmatch_die)])
+
+/* Convert a value into a corresponding argument. */
+
+char const *argmatch_to_argument (char const *value,
+ char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
+ argmatch_to_argument (Value, Arglist, \
+ (char const *) (Vallist), sizeof *(Vallist))
+
+#endif /* ARGMATCH_H_ */
diff --git a/lib/Makemodule.am b/lib/Makemodule.am
index afc2156..6757cb9 100644
--- a/lib/Makemodule.am
+++ b/lib/Makemodule.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES += libcommon.la
libcommon_la_CFLAGS = $(AM_CFLAGS)
libcommon_la_SOURCES = \
+ lib/argmatch.c \
lib/at.c \
lib/blkdev.c \
lib/canonicalize.c \
diff --git a/lib/argmatch.c b/lib/argmatch.c
new file mode 100644
index 0000000..58ce5e1
--- /dev/null
+++ b/lib/argmatch.c
@@ -0,0 +1,272 @@
+/* argmatch.c -- find a match for a string in an array
+
+ Copyright (C) 1990, 1998-1999, 2001-2007, 2009-2013 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by David MacKenzie <djm@ai.mit.edu>
+ Modified by Akim Demaille <demaille@inf.enst.fr> */
+
+#include <config.h>
+
+/* Specification. */
+#include "argmatch.h"
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "nls.h"
+
+#include "error.h"
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+/* When reporting an invalid argument, show nonprinting characters
+ by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
+ literal_quoting_style. */
+#ifndef ARGMATCH_QUOTING_STYLE
+# define ARGMATCH_QUOTING_STYLE locale_quoting_style
+#endif
+
+/* Non failing version of argmatch call this function after failing. */
+#ifndef ARGMATCH_DIE
+# define ARGMATCH_DIE exit (EXIT_FAILURE)
+#endif
+
+#ifdef ARGMATCH_DIE_DECL
+ARGMATCH_DIE_DECL;
+#endif
+
+static void
+__argmatch_die (void)
+{
+ ARGMATCH_DIE;
+}
+
+/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
+ Default to __argmatch_die, but allow caller to change this at run-time. */
+argmatch_exit_fn argmatch_die = __argmatch_die;
+
+\f
+/* If ARG is an unambiguous match for an element of the
+ NULL-terminated array ARGLIST, return the index in ARGLIST
+ of the matched element, else -1 if it does not match any element
+ or -2 if it is ambiguous (is a prefix of more than one element).
+
+ If VALLIST is none null, use it to resolve ambiguities limited to
+ synonyms, i.e., for
+ "yes", "yop" -> 0
+ "no", "nope" -> 1
+ "y" is a valid argument, for 0, and "n" for 1. */
+
+ptrdiff_t
+argmatch (const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i; /* Temporary index in ARGLIST. */
+ size_t arglen; /* Length of ARG. */
+ ptrdiff_t matchind = -1; /* Index of first nonexact match. */
+ bool ambiguous = false; /* If true, multiple nonexact match(es). */
+
+ arglen = strlen (arg);
+
+ /* Test all elements for either exact match or abbreviated matches. */
+ for (i = 0; arglist[i]; i++)
+ {
+ if (!strncmp (arglist[i], arg, arglen))
+ {
+ if (strlen (arglist[i]) == arglen)
+ /* Exact match found. */
+ return i;
+ else if (matchind == -1)
+ /* First nonexact match found. */
+ matchind = i;
+ else
+ {
+ /* Second nonexact match found. */
+ if (vallist == NULL
+ || memcmp (vallist + valsize * matchind,
+ vallist + valsize * i, valsize))
+ {
+ /* There is a real ambiguity, or we could not
+ disambiguate. */
+ ambiguous = true;
+ }
+ }
+ }
+ }
+ if (ambiguous)
+ return -2;
+ else
+ return matchind;
+}
+
+/* Error reporting for argmatch.
+ CONTEXT is a description of the type of entity that was being matched.
+ VALUE is the invalid value that was given.
+ PROBLEM is the return value from argmatch. */
+
+void
+argmatch_invalid (const char *context, const char *value, ptrdiff_t problem)
+{
+ char const *format = (problem == -1
+ ? _("invalid argument %s for %s")
+ : _("ambiguous argument %s for %s"));
+
+ error (0, 0, format, value, context);
+}
+
+/* List the valid arguments for argmatch.
+ ARGLIST is the same as in argmatch.
+ VALLIST is a pointer to an array of values.
+ VALSIZE is the size of the elements of VALLIST */
+void
+argmatch_valid (const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i;
+ const char *last_val = NULL;
+
+ /* We try to put synonyms on the same line. The assumption is that
+ synonyms follow each other */
+ fputs (_("Valid arguments are:"), stderr);
+ for (i = 0; arglist[i]; i++)
+ if ((i == 0)
+ || memcmp (last_val, vallist + valsize * i, valsize))
+ {
+ fprintf (stderr, "\n - %s", arglist[i]);
+ last_val = vallist + valsize * i;
+ }
+ else
+ {
+ fprintf (stderr, ", %s", arglist[i]);
+ }
+ putc ('\n', stderr);
+}
+
+/* Never failing versions of the previous functions.
+
+ CONTEXT is the context for which argmatch is called (e.g.,
+ "--version-control", or "$VERSION_CONTROL" etc.). Upon failure,
+ calls the (supposed never to return) function EXIT_FN. */
+
+ptrdiff_t
+__xargmatch_internal (const char *context,
+ const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn)
+{
+ ptrdiff_t res = argmatch (arg, arglist, vallist, valsize);
+ if (res >= 0)
+ /* Success. */
+ return res;
+
+ /* We failed. Explain why. */
+ argmatch_invalid (context, arg, res);
+ argmatch_valid (arglist, vallist, valsize);
+ (*exit_fn) ();
+
+ return -1; /* To please the compilers. */
+}
+
+/* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
+ return the first corresponding argument in ARGLIST */
+const char *
+argmatch_to_argument (const char *value,
+ const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i;
+
+ for (i = 0; arglist[i]; i++)
+ if (!memcmp (value, vallist + valsize * i, valsize))
+ return arglist[i];
+ return NULL;
+}
+
+#ifdef TEST
+/*
+ * Based on "getversion.c" by David MacKenzie <djm@gnu.ai.mit.edu>
+ */
+char *program_name;
+
+/* When to make backup files. */
+enum backup_type
+{
+ /* Never make backups. */
+ no_backups,
+
+ /* Make simple backups of every file. */
+ simple_backups,
+
+ /* Make numbered backups of files that already have numbered backups,
+ and simple backups of the others. */
+ numbered_existing_backups,
+
+ /* Make numbered backups of every file. */
+ numbered_backups
+};
+
+/* Two tables describing arguments (keys) and their corresponding
+ values */
+static const char *const backup_args[] =
+{
+ "no", "none", "off",
+ "simple", "never",
+ "existing", "nil",
+ "numbered", "t",
+ 0
+};
+
+static const enum backup_type backup_vals[] =
+{
+ no_backups, no_backups, no_backups,
+ simple_backups, simple_backups,
+ numbered_existing_backups, numbered_existing_backups,
+ numbered_backups, numbered_backups
+};
+
+int
+main (int argc, const char *const *argv)
+{
+ const char *cp;
+ enum backup_type backup_type = no_backups;
+
+ program_name = (char *) argv[0];
+
+ if (argc > 2)
+ {
+ fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name);
+ exit (1);
+ }
+
+ if ((cp = getenv ("VERSION_CONTROL")))
+ backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
+ backup_args, backup_vals);
+
+ if (argc == 2)
+ backup_type = XARGMATCH (program_name, argv[1],
+ backup_args, backup_vals);
+
+ printf ("The version control is '%s'\n",
+ ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
+
+ return 0;
+}
+#endif
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 09/16] cal: add --highligth option which uses argmatch
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (7 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 08/16] lib: copy argmatch from gnulib Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-06 0:11 ` Pádraig Brady
2013-05-06 17:19 ` Karel Zak
2013-05-02 18:51 ` [PATCH 10/16] cal: add --highlight to usage() Sami Kerola
` (6 subsequent siblings)
15 siblings, 2 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa, Pádraig Brady
This switch will allow an user to choose when highlighting is outputed.
The default remains the same as it has been, e.g., highlighting is used
depending on whether stdout is a terminal or not.
CC: Pádraig Brady <P@draigBrady.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/Makemodule.am | 2 +-
misc-utils/cal.c | 40 ++++++++++++++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am
index a615047..3f95458 100644
--- a/misc-utils/Makemodule.am
+++ b/misc-utils/Makemodule.am
@@ -10,7 +10,7 @@ if !HAVE_LANGINFO
cal_SOURCES += lib/langinfo.c
endif
-cal_LDADD = $(LDADD)
+cal_LDADD = $(LDADD) libcommon.la
if HAVE_TINFO
cal_LDADD += -ltinfo @NCURSES_LIBS@
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 665dbcd..cf50c57 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -66,6 +66,7 @@
#include <unistd.h>
#include <errno.h>
+#include "argmatch.h"
#include "c.h"
#include "closestream.h"
#include "nls.h"
@@ -256,6 +257,24 @@ main(int argc, char **argv) {
int ch, day = 0, month = 0, year = 0, yflag = 0;
int num_months = NUM_MONTHS;
+ enum Highlight_type {
+ HIGHLIGHT_UNUSED,
+ HIGHLIGHT_NEVER,
+ HIGHLIGHT_AUTO,
+ HIGHLIGHT_ALWAYS
+ };
+ int highlight = HIGHLIGHT_AUTO;
+ static char const *const highlight_type_string[] = {
+ "never", "auto", "always", NULL
+ };
+ static enum Highlight_type const highlight_type[] = {
+ HIGHLIGHT_NEVER, HIGHLIGHT_AUTO, HIGHLIGHT_ALWAYS
+ };
+
+ enum {
+ OPT_HIGHLIGHT = CHAR_MAX + 1
+ };
+
static const struct option longopts[] = {
{"one", no_argument, NULL, '1'},
{"three", no_argument, NULL, '3'},
@@ -263,6 +282,7 @@ main(int argc, char **argv) {
{"monday", no_argument, NULL, 'm'},
{"julian", no_argument, NULL, 'j'},
{"year", no_argument, NULL, 'y'},
+ {"highlight", required_argument, NULL, OPT_HIGHLIGHT},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
@@ -340,6 +360,9 @@ main(int argc, char **argv) {
case 'y':
yflag = 1;
break;
+ case OPT_HIGHLIGHT:
+ highlight = XARGMATCH("--highlight", optarg, highlight_type_string, highlight_type);
+ break;
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
@@ -391,8 +414,21 @@ main(int argc, char **argv) {
}
headers_init(julian);
- if (!isatty(STDOUT_FILENO))
- day = 0; /* don't highlight */
+ switch (highlight) {
+ case HIGHLIGHT_NEVER:
+ day = 0;
+ break;
+ case HIGHLIGHT_AUTO:
+ if (!isatty(STDOUT_FILENO))
+ day = 0; /* don't highlight */
+ break;
+ case HIGHLIGHT_ALWAYS:
+ if (day == 0)
+ day = local_time->tm_yday + 1;;
+ break;
+ default:
+ abort();
+ }
if (yflag)
yearly(day, year, julian);
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 10/16] cal: add --highlight to usage()
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (8 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 09/16] cal: add --highligth option which uses argmatch Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 11/16] docs: cal: add --highlight option description Sami Kerola
` (5 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
And clean up the usage() function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index cf50c57..d88fc2e 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -809,20 +809,19 @@ center(const char *str, size_t len, int separate)
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
- fputs(_("\nUsage:\n"), out);
- fprintf(out,
- _(" %s [options] [[[day] month] year]\n"),
- program_invocation_short_name);
-
- fputs(_("\nOptions:\n"), out);
- fputs(_(" -1, --one show only current month (default)\n"
- " -3, --three show previous, current and next month\n"
- " -s, --sunday Sunday as first day of week\n"
- " -m, --monday Monday as first day of week\n"
- " -j, --julian output Julian dates\n"
- " -y, --year show whole current year\n"
- " -V, --version display version information and exit\n"
- " -h, --help display this help text and exit\n\n"), out);
-
+ fputs(USAGE_HEADER, out);
+ fprintf(out, _(" %s [options] [[[day] month] year]\n"), program_invocation_short_name);
+ fputs(USAGE_OPTIONS, out);
+ fputs(_(" -1, --one show only current month (default)\n"), out);
+ fputs(_(" -3, --three show previous, current and next month\n"), out);
+ fputs(_(" -s, --sunday Sunday as first day of week\n"), out);
+ fputs(_(" -m, --monday Monday as first day of week\n"), out);
+ fputs(_(" -j, --julian output Julian dates\n"), out);
+ fputs(_(" -y, --year show whole current year\n"), out);
+ fputs(_(" --highlight <when> advice when to highlight; never, auto, always\n"), out);
+ fputs(USAGE_SEPARATOR, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
+ fprintf(out, USAGE_MAN_TAIL("cal(1)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 11/16] docs: cal: add --highlight option description
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (9 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 10/16] cal: add --highlight to usage() Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 12/16] tests: add cal day highlight corner cases Sami Kerola
` (4 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.1 | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/misc-utils/cal.1 b/misc-utils/cal.1
index 4d9b3d1..decdcf5 100644
--- a/misc-utils/cal.1
+++ b/misc-utils/cal.1
@@ -65,6 +65,19 @@ Display Julian dates (days one-based, numbered from January 1).
\fB\-y\fR, \fB\-\-year\fR
Display a calendar for the current year.
.TP
+\fB\-\-highlight\fR \fIwhen\fR
+Highlight output. The
+.I when
+can be one
+.IR never ,
+.IR auto ,
+or
+.IR always .
+Never will turn off highlighting in all situations. Auto is default, and
+it will make highlight to be in use if output is done to termina. Always
+will allow highlight to be outputed when cal outputs to pipe, or is
+called from a script.
+.TP
\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.TP
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 12/16] tests: add cal day highlight corner cases
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (10 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 11/16] docs: cal: add --highlight option description Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 13/16] cal: stop trimming whitespaces Sami Kerola
` (3 subsequent siblings)
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Check that the first, andn last, possible dates and strange Sep 1752
dates are highlighted correctly.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
tests/expected/cal/highlight | 55 ++++++++++++++++++++++++++++++++++
tests/ts/cal/highlight | 70 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+)
create mode 100644 tests/expected/cal/highlight
create mode 100755 tests/ts/cal/highlight
diff --git a/tests/expected/cal/highlight b/tests/expected/cal/highlight
new file mode 100644
index 0000000..7fa8304
--- /dev/null
+++ b/tests/expected/cal/highlight
@@ -0,0 +1,55 @@
+
+First day
+ January 1
+Su Mo Tu We Th Fr Sa
+ ^[[7m 1^[[27m
+ 2 3 4 5 6 7 8
+ 9 10 11 12 13 14 15
+16 17 18 19 20 21 22
+23 24 25 26 27 28 29
+30 31
+Reformation corner cases 1
+ September 1752
+Su Mo Tu We Th Fr Sa
+ 1 ^[[7m 2^[[27m 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
+Reformation corner cases 2
+ September 1752
+Su Mo Tu We Th Fr Sa
+ 1 2 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
+Reformation corner cases 3
+ September 1752
+Su Mo Tu We Th Fr Sa
+ 1 2 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
+Reformation corner cases 4
+ September 1752
+Su Mo Tu We Th Fr Sa
+ 1 2 ^[[7m14^[[27m 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
+Last day
+ November 9999 December 9999 January 10000
+Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
+ 1 2 3 4 5 6 1 2 3 4 1
+ 7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
+14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
+21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
+28 29 30 26 27 28 29 30 ^[[7m31^[[27m 23 24 25 26 27 28 29
+ 30 31
diff --git a/tests/ts/cal/highlight b/tests/ts/cal/highlight
new file mode 100755
index 0000000..6fc2c3e
--- /dev/null
+++ b/tests/ts/cal/highlight
@@ -0,0 +1,70 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="$(dirname $0)/../.."
+TS_DESC="highlights"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+set -o pipefail
+
+USETERM=$( ts_has_option "useterm" "$*" )
+
+[ "$USETERM" == "yes" ] && TS_VERBOSE="yes"
+ts_log ""
+
+ts_log "First day"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL --highlight -3 always 1 1 1
+fi
+$TS_CMD_CAL --highlight always 1 1 1 >> $TS_OUTPUT
+
+ts_log "Reformation corner cases 1"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL --highlight always 2 9 1752
+fi
+$TS_CMD_CAL --highlight always 2 9 1752 >> $TS_OUTPUT
+
+ts_log "Reformation corner cases 2"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL --highlight always 3 9 1752
+fi
+$TS_CMD_CAL --highlight always 3 9 1752 >> $TS_OUTPUT
+
+ts_log "Reformation corner cases 3"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL --highlight always 13 9 1752
+fi
+$TS_CMD_CAL --highlight always 13 9 1752 >> $TS_OUTPUT
+
+ts_log "Reformation corner cases 4"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL --highlight always 14 9 1752
+fi
+$TS_CMD_CAL --highlight always 14 9 1752 >> $TS_OUTPUT
+
+ts_log "Last day"
+if [ "$USETERM" == "yes" ]; then
+ $TS_CMD_CAL --highlight always 31 12 9999
+fi
+$TS_CMD_CAL --highlight always -3 31 12 9999 >> $TS_OUTPUT
+
+
+ts_finalize
+
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 13/16] cal: stop trimming whitespaces
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (11 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 12/16] tests: add cal day highlight corner cases Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-06 0:12 ` Pádraig Brady
2013-05-14 10:45 ` Karel Zak
2013-05-02 18:51 ` [PATCH 14/16] cal: move global variables to local scope Sami Kerola
` (2 subsequent siblings)
15 siblings, 2 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa, Pádraig Brady
Remove trailing spaces from output it is trivial
cal | sed 's/ *$//'
but padding them back is difficult.
CC: Pádraig Brady <P@draigbrady.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 17 ---
tests/expected/cal/1m | 48 ++++----
tests/expected/cal/3m | 48 ++++----
tests/expected/cal/highlight | 72 ++++++------
tests/expected/cal/sep1752 | 264 +++++++++++++++++++++----------------------
tests/expected/cal/year | 240 +++++++++++++++++++--------------------
6 files changed, 336 insertions(+), 353 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index d88fc2e..f4fb898 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -246,7 +246,6 @@ void yearly(int, int, int);
void do_monthly(int, int, int, struct fmt_st*);
void monthly(int, int, int);
void monthly3(int, int, int);
-void trim_trailing_spaces(char *);
static void __attribute__ ((__noreturn__)) usage(FILE * out);
void headers_init(int);
@@ -517,7 +516,6 @@ do_monthly(int day, int month, int year, struct fmt_st *out) {
p = ascii_day(p, xd);
}
*p = '\0';
- trim_trailing_spaces(lineout);
snprintf(out->s[row+2], FMT_ST_CHARS, "%s", lineout);
if (has_hl)
Hrow = out->s[row+2];
@@ -641,7 +639,6 @@ yearly(int day, int year, int julian) {
p += sprintf(p, " ");
}
*p = '\0';
- trim_trailing_spaces(lineout);
my_putstring(lineout);
my_putstring("\n");
}
@@ -767,20 +764,6 @@ ascii_day(char *p, int day) {
return p;
}
-void
-trim_trailing_spaces(char *s)
-{
- char *p;
-
- for (p = s; *p; ++p)
- continue;
- while (p > s && isspace(*--p))
- continue;
- if (p > s)
- ++p;
- *p = '\0';
-}
-
/*
* Center string, handling multibyte characters appropriately.
* In addition if the string is too large for the width it's truncated.
diff --git a/tests/expected/cal/1m b/tests/expected/cal/1m
index f657875..afe7f71 100644
--- a/tests/expected/cal/1m
+++ b/tests/expected/cal/1m
@@ -2,36 +2,36 @@
Gregorian - Monday-based week
September 2006
Mo Tu We Th Fr Sa Su
- 1 2 3
- 4 5 6 7 8 9 10
-11 12 13 14 15 16 17
-18 19 20 21 22 23 24
-25 26 27 28 29 30
-
+ 1 2 3
+ 4 5 6 7 8 9 10
+11 12 13 14 15 16 17
+18 19 20 21 22 23 24
+25 26 27 28 29 30
+
Gregorian - Sunday-based week
September 2006
Su Mo Tu We Th Fr Sa
- 1 2
- 3 4 5 6 7 8 9
-10 11 12 13 14 15 16
-17 18 19 20 21 22 23
-24 25 26 27 28 29 30
-
+ 1 2
+ 3 4 5 6 7 8 9
+10 11 12 13 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
Julian - Monday-based week
September 2006
Mon Tue Wed Thu Fri Sat Sun
- 244 245 246
-247 248 249 250 251 252 253
-254 255 256 257 258 259 260
-261 262 263 264 265 266 267
-268 269 270 271 272 273
-
+ 244 245 246
+247 248 249 250 251 252 253
+254 255 256 257 258 259 260
+261 262 263 264 265 266 267
+268 269 270 271 272 273
+
Julian - Sunday-based week
September 2006
Sun Mon Tue Wed Thu Fri Sat
- 244 245
-246 247 248 249 250 251 252
-253 254 255 256 257 258 259
-260 261 262 263 264 265 266
-267 268 269 270 271 272 273
-
+ 244 245
+246 247 248 249 250 251 252
+253 254 255 256 257 258 259
+260 261 262 263 264 265 266
+267 268 269 270 271 272 273
+
diff --git a/tests/expected/cal/3m b/tests/expected/cal/3m
index ba9657d..b6334ff 100644
--- a/tests/expected/cal/3m
+++ b/tests/expected/cal/3m
@@ -2,36 +2,36 @@
Gregorian - Monday-based week
August 2006 September 2006 October 2006
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 2 3 4 5 6 1 2 3 1
- 7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8
-14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15
-21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
-28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
- 30 31
+ 1 2 3 4 5 6 1 2 3 1
+ 7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8
+14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15
+21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22
+28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29
+ 30 31
Gregorian - Sunday-based week
August 2006 September 2006 October 2006
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 5 1 2 1 2 3 4 5 6 7
- 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
-13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
-20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
-27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
-
+ 1 2 3 4 5 1 2 1 2 3 4 5 6 7
+ 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
+13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
+20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
+27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
+
Julian - Monday-based week
August 2006 September 2006 October 2006
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 213 214 215 216 217 218 244 245 246 274
-219 220 221 222 223 224 225 247 248 249 250 251 252 253 275 276 277 278 279 280 281
-226 227 228 229 230 231 232 254 255 256 257 258 259 260 282 283 284 285 286 287 288
-233 234 235 236 237 238 239 261 262 263 264 265 266 267 289 290 291 292 293 294 295
-240 241 242 243 268 269 270 271 272 273 296 297 298 299 300 301 302
- 303 304
+ 213 214 215 216 217 218 244 245 246 274
+219 220 221 222 223 224 225 247 248 249 250 251 252 253 275 276 277 278 279 280 281
+226 227 228 229 230 231 232 254 255 256 257 258 259 260 282 283 284 285 286 287 288
+233 234 235 236 237 238 239 261 262 263 264 265 266 267 289 290 291 292 293 294 295
+240 241 242 243 268 269 270 271 272 273 296 297 298 299 300 301 302
+ 303 304
Julian - Sunday-based week
August 2006 September 2006 October 2006
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 213 214 215 216 217 244 245 274 275 276 277 278 279 280
-218 219 220 221 222 223 224 246 247 248 249 250 251 252 281 282 283 284 285 286 287
-225 226 227 228 229 230 231 253 254 255 256 257 258 259 288 289 290 291 292 293 294
-232 233 234 235 236 237 238 260 261 262 263 264 265 266 295 296 297 298 299 300 301
-239 240 241 242 243 267 268 269 270 271 272 273 302 303 304
-
+ 213 214 215 216 217 244 245 274 275 276 277 278 279 280
+218 219 220 221 222 223 224 246 247 248 249 250 251 252 281 282 283 284 285 286 287
+225 226 227 228 229 230 231 253 254 255 256 257 258 259 288 289 290 291 292 293 294
+232 233 234 235 236 237 238 260 261 262 263 264 265 266 295 296 297 298 299 300 301
+239 240 241 242 243 267 268 269 270 271 272 273 302 303 304
+
diff --git a/tests/expected/cal/highlight b/tests/expected/cal/highlight
index 7fa8304..26b0899 100644
--- a/tests/expected/cal/highlight
+++ b/tests/expected/cal/highlight
@@ -2,54 +2,54 @@
First day
January 1
Su Mo Tu We Th Fr Sa
- ^[[7m 1^[[27m
- 2 3 4 5 6 7 8
- 9 10 11 12 13 14 15
-16 17 18 19 20 21 22
-23 24 25 26 27 28 29
-30 31
+ ^[[7m 1^[[27m
+ 2 3 4 5 6 7 8
+ 9 10 11 12 13 14 15
+16 17 18 19 20 21 22
+23 24 25 26 27 28 29
+30 31
Reformation corner cases 1
September 1752
Su Mo Tu We Th Fr Sa
- 1 ^[[7m 2^[[27m 14 15 16
-17 18 19 20 21 22 23
-24 25 26 27 28 29 30
-
-
-
+ 1 ^[[7m 2^[[27m 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
Reformation corner cases 2
September 1752
Su Mo Tu We Th Fr Sa
- 1 2 14 15 16
-17 18 19 20 21 22 23
-24 25 26 27 28 29 30
-
-
-
+ 1 2 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
Reformation corner cases 3
September 1752
Su Mo Tu We Th Fr Sa
- 1 2 14 15 16
-17 18 19 20 21 22 23
-24 25 26 27 28 29 30
-
-
-
+ 1 2 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
Reformation corner cases 4
September 1752
Su Mo Tu We Th Fr Sa
- 1 2 ^[[7m14^[[27m 15 16
-17 18 19 20 21 22 23
-24 25 26 27 28 29 30
-
-
-
+ 1 2 ^[[7m14^[[27m 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
Last day
November 9999 December 9999 January 10000
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 5 6 1 2 3 4 1
- 7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
-14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
-21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
-28 29 30 26 27 28 29 30 ^[[7m31^[[27m 23 24 25 26 27 28 29
- 30 31
+ 1 2 3 4 5 6 1 2 3 4 1
+ 7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
+14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
+21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
+28 29 30 26 27 28 29 30 ^[[7m31^[[27m 23 24 25 26 27 28 29
+ 30 31
diff --git a/tests/expected/cal/sep1752 b/tests/expected/cal/sep1752
index b718fa0..0b12e49 100644
--- a/tests/expected/cal/sep1752
+++ b/tests/expected/cal/sep1752
@@ -2,197 +2,197 @@
Gregorian - Monday-based month
September 1752
Mo Tu We Th Fr Sa Su
- 1 2 14 15 16 17
-18 19 20 21 22 23 24
-25 26 27 28 29 30
-
-
-
+ 1 2 14 15 16 17
+18 19 20 21 22 23 24
+25 26 27 28 29 30
+
+
+
Gregorian - Sunday-based month
September 1752
Su Mo Tu We Th Fr Sa
- 1 2 14 15 16
-17 18 19 20 21 22 23
-24 25 26 27 28 29 30
-
-
-
+ 1 2 14 15 16
+17 18 19 20 21 22 23
+24 25 26 27 28 29 30
+
+
+
Julian - Monday-based month
September 1752
Mon Tue Wed Thu Fri Sat Sun
- 245 246 258 259 260 261
-262 263 264 265 266 267 268
-269 270 271 272 273 274
-
-
-
+ 245 246 258 259 260 261
+262 263 264 265 266 267 268
+269 270 271 272 273 274
+
+
+
Julian - Sunday-based month
September 1752
Sun Mon Tue Wed Thu Fri Sat
- 245 246 258 259 260
-261 262 263 264 265 266 267
-268 269 270 271 272 273 274
-
-
-
+ 245 246 258 259 260
+261 262 263 264 265 266 267
+268 269 270 271 272 273 274
+
+
+
Gregorian - Monday-based three months
August 1752 September 1752 October 1752
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 2 1 2 14 15 16 17 1
- 3 4 5 6 7 8 9 18 19 20 21 22 23 24 2 3 4 5 6 7 8
-10 11 12 13 14 15 16 25 26 27 28 29 30 9 10 11 12 13 14 15
-17 18 19 20 21 22 23 16 17 18 19 20 21 22
-24 25 26 27 28 29 30 23 24 25 26 27 28 29
-31 30 31
+ 1 2 1 2 14 15 16 17 1
+ 3 4 5 6 7 8 9 18 19 20 21 22 23 24 2 3 4 5 6 7 8
+10 11 12 13 14 15 16 25 26 27 28 29 30 9 10 11 12 13 14 15
+17 18 19 20 21 22 23 16 17 18 19 20 21 22
+24 25 26 27 28 29 30 23 24 25 26 27 28 29
+31 30 31
Gregorian - Sunday-based three months
August 1752 September 1752 October 1752
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 1 2 14 15 16 1 2 3 4 5 6 7
- 2 3 4 5 6 7 8 17 18 19 20 21 22 23 8 9 10 11 12 13 14
- 9 10 11 12 13 14 15 24 25 26 27 28 29 30 15 16 17 18 19 20 21
-16 17 18 19 20 21 22 22 23 24 25 26 27 28
-23 24 25 26 27 28 29 29 30 31
-30 31
+ 1 1 2 14 15 16 1 2 3 4 5 6 7
+ 2 3 4 5 6 7 8 17 18 19 20 21 22 23 8 9 10 11 12 13 14
+ 9 10 11 12 13 14 15 24 25 26 27 28 29 30 15 16 17 18 19 20 21
+16 17 18 19 20 21 22 22 23 24 25 26 27 28
+23 24 25 26 27 28 29 29 30 31
+30 31
Julian - Monday-based three months
August 1752 September 1752 October 1752
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 214 215 245 246 258 259 260 261 275
-216 217 218 219 220 221 222 262 263 264 265 266 267 268 276 277 278 279 280 281 282
-223 224 225 226 227 228 229 269 270 271 272 273 274 283 284 285 286 287 288 289
-230 231 232 233 234 235 236 290 291 292 293 294 295 296
-237 238 239 240 241 242 243 297 298 299 300 301 302 303
-244 304 305
+ 214 215 245 246 258 259 260 261 275
+216 217 218 219 220 221 222 262 263 264 265 266 267 268 276 277 278 279 280 281 282
+223 224 225 226 227 228 229 269 270 271 272 273 274 283 284 285 286 287 288 289
+230 231 232 233 234 235 236 290 291 292 293 294 295 296
+237 238 239 240 241 242 243 297 298 299 300 301 302 303
+244 304 305
Julian - Sunday-based three months
August 1752 September 1752 October 1752
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 214 245 246 258 259 260 275 276 277 278 279 280 281
-215 216 217 218 219 220 221 261 262 263 264 265 266 267 282 283 284 285 286 287 288
-222 223 224 225 226 227 228 268 269 270 271 272 273 274 289 290 291 292 293 294 295
-229 230 231 232 233 234 235 296 297 298 299 300 301 302
-236 237 238 239 240 241 242 303 304 305
-243 244
+ 214 245 246 258 259 260 275 276 277 278 279 280 281
+215 216 217 218 219 220 221 261 262 263 264 265 266 267 282 283 284 285 286 287 288
+222 223 224 225 226 227 228 268 269 270 271 272 273 274 289 290 291 292 293 294 295
+229 230 231 232 233 234 235 296 297 298 299 300 301 302
+236 237 238 239 240 241 242 303 304 305
+243 244
Gregorian - Monday-based year
1752
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 2 3 4 5 1 2 1
- 6 7 8 9 10 11 12 3 4 5 6 7 8 9 2 3 4 5 6 7 8
-13 14 15 16 17 18 19 10 11 12 13 14 15 16 9 10 11 12 13 14 15
-20 21 22 23 24 25 26 17 18 19 20 21 22 23 16 17 18 19 20 21 22
-27 28 29 30 31 24 25 26 27 28 29 23 24 25 26 27 28 29
- 30 31
+ 1 2 3 4 5 1 2 1
+ 6 7 8 9 10 11 12 3 4 5 6 7 8 9 2 3 4 5 6 7 8
+13 14 15 16 17 18 19 10 11 12 13 14 15 16 9 10 11 12 13 14 15
+20 21 22 23 24 25 26 17 18 19 20 21 22 23 16 17 18 19 20 21 22
+27 28 29 30 31 24 25 26 27 28 29 23 24 25 26 27 28 29
+ 30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
- 6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
-13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
-20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
-27 28 29 30 25 26 27 28 29 30 31 29 30
-
+ 1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
+ 6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
+13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
+20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
+27 28 29 30 25 26 27 28 29 30 31 29 30
+
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 2 3 4 5 1 2 1 2 14 15 16 17
- 6 7 8 9 10 11 12 3 4 5 6 7 8 9 18 19 20 21 22 23 24
-13 14 15 16 17 18 19 10 11 12 13 14 15 16 25 26 27 28 29 30
-20 21 22 23 24 25 26 17 18 19 20 21 22 23
-27 28 29 30 31 24 25 26 27 28 29 30
- 31
+ 1 2 3 4 5 1 2 1 2 14 15 16 17
+ 6 7 8 9 10 11 12 3 4 5 6 7 8 9 18 19 20 21 22 23 24
+13 14 15 16 17 18 19 10 11 12 13 14 15 16 25 26 27 28 29 30
+20 21 22 23 24 25 26 17 18 19 20 21 22 23
+27 28 29 30 31 24 25 26 27 28 29 30
+ 31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 1 2 3 4 5 1 2 3
- 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
- 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
-16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
-23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
-30 31
+ 1 1 2 3 4 5 1 2 3
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
+16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
+23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
+30 31
Gregorian - Sunday-based year
1752
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 1 1 2 3 4 5 6 7
- 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
-12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
-19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
-26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
-
+ 1 2 3 4 1 1 2 3 4 5 6 7
+ 5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
+12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
+19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
+26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
+
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 1 2 1 2 3 4 5 6
- 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
-12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
-19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
-26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
- 31
+ 1 2 3 4 1 2 1 2 3 4 5 6
+ 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
+12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
+19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
+26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
+ 31
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 1 1 2 14 15 16
- 5 6 7 8 9 10 11 2 3 4 5 6 7 8 17 18 19 20 21 22 23
-12 13 14 15 16 17 18 9 10 11 12 13 14 15 24 25 26 27 28 29 30
-19 20 21 22 23 24 25 16 17 18 19 20 21 22
-26 27 28 29 30 31 23 24 25 26 27 28 29
- 30 31
+ 1 2 3 4 1 1 2 14 15 16
+ 5 6 7 8 9 10 11 2 3 4 5 6 7 8 17 18 19 20 21 22 23
+12 13 14 15 16 17 18 9 10 11 12 13 14 15 24 25 26 27 28 29 30
+19 20 21 22 23 24 25 16 17 18 19 20 21 22
+26 27 28 29 30 31 23 24 25 26 27 28 29
+ 30 31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 5 6 7 1 2 3 4 1 2
- 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
-15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
-22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
-29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
- 31
+ 1 2 3 4 5 6 7 1 2 3 4 1 2
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
+29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
+ 31
Julian - Monday-based year
1752
January February
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 1 2 3 4 5 32 33
- 6 7 8 9 10 11 12 34 35 36 37 38 39 40
- 13 14 15 16 17 18 19 41 42 43 44 45 46 47
- 20 21 22 23 24 25 26 48 49 50 51 52 53 54
- 27 28 29 30 31 55 56 57 58 59 60
-
+ 1 2 3 4 5 32 33
+ 6 7 8 9 10 11 12 34 35 36 37 38 39 40
+ 13 14 15 16 17 18 19 41 42 43 44 45 46 47
+ 20 21 22 23 24 25 26 48 49 50 51 52 53 54
+ 27 28 29 30 31 55 56 57 58 59 60
+
March April
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 61 92 93 94 95 96
- 62 63 64 65 66 67 68 97 98 99 100 101 102 103
- 69 70 71 72 73 74 75 104 105 106 107 108 109 110
- 76 77 78 79 80 81 82 111 112 113 114 115 116 117
- 83 84 85 86 87 88 89 118 119 120 121
- 90 91
+ 61 92 93 94 95 96
+ 62 63 64 65 66 67 68 97 98 99 100 101 102 103
+ 69 70 71 72 73 74 75 104 105 106 107 108 109 110
+ 76 77 78 79 80 81 82 111 112 113 114 115 116 117
+ 83 84 85 86 87 88 89 118 119 120 121
+ 90 91
May June
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 122 123 124 153 154 155 156 157 158 159
-125 126 127 128 129 130 131 160 161 162 163 164 165 166
-132 133 134 135 136 137 138 167 168 169 170 171 172 173
-139 140 141 142 143 144 145 174 175 176 177 178 179 180
-146 147 148 149 150 151 152 181 182
-
+ 122 123 124 153 154 155 156 157 158 159
+125 126 127 128 129 130 131 160 161 162 163 164 165 166
+132 133 134 135 136 137 138 167 168 169 170 171 172 173
+139 140 141 142 143 144 145 174 175 176 177 178 179 180
+146 147 148 149 150 151 152 181 182
+
July August
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 183 184 185 186 187 214 215
-188 189 190 191 192 193 194 216 217 218 219 220 221 222
-195 196 197 198 199 200 201 223 224 225 226 227 228 229
-202 203 204 205 206 207 208 230 231 232 233 234 235 236
-209 210 211 212 213 237 238 239 240 241 242 243
- 244
+ 183 184 185 186 187 214 215
+188 189 190 191 192 193 194 216 217 218 219 220 221 222
+195 196 197 198 199 200 201 223 224 225 226 227 228 229
+202 203 204 205 206 207 208 230 231 232 233 234 235 236
+209 210 211 212 213 237 238 239 240 241 242 243
+ 244
September October
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 245 246 258 259 260 261 275
-262 263 264 265 266 267 268 276 277 278 279 280 281 282
-269 270 271 272 273 274 283 284 285 286 287 288 289
- 290 291 292 293 294 295 296
- 297 298 299 300 301 302 303
- 304 305
+ 245 246 258 259 260 261 275
+262 263 264 265 266 267 268 276 277 278 279 280 281 282
+269 270 271 272 273 274 283 284 285 286 287 288 289
+ 290 291 292 293 294 295 296
+ 297 298 299 300 301 302 303
+ 304 305
November December
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 306 307 308 309 310 336 337 338
-311 312 313 314 315 316 317 339 340 341 342 343 344 345
-318 319 320 321 322 323 324 346 347 348 349 350 351 352
-325 326 327 328 329 330 331 353 354 355 356 357 358 359
-332 333 334 335 360 361 362 363 364 365 366
-
+ 306 307 308 309 310 336 337 338
+311 312 313 314 315 316 317 339 340 341 342 343 344 345
+318 319 320 321 322 323 324 346 347 348 349 350 351 352
+325 326 327 328 329 330 331 353 354 355 356 357 358 359
+332 333 334 335 360 361 362 363 364 365 366
+
Julian - Sunday-based year
diff --git a/tests/expected/cal/year b/tests/expected/cal/year
index 616d61a..0fd88d3 100644
--- a/tests/expected/cal/year
+++ b/tests/expected/cal/year
@@ -4,174 +4,174 @@ Gregorian - Monday-based week
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 1 2 3 4 5 1 2 3 4 5
- 2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
- 9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
-16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
-23 24 25 26 27 28 29 27 28 27 28 29 30 31
-30 31
+ 1 1 2 3 4 5 1 2 3 4 5
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
+16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
+23 24 25 26 27 28 29 27 28 27 28 29 30 31
+30 31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 2 1 2 3 4 5 6 7 1 2 3 4
- 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
-10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
-17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
-24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
-
+ 1 2 1 2 3 4 5 6 7 1 2 3 4
+ 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
+10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
+17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
+24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
+
July August September
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 2 1 2 3 4 5 6 1 2 3
- 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
-10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
-17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
-24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
-31
+ 1 2 1 2 3 4 5 6 1 2 3
+ 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
+10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
+17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
+24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
+31
October November December
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
- 1 1 2 3 4 5 1 2 3
- 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
- 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
-16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
-23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
-30 31
+ 1 1 2 3 4 5 1 2 3
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
+16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
+23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
+30 31
Gregorian - Sunday-based week
2006
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4
- 8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11
-15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18
-22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25
-29 30 31 26 27 28 26 27 28 29 30 31
-
+ 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 5 6 7 8 9 10 11
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 12 13 14 15 16 17 18
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 19 20 21 22 23 24 25
+29 30 31 26 27 28 26 27 28 29 30 31
+
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 1 2 3 4 5 6 1 2 3
- 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10
- 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17
-16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24
-23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30
-30
+ 1 1 2 3 4 5 6 1 2 3
+ 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10
+ 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17
+16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24
+23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30
+30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 1 2 3 4 5 1 2
- 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9
- 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16
-16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23
-23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30
-30 31
+ 1 1 2 3 4 5 1 2
+ 2 3 4 5 6 7 8 6 7 8 9 10 11 12 3 4 5 6 7 8 9
+ 9 10 11 12 13 14 15 13 14 15 16 17 18 19 10 11 12 13 14 15 16
+16 17 18 19 20 21 22 20 21 22 23 24 25 26 17 18 19 20 21 22 23
+23 24 25 26 27 28 29 27 28 29 30 31 24 25 26 27 28 29 30
+30 31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
- 1 2 3 4 5 6 7 1 2 3 4 1 2
- 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
-15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
-22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
-29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
- 31
+ 1 2 3 4 5 6 7 1 2 3 4 1 2
+ 8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
+15 16 17 18 19 20 21 12 13 14 15 16 17 18 10 11 12 13 14 15 16
+22 23 24 25 26 27 28 19 20 21 22 23 24 25 17 18 19 20 21 22 23
+29 30 31 26 27 28 29 30 24 25 26 27 28 29 30
+ 31
Julian - Monday-based week
2006
January February
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 1 32 33 34 35 36
- 2 3 4 5 6 7 8 37 38 39 40 41 42 43
- 9 10 11 12 13 14 15 44 45 46 47 48 49 50
- 16 17 18 19 20 21 22 51 52 53 54 55 56 57
- 23 24 25 26 27 28 29 58 59
- 30 31
+ 1 32 33 34 35 36
+ 2 3 4 5 6 7 8 37 38 39 40 41 42 43
+ 9 10 11 12 13 14 15 44 45 46 47 48 49 50
+ 16 17 18 19 20 21 22 51 52 53 54 55 56 57
+ 23 24 25 26 27 28 29 58 59
+ 30 31
March April
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 60 61 62 63 64 91 92
- 65 66 67 68 69 70 71 93 94 95 96 97 98 99
- 72 73 74 75 76 77 78 100 101 102 103 104 105 106
- 79 80 81 82 83 84 85 107 108 109 110 111 112 113
- 86 87 88 89 90 114 115 116 117 118 119 120
-
+ 60 61 62 63 64 91 92
+ 65 66 67 68 69 70 71 93 94 95 96 97 98 99
+ 72 73 74 75 76 77 78 100 101 102 103 104 105 106
+ 79 80 81 82 83 84 85 107 108 109 110 111 112 113
+ 86 87 88 89 90 114 115 116 117 118 119 120
+
May June
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
-121 122 123 124 125 126 127 152 153 154 155
-128 129 130 131 132 133 134 156 157 158 159 160 161 162
-135 136 137 138 139 140 141 163 164 165 166 167 168 169
-142 143 144 145 146 147 148 170 171 172 173 174 175 176
-149 150 151 177 178 179 180 181
-
+121 122 123 124 125 126 127 152 153 154 155
+128 129 130 131 132 133 134 156 157 158 159 160 161 162
+135 136 137 138 139 140 141 163 164 165 166 167 168 169
+142 143 144 145 146 147 148 170 171 172 173 174 175 176
+149 150 151 177 178 179 180 181
+
July August
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 182 183 213 214 215 216 217 218
-184 185 186 187 188 189 190 219 220 221 222 223 224 225
-191 192 193 194 195 196 197 226 227 228 229 230 231 232
-198 199 200 201 202 203 204 233 234 235 236 237 238 239
-205 206 207 208 209 210 211 240 241 242 243
-212
+ 182 183 213 214 215 216 217 218
+184 185 186 187 188 189 190 219 220 221 222 223 224 225
+191 192 193 194 195 196 197 226 227 228 229 230 231 232
+198 199 200 201 202 203 204 233 234 235 236 237 238 239
+205 206 207 208 209 210 211 240 241 242 243
+212
September October
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 244 245 246 274
-247 248 249 250 251 252 253 275 276 277 278 279 280 281
-254 255 256 257 258 259 260 282 283 284 285 286 287 288
-261 262 263 264 265 266 267 289 290 291 292 293 294 295
-268 269 270 271 272 273 296 297 298 299 300 301 302
- 303 304
+ 244 245 246 274
+247 248 249 250 251 252 253 275 276 277 278 279 280 281
+254 255 256 257 258 259 260 282 283 284 285 286 287 288
+261 262 263 264 265 266 267 289 290 291 292 293 294 295
+268 269 270 271 272 273 296 297 298 299 300 301 302
+ 303 304
November December
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat Sun
- 305 306 307 308 309 335 336 337
-310 311 312 313 314 315 316 338 339 340 341 342 343 344
-317 318 319 320 321 322 323 345 346 347 348 349 350 351
-324 325 326 327 328 329 330 352 353 354 355 356 357 358
-331 332 333 334 359 360 361 362 363 364 365
-
+ 305 306 307 308 309 335 336 337
+310 311 312 313 314 315 316 338 339 340 341 342 343 344
+317 318 319 320 321 322 323 345 346 347 348 349 350 351
+324 325 326 327 328 329 330 352 353 354 355 356 357 358
+331 332 333 334 359 360 361 362 363 364 365
+
Julian - Sunday-based week
2006
January February
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 1 2 3 4 5 6 7 32 33 34 35
- 8 9 10 11 12 13 14 36 37 38 39 40 41 42
- 15 16 17 18 19 20 21 43 44 45 46 47 48 49
- 22 23 24 25 26 27 28 50 51 52 53 54 55 56
- 29 30 31 57 58 59
-
+ 1 2 3 4 5 6 7 32 33 34 35
+ 8 9 10 11 12 13 14 36 37 38 39 40 41 42
+ 15 16 17 18 19 20 21 43 44 45 46 47 48 49
+ 22 23 24 25 26 27 28 50 51 52 53 54 55 56
+ 29 30 31 57 58 59
+
March April
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 60 61 62 63 91
- 64 65 66 67 68 69 70 92 93 94 95 96 97 98
- 71 72 73 74 75 76 77 99 100 101 102 103 104 105
- 78 79 80 81 82 83 84 106 107 108 109 110 111 112
- 85 86 87 88 89 90 113 114 115 116 117 118 119
- 120
+ 60 61 62 63 91
+ 64 65 66 67 68 69 70 92 93 94 95 96 97 98
+ 71 72 73 74 75 76 77 99 100 101 102 103 104 105
+ 78 79 80 81 82 83 84 106 107 108 109 110 111 112
+ 85 86 87 88 89 90 113 114 115 116 117 118 119
+ 120
May June
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 121 122 123 124 125 126 152 153 154
-127 128 129 130 131 132 133 155 156 157 158 159 160 161
-134 135 136 137 138 139 140 162 163 164 165 166 167 168
-141 142 143 144 145 146 147 169 170 171 172 173 174 175
-148 149 150 151 176 177 178 179 180 181
-
+ 121 122 123 124 125 126 152 153 154
+127 128 129 130 131 132 133 155 156 157 158 159 160 161
+134 135 136 137 138 139 140 162 163 164 165 166 167 168
+141 142 143 144 145 146 147 169 170 171 172 173 174 175
+148 149 150 151 176 177 178 179 180 181
+
July August
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 182 213 214 215 216 217
-183 184 185 186 187 188 189 218 219 220 221 222 223 224
-190 191 192 193 194 195 196 225 226 227 228 229 230 231
-197 198 199 200 201 202 203 232 233 234 235 236 237 238
-204 205 206 207 208 209 210 239 240 241 242 243
-211 212
+ 182 213 214 215 216 217
+183 184 185 186 187 188 189 218 219 220 221 222 223 224
+190 191 192 193 194 195 196 225 226 227 228 229 230 231
+197 198 199 200 201 202 203 232 233 234 235 236 237 238
+204 205 206 207 208 209 210 239 240 241 242 243
+211 212
September October
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 244 245 274 275 276 277 278 279 280
-246 247 248 249 250 251 252 281 282 283 284 285 286 287
-253 254 255 256 257 258 259 288 289 290 291 292 293 294
-260 261 262 263 264 265 266 295 296 297 298 299 300 301
-267 268 269 270 271 272 273 302 303 304
-
+ 244 245 274 275 276 277 278 279 280
+246 247 248 249 250 251 252 281 282 283 284 285 286 287
+253 254 255 256 257 258 259 288 289 290 291 292 293 294
+260 261 262 263 264 265 266 295 296 297 298 299 300 301
+267 268 269 270 271 272 273 302 303 304
+
November December
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
- 305 306 307 308 335 336
-309 310 311 312 313 314 315 337 338 339 340 341 342 343
-316 317 318 319 320 321 322 344 345 346 347 348 349 350
-323 324 325 326 327 328 329 351 352 353 354 355 356 357
-330 331 332 333 334 358 359 360 361 362 363 364
- 365
+ 305 306 307 308 335 336
+309 310 311 312 313 314 315 337 338 339 340 341 342 343
+316 317 318 319 320 321 322 344 345 346 347 348 349 350
+323 324 325 326 327 328 329 351 352 353 354 355 356 357
+330 331 332 333 334 358 359 360 361 362 363 364
+ 365
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 14/16] cal: move global variables to local scope
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (12 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 13/16] cal: stop trimming whitespaces Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-14 10:49 ` Karel Zak
2013-05-02 18:51 ` [PATCH 15/16] cal: mark all functions static Sami Kerola
2013-05-02 18:51 ` [PATCH 16/16] cal: simplify day_in_week() Sami Kerola
15 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Also include small change to function parameter coding style. The braces
are from function line to new line, and return value is in same line with
the function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 103 ++++++++++++++++++++++++++++---------------------------
1 file changed, 52 insertions(+), 51 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index f4fb898..127a855 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -223,31 +223,22 @@ static int days_in_month[2][13] = {
};
-/* utf-8 can have up to 6 bytes per char; and an extra byte for ending \0 */
-char day_headings[J_WEEK_LEN * 6 + 1];
-/* weekstart = 1 => " M Tu W Th F S S " */
-const char *full_month[MONTHS_IN_YEAR];
-
-/* 0 => sunday, 1 => monday */
-int weekstart = SUNDAY;
-int julian;
-
/* function prototypes */
static int leap_year(int year);
static int centuries_since_1700(int year, int centuries);
static int leap_years_since_year_1(int year);
-char * ascii_day(char *, int);
+char * ascii_day(const int, char *, int);
int center_str(const char* src, char* dest, size_t dest_size, size_t width);
void center(const char *, size_t, int);
-void day_array(int, int, int, int *);
+void day_array(const int, const int, int, int, int, int *);
int day_in_week(int, int, int);
int day_in_year(int, int, int);
-void yearly(int, int, int);
-void do_monthly(int, int, int, struct fmt_st*);
-void monthly(int, int, int);
-void monthly3(int, int, int);
+void yearly(int, int, const int, const int, const char *, const char **);
+void do_monthly(const int, const int, const char *, const char **, int, int, int, struct fmt_st*);
+void monthly(const int, const int, const char *, const char **, int, int, int);
+void monthly3(const int, const int, const char *, const char **, int, int, int);
static void __attribute__ ((__noreturn__)) usage(FILE * out);
-void headers_init(int);
+void headers_init(const int, const int, char *, const char **);
int
main(int argc, char **argv) {
@@ -255,6 +246,12 @@ main(int argc, char **argv) {
time_t now;
int ch, day = 0, month = 0, year = 0, yflag = 0;
int num_months = NUM_MONTHS;
+ /* UTF-8 can have up to 6 bytes per char; and an extra byte for
+ * ending \0 */
+ char day_headings[J_WEEK_LEN * 6 + 1];
+ const char *full_month[MONTHS_IN_YEAR];
+ int julian = 0;
+ int weekstart = SUNDAY;
enum Highlight_type {
HIGHLIGHT_UNUSED,
@@ -411,7 +408,7 @@ main(int argc, char **argv) {
default:
usage(stderr);
}
- headers_init(julian);
+ headers_init(julian, weekstart, day_headings, full_month);
switch (highlight) {
case HIGHLIGHT_NEVER:
@@ -430,11 +427,11 @@ main(int argc, char **argv) {
}
if (yflag)
- yearly(day, year, julian);
+ yearly(day, year, julian, weekstart, day_headings, full_month);
else if (num_months == 1)
- monthly(day, month, year);
+ monthly(julian, weekstart, day_headings, full_month, day, month, year);
else if (num_months == 3)
- monthly3(day, month, year);
+ monthly3(julian, weekstart, day_headings, full_month, day, month, year);
return EXIT_SUCCESS;
}
@@ -464,7 +461,8 @@ static int leap_years_since_year_1(int year)
centuries_since_1700(year, 4));
}
-void headers_init(int julian)
+void headers_init(const int julian, const int weekstart, char *day_headings,
+ const char **full_month)
{
int i, wd, spaces = julian ? J_DAY_LEN - 1 : DAY_LEN - 1;
char *cur_dh = day_headings;
@@ -475,8 +473,7 @@ void headers_init(int julian)
if (i)
strcat(cur_dh++, " ");
- space_left =
- sizeof(day_headings) - (cur_dh - day_headings);
+ space_left = (J_WEEK_LEN * 6 + 1) - (cur_dh - day_headings);
if (space_left <= spaces)
break;
cur_dh +=
@@ -488,13 +485,15 @@ void headers_init(int julian)
full_month[i] = nl_langinfo(MON_1 + i);
}
-void
-do_monthly(int day, int month, int year, struct fmt_st *out) {
+void do_monthly(const int julian, const int weekstart, const char *day_headings,
+ const char **full_month, int day, int month, int year,
+ struct fmt_st *out)
+{
int col, row, days[MAXDAYS];
char *p, lineout[FMT_ST_CHARS];
int width = (julian ? J_WEEK_LEN : WEEK_LEN) - 1;
- day_array(day, month, year, days);
+ day_array(julian, weekstart, day, month, year, days);
/*
* %s is the month name, %d the year number.
@@ -513,7 +512,7 @@ do_monthly(int day, int month, int year, struct fmt_st *out) {
int xd = days[row * DAYS_IN_WEEK + col];
if (xd != SPACE && (xd & TODAY_FLAG))
has_hl = 1;
- p = ascii_day(p, xd);
+ p = ascii_day(julian, p, xd);
}
*p = '\0';
snprintf(out->s[row+2], FMT_ST_CHARS, "%s", lineout);
@@ -522,20 +521,22 @@ do_monthly(int day, int month, int year, struct fmt_st *out) {
}
}
-void
-monthly(int day, int month, int year) {
+void monthly(const int julian, const int weekstart, const char *day_headings,
+ const char **full_month, int day, int month, int year)
+{
int i;
struct fmt_st out;
- do_monthly(day, month, year, &out);
+ do_monthly(julian, weekstart, day_headings, full_month, day, month, year, &out);
for (i = 0; i < FMT_ST_LINES; i++) {
my_putstring(out.s[i]);
my_putstring("\n");
}
}
-void
-monthly3(int day, int month, int year) {
+void monthly3(const int julian, const int weekstart, const char *day_headings,
+ const char **full_month, int day, int month, int year)
+{
char lineout[FMT_ST_CHARS];
int i;
int width;
@@ -560,9 +561,9 @@ monthly3(int day, int month, int year) {
next_year = year;
}
- do_monthly(day, prev_month, prev_year, &out_prev);
- do_monthly(day, month, year, &out_curm);
- do_monthly(day, next_month, next_year, &out_next);
+ do_monthly(julian, weekstart, day_headings, full_month, day, prev_month, prev_year, &out_prev);
+ do_monthly(julian, weekstart, day_headings, full_month, day, month, year, &out_curm);
+ do_monthly(julian, weekstart, day_headings, full_month, day, next_month, next_year, &out_next);
width = (julian ? J_WEEK_LEN : WEEK_LEN) -1;
for (i = 0; i < 2; i++) {
@@ -589,8 +590,9 @@ monthly3(int day, int month, int year) {
}
}
-void
-yearly(int day, int year, int julian) {
+void yearly(int day, int year, const int julian, const int weekstart,
+ const char *day_headings, const char **full_month)
+{
int col, *dp, i, month, row, which_cal;
int maxrow, sep_len, week_len;
int days[MONTHS_IN_YEAR][MAXDAYS];
@@ -613,7 +615,7 @@ yearly(int day, int year, int julian) {
my_putstring("\n\n");
for (i = 0; i < MONTHS_IN_YEAR; i++)
- day_array(day, i + 1, year, days[i]);
+ day_array(julian, weekstart, day, i + 1, year, days[i]);
for (month = 0; month < MONTHS_IN_YEAR; month += maxrow) {
center(full_month[month], week_len - 1, sep_len + 1);
if (julian) {
@@ -635,7 +637,7 @@ yearly(int day, int year, int julian) {
for (which_cal = 0; which_cal < maxrow; which_cal++) {
dp = &days[month + which_cal][row * DAYS_IN_WEEK];
for (col = 0; col < DAYS_IN_WEEK; col++)
- p = ascii_day(p, *dp++);
+ p = ascii_day(julian, p, *dp++);
p += sprintf(p, " ");
}
*p = '\0';
@@ -653,8 +655,9 @@ yearly(int day, int year, int julian) {
* out end to end. You would have 42 numbers or spaces. This routine
* builds that array for any month from Jan. 1 through Dec. 9999.
*/
-void
-day_array(int day, int month, int year, int *days) {
+void day_array(const int julian, const int weekstart, int day, int month,
+ int year, int *days)
+{
int julday, daynum, dw, dm;
int *sep1752;
@@ -684,8 +687,8 @@ day_array(int day, int month, int year, int *days) {
* day_in_year --
* return the 1 based day number within the year
*/
-int
-day_in_year(int day, int month, int year) {
+int day_in_year(int day, int month, int year)
+{
int i, leap;
leap = leap_year(year);
@@ -701,8 +704,8 @@ day_in_year(int day, int month, int year) {
* 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
* missing days.
*/
-int
-day_in_week(int day, int month, int year) {
+int day_in_week(int day, int month, int year)
+{
long temp;
temp =
@@ -716,8 +719,8 @@ day_in_week(int day, int month, int year) {
return(REFORMATION_WEEKDAY);
}
-char *
-ascii_day(char *p, int day) {
+char *ascii_day(const int julian, char *p, int day)
+{
int display, val;
int highlight = 0;
static char *aday[] = {
@@ -769,15 +772,13 @@ ascii_day(char *p, int day) {
* In addition if the string is too large for the width it's truncated.
* The number of trailing spaces may be 1 less than the number of leading spaces.
*/
-int
-center_str(const char* src, char* dest, size_t dest_size, size_t width)
+int center_str(const char *src, char *dest, size_t dest_size, size_t width)
{
return mbsalign(src, dest, dest_size, &width,
MBS_ALIGN_CENTER, MBA_UNIBYTE_FALLBACK);
}
-void
-center(const char *str, size_t len, int separate)
+void center(const char *str, size_t len, int separate)
{
char lineout[FMT_ST_CHARS];
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 15/16] cal: mark all functions static
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (13 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 14/16] cal: move global variables to local scope Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 16/16] cal: simplify day_in_week() Sami Kerola
15 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Proposed-by: Dave Reisner <dreisner@archlinux.org>
Reference: http://marc.info/?l=util-linux-ng&m=136717012419551&w=2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 61 +++++++++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 29 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 127a855..78f092d 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -227,18 +227,18 @@ static int days_in_month[2][13] = {
static int leap_year(int year);
static int centuries_since_1700(int year, int centuries);
static int leap_years_since_year_1(int year);
-char * ascii_day(const int, char *, int);
-int center_str(const char* src, char* dest, size_t dest_size, size_t width);
-void center(const char *, size_t, int);
-void day_array(const int, const int, int, int, int, int *);
-int day_in_week(int, int, int);
-int day_in_year(int, int, int);
-void yearly(int, int, const int, const int, const char *, const char **);
-void do_monthly(const int, const int, const char *, const char **, int, int, int, struct fmt_st*);
-void monthly(const int, const int, const char *, const char **, int, int, int);
-void monthly3(const int, const int, const char *, const char **, int, int, int);
+static char * ascii_day(const int, char *, int);
+static int center_str(const char* src, char* dest, size_t dest_size, size_t width);
+static void center(const char *, size_t, int);
+static void day_array(const int, const int, int, int, int, int *);
+static int day_in_week(int, int, int);
+static int day_in_year(int, int, int);
+static void yearly(int, int, const int, const int, const char *, const char **);
+static void do_monthly(const int, const int, const char *, const char **, int, int, int, struct fmt_st*);
+static void monthly(const int, const int, const char *, const char **, int, int, int);
+static void monthly3(const int, const int, const char *, const char **, int, int, int);
static void __attribute__ ((__noreturn__)) usage(FILE * out);
-void headers_init(const int, const int, char *, const char **);
+static void headers_init(const int, const int, char *, const char **);
int
main(int argc, char **argv) {
@@ -461,8 +461,8 @@ static int leap_years_since_year_1(int year)
centuries_since_1700(year, 4));
}
-void headers_init(const int julian, const int weekstart, char *day_headings,
- const char **full_month)
+static void headers_init(const int julian, const int weekstart,
+ char *day_headings, const char **full_month)
{
int i, wd, spaces = julian ? J_DAY_LEN - 1 : DAY_LEN - 1;
char *cur_dh = day_headings;
@@ -485,9 +485,9 @@ void headers_init(const int julian, const int weekstart, char *day_headings,
full_month[i] = nl_langinfo(MON_1 + i);
}
-void do_monthly(const int julian, const int weekstart, const char *day_headings,
- const char **full_month, int day, int month, int year,
- struct fmt_st *out)
+static void do_monthly(const int julian, const int weekstart,
+ const char *day_headings, const char **full_month,
+ int day, int month, int year, struct fmt_st *out)
{
int col, row, days[MAXDAYS];
char *p, lineout[FMT_ST_CHARS];
@@ -521,8 +521,9 @@ void do_monthly(const int julian, const int weekstart, const char *day_headings,
}
}
-void monthly(const int julian, const int weekstart, const char *day_headings,
- const char **full_month, int day, int month, int year)
+static void monthly(const int julian, const int weekstart,
+ const char *day_headings, const char **full_month, int day,
+ int month, int year)
{
int i;
struct fmt_st out;
@@ -534,8 +535,9 @@ void monthly(const int julian, const int weekstart, const char *day_headings,
}
}
-void monthly3(const int julian, const int weekstart, const char *day_headings,
- const char **full_month, int day, int month, int year)
+static void monthly3(const int julian, const int weekstart,
+ const char *day_headings, const char **full_month, int day,
+ int month, int year)
{
char lineout[FMT_ST_CHARS];
int i;
@@ -590,8 +592,8 @@ void monthly3(const int julian, const int weekstart, const char *day_headings,
}
}
-void yearly(int day, int year, const int julian, const int weekstart,
- const char *day_headings, const char **full_month)
+static void yearly(int day, int year, const int julian, const int weekstart,
+ const char *day_headings, const char **full_month)
{
int col, *dp, i, month, row, which_cal;
int maxrow, sep_len, week_len;
@@ -655,8 +657,8 @@ void yearly(int day, int year, const int julian, const int weekstart,
* out end to end. You would have 42 numbers or spaces. This routine
* builds that array for any month from Jan. 1 through Dec. 9999.
*/
-void day_array(const int julian, const int weekstart, int day, int month,
- int year, int *days)
+static void day_array(const int julian, const int weekstart, int day, int month,
+ int year, int *days)
{
int julday, daynum, dw, dm;
int *sep1752;
@@ -687,7 +689,7 @@ void day_array(const int julian, const int weekstart, int day, int month,
* day_in_year --
* return the 1 based day number within the year
*/
-int day_in_year(int day, int month, int year)
+static int day_in_year(int day, int month, int year)
{
int i, leap;
@@ -704,7 +706,7 @@ int day_in_year(int day, int month, int year)
* 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
* missing days.
*/
-int day_in_week(int day, int month, int year)
+static int day_in_week(int day, int month, int year)
{
long temp;
@@ -719,7 +721,7 @@ int day_in_week(int day, int month, int year)
return(REFORMATION_WEEKDAY);
}
-char *ascii_day(const int julian, char *p, int day)
+static char *ascii_day(const int julian, char *p, int day)
{
int display, val;
int highlight = 0;
@@ -772,13 +774,14 @@ char *ascii_day(const int julian, char *p, int day)
* In addition if the string is too large for the width it's truncated.
* The number of trailing spaces may be 1 less than the number of leading spaces.
*/
-int center_str(const char *src, char *dest, size_t dest_size, size_t width)
+static int center_str(const char *src, char *dest, size_t dest_size,
+ size_t width)
{
return mbsalign(src, dest, dest_size, &width,
MBS_ALIGN_CENTER, MBA_UNIBYTE_FALLBACK);
}
-void center(const char *str, size_t len, int separate)
+static void center(const char *str, size_t len, int separate)
{
char lineout[FMT_ST_CHARS];
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH 16/16] cal: simplify day_in_week()
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
` (14 preceding siblings ...)
2013-05-02 18:51 ` [PATCH 15/16] cal: mark all functions static Sami Kerola
@ 2013-05-02 18:51 ` Sami Kerola
2013-05-03 20:19 ` Sami Kerola
15 siblings, 1 reply; 27+ messages in thread
From: Sami Kerola @ 2013-05-02 18:51 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The day_in_week() does not need to perform fullfledged September 1752
calculations, that month is dealt as static assignment.
Reported-by: Thomas Bächler <thomas@archlinux.org>
References: http://www.spinics.net/lists/util-linux-ng/msg07910.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/cal.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 78f092d..d9b07bf 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -164,7 +164,6 @@ enum {
};
#define FIRST_WEEKDAY SATURDAY /* Jan 1st, 1 was a Saturday */
-#define REFORMATION_WEEKDAY THURSDAY /* after reformation it was Thursday */
#define REFORMATION_YEAR 1752 /* Signed-off-by: Lord Chesterfield */
#define REFORMATION_MONTH 9 /* September */
#define FIRST_MISSING_DAY 639799 /* 3 Sep 1752 */
@@ -702,9 +701,9 @@ static int day_in_year(int day, int month, int year)
/*
* day_in_week
* return the 0 based day number for any date from 1 Jan. 1 to
- * 31 Dec. 9999. Assumes the Gregorian reformation eliminates
- * 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
- * missing days.
+ * 31 Dec. 9999. Assumes the Gregorian reformation dates
+ * 3 Sep. 1752 through 13 Sep. 1752 are handled as statically
+ * assigned array, see day_array().
*/
static int day_in_week(int day, int month, int year)
{
@@ -715,10 +714,10 @@ static int day_in_week(int day, int month, int year)
leap_years_since_year_1(year - SMALLEST_YEAR)
+ day_in_year(day, month, year);
if (temp < FIRST_MISSING_DAY)
- return ((temp - 1 + FIRST_WEEKDAY) % DAYS_IN_WEEK);
- if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS))
- return (((temp - 1 + FIRST_WEEKDAY) - NUMBER_MISSING_DAYS) % DAYS_IN_WEEK);
- return(REFORMATION_WEEKDAY);
+ return ((temp + (FIRST_WEEKDAY - 1)) % DAYS_IN_WEEK);
+ if (temp > FIRST_MISSING_DAY)
+ return ((temp + (FIRST_WEEKDAY - 1 - NUMBER_MISSING_DAYS)) % DAYS_IN_WEEK);
+ abort();
}
static char *ascii_day(const int julian, char *p, int day)
--
1.8.2.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH 16/16] cal: simplify day_in_week()
2013-05-02 18:51 ` [PATCH 16/16] cal: simplify day_in_week() Sami Kerola
@ 2013-05-03 20:19 ` Sami Kerola
0 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-03 20:19 UTC (permalink / raw)
To: util-linux
On 2 May 2013 19:51, Sami Kerola <kerolasa@iki.fi> wrote:
> The day_in_week() does not need to perform fullfledged September 1752
> calculations, that month is dealt as static assignment.
Hi Karel, and others,
Please drop this patch. Having abort() at the end of the function is
bad choice, if something like weekday name highlighting is
implemented[1]. When I reconsider that bit the function it should
return for the eleven days at September 1752 a day out of bounds,
which basically some sort of NaN equivalent.
[1] http://www.spinics.net/lists/util-linux-ng/msg07904.html
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 09/16] cal: add --highligth option which uses argmatch
2013-05-02 18:51 ` [PATCH 09/16] cal: add --highligth option which uses argmatch Sami Kerola
@ 2013-05-06 0:11 ` Pádraig Brady
2013-05-06 10:44 ` Sami Kerola
2013-05-06 17:19 ` Karel Zak
1 sibling, 1 reply; 27+ messages in thread
From: Pádraig Brady @ 2013-05-06 0:11 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On 05/02/2013 07:51 PM, Sami Kerola wrote:
> This switch will allow an user to choose when highlighting is outputed.
> The default remains the same as it has been, e.g., highlighting is used
> depending on whether stdout is a terminal or not.
>
> CC: Pádraig Brady <P@draigBrady.com>
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> misc-utils/Makemodule.am | 2 +-
> misc-utils/cal.c | 40 ++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am
> index a615047..3f95458 100644
> --- a/misc-utils/Makemodule.am
> +++ b/misc-utils/Makemodule.am
> @@ -10,7 +10,7 @@ if !HAVE_LANGINFO
> cal_SOURCES += lib/langinfo.c
> endif
>
> -cal_LDADD = $(LDADD)
> +cal_LDADD = $(LDADD) libcommon.la
>
> if HAVE_TINFO
> cal_LDADD += -ltinfo @NCURSES_LIBS@
> diff --git a/misc-utils/cal.c b/misc-utils/cal.c
> index 665dbcd..cf50c57 100644
> --- a/misc-utils/cal.c
> +++ b/misc-utils/cal.c
> @@ -66,6 +66,7 @@
> #include <unistd.h>
> #include <errno.h>
>
> +#include "argmatch.h"
> #include "c.h"
> #include "closestream.h"
> #include "nls.h"
> @@ -256,6 +257,24 @@ main(int argc, char **argv) {
> int ch, day = 0, month = 0, year = 0, yflag = 0;
> int num_months = NUM_MONTHS;
>
> + enum Highlight_type {
> + HIGHLIGHT_UNUSED,
> + HIGHLIGHT_NEVER,
> + HIGHLIGHT_AUTO,
> + HIGHLIGHT_ALWAYS
> + };
> + int highlight = HIGHLIGHT_AUTO;
> + static char const *const highlight_type_string[] = {
> + "never", "auto", "always", NULL
> + };
> + static enum Highlight_type const highlight_type[] = {
> + HIGHLIGHT_NEVER, HIGHLIGHT_AUTO, HIGHLIGHT_ALWAYS
> + };
> +
> + enum {
> + OPT_HIGHLIGHT = CHAR_MAX + 1
> + };
> +
> static const struct option longopts[] = {
> {"one", no_argument, NULL, '1'},
> {"three", no_argument, NULL, '3'},
> @@ -263,6 +282,7 @@ main(int argc, char **argv) {
> {"monday", no_argument, NULL, 'm'},
> {"julian", no_argument, NULL, 'j'},
> {"year", no_argument, NULL, 'y'},
> + {"highlight", required_argument, NULL, OPT_HIGHLIGHT},
I'd have it as an optional arg, defaulting to auto.
> {"version", no_argument, NULL, 'V'},
> {"help", no_argument, NULL, 'h'},
> {NULL, 0, NULL, 0}
> @@ -340,6 +360,9 @@ main(int argc, char **argv) {
> case 'y':
> yflag = 1;
> break;
> + case OPT_HIGHLIGHT:
> + highlight = XARGMATCH("--highlight", optarg, highlight_type_string, highlight_type);
> + break;
> case 'V':
> printf(UTIL_LINUX_VERSION);
> return EXIT_SUCCESS;
> @@ -391,8 +414,21 @@ main(int argc, char **argv) {
> }
> headers_init(julian);
>
> - if (!isatty(STDOUT_FILENO))
> - day = 0; /* don't highlight */
> + switch (highlight) {
> + case HIGHLIGHT_NEVER:
> + day = 0;
> + break;
> + case HIGHLIGHT_AUTO:
> + if (!isatty(STDOUT_FILENO))
> + day = 0; /* don't highlight */
> + break;
> + case HIGHLIGHT_ALWAYS:
> + if (day == 0)
> + day = local_time->tm_yday + 1;;
s/;;/;/ shellism :)
> + break;
> + default:
> + abort();
> + }
>
> if (yflag)
> yearly(day, year, julian);
>
s/highligth/highlight/ in the subject line
Also I'd s/--highlight/--color/ to align with dmesg and other utils.
Only highlighting is done at present, but that could be set up
to use color in the user's environment. Also in future other parts
of the output could be colored etc.
BTW, dmesg could get the same support for specifying "always" and "never".
thanks!
Pádraig.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 13/16] cal: stop trimming whitespaces
2013-05-02 18:51 ` [PATCH 13/16] cal: stop trimming whitespaces Sami Kerola
@ 2013-05-06 0:12 ` Pádraig Brady
2013-05-14 10:45 ` Karel Zak
1 sibling, 0 replies; 27+ messages in thread
From: Pádraig Brady @ 2013-05-06 0:12 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On 05/02/2013 07:51 PM, Sami Kerola wrote:
> Remove trailing spaces from output it is trivial
>
> cal | sed 's/ *$//'
>
> but padding them back is difficult.
>
> CC: Pádraig Brady <P@draigbrady.com>
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Looks good.
thanks,
Pádraig.
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 09/16] cal: add --highligth option which uses argmatch
2013-05-06 0:11 ` Pádraig Brady
@ 2013-05-06 10:44 ` Sami Kerola
0 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-06 10:44 UTC (permalink / raw)
To: Pádraig Brady; +Cc: util-linux
On 6 May 2013 01:11, Pádraig Brady <P@draigbrady.com> wrote:
Hi Pádraig,
> I'd have it as an optional arg, defaulting to auto.
Good point. That would result to more consistent interface, which is a
virtue in itself.
>> + case HIGHLIGHT_ALWAYS:
>> + if (day == 0)
>> + day = local_time->tm_yday + 1;;
>
> s/;;/;/ shellism :)
Oops, I will push a fix to my git within next 48 hours. I have slight
problem with my programming environment at the moment which I need to
sort out first.
>> + break;
>> + default:
>> + abort();
>> + }
>>
>> if (yflag)
>> yearly(day, year, julian);
>>
>
> s/highligth/highlight/ in the subject line
Oh dear, me and my finglish.
> Also I'd s/--highlight/--color/ to align with dmesg and other utils.
> Only highlighting is done at present, but that could be set up
> to use color in the user's environment. Also in future other parts
> of the output could be colored etc.
>
> BTW, dmesg could get the same support for specifying "always" and "never".
Karel earlier mentioned the same, and I wrote some sort of change
which will add --when to dmesg. Allowing user to choose dmesg colors
etc highlights using facilities & priorities as criteria would
probably be quite neat feature.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 08/16] lib: copy argmatch from gnulib
2013-05-02 18:51 ` [PATCH 08/16] lib: copy argmatch from gnulib Sami Kerola
@ 2013-05-06 17:16 ` Karel Zak
2013-05-07 21:14 ` Sami Kerola
0 siblings, 1 reply; 27+ messages in thread
From: Karel Zak @ 2013-05-06 17:16 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Thu, May 02, 2013 at 07:51:33PM +0100, Sami Kerola wrote:
> Both argmatch.h and argmatch.c are copied from gnulib.
Ah no... this is overkill, all we need is to parse three words.
I have updated lib/colors.c and dmesg.c to support color modes 'auto',
'never' and 'always'. Please, use it also in cal.c.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 09/16] cal: add --highligth option which uses argmatch
2013-05-02 18:51 ` [PATCH 09/16] cal: add --highligth option which uses argmatch Sami Kerola
2013-05-06 0:11 ` Pádraig Brady
@ 2013-05-06 17:19 ` Karel Zak
1 sibling, 0 replies; 27+ messages in thread
From: Karel Zak @ 2013-05-06 17:19 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux, Pádraig Brady
On Thu, May 02, 2013 at 07:51:34PM +0100, Sami Kerola wrote:
> static const struct option longopts[] = {
> {"one", no_argument, NULL, '1'},
> {"three", no_argument, NULL, '3'},
> @@ -263,6 +282,7 @@ main(int argc, char **argv) {
> {"monday", no_argument, NULL, 'm'},
> {"julian", no_argument, NULL, 'j'},
> {"year", no_argument, NULL, 'y'},
> + {"highlight", required_argument, NULL, OPT_HIGHLIGHT},
I agree with Pádraig, --color seems better and extendible.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 08/16] lib: copy argmatch from gnulib
2013-05-06 17:16 ` Karel Zak
@ 2013-05-07 21:14 ` Sami Kerola
0 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-07 21:14 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 6 May 2013 18:16, Karel Zak <kzak@redhat.com> wrote:
> On Thu, May 02, 2013 at 07:51:33PM +0100, Sami Kerola wrote:
>> Both argmatch.h and argmatch.c are copied from gnulib.
>
> Ah no... this is overkill, all we need is to parse three words.
>
> I have updated lib/colors.c and dmesg.c to support color modes 'auto',
> 'never' and 'always'. Please, use it also in cal.c.
I thought there might be other uses to argmatch, but perhaps there
isn't. I changed the cal to use lib/colors.c argument parsing in
'cal-again' branch.
https://github.com/kerolasa/lelux-utiliteetit/commit/a33225e623b389e49d05b665104dcdef17e01502
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 13/16] cal: stop trimming whitespaces
2013-05-02 18:51 ` [PATCH 13/16] cal: stop trimming whitespaces Sami Kerola
2013-05-06 0:12 ` Pádraig Brady
@ 2013-05-14 10:45 ` Karel Zak
2013-05-21 20:34 ` Sami Kerola
1 sibling, 1 reply; 27+ messages in thread
From: Karel Zak @ 2013-05-14 10:45 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux, Pádraig Brady
On Thu, May 02, 2013 at 07:51:38PM +0100, Sami Kerola wrote:
> Remove trailing spaces from output it is trivial
and introduce a regression and ugly output, see "cal -3":
old version:
April 2013 May 2013 June 2013
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 4 1
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29
30
new version:
April 2013 May 2013 June 2013
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 4 1
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29
30
btw, it's pretty obvious from
https://github.com/kerolasa/lelux-utiliteetit/commit/5b472fb7f4d8b855756a249633250e818a560a66
I guess we have regression test just to check for regressions.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 14/16] cal: move global variables to local scope
2013-05-02 18:51 ` [PATCH 14/16] cal: move global variables to local scope Sami Kerola
@ 2013-05-14 10:49 ` Karel Zak
0 siblings, 0 replies; 27+ messages in thread
From: Karel Zak @ 2013-05-14 10:49 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Thu, May 02, 2013 at 07:51:39PM +0100, Sami Kerola wrote:
> Also include small change to function parameter coding style. The braces
> are from function line to new line, and return value is in same line with
> the function.
The version you send to mailing list seems correct, but the version
in your cal-again branch is completely broken. It's obvious that
nobody has tried "make cal" for the branch :-(
Anyway, I'm really not sure if this change:
> -void monthly(int, int, int);
> +void monthly(const int, const int, const char *, const char **, int, int, int);
makes the code more readable. Maybe you can drop the patch at all for now.
From long term point of view it would be better to introduce
'cal_context' struct for all the stuff. It's a way how to make the
code more readable and extendible.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH 13/16] cal: stop trimming whitespaces
2013-05-14 10:45 ` Karel Zak
@ 2013-05-21 20:34 ` Sami Kerola
0 siblings, 0 replies; 27+ messages in thread
From: Sami Kerola @ 2013-05-21 20:34 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux, Pádraig Brady
On 14 May 2013 11:45, Karel Zak <kzak@redhat.com> wrote:
> On Thu, May 02, 2013 at 07:51:38PM +0100, Sami Kerola wrote:
>> Remove trailing spaces from output it is trivial
>
> and introduce a regression and ugly output, see "cal -3":
[d'oh]
> I guess we have regression test just to check for regressions.
Fixed here.
https://github.com/kerolasa/lelux-utiliteetit/commit/a0a150f8c14ac6b62483d03ec446f07e751903bf#L0L564
As all can see removal of couple white spaces removed regression.
I also dropped the global variables patch (earlier nr 14) from the
fourth branch. There are no other changes in 'cal-fourth' branch.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2013-05-21 20:34 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-02 18:51 [PATCH 00/16]: [pull] cal: second review round Sami Kerola
2013-05-02 18:51 ` [PATCH 01/16] cal: fix preprocessor directive indendation Sami Kerola
2013-05-02 18:51 ` [PATCH 02/16] cal: convert function like definitions to functions Sami Kerola
2013-05-02 18:51 ` [PATCH 03/16] cal: clean up use of constants Sami Kerola
2013-05-02 18:51 ` [PATCH 04/16] tests: add calendar reformation check Sami Kerola
2013-05-02 18:51 ` [PATCH 05/16] cal: simplify calendar reformat calculations Sami Kerola
2013-05-02 18:51 ` [PATCH 06/16] cal: remove unnecessary initializations Sami Kerola
2013-05-02 18:51 ` [PATCH 07/16] cal: de-duplicate julian specific functions Sami Kerola
2013-05-02 18:51 ` [PATCH 08/16] lib: copy argmatch from gnulib Sami Kerola
2013-05-06 17:16 ` Karel Zak
2013-05-07 21:14 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 09/16] cal: add --highligth option which uses argmatch Sami Kerola
2013-05-06 0:11 ` Pádraig Brady
2013-05-06 10:44 ` Sami Kerola
2013-05-06 17:19 ` Karel Zak
2013-05-02 18:51 ` [PATCH 10/16] cal: add --highlight to usage() Sami Kerola
2013-05-02 18:51 ` [PATCH 11/16] docs: cal: add --highlight option description Sami Kerola
2013-05-02 18:51 ` [PATCH 12/16] tests: add cal day highlight corner cases Sami Kerola
2013-05-02 18:51 ` [PATCH 13/16] cal: stop trimming whitespaces Sami Kerola
2013-05-06 0:12 ` Pádraig Brady
2013-05-14 10:45 ` Karel Zak
2013-05-21 20:34 ` Sami Kerola
2013-05-02 18:51 ` [PATCH 14/16] cal: move global variables to local scope Sami Kerola
2013-05-14 10:49 ` Karel Zak
2013-05-02 18:51 ` [PATCH 15/16] cal: mark all functions static Sami Kerola
2013-05-02 18:51 ` [PATCH 16/16] cal: simplify day_in_week() Sami Kerola
2013-05-03 20:19 ` Sami Kerola
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox