[gnu.utils.bug] GNU-indent bugs

siebers%cadillac.cad.mcc.com@MCC.COM (Greg Siebers) (07/14/89)

I intended to send this only to Jim Kingdon, but I cannot reach him at
either kingdon@ai.mit.edu or kingdon@prep.ai.mit.edu.  Sorry for its length.


I have done some simple comparisons between the new GNU-indent and Sun's version
of indent from SunOS 4.0.1, and I noticed a few places where Sun's version did a
better job.  For example, for the Sun version I used the following ~/.indent.pro:

    -bap -bacc -bad -bbb -bc -br -nbs -cdb -ce -cli0.5 -d0 -di16
    -eei -nfc1 -i4 -nip -l100 -lp -npcs -npsl -sc -nsob -v

and the only changes for GNU-indent were:  -cli4  instead of  -cli0.5
                                           -ip0   instead of  -nip

*********************************************************************************

The sample input file was the following:
=======================================

static int Write(ch)
char ch;
{
    extern int write ();

    ch &= '\177';
    if (write(1, &ch, 1) != 1)
        fprintf (stderr, "Unbuffered write failed");
}

/*--------------------------------------------------------------------*/

void CharOut (c)
int c;
{
    int m, n;

    switch ((char) c) {
        case ('\t'):
            m = 1;
            do {
                m += TAB_WIDTH;
            } while (m <= next_column);
            if (m > screen_width) {
                SoftNewLine();
            } else {
                for (n = m - next_column; n > 0; n--)
                    CharOut((int) ' ');
                    }
            break;
    }
}

*********************************************************************************

The output from Sun's version of indent was:
===========================================

static int      Write(ch)
char            ch;
{
    extern int      write();

    ch &= '\177';
    if (write(1, &ch, 1) != 1)
        fprintf(stderr, "Unbuffered write failed");
}

/*--------------------------------------------------------------------*/

void            CharOut(c)
int             c;
{
    int             m,
                    n;

    switch ((char) c) {
      case ('\t'):
        m = 1;
        do {
            m += TAB_WIDTH;
        } while (m <= next_column);
        if (m > screen_width) {
            SoftNewLine();
        } else {
            for (n = m - next_column; n > 0; n--)
                CharOut((int) ' ');
        }
        break;
    }
}

*********************************************************************************

and the output from GNU-indent was:
==================================

static int      Write(ch)
char ch;
{
    extern int      write();

    ch            &='\177';

    if (write(1, &ch, 1) !=1)
        fprintf(stderr, "Unbuffered write failed");
}

/*--------------------------------------------------------------------*/

void            CharOut(c)
int             c;
{
    int             m,
                    n;

    switch ((char) c) {
        case ('\t'):
            m = 1;
            do {
                m += TAB_WIDTH;
            } while         (m <= next_column);

            if (m > screen_width) {
                SoftNewLine();
            } else {
                for (n = m - next_column; n > 0; n--)
                    CharOut((int) ' ');
            }
            break;
    }
}

*********************************************************************************

Using "grep -n ch" to locate some critical lines:
================================================

test.SUN:3:char            ch;
test.SUN:7:    ch &= '\177';
test.SUN:8:    if (write(1, &ch, 1) != 1)

test.GNU:3:char ch;                             NOTE:  no indentation
test.GNU:7:    ch            &='\177';          NOTE:  extra indent; no space after =
test.GNU:9:    if (write(1, &ch, 1) !=1)        NOTE:  extra line 8; no space after =

*********************************************************************************

and using "grep while" yields:
=============================

test.SUN:	} while (m <= next_column);

test.GNU:	    } while         (m <= next_column);       NOTE:  extra indentation

*********************************************************************************

I also tried compiling GNU-indent on an Apollo running SR10.1, and I obtained
the following warning and error messages, most of which could be fixed by
running lint and taking note of comments regarding enumeration type clashes:
===========================================================================

