bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gawk] 4.1.1 breaks makewhatis -w


From: Daryl F
Subject: [bug-gawk] 4.1.1 breaks makewhatis -w
Date: Sat, 19 Apr 2014 23:06:24 -0500 (CDT)
User-agent: Alpine 2.00 (LNX 1167 2008-08-23)

The readline function seems to be affected. The script complains of a broken pipe at line #219 but doesn't do it on all man pages.

Definitely has a problem with /usr/man/man1/perlapi.1pm.gzB

Fallling back to gawk 4.1.0 made the problem disappear. I can't tell if this a lurking bug in makewhatis or if there is a regression in gawk.

Any assistance is appreciated. Below is the makewhatis script in use.

     1  #!/bin/sh
     2  # Generated automatically from makewhatis.in by the
     3  # configure script.
     4  #
     5  #!/bin/sh
     6  # makewhatis: create the whatis database
     7  # Created: Sun Jun 14 10:49:37 1992
     8  # Revised: Sat Jan  8 14:12:37 1994 by address@hidden
     9  # Revised: Sat Mar 23 17:56:18 1996 by address@hidden
    10  # Copyright 1992, 1993, 1994 Rickard E. Faith (address@hidden)
    11  # May be freely distributed and modified as long as copyright is 
retained.
    12  #
    13  # Wed Dec 23 13:27:50 1992: Rik Faith (address@hidden) applied changes
    14  # based on Mitchum DSouza (address@hidden) cat patches.
    15  # Also, cleaned up code and make it work with NET-2 doc pages.
    16  #
    17  # makewhatis-1.4: aeb 940802, 941007, 950417
    18  # Fixed so that the -c option works correctly for the cat pages
    19  # on my machine. Fix for -u by Nan Zou (address@hidden).
    20  # Many minor changes.
    21  # The -s option is undocumented, and may well disappear again.
    22  #
    23  # Sat Mar 23 1996: Michael Hamilton (address@hidden).
    24  # I changed the script to invoke gawk only once for each directory tree.
    25  # This speeds things up considerably (from 30 minutes down to 1.5 
minutes
    26  # on my 486DX66).
    27  # 960401 - aeb: slight adaptation to work correctly with cat pages.
    28  # 960510 - added fixes by address@hidden, author of mawk.
    29  # 971012 - replaced "test -z" - it doesnt work on SunOS 4.1.3_U1.
    30  # 980710 - be more careful with TMPFILE.
    31  # 000323 - do not change PATH, better treatment of catpages - Bryan 
Henderson.
    32  # 011117 - avoid suspicious filenames.
    33  # 030310 - find files only; fix LAPACK cruft; no /usr/man default;
    34  #       use /dev/stderr instead of /dev/tty; handle files with strange 
names;
    35  #       add support for chinese, hungarian, indonesian, japanese, 
korean,
    36  #       polish, russian (Thierry Vignaud).
    37  #
    38  # makewhatis 1.6: Federico Lucifredi
    39  # 060608 - Corrected traps.
    40  # 060719 - section choosing behavior to match man's (Mike frysinger).
    41  #
    42  # Note for Slackware users: "makewhatis -v -w -c" will work.
    43  #
    44  # makewhatis flc 060719 (from man-1.6g)

    45  program=`basename $0`

    46  # In case both /usr/man and /usr/share/man exist, the former is local
    47  # and should be first.
    48  # It is a bug to add /var/cache/man to DEFCATPATH.
    49  dm=
    50  for d in /usr/man /usr/share/man /usr/X11R6/man /usr/local/man
    51  do
    52      if [ -d $d ]; then
    53          if [ x$dm = x ]; then dm=$d; else dm=$dm:$d; fi
    54      fi
    55  done
    56  DEFMANPATH=$dm
    57  dc=
    58  for d in /usr/man/preformat /usr/man /usr/share/man/preformat 
/usr/share/man
    59  do
    60      if [ -d $d ]; then
    61          if [ x$dc = x ]; then dc=$d; else dc=$dc:$d; fi
    62      fi
    63  done
    64  DEFCATPATH=$dc

    65  # In case /usr is read-only, make /usr/foo/whatis (etc) a symlink to
    66  # something like /var/cache/man/foo-whatis.
    67  # Some distributions make a single big /var/cache/man/whatis file,
    68  # but that leads to problems and bugs.

    69  # AWK=/usr/bin/gawk
    70  AWK=/usr/bin/awk

    71  # Find a place for our temporary files. If security is not a concern, 
