Plan 9 from Bell Labs’s /usr/web/sources/plan9/sys/lib/lp/process/psextract

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/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;
}

'

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.