Commit Graph

168 Commits

Author SHA1 Message Date
Karel Zak 31862cde0a fix compiler warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-21 10:26:25 +01:00
Karel Zak 07c8462fb7 cal: do not use putp(), directly use stdio functions
It seems our putp() based output is not portable as some ncurses
implementations strictly follow POSIX where putp() accepts only
terminfo capability strings and nothing else.

We already use standard stdio.h functions to output terminfo strings
(e.g.  for colors). It seems we can do the same for cal(1) to
highlight the current day.

Note that mix putp() and fputs() is bad idea due to different
buffering ways in some cases (see cal.c git log for more details).

This patch also reduces complexity of the code as we can directly
output to stdout without snprintf to string.

Addresses: https://github.com/karelzak/util-linux/pull/1167
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 10:19:26 +02:00
Karel Zak 7586e9d1aa cal: use size_t to calculate width [lgtm scan]
We use size_t for width. This patch makes it consistent for
years_width too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-03 13:17:51 +02:00
Aurelien LAJOIE 27fafcf8a8 cal: Add column mode
Add`-v` `--vertical` option to get a vertical output
Add it into relative bash-completion

For example `cal -yv`

                             2020

    January            February           March
Su     5 12 19 26         2  9 16 23      1  8 15 22 29
Mo     6 13 20 27         3 10 17 24      2  9 16 23 30
Tu     7 14 21 28         4 11 18 25      3 10 17 24 31
We  1  8 15 22 29         5 12 19 26      4 11 18 25
Th  2  9 16 23 30         6 13 20 27      5 12 19 26
Fr  3 10 17 24 31         7 14 21 28      6 13 20 27
Sa  4 11 18 25         1  8 15 22 29      7 14 21 28

    April              May                June
Su     5 12 19 26         3 10 17 24 31      7 14 21 28
Mo     6 13 20 27         4 11 18 25      1  8 15 22 29
Tu     7 14 21 28         5 12 19 26      2  9 16 23 30
We  1  8 15 22 29         6 13 20 27      3 10 17 24
Th  2  9 16 23 30         7 14 21 28      4 11 18 25
Fr  3 10 17 24         1  8 15 22 29      5 12 19 26
Sa  4 11 18 25         2  9 16 23 30      6 13 20 27

    July               August             September
Su     5 12 19 26         2  9 16 23 30      6 13 20 27
Mo     6 13 20 27         3 10 17 24 31      7 14 21 28
Tu     7 14 21 28         4 11 18 25      1  8 15 22 29
We  1  8 15 22 29         5 12 19 26      2  9 16 23 30
Th  2  9 16 23 30         6 13 20 27      3 10 17 24
Fr  3 10 17 24 31         7 14 21 28      4 11 18 25
Sa  4 11 18 25         1  8 15 22 29      5 12 19 26

    October            November           December
Su     4 11 18 25      1  8 15 22 29         6 13 20 27
Mo     5 12 19 26      2  9 16 23 30         7 14 21 28
Tu     6 13 20 27      3 10 17 24         1  8 15 22 29
We     7 14 21 28      4 11 18 25         2  9 16 23 30
Th  1  8 15 22 29      5 12 19 26         3 10 17 24 31
Fr  2  9 16 23 30      6 13 20 27         4 11 18 25
Sa  3 10 17 24 31      7 14 21 28         5 12 19 26
2020-05-11 17:27:06 +02:00
Aurelien LAJOIE 4de7efb505 cal: Add helper functions for left align 2020-05-11 17:25:34 +02:00
Aurelien LAJOIE 0c440bd7a2 cal: Add weekdays into cal_control 2020-05-11 17:23:37 +02:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Aurelien LAJOIE a5e322f4f4 cal: correctly set the week width
There is seven values but only 6 spaces between them, that why the -1
The value is always used with a minus one, just set it correctly instead
of always fix when used

Signed-off-by: Aurelien LAJOIE <orel@melix.net>
2020-03-31 15:32:01 +02:00
Aurelien LAJOIE b908299188 cal: Correctly center the year
Signed-off-by: Aurelien LAJOIE <orel@melix.net>
2020-03-31 15:31:54 +02:00
Aurelien LAJOIE c1f1439316 cal: use a const char*
A put string function should not modify the char*

Signed-off-by: Aurelien LAJOIE <orel@melix.net>
2020-03-31 15:31:52 +02:00
Sami Kerola 3160589d86
various: use threadsafe versions of time functions [lgtm scan]
Deprecating calls to not-thread safe asctime(), ctime(), and localtime()
calls is pretty close to pointless change.  Lets do it to reduce lgtm scan
warnings with justification it's nicer to use static analysis tools when
they have very few positives.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-02-15 15:23:44 +00:00
Sami Kerola a7466bdcbe
po: remove possibility to translate static option arguments
These strings are expected to be wrote exactly as they are parsed, so make
translating them impossible.  Since mkfs.cramfs -N option arguments need
this treatment use opportunity to slice usage() output to multiple lines.