use
    72  #       TMPFILE=/tmp/whatis$$; TMPFILEDIR=none
    73  # Of course makewhatis should only have the required permissions
    74  # (for reading and writing directories like /usr/man).
    75  # We try here to be careful (and avoid preconstructed symlinks)
    76  # in case makewhatis is run as root, by creating a subdirectory of /tmp.

    77  TMPFILEDIR=/tmp/whatis.tmp.dir.$$
    78  rm -rf $TMPFILEDIR
    79  if ! mkdir -m 0700 $TMPFILEDIR; then
    80      echo Could not create $TMPFILEDIR
    81      exit 1;
    82  fi
    83  TMPFILE=$TMPFILEDIR/w

    84  # make sure TMPFILEDIR is deleted if program is killed or terminates
    85  # (just delete this line if your shell doesnt know about trap)
    86  trap "rm -rf $TMPFILEDIR" 0
    87  trap "rm -rf $TMPFILEDIR; exit 255" 1 2 3 15

    88  # default find arg: no directories, no empty files
    89  findarg0="-type f -size +0"

    90  topath=manpath

    91  defmanpath=$DEFMANPATH
    92  defcatpath=

    93  if [ -n "$MANSECT" ]; then
    94          sections=$MANSECT
    95  else
    96          sections=`$AWK '($1 == "MANSECT") { print $2 }' /etc/man.conf`
    97          if [ x"$sections" = x ]; then
    98                  sections="1:1p:8:2:3:3p:4:5:6:7:9:0p:tcl:n:l:p:o"
    99          fi
   100  fi
   101  sections=`echo $sections | sed -e 's/:/ /g'`

   102  for name in "$@"
   103  do
   104  if [ -n "$setsections" ]; then
   105          setsections=
   106          sections=$name
   107          continue
   108  fi
   109  case $name in
   110      --version|-V)
   111          echo "$program from man-1.6g"
   112          exit 0;;
   113      -c) topath=catpath
   114          defmanpath=
   115          defcatpath=$DEFCATPATH
   116          continue;;
   117      -s) setsections=1
   118          continue;;
   119      -u) findarg="-ctime 0"
   120          update=1
   121          continue;;
   122      -v) verbose=1
   123          continue;;
   124      -w) manpath=`man --path`
   125          catpath=$manpath
   126          continue;;
   127      -*) echo "Usage: makewhatis [-s sections] [-u] [-v] [-w] [manpath] [-c 
[catpath]]"
   128          echo "       This will build the whatis database for the man 
pages"
   129          echo "       found in manpath and the cat pages found in 
catpath."
   130          echo "       -s: sections (default: $sections)"
   131          echo "       -u: update database with new pages"
   132          echo "       -v: verbose"
   133          echo "       -w: use manpath obtained from \`man --path\`"
   134          echo "       [manpath]: man directories (default: $DEFMANPATH)"
   135          echo "       [catpath]: cat directories (default: the first 
