Changeset 4271


Ignore:
Timestamp:
Jan 15, 2010, 1:17:03 AM (8 years ago)
Author:
Sam Hocevar
Message:

Implement zzcat -s (squeeze empty lines).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/zzcat.c

    r4270 r4271  
    6868static int number_lines = 0;
    6969static int number_nonblank = 0;
     70static int squeeze_lines = 0;
    7071
    7172/*
     
    8081    for (;;)
    8182    {
    82 #define OPTSTR "+AbeEntTvx:lhV"
     83#define OPTSTR "+AbeEnstTvx:lhV"
    8384#define MOREINFO "Try `%s --help' for more information.\n"
    8485        int option_index = 0;
     
    8990            { "show-ends",        0, NULL, 'E' },
    9091            { "number",           0, NULL, 'n' },
     92            { "squeeze-blank",    0, NULL, 's' },
    9193            { "show-tabs",        0, NULL, 'T' },
    9294            { "show-nonprinting", 0, NULL, 'v' },
     
    118120        case 'n': /* --number */
    119121            number_lines = 1;
     122            break;
     123        case 's': /* --squeeze-blank */
     124            squeeze_lines = 1;
    120125            break;
    121126        case 't':
     
    175180
    176181    if (!(escape_tabs || escape_ends || escape_other
    177            || number_lines || number_nonblank))
     182           || number_lines || number_nonblank || squeeze_lines))
    178183    {
    179184        fwrite(buf, len, 1, stdout);
     
    184189    {
    185190        int ch = (unsigned int)(unsigned char)buf[i];
     191
     192        if (squeeze_lines && i > 1
     193             && ch == '\n' && buf[i - 1] == '\n' && buf[i - 2] == '\n')
     194            continue;
    186195
    187196        if (number_lines || number_nonblank)
Note: See TracChangeset for help on using the changeset viewer.