aboutsummaryrefslogtreecommitdiff
path: root/lp/process/psextract
blob: 55695a1c1a58c85fb694a9de9abe1cdd4b6dc137 (plain)
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
#!/usr/local/plan9/bin/rc

# extract pages $OLIST from postscript on stdin

if(~ $OLIST '')
	exec cat

awk '
BEGIN {
	x=ENVIRON["OLIST"];
	gsub(/^-o/, "", x);
	na = split(x, a, ",");
	header = 1;
	goodpage = 0;
}

header || goodpage {
 	print
}

/^%%EndSetup[ 	]*$/ { header = 0; next }

/^%%Page:/ {
	header = 0;
	p=$2+0;
	goodpage = 0;
	for(i=1; i<=na; i++){
		if(aa=match(a[i], "-")){
			low=substr(a[i], 1, RSTART);
			high=substr(a[i], RSTART+RLENGTH);
			if(low == "")
				low = 0;
			else
				low = low+0;
			if(high == "")
				high = 100000;
			else
				high = high+0;
			if(low <= p && p <= high){
				goodpage = 1;
				break;
			}
		}else{
			if(a[i] == p){
				goodpage = 1;
				break;
			}
		}
	}
}

/^%%EndPage[ 	]*$/ {
	goodpage = 0;
}

/^%%Trailer[ 	]*$/ { 
	goodpage = 1;
}

'