existing"
   136          echo "           directory in $DEFCATPATH)"
   137          exit;;
   138       *) if [ -d $name ]
   139          then
   140              eval $topath="\$$topath":$name
   141          else
   142              echo "No such directory $name"
   143              exit
   144          fi;;
   145  esac
   146  done

   147  manpath=`echo ${manpath-$defmanpath} | tr : ' '`
   148  if [ x"$catpath" = x ]; then
   149     for d in `echo $defcatpath | tr : ' '`
   150     do
   151        if [ -d $d ]; then catpath=$d; break; fi
   152     done
   153  fi
   154  catpath=`echo ${catpath} | tr : ' '`

   155  # first truncate all the whatis files that will be created new,
   156  # then only update - we might visit the same directory twice
   157  if [ x$update = x ]; then
   158     for pages in man cat
   159     do
   160        eval path="\$$pages"path
   161        for mandir in $path
   162        do
   163           cp /dev/null $mandir/whatis
   164        done
   165     done
   166  fi

   167  for pages in man cat
   168  do
   169     export pages
   170     eval path="\$$pages"path
   171     for mandir in $path
   172     do
   173       if [ x$verbose != x ]; then
   174          echo "about to enter $mandir" > /dev/stderr
   175       fi

   176       # kludge for Slackware's /usr/man/preformat
   177       if [ $mandir = /usr/man/preformat ]
   178       then
   179          mandir1=/usr/man
   180       else
   181          mandir1=$mandir
   182       fi

   183       # if $mandir is on a readonly partition, and the whatis file
   184       # is not a symlink, then let's skip trying to update it
   185       if [ ! -L ${mandir1}/whatis ]
   186       then
   187          if [ -e ${mandir1}/whatis ] && [ ! -w ${mandir1}/whatis ]
   188          then
   189             if [ x$verbose != x ]; then
   190                echo skipping $mandir - whatis file is readonly > 
/dev/stderr
   191             fi
   192             continue
   193          elif [ ! -e ${mandir1}/whatis ] && [ ! -w ${mandir1} ]
   194          then
   195             if [ x$verbose != x ]; then
   196                echo skipping $mandir - directory is readonly > 
/dev/stderr
   197             fi
   198             continue
   199          fi
   200       fi

   201       if [ -s ${mandir}/whatis -a $pages = man -a x$update = x ]; then
   202          if [ x$verbose != x ]; then
   203             echo skipping $mandir - we did it already > /dev/stderr
   204          fi
   205       else
   206         here=`pwd`
   207         cd $mandir
   208         for i in $sections
   209         do
   210           if [ -d ${pages}$i ]
   211           then
   212              cd ${pages}$i
   213              section=$i
   214              curdir=$mandir/${pages}$i
   215              export section verbose curdir
   216              find $mandir/${pages}$i/. -name '*' $findarg0 $findarg 
