Wed Jun 9 14:23:00 GMT 1999

"Kaveh R. Ghazi" wrote:
>         Here's another problem in fixincludes WRT sparc-sun-sunos4.1.4:

[[_CTRL() macro diffs omitted

>         This appears to happen because the ioctl_fix_ctrl fix never
> runs on the termios.h file.  The select pattern for that fix in
> inclhack.def is "CTRL[ \t]" (i.e. CTRL followed by at least one
> whitespace char.)  All the CTRL instances are followed by an open
> paren in termios.h.  Note the sed patterns don't require CTRL to have
> a whitespace after it.

Oops.  The original, of course, is too obtuse for words.
The comment around the original bragged about how efficient
it was, yet when I broke up the ugly, 50-line sed program,
it ran faster.

>         I don't know what the proper regexp for the select statement
> is.  The problem is that the ioctl_fix_ctrl fix is not documented at
> all other than saying "Fix CTRL macros".  But its not like the old
> fixincludes script had much in the way of docs anyway... :-)

Especially not that particular script :-(.  I will insert
some of my comments from below into inclhack.def :-).
Here is the relevant portion of the original script
(with tab substitutions):

  /[^A-Z0-9_]CTRL[ \t]*(/         s/\([^'\'']\))/'\''\1'\'')/
  /[^A-Z0-9]_CTRL[ \t]*(/         s/\([^'\'']\))/'\''\1'\'')/
  /#[ \t]*define[ \t]*[ \t]CTRL/  s/'\''\([cgx]\)'\''/\1/g
  /#[ \t]*define[ \t]*[ \t]_CTRL/ s/'\''\([cgx]\)'\''/\1/g
  /#[ \t]*define.BSD43_CTRL/      s/'\''\([cgx]\)'\''/\1/g

This is obviously weird stuff.
Oh, yes, this is the original selection pattern:

if egrep '//|[ \t_]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[ \t]+[!-.0-z\{\

What is so hard to understand about that?

I think the correct selection expression is thus:

    select = "CTRL[ \t]*\(";

Now for the sed stuff:

>         A related problem is that the ioctl_fix_ctrl gets run on many
> other files unnecessarily because they contain macros whose name ends
> in CTRL which matches the select pattern.  E.g. LEFTCTRL, RIGHTCTRL.
> But these files aren't of the form of which the sed patterns operate
> on.  Fixing the select value will fix this too.

As long as LEFTCTRL does not preceed an '('-:

>         The third problem is that even if I force the ioctl_fix_ctrl fix
> to run, I still get a one line diff of this:
>  > @@ -48,7 +48,7 @@
>  >  #define        VTIME           VEOL
>  >
>  >  #ifndef        _POSIX_SOURCE
>  > -#define        _CTRL(c)        (c&037)
>  > +#define        _CTRL('c')      ('c'&037)
>  >
>         So I'm not sure what the right patch for this is...

Well, that is very interesting.  My fixincl produces exactly the same
sed script, except that the "." between the "define" and "BSD43_CTRL"
is, instead, "[ \t]*[ \t]".  Basically, what is supposed to be happening
is that every _invocation_ of the "_CTRL()" or "CTRL()" macros is
supposed to have its argument inserted into single quotes.  A side effect
is that the quotes are inserted in the definitions of those macros
as well.  So, the last three sed expressions are supposed to clean
up the definitions, as long as those definitions are using "c", "g"
or "x" as the macro argument :).  Yuck.  Anyway, it seems the fourth
sed expression was not run successfully on this line.  Why not?

Here is my scriptlet from

    # Fix  31:  Ioctl_Fix_Ctrl
    if ( test -n "`egrep 'CTRL[ 	]' ${file}`"
       ) > /dev/null 2>&1 ; then
    if [ ! -r ${DESTFILE} ]
    then infile=${file}
    else infile=${DESTFILE} ; fi 

    sed -e '/[^A-Z0-9_]CTRL[ 	]*(/s/\([^'\'']\))/'\''\1'\'')/' \
        -e '/[^A-Z0-9]_CTRL[ 	]*(/s/\([^'\'']\))/'\''\1'\'')/' \
        -e '/#[ 	]*define[ 	]*[ 	]CTRL/s/'\''\([cgx]\)'\''/\1/g' \
        -e '/#[ 	]*define[ 	]*[ 	]_CTRL/s/'\''\([cgx]\)'\''/\1/g' \
        -e '/#[ 	]*define[ 	]*[ 	]BSD43_CTRL/s/'\''\([cgx]\)'\''/\1/g' \
          < $infile > ${DESTDIR}/fixinc.tmp
    rm -f ${DESTFILE}
    mv -f ${DESTDIR}/fixinc.tmp ${DESTFILE}
    fi # end of selection 'if'

Does _ANYONE_ see any obvious reason why the fourth sed expression
fails to alter the "#define _CTRL('c') ('c'&037)" line
into "#define _CTRL(c) (c&037)"?  The original line ought to
have beein "#define _CTRL(c) ('c'&037)", which is where the problem starts.

More information about the Gcc-patches mailing list