Add a debug mode to zzcat.

This commit is contained in:
Sam Hocevar
2010-01-21 01:17:21 +00:00
committed by sam
parent b9cc488ad5
commit 96d16fc2fe
2 changed files with 22 additions and 3 deletions
+4 -1
View File
@@ -2,7 +2,7 @@
.SH NAME
zzcat \- concatenate files using different instruction sequences
.SH SYNOPSIS
\fBzzcat\fR [\fB\-AbeEntTv\fR] [\fB\-r\fR \fIloops\fR]
\fBzzcat\fR [\fB\-AbdeEntTv\fR] [\fB\-r\fR \fIloops\fR]
[\fB\-x\fR \fIsequence\fR] [\fIFILE\fR]...
.br
\fBzzcat \-l\fR | \fB\-\-list\fR
@@ -26,6 +26,9 @@ Equivalent to \fB\-vET\fR.
\fB\-b\fR, \fB\-\-number\-nonblank\fR
Number nonempty output lines.
.TP
\fB\-d\fR, \fB\-\-debug\fR
Output debugging information.
.TP
\fB\-e\fR
Equivalent to \fB\-vET\fR.
.TP
+18 -2
View File
@@ -64,6 +64,7 @@ static void version(void);
static void usage(void);
/* Global parameters */
static int debug = 0;
static int repeat = 1;
static char escape_tabs = 0;
static char escape_ends = 0;
@@ -88,13 +89,14 @@ int main(int argc, char *argv[])
for (;;)
{
#define OPTSTR "+AbeEnr:stTvx:lhV"
#define OPTSTR "+AbdeEnr:stTvx:lhV"
#define MOREINFO "Try `%s --help' for more information.\n"
int option_index = 0;
static struct myoption long_options[] =
{
{ "show-all", 0, NULL, 'A' },
{ "number-nonblank", 0, NULL, 'b' },
{ "debug", 0, NULL, 'd' },
{ "show-ends", 0, NULL, 'E' },
{ "number", 0, NULL, 'n' },
{ "repeat", 1, NULL, 'r' },
@@ -120,6 +122,9 @@ int main(int argc, char *argv[])
case 'b': /* --number-nonblank */
number_nonblank = 1;
break;
case 'd': /* --debug */
debug = 1;
break;
case 'e':
escape_ends = escape_other = 1;
break;
@@ -277,10 +282,20 @@ static void output(char const *buf, size_t len)
{ \
retlen = retoff + _cnt; \
if (!retbuf || ROUNDUP(retlen) != ROUNDUP(retlen - _cnt)) \
{ \
if (debug) \
fprintf(stderr, "D: zzcat: allocating %i bytes for %i\n", \
(int)ROUNDUP(retlen), (int)retlen); \
retbuf = realloc(retbuf, ROUNDUP(retlen)); \
} \
} \
if (_cnt > 0) \
{ \
if (debug) \
fprintf(stderr, "D: zzcat: writing %i byte%s at offset %i\n", \
(int)_cnt, _cnt == 1 ? "" : "s", (int)retoff); \
memcpy(retbuf + retoff, address, _cnt); \
} \
retoff += _off; \
} while(0)
@@ -784,7 +799,7 @@ static void version(void)
static void usage(void)
{
printf("Usage: zzcat [AbeEntTv] [-x sequence] [FILE...]\n");
printf("Usage: zzcat [AbdeEntTv] [-x sequence] [FILE...]\n");
printf(" zzcat -l | --list\n");
printf(" zzcat -h | --help\n");
printf(" zzcat -V | --version\n");
@@ -793,6 +808,7 @@ static void usage(void)
printf("Mandatory arguments to long options are mandatory for short options too.\n");
printf(" -A, --show-all equivalent to -vET\n");
printf(" -b, --number-nonblank number nonempty output lines\n");
printf(" -d, --debug print debugging information\n");
printf(" -e equivalent to -vE\n");
printf(" -E, --show-ends display $ at end of each line\n");
printf(" -n, --number number all output lines\n");