~fauli/texmfind/2008

« back to all changes in this revision

Viewing changes to branches/texmfind-0.1-r1/export-texmf_files

  • Committer: Christian Faulhammer
  • Date: 2009-09-08 19:05:07 UTC
  • Revision ID: fauli@gentoo.org-20090908190507-m107q92d23cw6ti2
Sort files to match we need

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
# vim: set foldmethod=marker tw=0 commentstring=\ #%s :
3
 
 
4
 
########################################################################
5
 
6
 
# export-texmf_files : Generate flat data file, for texmfind utility, on
7
 
# a Gentoo box with integral dev-texlive/dev-tex installation . Not
8
 
# intended for end users.
9
 
#
10
 
# Copyright (C) 2008 Alexandre
11
 
12
 
# This program is free software: you can redistribute it and/or modify
13
 
# it under the terms of the GNU General Public License as published by
14
 
# the Free Software Foundation, either version 3 of the License, or
15
 
# (at your option) any later version.
16
 
17
 
# This program is distributed in the hope that it will be useful,
18
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
# GNU General Public License for more details.
21
 
22
 
# You should have received a copy of the GNU General Public License
23
 
# along with this program, located in /usr/share/doc/texmfind/licence.
24
 
# If not, see <http://www.gnu.org/licenses/>.
25
 
26
 
# The author can be contacted by email : etux@bluewin.ch
27
 
#
28
 
#########################################################################
29
 
 
30
 
# Intermediary output list files to... ?
31
 
tmp_files_path="/tmp"
32
 
# Pattern for texmf installed files ?
33
 
texmf_path_pattern="/usr/share/texmf*"
34
 
 
35
 
# Files #{{{
36
 
# Each file should have an associated function sharing the same name.
37
 
# Files will be built by those functions in the order they appear here,
38
 
# in ${files}.
39
 
 
40
 
files=( "texmf_all"      # List of all texmf regular files.
41
 
        "texmf_qfiles"   # Add corresponding ebuild to file list.
42
 
        "texmf_format"   # Format previous file for further processing.
43
 
        "texmf_noboring" # Boring files removed from previous file.
44
 
        "texmf_files"    # Last format. Ready for production :p
45
 
      )
46
 
 
47
 
tmp () {
48
 
  echo "${tmp_files_path}/${1}"
49
 
}
50
 
 
51
 
# Prepend files with tmp path
52
 
