summaryrefslogtreecommitdiffstats
path: root/misc-utils/cal.c
Commit message (Collapse)AuthorAgeFilesLines
* cal: make sure months_in_row makes sense [coverity scan]Karel Zak2019-05-161-5/+11
| | | | | | | * 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>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-3/+2Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: fix Sexit and SenterKarel Zak2019-02-181-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: use standout mode on monochrome terminalsKarel Zak2019-02-041-3/+15
| | | | | | | | | 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>
* cal: fix --span for large numbers of monthsKarel Zak2018-08-071-6/+9
| | | | | | | 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>
* cal: use snprintf everywhereKarel Zak2018-08-071-15/+17
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* nls: remove translation stringsSami Kerola2018-05-281-3/+3
| | | | | | | | | | 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: e19cc7b65b31c57f0fe9cb73c9afad5197796f82 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* cal: add ifdef TEST_CALKarel Zak2018-02-021-2/+20
| | | | | | | | | | 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>
* cal: remove extra space after year outputKarel Zak2018-01-301-3/+0Star
| | | | | Reported-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: don't use year header for -1, -3 or -nKarel Zak2018-01-301-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: follow terminal widthKarel Zak2018-01-301-9/+19
| | | | | | | * 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>
* cal: do not set months_in_row with -3 optionJ William Piggott2018-01-241-1/+0Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* cal: honor num_months when only a year argumentJ William Piggott2018-01-241-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* cal: fix first week calculationJ William Piggott2018-01-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* cal: fix week calculations for 1752J William Piggott2018-01-221-0/+3
| | | | | | | | | | | | | | | | | | | | | | 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>
* cal: Use ALTMON_* correctlyRafal Luzynski2018-01-221-2/+2
| | | | | | | | | | | 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
* cal: fix julian calendars for large yearsJ William Piggott2018-01-221-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | 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>
* cal: add option to set Gregorian reform dateJ William Piggott2018-01-161-4/+49
| | | | | | | | | | | 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>
* cal: move REFORMATION_YEAR to control structJ William Piggott2018-01-151-37/+49
| | | | Signed-off-by: J William Piggott <elseifthen@gmx.com>
* cal: fix multi-byte comment, explain in better wayKarel Zak2017-12-181-13/+17
| | | | | | | | | | | | | 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>
* Revert "cal: simplify leap year rule"Karel Zak2017-12-141-1/+5
| | | | | | | It was mistake, we use extra rule for date < 1752 from the beginning and another calculations depends on this. This reverts commit b9bd8dc267a71611859496bff29e329868273714.
* cal: explain magic values for day of week calculationKarel Zak2017-12-131-8/+16
| | | | | | Based on BERNDT E.SCHWERDTFEGER papers. Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: simplify leap year ruleKarel Zak2017-11-131-5/+1Star
| | | | | | | | | | | | 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>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | 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>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | 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>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-5/+7
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: fix ggc-7 fallthrough warningsSami Kerola2017-06-141-2/+2
| | | | | | | | | | | | | | | | | | | (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>
* build-sys: ncurses headers cleanupKarel Zak2017-05-311-4/+4
| | | | | | | | | * 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>
* cal: ncurses cleanupKarel Zak2017-05-301-7/+8
| | | | | | | | | * 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>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-2/+2
| | | | | | | | | | 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>
* docs: Fix word repetitionsYuri Chornoivan2017-02-131-1/+1
|
* Use --help suggestion on invalid optionKarel Zak2016-12-191-2/+1Star
| | | | | | | | 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>
* misc: fix typos using codespellRuediger Meier2016-12-011-1/+1
| | | | | | | | | | | | | # 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>
* cal: support abbreviated month namesKarel Zak2016-10-071-1/+18
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: support alone month name parameterKarel Zak2016-10-071-2/+8
| | | | | | For example 'cal August' to print August for the current year. Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: remove err message from monthname_to_number()Karel Zak2016-10-071-3/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: simplify if clauses [oclint]Sami Kerola2016-07-211-4/+2Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* cal: cleanup non-ncurses buildKarel Zak2016-06-091-12/+17
|
* misc: Fix various typosSebastian Rasmussen2016-05-311-2/+2
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* cal: support timestampsKarel Zak2016-05-311-1/+11
| | | | | | | | For example $ cal '2 weeks ago' Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: allow to specify month by nameKarel Zak2016-05-311-2/+31
| | | | | | | | For example: $ cal August 2016 Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: use %04d for yearKarel Zak2016-05-181-4/+4
| | | | | | | | | | It seems that people are crazy enough to assume that "cal 16" is the year 2016, rather than 16 (2000 years ago). This patch makes it more clear as the output is 0016. Addresses: https://github.com/karelzak/util-linux/issues/320 Signed-off-by: Karel Zak <kzak@redhat.com>
* cal: remove libtermcap arguments to my_tgetstr()Sami Kerola2016-03-091-3/+3
| | | | | | Missed in commit b4566a8a8d0cf345e637194f9c95091a1ef4dfe0. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: safer (and uniform) handling of return valueYuriy M. Kaminskiy2016-03-071-1/+6
| | | | | | When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow. Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: remove libtermcap supportSami Kerola2016-01-261-48/+11Star
| | | | | | | | | | It is unlikely anyone is going to build this project on system where libtermcap is available. Fedora project obsoleted libtermcap 2007-12-12 in favour of ncurses. Debian made same move 2005. Reference: https://fedoraproject.org/wiki/Deprecated_packages Reference: https://www.debian.org/doc/manuals/debian-faq/ch-compat.en.html#s-termcap Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* cal: Add --span optionDeiz2015-10-101-8/+15
| | | | | | | This allows the date spanning behaviour of -3 to be used with other month ranges. Signed-off-by: Deiz <silverwraithii@gmail.com>
* cal: Track date span independently from months_in_rowDeiz2015-10-101-1/+4
| | | | | | | | This fixes a minor issue where cal -n 3 would mirror the spanning behaviour of cal -3 with Gregorian calendars, instead of starting with the current month. Signed-off-by: Deiz <silverwraithii@gmail.com>
* cal: check biggest week number correctly when highlightingSami Kerola2015-08-311-1/+1
| | | | | | | This allows Sunday based week 54 be highlighted, and deny week 54 for Monday based weeks when year has only 52 weeks. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* cal: replace magic constants with symbolical valuesSami Kerola2015-08-311-32/+41
| | | | | | This makes it easier to know what the values in guestion represent. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* cal: correct gregorian week numberingSami Kerola2015-08-311-18/+15Star
| | | | | | | | | | | Jan 1 is always First week, and year always has 53 weeks. The week 53 may be cut short, e.g., it may and often has fewer than 7 days. Every year 28 year intervals US week numbering continues all the way to 54th week, such as 1972, 2000, and 2028. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1249486 Reported-by: Michal Toth Signed-off-by: Sami Kerola <kerolasa@iki.fi>