From: junio@twinsun.COM (Jun Hamano)
Newsgroups: gnu.utils.bug
Subject: autoheader (autoconf 1.3)
Date: 25 Jan 1993 21:15:47 -0500
Organization: GNUs Not Usenet
Distribution: gnu

This patch supersedes my previous patch sent in
<9301251921.AA01130@tori.twinsun.com>.

Earlier, I reported that autoheader fails to parse m4 output
because of incompatibility between traditional `sed' and GNU sed.
Namely, for '/p1/,/p2/' construct, traditional sed sometimes
doesn't consider it is the end of range if both patterns appear
on the same line.

Another problem with autoheader was that at one place it feeds
sed a single very long line, which was silently truncated.

In the following patch, the first hunk fixes the `/p1/,/p2/'
problem, and the second fixes the truncated line problem.

-- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 ---- >8 --
*** autoheader.sh	1993/01/25 19:06:06	1.1
--- autoheader.sh	1993/01/25 21:57:49
***************
*** 61,69 ****
  
  # We extract assignments of SYMS, FUNCS, and HEADERS from the modified
  # autoconf processing of the input file.
  eval "`echo \"$frob\" \
         | m4 $MACROFILES - $infile \
!        | sed -n '/^@@@/,/@@@$/s/^@*\([^@]*\)@*$/\1/p'`"
  
  # Make SYMS newline-separated rather than blank-separated.
  syms="`for sym in $syms; do echo $sym; done`"
--- 61,79 ----
  
  # We extract assignments of SYMS, FUNCS, and HEADERS from the modified
  # autoconf processing of the input file.
+ # Traditional sed mishandles /p1/,/p2/ construct if both patterns
+ # appear on the same line (junio@twinsun.com).
  eval "`echo \"$frob\" \
         | m4 $MACROFILES - $infile \
!        | sed -n -e '
! 		: again
! 		/^@@@.*@@@$/s/@@@\(.*\)@@@$/\1/p
! 		/^@@@/{
! 			s/^@@@//p
! 			n
! 			s/^/@@@/
! 			b again
! 		}'`"
  
  # Make SYMS newline-separated rather than blank-separated.
  syms="`for sym in $syms; do echo $sym; done`"
***************
*** 71,88 ****
  test $# -eq 0 && exec > config.h.in
  
  echo "/* Generated automatically from $infile by autoheader.  DO NOT EDIT!  */"
- echo ''
  
- # Turn newlines into @s, then double-@s back into newlines.
  # This puts each paragraph on its own line, separated by @s.
  if test -n "$syms"; then
!   # Make sure blank lines are really blank so that @@ below wins.
!   sed 's/^[ 	]*$//' $TEMPLATES | tr \\012 @ | 
!   sed -e 's/@@/
! /g' |
!   # Select each paragraph that refers to a symbol we picked out above.
!   fgrep "$syms" |
!   sed '$!s/$/@/' | tr @ \\012
  fi
  
  for func in $funcs; do
--- 81,108 ----
  test $# -eq 0 && exec > config.h.in
  
  echo "/* Generated automatically from $infile by autoheader.  DO NOT EDIT!  */"
  
  # This puts each paragraph on its own line, separated by @s.
  if test -n "$syms"; then
!    # Make sure the boundary of template files is also the boundary
!    # of the paragraph.  Extra newlines don't hurt since they will
!    # be removed.
!    for t in $TEMPLATES; do cat $t; echo; echo; done |
!    # The sed script is suboptimal because it has to take care of
!    # some broken sed (e.g. AIX) that remove '\n' from the
!    # pattern/hold space if the line is empty. (junio@twinsun.com).
!    sed -n -e '
! 	/^[ 	]*$/{
! 		x
! 		s/\n/@/g
! 		p
! 		s/.*/@/
! 		x
! 	}
! 	H' | sed -e 's/@@*/@/g' |
!    # Select each paragraph that refers to a symbol we picked out above.
!    fgrep "$syms" |
!    tr @ \\012
  fi
  
  for func in $funcs; do