diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/binlogcat.c | 20 | ||||
-rw-r--r-- | src/binlogsel.c | 33 | ||||
-rw-r--r-- | src/err.c | 9 | ||||
-rw-r--r-- | src/err.h | 1 |
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 @@ -131,48 +131,64 @@ catlog(const char *fname) } free(rec); packenv_free(env); packfree(inst); fclose(fp); } void help() { - printf("usage: %s [-dhnv] [-t FORMAT] [FILE...]\n", progname); + printf("usage: %s [-dhnVv] [-t FORMAT] [FILE...]\n", progname); + printf("Format binary log files in human-readable form\n"); + printf("\nOptions are:\n\n"); + printf(" -d print timestamps relative to first record in the file\n"); + printf(" -n output record numbers\n"); + printf(" -v print information about each file\n"); + printf(" -t FORMAT format timestamps according to FORMAT\n"); + printf("\n"); + printf(" -h print this help summary\n"); + printf(" -V show program version\n"); + printf("\n"); + printf("Report bugs and suggestions to <%s>\n", PACKAGE_BUGREPORT); + if (sizeof(PACKAGE_URL) > 1) + printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL); } int main(int argc, char **argv) { int c; setprogname(argv[0]); - while ((c = getopt(argc, argv, "dht:nv")) != EOF) + while ((c = getopt(argc, argv, "dht:nVv")) != EOF) switch (c) { case 'd': timediff_option = 1; timefmt = "%s"; break; case 'h': help(); return 0; case 't': timefmt = optarg; break; case 'n': number_option = 1; break; + case 'V': + version(); + exit(0); case 'v': verbose_option = 1; break; default: exit(1); } argc -= optind; argv += optind; if (argc == 0) catlog("-"); diff --git a/src/binlogsel.c b/src/binlogsel.c index 8f1cfce..b05b12c 100644 --- a/src/binlogsel.c +++ b/src/binlogsel.c @@ -44,25 +44,43 @@ enum binlog_index_type index_type = index_year; #define FROM_TIME 0x01 #define TO_TIME 0x02 int timemask; time_t from_time, to_time; static int matchnames(const char *dir, const char *pat, glob_t *gl); void selglob(const char *dir, const char *pattern); void help() { - printf("usage: %s [-dhnv] [-t FORMAT] [-F FROMTIME] [-T TOTIME] [-p PATTERN] [-D DIR] [FILE...]\n", progname); + printf("usage: %s [-dhnVv] [-t FORMAT] [-F TIME] [-T TIME] [-p PATTERN] [-D DIR] [FILE...]\n", progname); + printf("Select records from binary logs\n"); + printf("\nOptions are:\n\n"); + printf(" -D DIR log file storage directory\n"); + printf(" -F TIME print records starting from TIME\n"); + printf(" -T TIME print records starting up to TIME\n"); + printf(" -p PATTERN select files matching PATTERN\n"); + printf("\n"); + printf(" -d print timestamps relative to first record in the file\n"); + printf(" -n output record numbers\n"); + printf(" -v print information about each file\n"); + printf(" -t FMT format timestamps according to FMT\n"); + printf("\n"); + printf(" -h print this help summary\n"); + printf(" -V show program version\n"); + printf("\n"); + printf("Report bugs and suggestions to <%s>\n", PACKAGE_BUGREPORT); + if (sizeof(PACKAGE_URL) > 1) + printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL); } /* Convert strftime-like pattern into globbing pattern */ char * convpattern(const char *dir) { char *p, *q; char *newpat; size_t size = strlen(pattern) + 1; if (dir) size += strlen(dir) + 1; @@ -398,25 +416,25 @@ selidx_day(const char *dir) if (!glinit) { glinit = matchnames(dir, "[0-9][0-9]", &gl); if (!glinit) { error("no matching files"); exit(1); } } to_day = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]); } dirlen = strlen(dir) + 4; dirbuf = xmalloc(dirlen); - for (;from_day <= to_day; from_day++) { + for (; from_day <= to_day; from_day++) { snprintf(dirbuf, dirlen, "%s/%02d", dir, from_day); selglob(dirbuf, BINLOG_GLOB_PATTERN); } free(dirbuf); if (glinit) globfree(&gl); } void selidx_month(const char *dir) { int from_month, to_month; @@ -449,25 +467,25 @@ selidx_month(const char *dir) if (!glinit) { glinit = matchnames(dir, "[0-9][0-9]", &gl); if (!glinit) { error("no matching files"); exit(1); } } to_month = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]); } dirlen = strlen(dir) + 4; dirbuf = xmalloc(dirlen); - for (;from_month <= to_month; from_month++) { + for (; from_month <= to_month; from_month++) { snprintf(dirbuf, dirlen, "%s/%02d", dir, from_month); selidx_day(dirbuf); } free(dirbuf); if (glinit) globfree(&gl); } void selidx_year(const char *dir) { int from_year, to_year; @@ -495,35 +513,35 @@ selidx_year(const char *dir) if (!glinit) { glinit = matchnames(dir, "[0-9][0-9][0-9][0-9]", &gl); if (!glinit) { error("no matching files"); exit(1); } } to_year = filename_to_int(gl.gl_pathv[gl.gl_pathc - 1]); } dirlen = strlen(dir) + 6; dirbuf = xmalloc(dirlen); - for (;from_year <= to_year; from_year++) { + for (; from_year <= to_year; from_year++) { snprintf(dirbuf, dirlen, "%s/%04d", dir, from_year); selidx_month(dirbuf); } free(dirbuf); if (glinit) globfree(&gl); } int -globerrfunc (const char *epath, int eerrno) +globerrfunc(const char *epath, int eerrno) { error("%s: %s", epath, strerror(eerrno)); return 0; } static int matchnames(const char *dir, const char *pat, glob_t *gl) { char *p = mkfilename(dir, pat); int rc = glob(p, GLOB_ERR, globerrfunc, gl); free(p); switch (rc) { @@ -605,25 +623,25 @@ selglob(const char *dir, const char *pattern) free(logfiles); globfree(&gl); } int main(int argc, char **argv) { int c; struct timespec ts; setprogname(argv[0]); - while ((c = getopt(argc, argv, "D:dF:hi:p:T:t:nv")) != EOF) + while ((c = getopt(argc, argv, "D:dF:hi:p:T:t:nV")) != EOF) switch (c) { case 'D': directory = optarg; break; case 'd': timediff_option = 1; timefmt = "%s"; break; case 'F': if (!parse_datetime(&ts, optarg, NULL)) { error("invalid timespec: %s", optarg); exit(1); @@ -649,24 +667,27 @@ main(int argc, char **argv) error("invalid timespec: %s", optarg); exit(1); } to_time = ts.tv_sec; timemask |= TO_TIME; break; case 't': timefmt = optarg; break; case 'n': number_option = 1; break; + case 'V': + version(); + exit(0); case 'v': verbose_option = 1; break; default: exit(1); } argc -= optind; argv += optind; if (argc) { if (pattern || directory) { @@ -51,12 +51,21 @@ error(const char *fmt, ...) } void packerror(const char *fmt, ...) { va_list ap; va_start(ap, fmt); verror(fmt, ap); va_end(ap); } +void +version(void) +{ + printf("%s (%s) %s\n", progname, PACKAGE_TARNAME, PACKAGE_VERSION); + printf("Copyright (C) 2013 Sergey Poznyakoff\n"); + printf("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"); + printf("This is free software: you are free to change and redistribute it.\n"); + printf("There is NO WARRANTY, to the extent permitted by law.\n"); +} @@ -10,12 +10,13 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. */ extern const char *progname; void setprogname(const char *); void error(const char *fmt, ...); void packerror(const char *fmt, ...); +void version(void); |