Addresses: https://bugs.debian.org/907568
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-24 09:29:52 +01:00
Karel Zak f06d8b69a9 cal: make sure months_in_row makes sense [coverity scan]
* avoid divide by zero in mountly() dues to wrong months_in_row
* make sure months_in_row is at least 1

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-16 14:22:43 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak d135e1a1e3 cal: fix Sexit and Senter
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-18 13:10:58 +01:00
Karel Zak f90d8b8bcc cal: use standout mode on monochrome terminals
The function colors_init() checks for colors, it means it fails
on monochrome terminals, but cal(1) in this case still need to
highlight the current day.

Reported-by: Nuno Silva <nunojsilva@ist.utl.pt>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-04 14:20:03 +01:00
Karel Zak 2395f93c8c cal: fix --span for large numbers of months
The need to calculate with whole years when go back for --span.

Addresses: https://github.com/karelzak/util-linux/issues/677
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-07 10:52:33 +02:00
Karel Zak 100a140688 cal: use snprintf everywhere
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-07 10:15:42 +02:00
Sami Kerola 1405658822 nls: remove translation strings
While looking earlier commit I noticed everything but formatting was removed
from a message in namei.c file.  That inspired me to look if there are more
strings that does not need translation project attention.  This change
removes at least some of them, if not all.

Reference: e19cc7b65b
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-28 13:36:38 +02:00
Karel Zak b9d9ab7dae cal: add ifdef TEST_CAL
The test program follows CAL_TEST_TIME=<sec> rather than libc time().
It allows to use cal(1) in regression tests in cases where output
depends on the current time.

(We already use the same for example for logger.)

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-02 10:05:15 +01:00
Karel Zak f066c107ce cal: remove extra space after year output
Reported-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-30 16:17:10 +01:00
Karel Zak 37bd991f77 cal: don't use year header for -1, -3 or -n
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-30 16:14:15 +01:00
Karel Zak 8315a2ff15 cal: follow terminal width
* modify number of months in row according to the terminal width
* don't print blank space behind last char on row

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-30 16:10:06 +01:00
J William Piggott d7db28c6d6 cal: do not set months_in_row with -3 option
Having the -3 option set months_in_row causes ordinal days
to wrap; it overrides the automatic handling of months_in_row
that falls back to 2 month columns for ordinal days.

Before:
cal -3j 2020
                           2020

            July                         August                      September
Sun Mon Tue Wed Thu Fri Sat   Sun Mon Tue Wed Thu Fri Sat   Sun Mon Tue Wed Thu Fri Sat
    182 183 184 185 186 187                   213 214 215   244 245 246 247 248 249 250
188 189 190 191 192 193 194   216 217 218 219 220 221 222   251 252 253 254 255 256 257
195 196 197 198 199 200 201   223 224 225 226 227 228 229   258 259 260 261 262 263 264
202 203 204 205 206 207 208   230 231 232 233 234 235 236   265 266 267 268 269 270 271
209 210 211 212               237 238 239 240 241 242 243   272 273

Patched:
cal -3j 2020
                           2020

          December                      January
Sun Mon Tue Wed Thu Fri Sat   Sun Mon Tue Wed Thu Fri Sat
335 336 337 338 339 340 341                 1   2   3   4
342 343 344 345 346 347 348     5   6   7   8   9  10  11
349 350 351 352 353 354 355    12  13  14  15  16  17  18
356 357 358 359 360 361 362    19  20  21  22  23  24  25
363 364 365                    26  27  28  29  30  31

          February
Sun Mon Tue Wed Thu Fri Sat
                         32
 33  34  35  36  37  38  39
 40  41  42  43  44  45  46
 47  48  49  50  51  52  53
 54  55  56  57  58  59  60

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2018-01-24 13:24:33 +01:00
J William Piggott 2bcf8f7934 cal: honor num_months when only a year argument
I don't know if this was an oversight or an overzealous
interpretation of POSIX. Just in case, I'll address the
POSIX possibility. POSIX description for cal(1) says:

  If only the year operand is given, cal shall produce a
  calendar for all twelve months in the given calendar year.

It also says that cal(1) has no options, so in that context
if an option is given then it should be expected to override
POSIX behavior.

Before patched all of these command displayed a full year:
cal -1 2020
cal -3 2020
cal -n6 2020

Patched the number of months options are honored.

This patch also fixes the -1 option which was a no-op.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2018-01-24 13:24:33 +01:00
J William Piggott 6304358cb7 cal: fix first week calculation
Commit efafeaf set 1 Jan as week 1, but the change
was missed in week_to_day() and in the man page.

Before
cal --week=40 --iso 1752
      October 1752
   Su Mo Tu We Th Fr Sa
41  1  2  3  4  5  6  7
42  8  9 10 11 12 13 14
43 15 16 17 18 19 20 21
44 22 23 24 25 26 27 28
45 29 30 31

Patched
cal --week=40 --iso 1752
     September 1752
   Su Mo Tu We Th Fr Sa
