texindex.in 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/sh
  2. # $Id$
  3. #
  4. # Copyright 2015, 2016 Free Software Foundation, Inc.
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License,
  9. # or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. # Originally written by Karl Berry.
  20. # Please send bug reports, etc. to bug-texinfo@gnu.org.
  21. #
  22. # Shell wrapper for the texindex.awk program. This is the most
  23. # convenient way to support --options; with a #! line, it is (g)awk
  24. # itself that interprets the options. We want texindex --version
  25. # to report texindex's version number, not gawk's.
  26. #
  27. # So our job here is to (a) find the awk interpreter,
  28. # and (b) find the texindex.awk script file.
  29. mydir=`cd \`dirname $0\` && pwd`
  30. #
  31. # allow user override for awk program location.
  32. awk_binary=
  33. awk_envvar=$TEXINDEX_AWK
  34. if test -n "$awk_envvar"; then
  35. if test -s "$awk_envvar"; then
  36. awk_binary=$awk_envvar
  37. else
  38. echo "$0: TEXINDEX_AWK environment variable set, but value" >&2
  39. echo "$0: is not a readable non-empty file; ignoring: $awk_envvar" >&2
  40. fi
  41. fi
  42. #
  43. # else use configured value for awk.
  44. if test -z "$awk_binary"; then
  45. awk_binary="@AWK@"
  46. fi
  47. #
  48. # that should never be empty, but just in case, else fall back to plain
  49. # "awk". (Let's not go to the trouble of searching PATH unless we get
  50. # reports of problems.)
  51. test -z "$awk_binary" && awk_binary=awk
  52. #
  53. # finding the texindex.awk script file ...
  54. ti_script=
  55. #
  56. # allow user override for script location:
  57. ti_envvar=$TEXINDEX_SCRIPT
  58. if test -n "$ti_envvar"; then
  59. if test -s "$ti_envvar"; then
  60. ti_script=$ti_envvar
  61. else
  62. echo "$0: TEXINDEX_SCRIPT environment variable set, but value" >&2
  63. echo "$0: is not a readable non-empty file; ignoring: $ti_script" >&2
  64. fi
  65. fi
  66. #
  67. # else if script is in the same directory as us (development tree), use it:
  68. test -z "$ti_script" && test -s "$mydir/texindex.awk" \
  69. && ti_script=$mydir/texindex.awk
  70. #
  71. # else look for script in pkgdatadir.
  72. if test -z "$ti_script"; then
  73. pkgdatadir_configured="@pkgdatadir@"
  74. test -s "$pkgdatadir_configured/texindex.awk" \
  75. && ti_script=$pkgdatadir_configured/texindex.awk
  76. fi
  77. #
  78. # look relative to $mydir, to allow the installed tree to be moved.
  79. if test -z "$ti_script"; then
  80. relative_dir=$mydir/../share/texinfo
  81. test -d "$relative_dir" \
  82. && test -s "$relative_dir/texindex.awk" \
  83. && ti_script=$relative_dir/texindex.awk
  84. fi
  85. #
  86. # didn't find it, abort.
  87. if test -z "$ti_script"; then
  88. echo "$0: could not locate texindex.awk script file, quitting." >&2
  89. echo "$0: (checked envvar TEXINDEX_SCRIPT ($TEXINDEX_SCRIPT)," >&2
  90. echo "$0: executable dir ($mydir)," >&2
  91. echo "$0: share dir relative to binary ($relative_dir)," >&2
  92. echo "$0: and configured pkgdatadir ($pkgdatadir_configured).)" >&2
  93. exit 1
  94. fi
  95. # Suppose a symlink named a\tb (four chars) is made to this script, and
  96. # "a\tb" --help
  97. # is invoked. We want the output to report the program name as the
  98. # four chars a, \, t, b, not a, tab, b.
  99. #
  100. # But we pass the value using (g)awk -v, and (g)awk processes arguments
  101. # to -v for escape sequences, so that by the time the rest of the script
  102. # sees it, it has a tab in it.
  103. #
  104. # Conclusion: we must double any backslashes before invoking gawk,
  105. # by running the command: sed 's,\\,\\\\,g'
  106. #
  107. # Sadly, since we have to do this in a shell, we need twice
  108. # as many backslash characters in the input. Hope it's portable across
  109. # shells and seds.
  110. #
  111. escaped0=`echo "$0" | sed 's,\\\\,\\\\\\\\,g'`
  112. exec $awk_binary -v Invocation_name="$escaped0" -f "$ti_script" -- "$@"