-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_page_no.sh
executable file
·115 lines (99 loc) · 2.23 KB
/
list_page_no.sh
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
#!/bin/bash
#
# Script for listing the page numbers of the already compiled articles.
# Output format:
# name <TAB> dir <TAB> #pages <TAB> startpage
# If an article is not to be included in the startpage count, "NA" will
# get output instead of the "startpage" value.
# the usage of this script
function usage()
{
echo
echo "${0##*/} [-r <name>] [-h]"
echo
echo "Lists the page numbers of the compiled articles as defined in $LIST."
echo "Output format:"
echo "name <TAB> dir <TAB> #pages <TAB> startpage"
echo "If an article is not to be included in the startpage count, \"NA\" will"
echo "get output instead of the \"startpage\" value."
echo
echo " -h this help"
echo " -r <name>"
echo " resume update with this article name"
echo " NB: the \"start page\" value won't be correct in this case"
echo
}
# function for listing the page numbers
function list_page_no()
{
OLDDIR="`pwd`"
cd "$DIR"
COUNT=`pdfinfo $NAME.pdf | grep "Pages:" | sed s/".*:\| *"//g`
# output article stats
if [ "$ADD" = "yes" ]
then
echo -e "$NAME\t$DIR\t$COUNT\t$START_PAGE"
else
echo -e "$NAME\t$DIR\t$COUNT\tNA"
fi
if [ "$ADD" = "yes" ]
then
START_PAGE=$(($START_PAGE+$COUNT))
fi
cd "$OLDDIR"
}
ROOT=`expr "$0" : '\(.*\)/'`
LIST=$ROOT/articles.list
COMMENT="#"
RESUME=""
START_PAGE=1
# interprete parameters
while getopts ":hr:" flag
do
case $flag in
r) RESUME=$OPTARG
;;
h) usage
exit 0
;;
*) usage
exit 1
;;
esac
done
if [ "$RESUME" = "" ]
then
echo -e "name\tdir\tpageno\tstartpage"
fi
while read LINE
do
# comment or empty line?
if [[ "$LINE" =~ ^$COMMENT ]] || [ -z "$LINE" ]
then
continue
fi
IFS=$'\t' read -r -a PARTS <<< "${LINE}"
NAME="${PARTS[0]}"
DIR="${PARTS[1]}"
ADD="${PARTS[3]}"
# find project to resume
if [ ! "$RESUME" = "" ]
then
if [ ! "$RESUME" = "$NAME" ]
then
continue
else
RESUME=""
fi
fi
list_page_no
# failed?
if [[ $RC != 0 ]] && [ "$RC" != "" ]
then
echo
echo "Listing page numbers for '$NAME' failed with exit code: $RC"
echo "You can resume listing with: ${0##*/} -r $NAME"
echo
exit $RC
fi
done < "$LIST"