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
|
endif
|
||||||
|
|
||||||
|
GNUmakevars: GNUmakevars.sh
|
||||||
|
sh ./$^ > $@
|
||||||
|
GNUmakerules: GNUmakerules.sh
|
||||||
|
sh ./$^ > $@
|
||||||
|
|
||||||
|
|
||||||
include GNUmakerules
|
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:"
|
30
ts/ts.c
30
ts/ts.c
|
@ -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) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S",
|
if (use_seconds) {
|
||||||
localtime(&tv.tv_sec));
|
tv.tv_usec -= start.tv_usec;
|
||||||
fputs(s, fp);
|
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) {
|
if (use_microseconds) {
|
||||||
fprintf(fp, ".%06ld ", (long)tv.tv_usec);
|
fprintf(fp, ".%06ld ", (long)tv.tv_usec);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue