From e315472e6344f5339853da81219b027e559c9301 Mon Sep 17 00:00:00 2001 From: hjp Date: Mon, 2 Feb 2009 11:39:33 +0000 Subject: [PATCH] added rules to build GNUmakerules and GNUmakevars if they are missing added new options: -s (seconds since the epoch) -r (relative to start of program) --- ts/GNUmakefile | 6 ++++++ ts/GNUmakerules.sh | 3 +++ ts/GNUmakevars.sh | 5 +++++ ts/ts.c | 30 +++++++++++++++++++++++++----- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100755 ts/GNUmakerules.sh create mode 100755 ts/GNUmakevars.sh diff --git a/ts/GNUmakefile b/ts/GNUmakefile index e52530b..7ad169b 100644 --- a/ts/GNUmakefile +++ b/ts/GNUmakefile @@ -31,4 +31,10 @@ configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish endif +GNUmakevars: GNUmakevars.sh + sh ./$^ > $@ +GNUmakerules: GNUmakerules.sh + sh ./$^ > $@ + + include GNUmakerules diff --git a/ts/GNUmakerules.sh b/ts/GNUmakerules.sh new file mode 100755 index 0000000..e523b37 --- /dev/null +++ b/ts/GNUmakerules.sh @@ -0,0 +1,3 @@ +#!/bin/sh +echo "\$(BINDIR)/%: %" +echo -e "\tcp \$^ \$@" diff --git a/ts/GNUmakevars.sh b/ts/GNUmakevars.sh new file mode 100755 index 0000000..a7de4ae --- /dev/null +++ b/ts/GNUmakevars.sh @@ -0,0 +1,5 @@ +#!/bin/sh +prefix=${prefix:-/usr/local} +echo "BINDIR=$prefix/bin" +echo +echo "all:" diff --git a/ts/ts.c b/ts/ts.c index 1e22576..48d3f8d 100644 --- a/ts/ts.c +++ b/ts/ts.c @@ -9,7 +9,7 @@ static char *cmnd; static void usage(void) { - fprintf(stderr, "Usage: %s [-u] [-o file]\n", cmnd); + fprintf(stderr, "Usage: %s [-u] [-s] [-r] [-o file]\n", cmnd); exit(1); } @@ -17,14 +17,16 @@ static void usage(void) { int main(int argc, char **argv) { int c; int use_microseconds = 0; + int use_seconds = 0; int print_ts = 1; char lastfile[FILENAME_MAX] = "", file[FILENAME_MAX] = ""; char *filepat = NULL; FILE *fp = NULL; + struct timeval start = { 0, 0 }; cmnd = argv[0]; - while ((c = getopt(argc, argv, "uo:")) != EOF) { + while ((c = getopt(argc, argv, "suro:")) != EOF) { switch (c) { case 'u': use_microseconds = 1; @@ -32,6 +34,14 @@ int main(int argc, char **argv) { case 'o': filepat = optarg; break; + case 's': + use_seconds = 1; + break; + case 'r': + gettimeofday(&start, NULL); + use_seconds = 1; + use_microseconds = 1; + break; default: usage(); } @@ -64,9 +74,19 @@ int main(int argc, char **argv) { } } - strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S", - localtime(&tv.tv_sec)); - fputs(s, fp); + if (use_seconds) { + tv.tv_usec -= start.tv_usec; + if (tv.tv_usec < 0) { + tv.tv_usec += 1000000; + tv.tv_sec -= 1; + } + tv.tv_sec -= start.tv_sec; + fprintf(fp, "%ld", (long)tv.tv_sec); + } else { + strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S", + localtime(&tv.tv_sec)); + fputs(s, fp); + } if (use_microseconds) { fprintf(fp, ".%06ld ", (long)tv.tv_usec); }