cal: fix preprocessor directive indendation

And code within the blocks selected by preprocessor to be live code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cal: convert function like definitions to functions

Reviewed-by: Thomas Bächler <thomas@archlinux.org>
Reviewed-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cal: clean up use of constants

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>
tests: add calendar reformation check

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cal: simplify calendar reformat calculations

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>
cal: remove unnecessary initializations

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cal: de-duplicate julian specific functions

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>
lib: copy argmatch from gnulib

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>
cal: add --highligth option which uses argmatch

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>
cal: add --highlight to usage()

And clean up the usage() function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
docs: cal: add --highlight option description

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
tests: add cal day highlight corner cases

Check that the first, andn last, possible dates  and strange Sep 1752
dates are highlighted correctly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cal: stop trimming whitespaces

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>
cal: move global variables to local scope

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>
cal: mark all functions static

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>
cal: simplify day_in_week()

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>