Commit 0aea6955 authored by Adam Wujek's avatar Adam Wujek 💬

tools: add printing version of repo

with -V switch
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 07da0470
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# build user-space tools for zio # build user-space tools for zio
CFLAGS = -I$(M)/include/ -Wall $(ZIO_VERSION) $(EXTRACFLAGS) CFLAGS = -I$(M)/include/ -Wall $(ZIO_VERSION) $(EXTRACFLAGS)
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
CC ?= $(CROSS_COMPILE)gcc CC ?= $(CROSS_COMPILE)gcc
progs := zio-dump progs := zio-dump
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <linux/zio-user.h> #include <linux/zio-user.h>
static char git_version[] = "version: " GIT_VERSION;
#define FNAME "/dev/zdtc-0000-0-0-ctrl" #define FNAME "/dev/zdtc-0000-0-0-ctrl"
void help(char *name) void help(char *name)
...@@ -25,10 +27,17 @@ void help(char *name) ...@@ -25,10 +27,17 @@ void help(char *name)
" -f <file> default: %s\n" " -f <file> default: %s\n"
" -t <time> default: \"1.5\" (see code for details)\n" " -t <time> default: \"1.5\" (see code for details)\n"
" -p <period> default: \"0\"\n" " -p <period> default: \"0\"\n"
" -n <number> default: infinite\n", FNAME); " -n <number> default: infinite\n"
" -v increase verbosity\n"
" -V print version information \n", FNAME);
exit(1); exit(1);
} }
static void print_version(char *pname)
{
printf("%s %s\n", pname, git_version);
}
/* Boring parsing separated to a separate function (same code as elsewhere) */ /* Boring parsing separated to a separate function (same code as elsewhere) */
static int parse_ts(char *s, struct timespec *ts) static int parse_ts(char *s, struct timespec *ts)
{ {
...@@ -77,7 +86,7 @@ int main(int argc, char **argv) ...@@ -77,7 +86,7 @@ int main(int argc, char **argv)
struct timespec period = {0, 0}; struct timespec period = {0, 0};
/* -f <filename> -t <[+][secs].frac> -p <.frac> -v */ /* -f <filename> -t <[+][secs].frac> -p <.frac> -v */
while ((i = getopt (argc, argv, "f:t:p:n:v")) != -1) { while ((i = getopt (argc, argv, "f:t:p:n:vV")) != -1) {
switch(i) { switch(i) {
case 'f': case 'f':
fname = optarg; fname = optarg;
...@@ -94,6 +103,9 @@ int main(int argc, char **argv) ...@@ -94,6 +103,9 @@ int main(int argc, char **argv)
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 'V':
print_version(argv[0]);
exit(0);
default: default:
help(argv[0]); help(argv[0]);
} }
......
...@@ -17,8 +17,15 @@ ...@@ -17,8 +17,15 @@
#include <linux/zio-user.h> #include <linux/zio-user.h>
static char git_version[] = "version: " GIT_VERSION;
#define VERBOSE 0 #define VERBOSE 0
static void print_version(char *pname)
{
printf("%s %s\n", pname, git_version);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int cfd; /* control file descriptor */ int cfd; /* control file descriptor */
...@@ -33,10 +40,15 @@ int main(int argc, char **argv) ...@@ -33,10 +40,15 @@ int main(int argc, char **argv)
void *map,*ptr; void *map,*ptr;
struct timeval tv1, tv2; struct timeval tv1, tv2;
if ((argc == 2) && (!strcmp(argv[1], "-V"))) {
print_version(argv[0]);
exit(0);
}
if (argc != 3) { if (argc != 3) {
fprintf(stderr, "%s: Wrong number of arguments\n" fprintf(stderr, "%s: Wrong number of arguments\n"
"Use: \"%s <data-file> <nblocks>\"\n", "Use: \"%s <data-file> <nblocks>\"\n",
argv[0], argv[0]); argv[0], argv[0]);
fprintf(stderr, "Or -V for version details\n");
exit(1); exit(1);
} }
nblocks = atoi(argv[2]); nblocks = atoi(argv[2]);
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <linux/zio-user.h> #include <linux/zio-user.h>
static char git_version[] = "version: " GIT_VERSION;
unsigned char buf[1024*1024]; unsigned char buf[1024*1024];
char *prgname; char *prgname;
int opt_print_attr; int opt_print_attr;
...@@ -222,10 +224,16 @@ void help(char *name) ...@@ -222,10 +224,16 @@ void help(char *name)
" -s sniff-device (array of controls)\n" " -s sniff-device (array of controls)\n"
" -m print memory address (for mmap)\n" " -m print memory address (for mmap)\n"
" -n <number> stop after that many blocks\n" " -n <number> stop after that many blocks\n"
" -r <number> shown bytes at buffer begin/end\n"); " -r <number> shown bytes at buffer begin/end\n"
" -V print version information \n");
exit(1); exit(1);
} }
static void print_version(char *pname)
{
printf("%s %s\n", pname, git_version);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
FILE *f; FILE *f;
...@@ -240,7 +248,7 @@ int main(int argc, char **argv) ...@@ -240,7 +248,7 @@ int main(int argc, char **argv)
prgname = argv[0]; prgname = argv[0];
while ((c = getopt (argc, argv, "aAcsmn:r:")) != -1) { while ((c = getopt (argc, argv, "aAcsmn:r:V")) != -1) {
switch(c) { switch(c) {
case 'a': case 'a':
opt_print_attr = 1; opt_print_attr = 1;
...@@ -274,6 +282,9 @@ int main(int argc, char **argv) ...@@ -274,6 +282,9 @@ int main(int argc, char **argv)
help(prgname); help(prgname);
} }
break; break;
case 'V':
print_version(argv[0]);
exit(0);
default: default:
help(prgname); help(prgname);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment