File: texi2dvi

package info (click to toggle)
gtalk 0.99.10-8
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,976 kB
  • ctags: 2,432
  • sloc: ansic: 16,651; lisp: 14,650; sh: 524; makefile: 146
file content (122 lines) | stat: -rwxr-xr-x 3,302 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
#
# texi2dvi - prepare Texinfo files for printing.  
#
# Copyright (C) 1990, 1991 Free Software Foundation.
#
# Roland McGrath <roland@gnu.ai.mit.edu>
# Version 0.10
# 24 Sep 91
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# A copy of the GNU General Public License can be obtained from this
# program's author (send electronic mail to roland@ai.mit.edu) or from
# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
# 02139, USA.

if [ $# -eq 0 ]; then
  echo "Usage: `basename $0` FILE ..." >&2
  exit 1
fi

TEXINDEX=${TEXINDEX-texindex}
TEX=${TEXINFO-${TEX-tex}}

for file in $*; do
  base="`basename $file .texinfo | \
	 sed -e 's/\.texi$//' -e 's/\.tex$//'`"

  # Find all existing index files corresponding to FILE.
  idx_files="`echo ${base}.??`"
  if [ "$idx_files" = "${base}.??" ]; then
    idx_files=''
  else
    # Ignore files with two-letter extensions that don't look like index files.
    oidx_files="$idx_files"
    idx_files=''
    for idx_file in $oidx_files; do
      if [ "`sed -n '1s/^\(.\).*$/\1/p' $idx_file`" = \\ ]; then
        # It starts with a backslash, so it's probably an index file.
	idx_files="$idx_files $idx_file"
      fi
    done
  fi

  for idx_file in $idx_files; do
    # Save a copy of the old index file.
    cp ${idx_file} ${idx_file}O
  done

  if [ "$idx_files" != "" ]; then
    # Run texindex on the index files.
    ${TEXINDEX} $idx_files
  fi

  # Run TeX on FILE.
  if ${TEX} $file; then

    # Find all the index files that exist now,
    # so we can see if there are any new ones.
    new_idx_files="`echo ${base}.??`"
    if [ "$new_idx_files" = "${base}.??" ]; then
      new_idx_files=''
    else
      oidx_files="$idx_files"
      new_idx_files=''
      for idx_file in $oidx_files; do
	if [ "`sed -n '1s/^\(.\).*$/\1/p' $idx_file`" = \\ ]; then
	  # It starts with a backslash, so it's probably an index file.
	  new_idx_files="$new_idx_files $idx_file"
	fi
      done
    fi

    if [ "$new_idx_files" != "$idx_files" ]; then
      # There are some new index files.
      changed=yes
      idx_files="$new_idx_files"
    else
      # Run through all the index files, comparing them to the old ones.
      changed=no
      for idx_file in $idx_files; do
	# Compare the old and new index files.
	cmp -s ${idx_file}O ${idx_file}
	status=$?

	# Remove the old index file.
	rm -f ${idx_file}O

	if [ $status -ne 0 ]; then
	  # The index file has changed.
	  changed=yes
	fi
      done	# for idx_file
    fi

    if [ $changed = yes ]; then
      # Some index file changed.  Run texindex and TeX again.

      # Run texindex on the index files.
      if ${TEXINDEX} $idx_files; then
	# Run TeX on FILE.
	${TEX} $file
      fi
    fi
  else
    # TeX failed.  Remove the copies of the index files.
    for idx_file in $idx_files; do
      rm ${idx_file}O
    done
  fi

done	   # for file