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:
parent
64d708aeeb
commit
e315472e63
|
@ -31,4 +31,10 @@ configure: $(CONFDIR)/start $(CONFDIR)/perl $(CONFDIR)/finish
|
|||
|
||||
endif
|
||||
|
||||
GNUmakevars: GNUmakevars.sh
|
||||
sh ./$^ > $@
|
||||
GNUmakerules: GNUmakerules.sh
|
||||
sh ./$^ > $@
|
||||
|
||||
|
||||
include GNUmakerules
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
echo "\$(BINDIR)/%: %"
|
||||
echo -e "\tcp \$^ \$@"
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
prefix=${prefix:-/usr/local}
|
||||
echo "BINDIR=$prefix/bin"
|
||||
echo
|
||||
echo "all:"
|
24
ts/ts.c
24
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) {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue