aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-15 20:07:26 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-15 20:07:26 +0300
commit7d0beb6599c53544739409ca4aec104bf27a3f35 (patch)
treeb561fbba7c9acedec17cbc398cee12a465faad6e /src
parentef3f928cc712f6774e19f8cb8f880cbeac15e8ff (diff)
downloadvmod-binlog-7d0beb6599c53544739409ca4aec104bf27a3f35.tar.gz
vmod-binlog-7d0beb6599c53544739409ca4aec104bf27a3f35.tar.bz2
Add version and help output to command line utilities.
Diffstat (limited to 'src')
-rw-r--r--src/binlogcat.c20
-rw-r--r--src/binlogsel.c33
-rw-r--r--src/err.c9
-rw-r--r--src/err.h1
4 files changed, 55 insertions, 8 deletions
diff --git a/src/binlogcat.c b/src/binlogcat.c
index 656d8f2..ada8efe 100644
--- a/src/binlogcat.c
+++ b/src/binlogcat.c
@@ -137,22 +137,35 @@ catlog(const char *fname)
137 fclose(fp); 137 fclose(fp);
138} 138}
139 139
140void 140void
141help() 141help()
142{ 142{
143 printf("usage: %s [-dhnv] [-t FORMAT] [FILE...]\n", progname); 143 printf("usage: %s [-dhnVv] [-t FORMAT] [FILE...]\n", progname);
144 printf("Format binary log files in human-readable form\n");
145 printf("\nOptions are:\n\n");
146 printf(" -d print timestamps relative to first record in the file\n");
147 printf(" -n output record numbers\n");
148 printf(" -v print information about each file\n");
149 printf(" -t FORMAT format timestamps according to FORMAT\n");
150 printf("\n");
151 printf(" -h print this help summary\n");
152 printf(" -V show program version\n");
153 printf("\n");
154 printf("Report bugs and suggestions to <%s>\n", PACKAGE_BUGREPORT);
155 if (sizeof(PACKAGE_URL) > 1)
156 printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
144} 157}
145 158
146int 159int
147main(int argc, char **argv) 160main(int argc, char **argv)
148{ 161{
149 int c; 162 int c;
150 163
151 setprogname(argv[0]); 164 setprogname(argv[0]);
152 while ((c = getopt(argc, argv, "dht:nv")) != EOF) 165 while ((c = getopt(argc, argv, "dht:nVv")) != EOF)
153 switch (c) { 166 switch (c) {
154 case 'd': 167 case 'd':
155 timediff_option = 1; 168 timediff_option = 1;
156 timefmt = "%s"; 169 timefmt = "%s";
157 break; 170 break;
158 case 'h': 171 case 'h':
@@ -161,12 +174,15 @@ main(int argc, char **argv)
161 case 't': 174 case 't':
162 timefmt = optarg; 175 timefmt = optarg;
163 break; 176 break;
164 case 'n': 177 case 'n':
165 number_option = 1; 178 number_option = 1;
166 break; 179 break;
180 case 'V':
181 version();
182 exit(0);
167 case 'v': 183 case 'v':
168 verbose_option = 1; 184 verbose_option = 1;
169 break; 185 break;
170 default: 186 default:
171 exit(1); 187 exit(1);
172 } 188 }
diff --git a/src/binlogsel.c b/src/binlogsel.c
index 8f1cfce..b05b12c 100644
--- a/src/binlogsel.c
+++ b/src/binlogsel.c
@@ -50,13 +50,31 @@ time_t from_time, to_time;
50static int matchnames(const char *dir, const char *pat, glob_t *gl); 50static int matchnames(const char *dir, const char *pat, glob_t *gl);
51void selglob(const char *dir, const char *pattern); 51void selglob(const char *dir, const char *pattern);
52 52
53void 53void
54help() 54help()
55{ 55{
56 printf("usage: %s [-dhnv] [-t FORMAT] [-F FROMTIME] [-T TOTIME] [-p PATTERN] [-D DIR] [FILE...]\n", progname); 56 printf("usage: %s [-dhnVv] [-t FORMAT] [-F TIME] [-T TIME] [-p PATTERN] [-D DIR] [FILE...]\n", progname);
57 printf("Select records from binary logs\n");
58 printf("\nOptions are:\n\n");
59 printf(" -D DIR log file storage directory\n");
60 printf(" -F TIME print records starting from TIME\n");
61 printf(" -T TIME print records starting up to TIME\n");
62 printf(" -p PATTERN select files matching PATTERN\n");
63 printf("\n");
64 printf(" -d print timestamps relative to first record in the file\n");
65 printf(" -n output record numbers\n");
66 printf(" -v print information about each file\n");
67 printf(" -t FMT format timestamps according to FMT\n");
68 printf("\n");
69 printf(" -h print this help summary\n");
70 printf(" -V show program version\n");
71 printf("\n");
72 printf("Report bugs and suggestions to <%s>\n", PACKAGE_BUGREPORT);
73 if (sizeof(PACKAGE_URL) > 1)
74 printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
57} 75}
58 76
59/* Convert strftime-like pattern into globbing pattern */ 77/* Convert strftime-like pattern into globbing pattern */
60char * 78char *
61convpattern(const char *dir) 79convpattern(const char *dir)
62{ 80{
@@ -404,13 +422,13 @@ selidx_day(const char *dir)
404 } 422 }
405 to_day = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]); 423 to_day = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]);
406 } 424 }
407 425
408 dirlen = strlen(dir) + 4; 426 dirlen = strlen(dir) + 4;
409 dirbuf = xmalloc(dirlen); 427 dirbuf = xmalloc(dirlen);
410 for (;from_day <= to_day; from_day++) { 428 for (; from_day <= to_day; from_day++) {
411 snprintf(dirbuf, dirlen, "%s/%02d", dir, from_day); 429 snprintf(dirbuf, dirlen, "%s/%02d", dir, from_day);
412 selglob(dirbuf, BINLOG_GLOB_PATTERN); 430 selglob(dirbuf, BINLOG_GLOB_PATTERN);
413 } 431 }
414 free(dirbuf); 432 free(dirbuf);
415 if (glinit) 433 if (glinit)
416 globfree(&gl); 434 globfree(&gl);
@@ -455,13 +473,13 @@ selidx_month(const char *dir)
455 } 473 }
456 to_month = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]); 474 to_month = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]);
457 } 475 }
458 476
459 dirlen = strlen(dir) + 4; 477 dirlen = strlen(dir) + 4;
460 dirbuf = xmalloc(dirlen); 478 dirbuf = xmalloc(dirlen);
461 for (;from_month <= to_month; from_month++) { 479 for (; from_month <= to_month; from_month++) {
462 snprintf(dirbuf, dirlen, "%s/%02d", dir, from_month); 480 snprintf(dirbuf, dirlen, "%s/%02d", dir, from_month);
463 selidx_day(dirbuf); 481 selidx_day(dirbuf);
464 } 482 }
465 free(dirbuf); 483 free(dirbuf);
466 if (glinit) 484 if (glinit)
467 globfree(&gl); 485 globfree(&gl);
@@ -501,23 +519,23 @@ selidx_year(const char *dir)
501 } 519 }
502 to_year = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]); 520 to_year = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]);
503 } 521 }
504 522
505 dirlen = strlen(dir) + 6; 523 dirlen = strlen(dir) + 6;
506 dirbuf = xmalloc(dirlen); 524 dirbuf = xmalloc(dirlen);
507 for (;from_year <= to_year; from_year++) { 525 for (; from_year <= to_year; from_year++) {
508 snprintf(dirbuf, dirlen, "%s/%04d", dir, from_year); 526 snprintf(dirbuf, dirlen, "%s/%04d", dir, from_year);
509 selidx_month(dirbuf); 527 selidx_month(dirbuf);
510 } 528 }
511 free(dirbuf); 529 free(dirbuf);
512 if (glinit) 530 if (glinit)
513 globfree(&gl); 531 globfree(&gl);
514} 532}
515 533
516int 534int
517globerrfunc (const char *epath, int eerrno) 535globerrfunc(const char *epath, int eerrno)
518{ 536{
519 error("%s: %s", epath, strerror(eerrno)); 537 error("%s: %s", epath, strerror(eerrno));
520 return 0; 538 return 0;
521} 539}
522 540
523static int 541static int
@@ -611,13 +629,13 @@ int
611main(int argc, char **argv) 629main(int argc, char **argv)
612{ 630{
613 int c; 631 int c;
614 struct timespec ts; 632 struct timespec ts;
615 633
616 setprogname(argv[0]); 634 setprogname(argv[0]);
617 while ((c = getopt(argc, argv, "D:dF:hi:p:T:t:nv")) != EOF) 635 while ((c = getopt(argc, argv, "D:dF:hi:p:T:t:nV")) != EOF)
618 switch (c) { 636 switch (c) {
619 case 'D': 637 case 'D':
620 directory = optarg; 638 directory = optarg;
621 break; 639 break;
622 case 'd': 640 case 'd':
623 timediff_option = 1; 641 timediff_option = 1;
@@ -655,12 +673,15 @@ main(int argc, char **argv)
655 case 't': 673 case 't':
656 timefmt = optarg; 674 timefmt = optarg;
657 break; 675 break;
658 case 'n': 676 case 'n':
659 number_option = 1; 677 number_option = 1;
660 break; 678 break;
679 case 'V':
680 version();
681 exit(0);
661 case 'v': 682 case 'v':
662 verbose_option = 1; 683 verbose_option = 1;
663 break; 684 break;
664 default: