Commit Graph

30 Commits

Author SHA1 Message Date
Richard Ipsum
5b92551057 cal: Centre month and year above calendar 2019-04-28 14:10:38 -07:00
Richard Ipsum
aae808fe5b cal: Fix grid alignment for years < 1000 2019-04-22 19:08:17 -07:00
sin
41a9742037 cal: Highlight current day
Thanks cls!
2015-11-21 10:20:07 +00:00
sin
2366164de7 No need for semicolon after ARGEND
This is also the style used in Plan 9.
2015-11-01 10:18:55 +00:00
FRIGN
11e2d472bf Add *fshut() functions to properly flush file streams
This has been a known issue for a long time. Example:

printf "word" > /dev/full

wouldn't report there's not enough space on the device.
This is due to the fact that every libc has internal buffers
for stdout which store fragments of written data until they reach
a certain size or on some callback to flush them all at once to the
kernel.
You can force the libc to flush them with fflush(). In case flushing
fails, you can check the return value of fflush() and report an error.

However, previously, sbase didn't have such checks and without fflush(),
the libc silently flushes the buffers on exit without checking the errors.
No offense, but there's no way for the libc to report errors in the exit-
condition.

GNU coreutils solve this by having onexit-callbacks to handle the flushing
and report issues, but they have obvious deficiencies.
After long discussions on IRC, we came to the conclusion that checking the
return value of every io-function would be a bit too much, and having a
general-purpose fclose-wrapper would be the best way to go.

It turned out that fclose() alone is not enough to detect errors. The right
way to do it is to fflush() + check ferror on the fp and then to a fclose().
This is what fshut does and that's how it's done before each return.
The return value is obviously affected, reporting an error in case a flush
or close failed, but also when reading failed for some reason, the error-
state is caught.

the !!( ... + ...) construction is used to call all functions inside the
brackets and not "terminating" on the first.
We want errors to be reported, but there's no reason to stop flushing buffers
when one other file buffer has issues.
Obviously, functionales come before the flush and ret-logic comes after to
prevent early exits as well without reporting warnings if there are any.

One more advantage of fshut() is that it is even able to report errors
on obscure NFS-setups which the other coreutils are unable to detect,
because they only check the return-value of fflush() and fclose(),
not ferror() as well.
2015-04-05 09:13:56 +01:00
Hiltjo Posthuma
8f436abde6 style: document intentional fallthrough 2015-03-09 00:33:13 +01:00
FRIGN
8ffa06b3dc Add little estrtonum()-range-fix 2015-03-08 21:35:16 +01:00
FRIGN
76ad86b2a3 Audit cal(1)
1) Update manpage with the num-syntax.
2) Use size_t for years and derivatives.
3) Use putchar instead of printf wherever possible.
4) Update usage().
5) Style changes.
2015-03-08 21:28:32 +01:00
FRIGN
8c359daee3 Convert cal(1) to strtonum 2015-01-30 16:01:37 +01:00
FRIGN
40bbe91c9e Fix a small error in cal(1) manpage
The current implementation doesn't implement the day-variable.
2015-01-16 21:48:50 +00:00
FRIGN
f8177c8ca4 cal(1) cleanup
According to suckless coding guidelines.
2015-01-16 21:22:24 +00:00
Greg Reagle
efac15726b If only the year operand is given, cal shall produce a calendar for all twelve months in the given calendar year. 2015-01-16 16:26:42 +00:00
Greg Reagle
6c2074560e Use the Julian/Gregorian calendar
Use the Julian calendar for dates through September 2, 1752 and
the Gregorian calendar for dates from September 14, 1752.
2015-01-16 10:03:18 +00:00
Greg Reagle
83616df6fc cal: Removed unused "day" variable 2015-01-07 03:21:12 +00:00
Greg Reagle
c6f1e8aa20 Various cal(1) improvements
1) No limit on number of months (removed MONTHMAX)
2) Strings printed to stdout rather than copied to an internal buffer
3) Rewritten date calculation algorithms
2015-01-02 13:14:41 +00:00
Markus Wichmann
fea48eb229 Fix problem with multi month display spanning a year. 2014-12-16 10:56:13 +00:00
FRIGN
ec8246bbc6 Un-boolify sbase
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
2014-11-14 10:54:20 +00:00
FRIGN
eee98ed3a4 Fix coding style
It was about damn time. Consistency is very important in such a
big codebase.
2014-11-13 18:08:43 +00:00
sin
0c5b7b9155 Stop using EXIT_{SUCCESS,FAILURE} 2014-10-02 23:46:59 +01:00
Willem van de Krol
f02f2190f0 fixed incorrect fday handling in dayofweek() function 2014-07-04 21:47:36 +01:00
Willem van de Krol
5721deb2c4 optimized isleap() function 2014-07-04 21:47:12 +01:00
Hiltjo Posthuma
953ebf3573 code style
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-06-01 18:02:30 +01:00
Hiltjo Posthuma
f7403ce6c6 style: whitespace fixes
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
2014-04-01 16:20:43 +01:00
sin
b5a511dacf Exit with EXIT_SUCCESS/EXIT_FAILURE instead of 0 and 1
Fixed for consistency purposes.
2013-10-07 16:44:22 +01:00
sin
af4af8a0d8 Change sprintf to snprintf
cal.c:40: warning: sprintf() is often misused, please use snprintf()
2013-07-20 00:54:49 -04:00
Christoph Lohmann
45f67c556b Another correction for the cal(1) usage. 2013-06-19 23:24:34 +02:00
Jesse Ogle
6442071c29 Updated cal usage()
Now usage matches cal.1

Signed-off-by: Christoph Lohmann <20h@r-36.net>
2013-06-19 23:23:59 +02:00
Jesse Ogle
8fc4858a3c Bugfix for cal when columns specified as 0
cal -c 0 caused an infinite loop. now the number of columns is set to
the number of months when 0 (i.e. the calendars never wrap).

Signed-off-by: Christoph Lohmann <20h@r-36.net>
2013-06-19 23:23:43 +02:00
Christoph Lohmann
b10b1da57d Make date(1) compatible to GNU date(1).
We have variable first day of weeks now! My week starts on Wednesday!
2013-06-19 22:10:26 +02:00
Jesse Ogle
0f523ec9c6 Added cal and updated Makefile
Signed-off-by: Christoph Lohmann <20h@r-36.net>
2013-06-19 21:13:28 +02:00