parousia(0.73)> make
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c indent.c
******** Line 266 of "indent.c": [Warning #159]  Variable "last_token_ends_sp" was not
         initialized before this use.
******** Line 1277 of "indent.c": [Warning #202]  Value assigned to flushed_nl is never
         used; assignment eliminated by optimizer.
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c io.c
******** Line 244 of "io.c": [Warning #202]  Value assigned to cur_col is never used;
         assignment eliminated by optimizer.
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c lexi.c

 (0086)     {0, 0}

******** Line 86 of "lexi.c": [Error #079]  Illegal type of constant "0" for variable
         "rwcode".
*** Exit 1

Stop.

parousia(0.74)> diff -c0 -t lexi.c.bak lexi.c
*** lexi.c.bak	Tue Jul  4 21:46:41 1989
--- lexi.c	Wed Jul 12 13:03:36 1989
***************
*** 86 ****
!     {0, 0}
--- 86 ----
!     {0, rw_break}                  NOTE:  just a quick fix to allow it to compile

parousia(0.77)> make
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c lexi.c
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c parse.c
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c pr_comment.c
******** Line 330 of "pr_comment.c": [Warning #202]  Value assigned to now_col is never
         used; assignment eliminated by optimizer.
******** Line 312 of "pr_comment.c": [Warning #202]  Value assigned to now_col is never
         used; assignment eliminated by optimizer.
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c args.c

 (0150)     {"T", PRO_KEY, 0, 0, 0, &exp_T},

******** Line 150 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0159)     {"bli", PRO_INT, 0, 0, &brace_indent, &exp_bli},

******** Line 159 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0164)     {"cd", PRO_INT, 0, 0, &decl_com_ind, &exp_cd},

******** Line 164 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0166)     {"ci", PRO_INT, 0, 0, &continuation_indent, &exp_ci},

******** Line 166 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0167)     {"cli", PRO_INT, 0, 0, &case_indent, &exp_cli},

******** Line 167 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0168)     {"cp", PRO_INT, 33, 0, &else_endif_col, &exp_cp},

******** Line 168 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0169)     {"c", PRO_INT, 33, 0, &com_ind, &exp_c},

******** Line 169 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0170)     {"di", PRO_INT, 16, 0, &decl_indent, &exp_di},

******** Line 170 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0172)     {"d", PRO_INT, 0, 0, &unindent_displace, &exp_d},

******** Line 172 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0175)     {"fbc", PRO_FONT, 0, 0, (int *) &blkcomf, &exp_fbc},

******** Line 175 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0176)     {"fbx", PRO_FONT, 0, 0, (int *) &boxcomf, &exp_fbx},

******** Line 176 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".

 (0177)     {"fb", PRO_FONT, 0, 0, (int *) &bodyf, &exp_fb},

******** Line 177 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0180)     {"fc", PRO_FONT, 0, 0, (int *) &scomf, &exp_fc},

******** Line 180 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0181)     {"fk", PRO_FONT, 0, 0, (int *) &keywordf, &exp_fk},

******** Line 181 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0182)     {"fs", PRO_FONT, 0, 0, (int *) &stringf, &exp_fs},

******** Line 182 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0183)     {"gnu", PRO_SETTINGS, 0, 0,

******** Line 183 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0188)     {"i", PRO_INT, 4, 0, &ind_size, &exp_i},

******** Line 188 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0189)     {"kr", PRO_SETTINGS, 0, 0,

******** Line 189 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0193)     {"lc", PRO_INT, 0, 0, &block_comment_max_col, &exp_lc},

******** Line 193 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0195)     {"l", PRO_INT, 78, 0, &max_col, &exp_l},

******** Line 195 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0214)     {"npro", PRO_IGN, 0, 0, 0, &exp_pro},

******** Line 214 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0227)     {"st", PRO_STDIN, 0, 0, 0, &exp_st},

******** Line 227 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0229)     {"version", PRO_PRSTRING, 0, 0, (int *)"GNU indent 1.0.  Based on Berkeley indent 5.11 (9/15/88).", &exp_version},

******** Line 229 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
 (0233)     {0, 0, 0, 0, 0, 0}

