make_sed.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. # $Id: make_sed.sh,v 1.9 2005/07/16 18:15:31 tom Exp $
  3. ##############################################################################
  4. # Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. #
  5. # #
  6. # Permission is hereby granted, free of charge, to any person obtaining a #
  7. # copy of this software and associated documentation files (the "Software"), #
  8. # to deal in the Software without restriction, including without limitation #
  9. # the rights to use, copy, modify, merge, publish, distribute, distribute #
  10. # with modifications, sublicense, and/or sell copies of the Software, and to #
  11. # permit persons to whom the Software is furnished to do so, subject to the #
  12. # following conditions: #
  13. # #
  14. # The above copyright notice and this permission notice shall be included in #
  15. # all copies or substantial portions of the Software. #
  16. # #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL #
  20. # THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING #
  22. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER #
  23. # DEALINGS IN THE SOFTWARE. #
  24. # #
  25. # Except as contained in this notice, the name(s) of the above copyright #
  26. # holders shall not be used in advertising or otherwise to promote the sale, #
  27. # use or other dealings in this Software without prior written #
  28. # authorization. #
  29. ##############################################################################
  30. #
  31. # Author: Thomas E. Dickey 1997-2005
  32. #
  33. # Construct a sed-script to perform renaming within man-pages. Originally
  34. # written in much simpler form, this one accounts for the common cases of
  35. # section-names in man-pages.
  36. if test $# != 1 ; then
  37. echo '? expected a single filename'
  38. exit 1
  39. fi
  40. COL=col$$
  41. INPUT=input$$
  42. UPPER=upper$$
  43. SCRIPT=script$$
  44. RESULT=result$$
  45. rm -f $UPPER $SCRIPT $RESULT
  46. trap "rm -f $COL.* $INPUT $UPPER $SCRIPT $RESULT" 0 1 2 5 15
  47. fgrep -v \# $1 | \
  48. sed -e 's/[ ][ ]*/ /g' >$INPUT
  49. for F in 1 2 3 4
  50. do
  51. sed -e 's/\./ /g' $INPUT | \
  52. cut -f $F > $COL.$F
  53. done
  54. for F in 2 4
  55. do
  56. tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ <$COL.$F >$UPPER
  57. mv $UPPER $COL.$F
  58. done
  59. paste $COL.* | \
  60. sed -e 's/^/s\/\\</' \
  61. -e 's/$/\//' >$UPPER
  62. echo "# Do the TH lines" >>$RESULT
  63. sed -e 's/\//\/TH /' \
  64. -e 's/ / /' \
  65. -e 's/ / ""\/TH /' \
  66. -e 's/ / /' \
  67. -e 's/\/$/ ""\//' \
  68. $UPPER >>$RESULT
  69. echo "# Do the embedded references" >>$RESULT
  70. sed -e 's/</<fB/' \
  71. -e 's/ /\\\\fR(/' \
  72. -e 's/ /)\/fB/' \
  73. -e 's/ /\\\\fR(/' \
  74. -e 's/\/$/)\//' \
  75. $UPPER >>$RESULT
  76. echo "# Do the \fBxxx\fR references in the .NAME section" >>$RESULT
  77. sed -e 's/\\</^\\\\fB/' \
  78. -e 's/ [^ ]* /\\\\f[RP] -\/\\\\fB/' \
  79. -e 's/ .*$/\\\\fR -\//' \
  80. $UPPER >>$RESULT
  81. # Finally, send the result to standard output
  82. cat $RESULT