summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 81096a5..f450281 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,6 +36,12 @@ extern const char *PACKAGE_VERSION_GIT;
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
struct option LONGOPTS_[] = {
{
+ .name = "list-formats",
+ .has_arg = 0,
+ .flag = NULL,
+ .val = 'F',
+ },
+ {
.name = "help",
.has_arg = 0,
.flag = NULL,
@@ -62,15 +68,76 @@ _print_help(const char *program_name)
_print_usage(stdout, program_name);
puts("Options:");
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
- puts("\t-h, --help Show this help information");
- puts("\t-V, --version Show version information");
+ puts("\t-F, --list-formats List all supported date and time formats");
+ puts("\t-h, --help Show this help information");
+ puts("\t-V, --version Show version information");
#else
+ puts("\t-F List all supported date and time formats");
puts("\t-h Show this help information");
puts("\t-V Show version information");
#endif
}
static void
+_list_formats(void)
+{
+ time_t tim;
+ struct tm *tm;
+ char *out;
+ size_t out_sz;
+ char *buf;
+ size_t i;
+
+ tim = time(NULL);
+ tm = localtime(&tim);
+
+ puts("Time formats:");
+ out = NULL;
+ out_sz = 0;
+ buf = NULL;
+ i = 0;
+ while (datetime_strftime_time(tm, &out, &out_sz, &buf, &i) > 0) {
+ printf(" * %s\n", out);
+ }
+ if (out != NULL) {
+ free(out);
+ }
+ if (buf != NULL) {
+ free(buf);
+ }
+
+ puts("Date formats:");
+ out = NULL;
+ out_sz = 0;
+ buf = NULL;
+ i = 0;
+ while (datetime_strftime_date(tm, &out, &out_sz, &buf, &i) > 0) {
+ printf(" * %s\n", out);
+ }
+ if (out != NULL) {
+ free(out);
+ }
+ if (buf != NULL) {
+ free(buf);
+ }
+
+ puts("Additional formats:");
+ out = NULL;
+ out_sz = 0;
+ buf = NULL;
+ i = 0;
+ while (datetime_strftime_misc(tm, &out, &out_sz, &buf, &i) > 0) {
+ printf(" * %s\n", out);
+ }
+ if (out != NULL) {
+ free(out);
+ }
+ if (buf != NULL) {
+ free(buf);
+ }
+}
+
+static void
_print_version(void)
{
printf("@ (atsign) %s%s\n", PACKAGE_VERSION, PACKAGE_VERSION_GIT);
@@ -128,11 +195,14 @@ main(int argc, char * const argv[])
optind = 1;
opterr = 0;
#if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG
- while ((opt = getopt_long(argc, argv, "hV", LONGOPTS_, NULL)) > 0) {
+ while ((opt = getopt_long(argc, argv, "FhV", LONGOPTS_, NULL)) > 0) {
#else
- while ((opt = getopt(argc, argv, "hV")) > 0) {
+ while ((opt = getopt(argc, argv, "FhV")) > 0) {
#endif
switch (opt) {
+ case 'F':
+ _list_formats();
+ return EXIT_SUCCESS;
case 'h':
_print_help(argv[0]);
return EXIT_SUCCESS;