Convert cal(1) to strtonum
This commit is contained in:
parent
7a0c2669fb
commit
8c359daee3
23
cal.c
23
cal.c
@ -1,4 +1,5 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -136,15 +137,15 @@ usage(void)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int year, month, ncols, nmons, fday;
|
|
||||||
struct tm *ltime;
|
struct tm *ltime;
|
||||||
|
int year, ncols, nmons, month, fday;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
ltime = localtime(&now);
|
ltime = localtime(&now);
|
||||||
year = ltime->tm_year + 1900;
|
year = ltime->tm_year + 1900;
|
||||||
month = ltime->tm_mon + 1;
|
month = ltime->tm_mon + 1;
|
||||||
fday = 0;
|
fday = 0;
|
||||||
|
|
||||||
ncols = 3;
|
ncols = 3;
|
||||||
nmons = 0;
|
nmons = 0;
|
||||||
@ -162,16 +163,16 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
ncols = estrtol(EARGF(usage()), 0);
|
ncols = estrtonum(EARGF(usage()), 0, INT_MAX);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
fday = estrtol(EARGF(usage()), 0);
|
fday = estrtonum(EARGF(usage()), 0, 6);
|
||||||
break;
|
break;
|
||||||
case 'm': /* Monday */
|
case 'm': /* Monday */
|
||||||
fday = 1;
|
fday = 1;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
nmons = estrtol(EARGF(usage()), 0);
|
nmons = estrtonum(EARGF(usage()), 1, INT_MAX);
|
||||||
break;
|
break;
|
||||||
case 's': /* Sunday */
|
case 's': /* Sunday */
|
||||||
fday = 0;
|
fday = 0;
|
||||||
@ -195,10 +196,10 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 2:
|
case 2:
|
||||||
month = estrtol(argv[0], 0);
|
month = estrtonum(argv[0], 1, 12);
|
||||||
argv++;
|
argv++;
|
||||||
case 1:
|
case 1:
|
||||||
year = estrtol(argv[0], 0);
|
year = estrtonum(argv[0], 0, INT_MAX);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
@ -206,10 +207,6 @@ main(int argc, char *argv[])
|
|||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ncols < 0 || month < 1 || month > 12 || nmons < 1 || fday < 0 || fday > 6) {
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
drawcal(year, month - 1, ncols, nmons, fday);
|
drawcal(year, month - 1, ncols, nmons, fday);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user