-
Notifications
You must be signed in to change notification settings - Fork 0
/
psmove
executable file
·59 lines (46 loc) · 1.17 KB
/
psmove
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
#!/bin/rc
rfork
ramfs
fn usage{
echo 'usage: pstoc pagefrom pageto <input.ps >output.ps' >[1=2]
}
~ $#* 2 || {
usage
exit usage
}
pagefrom=$*(1)
pageto=$*(2)
cat >/tmp/input.ps
file=/tmp/input.ps
pages=`{grep '^%%Pages: ' $file | sed -e 's/\(atend\)//g' -e 's/^%%Pages: //'}
if(~ $pagefrom -*)
pagefrom=`{echo $pages $pagefrom | bc}
if(~ $pageto -*)
pageto=`{echo $pages $pageto | bc}
test $pagefrom -gt $pages && { usage; exit usage }
test $pageto -gt $pages && { usage; exit usage }
# extract pages
sed -n '1,/^%%EndSetup/p' $file >/tmp/preamble
sed -n '/^%%Trailer/,$p' $file >/tmp/postamble
p=$pages
while(! ~ $p 0){
sed -n '/^%%Page: '^$p^' '^$p^'/,/^%%EndPage: '^$p^' '^$p^'/p' $file >/tmp/$p
p=`{echo $p - 1 | bc}
}
# reorder pages
cp /tmp/$pagefrom /tmp/toc
p=$pagefrom
while(! ~ $p $pageto){
cp /tmp/`{echo $p - 1 | bc} /tmp/$p
p=`{echo $p - 1 | bc}
}
cp /tmp/toc /tmp/$pageto
rm /tmp/toc
# fix page numbers
p=$pages
while(! ~ $p 0){
sed -e 's/^%%Page: .+ .+$/%%Page: '^$p^' '^$p^'/g' -e 's/^%%EndPage: .+ .+$/%%EndPage: '^$p^' '^$p^'/g' /tmp/$p > /tmp/new^$p
mv /tmp/new^$p /tmp/$p
p=`{echo $p - 1 | bc}
}
cat /tmp/preamble /tmp/^`{seq 1 $pages} /tmp/postamble