******** Line 233 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_type".
******** Line 233 of "args.c": [Error #079]  Illegal type of constant "0" for variable
         "p_special".
*** Exit 1

Stop.

parousia(0.78)> diff -c0 -t args.c.bak args.c
*** args.c.bak	Tue Jul 11 23:24:25 1989
--- args.c	Wed Jul 12 13:34:42 1989
***************                             NOTE:  more quick fixes for compilation,
*** 150 ****                                         and not necessarily correct
!     {"T", PRO_KEY, 0, 0, 0, &exp_T},
--- 150 ----
!     {"T", PRO_KEY, 0, OFF, 0, &exp_T},
***************
*** 159 ****
!     {"bli", PRO_INT, 0, 0, &brace_indent, &exp_bli},
--- 159 ----
!     {"bli", PRO_INT, 0, OFF, &brace_indent, &exp_bli},
***************
*** 164 ****
!     {"cd", PRO_INT, 0, 0, &decl_com_ind, &exp_cd},
--- 164 ----
!     {"cd", PRO_INT, 0, OFF, &decl_com_ind, &exp_cd},
***************
*** 166,170 ****
!     {"ci", PRO_INT, 0, 0, &continuation_indent, &exp_ci},
!     {"cli", PRO_INT, 0, 0, &case_indent, &exp_cli},
!     {"cp", PRO_INT, 33, 0, &else_endif_col, &exp_cp},
!     {"c", PRO_INT, 33, 0, &com_ind, &exp_c},
!     {"di", PRO_INT, 16, 0, &decl_indent, &exp_di},
--- 166,170 ----
!     {"ci", PRO_INT, 0, OFF, &continuation_indent, &exp_ci},
!     {"cli", PRO_INT, 0, OFF, &case_indent, &exp_cli},
!     {"cp", PRO_INT, 33, OFF, &else_endif_col, &exp_cp},
!     {"c", PRO_INT, 33, OFF, &com_ind, &exp_c},
!     {"di", PRO_INT, 16, OFF, &decl_indent, &exp_di},
***************
*** 172 ****
!     {"d", PRO_INT, 0, 0, &unindent_displace, &exp_d},
--- 172 ----
!     {"d", PRO_INT, 0, OFF, &unindent_displace, &exp_d},
***************
*** 175,177 ****
!     {"fbc", PRO_FONT, 0, 0, (int *) &blkcomf, &exp_fbc},
!     {"fbx", PRO_FONT, 0, 0, (int *) &boxcomf, &exp_fbx},
!     {"fb", PRO_FONT, 0, 0, (int *) &bodyf, &exp_fb},
--- 175,177 ----
!     {"fbc", PRO_FONT, 0, OFF, (int *) &blkcomf, &exp_fbc},
!     {"fbx", PRO_FONT, 0, OFF, (int *) &boxcomf, &exp_fbx},
!     {"fb", PRO_FONT, 0, OFF, (int *) &bodyf, &exp_fb},
***************
*** 180,183 ****
!     {"fc", PRO_FONT, 0, 0, (int *) &scomf, &exp_fc},
!     {"fk", PRO_FONT, 0, 0, (int *) &keywordf, &exp_fk},
!     {"fs", PRO_FONT, 0, 0, (int *) &stringf, &exp_fs},
!     {"gnu", PRO_SETTINGS, 0, 0,
--- 180,183 ----
!     {"fc", PRO_FONT, 0, OFF, (int *) &scomf, &exp_fc},
!     {"fk", PRO_FONT, 0, OFF, (int *) &keywordf, &exp_fk},
!     {"fs", PRO_FONT, 0, OFF, (int *) &stringf, &exp_fs},
!     {"gnu", PRO_SETTINGS, 0, OFF,
***************
*** 188,189 ****
!     {"i", PRO_INT, 4, 0, &ind_size, &exp_i},
!     {"kr", PRO_SETTINGS, 0, 0,
--- 188,189 ----
!     {"i", PRO_INT, 4, OFF, &ind_size, &exp_i},
!     {"kr", PRO_SETTINGS, 0, OFF,
***************
*** 193 ****
!     {"lc", PRO_INT, 0, 0, &block_comment_max_col, &exp_lc},
--- 193 ----
!     {"lc", PRO_INT, 0, OFF, &block_comment_max_col, &exp_lc},
***************
*** 195 ****
!     {"l", PRO_INT, 78, 0, &max_col, &exp_l},
--- 195 ----
!     {"l", PRO_INT, 78, OFF, &max_col, &exp_l},
***************
*** 214 ****
!     {"npro", PRO_IGN, 0, 0, 0, &exp_pro},
--- 214 ----
!     {"npro", PRO_IGN, 0, OFF, 0, &exp_pro},
***************
*** 227 ****
!     {"st", PRO_STDIN, 0, 0, 0, &exp_st},
--- 227 ----
!     {"st", PRO_STDIN, 0, OFF, 0, &exp_st},
***************
*** 229 ****
!     {"version", PRO_PRSTRING, 0, 0, (int *)VERSION_STRING, &exp_version},
--- 229 ----
!     {"version", PRO_PRSTRING, 0, OFF, (int *)VERSION_STRING, &exp_version},
***************
*** 233 ****
!     {0, 0, 0, 0, 0, 0}
--- 233 ----
!     {0, PRO_BOOL, 0, OFF, 0, 0}

parousia(0.81)> make
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c args.c
cc -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std -c globs.c
cc -o indent -O -A nansi -A cpu,3000 -A systype,bsd4.3 -A runtype,bsd4.3 -W0,-frnd,-comchk,-std indent.o io.o lexi.o parse.o pr_comment.o args.o globs.o

*********************************************************************************

 -----------------------------------------------------------------------
   Gregory R. Siebers  | MAIL: P.O. Box 200195, Austin, TX 78720
    MCC CAD Program    | ARPA: siebers@mcc.com
     (512) 338-3656    | UUCP: ...!cs.utexas.edu!milano!cadillac!siebers
 -----------------------------------------------------------------------