-
Notifications
You must be signed in to change notification settings - Fork 3
/
makebook.example.1
376 lines (322 loc) · 8.63 KB
/
makebook.example.1
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/bin/sh
# doesnt include the cover because printed on thicker paper
# list of [p_start] chaptername [n_nbpage]
sources="p_3 aftercover n_2 summary n_4 intro n_14 realstart n_12 maincontent n_50 conclusion n_10"
####################################################################"
# Paramétrages
output=mybook
pdfwithimages=oui
# set to "-vecto" to use "-vecto" version of files and config
vectoopt=""
# other user options
setopt=""
#checkpagenum=''
checkpagenum='check'
pagenumwhy='' # reason why start page is set : 'set' or 'computed'echo
sourcespattern=1
# 0 : no change to filename in sources
# 1 : nomfich stands for filename/filename(.sla)
# 2 : nomfich stands for filename/PAO/filename(.sla)
# end new for aranya
# Rq : Nb d'éléments d'un array : ${#array[@]} ou ${#array[*]}
check='oui' # '' to not check (only merge chapter pdfs)
vconfig=''
vcheck=''
searched='' # searched string
xmlsearched='' # xml searched string
nbfound=0
nopdf=''
pdfopt=''
####################################################################
reset
. shellcolors
while [ "$stopoptions" = "" ]
do
stopoptions=true
if [ "$1" = '-?' ]
then
echo "mak makes the global PDF"
echo "Due to inline config, name of produced PDF is $output.pdf"
echo
echo "Options :"
echo "-? : get this help"
echo "-set : set value to correct value"
echo "-pagenum : also checks the first page number of each doc"
echo "-nopagenum : dont check the first page number of each doc"
echo "-nocheck : dont check anything, just merge all chapter's pdfs"
echo "-nopdf : dont create nor merge pdfs (only checks)"
echo "-forcepdf : force all pdf (re)creation, even when it exists allready"
echo "-vconfig : verbose output about config files"
echo "-vcheck : very verbose output about check"
echo '-find "word1 or phrase1" : find occurences in all chapters text'
echo '-xmlfind "string1" : find occurences of string in all chapters SLA file (text + xml tags)'
echo '-replace "string2" : replace found occurences with specified string2. (with -xmlfind only. with -find still to do)'
echo '-checkcolorall : check for (bad) uses of "All" named color'
echo "beta :"
echo "-vecto : uses -vecto version of each file (sla and pdf)"
echo
exit
fi
if [ "$1" = "-nocheck" ]
then
shift
check=''
echo "Chapter PDFs will be merged. No check will happen"
break
fi
if [ "$1" = "-vconfig" ]
then
vconfig=$1
shift
break
fi
if [ "$1" = "-vcheck" ]
then
vcheck=$1
shift
break
fi
if [ -f .found.tmp ]
then
rm .found.tmp
fi
if [ "$1" = "-find" ]
then
shift
if [ "$1" = "" ]
then
echo "${ESC_error}-find option must have additionnal parameter$ESC_normal"
exit
fi
searched="$1"
check=''
nopdf='-nopdf'
stopoptions=''
shift
continue
fi
if [ "$1" = "-xmlfind" ]
then
shift
if [ "$1" = "" ]
then
echo "${ESC_error}-xmlfind option must have additionnal parameter$ESC_normal"
exit
fi
xmlsearched="$1"
check=''
nopdf='-nopdf'
stopoptions=''
shift
continue
fi
if [ "$1" = '-checkcolorall' ]
then
checkcolorall='yes'
xmlsearched="COLOR=\"All\""
check=''
nopdf='-nopdf'
stopoptions=''
shift
continue
fi
if [ "$1" = "-replace" ]
then
if [ "$xmlsearched" = "" ] && [ "$searched" = "" ]
then
echo "${ESC_error}-replace option must follow some -xmlfind or -find option. No such options found here.$ESC_normal"
exit
fi
shift
if [ "$1" = "" ]
then
echo "${ESC_error}-replace option must have additionnal parameter$ESC_normal"
exit
fi
replaced="$1"
shift
echo "Replace all found strings with '$replaced'"
stopoptions=''
continue
fi
if [ "$1" = "-set" ]
then
shift
setopt='-set'
stopoptions=''
nopdf='-nopdf'
continue
fi
if [ "$1" = "-nopdf" ]
then
shift
nopdf='-nopdf'
continue
fi
if [ "$1" = "-forcepdf" ]
then
shift
nopdf=''
pdfopt='-forcepdf'
continue
fi
if [ "$1" = "-vecto" ]
then
shift
vectoopt='-vecto'
stopoptions=''
continue
fi
if [ "$1" = "-nopagenum" ]
then
shift
checkpagenum=''
stopoptions=''
continue
fi
done
####################################################################"
verboseopt="$vconfig $vcheck"
listepdf=""
pagenumopt=''
numpagecourant=1
for fic in $sources
do
if [ "${fic#p_}" != "$fic" ] && [ $checkpagenum = 'check' ]
then
numpagecourant=${fic#p_}
pagenumopt="-pagenum $numpagecourant"
echo "Début page $numpagecourant"
pagenumwhy=set
continue
fi
if [ "${fic#n_}" != "$fic" ] && [ $checkpagenum = 'check' ]
then
numpagecourant=$(( $numpagecourant+${fic#n_} ))
pagenumopt="-pagenum $numpagecourant"
echo "${fic#n_} pages"
pagenumwhy=computed
continue
fi
if [ "$sourcespattern" = 1 ]
then
fic="$fic/$fic"
elif [ "$sourcespattern" = 2 ]
then
fic="$fic/PAO/$fic"
fi
fic="$fic$vecto"
[ ! -f $fic.sla ] && echo Error : missing $fic.sla file && exit
echo
echo -n $fic
[ "$pagenumopt" != "" ] && echo " : page $numpagecourant ($pagenumwhy)"
[ "$pagenumopt" = "" ] && echo "${ESC_error}no starting page ?$ESC_normal"
pagenumwhy=''
if [ "$searched" != '' ] || [ "$xmlsearched" != '' ]
then
# Enlever d'abord les césures avant de chercher $searched, et même $xmlsearched
# césures conditionnelles = caractère Unicode U+00AD
# http://stackoverflow.com/questions/8562354/remove-unicode-characters-from-textfiles-sed-other-bash-shell-methods
# La commande `echo -ne '\u00AD' | xxd` donne c2ad qu'il faut utiliser avec \x dans `sed 's/...'` =
cleansla="$fic.clean.sla"
sed -e 's/\xc2\xad//g' "$fic.sla" > "$cleansla"
fi
if [ "$searched" != '' ]
then
count=`grep -i "<ITEXT[^>]*CH=" "$cleansla" | grep -c -o -i "\"[^\"]*$searched[^\"]*\""`
echo Search for "$searched" : $count results
if [ "$count" != "0" ]
then
nbfound=$(( $nbfound+$count ))
echo $ESC_yellow
grep -ni "<ITEXT[^>]*CH=" "$cleansla" | grep -i "\"[^\"]*$searched[^\"]*\"" | sed -e 's/<ITEXT[^>]*CH="//' | sed -e 's/"\/>//'
echo $ESC_normal
# -n : line number
# /dev/null is added so grep believes there is more than one file and outputs the filename
grep -ni "<ITEXT[^>]*CH=\"[^\"]*$searched[^\"]*\"" "$cleansla" /dev/null | sed -e 's/<ITEXT[^>]*CH="//' | sed -e 's/"\/>//' >> .found.tmp
fi
rm $cleansla
fi
if [ "$xmlsearched" != '' ]
then
# FIXME ? : malgré les -i ça n'a pas l'air case-insensitif
count=`grep -c -o -i "$xmlsearched" "$cleansla"`
echo Search for "$xmlsearched" : $count results
if [ "$count" != "0" ]
then
nbfound=$(( $nbfound+$count ))
echo $ESC_yellow
grep -ni "$xmlsearched" "$cleansla"
echo $ESC_normal
# -n : line number
# /dev/null is added so grep believes there is more than one file and outputs the filename
grep -ni "$xmlsearched" "$cleansla" /dev/null >> .found.tmp
echo "replaced=$replaced"
if [ "$replaced" != '' ]
then
if [ -f "$fic.before_replace.sla" ]
then
echo "$fic.before_replace.sla allready exists : moved as .bak"
mv "$fic.before_replace.sla" "$fic.before_replace.sla.bak"
fi
cp "$fic.sla" "$fic.before_replace.sla"
echo $fic.sla is saved into $fic.before_replace.sla
echo $xmlsearched is replaced with $replaced in $fic.sla
sed -i -- "s/$xmlsearched/$replaced/g" "$fic.sla"
fi
fi
rm $cleansla
fi
if [ "$check" = "oui" ]
then
# echo slacheck $vectoopt $setopt $pagenumopt $pdfopt $verboseopt $fic
slacheck $vectoopt $setopt $pagenumopt $pdfopt $verboseopt $fic
fi
listepdf="$listepdf $fic.pdf"
if [ "$pdfwithimages" = "no" ]
then
mv -b "$fic/images" "$fic/images.bak"
fi
done
if [ "$1" = "-nopdf" ] || [ "$1" = "nopdf" ]
then
exit
fi
if [ "$nopdf" = "" ]
then
mv $output.pdf $output.pdf.bak
# add some special file as a last page cover
# listepdf="$listepdf separettes/p68-HR.pdf"
pdftk $listepdf cat output $output.pdf
if [ -f $output.pdf ]
then
ls -ltr $output.pdf
echo $output.pdf created OK
evince $output.pdf &
fi
fi
# création d'une version sans marge (marges enlevées à l'arrache pour l'instant) : un peu utile pour impression un peu plus grand en pleine page
# pdfcrop --margins '-25 -25 -25 -25' $output.pdf normargin_$output.pdf
# [ -f normargin_$output.pdf ] && evince normargin_$output.pdf & ls -ltr normargin_$output.pdf ; echo normargin_$output.pdf created OK
if [ "$pdfwithimages" = "no" ]
then
for fic in $sources
do
fic=$fic$vecto
mv -b "$fic/images.bak" "$fic/images"
done
fi
if [ "$searched$xmlsearched" != '' ]
then
echo Done
echo
echo ${ESC_yellow}Searching \'$searched$xmlsearched\' : $nbfound results found in whole book$ESC_normal
if [ $nbfound != 0 ]
then
if [ "$checkcolorall" != '' ]
then
echo "${ESC_error}Some (bad) uses of COLOR=\"All\" have been found !$ESC_normal"
fi
cat .found.tmp
fi
fi