* BUG: cal prints bad month headers
@ 2014-05-27 9:45 Ruediger Meier
2014-05-27 10:50 ` Ruediger Meier
0 siblings, 1 reply; 6+ messages in thread
From: Ruediger Meier @ 2014-05-27 9:45 UTC (permalink / raw)
To: util-linux; +Cc: Sami Kerola
Hi,
I have a system where "cal -ym" diff looks like this:
------------
Gregorian - Monday-based week
- 2006
+ 2006 January February March April
May June July August September October November December
+
- 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
@@ -10,7 +10,7 @@
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
@@ -18,7 +18,7 @@
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
@@ -26,7 +26,7 @@
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
--------------------
This happens only if output is redirected into a file
$ ./cal -ym > bla ;cat bla
It looks good in terminal.
Reverting 95f4adde (plus 0c6dc4b9 and 4a7424a5) fixes the problem.
The system is a Fedora 18, ppc64. I can't reproduce it on any other
ppc64 system. Unfortunately I don't have any other Fedora 18 for
testing.
cu,
Rudi
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: BUG: cal prints bad month headers 2014-05-27 9:45 BUG: cal prints bad month headers Ruediger Meier @ 2014-05-27 10:50 ` Ruediger Meier 2014-05-27 11:29 ` Pádraig Brady 2014-05-27 13:07 ` [PATCH] cal: all output must use my_putstring Ruediger Meier 0 siblings, 2 replies; 6+ messages in thread From: Ruediger Meier @ 2014-05-27 10:50 UTC (permalink / raw) To: util-linux; +Cc: Sami Kerola On Tuesday 27 May 2014, Ruediger Meier wrote: > This happens only if output is redirected into a file > $ ./cal -ym > bla ;cat bla > It looks good in terminal. > > Reverting 95f4adde (plus 0c6dc4b9 and 4a7424a5) fixes the problem. Just another hint. Adding a fflush() like you see below also "fixes" the problem. Maybe we are mixing several output methods (printf, puts, my_putstring, etc.) like we shouldn't. diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 81375fe..2b61a30 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -760,6 +760,7 @@ static void yearly(const struct cal_control *ctl) set_consecutive_months(&m1, month, ctl->req.year); for (i = &m1; i; i = i->next) cal_fill_month(i, ctl); + fflush(NULL); cal_output_header(&m1, ctl); cal_output_months(&m1, ctl); } ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: BUG: cal prints bad month headers 2014-05-27 10:50 ` Ruediger Meier @ 2014-05-27 11:29 ` Pádraig Brady 2014-05-27 13:07 ` [PATCH] cal: all output must use my_putstring Ruediger Meier 1 sibling, 0 replies; 6+ messages in thread From: Pádraig Brady @ 2014-05-27 11:29 UTC (permalink / raw) To: Ruediger Meier; +Cc: util-linux, Sami Kerola On 05/27/2014 11:50 AM, Ruediger Meier wrote: > On Tuesday 27 May 2014, Ruediger Meier wrote: >> This happens only if output is redirected into a file >> $ ./cal -ym > bla ;cat bla >> It looks good in terminal. >> >> Reverting 95f4adde (plus 0c6dc4b9 and 4a7424a5) fixes the problem. > > Just another hint. Adding a fflush() like you see below also "fixes" the > problem. Maybe we are mixing several output methods (printf, puts, > my_putstring, etc.) like we shouldn't. > > diff --git a/misc-utils/cal.c b/misc-utils/cal.c > index 81375fe..2b61a30 100644 > --- a/misc-utils/cal.c > +++ b/misc-utils/cal.c > @@ -760,6 +760,7 @@ static void yearly(const struct cal_control *ctl) > set_consecutive_months(&m1, month, ctl->req.year); > for (i = &m1; i; i = i->next) > cal_fill_month(i, ctl); > + fflush(NULL); > cal_output_header(&m1, ctl); > cal_output_months(&m1, ctl); > } > -- > To unsubscribe from this list: send the line "unsubscribe util-linux" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > This would avoid the problem. The correct fix would to have all output go through the same channel (buffer), i.e. all output should use my_putstring() cheers, Pádraig. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] cal: all output must use my_putstring 2014-05-27 10:50 ` Ruediger Meier 2014-05-27 11:29 ` Pádraig Brady @ 2014-05-27 13:07 ` Ruediger Meier 2014-05-27 14:12 ` Karel Zak 1 sibling, 1 reply; 6+ messages in thread From: Ruediger Meier @ 2014-05-27 13:07 UTC (permalink / raw) To: util-linux; +Cc: Pádraig Brady From: Ruediger Meier <ruediger.meier@ga-group.nl> Replace all puts, fputs and printf calls by my_putstring() because we don't want to mix different output channels (buffers). Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl> --- misc-utils/cal.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 81375fe..e763fe1 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -609,7 +609,7 @@ static void cal_output_header(struct cal_month *month, const struct cal_control center(out, ctl->week_width - 1, i->next == NULL ? 0 : ctl->gutter_width); } if (!ctl->yflag) { - fputs("\n", stdout); + my_putstring("\n"); for (i = month; i; i = i->next) { sprintf(out, _("%d"), i->year); center(out, ctl->week_width - 1, i->next == NULL ? 0 : ctl->gutter_width); @@ -621,23 +621,27 @@ static void cal_output_header(struct cal_month *month, const struct cal_control center(out, ctl->week_width - 1, i->next == NULL ? 0 : ctl->gutter_width); } } - puts(""); + my_putstring("\n"); for (i = month; i; i = i->next) { if (ctl->weektype) { if (ctl->julian) - printf("%*s%s", (int)ctl->day_width - 1, "", day_headings); + sprintf(out, "%*s%s", (int)ctl->day_width - 1, "", day_headings); else - printf("%*s%s", (int)ctl->day_width, "", day_headings); + sprintf(out, "%*s%s", (int)ctl->day_width, "", day_headings); + my_putstring(out); } else - fputs(day_headings, stdout); - if (i->next != NULL) - printf("%*s", ctl->gutter_width, ""); + my_putstring(day_headings); + if (i->next != NULL) { + sprintf(out, "%*s", ctl->gutter_width, ""); + my_putstring(out); + } } - puts(""); + my_putstring("\n"); } static void cal_output_months(struct cal_month *month, const struct cal_control *ctl) { + char out[FMT_ST_CHARS]; int reqday, week_line, d; int skip; struct cal_month *i; @@ -659,12 +663,13 @@ static void cal_output_months(struct cal_month *month, const struct cal_control if (0 < i->weeks[week_line]) { if ((ctl->weektype & WEEK_NUM_MASK) == i->weeks[week_line]) - printf("%s%2d%s", Senter, i->weeks[week_line], + sprintf(out, "%s%2d%s", Senter, i->weeks[week_line], Sexit); else - printf("%2d", i->weeks[week_line]); + sprintf(out, "%2d", i->weeks[week_line]); } else - printf("%2s", ""); + sprintf(out, "%2s", ""); + my_putstring(out); skip = ctl->day_width; } else /* First day of the week is one char narrower than the other days, @@ -675,21 +680,26 @@ static void cal_output_months(struct cal_month *month, const struct cal_control d < DAYS_IN_WEEK * week_line + DAYS_IN_WEEK; d++) { if (0 < i->days[d]) { if (reqday == i->days[d]) - printf("%*s%s%*d%s", skip - (ctl->julian ? 3 : 2), + sprintf(out, "%*s%s%*d%s", skip - (ctl->julian ? 3 : 2), "", Senter, (ctl->julian ? 3 : 2), i->days[d], Sexit); else - printf("%*d", skip, i->days[d]); + sprintf(out, "%*d", skip, i->days[d]); } else - printf("%*s", skip, ""); + sprintf(out, "%*s", skip, ""); + my_putstring(out); if (skip < (int)ctl->day_width) skip++; } - if (i->next != NULL) - printf("%*s", ctl->gutter_width, ""); + if (i->next != NULL) { + sprintf(out, "%*s", ctl->gutter_width, ""); + my_putstring(out); + } + } + if (i == NULL) { + sprintf(out, "%*s\n", ctl->gutter_width - (ctl->yflag ? 0 : 1), ""); + my_putstring(out); } - if (i == NULL) - printf("%*s\n", ctl->gutter_width - (ctl->yflag ? 0 : 1), ""); } } @@ -754,7 +764,7 @@ static void yearly(const struct cal_control *ctl) year_width--; sprintf(out, "%d", ctl->req.year); center(out, year_width, 0); - fputs("\n\n", stdout); + my_putstring("\n\n"); for (month = 1; month < MONTHS_IN_YEAR; month += ctl->julian ? 2 : 3) { set_consecutive_months(&m1, month, ctl->req.year); @@ -764,7 +774,7 @@ static void yearly(const struct cal_control *ctl) cal_output_months(&m1, ctl); } /* Is empty line at the end year output really needed? */ - puts(""); + my_putstring("\n"); } /* -- 1.8.4.5 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] cal: all output must use my_putstring 2014-05-27 13:07 ` [PATCH] cal: all output must use my_putstring Ruediger Meier @ 2014-05-27 14:12 ` Karel Zak 2014-05-27 14:50 ` Ruediger Meier 0 siblings, 1 reply; 6+ messages in thread From: Karel Zak @ 2014-05-27 14:12 UTC (permalink / raw) To: Ruediger Meier; +Cc: util-linux, Pádraig Brady On Tue, May 27, 2014 at 03:07:05PM +0200, Ruediger Meier wrote: > From: Ruediger Meier <ruediger.meier@ga-group.nl> > > Replace all puts, fputs and printf calls by my_putstring() because > we don't want to mix different output channels (buffers). Oh, this is well know problem I fixed one year ago, see e66ba1bfaf070682e26c1a53e64af1088fea56bc. It seems the problem was re-introduced during Sami's cal(1) refactoring. Thanks! I'm going to push it. Karel -- Karel Zak <kzak@redhat.com> http://karelzak.blogspot.com ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] cal: all output must use my_putstring 2014-05-27 14:12 ` Karel Zak @ 2014-05-27 14:50 ` Ruediger Meier 0 siblings, 0 replies; 6+ messages in thread From: Ruediger Meier @ 2014-05-27 14:50 UTC (permalink / raw) To: Karel Zak; +Cc: util-linux, Pádraig Brady On Tuesday 27 May 2014, Karel Zak wrote: > On Tue, May 27, 2014 at 03:07:05PM +0200, Ruediger Meier wrote: > > From: Ruediger Meier <ruediger.meier@ga-group.nl> > > > > Replace all puts, fputs and printf calls by my_putstring() because > > we don't want to mix different output channels (buffers). > > Oh, this is well know problem I fixed one year ago, see > e66ba1bfaf070682e26c1a53e64af1088fea56bc. Funny that this one was also a fix for Fedora 18. Probably F-18 has bad ncurses-libs or glibc because usually it seemed to be compatible to printf function family. putp() uses tputs() which uses putc() per default. putc() should be mixable with any other stdio output function. cu, Rudi ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-05-28 11:29 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-05-27 9:45 BUG: cal prints bad month headers Ruediger Meier 2014-05-27 10:50 ` Ruediger Meier 2014-05-27 11:29 ` Pádraig Brady 2014-05-27 13:07 ` [PATCH] cal: all output must use my_putstring Ruediger Meier 2014-05-27 14:12 ` Karel Zak 2014-05-27 14:50 ` Ruediger Meier
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox