#!/usr/local/bin/perl # graphpaper - print graph paper # graphpaper [ size ] # optional argument specifies size of squares in decimal $lpr = "/usr/ucb/lpr"; $size = .25; # default square size while ($ARGV[0]) { if ($ARGV[0] =~ /^[\d.]+$/) { $size = $ARGV[0]; shift; } } if ( ! -t STDOUT ) { # if we're being piped somewhere, don't print print STDERR "Piping to standard output\n"; select STDOUT; } elsif ( -x $lpr ) { open (LPR,"| $lpr") || die "Cannot open pipe to $lpr\n"; print STDERR "Piping to $lpr\n"; select LPR; } else { die "Cannot execute $lpr\n"; } print STDERR "Using $size inch squares\n"; die "$0: Unable to print!\n" unless print <<"EOPS"; %!PS % graph paper % measurements in inches /spacing { $size } def % this is set from Perl /width { 8.5 } def /height { 11 } def % measurements in points, % taken from inch measurements above /pspacing { spacing 72 mul } bind def /pwidth { width 72 mul } bind def /pheight { height 72 mul } bind def /verticals { newpath 0 pspacing pwidth { 0 moveto 0 pheight rlineto } bind for stroke } bind def /horizontals { newpath 0 pspacing pheight { 0 exch moveto pwidth 0 rlineto } bind for stroke } bind def % --- begin --- 0.1 setlinewidth 0.25 setgray [ 0 1 1 ] 0 setdash verticals horizontals showpage EOPS