Cover V02, I02
Article
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Listing 1
Listing 10
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6
Listing 7
Listing 8
Listing 9

mar93.tar


Listing 2: The getptr/gethead command

1: #
2: # getptr/gethead (linked):
3: #   Prompt for printer/letterhead name, with optional default
4: #   Written by Leor Zolman, 9/91
5: #
6: # Usage:
7: #   getptr [default-printer]
8: #   gethead [default-letterhead]
9: #   Returns corresponding "lp" command line args on standard output.
10: #
11:
12: PTRDIR=/u/leor/docs/Cols/SA/Printers            # Printer control directory
13:
14: case $0 in
15:   getptr)   CODECHAR=G                          # for restricting selections
16:             WHAT="Printer";;
17:   gethead)  CODECHAR=H
18:             WHAT="Letterhead";;
19: esac
20:
21: [ $# -gt 1 ] && echo "Usage: $0 [default-$WHAT]" >&2 && exit
22:
23: . $PTRDIR/initmap.sh        # initialize and handle special-case mappings
24:
25: # choose printer area:
26:
27: saveptype=$ptype
28: while true
29: do
30:     echo "\n" >&2
31:     header="----------- ${WHAT}s ($DEPTDESC Area) -----------"
32:     echo $header >&2
33:     sed -n 's/^[^,]*, *\([^,]*\),[^:]*:\([^:]*\):.*'\
34: $CODECHAR'[A-Z]*$/\1 (\2)/p' paper.map
35:     echo "$header" | tr '[ -z]' '[-*]' >&2
36:     echo "Choose a $WHAT, 'A' to change area, \c" >&2
37:     echo "Return for default [$ptype] ?\c">&2
38:     read code
39:     [ "$code" != "" ] && ptype=$code
40:
41:     if [ "$ptype" = a -o "$ptype" = A ]; then
42:      while true
43:      do
44:         echo "\n   DEPARTMENTAL AREAS:" >&2
45:         sed -n 's/^.*"\(.\)\(.*\)".*$/\1\2  (\1)/p' dept.map
46:         while true
47:         do
48:             echo "\nSelect an area (by single-letter code): \c">&2
49:             read code
50:             code=`echo "$code\c" | tr '[a-z]' '[A-Z]'`
51:             if tmp=`grep $code'$' dept.map`
52:             then
53:                 DEPT=`echo $tmp | cut -d, -f2 | tr -d "\011" `
54:                 break
55:             else
56:                 echo "Please choose from the displayed list only!" >&2
57:             fi
58:         done
59:         [ $DEBUG = Y ] && echo "after dept loop, DEPT = $DEPT" && exit
60:         ptype=$saveptype
61:         . $PTRDIR/initmap.sh
62:         break
63:      done
64:      continue
65:     else
66:         if grep ":$ptype:" $PTRDIR/paper.map >/dev/null
67:         then
68:             break
69:         else
70:             echo "\nPlease choose from the listed options only." >&2
71:             ptype=$saveptype
72:         fi
73:     fi
74: done
75:
76: #
77: # Map $ptype and $DEPT into appropriate lp text in $lpopts:
78: #
79:
80: . $PTRDIR/proxmap.sh
81:
82: echo "$lpopts"
83: exit 0