Magellan Linux

Diff of /branches/mage-next/src/mkinfodir.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2917 by niro, Mon Nov 30 13:51:05 2015 UTC revision 2918 by niro, Mon Nov 30 14:31:28 2015 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Id: mkinfodir,v 1.7 2005-06-01 15:48:42 niro Exp $  
3  # Generate the top-level Info node, given a directory of Info files  # Generate the top-level Info node, given a directory of Info files
4  # and (optionally) a skeleton file.  The output will be suitable for a  # and (optionally) a skeleton file.  The output will be suitable for a
5  # top-level dir file.  The skeleton file contains info topic names in the  # top-level dir file.  The skeleton file contains info topic names in the
# Line 23  Line 23 
23    
24  # $Id$  # $Id$
25    
26  INFODIR=$1  INFODIR="$1"
27  if [ $# = 2 ] ; then  if [[ $# = 2 ]]
28    SKELETON=$2  then
29     SKELETON="$2"
30  else  else
31    SKELETON=/dev/null   SKELETON="/dev/null"
32  fi  fi
33    
34  skip=  skip=
35    
36  if [ $# -gt 2 ] ; then  if [[ $# -gt 2 ]]
37    echo usage: $0 info-directory [ skeleton-file ] 1>&2  then
38    exit 1   echo "usage: $0 info-directory [ skeleton-file ]" 1>&2
39  elif [ -z "${INFODIR}" ] ; then   exit 1
40    INFODIR="%%DEFAULT_INFO_DIR%%"  elif [[ -z ${INFODIR} ]]
41    then
42     INFODIR="%%DEFAULT_INFO_DIR%%"
43  else  else
44    true   true
45  fi  fi
46    
47  if [ ! -d ${INFODIR} ] ; then  if [[ ! -d ${INFODIR} ]]
48    echo "$0: first argument must specify a directory"  then
49    exit 1   echo "$0: first argument must specify a directory"
50     exit 1
51  fi  fi
52    
53  # sanity checks  # sanity checks
54    for cmd in sed awk zcat ls grep egrep wc expr fgrep sort tr cut
55    do
56     if [[ -z $(type -P ${cmd}) ]]
57     then
58     echo "Command ${cmd} not found, not running $0"
59     exit 1
60     fi
61    done
62    
63  if [[ -x $(type -P date) ]]  if [[ -x $(type -P date) ]]
64  then  then
65   _DATE="$(date)"   _DATE="$(date)"
# Line 94  echo "This version was generated on ${_D Line 107  echo "This version was generated on ${_D
107  echo "by ${_WHOAMI}@${_HOSTNAME} for ${_PWD}"  echo "by ${_WHOAMI}@${_HOSTNAME} for ${_PWD}"
108    
109  cat << moobler  cat << moobler
110  \$Id: mkinfodir,v 1.7 2005-06-01 15:48:42 niro Exp $  
111  This is the file .../info/dir, which contains the topmost node of the  This is the file .../info/dir, which contains the topmost node of the
112  Info hierarchy.  The first time you invoke Info you start off  Info hierarchy.  The first time you invoke Info you start off
113  looking at that node, which is (dir)Top.  looking at that node, which is (dir)Top.
114    
115  File: dir Node: Top This is the top of the INFO tree  File: dir Node: Top This is the top of the INFO tree
116    
117    This (the Directory node) gives a menu of major topics.    This (the Directory node) gives a menu of major topics.
# Line 122  moobler Line 135  moobler
135  ### then generate entries for those in the same way, putting the info for  ### then generate entries for those in the same way, putting the info for
136  ### those at the end....  ### those at the end....
137    
138  infofiles=`(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*\.gz$' | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')`  infofiles=$(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*\.gz$' | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')
139    
140  # echoing gets clobbered by backquotes; we do it the hard way...  # echoing gets clobbered by backquotes; we do it the hard way...
141  lines=`wc $SKELETON | awk '{print $1}'`  lines=$(wc ${SKELETON} | awk '{print $1}')
142  line=1  line=1
143  while [ $lines -ge $line ] ; do  while [ ${lines} -ge ${line} ]
144    # Read one line from the file.  This is so that we can echo lines with  do
145    # whitespace and quoted characters in them.   # Read one line from the file.  This is so that we can echo lines with
146    fileline=`awk NR==$line $SKELETON`   # whitespace and quoted characters in them.
147     fileline=$(awk NR==${line} ${SKELETON})
   # flag fancy features  
   if [ ! -z "$echoline" ] ; then # echo line  
     echo "$fileline"  
     fileline=  
     echoline=  
   elif [ "${fileline}" = "--" ] ; then # should we echo the next line?  
     echoline=1  
   elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir?  
     skip=1  
   elif [ "${fileline}" = "!!" ] ; then # quit now  
     exit 0  
   fi  
   
   # handle files if they exist  
   for file in $fileline"" ; do # expand wildcards ("" handles blank lines)  
   
     fname=  
   
     if [ -z "$echoline" -a ! -z "$file" ] ; then  
   
       # Find the file to operate upon.  Check both possible names.  
       infoname=`echo $file | sed 's/\.gz$//'`  
       infoname=`echo $infoname | sed 's/\.info$//'`  
       noext=  
       ext=  
       if [ -f ${INFODIR}/$infoname ] ; then  
         noext=$infoname  
       fi  
       if [ -f ${INFODIR}/${infoname}.info ] ; then  
         ext=${infoname}.info  
       fi  
       if [ -f ${INFODIR}/${infoname}.info.gz ] ; then  
  ext=${infoname}.info.gz  
       fi  
       # If it exists with both names take what was said in the file.  
       if [ ! -z "$ext" -a ! -z "$noext" ]; then  
         fname=$file  
         warn="### Warning: $ext and $noext both exist!  Using ${file}. ###"  
       elif [ ! \( -z "$ext" -a -z "$noext" \) ]; then  
         # just take the name if it exists only once  
         fname=${noext}${ext}  
       fi  
   
       # if we found something and aren't skipping, do the entry  
       if [ ! -z "$fname" ] ; then  
         if [ -z "$skip" ] ; then  
   
           if [ ! -z "$warn" ] ; then # issue any warning  
     echo $warn  
     warn=  
           fi  
   if [ "${fname##*.}" = "gz" ] ; then  
     entry=`zcat ${INFODIR}/${fname} | sed -e '1,/START-INFO-DIR-ENTRY/d' \  
      -e '/END-INFO-DIR-ENTRY/,$d' `  
   else  
             entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \  
      -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname`  
   fi  
           if [ ! -z "${entry}" ] ; then  
             echo "${entry}"  
           else  
             echo "* ${infoname}: (${infoname})."  
           fi  
         fi  
   
         # remove the name from the directory listing  
  infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/  / /g"`  
   
       fi  
   
     fi  
148    
149    done   # flag fancy features
150     if [[ ! -z ${echoline} ]]
151     then
152     # echo line
153     echo "${fileline}"
154     fileline=
155     echoline=
156     elif [ "${fileline}" = "--" ]
157     then
158     # should we echo the next line?
159     echoline=1
160     elif [ "${fileline}" = "%%" ]
161     then
162     # eliminate remaining files from dir?
163     skip=1
164     elif [ "${fileline}" = "!!" ]
165     then
166     # quit now
167     exit 0
168     fi
169    
170    line=`expr $line + 1`   # handle files if they exist
171     for file in ${fileline}""
172     do
173     # expand wildcards ("" handles blank lines)
174     fname=
175     if [[ -z ${echoline} ]] && [[ -n ${file} ]]
176     then
177     # Find the file to operate upon.  Check both possible names.
178     infoname=$(echo ${file} | sed 's/\.gz$//')
179     infoname=$(echo ${infoname} | sed 's/\.info$//')
180     noext=
181     ext=
182     if [ -f ${INFODIR}/${infoname} ]
183     then
184     noext="${infoname}"
185     fi
186     if [ -f ${INFODIR}/${infoname}.info ]
187     then
188     ext="${infoname}.info"
189     fi
190     if [ -f ${INFODIR}/${infoname}.info.gz ]
191     then
192     ext="${infoname}.info.gz"
193     fi
194     # If it exists with both names take what was said in the file.
195     if [[ -n ${ext} ]] && [[ -n ${noext} ]]
196     then
197     fname="${file}"
198     warn="### Warning: $ext and $noext both exist!  Using ${file}. ###"
199     elif [ ! \( -z "$ext" -a -z "$noext" \) ]
200     then
201     # just take the name if it exists only once
202     fname=${noext}${ext}
203     fi
204     # if we found something and aren't skipping, do the entry
205     if [[ -n ${fname} ]]
206     then
207     if [[ -z ${skip} ]]
208     then
209     if [ -n ${warn} ]]
210     then
211     # issue any warning
212     echo "${warn}"
213     warn=
214     fi
215     if [[ ${fname##*.} = gz ]]
216     then
217     entry=$(zcat ${INFODIR}/${fname} | sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d')
218     else
219     entry=$(sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${fname})
220     fi
221     if [[ -n ${entry} ]]
222     then
223     echo "${entry}"
224     else
225     echo "* ${infoname}: (${infoname})."
226     fi
227     fi
228     # remove the name from the directory listing
229     infofiles=$(echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/  / /g")
230     fi
231     fi
232     done
233     line=$(expr $line + 1)
234  done  done
235    
236  if [ -z "${infofiles}" ] ; then  if [[ -z ${infofiles} ]]
237    exit 0  then
238  elif [ $lines -gt 0 ]; then   exit 0
239    echo  elif [[ ${lines} -gt 0 ]]
240    then
241     echo
242  fi  fi
243    
244  # Sort remaining files by INFO-DIR-SECTION.  # Sort remaining files by INFO-DIR-SECTION.
245  prevsect=  prevsect=
246  filesectdata=`(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | \  filesectdata=$(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | fgrep -v 'INFO-DIR-SECTION Miscellaneous' | sort -t: -k2 -k1 | tr ' ' '_')
247        fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \  for sectdata in ${filesectdata}
248        sort -t: -k2 -k1 | tr ' ' '_')`  do
249  for sectdata in ${filesectdata}; do   file=$(echo ${sectdata} | cut -d: -f1)
250    file=`echo ${sectdata} | cut -d: -f1`   section=$(sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file})
251    section=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}`   infofiles=$(echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/  / /g")
252    infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/  / /g"`   if [[ ${prevsect} != ${section} ]]
253     then
254    if [ "${prevsect}" != "${section}" ] ; then   if [[ -n ${prevsect} ]]
255      if [ ! -z "${prevsect}" ] ; then   then
256        echo ""   echo ""
257      fi   fi
258      echo "${section}"   echo "${section}"
259      prevsect="${section}"   prevsect="${section}"
260    fi   fi
261    infoname=`echo $file | sed 's/\.gz$//'`   infoname=$(echo ${file} | sed 's/\.gz$//')
262    infoname=`echo $infoname | sed 's/\.info$//'`   infoname=$(echo ${infoname} | sed 's/\.info$//')
263    if [ "${file##*.}" = "gz" ] ; then   if [[ ${file##*.} = gz ]]
264      entry=`zcat ${INFODIR}/$file | sed -e '1,/START-INFO-DIR-ENTRY/d' \   then
265       -e '/END-INFO-DIR-ENTRY/,$d' `   entry=$(zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d')
266    else   else
267              entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \   entry=$(sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file})
268       -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file`   fi
269    fi   if [[ -n ${entry} ]]
270    if [ ! -z "${entry}" ] ; then   then
271      echo "${entry}"   echo "${entry}"
272    elif [ ! -d "${INFODIR}/${file}" ] ; then   elif [[ ! -d ${INFODIR}/${file} ]]
273      echo "* ${infoname}: (${infoname})."   then
274    fi   echo "* ${infoname}: (${infoname})."
275     fi
276  done  done
277    
278  # Process miscellaneous files.  # Process miscellaneous files.
279  for file in ${infofiles}; do  for file in ${infofiles}
280    if [ ! -z "${prevsect}" ] ; then  do
281      echo ""   if [[ -n ${prevsect} ]]
282      echo "Miscellaneous"   then
283      prevsect=""   echo ""
284    fi   echo "Miscellaneous"
285     prevsect=""
286    infoname=`echo $file | sed 's/\.gz$//'`   fi
287    infoname=`echo $infoname | sed 's/\.info$//'`  
288    if [ "${file##*.}" = "gz" ] ; then   infoname=$(echo ${file} | sed 's/\.gz$//')
289             entry=`zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' \   infoname=$(echo ${infoname} | sed 's/\.info$//')
290       -e '/END-INFO-DIR-ENTRY/,$d'`   if [[ ${file##*.} = gz ]]
291    else   then
292              entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \   entry=$(zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d')
293       -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file`   else
294    fi   entry=$(sed -e '1,/START-INFO-DIR-ENTRY/d' -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file})
295     fi
   
   if [ ! -z "${entry}" ] ; then  
     echo "${entry}"  
   elif [ ! -d "${INFODIR}/${file}" ] ; then  
     echo "* ${infoname}: (${infoname})."  
   fi  
 done  
296    
297     if [[ -n ${entry} ]]
298     then
299     echo "${entry}"
300     elif [[ ! -d ${INFODIR}/${file} ]]
301     then
302     echo "* ${infoname}: (${infoname})."
303     fi
304    done

Legend:
Removed from v.2917  
changed lines
  Added in v.2918