cal(1) cleanup

According to suckless coding guidelines.
This commit is contained in:
FRIGN 2015-01-16 22:17:54 +01:00 committed by sin
parent bdca40494a
commit f8177c8ca4
1 changed files with 29 additions and 28 deletions

23
cal.c
View File

@ -5,14 +5,14 @@
#include "util.h"
enum {Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
enum caltype {Julian, Gregorian};
enum {TRANS_YEAR = 1752, TRANS_MONTH = Sep, TRANS_DAY = 2};
enum { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };
enum caltype { JULIAN, GREGORIAN };
enum { TRANS_YEAR = 1752, TRANS_MONTH = SEP, TRANS_DAY = 2 };
static int
isleap(int year, enum caltype cal)
{
if (cal == Gregorian) {
if (cal == GREGORIAN) {
if (year % 400 == 0)
return 1;
if (year % 100 == 0)
@ -28,7 +28,8 @@ static int
monthlength(int year, int month, enum caltype cal)
{
int mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
return (month==Feb && isleap(year,cal)) ? 29 : mdays[month];
return (month == FEB && isleap(year,cal)) ? 29 : mdays[month];
}
/* From http://www.tondering.dk/claus/cal/chrweek.php#calcdow */
@ -36,12 +37,13 @@ static int
dayofweek(int year, int month, int dom, enum caltype cal)
{
int m, y, a;
month += 1; /* in this formula, 1 <= month <= 12 */
a = (14 - month) / 12;
y = year - a;
m = month + 12 * a - 2;
if (cal == Gregorian)
if (cal == GREGORIAN)
return (dom + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12) % 7;
else /* cal == Julian */
return (5 + dom + y + y / 4 + (31 * m) / 12) % 7;
@ -55,9 +57,9 @@ printgrid(int year, int month, int fday, int line)
int offset, dom, d = 0;
if (year < TRANS_YEAR || (year == TRANS_YEAR && month <= TRANS_MONTH))
cal = Julian;
cal = JULIAN;
else
cal = Gregorian;
cal = GREGORIAN;
trans = (year == TRANS_YEAR && month == TRANS_MONTH);
offset = dayofweek(year, month, 1, cal) - fday;
if (offset < 0)
@ -127,9 +129,8 @@ drawcal(int year, int month, int ncols, int nmons, int fday)
static void
usage(void)
{
eprintf("usage: %s [-1] [-3] [-m] [-s] [-y] [-c columns]"
" [-f firstday] [-n nmonths] [ [month] year]\n",
argv0);
eprintf("usage: %s [-1 | -3 | -y | -n nmonths] "
"[-s | -m | -f firstday] [-c columns] [[[day] month] year]\n", argv0);
}
int