#!/bin/bash # Sat Dec 7 15:54:06 EST 2002 # NAME: mklabels # Copyright 2002,2003, Chris F.A. Johnson # Released under the terms of the GNU General Public License pgy=11 ## vertical page size in inches cols=2 ## number of labels across page rows=5 ## number of labels top to bottom pgleft=.75 ## space in inches from left of page to left edge of label pgtop=.25 ## space in inches from top of page to top of label labx=3.5 ## label width, in inches laby=2 ## label height, in inches labl=.25 ## space in inches from left edge of label labt=.25 ## space in inches from top edge of label font=Helvetica fontsize=18 leading=15 ## space between lines as percentage of font size indent=.5 ## indent lines; indent=0 to turn off; increase to taste fldsep=" " ## field separator, default is tab ######### DO NOT MODIFY BELOW THIS LINE ######### version() { echo " $progname, version $version Copyright $copyright, $author${email:+, $email} This is free software, released under the terms of the GNU General Public License. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " } options() { echo " OPTIONS: -P N.N - height of page in inches -c N - number of labels across page ($cols) -r N - number of labels top to bottom ($rows) -F FONT - font family -S SIZE - font size in points -m N.N - inches from left edge of label -M N.N - inches from top edge of label -l N.N - inches from left of page to left edge of label ($pgleft) -t N.N - inches from top of page to top of label ($pgtop) -x N.N - label width, in inches -y N.N - label height, in inches -L LEADING - space between lines as percentage of font size ($leading) -i N.N - indent lines; indent=0 to turn off; increase to taste -f C - use character C as field separator (\"$fldsep\") -g - print alignment grid with labels -G - print alignment grid only -h, --help - help: print this message -H, --help_long - more help -v - verbose: -V, --version - print version information Copyright $copyright, $author " } usage() { echo " $progname - Create a postscript file for printing labels USAGE: $progname [OPTIONS] [FILE]..." if [ $longusage -eq 0 ] then echo " If no FILE is given, labels are read from STDIN. " else echo " $progname creates a PostScript file on STDOUT, which can be redirected to a file or your printer. The PostScript is clean and easily editable. It reads a file (or files, or STDIN if no file is given) with addresses 1 to a line. Fields, which will be printed 1 to a line, should be separated by tabs (configurable). The default is for $cols columns of $rows rows (adjust cols and rows), with a label size of $labx by $laby inches. All the configurable parameters may be adjusted at the top of the script or by command-line options. To print a grid to help with alignment, use the -G option. " fi options } verbose=0 longusage=0 version="1.1" copyright="2002,2003" author="Chris F.A. Johnson" email=cfaj@freeshell.org progname=${0##*/} dogrid=0 while getopts vVhH-:gGf:c:r:l:t:x:y:m:M:F:S:L:i:P: var do case "$var" in c) cols=$OPTARG ;; r) rows=$OPTARG ;; l) pgleft=$OPTARG ;; t) pgtop=$OPTARG ;; x) labx=$OPTARG ;; y) laby=$OPTARG ;; m) labl=$OPTARG ;; M) labt=$OPTARG ;; F) font=$OPTARG ;; S) fontsize=$OPTARG ;; L) leading=$OPTARG ;; i) indent=$OPTARG ;; f) fldsep=$OPTARG ;; P) pgy=$OPTARG ;; g) dogrid=1 ;; G) dogrid=2 ;; -) case $OPTARG in help) usage; exit ;; help_long) longusage=1; usage; exit ;; version) version; exit ;; esac ;; h) usage; exit ;; H) longusage=1; usage; exit ;; v) verbose=1 ;; V) version; exit ;; *);; esac done shift $(( $OPTIND - 1 )) echo "%!PS" echo " /bdef {bind def} bind def /ldef {load def} bdef /inch { 72 mul } bdef /gs /gsave ldef /gr /grestore ldef /m /moveto ldef /rm /rmoveto ldef /l /lineto ldef /rl /rlineto ldef /topleft { %% column row topleft laby mul neg pgy add pgtop sub leading add exch labx mul pgleft add exch translate 0 0 moveto } def /F { findfont exch scalefont setfont } bdef /nl { lindent leading rmoveto } def " echo "%%EndProlog " echo " /cols $cols def /rows $rows def /pgleft $pgleft inch def /pgtop $pgtop inch def /pgy $pgy inch def /labx $labx inch def /laby $laby inch def /font /$font def /fontsize $fontsize def /leading fontsize dup $leading mul 100 div add neg def /lindent ${indent:-0} leading neg mul def /labt $labt inch leading sub neg def /labl $labl inch def fontsize font F " if [ ${dogrid:-0} -gt 0 ] then echo " gs /y 0 def rows { /x 0 def cols { gs x y topleft 0 laby neg rl labx 0 rl 0 laby rl closepath stroke /x x 1 add def gr } repeat /y y 1 add def } repeat gr " fi [ $dogrid -eq 2 ] && exit n=0 p=0 IFS=${fldsep:-$'\t'} cat "$@" | while read line do [ "$line" ] || continue l=$(( $n % ( $cols * $rows ) )) if [ $l -eq 0 ] then [ $p -ge 1 ] && printf "\nshowpage\n\n" p=$(( $p + 1 )) fi x=$(( $l % $cols )) y=$(( $l / $cols )) echo "gs" echo " $x $y topleft" echo " labl labt moveto" set -- $line while [ $# -gt 0 ] do ln="${1//(/\(}" echo " gs (${ln//)/\)}) show gr nl" shift done echo "gr" echo n=$(( $n + 1 )) done ### END OF SCRIPT ###