From cc3212838417a9f55fa102918a83442a081af986 Mon Sep 17 00:00:00 2001 From: mdw Date: Fri, 15 Oct 1999 21:05:28 +0000 Subject: [PATCH] In `key list', show timezone for local times, and support `-u' option for UTC output. --- keyutil.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/keyutil.c b/keyutil.c index adf8c50..9219ef5 100644 --- a/keyutil.c +++ b/keyutil.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: keyutil.c,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id: keyutil.c,v 1.2 1999/10/15 21:05:28 mdw Exp $ * * Simple key manager program * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: keyutil.c,v $ + * Revision 1.2 1999/10/15 21:05:28 mdw + * In `key list', show timezone for local times, and support `-u' option + * for UTC output. + * * Revision 1.1 1999/09/03 08:41:12 mdw * Initial import. * @@ -338,7 +342,8 @@ static int cmd_list(int argc, char *argv[]) enum { f_bogus = 1, f_newline = 2, - f_attr = 4 + f_attr = 4, + f_utc = 8 }; /* --- Parse subcommand options --- */ @@ -347,13 +352,17 @@ static int cmd_list(int argc, char *argv[]) static struct option opt[] = { { "quiet", 0, 0, 'q' }, { "verbose", 0, 0, 'v' }, + { "utc", 0, 0, 'u' }, { 0, 0, 0, 0 } }; - int i = mdwopt(argc, argv, "qv", opt, 0, 0, 0); + int i = mdwopt(argc, argv, "+uqv", opt, 0, 0, 0); if (i < 0) break; switch (i) { + case 'u': + fl |= f_utc; + break; case 'q': if (v) v--; @@ -368,7 +377,7 @@ static int cmd_list(int argc, char *argv[]) } if (fl & f_bogus || optind != argc) - die(EXIT_FAILURE, "Usage: list [-qv]"); + die(EXIT_FAILURE, "Usage: list [-uqv]"); /* --- Open the key file --- */ @@ -377,7 +386,12 @@ static int cmd_list(int argc, char *argv[]) /* --- Write the header --- */ - tfmt = v ? "%Y-%m-%d %H:%M:%S" : "%Y-%m-%d"; + if (!v) + tfmt = "%Y-%m-%d"; + else if (fl & f_utc) + tfmt = "%Y-%m-%d %H:%M:%S UTC"; + else + tfmt = "%Y-%m-%d %H:%M:%S %Z"; /* --- Now iterate through the keys --- */ @@ -399,7 +413,7 @@ static int cmd_list(int argc, char *argv[]) if (k->exp == KEXP_FOREVER) strcpy(ebuf, "forever"); else { - tm = localtime(&k->exp); + tm = (fl & f_utc) ? gmtime(&k->exp) : localtime(&k->exp); strftime(ebuf, sizeof(ebuf), tfmt, tm); } @@ -567,7 +581,7 @@ static struct cmd { { "delete", cmd_delete, "delete KEYID..." }, { "setattr", cmd_setattr, "setattr KEYID ATTR..." }, { "comment", cmd_comment, "comment KEYID [COMMENT]" }, - { "list", cmd_list, "list [-qv]" }, + { "list", cmd_list, "list [-uqv]" }, { "tidy", cmd_tidy, "tidy" }, { "extract", cmd_extract, "extract FILE KEYID..." }, { "merge", cmd_merge, "merge FILE" }, -- 2.11.0