-print | $AWK '

   217              function readline() {
   218                if (use_zcat || use_bzcat || use_lzcat) {
   219                  result = (pipe_cmd | getline);
   220                  if (result < 0) {
   221                    print "Pipe error: " pipe_cmd " " ERRNO > 
"/dev/stderr";
   222                  }
   223                } else {
   224                  result = (getline < filename);
   225                  if (result < 0) {
   226                    print "Read file error: " filename " " ERRNO > 
"/dev/stderr";
   227                  }
   228                }
   229                return result;
   230              }
   231
   232              function closeline() {
   233                if (use_zcat || use_bzcat || use_lzcat) {
   234                  return close(pipe_cmd);
   235                } else {
   236                  return close(filename);
   237                }
   238              }
   239
   240              function do_one() {
   241                insh = 0; thisjoin = 1; done = 0;
   242                entire_line = "";

   243                if (verbose) {
   244                  print "adding " filename > "/dev/stderr"
   245                }
   246
   247                use_zcat = match(filename,"\\.Z$") ||
   248                           match(filename,"\\.z$") || 
match(filename,"\\.gz$");
   249                if (!use_zcat)
   250                  use_bzcat = match(filename,"\\.bz2");
   251                if(!use_bzcat)
   252                  use_lzcat = match(filename,"\\.lzma");
   253                if (use_zcat || use_bzcat || use_lzcat ) {
   254                  filename_no_gz = substr(filename, 0, RSTART - 1);
   255                } else {
   256                  filename_no_gz = filename;
   257                }
   258                match(filename_no_gz, "/[^/]+$");
   259                progname = substr(filename, RSTART + 1, RLENGTH - 1);
   260                if (match(progname, "\\." section "[A-Za-z]+")) {
   261                  actual_section = substr(progname, RSTART + 1, RLENGTH - 
1);
   262                } else {
   263                  actual_section = section;
   264                }
   265                sub(/\..*/, "", progname);
   266                if (use_zcat || use_bzcat || use_lzcat) {
   267                  if (use_zcat) {
   268                    pipe_cmd = "zcat \"" filename "\"";
   269                  } else if (use_bzcat) {
   270                    pipe_cmd = "bzcat \"" filename "\"";
   271                  } else {
   272                    pipe_cmd = "lzcat \"" filename "\"";
   273                  }
   274                  # try to avoid suspicious stuff
   275                  if (filename ~ /[;&|`$(]/) {
   276                    print "ignored strange file name " filename " in " curdir > 
"/dev/stderr";
   277                    return;
   278                  }
   279                }
   280
   281                while (!done && readline() > 0) {
   282                  gsub(/.\b/, "");
   283                  if (($1 ~ /^\.[Ss][Hh]/ &&
   284                    ($2 ~ /[Nn][Aa][Mm][Ee]/ ||
   285                     $2 ~ /^JM?O/ || $2 ~ /^NAVN/ || $2 ~ /^NUME/ ||
   286                     $2 ~ /^BEZEICHNUNG/ || $2 ~ /^NOMBRE/ ||
   287                     $2 ~ /^NIMI/ || $2 ~ /^NOM/ || $2 ~ /^IME/ ||
   288                     $2 ~ /^N[?]V/ || $2 ~ /^NAMA/ || $2 ~ /^̾??/ ||
   289                     $2 ~ /^̾?? || $2 ~ /^?̸?/ || $2 ~ /^NAZWA/ ||
   290                     $2 ~ /^????/ || $2 ~ /^??? || $2 ~ /^?W?? ||
   291                     $2 ~ /^NOME/ || $2 ~ /^NAAM/ || $2 ~ /^??)) ||
   292                    (pages == "cat" && $1 ~ /^NAME/)) {
   293                      if (!insh) {
   294                        insh = 1;
   295                      } else {
   296                        done = 1;
   297                      }
   298                  } else if (insh) {
   299                    if ($1 ~ /^\.[Ss][HhYS]/ ||
   300                      (pages == "cat" &&
   301                      ($1 ~ /^S[yYeE]/ || $1 ~ /^DESCRIPTION/ ||
   302                       $1 ~ /^COMMAND/ || $1 ~ /^OVERVIEW/ ||
   303                       $1 ~ /^STRUCTURES/ || $1 ~ /^INTRODUCTION/ ||
   304                       $0 ~ /^[^ ]/))) {
   305                        # end insh for Synopsis, Syntax, but also for
   306                        # DESCRIPTION (e.g., XFree86.1x),
   307                        # COMMAND (e.g., xspread.1)
   308                        # OVERVIEW (e.g., TclCommandWriting.3)
   309                        # STRUCTURES (e.g., XEvent.3x)
   310                        # INTRODUCTION (e.g., TclX.n)
   311                        # and anything at all that begins in Column 1, so
   312                        # is probably a section header.
   313                      done = 1;
   314                    } else {
   315                      if ($0 ~ progname"-") {  # Fix old cat pages
   316                          sub(progname"-", progname" - ");
   317                      }
   318                      if ($0 ~ /[^ \\]-$/) {
   319                        sub(/-$/, "");    # Handle Hyphenations
   320                        nextjoin = 1;
   321                      } else if ($0 ~ /\\c$/) {
   322                        sub(/\\c$/, "");          # Handle Continuations
   323                        nextjoin = 1;
   324                      } else
   325                        nextjoin = 0;

   326                      sub(/^.[IB] /, "");       # Kill bold and italics
   327                      sub(/^.BI /, "");         #
   328                      sub(/^.SM /, "");         # Kill small
   329                      sub(/^.Nm /, "");         # Kill bold
   330                      sub(/^.Tn /, "");         # Kill normal
   331                      sub(/^.Li /, "");         # Kill .Li
   332                      sub(/^.Dq /, "");         # Kill .Dq
   333                      sub(/^.Nd */, "- ");      # Convert .Nd to dash
   334                      sub(/\\\".*/, "");        # Trim pending comments
   335                      sub(/  *$/, "");          # Trim pending spaces
   336                      sub(/^\.$/, "");          # Kill blank comments
   337                      sub(/^'"'"'.*/, "");      # Kill comment/troff lines
   338                      sub(/^.in .*/, "");       # Kill various macros
   339                      sub(/^.ti .*/, "");
   340                      sub(/^.ta .*/, "");
   341                      sub(/^.Vb .*/, "");
   342                      sub(/^.[PLTH]P$/, "");    # .PP/.LP/.TP/.HP
   343                      sub(/^.Pp$/, "");
   344                      sub(/^.[iI]X .*$/, "");
   345                      sub(/^.nolinks$/, "");
   346                      sub(/^.B$/, "");
   347                      sub(/^.nf$/, "");

   348                      if (($1 ~ /^\.../ || $1 == "") &&
   349                          (entire_line ~ / - / || entire_line ~ / \\- /)) 
{
   350                        # Assume that this ends the description of one 
line
   351                        # Sometimes there are several descriptions in one 
page,
   352                        # as in outb(2).
   353                        handle_entire_line();
   354                        entire_line = "";
   355                        thisjoin = 1;
   356                      } else {
   357                        if (thisjoin) {
   358                          entire_line = entire_line $0;
   359                        } else {
   360                          entire_line = entire_line " " $0;
   361                        }
   362                        thisjoin = nextjoin;
   363                      }
   364                    }
   365                  }
   366                }
   367                handle_entire_line();
   368                closeline();
   369              }

   370              function handle_entire_line() {
   371                x = entire_line;             # Keep it short

   372                gsub(/\015/, "", x);         # Kill DOS remains
   373                gsub(/    /, " ", x);        # Translate tabs to spaces
   374                gsub(/  +/, " ", x);         # Collapse spaces
   375                gsub(/ *, */, ", ", x);      # Fix comma spacings
   376                sub(/^ /, "", x);            # Kill initial spaces
   377                sub(/ $/, "", x);            # Kill trailing spaces
   378                sub(/__+/, "_", x);          # Collapse underscores

   379                gsub(/\\f\(../, "", x);         # Kill font changes
   380                gsub(/\\f[PRIB0123]/, "", x);   # Kill font changes
   381                gsub(/\\s[-+0-9]*/, "", x);     # Kill size changes
   382                gsub(/\\&/, "", x);             # Kill \&
   383                gsub(/\\\|/, "", x);            # Kill \|
   384                gsub(/\\\((ru|ul)/, "_", x);    # Translate
   385                gsub(/\\\((mi|hy|em)/, "-", x); # Translate
   386                gsub(/\\\*\(../, "", x);        # Kill troff strings
   387                gsub(/\\/, "", x);              # Kill all backslashes
   388                gsub(/"/, "", x);               # Kill quotes (from .Nd "foo 
bar")
   389                sub(/<h1 align=center>/, "", x);# Yuk! HTML cruft
   390                gsub(/\000.*/, "X", x);         # Binary cruft in LAPACK 
pages
   391                gsub(/  +/, " ", x);            # Collapse spaces (again)
   392                sub(/^ /, "", x);               # Kill initial spaces 
(again)
   393                sub(/ $/, "", x);               # Kill trailing spaces 
(again)
   394                sub(/\.$/, "", x);              # Kill trailing period

   395                if (!match(x, / - /))
   396                  return;

   397                after_dash = substr(x, RSTART);
   398                head = substr(x, 1, RSTART-1) ", ";
   399                while (match(head, /, /)) {
   400                  prog = substr(head, 1, RSTART-1);
   401                  head = substr(head, RSTART+2);
   402                  if (prog != progname)
   403                    prog = prog " [" progname "]";
   404                  printf "%-*s (%s) %s\n", 20, prog, actual_section, 
after_dash;
   405                }
   406              }

   407              {                   # Main action - process each filename 
read in.
   408                filename = $0;
   409                do_one();
   410              }
   411              ' pages=$pages section=$section verbose=$verbose 
curdir=$curdir
   412              cd ..
   413           fi
   414         done > $TMPFILE

   415         cd "$here"

   416         if [ -f ${mandir1}/whatis ]
   417         then
   418           cat ${mandir1}/whatis >> $TMPFILE
   419         fi
   420         tr -s '\n' < $TMPFILE | sort -u > ${mandir1}/whatis

   421         chmod 644 ${mandir1}/whatis
   422         rm $TMPFILE
   423       fi
   424     done
   425  done

   426  # remove tempdir
   427  rm -rf $TMPFILEDIR



-Daryl

reply via email to

[Prev in Thread] Current Thread [Next in Thread]