summaryrefslogtreecommitdiffstats
path: root/games
diff options
context:
space:
mode:
authormux <mux@FreeBSD.org>2003-03-28 16:37:45 +0000
committermux <mux@FreeBSD.org>2003-03-28 16:37:45 +0000
commitc91649aa818a8c6873545d1a36c2af8d15756934 (patch)
tree1dc049ad691b6e8100f5e661a0e436304c28464a /games
parent7f82ad918495ef3ec718932a65ab651327491593 (diff)
downloadFreeBSD-src-c91649aa818a8c6873545d1a36c2af8d15756934.zip
FreeBSD-src-c91649aa818a8c6873545d1a36c2af8d15756934.tar.gz
Add an option to print the time in 12-hour format.
Submitted by: Samy Al Bahra <samy@kerneled.com>
Diffstat (limited to 'games')
-rw-r--r--games/grdc/grdc.64
-rw-r--r--games/grdc/grdc.c26
2 files changed, 26 insertions, 4 deletions
diff --git a/games/grdc/grdc.6 b/games/grdc/grdc.6
index 99b7678..e9beaf7 100644
--- a/games/grdc/grdc.6
+++ b/games/grdc/grdc.6
@@ -8,6 +8,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl s
+.Op Fl t
.Op Ar n
.Sh DESCRIPTION
.Nm
@@ -21,6 +22,9 @@ seconds (default never).
The optional
.Fl s
flag makes digits scroll as they change.
+The optional
+.Fl t
+flag tells grdc to output the time in a 12-hour format.
In this curses mode implementation,
the scrolling option has trouble keeping up.
.Sh AUTHORS
diff --git a/games/grdc/grdc.c b/games/grdc/grdc.c
index 97d956f..1c79c8c 100644
--- a/games/grdc/grdc.c
+++ b/games/grdc/grdc.c
@@ -1,11 +1,16 @@
/*
* Grand digital clock for curses compatible terminals
- * Usage: grdc [-s] [n] -- run for n seconds (default infinity)
+ * Usage: grdc [-st] [n] -- run for n seconds (default infinity)
* Flags: -s: scroll
+ * -t: output time in 12-hour format
+ *
*
* modified 10-18-89 for curses (jrl)
* 10-18-89 added signal handling
*
+ * modified 03-25-03 for 12 hour option
+ * - Samy Al Bahra <samy@kerneled.com>
+ *
* $FreeBSD$
*/
@@ -59,14 +64,18 @@ int i, j, s, k;
int n;
int ch;
int scrol;
+int t12;
- scrol = 0;
+ t12 = scrol = 0;
- while ((ch = getopt(argc, argv, "s")) != -1)
+ while ((ch = getopt(argc, argv, "ts")) != -1)
switch (ch) {
case 's':
scrol = 1;
break;
+ case 't':
+ t12 = 1;
+ break;
case '?':
default:
usage();
@@ -135,6 +144,15 @@ int scrol;
set(tm->tm_sec/10, 4);
set(tm->tm_min%10, 10);
set(tm->tm_min/10, 14);
+
+ if (t12) {
+ if (tm->tm_hour > 12) {
+ tm->tm_hour -= 12;
+ mvaddstr(YBASE + 5, XBASE + 52, "PM");
+ } else
+ mvaddstr(YBASE + 5, XBASE + 52, "AM");
+ }
+
set(tm->tm_hour%10, 20);
set(tm->tm_hour/10, 24);
set(10, 7);
@@ -229,6 +247,6 @@ void
usage(void)
{
- (void)fprintf(stderr, "usage: grdc [-s] [n]\n");
+ (void)fprintf(stderr, "usage: grdc [-st] [n]\n");
exit(1);
}
OpenPOWER on IntegriCloud