Changeset 4289


Ignore:
Timestamp:
01/21/10 02:17:21 (3 years ago)
Author:
sam
Message:

Add a debug mode to zzcat.

Location:
zzuf/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/doc/zzcat.1.in

    r4278 r4289  
    33zzcat \- concatenate files using different instruction sequences 
    44.SH SYNOPSIS 
    5 \fBzzcat\fR [\fB\-AbeEntTv\fR] [\fB\-r\fR \fIloops\fR] 
     5\fBzzcat\fR [\fB\-AbdeEntTv\fR] [\fB\-r\fR \fIloops\fR] 
    66[\fB\-x\fR \fIsequence\fR] [\fIFILE\fR]... 
    77.br 
     
    2626\fB\-b\fR, \fB\-\-number\-nonblank\fR 
    2727Number nonempty output lines. 
     28.TP 
     29\fB\-d\fR, \fB\-\-debug\fR 
     30Output debugging information. 
    2831.TP 
    2932\fB\-e\fR 
  • zzuf/trunk/src/zzcat.c

    r4288 r4289  
    6565 
    6666/* Global parameters */ 
     67static int debug = 0; 
    6768static int repeat = 1; 
    6869static char escape_tabs = 0; 
     
    8990    for (;;) 
    9091    { 
    91 #define OPTSTR "+AbeEnr:stTvx:lhV" 
     92#define OPTSTR "+AbdeEnr:stTvx:lhV" 
    9293#define MOREINFO "Try `%s --help' for more information.\n" 
    9394        int option_index = 0; 
     
    9697            { "show-all",         0, NULL, 'A' }, 
    9798            { "number-nonblank",  0, NULL, 'b' }, 
     99            { "debug",            0, NULL, 'd' }, 
    98100            { "show-ends",        0, NULL, 'E' }, 
    99101            { "number",           0, NULL, 'n' }, 
     
    120122        case 'b': /* --number-nonblank */ 
    121123            number_nonblank = 1; 
     124            break; 
     125        case 'd': /* --debug */ 
     126            debug = 1; 
    122127            break; 
    123128        case 'e': 
     
    278283            retlen = retoff + _cnt; \ 
    279284            if (!retbuf || ROUNDUP(retlen) != ROUNDUP(retlen - _cnt)) \ 
     285            { \ 
     286                if (debug) \ 
     287                    fprintf(stderr, "D: zzcat: allocating %i bytes for %i\n", \ 
     288                            (int)ROUNDUP(retlen), (int)retlen); \ 
    280289                retbuf = realloc(retbuf, ROUNDUP(retlen)); \ 
     290            } \ 
    281291        } \ 
    282292        if (_cnt > 0) \ 
     293        { \ 
     294            if (debug) \ 
     295                fprintf(stderr, "D: zzcat: writing %i byte%s at offset %i\n", \ 
     296                        (int)_cnt, _cnt == 1 ? "" : "s", (int)retoff); \ 
    283297            memcpy(retbuf + retoff, address, _cnt); \ 
     298        } \ 
    284299        retoff += _off; \ 
    285300    } while(0) 
     
    785800static void usage(void) 
    786801{ 
    787     printf("Usage: zzcat [AbeEntTv] [-x sequence] [FILE...]\n"); 
     802    printf("Usage: zzcat [AbdeEntTv] [-x sequence] [FILE...]\n"); 
    788803    printf("       zzcat -l | --list\n"); 
    789804    printf("       zzcat -h | --help\n"); 
     
    794809    printf("  -A, --show-all            equivalent to -vET\n"); 
    795810    printf("  -b, --number-nonblank     number nonempty output lines\n"); 
     811    printf("  -d, --debug               print debugging information\n"); 
    796812    printf("  -e                        equivalent to -vE\n"); 
    797813    printf("  -E, --show-ends           display $ at end of each line\n"); 
Note: See TracChangeset for help on using the changeset viewer.