Subject Brokenness in sed

I've searched around and this is apparently a very old problem.
When you join two lines into the pattern space with the 'N'
command, an insertion should precede all the text in the
current pattern.  It does on every UNIX box I have access to,
except for GNU's sed program.  Further, there is no option for
either normalizing or "ab-normalizing" the behavior.  This is
a bug.  It needs to be possible to get normal behavior, preferably
without having to specify an ``--insert-normally'' option.

Here is a short script (from the GCC fixinclude stuff) that
demonstrates the problem.

#! /bin/ksh

res=test-$$

# # # # # # # INPUT FILE:
#
cat > ${res}-in.h <<'_EOF_'
#ifndef TEST
#define TEST

extern "C++" {
inline void *memchr(void *__1, int __2, size_t __3)
        { return (void *)memchr((const void *)__1, __2, __3); }
inline char *strstr(char *__1, const char *__2)
        { return (char *)strstr((const char *)__1, __2); }
}

#endif /* TEST */
_EOF_

# # # # # # # RESULT FILE:
#
cat > ${res}-samp.h <<'_EOF_'
#ifndef TEST
#define TEST

#ifndef __GNUC__
extern "C++" {
inline void *memchr(void *__1, int __2, size_t __3)
        { return (void *)memchr((const void *)__1, __2, __3); }
inline char *strstr(char *__1, const char *__2)
        { return (char *)strstr((const char *)__1, __2); }
}
#endif /* ! __GNUC__ */

#endif /* TEST */
_EOF_

# # # # # # # OUTPUT FILE:
#
SED=${SED:-$PWD/=b/sed/sed}
[ -x ${SED} ] || SED=`which sed`

cmd='/extern "C\+\+"/N
     /inline void.*memchr/i\
#ifndef __GNUC__
     /return.*strstr/N
     /return.*strstr.*}/a\
#endif /* ! __GNUC__ */'

${SED} "${cmd}" ${res}-in.h > ${res}-out.h

if cmp ${res}-samp.h ${res}-out.h > /dev/null
then
  exitcode=0
  echo "'sed' works correctly"
else
  echo "INVALID RESULT"
  exitcode=1
fi
rm -f ${res}-*
exit $exitcode



_______________________________________________
Bug-sh-utils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-sh-utils

Reply via email to