for (( i=0; i < ${#files[@]}; i++ )); do
53
 
  files[${i}]=$(tmp ${files[${i}]})
54
 
done
55
 
 
56
 
#}}}
57
 
# File functions #{{{
58
 
previous_file () { #{{{
59
 
# Given a (fullpath) filename existing in ${files}, will return the
60
 
# previous (fullpath) filename in the list.
61
 
  file=${1}
62
 
  for (( i=0; i < ${#files[@]}; i++ )); do
63
 
    if [[ ${file} == ${files[${i}]} ]]; then
64
 
      echo ""
65
 
      break
66
 
    elif [[ ${file} == ${files[(${i}+1)]} ]]; then
67
 
      echo ${files[${i}]}
68
 
      break
69
 
    fi
70
 
  done
71
 
}
72
 
#}}}
73
 
texmf_common () { #{{{
74
 
  file=${1}
75
 
  if [[ -e ${file} ]]; then
76
 
    printf \
77
 
    "* File \"%s\" allready exists; Skipping.\n\t-> (To rebuild, just delete it).\n\n" \
78
 
    "${1}"
79
 
  else 
80
 
    func=${file##*/}
81
 
    prev=$(previous_file ${file})
82
 
    eval "${func} ${file} ${prev}"
83
 
  fi
84
 
}
85
 
#}}}
86
 
texmf_all () { #{{{
87
 
  file=${1}
88
 
  find ${texmf_path_pattern} -type f > ${file}
89
 
  printf \
90
 
    "* Found %d texmf regular files.\n\t-> %s\n\n" \
91
 
    $(cat ${file} | wc -l) \
92
 
    ${file}
93
 
}
94
 
#}}}
95
 
texmf_qfiles () { #{{{
96
 
  file=${1}
97
 
  prev=${2}
98
 
  printf "* Appending ebuild to each file (might take some time).\n\t-> %s\n\n" ${file}
99
 
  qfile -Cf ${prev} > ${file}
100
 
}
101
 
#}}}
102
 
texmf_format () { #{{{
103
 
  file=${1}
104
 
  prev=${2}
105
 
  printf "* Format output to new file\n\t -> %s\n\n" ${file}
106
 
  sedex="(.*)[[:space:]]\((.*\/(.*))\)"
107
 
  sed -re "s/${sedex}/\2 \1 \3/" ${prev} > ${file}
108
 
}
109
 
#}}}
110
 
texmf_noboring () { #{{{
111
 
  # Using sed to remove some boring files from list.
112
 
  file=${1}
113
 
  prev=${2}
114
 
  # Boring pattern #{{{
115
 
boring_pattern=\
116
 
"[0-9]{0,2}read\.*me|"\
117
 
"alire|"\
118
 
"catalog(ue)*|"\
119
 
"copying|"\
120
 
"configure|"\
121
 
"demo\.|"\
122
 
"docindex\.|"\
123
 
"history|"\
124
 
"index\.html|"\
125
 
"img[0-9]{0,2}\.gif|"\
126
 
"news|"\
127
 
"ex[ae]mple|"\
128
 
"licen(c|s)e|"\
129
 
"version|"\
130
 
"changelog|"\
131
 
"changes|"\
132
 
"copyright|"\
133
 
"faq|"\
134
 
"install|"\
135
 
"makefile|"\
136
 
"makefont|"\
137
 
"manifest|"\
138
 
"manual|"\
139
 
"sample|"\
140
 
"todo|"\
141
 
"test[0-9]{0,2}\.|"\
142
 
"warnings|"\
143
 
"authors"
144
 
#}}}
145
 
  boring_file=$(tmp "texmf_boring")
146
 
  sed -r -e "\@(.*[[:space:]]){2}(${boring_pattern}).*@Id" ${prev} > ${file}
147
 
  diff ${prev} ${file} > ${boring_file}
148
 
  removed=$(cat ${boring_file} | sed "\@^[0-9]@d" | wc -l)
149
 
  printf \
150
 
    "* Removed %d boring files from list.\n\t -> %s\n\t -> %s\n\n" \
151
 
    ${removed} \
152
 
    ${file} \
153
 
    ${boring_file}
154
 
}
155
 
#}}}
156
 
texmf_files () { #{{{
157
 
  file=${1}
158
 
  prev=${2}
159
 
  awk '{ print $3, $2 }' ${prev} > ${file}
160
 
  supertmp="${tmp_files_path}/supertmp"
161
 
  sort ${file} > ${supertmp}
162
 
  # Remove files duplicated in different places by the same ebuild
163
 
  uniq ${supertmp} > ${file}
164
 
  removed=$(( $(cat ${supertmp} | wc -l) - $(cat ${file} | wc -l) ))
165
 
  rm ${supertmp}
166
 
  cp ${file} ${HOME}
167
 
  printf "* Removed %d dups from list. " ${removed}
168
 
  printf \
169
 
    "Final output (copied to \$HOME).\n\t -> %s\n\n" \
170
 
    ${file}
171
 
}
172
 
#}}}
173
 
#}}}
174
 
# For each file, trigger its associated function.#{{{
175
 
for f in ${files[@]}; do
176
 
  eval "texmf_common ${f}"
177
 
done
178
 
#}}}
179
 
# The end # {{{
180
 
printf "If you dont need to keep tmp files for posterity, you can remove \"texmf_*\" files from %s.\n" ${tmp_files_path}
181
 
 
182
 
exit
183
 
#}}}