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)
This commit is contained in:
hjp 2009-02-02 11:39:33 +00:00
parent 64d708aeeb
commit e315472e63
4 changed files with 39 additions and 5 deletions

View File

@ -31,4 +31,10 @@ configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish
endif endif
GNUmakevars: GNUmakevars.sh
sh ./$^ > $@
GNUmakerules: GNUmakerules.sh
sh ./$^ > $@
include GNUmakerules include GNUmakerules

3
ts/GNUmakerules.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "\$(BINDIR)/%: %"
echo -e "\tcp \$^ \$@"

5
ts/GNUmakevars.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
prefix=${prefix:-/usr/local}
echo "BINDIR=$prefix/bin"
echo
echo "all:"

24
ts/ts.c
View File

@ -9,7 +9,7 @@
static char *cmnd; static char *cmnd;
static void usage(void) { 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); exit(1);
} }
@ -17,14 +17,16 @@ static void usage(void) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int c; int c;
int use_microseconds = 0; int use_microseconds = 0;
int use_seconds = 0;
int print_ts = 1; int print_ts = 1;
char lastfile[FILENAME_MAX] = "", file[FILENAME_MAX] = ""; char lastfile[FILENAME_MAX] = "", file[FILENAME_MAX] = "";
char *filepat = NULL; char *filepat = NULL;
FILE *fp = NULL; FILE *fp = NULL;
struct timeval start = { 0, 0 };
cmnd = argv[0]; cmnd = argv[0];
while ((c = getopt(argc, argv, "uo:")) != EOF) { while ((c = getopt(argc, argv, "suro:")) != EOF) {
switch (c) { switch (c) {
case 'u': case 'u':
use_microseconds = 1; use_microseconds = 1;
@ -32,6 +34,14 @@ int main(int argc, char **argv) {
case 'o': case 'o':
filepat = optarg; filepat = optarg;
break; break;
case 's':
use_seconds = 1;
break;
case 'r':
gettimeofday(&start, NULL);
use_seconds = 1;
use_microseconds = 1;
break;
default: default:
usage(); usage();
} }
@ -64,9 +74,19 @@ int main(int argc, char **argv) {
} }
} }
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", strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S",
localtime(&tv.tv_sec)); localtime(&tv.tv_sec));
fputs(s, fp); fputs(s, fp);
}
if (use_microseconds) { if (use_microseconds) {
fprintf(fp, ".%06ld ", (long)tv.tv_usec); fprintf(fp, ".%06ld ", (long)tv.tv_usec);
} }