36                 1  2
37  3  4  5  6  7  8  9
38 10 11 12 13 14 15 16
39 17 18 19 20 21 22 23
40 24 25 26 27 28 29 30

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2018-01-22 14:16:57 +01:00
J William Piggott e572a765f9 cal: fix week calculations for 1752
Before:
cal --week=39 1752
     September 1752
   Su Mo Tu We Th Fr Sa
36        1  2 14 15 16
37 17 18 19 20 21 22 23
38 24 25 26 27 28 29 30

Patched:
cal --week=39 1752
      October 1752
   Su Mo Tu We Th Fr Sa
39  1  2  3  4  5  6  7
40  8  9 10 11 12 13 14
41 15 16 17 18 19 20 21
42 22 23 24 25 26 27 28
43 29 30 31

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2018-01-22 14:16:57 +01:00
Rafal Luzynski 4e12a62e88 cal: Use ALTMON_* correctly
cal: use ALTMON_* and _NL_ABALTMON_* constants to display
months in a standalone form correctly.  These constants have just
been newly added to glibc.  ALTMON_x has been used in BSD family
since 1990s and has been accepted as the future POSIX extension.
_NL_ABALTMON_* is exclusively a GNU extension but it is expected
to be added to POSIX in future.

More info: https://sourceware.org/bugzilla/show_bug.cgi?id=10871
2018-01-22 11:50:50 +01:00
J William Piggott 1dca3edc36 cal: fix julian calendars for large years
Before:
cal --r julian 31 12 2147483646
 December 2147483646
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 31

Patched:
cal --r julian 31 12 2147483646
 December 2147483646
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 31

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2018-01-22 11:33:20 +01:00
J William Piggott ae51e7b429 cal: add option to set Gregorian reform date
Create the new option: --reform <1752|gregorian|iso|julian>

This adds the capability to display either the proleptic Gregorian or
the Julian calendar systems exclusively.

Also create the option --iso as alias of --reform=gregorian.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
2018-01-16 13:51:24 -05:00
J William Piggott db9baa8ab7 cal: move REFORMATION_YEAR to control struct
Signed-off-by: J William Piggott <elseifthen@gmx.com>
2018-01-15 11:06:36 -05:00
Karel Zak 6ce7eca36c cal: fix multi-byte comment, explain in better way
On Sun, Dec 17, 2017 at 07:47:49PM -0500, J William Piggott wrote
> * it contains multi-byte characters (which is what drew me to reading it).
> * it truncates one very important piece of the formula: ". . . (mod 7)."
> * it explains the values for 'e', but there is no 'e' in the code.
> * it doesn't include a row resolving 'e' in the table, so it is not
>    obvious what it relates to in the code.
> * without citing it as an external reference, the comment language is confusing.

Co-Author: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-18 12:44:03 +01:00
Karel Zak b9c650106b Revert "cal: simplify leap year rule"
It was mistake, we use extra rule for date < 1752 from the beginning
and another calculations depends on this.

This reverts commit b9bd8dc267.
2017-12-14 13:19:08 +01:00
Karel Zak 3c49b23ad6 cal: explain magic values for day of week calculation
Based on BERNDT E.SCHWERDTFEGER papers.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-13 19:09:56 +01:00
Karel Zak b9bd8dc267 cal: simplify leap year rule
Gregorian rule for leap years has been adopted by reformation in year
1782 (Calendar Act 1750), but all tools (date, SQL servers, etc. etc.)
don't care about it and apply the new rule for all year -- including
years before the reformation.

It's better to be compatible with another tools than try to be perfect :-)

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1507271
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-13 17:34:19 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Karel Zak 3947ca4ca9 build-sys: ncurses headers cleanup
* assume ncursesw headers in ncursesw/ directory only
* prefer long paths, <term.h> and <ncurses.h> should be last
  possibility
* fix typos

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-31 11:01:46 +02:00
Karel Zak 18451b2cf4 cal: ncurses cleanup
* use proper paths to term.h
* keep ncurses support optional
* link with TINFO_LIBS (-ltinfo), or fallback to NCURSES_LIBS (-ltinfo -lncurses)
* don't include unnecessary ncurses.h (term.h is enough)

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-30 17:14:46 +02:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Ruediger Meier 12f17a23df misc: fix typos using codespell
# command used was:
 $ ~/src/codespell/codespell \
   -w -D /home/rudi/src/codespell/build/lib/codespell_lib/data/dictionary.txt \
   $(git ls-files | grep -v "^po/\|\.xz$\|\.gz$\|\.bz2$\|\.img$\|^Documentation/releases/")

 BTW some manually grammer fixes:
   s/uses/used/
   s/begin/beginning/

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-01 00:01:43 +01:00
Karel Zak c880563200 cal: support abbreviated month names
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-07 16:10:28 +02:00
Karel Zak 535fd6d2b6 cal: support alone month name parameter
For example 'cal August' to print August for the current year.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-07 16:02:36 +02:00
Karel Zak c49fb9cacd cal: remove err message from monthname_to_number()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-07 15:24:32 +02:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Karel Zak 58149472ad cal: cleanup non-ncurses build 2016-06-09 11:39:24 +02:00