Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/calendar/calendar.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <locale.h> | #include <locale.h> | ||||
#include <langinfo.h> | |||||
#include <pwd.h> | #include <pwd.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "calendar.h" | #include "calendar.h" | ||||
#define UTCOFFSET_NOTSET 100 /* Expected between -24 and +24 */ | #define UTCOFFSET_NOTSET 100 /* Expected between -24 and +24 */ | ||||
#define LONGITUDE_NOTSET 1000 /* Expected between -360 and +360 */ | #define LONGITUDE_NOTSET 1000 /* Expected between -360 and +360 */ | ||||
struct passwd *pw; | struct passwd *pw; | ||||
int doall = 0; | int doall = 0; | ||||
int debug = 0; | int debug = 0; | ||||
static char *DEBUG = NULL; | static char *DEBUG = NULL; | ||||
static time_t f_time = 0; | static time_t f_time = 0; | ||||
double UTCOffset = UTCOFFSET_NOTSET; | double UTCOffset = UTCOFFSET_NOTSET; | ||||
int EastLongitude = LONGITUDE_NOTSET; | int EastLongitude = LONGITUDE_NOTSET; | ||||
#ifdef WITH_ICONV | |||||
const char *outputEncoding; | |||||
#endif | |||||
static void usage(void) __dead2; | static void usage(void) __dead2; | ||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int f_dayAfter = 0; /* days after current date */ | int f_dayAfter = 0; /* days after current date */ | ||||
int f_dayBefore = 0; /* days before current date */ | int f_dayBefore = 0; /* days before current date */ | ||||
int Friday = 5; /* day before weekend */ | int Friday = 5; /* day before weekend */ | ||||
int ch; | int ch; | ||||
struct tm tp1, tp2; | struct tm tp1, tp2; | ||||
(void)setlocale(LC_ALL, ""); | (void)setlocale(LC_ALL, ""); | ||||
#ifdef WITH_ICONV | |||||
/* save the information about the encoding used in the terminal */ | |||||
outputEncoding = strdup(nl_langinfo(CODESET)); | |||||
if (outputEncoding == NULL) | |||||
errx(1, "cannot allocate memory"); | |||||
#endif | |||||
while ((ch = getopt(argc, argv, "-A:aB:D:dF:f:l:t:U:W:?")) != -1) | while ((ch = getopt(argc, argv, "-A:aB:D:dF:f:l:t:U:W:?")) != -1) | ||||
switch (ch) { | switch (ch) { | ||||
case '-': /* backward contemptible */ | case '-': /* backward contemptible */ | ||||
jilles: Perhaps `nl_langinfo(CODESET)` is better than hard-coding the locale name format. | |||||
case 'a': | case 'a': | ||||
if (getuid()) { | if (getuid()) { | ||||
errno = EPERM; | errno = EPERM; | ||||
err(1, NULL); | err(1, NULL); | ||||
} | } | ||||
doall = 1; | doall = 1; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |
Perhaps nl_langinfo(CODESET) is better than hard-coding the locale name format.