From ccc96d7ab5e206fa28bb0267fb3c852ae0befda4 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 10 Jun 2016 15:20:01 -0700 Subject: [PATCH] strftime.c: update to latest Signed-off-by: Kyle J. McKay --- src/strftime.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/strftime.c b/src/strftime.c index ac7bbe8..c639a65 100644 --- a/src/strftime.c +++ b/src/strftime.c @@ -20,8 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #define VERSION \ -"strftime version 1.0.0\n" \ -"Copyright (C) 2016 Kyle J. McKay \n" \ +"strftime version 1.1.0\n" \ +"Copyright (C) 2016 Kyle J. McKay \n" \ "License GPLv2+: GNU GPL version 2 or later.\n" \ "\n" \ "This is free software: you are free to change and redistribute it.\n" \ @@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. " --help/-h show this help\n" \ " --version/-V show version/license info\n" \ " --locale/-l use default locale rather than \"C\" locale\n" \ +" --adjust/-a n add n (which may be negative) to before formatting\n" \ " -- terminate options, next arg is format even if it starts with -\n" \ " if omitted or empty string ('') use current time\n" \ " must be [+|-]HH[MM[SS]] same meaning as strftime(3) '%z' value\n" \ @@ -64,6 +65,7 @@ int main(int argc, char *argv[]) int defaultformat = 1; int dosetlocale = 0; struct tm localvals; + long adjust = 0; while (arg < argc && *argv[arg] == '-') { if (!strcmp(argv[arg], "--help") || !strcmp(argv[arg], "-h")) { @@ -79,6 +81,23 @@ int main(int argc, char *argv[]) ++arg; continue; } + if (!strcmp(argv[arg], "--adjust") || !strcmp(argv[arg], "-a")) { + char *end; + + if (++arg >= argc || !*argv[arg]) { + fprintf(stderr, "strftime: missing --adjust value " + "(see strftime -h)\n"); + return 1; + } + adjust = strtol(argv[arg], &end, 10); + if (*end) { + fprintf(stderr, "strftime: invalid number: %s\n", + argv[arg]); + return 2; + } + ++arg; + continue; + } if (!strcmp(argv[arg], "--")) { ++arg; break; @@ -153,6 +172,7 @@ int main(int argc, char *argv[]) setlocale(LC_ALL, ""); } tzset(); + t += (time_t)adjust; localvals = *localtime(&t); if (!strftime(buff, sizeof(buff), fmt, &localvals)) { fprintf(stderr, "strftime: format string too long\n"); -- 2.11.4.GIT