aboutsummaryrefslogtreecommitdiff
path: root/lp/process/psextract
diff options
context:
space:
mode:
Diffstat (limited to 'lp/process/psextract')
-rwxr-xr-xlp/process/psextract60
1 files changed, 60 insertions, 0 deletions
diff --git a/lp/process/psextract b/lp/process/psextract
new file mode 100755
index 00000000..55695a1c
--- /dev/null
+++ b/lp/process/psextract
@@ -0,0 +1,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;
+}
+
+'